4 #include "MCHelixLine.hi"
7 #include <TPolyLine3D.h>
9 #include <TPolyMarker3D.h>
13 #include <Reve/ReveManager.h>
14 #include <Reve/RGBrowser.h>
15 #include <Reve/NLTTrack.h>
25 //______________________________________________________________________________
28 // Visual representation of a track.
33 //______________________________________________________________________________
48 // Default constructor.
51 //______________________________________________________________________________
52 Track::Track(TParticle* t, Int_t label, TrackRnrStyle* rs):
55 fV(t->Vx(), t->Vy(), t->Vz()),
56 fP(t->Px(), t->Py(), t->Pz()),
57 fBeta(t->P()/t->Energy()),
66 // Constructor from TParticle.
69 fMainColorPtr = &fLineColor;
71 TParticlePDG* pdgp = t->GetPDG();
73 fPdg = pdgp->PdgCode();
74 fCharge = (Int_t) TMath::Nint(pdgp->Charge()/3);
77 SetName(t->GetName());
80 //______________________________________________________________________________
81 Track::Track(Reve::MCTrack* t, TrackRnrStyle* rs):
84 fV(t->Vx(), t->Vy(), t->Vz()),
85 fP(t->Px(), t->Py(), t->Pz()),
86 fBeta(t->P()/t->Energy()),
95 // Constructor from Reve Monte Carlo track.
98 fMainColorPtr = &fLineColor;
100 TParticlePDG* pdgp = t->GetPDG();
102 t->ResetPdgCode(); pdgp = t->GetPDG();
104 fCharge = (Int_t) TMath::Nint(pdgp->Charge()/3);
106 SetName(t->GetName());
109 //______________________________________________________________________________
110 Track::Track(Reve::RecTrack* t, TrackRnrStyle* rs) :
124 // Constructor from Reve reconstructed track.
127 fMainColorPtr = &fLineColor;
129 SetName(t->GetName());
132 //______________________________________________________________________________
133 Track::Track(const Track& t) :
147 SetMainColor(t.GetMainColor());
149 fRnrLine = t.fRnrLine;
150 fRnrPoints = t.fRnrPoints;
152 fLineColor = t.fLineColor;
153 fLineStyle = t.fLineStyle;
154 fLineWidth = t.fLineWidth;
156 SetRnrStyle (t.fRnrStyle);
159 //______________________________________________________________________________
165 for (vpPathMark_i i=fPathMarks.begin(); i!=fPathMarks.end(); ++i)
169 /******************************************************************************/
171 //______________________________________________________________________________
172 void Track::SetStdTitle()
174 // Set standard track title based on most data-member values.
176 TString idx(fIndex == kMinInt ? "<undef>" : Form("%d", fIndex));
177 TString lbl(fLabel == kMinInt ? "<undef>" : Form("%d", fLabel));
178 SetTitle(Form("Index=%s, Label=%s\nChg=%d, Pdg=%d\n"
179 "pT=%.3f, pZ=%.3f\nV=(%.3f, %.3f, %.3f)",
180 idx.Data(), lbl.Data(), fCharge, fPdg,
181 fP.Perp(), fP.z, fV.x, fV.y, fV.z));
184 //______________________________________________________________________________
185 void Track::SetTrackParams(const Track& t)
187 // Copy track parameters from t.
188 // PathMarks are cleared.
198 SetMainColor(t.GetMainColor());
200 fRnrLine = t.fRnrLine;
201 fRnrPoints = t.fRnrPoints;
203 fLineColor = t.fLineColor;
204 fLineStyle = t.fLineStyle;
205 fLineWidth = t.fLineWidth;
207 SetRnrStyle(t.fRnrStyle);
210 //______________________________________________________________________________
211 void Track::SetPathMarks(const Track& t)
213 // Copy path-marks from t.
215 const std::vector<PathMark*>& refs = t.GetPathMarksRef();
216 for(std::vector<PathMark*>::const_iterator i=refs.begin(); i!=refs.end(); ++i)
218 fPathMarks.push_back(new PathMark(**i));
222 /******************************************************************************/
224 //______________________________________________________________________________
225 void Track::SetRnrStyle(TrackRnrStyle* rs)
227 // Set track's render style.
228 // Reference counts of old and new render-style are updated.
230 if (fRnrStyle == rs) return;
231 if (fRnrStyle) fRnrStyle->DecRefCount(this);
233 if (fRnrStyle) rs->IncRefCount(this);
236 /******************************************************************************/
238 //______________________________________________________________________________
239 void Track::SetAttLineAttMarker(TrackList* tl)
241 // Set line and marker attributes from TrackList.
243 SetLineColor(tl->GetLineColor());
244 SetLineStyle(tl->GetLineStyle());
245 SetLineWidth(tl->GetLineWidth());
247 SetMarkerColor(tl->GetMarkerColor());
248 SetMarkerStyle(tl->GetMarkerStyle());
249 SetMarkerSize(tl->GetMarkerSize());
252 /******************************************************************************/
254 //______________________________________________________________________________
255 void Track::MakeTrack(Bool_t recurse)
257 // Calculate track representation based on track data and current
258 // settings of the render-style.
259 // If recurse is true, descend into children.
261 TrackRnrStyle& RS((fRnrStyle != 0) ? *fRnrStyle : TrackRnrStyle::fgDefStyle);
263 Float_t px = fP.x, py = fP.y, pz = fP.z;
271 std::vector<MCVertex> track_points;
272 Bool_t decay = kFALSE;
274 if ((TMath::Abs(fV.z) > RS.fMaxZ) || (fV.x*fV.x + fV.y*fV.y > RS.fMaxR*RS.fMaxR))
277 if (fCharge != 0 && TMath::Abs(RS.fMagField) > 1e-5 && fP.Perp2() > 1e-12)
279 // Charged particle in magnetic field with non-zero pT.
281 Float_t a = RS.fgkB2C * RS.fMagField * fCharge;
283 MCHelix helix(fRnrStyle, &mc_v0, TMath::C()*fBeta, &track_points, a); //m->cm
284 helix.Init(TMath::Sqrt(px*px+py*py), pz);
285 // Set max number of points for loop-to-vertex.
286 // loop-to-bounds (last step) does this separately.
289 if (!fPathMarks.empty())
291 for(std::vector<Reve::PathMark*>::iterator i=fPathMarks.begin(); i!=fPathMarks.end(); ++i)
293 Reve::PathMark* pm = *i;
295 if (RS.fFitReferences && pm->type == Reve::PathMark::Reference)
297 if(TMath::Abs(pm->V.z) > RS.fMaxZ ||
298 TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR)
301 // printf("%s fit reference \n", fName.Data());
302 helix.LoopToVertex(px, py, pz, pm->V.x, pm->V.y, pm->V.z);
307 else if(RS.fFitDaughters && pm->type == Reve::PathMark::Daughter)
309 if(TMath::Abs(pm->V.z) > RS.fMaxZ ||
310 TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR)
313 // printf("%s fit daughter \n", fName.Data());
314 helix.LoopToVertex(px, py, pz, pm->V.x, pm->V.y, pm->V.z);
319 else if(RS.fFitDecay && pm->type == Reve::PathMark::Decay)
321 if(TMath::Abs(pm->V.z) > RS.fMaxZ ||
322 TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR)
324 helix.LoopToVertex(px, py, pz, pm->V.x, pm->V.y, pm->V.z);
328 if (track_points.size() > 4096)
330 Warning("Track::MakeTrack", "exceeding 4k points (%u) for '%s'; aborting extrapolation.",
331 track_points.size(), GetName());
338 if(!decay || RS.fFitDecay == kFALSE)
340 helix.LoopToBounds(px,py,pz);
341 // printf("%s loop to bounds \n",fName.Data() );
346 // Neutral particle or no field
348 MCLine line(fRnrStyle, &mc_v0, TMath::C()*fBeta, &track_points);
350 if(!fPathMarks.empty())
352 for(std::vector<Reve::PathMark*>::iterator i=fPathMarks.begin(); i!=fPathMarks.end(); ++i)
354 Reve::PathMark* pm = *i;
356 if(RS.fFitDaughters && pm->type == Reve::PathMark::Daughter)
358 if(TMath::Abs(pm->V.z) > RS.fMaxZ ||
359 TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR)
363 line.GotoVertex(pm->V.x, pm->V.y, pm->V.z);
369 if(RS.fFitDecay && pm->type == Reve::PathMark::Decay)
371 if(TMath::Abs(pm->V.z) > RS.fMaxZ ||
372 TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR)
376 line.GotoVertex(pm->V.x, pm->V.y, pm->V.z);
384 if(!decay || RS.fFitDecay == kFALSE)
385 line.GotoBounds(px,py,pz);
390 Int_t size = TMath::Min(4096, (Int_t) track_points.size());
391 // printf("track '%s' N = %u\n", GetName(), track_points.size());
393 for(Int_t i=0; i<size; ++i)
395 const MCVertex& v = track_points[i];
396 SetNextPoint(v.x, v.y, v.z);
402 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
404 Track* t = dynamic_cast<Track*>(*i);
405 if(t) t->MakeTrack(recurse);
410 /******************************************************************************/
412 //______________________________________________________________________________
413 TClass* Track::ProjectedClass() const
415 // Virtual from NLTProjectable, return NLTTrack class.
417 return NLTTrack::Class();
420 /******************************************************************************/
426 bool operator()(PathMark* const & a, PathMark* const & b)
427 { return a->time < b->time; }
432 //______________________________________________________________________________
433 void Track::SortPathMarksByTime()
435 // Sort registerd pat-marks by time.
437 std::sort(fPathMarks.begin(), fPathMarks.end(), cmp_pathmark());
440 /******************************************************************************/
442 //______________________________________________________________________________
443 void Track::ImportHits()
445 // Import hits with same label as the track.
446 // Uses macro "hits_from_label.C".
448 Reve::LoadMacro("hits_from_label.C");
449 gROOT->ProcessLine(Form("hits_from_label(%d, (Reve::RenderElement*)%p);",
453 //______________________________________________________________________________
454 void Track::ImportClusters()
456 // Import clusters with same label as the track.
457 // Uses macro "clusters_from_label.C".
459 Reve::LoadMacro("clusters_from_label.C");
460 gROOT->ProcessLine(Form("clusters_from_label(%d, (Reve::RenderElement*)%p);",
464 //______________________________________________________________________________
465 void Track::ImportClustersFromIndex()
467 // Import clusters marked with same reconstructed track index as the track.
468 // Uses macro "clusters_from_index.C".
470 static const Exc_t eH("Track::ImportClustersFromIndex ");
472 if (fIndex == kMinInt)
473 throw(eH + "index not set.");
475 Reve::LoadMacro("clusters_from_index.C");
476 gROOT->ProcessLine(Form("clusters_from_index(%d, (Reve::RenderElement*)%p);",
480 /******************************************************************************/
482 //______________________________________________________________________________
483 void Track::ImportKine()
485 // Import kinematics of the track's label recursively.
486 // Uses macro "kine_tracks.C".
488 static const Exc_t eH("Track::ImportKine ");
490 if (fLabel == kMinInt)
491 throw(eH + "label not set.");
495 Warning(eH, "label negative, taking absolute value.");
501 Reve::LoadMacro("kine_tracks.C");
502 gROOT->ProcessLine(Form("kine_track(%d, kTRUE, kTRUE, kTRUE, kTRUE, (Reve::RenderElement*)%p);",
507 //______________________________________________________________________________
508 void Track::ImportKineWithArgs(Bool_t importMother, Bool_t importDaugters,
509 Bool_t colorPdg, Bool_t recurse)
511 // Import kinematics of the track's label. Arguments steer the
513 // importMother import particle with track's label
514 // importDaugters import direct daughters of label
515 // colorPdg color kinematics by PDG code
516 // recurse recursive import of daughters' daughters
517 // Uses macro "kine_tracks.C".
519 static const Exc_t eH("Track::ImportKineWithArgs ");
521 if (fLabel == kMinInt)
522 throw(eH + "label not set.");
526 Warning(eH, "label negative, taking absolute value.");
532 Reve::LoadMacro("kine_tracks.C");
533 gROOT->ProcessLine(Form("kine_track(%d, %d, %d, %d, %d, (Reve::RenderElement*)%p);",
534 label, importMother, importDaugters, colorPdg, recurse, this));
537 /******************************************************************************/
539 void Track::PrintParticle()
541 // Print track parameters.
543 printf("particle %s sign %d\n", GetName(), fCharge);
544 printf("V (%f, %f, %f) \n", fV.x, fV.y, fV.z);
545 printf("P (%f, %f, %f) Pt(%f)\n", fP.x, fP.y, fP.z, fP.Perp());
548 //______________________________________________________________________________
549 void Track::PrintKineStack()
551 // Print kinematics pertaining to track's label.
552 // Uses macro "print_kine_from_label.C".
554 static const Exc_t eH("Track::PrintKineStack ");
556 if (fLabel == kMinInt)
557 throw(eH + "label not set.");
561 Warning(eH, "label negative, taking absolute value.");
567 Reve::LoadMacro("print_kine_from_label.C");
568 gROOT->ProcessLine(Form("print_kine_from_label(%d);", label));
571 //______________________________________________________________________________
572 void Track::PrintPathMarks()
574 // Print registered path-marks.
576 static const Exc_t eH("Track::PrintPathMarks ");
578 printf("Track '%s', number of path marks %d, label %d\n",
579 GetName(), fPathMarks.size(), fLabel);
582 for(vpPathMark_i i=fPathMarks.begin(); i!=fPathMarks.end(); i++)
585 printf(" %-9s p: %8f %8f %8f Vertex: %8e %8e %8e %g \n",
587 pm->P.x, pm->P.y, pm->P.z,
588 pm->V.x, pm->V.y, pm->V.z,
593 /******************************************************************************/
595 //______________________________________________________________________________
596 void Track::CtrlClicked(Reve::Track* track)
598 // Emits "CtrlClicked(Reve::Track*)" signal.
599 // Called from TrackGL on secondary-selection.
601 Emit("CtrlClicked(Reve::Track*)", (Long_t)track);
604 //______________________________________________________________________________
605 void Track::SetLineStyle(Style_t lstyle)
607 // Set line-style of the track.
608 // The style is propagated to projected tracks.
610 TAttLine::SetLineStyle(lstyle);
611 std::list<NLTProjected*>::iterator pi = fProjectedList.begin();
612 while (pi != fProjectedList.end())
614 Track* pt = dynamic_cast<Track*>(*pi);
617 pt->SetLineStyle(lstyle);
618 pt->ElementChanged();
625 /******************************************************************************/
626 /******************************************************************************/
628 //______________________________________________________________________________
631 // Holding structure for a number of track rendering parameters.
633 // This is decoupled from Track/TrackList to allow sharing of the
634 // RnrStyle among several instances. Back references are kept so the
635 // tracks can be recreated when the parameters change.
637 // TrackList has Get/Set methods for RnrStlye. TrackEditor and
638 // TrackListEditor provide editor access.
640 ClassImp(Reve::TrackRnrStyle)
642 Float_t TrackRnrStyle::fgDefMagField = 5;
643 const Float_t TrackRnrStyle::fgkB2C = 0.299792458e-3;
644 TrackRnrStyle TrackRnrStyle::fgDefStyle;
646 //______________________________________________________________________________
647 TrackRnrStyle::TrackRnrStyle() :
651 fMagField(fgDefMagField),
660 fEditPathMarks(kFALSE),
663 fFitDaughters (kTRUE),
664 fFitReferences (kTRUE),
667 fRnrDaughters (kTRUE),
668 fRnrReferences (kTRUE),
674 // Default constructor.
676 fPMAtt.SetMarkerColor(4);
677 fPMAtt.SetMarkerStyle(2);
679 fFVAtt.SetMarkerSize(0.6);
680 fFVAtt.SetMarkerColor(4);
681 fFVAtt.SetMarkerStyle(2);
684 /**************************************************************************/
686 //______________________________________________________________________________
687 void TrackRnrStyle::RebuildTracks()
689 // Rebuild all tracks using this render-style.
692 std::list<RenderElement*>::iterator i = fBackRefs.begin();
693 while (i != fBackRefs.end())
695 track = dynamic_cast<Track*>(*i);
697 track->ElementChanged();
702 /******************************************************************************/
704 //______________________________________________________________________________
705 void TrackRnrStyle::SetMaxR(Float_t x)
707 // Set maximum radius and rebuild tracks.
713 //______________________________________________________________________________
714 void TrackRnrStyle::SetMaxZ(Float_t x)
716 // Set maximum z and rebuild tracks.
722 //______________________________________________________________________________
723 void TrackRnrStyle::SetMaxOrbs(Float_t x)
725 // Set maximum number of orbits and rebuild tracks.
731 //______________________________________________________________________________
732 void TrackRnrStyle::SetMinAng(Float_t x)
734 // Set minimum step angle and rebuild tracks.
740 //______________________________________________________________________________
741 void TrackRnrStyle::SetDelta(Float_t x)
743 // Set maximum error and rebuild tracks.
749 //______________________________________________________________________________
750 void TrackRnrStyle::SetFitDaughters(Bool_t x)
752 // Set daughter creation point fitting and rebuild tracks.
758 //______________________________________________________________________________
759 void TrackRnrStyle::SetFitReferences(Bool_t x)
761 // Set track-reference fitting and rebuild tracks.
767 //______________________________________________________________________________
768 void TrackRnrStyle::SetFitDecay(Bool_t x)
770 // Set decay fitting and rebuild tracks.
776 //______________________________________________________________________________
777 void TrackRnrStyle::SetRnrDecay(Bool_t rnr)
779 // Set decay rendering and rebuild tracks.
785 //______________________________________________________________________________
786 void TrackRnrStyle::SetRnrDaughters(Bool_t rnr)
788 // Set daughter rendering and rebuild tracks.
794 //______________________________________________________________________________
795 void TrackRnrStyle::SetRnrReferences(Bool_t rnr)
797 // Set track-reference rendering and rebuild tracks.
799 fRnrReferences = rnr;
804 /**************************************************************************/
805 /**************************************************************************/
807 //______________________________________________________________________________
811 ClassImp(Reve::TrackList)
813 //______________________________________________________________________________
814 TrackList::TrackList(TrackRnrStyle* rs) :
816 TAttMarker(1, 20, 1),
824 fMinPt (0), fMaxPt (0), fLimPt (0),
825 fMinP (0), fMaxP (0), fLimP (0)
827 // Constructor. If TrackRenderStyle argument is 0, a new default
828 // render-style is created.
830 fChildClass = Track::Class(); // override member from base RenderElementList
832 fMainColorPtr = &fLineColor;
833 if (fRnrStyle== 0) rs = new TrackRnrStyle;
837 //______________________________________________________________________________
838 TrackList::TrackList(const Text_t* name, TrackRnrStyle* rs) :
839 RenderElementList(name),
840 TAttMarker(1, 20, 1),
848 fMinPt (0), fMaxPt (0), fLimPt (0),
849 fMinP (0), fMaxP (0), fLimP (0)
851 // Constructor. If TrackRenderStyle argument is 0, a new default
852 // render-style is created.
854 fChildClass = Track::Class(); // override member from base RenderElementList
856 fMainColorPtr = &fLineColor;
857 if (fRnrStyle== 0) rs = new TrackRnrStyle;
861 //______________________________________________________________________________
862 TrackList::~TrackList()
869 /******************************************************************************/
871 //______________________________________________________________________________
872 void TrackList::SetRnrStyle(TrackRnrStyle* rs)
874 // Set default render-style for tracks.
875 // This is not enforced onto the tracks themselves but this is the
876 // render-style that is show in the TrackListEditor.
878 if (fRnrStyle == rs) return;
879 if (fRnrStyle) fRnrStyle->DecRefCount();
881 if (fRnrStyle) rs->IncRefCount();
884 /**************************************************************************/
886 //______________________________________________________________________________
887 void TrackList::MakeTracks(Bool_t recurse)
889 // Regenerate the visual representations of tracks.
890 // The momentum limits are rescanned during the same traversal.
894 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
896 Track* track = (Track*)(*i);
897 track->MakeTrack(recurse);
899 fLimPt = TMath::Max(fLimPt, track->fP.Perp());
900 fLimP = TMath::Max(fLimP, track->fP.Mag());
902 FindMomentumLimits(*i, recurse);
905 fLimPt = RoundMomentumLimit(fLimPt);
906 fLimP = RoundMomentumLimit(fLimP);
907 if (fMaxPt == 0) fMaxPt = fLimPt;
908 if (fMaxP == 0) fMaxP = fLimP;
913 //______________________________________________________________________________
914 void TrackList::FindMomentumLimits(RenderElement* el, Bool_t recurse)
916 // Loop over track elements of argument el and find highest pT and p.
917 // These are stored in members fLimPt and fLimP.
919 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
921 Track* track = dynamic_cast<Track*>(*i);
924 fLimPt = TMath::Max(fLimPt, track->fP.Perp());
925 fLimP = TMath::Max(fLimP, track->fP.Mag());
927 FindMomentumLimits(*i, recurse);
932 //______________________________________________________________________________
933 Float_t TrackList::RoundMomentumLimit(Float_t x)
935 // Round the momentum limit up to a nice value.
937 using namespace TMath;
938 Double_t fac = Power(10, 1 - Floor(Log10(x)));
939 return Ceil(fac*x) / fac;
942 /**************************************************************************/
944 //______________________________________________________________________________
945 void TrackList::SetRnrLine(Bool_t rnr)
947 // Set rendering of track as line for the list and the elements.
949 for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
951 Track* track = (Track*)(*i);
952 if (track->GetRnrLine() == fRnrLine)
953 track->SetRnrLine(rnr);
960 //______________________________________________________________________________
961 void TrackList::SetRnrLine(Bool_t rnr, RenderElement* el)
963 // Set rendering of track as line for children of el.
966 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
968 track = dynamic_cast<Track*>(*i);
969 if (track && (track->GetRnrLine() == fRnrLine))
970 track->SetRnrLine(rnr);
976 /******************************************************************************/
978 //______________________________________________________________________________
979 void TrackList::SetRnrPoints(Bool_t rnr)
981 // Set rendering of track as points for the list and the elements.
983 for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
985 Track* track = (Track*)(*i);
986 if (track->GetRnrPoints() == fRnrPoints)
987 track->SetRnrPoints(rnr);
989 SetRnrPoints(rnr, *i);
994 //______________________________________________________________________________
995 void TrackList::SetRnrPoints(Bool_t rnr, RenderElement* el)
997 // Set rendering of track as points for children of el.
1000 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
1002 track = dynamic_cast<Track*>(*i);
1004 if (track->GetRnrPoints() == fRnrPoints)
1005 track->SetRnrPoints(rnr);
1007 SetRnrPoints(rnr, *i);
1011 /******************************************************************************/
1013 //______________________________________________________________________________
1014 void TrackList::SetMainColor(Color_t col)
1016 // Set main (line) color for the list and the elements.
1018 for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
1020 Track* track = (Track*)(*i);
1021 if (track->GetLineColor() == fLineColor)
1022 track->SetLineColor(col);
1024 SetLineColor(col, *i);
1026 RenderElement::SetMainColor(col);
1029 //______________________________________________________________________________
1030 void TrackList::SetLineColor(Color_t col, RenderElement* el)
1032 // Set line color for children of el.
1035 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
1037 track = dynamic_cast<Track*>(*i);
1038 if (track && track->GetLineColor() == fLineColor)
1039 track->SetLineColor(col);
1041 SetLineColor(col, *i);
1045 /******************************************************************************/
1047 //______________________________________________________________________________
1048 void TrackList::SetLineWidth(Width_t width)
1050 // Set line width for the list and the elements.
1052 for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
1054 Track* track = (Track*)(*i);
1055 if (track->GetLineWidth() == fLineWidth)
1056 track->SetLineWidth(width);
1058 SetLineWidth(width, *i);
1063 //______________________________________________________________________________
1064 void TrackList::SetLineWidth(Width_t width, RenderElement* el)
1066 // Set line width for children of el.
1069 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
1071 track = dynamic_cast<Track*>(*i);
1072 if (track && track->GetLineWidth() == fLineWidth)
1073 track->SetLineWidth(width);
1075 SetLineWidth(width, *i);
1079 /******************************************************************************/
1081 //______________________________________________________________________________
1082 void TrackList::SetLineStyle(Style_t style)
1084 // Set line style for the list and the elements.
1086 for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
1088 Track* track = (Track*)(*i);
1089 if (track->GetLineStyle() == fLineStyle)
1090 track->SetLineStyle(style);
1092 SetLineStyle(style, *i);
1097 //______________________________________________________________________________
1098 void TrackList::SetLineStyle(Style_t style, RenderElement* el)
1100 // Set line style for children of el.
1103 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
1105 track = dynamic_cast<Track*>(*i);
1106 if (track && track->GetLineStyle() == fLineStyle)
1107 track->SetLineStyle(style);
1109 SetLineStyle(style, *i);
1113 /******************************************************************************/
1115 //______________________________________________________________________________
1116 void TrackList::SetMarkerStyle(Style_t style)
1118 // Set marker style for the list and the elements.
1120 for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
1122 Track* track = (Track*)(*i);
1123 if (track->GetMarkerStyle() == fMarkerStyle)
1124 track->SetMarkerStyle(style);
1126 SetMarkerStyle(style, *i);
1131 //______________________________________________________________________________
1132 void TrackList::SetMarkerStyle(Style_t style, RenderElement* el)
1134 // Set marker style for children of el.
1137 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
1139 track = dynamic_cast<Track*>(*i);
1140 if (track && track->GetMarkerStyle() == fMarkerStyle)
1141 track->SetMarkerStyle(style);
1143 SetMarkerStyle(style, *i);
1147 /******************************************************************************/
1149 //______________________________________________________________________________
1150 void TrackList::SetMarkerColor(Color_t col)
1152 // Set marker color for the list and the elements.
1154 for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
1156 Track* track = (Track*)(*i);
1157 if (track->GetMarkerColor() == fMarkerColor)
1158 track->SetMarkerColor(col);
1160 SetMarkerColor(col, *i);
1165 //______________________________________________________________________________
1166 void TrackList::SetMarkerColor(Color_t col, RenderElement* el)
1168 // Set marker color for children of el.
1171 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
1173 track = dynamic_cast<Track*>(*i);
1174 if (track && track->GetMarkerColor() == fMarkerColor)
1175 track->SetMarkerColor(col);
1177 SetMarkerColor(col, *i);
1181 /******************************************************************************/
1183 //______________________________________________________________________________
1184 void TrackList::SetMarkerSize(Size_t size)
1186 // Set marker size for the list and the elements.
1188 for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
1190 Track* track = (Track*)(*i);
1191 if (track->GetMarkerSize() == fMarkerSize)
1192 track->SetMarkerSize(size);
1194 SetMarkerSize(size, *i);
1199 //______________________________________________________________________________
1200 void TrackList::SetMarkerSize(Size_t size, RenderElement* el)
1202 // Set marker size for children of el.
1205 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
1207 track = dynamic_cast<Track*>(*i);
1208 if (track && track->GetMarkerSize() == fMarkerSize)
1209 track->SetMarkerSize(size);
1211 SetMarkerSize(size, *i);
1215 /******************************************************************************/
1217 //______________________________________________________________________________
1218 void TrackList::SelectByPt(Float_t min_pt, Float_t max_pt)
1220 // Select visibility of tracks by transverse momentum.
1221 // If data-member fRecurse is set, the selection is applied
1222 // recursively to all children.
1227 const Float_t minptsq = min_pt*min_pt;
1228 const Float_t maxptsq = max_pt*max_pt;
1230 for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
1232 const Float_t ptsq = ((Track*)(*i))->fP.Perp2();
1233 Bool_t on = ptsq >= minptsq && ptsq <= maxptsq;
1234 (*i)->SetRnrState(on);
1236 SelectByPt(min_pt, max_pt, *i);
1240 //______________________________________________________________________________
1241 void TrackList::SelectByPt(Float_t min_pt, Float_t max_pt, RenderElement* el)
1243 // Select visibility of el's children tracks by transverse momentum.
1245 const Float_t minptsq = min_pt*min_pt;
1246 const Float_t maxptsq = max_pt*max_pt;
1248 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
1250 Track* track = dynamic_cast<Track*>(*i);
1253 const Float_t ptsq = track->fP.Perp2();
1254 Bool_t on = ptsq >= minptsq && ptsq <= maxptsq;
1255 track->SetRnrState(on);
1257 SelectByPt(min_pt, max_pt, *i);
1262 //______________________________________________________________________________
1263 void TrackList::SelectByP(Float_t min_p, Float_t max_p)
1265 // Select visibility of tracks by momentum.
1266 // If data-member fRecurse is set, the selection is applied
1267 // recursively to all children.
1272 const Float_t minpsq = min_p*min_p;
1273 const Float_t maxpsq = max_p*max_p;
1275 for (List_i i=BeginChildren(); i!=EndChildren(); ++i)
1277 const Float_t psq = ((Track*)(*i))->fP.Mag2();
1278 Bool_t on = psq >= minpsq && psq <= maxpsq;
1279 (*i)->SetRnrState(psq >= minpsq && psq <= maxpsq);
1281 SelectByP(min_p, max_p, *i);
1285 //______________________________________________________________________________
1286 void TrackList::SelectByP(Float_t min_p, Float_t max_p, RenderElement* el)
1288 // Select visibility of el's children tracks by momentum.
1290 const Float_t minpsq = min_p*min_p;
1291 const Float_t maxpsq = max_p*max_p;
1293 for (List_i i=el->BeginChildren(); i!=el->EndChildren(); ++i)
1295 Track* track = dynamic_cast<Track*>(*i);
1298 const Float_t psq = ((Track*)(*i))->fP.Mag2();
1299 Bool_t on = psq >= minpsq && psq <= maxpsq;
1300 track->SetRnrState(on);
1302 SelectByP(min_p, max_p, *i);
1307 /******************************************************************************/
1309 //______________________________________________________________________________
1310 Track* TrackList::FindTrackByLabel(Int_t label)
1312 // Find track by label, select it and display it in the editor.
1314 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
1315 if (((Track*)(*i))->GetLabel() == label) {
1316 TGListTree *lt = gReve->GetLTEFrame()->GetListTree();
1317 TGListTreeItem *mlti = lt->GetSelected();
1318 if (mlti->GetUserData() != this)
1319 mlti = FindListTreeItem(lt);
1320 TGListTreeItem *tlti = (*i)->FindListTreeItem(lt, mlti);
1321 lt->HighlightItem(tlti);
1322 lt->SetSelected(tlti);
1323 gReve->EditRenderElement(*i);
1330 //______________________________________________________________________________
1331 Track* TrackList::FindTrackByIndex(Int_t index)
1333 // Find track by index, select it and display it in the editor.
1335 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
1336 if (((Track*)(*i))->GetIndex() == index) {
1337 TGListTree *lt = gReve->GetLTEFrame()->GetListTree();
1338 TGListTreeItem *mlti = lt->GetSelected();
1339 if (mlti->GetUserData() != this)
1340 mlti = FindListTreeItem(lt);
1341 TGListTreeItem *tlti = (*i)->FindListTreeItem(lt, mlti);
1342 lt->HighlightItem(tlti);
1343 lt->SetSelected(tlti);
1344 gReve->EditRenderElement(*i);
1351 //______________________________________________________________________________
1352 void TrackList::ImportHits()
1354 // Import hits for all track.
1356 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
1357 ((Track*)(*i))->ImportHits();
1361 //______________________________________________________________________________
1362 void TrackList::ImportClusters()
1364 // Import clusters for all track.
1366 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
1367 ((Track*)(*i))->ImportClusters();
1371 /******************************************************************************/
1373 //______________________________________________________________________________
1374 TClass* TrackList::ProjectedClass() const
1376 // Virtual from NLTProjectable, returns NLTTrackList class.
1378 return NLTTrackList::Class();
1382 /******************************************************************************/
1383 /******************************************************************************/
1385 #include "RGEditor.h"
1387 //______________________________________________________________________________
1390 // Provides event-based method for tagging of good / bad (or primary /
1391 // secondary) tracks. A report can be written into a text file.
1393 // Track status is toggled by using secondary-selection / ctrl-click
1394 // functionality of the GL viewer.
1396 // Some of the functionality is implemented in TrackCounterEditor
1399 ClassImp(TrackCounter)
1401 TrackCounter* TrackCounter::fgInstance = 0;
1403 //______________________________________________________________________________
1404 TrackCounter::TrackCounter(const Text_t* name, const Text_t* title) :
1406 TNamed(name, title),
1409 fClickAction (CA_ToggleTrack),
1415 // Connects to global signal "Reve::Track", "CtrlClicked(Reve::Track*)".
1417 if (fgInstance == 0) fgInstance = this;
1418 TQObject::Connect("Reve::Track", "CtrlClicked(Reve::Track*)",
1419 "Reve::TrackCounter", this, "DoTrackAction(Reve::Track*)");
1422 //______________________________________________________________________________
1423 TrackCounter::~TrackCounter()
1426 // Disconnect from the global track signals.
1428 TQObject::Disconnect("Reve::Track", "DoTrackAction(Reve::Track*)");
1429 if (fgInstance == this) fgInstance = 0;
1432 /**************************************************************************/
1434 //______________________________________________________________________________
1435 void TrackCounter::Reset()
1437 // Reset internal track-counters and track-list.
1439 printf("TrackCounter::Reset()\n");
1442 TIter next(&fTrackLists);
1444 while ((tlist = dynamic_cast<TrackList*>(next())))
1445 tlist->DecDenyDestroy();
1446 fTrackLists.Clear("nodelete");
1449 //______________________________________________________________________________
1450 void TrackCounter::RegisterTracks(TrackList* tlist, Bool_t goodTracks)
1452 // Register tracks from tlist and tlist itself.
1453 // If goodTracks is true, they are considered as primary/good
1456 tlist->IncDenyDestroy();
1457 fTrackLists.Add(tlist);
1459 List_i i = tlist->BeginChildren();
1460 while (i != tlist->EndChildren())
1462 Track* t = dynamic_cast<Track*>(*i);
1469 t->SetLineStyle(fBadLineStyle);
1477 //______________________________________________________________________________
1478 void TrackCounter::DoTrackAction(Track* track)
1480 // Slot called when track is ctrl-clicked.
1482 // No check is done if track actually belongs to one of the
1483 // registered track-lists.
1485 // Probably it would be safer to copy good/bad tracks into special
1487 // In this case one should also override RemoveElementLocal.
1489 switch (fClickAction)
1492 case CA_PrintTrackInfo:
1494 printf("Track '%s'\n", track->GetObject()->GetName());
1495 Vector &v = track->fV, &p = track->fP;
1496 printf(" Vx=%f, Vy=%f, Vz=%f; Pt=%f, Pz=%f, phi=%f)\n",
1497 v.x, v.y, v.z, p.Perp(), p.z, TMath::RadToDeg()*p.Phi());
1498 printf(" <other information should be printed ... full AliESDtrack>\n");
1502 case CA_ToggleTrack:
1504 if (track->GetLineStyle() == 1)
1506 track->SetLineStyle(fBadLineStyle);
1509 track->SetLineStyle(1);
1512 track->ElementChanged();
1515 printf("TrackCounter::CountTrack All=%d, Good=%d, Bad=%d\n",
1516 fAllTracks, fGoodTracks, fAllTracks-fGoodTracks);
1518 if (gReve->GetEditor()->GetModel() == GetObject())
1519 gReve->EditRenderElement(this);
1524 } // end switch fClickAction
1527 /**************************************************************************/
1529 //______________________________________________________________________________
1530 void TrackCounter::OutputEventTracks(FILE* out)
1532 // Print good-track summary into a plain-text file by iteration
1533 // through all registered track-lists.
1534 // State of each track is determined by its line-style, it is
1535 // considered a good track if it's line style is solid.
1540 fprintf(out, "TrackCounter::FinalizeEvent()\n");
1543 fprintf(out, "Event = %d Ntracks = %d\n", fEventId, fGoodTracks);
1545 TIter tlists(&fTrackLists);
1548 while ((tlist = (TrackList*) tlists()) != 0)
1550 List_i i = tlist->BeginChildren();
1551 while (i != tlist->EndChildren())
1553 Track* t = dynamic_cast<Track*>(*i);
1554 if (t != 0 && t->GetLineStyle() == 1)
1557 fprintf(out, " %2d: chg=%+2d pt=%8.5f eta=%+8.5f\n",
1558 cnt, t->fCharge, t->fP.Perp(), t->fP.Eta());