New files: used in alice-macros/kine_tracks.C to set path marks in imported tracks.
[u/mrichter/AliRoot.git] / EVE / Alieve / KineTools.cxx
CommitLineData
c63fcc1d 1// $Header$
2
3#include "KineTools.h"
4
5#include <TObject.h>
6#include <TTree.h>
7#include <TBranchElement.h>
8#include <AliStack.h>
9#include <AliTrackReference.h>
10
11#include "Reve/Track.h"
12#include "Reve/RenderElement.h"
13
14#include <algorithm>
15
16//______________________________________________________________________
17// KineTools
18//
19
20using namespace Reve;
21using namespace Alieve;
22using namespace std;
23
24ClassImp(KineTools)
25
26KineTools::KineTools()
27{
28
29}
30
31/**************************************************************************/
32void KineTools::SetDaughterPathMarks(TrackList* cont, AliStack* stack )
33{
34 // import daughters birth points
35 RenderElement::List_i iter = cont->BeginChildren();
36
37 while(iter != cont->EndChildren())
38 {
39 Track* track = dynamic_cast<Track*>(*iter);
40 TParticle* p = stack->Particle(track->GetLabel());
41 if(p->GetNDaughters()) {
42 Int_t d0 = p->GetDaughter(0), d1 = p->GetDaughter(1);
43 for(int d=d0; d>0 && d<=d1;++d)
44 {
45 TParticle* dp = stack->Particle(d);
46 Reve::PathMark* pm = new PathMark( PathMark::Daughter);
47 pm->V.Set(dp->Vx(),dp->Vy(), dp->Vz());
48 pm->P.Set(dp->Px(),dp->Py(), dp->Pz());
49 pm->time = dp->T();
50 track->AddPathMark(pm);
51 }
52 }
53 ++iter;
54 }
55}
56
57/**************************************************************************/
58
59namespace {
60struct cmp_pathmark {
61 bool operator()(PathMark* const & a, PathMark* const & b)
62 { return a->time < b->time; }
63};
64}
65
66void KineTools::SetPathMarks(TrackList* cont, AliStack* stack , TTree* treeTR)
67{
68 // set decay and reference points
69
70 static const Exc_t eH("KineTools::ImportPathMarks");
71
72 if(treeTR == 0) {
73 SetDaughterPathMarks(cont, stack);
74 return;
75 }
76
77 map<Int_t, vector<PathMark*> > refs;
78
79 Int_t nPrimaries = (Int_t) treeTR->GetEntries();
80 TIter next(treeTR->GetListOfBranches());
81 TBranchElement* el;
82 Bool_t isRef = kTRUE;
83 treeTR->SetBranchStatus("*",0);
84
85 while ((el = (TBranchElement*) next()))
86 {
87 if (strcmp("AliRun",el->GetName()) == 0)
88 isRef = kFALSE;
89
90 treeTR->SetBranchStatus(Form("%s*", el->GetName()), 1);
91 for (Int_t iPrimPart = 0; iPrimPart<nPrimaries; iPrimPart++)
92 {
93
94 TClonesArray* arr = 0;
95 treeTR->SetBranchAddress(el->GetName(), &arr);
96 treeTR->GetEntry(iPrimPart);
97
98 for (Int_t iTrackRef = 0; iTrackRef < arr->GetEntriesFast(); iTrackRef++)
99 {
100 AliTrackReference* atr = (AliTrackReference*)arr->At(iTrackRef);
101 Int_t track = atr->GetTrack();
102 if(atr->TestBit(TObject::kNotDeleted)) {
103 if(track > 0)
104 {
105 PathMark* pm;
106 if(isRef)
107 pm = new PathMark(PathMark::Reference);
108 else
109 pm = new PathMark(PathMark::Decay);
110
111 pm->V.Set(atr->X(),atr->Y(), atr->Z());
112 pm->P.Set(atr->Px(),atr->Py(), atr->Pz());
113 pm->time = atr->GetTime();
114
115 vector<PathMark*>& v = refs[track];
116 v.push_back(pm);
117 }
118 else
119 throw(eH + "negative label for entry " + Form("%d",iTrackRef) + " in branch " + el->GetName()+ ".");
120 }
121 } // loop track refs
122 treeTR->SetBranchAddress(el->GetName(), 0);
123 } // loop primaries, clones arrays
124 treeTR->SetBranchStatus(Form("%s*", el->GetName()), 0);
125 } // end loop through top branches
126
127
128 // sort references and add it to tracks
129 RenderElement::List_i cit = cont->BeginChildren();
130 while(cit != cont->EndChildren())
131 {
132 Track* track = dynamic_cast<Track*>(*cit);
133
134 // add daughters path marks in the map
135 TParticle* p = stack->Particle(track->GetLabel());
136 if(p->GetNDaughters()) {
137 for(int d=p->GetFirstDaughter(); d>0 && d<=p->GetLastDaughter();++d)
138 {
139 TParticle* dp = stack->Particle(d);
140 Reve::PathMark* pm = new PathMark( PathMark::Daughter);
141 pm->V.Set(dp->Vx(),dp->Vy(), dp->Vz());
142 pm->P.Set(dp->Px(),dp->Py(), dp->Pz());
143 pm->time = dp->T();
144 vector<PathMark*>& v = refs[track->GetLabel()];
145 v.push_back(pm);
146 }
147 }
148
149 map<Int_t, vector<PathMark*> > ::iterator ri = refs.find(track->GetLabel());
150 if(ri != refs.end()) {
151 vector<PathMark*>& v = ri->second;
152 sort(v.begin(), v.end(), cmp_pathmark());
153 for(vector<PathMark*>::iterator i=v.begin(); i!=v.end(); ++i){
154 track->AddPathMark(*i);
155 }
156 }
157 ++cit;
158 }
159}