4 #include "MCHelixLine.hi"
7 #include <TPolyLine3D.h>
8 #include <TPolyMarker3D.h>
12 #include <Reve/RGTopFrame.h>
19 //______________________________________________________________________
39 Track::Track(TParticle* t, Int_t label, TrackRnrStyle* rs):
42 fV(t->Vx(), t->Vy(), t->Vz()),
43 fP(t->Px(), t->Py(), t->Pz()),
44 fBeta(t->P()/t->Energy()),
52 fLineColor = fRnrStyle->GetColor();
53 fMainColorPtr = &fLineColor;
55 TParticlePDG* pdgp = t->GetPDG();
57 fCharge = (Int_t) TMath::Nint(pdgp->Charge()/3);
59 SetName(t->GetName());
62 Track::Track(Reve::MCTrack* t, TrackRnrStyle* rs):
65 fV(t->Vx(), t->Vy(), t->Vz()),
66 fP(t->Px(), t->Py(), t->Pz()),
67 fBeta(t->P()/t->Energy()),
75 fLineColor = fRnrStyle->GetColor();
76 fMainColorPtr = &fLineColor;
78 TParticlePDG* pdgp = t->GetPDG();
80 t->ResetPdgCode(); pdgp = t->GetPDG();
82 fCharge = (Int_t) TMath::Nint(pdgp->Charge()/3);
84 SetName(t->GetName());
87 Track::Track(Reve::RecTrack* t, TrackRnrStyle* rs) :
100 fLineColor = fRnrStyle->GetColor();
101 fMainColorPtr = &fLineColor;
103 SetName(t->GetName());
108 for (vpPathMark_i i=fPathMarks.begin(); i!=fPathMarks.end(); ++i)
113 void Track::Reset(Int_t n_points)
115 delete [] TPolyLine3D::fP; TPolyLine3D::fP = 0;
117 if(fN) TPolyLine3D::fP = new Float_t [3*fN];
118 memset(TPolyLine3D::fP, 0, 3*fN*sizeof(Float_t));
123 /**************************************************************************/
125 void Track::MakeTrack( Bool_t recurse)
127 TrackRnrStyle& RS((fRnrStyle != 0) ? *fRnrStyle : TrackRnrStyle::fgDefStyle);
129 Float_t px = fP.x, py = fP.y, pz = fP.z;
137 std::vector<MCVertex> track_points;
138 Bool_t decay = kFALSE;
140 if ((TMath::Abs(fV.z) > RS.fMaxZ) || (fV.x*fV.x + fV.y*fV.y > RS.fMaxR*RS.fMaxR))
143 if (fCharge != 0 && TMath::Abs(RS.fMagField) > 1e-5) {
145 // Charged particle in magnetic field
147 Float_t a = RS.fgkB2C * RS.fMagField * fCharge;
149 MCHelix helix(fRnrStyle, &mc_v0, TMath::C()*fBeta, &track_points, a); //m->cm
150 helix.Init(TMath::Sqrt(px*px+py*py), pz);
152 if(!fPathMarks.empty())
154 for(std::vector<Reve::PathMark*>::iterator i=fPathMarks.begin(); i!=fPathMarks.end(); ++i)
156 Reve::PathMark* pm = *i;
158 if (RS.fFitReferences && pm->type == Reve::PathMark::Reference)
160 if(TMath::Abs(pm->V.z) > RS.fMaxZ
161 || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR )
164 // printf("%s fit reference \n", fName.Data());
165 helix.LoopToVertex(px, py, pz, pm->V.x, pm->V.y, pm->V.z);
170 else if(RS.fFitDaughters && pm->type == Reve::PathMark::Daughter)
172 if(TMath::Abs(pm->V.z) > RS.fMaxZ
173 || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR )
176 // printf("%s fit daughter \n", fName.Data());
177 helix.LoopToVertex(px, py, pz, pm->V.x, pm->V.y, pm->V.z);
182 else if(RS.fFitDecay && pm->type == Reve::PathMark::Decay)
184 if(TMath::Abs(pm->V.z) > RS.fMaxZ
185 || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR )
187 helix.LoopToVertex(px, py, pz, pm->V.x, pm->V.y, pm->V.z);
195 if(!decay || RS.fFitDecay == kFALSE){
196 helix.LoopToBounds(px,py,pz);
197 // printf("%s loop to bounds \n",fName.Data() );
202 // Neutral particle or no field
204 MCLine line(fRnrStyle, &mc_v0, TMath::C()*fBeta, &track_points);
206 if(!fPathMarks.empty()){
207 for(std::vector<Reve::PathMark*>::iterator i=fPathMarks.begin(); i!=fPathMarks.end(); ++i) {
208 Reve::PathMark* pm = *i;
210 if(RS.fFitDaughters && pm->type == Reve::PathMark::Daughter){
211 if(TMath::Abs(pm->V.z) > RS.fMaxZ
212 || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR )
214 line.GotoVertex(pm->V.x, pm->V.y, pm->V.z);
220 if(RS.fFitDecay && pm->type == Reve::PathMark::Decay){
221 if(TMath::Abs(pm->V.z) > RS.fMaxZ
222 || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR )
224 line.GotoVertex(pm->V.x, pm->V.y, pm->V.z);
232 if(!decay || RS.fFitDecay == kFALSE)
233 line.GotoBounds(px,py,pz);
237 Reset(track_points.size());
238 for(std::vector<MCVertex>::iterator i=track_points.begin(); i!=track_points.end(); ++i)
239 SetNextPoint(i->x, i->y, i->z);
243 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
244 t = dynamic_cast<Track*>(*i);
245 if(t)t->MakeTrack(recurse);
250 /**************************************************************************/
252 struct cmp_pathmark {
253 bool operator()(PathMark* const & a, PathMark* const & b)
254 { return a->time < b->time; }
258 void Track::SortPathMarksByTime()
260 sort(fPathMarks.begin(), fPathMarks.end(), cmp_pathmark());
264 /**************************************************************************/
266 void Track::ImportHits()
268 Reve::LoadMacro("hits_from_label.C");
269 gROOT->ProcessLine(Form("hits_from_label(%d, (Reve::RenderElement*)%p);",
273 void Track::ImportClusters()
275 Reve::LoadMacro("clusters_from_label.C");
276 gROOT->ProcessLine(Form("clusters_from_label(%d, (Reve::RenderElement*)%p);",
280 void Track::ImportClustersFromIndex()
282 static const Exc_t eH("Track::ImportClustersFromIndex ");
285 throw(eH + "index not set.");
287 Reve::LoadMacro("clusters_from_index.C");
288 gROOT->ProcessLine(Form("clusters_from_index(%d, (Reve::RenderElement*)%p);",
292 /**************************************************************************/
294 void Track::ImportKine()
296 static const Exc_t eH("Track::ImportKine ");
299 throw(eH + "label not set.");
301 Reve::LoadMacro("kine_tracks.C");
302 gROOT->ProcessLine(Form("kine_track(%d, kFALSE, kTRUE, (Reve::RenderElement*)%p);",
307 void Track::ImportKineWithArgs(Bool_t importMother, Bool_t importDaugters)
309 static const Exc_t eH("Track::ImportKineWithArgs ");
312 throw(eH + "label not set.");
314 Reve::LoadMacro("kine_tracks.C");
315 gROOT->ProcessLine(Form("kine_track(%d, %d, %d, (Reve::RenderElement*)%p);",
316 fLabel, importMother, importDaugters, this));
320 /**************************************************************************/
322 void Track::PrintKineStack()
324 Reve::LoadMacro("print_kine_from_label.C");
325 gROOT->ProcessLine(Form("print_kine_from_label(%d);", fLabel));
329 void Track::PrintPathMarks()
331 static const Exc_t eH("Track::PrintPathMarks ");
334 throw(eH + "label not set.");
336 printf("Number of path marks %d label %d\n",
337 fPathMarks.size(), fLabel);
340 for(vpPathMark_i i=fPathMarks.begin(); i!=fPathMarks.end(); i++)
343 printf("Reve::PathMark: %-9s p: %8f %8f %8f Vertex: %8e %8e %8e %g \n",
345 pm->P.x, pm->P.y, pm->P.z,
346 pm->V.x, pm->V.y, pm->V.z,
351 /**************************************************************************/
353 void Track::CtrlClicked(Reve::Track* track)
355 Emit("CtrlClicked(Reve::Track*)", (Long_t)track);
359 /**************************************************************************/
360 /**************************************************************************/
362 //______________________________________________________________________
366 ClassImp(Reve::TrackRnrStyle)
368 Float_t TrackRnrStyle::fgDefMagField = 5;
369 const Float_t TrackRnrStyle::fgkB2C = 0.299792458e-3;
370 TrackRnrStyle TrackRnrStyle::fgDefStyle;
372 TrackRnrStyle::TrackRnrStyle() :
377 fMagField(fgDefMagField),
389 fFitDaughters (kTRUE),
390 fFitReferences (kTRUE),
393 fRnrDaughters (kTRUE),
394 fRnrReferences (kTRUE),
397 /**************************************************************************/
398 /**************************************************************************/
400 //______________________________________________________________________
404 ClassImp(Reve::TrackList)
406 void TrackList::Init()
412 if (fRnrStyle== 0) fRnrStyle = new TrackRnrStyle;
413 SetMainColorPtr(&fRnrStyle->fColor);
416 TrackList::TrackList(Int_t n_tracks, TrackRnrStyle* rs) :
418 TPolyMarker3D(n_tracks),
424 fEditPathMarks (kFALSE)
429 TrackList::TrackList(const Text_t* name, Int_t n_tracks, TrackRnrStyle* rs) :
431 TPolyMarker3D(n_tracks),
437 fEditPathMarks (kFALSE)
443 void TrackList::Reset(Int_t n_tracks)
445 delete [] fP; fP = 0;
447 if(fN) fP = new Float_t [3*fN];
448 memset(fP, 0, 3*fN*sizeof(Float_t));
452 /**************************************************************************/
454 void TrackList::Paint(Option_t* option)
458 TPolyMarker3D::Paint(option);
460 if(fRnrTracks && fRnrChildren) {
461 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
462 if((*i)->GetRnrSelf())
463 (*i)->GetObject()->Paint(option);
469 /**************************************************************************/
471 void TrackList::AddElement(RenderElement* el)
473 static const Exc_t eH("TrackList::AddElement ");
474 if (dynamic_cast<Track*>(el) == 0)
475 throw(eH + "new element not a Track.");
476 RenderElement::AddElement(el);
479 /**************************************************************************/
481 void TrackList::MakeTracks()
483 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
484 ((Track*)(*i))->MakeTrack();
490 void TrackList::MakeMarkers()
492 Reset(fChildren.size());
493 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
494 Track& t = *((Track*)(*i));
496 SetNextPoint(t.fV.x, t.fV.y, t.fV.z);
501 /**************************************************************************/
502 /*************************************************************************/
504 void TrackList::SetWidth(Width_t w)
506 Width_t oldw = fRnrStyle->fWidth;
507 fRnrStyle->fWidth = w;
508 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
509 Track& t = *((Track*)(*i));
510 if (t.GetLineWidth() == oldw)
515 void TrackList::SetMaxR(Float_t x)
517 fRnrStyle->fMaxR = x;
522 void TrackList::SetMaxZ(Float_t x)
524 fRnrStyle->fMaxZ = x;
529 void TrackList::SetMaxOrbs(Float_t x)
531 fRnrStyle->fMaxOrbs = x;
535 void TrackList::SetMinAng(Float_t x)
537 fRnrStyle->fMinAng = x;
541 void TrackList::SetDelta(Float_t x)
543 fRnrStyle->fDelta = x;
547 void TrackList::SetFitDaughters(Bool_t x)
549 fRnrStyle->fFitDaughters = x;
553 void TrackList::SetFitReferences(Bool_t x)
555 fRnrStyle->fFitReferences = x;
559 void TrackList::SetFitDecay(Bool_t x)
561 fRnrStyle->fFitDecay = x;
565 void TrackList::SetRnrDecay(Bool_t rnr)
567 fRnrStyle->fRnrDecay = rnr;
571 void TrackList::SetRnrDaughters(Bool_t rnr)
573 fRnrStyle->fRnrDaughters = rnr;
577 void TrackList::SetRnrReferences(Bool_t rnr)
579 fRnrStyle->fRnrReferences = rnr;
583 void TrackList::SetRnrMarkers(Bool_t rnr)
589 void TrackList::SetRnrTracks(Bool_t rnr)
596 /**************************************************************************/
597 /**************************************************************************/
599 void TrackList::SelectByPt(Float_t min_pt, Float_t max_pt)
601 fRnrStyle->fMinPt = min_pt;
602 fRnrStyle->fMaxPt = max_pt;
604 Float_t minptsq = min_pt*min_pt;
605 Float_t maxptsq = max_pt*max_pt;
608 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
609 ptsq = ((Track*)(*i))->fP.Perp2();
610 (*i)->SetRnrSelf(ptsq >= minptsq && ptsq <= maxptsq);
614 /**************************************************************************/
616 void TrackList::ImportHits()
618 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
619 ((Track*)(*i))->ImportHits();
623 void TrackList::ImportClusters()
625 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
626 ((Track*)(*i))->ImportClusters();
630 /**************************************************************************/
631 /**************************************************************************/
632 /**************************************************************************/
634 #include "RGEditor.h"
636 //______________________________________________________________________
640 ClassImp(TrackCounter)
642 TrackCounter* TrackCounter::fgInstance = 0;
644 TrackCounter::TrackCounter(const Text_t* name, const Text_t* title) :
649 fClickAction (CA_ToggleTrack),
654 if (fgInstance == 0) fgInstance = this;
655 TQObject::Connect("Reve::Track", "CtrlClicked(Reve::Track*)",
656 "Reve::TrackCounter", this, "DoTrackAction(Reve::Track*)");
659 TrackCounter::~TrackCounter()
661 TQObject::Disconnect("Reve::Track", "DoTrackAction(Reve::Track*)");
662 if (fgInstance == this) fgInstance = 0;
665 /**************************************************************************/
667 void TrackCounter::Reset()
669 printf("TrackCounter::Reset()\n");
672 TIter next(&fTrackLists);
674 while ((tlist = dynamic_cast<TrackList*>(next())))
675 tlist->RemoveParent(this);
679 void TrackCounter::RegisterTracks(TrackList* tlist, Bool_t goodTracks)
681 // printf("TrackCounter::RegisterTracks '%s', %s\n",
682 // tlist->GetObject()->GetName(), goodTracks ? "good" : "bad");
684 tlist->AddParent(this);
685 fTrackLists.Add(tlist);
687 List_i i = tlist->BeginChildren();
688 while (i != tlist->EndChildren())
690 Track* t = dynamic_cast<Track*>(*i);
697 t->SetLineStyle(fBadLineStyle);
705 void TrackCounter::DoTrackAction(Track* track)
707 // !!!! No check done if ok.
708 // !!!! Should also override RemoveElementLocal
709 // !!!! But then ... should also sotre local information if track is ok.
711 switch (fClickAction)
714 case CA_PrintTrackInfo:
716 printf("Track '%s'\n", track->GetObject()->GetName());
717 Vector &v = track->fV, &p = track->fP;
718 printf(" Vx=%f, Vy=%f, Vz=%f; Pt=%f, Pz=%f, phi=%f)\n",
719 v.x, v.y, v.z, p.Perp(), p.z, TMath::RadToDeg()*p.Phi());
720 printf(" <other information should be printed ... full AliESDtrack>\n");
726 if (track->GetLineStyle() == 1)
728 track->SetLineStyle(fBadLineStyle);
731 track->SetLineStyle(1);
736 printf("TrackCounter::CountTrack All=%d, Good=%d, Bad=%d\n",
737 fAllTracks, fGoodTracks, fAllTracks-fGoodTracks);
739 if (gReve->GetEditor()->GetModel() == GetObject())
740 gReve->EditRenderElement(this);
745 } // end switch fClickAction
748 /**************************************************************************/
750 void TrackCounter::OutputEventTracks(FILE* out)
755 fprintf(out, "TrackCounter::FinalizeEvent()\n");
758 fprintf(out, "Event = %d Ntracks = %d\n", fEventId, fGoodTracks);
760 TIter tlists(&fTrackLists);
763 while ((tlist = (TrackList*) tlists()) != 0)
765 List_i i = tlist->BeginChildren();
766 while (i != tlist->EndChildren())
768 Track* t = dynamic_cast<Track*>(*i);
769 if (t != 0 && t->GetLineStyle() == 1)
772 fprintf(out, " %2d: chg=%+2d pt=%8.5f eta=%+8.5f\n",
773 cnt, t->fCharge, t->fP.Perp(), t->fP.Eta());