2 // Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
4 /**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
7 * full copyright notice. *
8 **************************************************************************/
10 #include "AliEveKineTools.h"
14 #include <TBranchElement.h>
15 #include <TClonesArray.h>
18 #include <AliTrackReference.h>
20 #include <TEveTrack.h>
21 #include <TEveElement.h>
26 //______________________________________________________________________________
32 ClassImp(AliEveKineTools)
34 AliEveKineTools::AliEveKineTools()
37 /******************************************************************************/
39 void AliEveKineTools::SetDaughterPathMarks(TEveElement* cont, AliStack* stack, Bool_t recurse)
41 // Import daughters birth points.
43 TEveElement::List_i iter = cont->BeginChildren();
45 while(iter != cont->EndChildren())
47 TEveTrack* track = dynamic_cast<TEveTrack*>(*iter);
48 TParticle* p = stack->Particle(track->GetLabel());
49 if(p->GetNDaughters()) {
50 Int_t d0 = p->GetDaughter(0), d1 = p->GetDaughter(1);
51 for(int d=d0; d>0 && d<=d1; ++d)
53 TParticle* dp = stack->Particle(d);
54 TEvePathMark* pm = new TEvePathMark(TEvePathMark::kDaughter);
55 pm->fV.Set(dp->Vx(), dp->Vy(), dp->Vz());
56 pm->fP.Set(dp->Px(), dp->Py(), dp->Pz());
58 track->AddPathMark(pm);
61 SetDaughterPathMarks(track, stack, recurse);
67 /******************************************************************************/
72 bool operator()(TEvePathMark* const & a, TEvePathMark* const & b)
73 { return a->fTime < b->fTime; }
76 void slurp_tracks(map<Int_t, TEveTrack*>& tracks, TEveElement* cont, Bool_t recurse)
78 TEveElement::List_i citer = cont->BeginChildren();
79 while(citer != cont->EndChildren())
81 TEveTrack* track = dynamic_cast<TEveTrack*>(*citer);
82 tracks[track->GetLabel()] = track;
84 slurp_tracks(tracks, track, recurse);
91 void AliEveKineTools::SetTrackReferences(TEveElement* cont, TTree* treeTR, Bool_t recurse)
93 // set decay and reference points
95 static const TEveException eH("AliEveKineTools::ImportPathMarks");
98 map<Int_t, TEveTrack*> tracks;
99 slurp_tracks(tracks, cont, recurse);
101 Int_t nPrimaries = (Int_t) treeTR->GetEntries();
102 TIter next(treeTR->GetListOfBranches());
104 Bool_t isRef = kTRUE;
106 while ((el = (TBranchElement*) next()))
108 if (strcmp("AliRun",el->GetName()) == 0)
111 TClonesArray* arr = 0;
112 el->SetAddress(&arr);
113 for (Int_t iPrimPart = 0; iPrimPart<nPrimaries; iPrimPart++)
115 el->GetEntry(iPrimPart);
117 Int_t last_label = -1;
118 map<Int_t, TEveTrack*>::iterator iter = tracks.end();
119 Int_t Nent = arr->GetEntriesFast();
120 for (Int_t iTrackRef = 0; iTrackRef < Nent; iTrackRef++)
122 AliTrackReference* atr = (AliTrackReference*)arr->UncheckedAt(iTrackRef);
124 Int_t label = atr->GetTrack();
126 throw(eH + Form("negative label for entry %d in branch %s.",
127 iTrackRef, el->GetName()));
129 if(label != last_label) {
130 iter = tracks.find(label);
134 if (iter != tracks.end()) {
135 TEvePathMark* pm = new TEvePathMark(isRef ? TEvePathMark::kReference : TEvePathMark::kDecay);
136 pm->fV.Set(atr->X(),atr->Y(), atr->Z());
137 pm->fP.Set(atr->Px(),atr->Py(), atr->Pz());
138 pm->fTime = atr->GetTime();
139 TEveTrack* track = iter->second;
140 track->AddPathMark(pm);
143 } // loop primaries, clones arrays
145 } // end loop through top branches
148 void AliEveKineTools::SortPathMarks(TEveElement* cont, Bool_t recurse)
150 // Sort path-marks for all tracks by time.
153 map<Int_t, TEveTrack*> tracks;
154 slurp_tracks(tracks, cont, recurse);
157 for(map<Int_t, TEveTrack*>::iterator j=tracks.begin(); j!=tracks.end(); ++j)
159 j->second->SortPathMarksByTime();