ATLAS Offline Software
Loading...
Searching...
No Matches
VP1BPhysSystem.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
6// //
7// Implementation of class VP1BPhysSystem //
8// //
9// Author: Daniel Scheirich //
10// //
11// Initial version: September 2009 //
12// //
14
16#include "ui_bphyscontrollerform.h"
17
20#include "VP1Base/VP1QtUtils.h"
22
23
24#include <Inventor/nodes/SoBaseColor.h>
25#include <Inventor/nodes/SoDrawStyle.h>
26#include <Inventor/nodes/SoLineSet.h>
27#include <Inventor/nodes/SoMatrixTransform.h>
28#include <Inventor/nodes/SoSeparator.h>
29#include <Inventor/nodes/SoSphere.h>
30#include <Inventor/nodes/SoSwitch.h>
31#include <Inventor/nodes/SoTranslation.h>
32#include <Inventor/nodes/SoVertexProperty.h>
33#include <QFileDialog>
34#include <utility>
35
36
37
39
40#include "TrkTrack/Track.h"
44
47
49
50#include "TFile.h"
51#include "TTree.h"
52
53
54
55const unsigned int darknes = 50;
56const unsigned long darkGray = darknes*65536 + darknes*256 + darknes;
57
58bool Br::init(TTree* tree) {
60 if(tree==nullptr) return false;
61
62 vp1Filter->SetBranchAddress("evtNum", &evtNum);
63 vp1Filter->SetBranchAddress("runNum", &runNum);
64
65 vp1Filter->SetBranchAddress("vtx_x", &vtx_x);
66 vp1Filter->SetBranchAddress("vtx_y", &vtx_y);
67 vp1Filter->SetBranchAddress("vtx_z", &vtx_z);
68
69 vp1Filter->SetBranchAddress("vtx_xx", &vtx_xx);
70 vp1Filter->SetBranchAddress("vtx_yy", &vtx_yy);
71 vp1Filter->SetBranchAddress("vtx_zz", &vtx_zz);
72 vp1Filter->SetBranchAddress("vtx_xy", &vtx_xy);
73 vp1Filter->SetBranchAddress("vtx_xz", &vtx_xz);
74 vp1Filter->SetBranchAddress("vtx_yz", &vtx_yz);
75
76 vp1Filter->SetBranchAddress("vtx_mother", &vtx_mother);
77 vp1Filter->SetBranchAddress("vtx_color", &vtx_color);
78 vp1Filter->SetBranchAddress("vtx_daughters", &vtx_daughters);
79
80 //tracks
81 vp1Filter->SetBranchAddress("track_pt", &track_pt );
82 vp1Filter->SetBranchAddress("track_eta", &track_eta );
83 vp1Filter->SetBranchAddress("track_phi", &track_phi );
84 vp1Filter->SetBranchAddress("track_d0", &track_d0 );
85 vp1Filter->SetBranchAddress("track_z0", &track_z0 );
86 vp1Filter->SetBranchAddress("track_charge", &track_charge );
87 vp1Filter->SetBranchAddress("track_refitted_px", &track_refitted_px );
88 vp1Filter->SetBranchAddress("track_refitted_py", &track_refitted_py );
89 vp1Filter->SetBranchAddress("track_refitted_pz", &track_refitted_pz );
90 vp1Filter->SetBranchAddress("track_color", &track_color );
91 vp1Filter->SetBranchAddress("track_refitted_color", &track_refitted_color);
92
93 //neutral tracks
94 vp1Filter->SetBranchAddress("neutral_refitted_px", &neutral_refitted_px);
95 vp1Filter->SetBranchAddress("neutral_refitted_py", &neutral_refitted_py);
96 vp1Filter->SetBranchAddress("neutral_refitted_pz", &neutral_refitted_pz);
97 vp1Filter->SetBranchAddress("neutral_length", &neutral_length );
98 vp1Filter->SetBranchAddress("neutral_decay", &neutral_decay );
99 vp1Filter->SetBranchAddress("neutral_color", &neutral_color );
100
101 return true;
102
103}
104
105int Br::GetEntry(int i) {
106 return vp1Filter->GetEntry(i);
107}
108
110 public:
111 Ui::BPhysControllerForm ui;
112};
113//_____________________________________________________________________________________
114
116 : IVP13DSystemSimple("BPhys",
117 "VP1BPhysSystem",
118 "daniel.scheirich@cern.ch") ,
122
123 m_showAll{},
124 m_showSignal{},
127
133 m_br{},
134 m_c(new Clockwork)
135{
136 messageDebug("in BPhysSystem");
137
138 m_rootFile = nullptr;
139 m_tree = nullptr;
140 m_sg = nullptr;
141 m_root = nullptr;
142
143
144// messageDebug("Creating propagationHelper...");
145// propagationHelper = new TrackPropagationHelper(this);
146// messageDebug("...done");
147
148 messageDebug("leaving VP1BPhysSystem");
149}
150
151//_____________________________________________________________________________________
153{
154 messageDebug("in buildController");
155
156 QWidget * controller = new QWidget(nullptr);
157 m_c->ui.setupUi(controller);
158
159 //connect slots
160 connect(m_c->ui.bLoad,SIGNAL(released()),this,SLOT(loadFile()));
161
162 connect(m_c->ui.chDisplayVertices,SIGNAL(stateChanged(int)),this,SLOT(displayVerticesChanged(int)));
163 connect(m_c->ui.rbSphere,SIGNAL(toggled(bool)),this,SLOT(sphereToggled(bool)));
164 connect(m_c->ui.rbCross,SIGNAL(toggled(bool)),this,SLOT(crossToggled(bool)));
165 connect(m_c->ui.rbEllipsoid,SIGNAL(toggled(bool)),this,SLOT(ellipsoidToggled(bool)));
166
167 connect(m_c->ui.chDisplayAllTracks ,SIGNAL(stateChanged(int)),this,SLOT(displayAllTracksChanged(int)));
168 connect(m_c->ui.chDisplayOrigSignal,SIGNAL(stateChanged(int)),this,SLOT(displayOrigSignalChanged(int)));
169 connect(m_c->ui.chDisplayRefTracks ,SIGNAL(stateChanged(int)),this,SLOT(displayRefTracksChanged(int)));
170 connect(m_c->ui.chDisplayNeutral ,SIGNAL(stateChanged(int)),this,SLOT(displayNeutralChanged(int)));
171
172 if(m_c->ui.rbSphere->isChecked()) m_vertexStyle = 0;
173 if(m_c->ui.rbCross->isChecked()) m_vertexStyle = 1;
174 if(m_c->ui.rbEllipsoid->isChecked()) m_vertexStyle = 2;
175 m_showVertices = m_c->ui.chDisplayVertices->isChecked();
176
177 m_showAll = m_c->ui.chDisplayAllTracks->isChecked();
178 m_showSignal = m_c->ui.chDisplayOrigSignal->isChecked();
179 m_showRefitted = m_c->ui.chDisplayRefTracks->isChecked();
180 m_showNeutral = m_c->ui.chDisplayNeutral->isChecked();
181
182
183 messageDebug("leaving buildController");
184
185 return controller;
186}
187
188
189//_____________________________________________________________________________________
191
192 //delete all objects from the scene
193 m_root->removeAllChildren();
194
195 //Sanity check:
196 if (!m_sg) {
197 message("Error: Got null storegate pointer");
198 return;
199 }
200
201 //check that file was open
202 if(m_tree==nullptr) return;
203
204 //retrieving event info
205 const EventContext& ctx = Gaudi::Hive::currentContext();
206 int evtNum = ctx.eventID().event_number();
207 int runNum = ctx.eventID().run_number();
208
209 //retrieve TrackParticle candidates
210 const Rec::TrackParticleContainer* partCont;
211 StatusCode status = m_sg->retrieve(partCont, "TrackParticleCandidate");
212 if (status != StatusCode::SUCCESS || !partCont) {
213 message("Error: Could not retrieve track particle container (used key=TrackParticleCandidate)");
214 return;
215 }
216
218 //cleanup
219 m_vertexSwitches.clear();
220 m_trackSwitches.clear();
221 m_overlapSwitches.clear();
222 m_signalSwitches.clear();
223 m_neutralSwitches.clear();
224 m_refittedSwitches.clear();
225
227
228 std::vector<const Rec::TrackParticle*>* selectedParticles = new std::vector<const Rec::TrackParticle*>();
229
230
231 //find event
232 //int e = m_tree->GetEntryNumberWithIndex(runNum, evtNum); //for some reason this doesn't work 100% reliable
233
234 int e=-1;
235 for(int i=0; i<m_tree->GetEntries(); ++i) {
236 m_br->GetEntry(i);
237 if(m_br->runNum == runNum && m_br->evtNum == evtNum) {
238 e=i;
239 break;
240 }
241 }
242
243 if(e==-1) {
244 m_c->ui.lStatus->setText("No event to display");
245 message("Event is not in the VP1BPhys Display File. Skipping.");
246 }else{
247 m_c->ui.lStatus->setText("");
248
249 m_br->GetEntry(e);
250 for(; m_br->runNum == runNum && m_br->evtNum == evtNum && e<m_tree->GetEntries(); m_br->GetEntry(++e)) {
251
252
253 //filter tracks
254 //sanity check
255 if(m_br->track_pt->size() != m_br->track_eta->size() ||
256 m_br->track_pt->size() != m_br->track_eta->size() ||
257 m_br->track_pt->size() != m_br->track_phi->size() ||
258 m_br->track_pt->size() != m_br->track_d0->size() ||
259 m_br->track_pt->size() != m_br->track_z0->size() ||
260 m_br->track_pt->size() != m_br->track_charge->size() ||
261 m_br->track_pt->size() != m_br->track_color->size() ||
262 m_br->track_pt->size() != m_br->track_refitted_px->size() ||
263 m_br->track_pt->size() != m_br->track_refitted_py->size() ||
264 m_br->track_pt->size() != m_br->track_refitted_pz->size() ||
265 m_br->track_pt->size() != m_br->track_refitted_color->size() ||
266 m_br->neutral_refitted_px->size() != m_br->neutral_refitted_py->size() ||
267 m_br->neutral_refitted_px->size() != m_br->neutral_refitted_py->size() ||
268 m_br->neutral_refitted_px->size() != m_br->neutral_refitted_pz->size() ||
269 m_br->neutral_refitted_px->size() != m_br->neutral_length->size() ||
270 m_br->neutral_refitted_px->size() != m_br->neutral_color->size())
271 {
272 message("Different lengths of some filter track collections");
273 continue;
274 }
275
276 //draw selected particles
277 for(uint i=0; i<m_br->track_pt->size(); ++i) {
278 //TrackParticles
279 filterTrack(m_root, partCont,
280 m_br->track_pt->at(i),
281 m_br->track_eta->at(i),
282 m_br->track_phi->at(i),
283 m_br->track_d0->at(i),
284 m_br->track_z0->at(i),
285 m_br->vtx_x, m_br->vtx_y, m_br->vtx_z,
286 m_br->track_color->at(i),
287 selectedParticles);
288
289 //refitted tracks
291 m_br->vtx_x, m_br->vtx_y, m_br->vtx_z,
292 m_br->track_refitted_px->at(i),
293 m_br->track_refitted_py->at(i),
294 m_br->track_refitted_pz->at(i),
295 m_br->track_charge->at(i),
296 m_br->track_refitted_color->at(i));
297
298 }
299
300
301 //draw neutral tracks
302 std::vector<double>::iterator neutralPxItr = m_br->neutral_refitted_px->begin();
303 std::vector<double>::iterator neutralPyItr = m_br->neutral_refitted_py->begin();
304 std::vector<double>::iterator neutralPzItr = m_br->neutral_refitted_pz->begin();
305 std::vector<double>::iterator neutralLengthItr = m_br->neutral_length->begin();
306 std::vector<unsigned long>::iterator neutralColorItr = m_br->neutral_color->begin();
307
308 for(; neutralPxItr!=m_br->neutral_refitted_px->end(); ++neutralPxItr, ++neutralPyItr, ++neutralPzItr, ++neutralLengthItr, ++neutralColorItr) {
309 drawNeutralTrack(m_root, m_br->vtx_x, m_br->vtx_y, m_br->vtx_z,
310 *neutralPxItr, *neutralPyItr, *neutralPzItr, *neutralLengthItr, *neutralColorItr);
311 }
312
313 //draw vertices
314 drawVertex(m_root, m_br->vtx_x, m_br->vtx_y, m_br->vtx_z, 3/*sigma*/,
315 m_br->vtx_xx,
316 m_br->vtx_xy,
317 m_br->vtx_xz,
318 m_br->vtx_yy,
319 m_br->vtx_yz,
320 m_br->vtx_zz,
321 m_br->vtx_color,
323
324 }
325 }
326
327 //draw all remaining tracks
328 drawAllTrackParticles(m_sg,m_root,selectedParticles);
329
330 //cleaning up
331 delete selectedParticles;
332
333
334}
335//_____________________________________________________________________________________
337{
338 messageDebug("in buildEventSceneGraph");
339
340 m_sg = sg;
341 m_root = root;
342
343 actualBuild();
344
345 messageDebug("Leaving buildEventSceneGraph");
346
347}
348
349void VP1BPhysSystem::filterTrack(SoSeparator *root, const Rec::TrackParticleContainer* partCont,
350 double pt, double eta, double /*phi*/, double /*d0*/, double /*z0*/,
351 double x, double y, double z, unsigned long color,
352 std::vector<const Rec::TrackParticle*>* selectedParticles)
353{
354 messageDebug("in filterTrack");
355 //loop over TrackParticles
356 Rec::TrackParticleContainer::const_iterator partItr, partItrEnd = partCont->end();
357 for ( partItr = partCont->begin() ; partItr != partItrEnd; ++partItr) {
358
359 double trk_qOverP = (*partItr)->measuredPerigee()->parameters()[Trk::qOverP];
360 double trk_theta = (*partItr)->measuredPerigee()->parameters()[Trk::theta];
361// double trk_phi = (*partItr)->measuredPerigee()->parameters()[Trk::phi];
362
363 double trk_pt = fabs(1./trk_qOverP)*sin(trk_theta);
364 double trk_eta = -log(tan(trk_theta/2));
365
366 //identify selected track
367 if(fabs(trk_pt - pt)<0.1 && fabs(trk_eta - eta)<0.01) {
368 drawCutoffTrackParticle(root, *partItr, x, y, z, color);
369 if(selectedParticles!=nullptr) {
370 selectedParticles->push_back(*partItr);
371 }
372 }
373 }
374 messageDebug("leaving filterTrack");
375
376}
377//___________________________________________________________
378void VP1BPhysSystem::drawAllTrackParticles(StoreGateSvc* sg, SoSeparator *root, std::vector<const Rec::TrackParticle*>* selectedParticles) {
379 messageDebug("in drawAllTrackParticles");
380
381 //retrieve TrackParticle candidates
382 const Rec::TrackParticleContainer* partCont;
383 StatusCode status = sg->retrieve(partCont, "TrackParticleCandidate");
384 if (status != StatusCode::SUCCESS || !partCont) {
385 message("Error: Could not retrieve track particle container (used key=TrackParticleCandidate)");
386 return;
387 }
388
389 Rec::TrackParticleContainer::const_iterator partItr, partItrEnd = partCont->end();
390 for ( partItr = partCont->begin() ; partItr != partItrEnd; ++partItr) {
391 bool found = false;
392 if(selectedParticles!=nullptr) {
393 std::vector<const Rec::TrackParticle*>::const_iterator selItr = selectedParticles->begin();
394 for(; selItr!=selectedParticles->end(); ++selItr) {
395 if(*partItr == *selItr) {
396 found = true;
397 break;
398 }
399 }
400 }
401 if(!found) {
402 SoSwitch* trackSwitch = new SoSwitch();
403 root->addChild(trackSwitch);
404 trackSwitch->whichChild = m_showAll ? SO_SWITCH_ALL : SO_SWITCH_NONE;
405 drawTrackParticle(trackSwitch, *partItr, darkGray);
406 m_trackSwitches.push_back(trackSwitch);
407 }else{
408 SoSwitch* trackSwitch = new SoSwitch();
409 root->addChild(trackSwitch);
410 trackSwitch->whichChild = m_showAll && !m_showSignal && !m_showRefitted ? SO_SWITCH_ALL : SO_SWITCH_NONE;
411 drawTrackParticle(trackSwitch, *partItr, darkGray);
412 m_overlapSwitches.push_back(trackSwitch);
413 }
414 }
415 messageDebug("leaving drawAllTrackParticles");
416
417}
418//___________________________________________________________
419void VP1BPhysSystem::drawTrackParticle(SoSwitch* trackSwitch, const Rec::TrackParticle* part, unsigned long color) {
420
421 messageDebug("in drawTrackParticle");
422
423 //getting track space-points
424 std::vector<Amg::Vector3D >* points = getPoints(part);
425
426 //drawing line
427 drawPoints(trackSwitch,points,color, 0.0f, false);
428
429 //cleaning up
430 delete points;
431
432 messageDebug("leaving drawTrackParticle");
433
434}
435//___________________________________________________________
436void VP1BPhysSystem::drawCutoffTrackParticle(SoSeparator *root, const Rec::TrackParticle* part, double x, double y, double z, unsigned long color) {
437 messageDebug("in drawCutoffTrackParticle");
438
439 //getting track space-points
440 std::vector<Amg::Vector3D >* points = getPoints(part);
441
442 //getting cut-off point collection
443 std::vector<Amg::Vector3D >* cutoffPoints = findClosestApproach(points, x, y, z);
444
445 //drawing
446 SoSwitch* trackSwitch = new SoSwitch();
447 root->addChild(trackSwitch);
448 trackSwitch->whichChild = m_showSignal ? SO_SWITCH_ALL : SO_SWITCH_NONE;
449 drawPoints(trackSwitch,cutoffPoints,color,2,false);
450 m_signalSwitches.push_back(trackSwitch);
451
452 //cleaning up
453 delete points;
454 delete cutoffPoints;
455
456 messageDebug("leaving drawCutoffTrackParticle");
457
458}
459//___________________________________________________________
460void VP1BPhysSystem::drawNeutralTrack(SoSeparator* root, double x, double y, double z, double px, double py, double pz, double length, unsigned long color) {
461 messageDebug("in drawNeutralTrack");
462
463 std::vector<Amg::Vector3D >* points = new std::vector<Amg::Vector3D >();
464
465 //create neutral track vector
466 CLHEP::Hep3Vector p(px,py,pz);
467 CLHEP::Hep3Vector track = p.unit();
468 track *= length;
469
470 //create points
471 points->push_back(Amg::Vector3D(x-track.x(), y-track.y(), z-track.z()));
472 points->push_back(Amg::Vector3D(x,y,z));
473
474 SoSwitch* trackSwitch = new SoSwitch();
475 root->addChild(trackSwitch);
476 trackSwitch->whichChild = m_showNeutral ? SO_SWITCH_ALL : SO_SWITCH_NONE;
477 drawPoints(trackSwitch, points, color, 2, true);
478 m_neutralSwitches.push_back(trackSwitch);
479
480 //cleaning up
481 messageDebug("leaving drawNeutralTrack");
482 delete points;
483
484}
485
486//___________________________________________________________
487void VP1BPhysSystem::drawRefittedTrack(SoSeparator* root, double x, double y, double z,
488 double px, double py, double pz, double charge, unsigned long color)
489{
490 messageDebug("in drawRefittedTrack");
491
492 Amg::Vector3D mom(px,py,pz);
493 Amg::Vector3D pos(x,y,z);
494
495 const Trk::Track* track = getRefittedTrack(pos,mom,charge);
496
497 //getting track space-points
498 std::vector<Amg::Vector3D >* points = getPoints(track);
499
500 //drawing
501 SoSwitch* trackSwitch = new SoSwitch();
502 root->addChild(trackSwitch);
503 trackSwitch->whichChild = m_showRefitted ? SO_SWITCH_ALL : SO_SWITCH_NONE;
504 drawPoints(trackSwitch,points,color,2,false);
505 m_refittedSwitches.push_back(trackSwitch);
506
507 //cleaning up
508 delete points;
509 delete track;
510
511 messageDebug("leaving drawCutoffTrackParticle");
512
513}
514//___________________________________________________________
515void VP1BPhysSystem::drawPoints(SoSwitch* trackSwitch, std::vector<Amg::Vector3D >* points,
516 unsigned long color, double width, bool isNeutral)
517{
518 messageDebug("in drawPoints");
519 if(points == nullptr) return;
520
521 SoSeparator* sep = new SoSeparator();
522
523 //setting up draw style
524 SoDrawStyle* drawStyle = new SoDrawStyle();
525 drawStyle->lineWidth = width;
526 if(isNeutral) {
527 drawStyle->linePattern = 0x00ff;
528 }
529 sep->addChild(drawStyle);
530
531 //setting up color
532 SoBaseColor* baseColor = new SoBaseColor();
533 double r,g,b;
534 getColor(color,r,g,b);
535 baseColor->rgb.setValue(r,g,b);
536 sep->addChild(baseColor);
537
538 int iver(0);
539 SoVertexProperty *vertices = new SoVertexProperty();
540
541 std::vector<Amg::Vector3D >::iterator it, itE = points->end();
542 for(it = points->begin(); it != itE; ++it) {
543 vertices->vertex.set1Value(iver++,(*it).x(),(*it).y(),(*it).z());
544 }
545
546 //Create a set of lines from these vertices:
547 SoLineSet * line = new SoLineSet();
548 line->numVertices = iver;
549 line->vertexProperty = vertices;
550
551 //Add to the tree:
552 sep->addChild(line);
553
554 //add to the root
555 trackSwitch->addChild(sep);
556
557 //To avoid GUI freeze-ups:
558 updateGUI();
559
560 messageDebug("leaving drawPoints");
561
562}
563//___________________________________________________________
564
565std::vector<Amg::Vector3D >* VP1BPhysSystem::getPoints(const Trk::Track* track) {
566
567 messageDebug("in getPoints(Trk::Track)");
568
569 //retrieve/create VP1Extrapolator
570
571 messageDebug("Retrieving propagator...");
572 Trk::IExtrapolator* propagator = nullptr;
573 VP1ToolAccessHelper toolaccess(this);
574 propagator = toolaccess.getToolPointer<Trk::IExtrapolator>("Trk::Extrapolator/VP1Extrapolator",false/*silent*/,true/*create if not exists*/);
575 if(propagator == nullptr) {
576 message("Error: propagator Trk::Extrapolator/VP1Extrapolator couldn't be created");
577 }
578 messageDebug("...done");
579
580 messageDebug("Creating propagationHelper...");
581 TrackPropagationHelper* propagationHelper = new TrackPropagationHelper(this);
582 messageDebug("...done");
583
584 std::vector< Amg::Vector3D >* points = new std::vector<Amg::Vector3D >();
585
586// propagator = NULL;
587 //propagate track in magnetic field
588 if(propagator!=nullptr && propagationHelper!=nullptr) {
589 messageDebug("Starting propagator...");
590 propagationHelper->makePointsCharged(*points,track,propagator);
591 messageDebug("..done");
592 } else {
593 //if no propagator is initialized we use straight segments instead
594
595 const DataVector<const Trk::TrackParameters> *params = track->trackParameters();
596 //Just a sanity check:
597 if ( !params ) {
598 message("Error: no track parameters");
599 }else{
601 for (it = params->begin();it!=itE;++it) {
602 points->push_back(Amg::Vector3D((*it)->position().x(),(*it)->position().y(),(*it)->position().z()));
603 }
604 }
605 }
606
607 //cleaning up
608 delete propagationHelper;
609
610 //return
611 messageDebug("leaving getPoints(Trk::Track)");
612 return points;
613
614}
615//___________________________________________________________
616std::vector<Amg::Vector3D >* VP1BPhysSystem::getPoints(const Rec::TrackParticle* part) {
617 messageDebug("in getPoints(Rec::TrackParticle)");
618
619 //creating Trk::Track from TrackParticle
620 const Trk::Track *track = getTrack(part);
621
622 std::vector<Amg::Vector3D >* points = getPoints(track);
623
624 //cleaning up
625 delete track;
626
627 //return
628 messageDebug("leaving getPoints(Rec::TrackParticle)");
629 return points;
630}
631//___________________________________________________________
632std::vector<Amg::Vector3D >* VP1BPhysSystem::findClosestApproach(std::vector<Amg::Vector3D >* points, double x, double y, double z) {
633 messageDebug("in findClosestApproach");
634
635 std::vector<Amg::Vector3D >* pointsOut = new std::vector<Amg::Vector3D >();
636
637 //check # of points
638 if(points->size()<2) return pointsOut;
639
640 double lastDist = 1e10;
641 Amg::Vector3D point = points->at(0);
642 std::vector<Amg::Vector3D >::iterator startFrom = (points->begin())+1;
643
644 //find the closest approach
645 std::vector<Amg::Vector3D >::iterator it, itE = points->end();
646 for(it = points->begin(); (it+1) != itE; ++it) {
647 CLHEP::Hep3Vector p = CLHEP::Hep3Vector((*(it+1)).x()-(*it).x(), (*(it+1)).y()-(*it).y(), (*(it+1)).z()-(*it).z());
648 CLHEP::Hep3Vector v = CLHEP::Hep3Vector(x - (*it).x(), y - (*it).y(), z - (*it).z());
649
650 //projection of v into the direction of p
651 double proj = v.dot(p.unit());
652 CLHEP::Hep3Vector vect = p.unit();
653 vect *= proj;
654
655 //check that projection lies inside the track segment
656 if(proj<0 || proj > p.mag()) continue;
657
658 //check distance to the segment (Pythagorean theroem)
659 double dist = sqrt(p.mag2() - proj*proj);
660 if(dist<lastDist) {
661 lastDist = dist;
662 point = Amg::Vector3D((*it).x() + vect.x(), (*it).y() + vect.y(), (*it).z() + vect.z());
663 startFrom = it+1;
664 }
665 }
666
667 //create new cut-off track
668 pointsOut->push_back(point);
669 for(it = startFrom; it!=itE; ++it) {
670 pointsOut->push_back(*it);
671 }
672
673 messageDebug("leaving findClosestApproach");
674 return pointsOut;
675
676}
677//___________________________________________________________
678
679void VP1BPhysSystem::drawVertex(SoSeparator *root, double x, double y, double z, double /*radius*/,
680 double xx, double xy, double xz, double yy, double yz, double zz, unsigned long color,
681 std::vector<SoSwitch*>& vertexSwitches)
682{
683 messageDebug("in drawVertex");
684
685 SoSeparator* sep = new SoSeparator();
686
687 //move sphere to position
688 SoTranslation * translation = new SoTranslation;
689 translation->translation.setValue ( x, y, z );
690 sep->addChild ( translation );
691
692 //color
693 SoBaseColor* baseColor = new SoBaseColor();
694 double rr,gg,bb;
695 getColor(color,rr,gg,bb);
696 baseColor->rgb.setValue(rr,gg,bb);
697 sep->addChild(baseColor);
698
699 //switch
700 SoSwitch* vtxSwitch = new SoSwitch();
701 if(!m_showVertices)
702 vtxSwitch->whichChild = SO_SWITCH_NONE;
703 else
704 vtxSwitch->whichChild = m_vertexStyle;
705
706 sep->addChild(vtxSwitch);
707
709 SoSphere * sphere = new SoSphere;
710 sphere->radius = 2*CLHEP::mm;
711 vtxSwitch->addChild ( sphere );
712
714 SoLineSet* cross = createCross(3*CLHEP::mm);
715 vtxSwitch->addChild ( cross );
716
718 SoSeparator* sepEllipsoid = new SoSeparator();
719 vtxSwitch->addChild ( sepEllipsoid );
720
721 //transorm sphere to elipsoid
722 double a=xx*CLHEP::mm;
723 double b=xy*CLHEP::mm;
724 double c=xz*CLHEP::mm;
725 double d=yy*CLHEP::mm;
726 double e=yz*CLHEP::mm;
727 double f=zz*CLHEP::mm;
728
729 double det = a*(d*f-e*e) + 2*b*c*e - d*c*c-f*b*b;
730 if (det>0) {
731 double sixthrootofdet = exp(log(det)/6.0);
732 double invdet = 1.0/sixthrootofdet;
733 a *= invdet;
734 b *= invdet;
735 c *= invdet;
736 d *= invdet;
737 e *= invdet;
738 f *= invdet;
739 SbMatrix sbMat(a,b,c,0,
740 b,d,e,0,
741 c,e,f,0,
742 0,0,0,1);
743 SoMatrixTransform * matTrans = new SoMatrixTransform();
744 matTrans->matrix.setValue(sbMat);
745 sepEllipsoid->addChild (matTrans);
746 } else {
747 //FIXME: warn
748 }
749 SoSphere * ellipsoid = new SoSphere;
750 ellipsoid->radius = 3;
751 sepEllipsoid->addChild ( sphere );
752
753
754
755 //vertexSwitches
756 vertexSwitches.push_back(vtxSwitch);
757
758 //add to root
759 root->addChild(sep);
760
761 //To avoid GUI freeze-ups:
762 updateGUI();
763
764 messageDebug("leaving drawVertex");
765
766}
767
768//___________________________________________________________
771
772 messageDebug("in loadFile");
773
774 QString fileName = QFileDialog::getOpenFileName(nullptr, tr("Open File"),tr("."),tr("ROOT files (*.root)"));
775 if(fileName.isEmpty()) return;
776
777 m_c->ui.leFileName->setText(fileName);
778 m_fileName = fileName;
779
780
781 //close previous file
782 if(m_rootFile!=nullptr) {
783 m_rootFile->Close();
784
785 if(m_br!=nullptr) {
786 delete m_br;
787 m_br = nullptr;
788 }
789
790 m_rootFile = nullptr;
791 m_tree = nullptr;
792 }
793
794 //try to open a new file
795 m_rootFile = TFile::Open(m_fileName.toStdString().c_str());
796 if(m_rootFile!=nullptr && !m_rootFile->IsZombie()) {
797 m_tree = (TTree*)m_rootFile->Get("vp1bphys");
798 if(m_tree!=nullptr) {
799 m_tree->BuildIndex("runNum","evtNum");
800 m_br = new Br();
801 m_br->init(m_tree);
802 m_c->ui.lStatus->setText("");
803 }else{
804 m_c->ui.lStatus->setText("File doesn't contain vp1bphys tree");
805 message("File doesn't contain vp1bphys tree");
806 }
807 }else{
808 m_c->ui.lStatus->setText("File doesn't exist");
809 message("File doesn't exist");
810 m_tree = nullptr;
811 }
812
813 if(m_sg!=nullptr && m_root!=nullptr) actualBuild();
814 updateGUI();
815
816 messageDebug("leaving loadFile");
817}
818//___________________________________________________________
820
821 SoSFInt32 which;
822
823 if(state==Qt::Unchecked) {
824 m_showVertices = false;
825 which = SO_SWITCH_NONE;
826 }else{
827 m_showVertices = true;
828 which = m_vertexStyle;
829 }
830
831 //apply
832 std::vector<SoSwitch*>::iterator it=m_vertexSwitches.begin();
833 for(; it!=m_vertexSwitches.end(); ++it) {
834 (*it)->whichChild = which;
835 }
836
837}
838//___________________________________________________________
839void VP1BPhysSystem::sphereToggled ( bool checked ) {
840
841
842 if(checked) {
843 messageDebug("show vertices as spheres");
845 }
846
847 //apply
848 if(m_showVertices) {
849 std::vector<SoSwitch*>::iterator it=m_vertexSwitches.begin();
850 for(; it!=m_vertexSwitches.end(); ++it) {
851 (*it)->whichChild = m_vertexStyle;
852 }
853 }
854}
855//___________________________________________________________
856void VP1BPhysSystem::crossToggled ( bool checked ) {
857 if(checked) {
858 messageDebug("show vertices as crosses");
860 }
861
862 //apply
863 if(m_showVertices) {
864 std::vector<SoSwitch*>::iterator it=m_vertexSwitches.begin();
865 for(; it!=m_vertexSwitches.end(); ++it) {
866 (*it)->whichChild = m_vertexStyle;
867 }
868 }
869
870}
871//___________________________________________________________
872void VP1BPhysSystem::ellipsoidToggled ( bool checked ) {
873 if(checked) {
874 messageDebug("show vertices as error ellipsoids");
876 }
877
878 //apply
879 if(m_showVertices) {
880 std::vector<SoSwitch*>::iterator it=m_vertexSwitches.begin();
881 for(; it!=m_vertexSwitches.end(); ++it) {
882 (*it)->whichChild = m_vertexStyle;
883 }
884 }
885
886}
887//___________________________________________________________
889 if(state==Qt::Unchecked)
890 m_showAll = false;
891 else
892 m_showAll = true;
893
894 //loop over all tracks
895 std::vector<SoSwitch*>::iterator it=m_trackSwitches.begin();
896 for(; it!=m_trackSwitches.end(); ++it) {
897 (*it)->whichChild = m_showAll ? SO_SWITCH_ALL : SO_SWITCH_NONE;
898 }
899
900 //loop over overlap
901 it=m_overlapSwitches.begin();
902 for(; it!=m_overlapSwitches.end(); ++it) {
903 (*it)->whichChild = m_showAll && !m_showSignal && !m_showRefitted ? SO_SWITCH_ALL : SO_SWITCH_NONE;
904 }
905}
906//___________________________________________________________
908 if(state==Qt::Unchecked)
909 m_showSignal = false;
910 else
911 m_showSignal = true;
912
913 //loop over original signal tracks
914 std::vector<SoSwitch*>::iterator it=m_signalSwitches.begin();
915 for(; it!=m_signalSwitches.end(); ++it) {
916 (*it)->whichChild = m_showSignal ? SO_SWITCH_ALL : SO_SWITCH_NONE;
917 }
918
919 //loop over overlap
920 it=m_overlapSwitches.begin();
921 for(; it!=m_overlapSwitches.end(); ++it) {
922 (*it)->whichChild = m_showAll && !m_showSignal && !m_showRefitted ? SO_SWITCH_ALL : SO_SWITCH_NONE;
923 }
924}
925//___________________________________________________________
927 if(state==Qt::Unchecked)
928 m_showRefitted = false;
929 else
930 m_showRefitted = true;
931
932 //loop over refitted signal tracks
933 std::vector<SoSwitch*>::iterator it=m_refittedSwitches.begin();
934 for(; it!=m_refittedSwitches.end(); ++it) {
935 (*it)->whichChild = m_showRefitted ? SO_SWITCH_ALL : SO_SWITCH_NONE;
936 }
937 //loop over overlap
938 it=m_overlapSwitches.begin();
939 for(; it!=m_overlapSwitches.end(); ++it) {
940 (*it)->whichChild = m_showAll && !m_showSignal && !m_showRefitted ? SO_SWITCH_ALL : SO_SWITCH_NONE;
941 }
942
943}
944//___________________________________________________________
946 if(state==Qt::Unchecked)
947 m_showNeutral = false;
948 else
949 m_showNeutral = true;
950
951 //loop over neutral tracks
952 std::vector<SoSwitch*>::iterator it=m_neutralSwitches.begin();
953 for(; it!=m_neutralSwitches.end(); ++it) {
954 (*it)->whichChild = m_showNeutral ? SO_SWITCH_ALL : SO_SWITCH_NONE;
955 }
956}
957//___________________________________________________________
958
961 messageDebug("in getTrack");
962
963 messageDebug("Retrieving track parameters...");
964
966 std::vector< const Trk::TrackParameters* > trackpars;
967 trackpars = trackparticle->trackParameters();
968
969 auto trackStateOnSurfaces = std::make_unique<Trk::TrackStates>();
970 messageDebug("...done");
971
972 if (!trackpars.empty()) {
973 bool needresorting = trackpars.at(0)!=trackparticle->perigee();//Needed since TrackParticles are (at the moment)
974 //created with the first parameter put last
975 messageDebug("resorting...");
976 if (needresorting) {
977 messageDebug("dynamic cast");
978
979 //const Trk::ParametersT<Trk::Charged>* p = dynamic_cast<const Trk::ParametersT<Trk::Charged>* >(trackpars.at(trackpars.size()-1));
980 const Trk::TrackParameters* p = dynamic_cast<const Trk::TrackParameters* >(trackpars.at(trackpars.size()-1));
981
982 messageDebug("new TrackStateOnSurface");
983
984 if (p) trackStateOnSurfaces->push_back(new Trk::TrackStateOnSurface(nullptr,p->uniqueClone(),nullptr));
985 }
986 unsigned limit(needresorting?trackpars.size()-1:trackpars.size());
987 messageDebug("...done");
988
989 //NB: We only ever created this handle if charge()!=0.0:
990 messageDebug("Filling the vector...");
991 for (unsigned i = 0; i < limit; ++i) {
992// const Trk::ParametersT<Trk::Charged>* p = dynamic_cast<const Trk::ParametersT<Trk::Charged>* >(trackpars.at(i));
993 const Trk::TrackParameters* p = dynamic_cast<const Trk::TrackParameters* >(trackpars.at(i));
994 if (!p)
995 continue;
996/* if (!common()->trackSanityHelper()->isSafe(p))
997 continue;*/
998 trackStateOnSurfaces->push_back(new Trk::TrackStateOnSurface(nullptr,p->uniqueClone(),nullptr));
999 }
1000 messageDebug("...done");
1001
1002 }
1003
1004 messageDebug("Creating the track...");
1005
1006#ifdef TRKTRACK_TRACKINFO_H
1008 const Trk::Track * trk = new Trk::Track(ti,std::move(trackStateOnSurfaces)/*track assumes ownership*/,nullptr/*fitquality*/);
1009#else
1010 const Trk::Track * trk = new Trk::Track(Trk::Track::unknown, std::move(trackStateOnSurfaces)/*track assumes ownership*/,
1011 0/*fitquality*/,Trk::pion);
1012#endif
1013
1014 messageDebug("...done");
1015
1016 messageDebug("leaving getTrack");
1017 return trk;
1018
1019}
1020//___________________________________________________________
1021const Trk::Track* VP1BPhysSystem::getRefittedTrack(const Amg::Vector3D& position, const Amg::Vector3D& momentum, double charge) {
1022
1023
1024 const Amg::Vector3D& pos(std::move(position));
1025 const Amg::Vector3D& mom(std::move(momentum));
1026
1027 // init the error matrix
1028 AmgSymMatrix(5) covMtxP;
1029 covMtxP.setIdentity();
1030
1031 AmgSymMatrix(5) errMatr = covMtxP;
1032 Trk::Perigee * measuredPerigee = new Trk::Perigee( pos, mom, charge, pos, std::move(errMatr) );
1033
1034 //creates parameter base for the new track
1035 const Trk::TrackParameters* p = dynamic_cast<const Trk::TrackParameters* >(measuredPerigee);
1036
1037 //TODO: check parameters safety
1038
1039 //creates a vector of TracksStates on surface
1040 auto trackStateOnSurfaces = std::make_unique<Trk::TrackStates>();
1041 trackStateOnSurfaces->push_back(new Trk::TrackStateOnSurface(nullptr,p->uniqueClone(),nullptr));
1042
1043 //create track
1044#ifdef TRKTRACK_TRACKINFO_H
1046 const Trk::Track * trk = new Trk::Track(ti,std::move(trackStateOnSurfaces)/*track assumes ownership*/,nullptr/*fitquality*/);
1047#else
1048 const Trk::Track * trk = new Trk::Track(Trk::Track::unknown, std::move(trackStateOnSurfaces)/*track assumes ownership*/,
1049 0/*fitquality*/,Trk::pion);
1050#endif
1051
1052 return trk;
1053
1054
1055}
1056
1057//___________________________________________________________
1058
1059void VP1BPhysSystem::getColor(unsigned long icolor, double& r, double& g, double& b) {
1060 messageDebug("in getColor");
1061
1062 unsigned long red = icolor/65536;
1063 icolor -= red*65536;
1064
1065 unsigned long green = icolor/256;
1066 icolor -= green*256;
1067
1068 unsigned long blue = icolor;
1069
1070 r=red/255.;
1071 g=green/255.;
1072 b=blue/255.;
1073
1074 messageDebug("leaving getColor");
1075
1076}
1077//___________________________________________________________
1078SoLineSet* VP1BPhysSystem::createCross(double extent ) {
1079 messageDebug("in createCross");
1080
1081 SoVertexProperty *vertices = new SoVertexProperty();
1082 vertices->vertex.set1Value ( 0,-extent, 0 , 0 );
1083 vertices->vertex.set1Value ( 1, extent, 0 , 0 );
1084 vertices->vertex.set1Value ( 2, 0 ,-extent , 0 );
1085 vertices->vertex.set1Value ( 3, 0 , extent , 0 );
1086 vertices->vertex.set1Value ( 4, 0 , 0 ,-extent );
1087 vertices->vertex.set1Value ( 5, 0 , 0 , extent );
1088 SoLineSet * line = new SoLineSet();
1089 line->numVertices.set1Value(0,2);
1090 line->numVertices.set1Value(1,2);
1091 line->numVertices.set1Value(2,2);
1092 line->vertexProperty = vertices;
1093
1094 messageDebug("leving createCross");
1095 return line;
1096}
1097
const boost::regex rr(r_r)
Scalar eta() const
pseudorapidity method
double charge(const T &p)
Definition AtlasPID.h:997
bool isNeutral(const T &p)
Definition AtlasPID.h:1085
#define AmgSymMatrix(dim)
double length(const pvec &v)
unsigned int uint
static Double_t a
const double width
#define y
#define x
#define z
const unsigned int darknes
const unsigned long darkGray
std::vector< double > * neutral_refitted_px
std::vector< double > * track_refitted_pz
std::vector< double > * neutral_refitted_pz
double vtx_xy
double vtx_x
std::vector< unsigned long > * neutral_color
double vtx_xz
TTree * vp1Filter
double vtx_z
int vtx_mother
std::vector< int > * vtx_daughters
double vtx_xx
std::vector< double > * track_d0
unsigned long vtx_color
std::vector< double > * track_phi
double vtx_y
std::vector< double > * track_pt
std::vector< double > * track_refitted_px
std::vector< double > * neutral_refitted_py
std::vector< double > * track_refitted_py
int runNum
std::vector< double > * track_charge
std::vector< double > * neutral_length
int evtNum
std::vector< double > * track_eta
double vtx_yz
std::vector< double > * track_z0
std::vector< unsigned long > * track_refitted_color
int GetEntry(int i)
bool init(TTree *tree)
std::vector< int > * neutral_decay
std::vector< unsigned long > * track_color
double vtx_zz
double vtx_yy
Derived DataVector<T>.
Definition DataVector.h:795
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
IVP13DSystemSimple(const QString &name, const QString &information, const QString &contact_info)
void messageDebug(const QString &) const
State state() const
void message(const QString &) const
The Athena Transient Store API.
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
bool makePointsCharged(std::vector< Amg::Vector3D > &points, const Trk::Track *, Trk::IExtrapolator *extrapolator, Trk::ParticleHypothesis hypo=Trk::nonInteracting, bool useMEOT=false, const Trk::Volume *volume=0)
Interface class for the extrapolation AlgTool, it inherits from IAlgTool Detailed information about p...
Contains information about the 'fitter' of this track.
const Perigee * perigee() const
Attempts to cast the definingParameters() to Perigee.
const std::vector< const TrackParameters * > & trackParameters() const
Returns the track parameters.
represents the track state (measurement, material, fit parameters and quality) at a surface.
Ui::BPhysControllerForm ui
void drawTrackParticle(SoSwitch *trackSwitch, const Rec::TrackParticle *part, unsigned long color)
SoSeparator * m_root
void buildEventSceneGraph(StoreGateSvc *sg, SoSeparator *root)
const Trk::Track * getTrack(const Rec::TrackParticle *trackparticle)
utils *****************************************************************************
void displayNeutralChanged(int state)
void ellipsoidToggled(bool checked)
const Trk::Track * getRefittedTrack(const Amg::Vector3D &pos, const Amg::Vector3D &mom, double charge)
void displayOrigSignalChanged(int state)
std::vector< SoSwitch * > m_refittedSwitches
std::vector< SoSwitch * > m_overlapSwitches
StoreGateSvc * m_sg
void drawAllTrackParticles(StoreGateSvc *sg, SoSeparator *root, std::vector< const Rec::TrackParticle * > *selectedParticles)
SoLineSet * createCross(double extent)
std::vector< SoSwitch * > m_neutralSwitches
std::vector< Amg::Vector3D > * findClosestApproach(std::vector< Amg::Vector3D > *points, double x, double y, double z)
void displayVerticesChanged(int state)
void crossToggled(bool checked)
void loadFile()
slots *****************************************************************************
void drawVertex(SoSeparator *root, double x, double y, double z, double radius, double xx, double xy, double xz, double yy, double yz, double zz, unsigned long color, std::vector< SoSwitch * > &vertexSwitches)
std::vector< Amg::Vector3D > * getPoints(const Trk::Track *track)
Clockwork * m_c
std::vector< SoSwitch * > m_signalSwitches
void drawRefittedTrack(SoSeparator *root, double x, double y, double z, double px, double py, double pz, double charge, unsigned long color)
void drawNeutralTrack(SoSeparator *root, double x, double y, double z, double px, double py, double pz, double length, unsigned long color)
std::vector< SoSwitch * > m_trackSwitches
void filterTrack(SoSeparator *root, const Rec::TrackParticleContainer *partCont, double pt, double eta, double phi, double d0, double z0, double x, double y, double z, unsigned long color, std::vector< const Rec::TrackParticle * > *selectedParticles)
drawing methods *******************************************************************
QWidget * buildController()
void sphereToggled(bool checked)
void getColor(unsigned long icolor, double &r, double &g, double &b)
std::vector< SoSwitch * > m_vertexSwitches
void displayRefTracksChanged(int state)
void displayAllTracksChanged(int state)
void drawCutoffTrackParticle(SoSeparator *root, const Rec::TrackParticle *part, double x, double y, double z, unsigned long color)
void drawPoints(SoSwitch *trackSwitch, std::vector< Amg::Vector3D > *points, unsigned long color, double width, bool isNeutral)
toolT * getToolPointer(const QString &toolname, bool silent=false, bool createIfNotExists=false)
int r
Definition globals.cxx:22
Eigen::Matrix< double, 3, 1 > Vector3D
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
@ theta
Definition ParamDefs.h:66
@ qOverP
perigee
Definition ParamDefs.h:67
ParametersBase< TrackParametersDim, Charged > TrackParameters
TChain * tree