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()
128 TrackRnrStyle& RS((fRnrStyle != 0) ? *fRnrStyle : TrackRnrStyle::fgDefStyle);
130 Float_t px = fP.x, py = fP.y, pz = fP.z;
138 std::vector<MCVertex> track_points;
139 Bool_t decay = kFALSE;
141 if ((TMath::Abs(fV.z) > RS.fMaxZ) || (fV.x*fV.x + fV.y*fV.y > RS.fMaxR*RS.fMaxR))
144 if (fCharge != 0 && TMath::Abs(RS.fMagField) > 1e-5) {
146 // Charged particle in magnetic field
148 Float_t a = RS.fgkB2C * RS.fMagField * fCharge;
150 MCHelix helix(fRnrStyle, &mc_v0, TMath::C()*fBeta, &track_points, a); //m->cm
151 helix.Init(TMath::Sqrt(px*px+py*py), pz);
153 if(!fPathMarks.empty())
155 for(std::vector<Reve::PathMark*>::iterator i=fPathMarks.begin(); i!=fPathMarks.end(); ++i)
157 Reve::PathMark* pm = *i;
159 if (RS.fFitReferences && pm->type == Reve::PathMark::Reference)
161 if(TMath::Abs(pm->V.z) > RS.fMaxZ
162 || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR )
165 // printf("%s fit reference \n", fName.Data());
166 helix.LoopToVertex(px, py, pz, pm->V.x, pm->V.y, pm->V.z);
171 else if(RS.fFitDaughters && pm->type == Reve::PathMark::Daughter)
173 if(TMath::Abs(pm->V.z) > RS.fMaxZ
174 || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR )
177 // printf("%s fit daughter \n", fName.Data());
178 helix.LoopToVertex(px, py, pz, pm->V.x, pm->V.y, pm->V.z);
183 else if(RS.fFitDecay && pm->type == Reve::PathMark::Decay)
185 if(TMath::Abs(pm->V.z) > RS.fMaxZ
186 || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR )
188 helix.LoopToVertex(px, py, pz, pm->V.x, pm->V.y, pm->V.z);
196 if(!decay || RS.fFitDecay == kFALSE){
197 helix.LoopToBounds(px,py,pz);
198 // printf("%s loop to bounds \n",fName.Data() );
203 // Neutral particle or no field
205 MCLine line(fRnrStyle, &mc_v0, TMath::C()*fBeta, &track_points);
207 if(!fPathMarks.empty()){
208 for(std::vector<Reve::PathMark*>::iterator i=fPathMarks.begin(); i!=fPathMarks.end(); ++i) {
209 Reve::PathMark* pm = *i;
211 if(RS.fFitDaughters && pm->type == Reve::PathMark::Daughter){
212 if(TMath::Abs(pm->V.z) > RS.fMaxZ
213 || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR )
215 line.GotoVertex(pm->V.x, pm->V.y, pm->V.z);
221 if(RS.fFitDecay && pm->type == Reve::PathMark::Decay){
222 if(TMath::Abs(pm->V.z) > RS.fMaxZ
223 || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR )
225 line.GotoVertex(pm->V.x, pm->V.y, pm->V.z);
233 if(!decay || RS.fFitDecay == kFALSE)
234 line.GotoBounds(px,py,pz);
238 Reset(track_points.size());
239 for(std::vector<MCVertex>::iterator i=track_points.begin(); i!=track_points.end(); ++i)
240 SetNextPoint(i->x, i->y, i->z);
243 /**************************************************************************/
245 void Track::ImportHits()
247 Reve::LoadMacro("hits_from_label.C");
248 gROOT->ProcessLine(Form("hits_from_label(%d);", fLabel));
251 void Track::ImportClusters()
253 Reve::LoadMacro("clusters_from_label.C");
254 gROOT->ProcessLine(Form("clusters_from_label(%d);", fLabel));
257 void Track::ImportClustersFromIndex()
259 static const Exc_t eH("Track::ImportClustersFromIndex ");
262 throw(eH + "index not set.");
264 Reve::LoadMacro("clusters_from_index.C");
265 gROOT->ProcessLine(Form("clusters_from_index(%d);", fIndex));
268 void Track::ImportDaughters()
270 static const Exc_t eH("Track::ImportDaughters ");
273 throw(eH + "label not set.");
275 Reve::LoadMacro("kine_daughter_tracks.C");
276 gROOT->ProcessLine(Form("kine_daughter_tracks(%d);", fLabel));
279 /**************************************************************************/
281 void Track::PrintKineStack()
283 Reve::LoadMacro("print_kine_from_label.C");
284 gROOT->ProcessLine(Form("print_kine_from_label(%d);", fLabel));
288 void Track::PrintPathMarks()
290 static const Exc_t eH("Track::PrintPathMarks ");
293 throw(eH + "label not set.");
295 printf("Number of path marks %d label %d\n",
296 fPathMarks.size(), fLabel);
299 for(vpPathMark_i i=fPathMarks.begin(); i!=fPathMarks.end(); i++)
302 printf("Reve::PathMark: %-9s p: %8f %8f %8f Vertex: %8e %8e %8e %g \n",
304 pm->P.x, pm->P.y, pm->P.z,
305 pm->V.x, pm->V.y, pm->V.z,
310 /**************************************************************************/
312 void Track::CtrlClicked(Reve::Track* track)
314 Emit("CtrlClicked(Reve::Track*)", (Long_t)track);
318 /**************************************************************************/
319 /**************************************************************************/
321 //______________________________________________________________________
325 ClassImp(Reve::TrackRnrStyle)
327 Float_t TrackRnrStyle::fgDefMagField = 5;
328 const Float_t TrackRnrStyle::fgkB2C = 0.299792458e-3;
329 TrackRnrStyle TrackRnrStyle::fgDefStyle;
331 TrackRnrStyle::TrackRnrStyle() :
336 fMagField(fgDefMagField),
345 fFitDaughters (kTRUE),
346 fFitReferences (kTRUE),
349 fRnrDaughters (kTRUE),
350 fRnrReferences (kTRUE),
353 /**************************************************************************/
354 /**************************************************************************/
356 //______________________________________________________________________
360 ClassImp(Reve::TrackList)
362 void TrackList::Init()
366 // fMarker->SetMarkerSize(0.05);
368 if (fRnrStyle== 0) fRnrStyle = new TrackRnrStyle;
369 SetMainColorPtr(&fRnrStyle->fColor);
372 TrackList::TrackList(Int_t n_tracks, TrackRnrStyle* rs) :
373 RenderElementListBase(),
374 TPolyMarker3D(n_tracks),
380 fEditPathMarks (kFALSE)
385 TrackList::TrackList(const Text_t* name, Int_t n_tracks, TrackRnrStyle* rs) :
386 RenderElementListBase(),
387 TPolyMarker3D(n_tracks),
398 void TrackList::Reset(Int_t n_tracks)
400 delete [] fP; fP = 0;
402 if(fN) fP = new Float_t [3*fN];
403 memset(fP, 0, 3*fN*sizeof(Float_t));
407 /**************************************************************************/
409 void TrackList::Paint(Option_t* option)
413 TPolyMarker3D::Paint(option);
416 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
417 if((*i)->GetRnrElement())
418 (*i)->GetObject()->Paint(option);
424 /**************************************************************************/
426 void TrackList::AddElement(RenderElement* el)
428 static const Exc_t eH("TrackList::AddElement ");
429 if (dynamic_cast<Track*>(el) == 0)
430 throw(eH + "new element not a Track.");
431 RenderElementListBase::AddElement(el);
434 /**************************************************************************/
436 void TrackList::MakeTracks()
438 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
439 ((Track*)(*i))->MakeTrack();
445 void TrackList::MakeMarkers()
447 Reset(fChildren.size());
448 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
449 Track& t = *((Track*)(*i));
451 SetNextPoint(t.fV.x, t.fV.y, t.fV.z);
456 /**************************************************************************/
457 /*************************************************************************/
459 void TrackList::SetWidth(Width_t w)
461 Width_t oldw = fRnrStyle->fWidth;
462 fRnrStyle->fWidth = w;
463 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
464 Track& t = *((Track*)(*i));
465 if (t.GetLineWidth() == oldw)
470 void TrackList::SetMaxR(Float_t x)
472 fRnrStyle->fMaxR = x;
477 void TrackList::SetMaxZ(Float_t x)
479 fRnrStyle->fMaxZ = x;
484 void TrackList::SetMaxOrbs(Float_t x)
486 fRnrStyle->fMaxOrbs = x;
490 void TrackList::SetMinAng(Float_t x)
492 fRnrStyle->fMinAng = x;
496 void TrackList::SetDelta(Float_t x)
498 fRnrStyle->fDelta = x;
502 void TrackList::SetFitDaughters(Bool_t x)
504 fRnrStyle->fFitDaughters = x;
508 void TrackList::SetFitReferences(Bool_t x)
510 fRnrStyle->fFitReferences = x;
514 void TrackList::SetFitDecay(Bool_t x)
516 fRnrStyle->fFitDecay = x;
520 void TrackList::SetRnrDecay(Bool_t rnr)
522 fRnrStyle->fRnrDecay = rnr;
526 void TrackList::SetRnrDaughters(Bool_t rnr)
528 fRnrStyle->fRnrDaughters = rnr;
532 void TrackList::SetRnrReferences(Bool_t rnr)
534 fRnrStyle->fRnrReferences = rnr;
538 void TrackList::SetRnrMarkers(Bool_t rnr)
544 void TrackList::SetRnrTracks(Bool_t rnr)
551 /**************************************************************************/
552 /**************************************************************************/
554 void TrackList::SelectByPt(Float_t min_pt, Float_t max_pt)
556 Float_t minptsq = min_pt*min_pt;
557 Float_t maxptsq = max_pt*max_pt;
560 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
561 ptsq = ((Track*)(*i))->fP.Perp2();
562 (*i)->SetRnrElement(ptsq >= minptsq && ptsq <= maxptsq);
566 /**************************************************************************/
568 void TrackList::ImportHits()
570 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
571 ((Track*)(*i))->ImportHits();
575 void TrackList::ImportClusters()
577 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
578 ((Track*)(*i))->ImportClusters();
582 /**************************************************************************/
583 /**************************************************************************/
584 /**************************************************************************/
586 #include "RGEditor.h"
588 //______________________________________________________________________
592 ClassImp(TrackCounter)
594 TrackCounter* TrackCounter::fgInstance = 0;
596 TrackCounter::TrackCounter(const Text_t* name, const Text_t* title) :
601 fClickAction (CA_ToggleTrack),
606 if (fgInstance == 0) fgInstance = this;
607 TQObject::Connect("Reve::Track", "CtrlClicked(Reve::Track*)",
608 "Reve::TrackCounter", this, "DoTrackAction(Reve::Track*)");
611 TrackCounter::~TrackCounter()
613 TQObject::Disconnect("Reve::Track", "DoTrackAction(Reve::Track*)");
614 if (fgInstance == this) fgInstance = 0;
617 /**************************************************************************/
619 void TrackCounter::Reset()
621 printf("TrackCounter::Reset()\n");
624 TIter next(&fTrackLists);
626 while ((tlist = dynamic_cast<TrackList*>(next())))
627 tlist->RemoveParent(this);
631 void TrackCounter::RegisterTracks(TrackList* tlist, Bool_t goodTracks)
633 // printf("TrackCounter::RegisterTracks '%s', %s\n",
634 // tlist->GetObject()->GetName(), goodTracks ? "good" : "bad");
636 tlist->AddParent(this);
637 fTrackLists.Add(tlist);
639 List_i i = tlist->BeginChildren();
640 while (i != tlist->EndChildren())
642 Track* t = dynamic_cast<Track*>(*i);
649 t->SetLineStyle(fBadLineStyle);
657 void TrackCounter::DoTrackAction(Track* track)
659 // !!!! No check done if ok.
660 // !!!! Should also override RemoveElementLocal
661 // !!!! But then ... should also sotre local information if track is ok.
663 switch (fClickAction)
666 case CA_PrintTrackInfo:
668 printf("Track '%s'\n", track->GetObject()->GetName());
669 Vector &v = track->fV, &p = track->fP;
670 printf(" Vx=%f, Vy=%f, Vz=%f; Pt=%f, Pz=%f, phi=%f)\n",
671 v.x, v.y, v.z, p.Perp(), p.z, TMath::RadToDeg()*p.Phi());
672 printf(" <other information should be printed ... full AliESDtrack>\n");
678 if (track->GetLineStyle() == 1)
680 track->SetLineStyle(fBadLineStyle);
683 track->SetLineStyle(1);
688 printf("TrackCounter::CountTrack All=%d, Good=%d, Bad=%d\n",
689 fAllTracks, fGoodTracks, fAllTracks-fGoodTracks);
691 if (gReve->GetEditor()->GetModel() == GetObject())
692 gReve->EditRenderElement(this);
697 } // end switch fClickAction
700 /**************************************************************************/
702 void TrackCounter::OutputEventTracks(FILE* out)
707 fprintf(out, "TrackCounter::FinalizeEvent()\n");
710 fprintf(out, "Event = %d Ntracks = %d\n", fEventId, fGoodTracks);
712 TIter tlists(&fTrackLists);
715 while ((tlist = (TrackList*) tlists()) != 0)
717 List_i i = tlist->BeginChildren();
718 while (i != tlist->EndChildren())
720 Track* t = dynamic_cast<Track*>(*i);
721 if (t != 0 && t->GetLineStyle() == 1)
724 fprintf(out, " %2d: chg=%+2d pt=%8.5f eta=%+8.5f\n",
725 cnt, t->fCharge, t->fP.Perp(), t->fP.Eta());