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>
25 //______________________________________________________________________________
28 // Tools for import of kinematics. Preliminary version.
33 ClassImp(AliEveKineTools)
38 typedef std::map<Int_t, TEveTrack*> TrackMap_t;
40 void MapTracks(TrackMap_t& map, TEveElement* cont, Bool_t recurse)
42 TEveElement::List_i i = cont->BeginChildren();
43 while (i != cont->EndChildren()) {
44 TEveTrack* track = dynamic_cast<TEveTrack*>(*i);
45 map[track->GetLabel()] = track;
47 MapTracks(map, track, recurse);
53 /**************************************************************************/
55 void AliEveKineTools::SetDaughterPathMarks(TEveElement* cont, AliStack* stack, Bool_t recurse)
57 // Import daughters birth points.
59 TEveElement::List_i iter = cont->BeginChildren();
60 while(iter != cont->EndChildren())
62 TEveTrack* track = dynamic_cast<TEveTrack*>(*iter);
63 TParticle* p = stack->Particle(track->GetLabel());
64 if(p->GetNDaughters()) {
65 Int_t d0 = p->GetDaughter(0), d1 = p->GetDaughter(1);
66 for(int d=d0; d>0 && d<=d1; ++d)
68 TParticle* dp = stack->Particle(d);
69 TEvePathMark* pm = new TEvePathMark(TEvePathMark::kDaughter);
70 pm->fV.Set(dp->Vx(), dp->Vy(), dp->Vz());
71 pm->fP.Set(dp->Px(), dp->Py(), dp->Pz());
73 track->AddPathMark(pm);
76 SetDaughterPathMarks(track, stack, recurse);
82 /**************************************************************************/
84 void AliEveKineTools::SetTrackReferences(TEveElement* cont, TTree* treeTR, Bool_t recurse)
86 // Set decay and track reference path-marks.
88 static const TEveException eH("AliEveKineTools::ImportPathMarks");
91 MapTracks(map, cont, recurse);
93 Int_t nPrimaries = (Int_t) treeTR->GetEntries();
94 TIter next(treeTR->GetListOfBranches());
98 while ((el = (TBranchElement*) next()))
100 if (strcmp("AliRun",el->GetName()) == 0)
103 TClonesArray* arr = 0;
104 el->SetAddress(&arr);
105 for (Int_t iPrimPart = 0; iPrimPart<nPrimaries; iPrimPart++)
107 el->GetEntry(iPrimPart);
109 Int_t last_label = -1;
110 TrackMap_t::iterator iter = map.end();
111 Int_t Nent = arr->GetEntriesFast();
112 for (Int_t iTrackRef = 0; iTrackRef < Nent; iTrackRef++)
114 AliTrackReference* atr = (AliTrackReference*)arr->UncheckedAt(iTrackRef);
116 Int_t label = atr->GetTrack();
118 throw(eH + Form("negative label for entry %d in branch %s.",
119 iTrackRef, el->GetName()));
121 if(label != last_label) {
122 iter = map.find(label);
126 if (iter != map.end()) {
127 TEvePathMark* pm = new TEvePathMark(isRef ? TEvePathMark::kReference : TEvePathMark::kDecay);
128 pm->fV.Set(atr->X(),atr->Y(), atr->Z());
129 pm->fP.Set(atr->Px(),atr->Py(), atr->Pz());
130 pm->fTime = atr->GetTime();
131 TEveTrack* track = iter->second;
132 track->AddPathMark(pm);
135 } // loop primaries in clones arrays
137 } // end loop through top branches
140 /**************************************************************************/
142 void AliEveKineTools::SortPathMarks(TEveElement* el, Bool_t recurse)
144 // Sort path-marks for all tracks by time.
146 TEveTrack* track = dynamic_cast<TEveTrack*>(el);
147 if(track) track->SortPathMarksByTime();
149 TEveElement::List_i i = el->BeginChildren();
150 while (i != el->EndChildren() && recurse) {
151 track = dynamic_cast<TEveTrack*>(el);
152 if (track) track->SortPathMarksByTime();