]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Alieve/KineTools.cxx
Put black-listed classes out of Alieve namespace.
[u/mrichter/AliRoot.git] / EVE / Alieve / KineTools.cxx
1 // $Header$
2
3 #include "KineTools.h"
4
5 #include <TObject.h>
6 #include <TTree.h>
7 #include <TBranchElement.h>
8 #include <TClonesArray.h>
9
10 #include <AliStack.h>
11 #include <AliTrackReference.h>
12
13 #include <TEveTrack.h>
14 #include <TEveElement.h>
15
16 #include <algorithm>
17 #include <map>
18
19 //______________________________________________________________________
20 // KineTools
21 //
22 using namespace Alieve;
23 using namespace std;
24
25 ClassImp(KineTools)
26
27 KineTools::KineTools()
28 {}
29
30 /**************************************************************************/
31
32 void KineTools::SetDaughterPathMarks(TEveElement* cont, AliStack* stack, Bool_t recurse)
33 {
34   // Import daughters birth points.
35
36   TEveElement::List_i  iter = cont->BeginChildren();
37
38   while(iter != cont->EndChildren())
39   {
40     TEveTrack* track = dynamic_cast<TEveTrack*>(*iter); 
41     TParticle* p = stack->Particle(track->GetLabel());
42     if(p->GetNDaughters()) {
43       Int_t d0 = p->GetDaughter(0), d1 = p->GetDaughter(1);
44       for(int d=d0; d>0 && d<=d1; ++d) 
45       { 
46         TParticle* dp = stack->Particle(d);
47         TEvePathMark* pm = new TEvePathMark(TEvePathMark::kDaughter);
48         pm->fV.Set(dp->Vx(), dp->Vy(), dp->Vz());
49         pm->fP.Set(dp->Px(), dp->Py(), dp->Pz()); 
50         pm->fTime = dp->T();
51         track->AddPathMark(pm);
52       }
53       if (recurse)
54         SetDaughterPathMarks(track, stack, recurse);
55     }
56     ++iter;
57   }
58 }
59
60 /**************************************************************************/
61
62 namespace {
63 struct cmp_pathmark
64 {
65   bool operator()(TEvePathMark* const & a, TEvePathMark* const & b)
66   { return a->fTime < b->fTime; }
67 };
68
69 void slurp_tracks(map<Int_t, TEveTrack*>& tracks, TEveElement* cont, Bool_t recurse)
70 {
71   TEveElement::List_i citer = cont->BeginChildren();
72   while(citer != cont->EndChildren())
73   { 
74     TEveTrack* track = dynamic_cast<TEveTrack*>(*citer); 
75     tracks[track->GetLabel()] = track;
76     if (recurse)
77       slurp_tracks(tracks, track, recurse);
78     ++citer;
79   }
80 }
81
82 }
83
84 void KineTools::SetTrackReferences(TEveElement* cont, TTree* treeTR, Bool_t recurse)
85 {
86   // set decay and reference points
87
88   static const TEveException eH("KineTools::ImportPathMarks");
89
90   // Fill map
91   map<Int_t, TEveTrack*> tracks;
92   slurp_tracks(tracks, cont, recurse);
93  
94   Int_t nPrimaries = (Int_t) treeTR->GetEntries();
95   TIter next(treeTR->GetListOfBranches());
96   TBranchElement* el;
97   Bool_t isRef = kTRUE;
98
99   while ((el = (TBranchElement*) next()))
100   {
101     if (strcmp("AliRun",el->GetName()) == 0)
102       isRef = kFALSE;
103
104     TClonesArray* arr = 0;
105     el->SetAddress(&arr);
106     for (Int_t iPrimPart = 0; iPrimPart<nPrimaries; iPrimPart++) 
107     {
108       el->GetEntry(iPrimPart);
109
110       Int_t last_label = -1;
111       map<Int_t, TEveTrack*>::iterator iter = tracks.end(); 
112       Int_t Nent =  arr->GetEntriesFast();
113       for (Int_t iTrackRef = 0; iTrackRef < Nent; iTrackRef++) 
114       {
115         AliTrackReference* atr = (AliTrackReference*)arr->UncheckedAt(iTrackRef);
116
117         Int_t label = atr->GetTrack();
118         if (label < 0)
119           throw(eH + Form("negative label for entry %d in branch %s.",
120                           iTrackRef, el->GetName()));
121         
122         if(label != last_label) {
123           iter = tracks.find(label);
124           last_label = label;
125         }
126
127         if (iter != tracks.end()) {
128           TEvePathMark* pm = new TEvePathMark(isRef ? TEvePathMark::kReference : TEvePathMark::kDecay);
129           pm->fV.Set(atr->X(),atr->Y(), atr->Z());
130           pm->fP.Set(atr->Px(),atr->Py(), atr->Pz());  
131           pm->fTime = atr->GetTime();
132           TEveTrack* track  = iter->second;
133           track->AddPathMark(pm);
134         }
135       } // loop track refs 
136     } // loop primaries, clones arrays
137     delete arr;
138   } // end loop through top branches
139 }
140
141 void KineTools::SortPathMarks(TEveElement* cont, Bool_t recurse)
142 {
143   // Sort path-marks for all tracks by time.
144
145   // Fill map
146   map<Int_t, TEveTrack*> tracks;
147   slurp_tracks(tracks, cont, recurse);
148
149   // sort 
150   for(map<Int_t, TEveTrack*>::iterator j=tracks.begin(); j!=tracks.end(); ++j)
151   {
152     j->second->SortPathMarksByTime();
153   }
154 }