c63fcc1d |
1 | // $Header$ |
2 | |
3 | #include "KineTools.h" |
4 | |
5 | #include <TObject.h> |
6 | #include <TTree.h> |
7 | #include <TBranchElement.h> |
7704f096 |
8 | #include <TClonesArray.h> |
9 | |
c63fcc1d |
10 | #include <AliStack.h> |
11 | #include <AliTrackReference.h> |
12 | |
84aff7a4 |
13 | #include <TEveTrack.h> |
14 | #include <TEveElement.h> |
c63fcc1d |
15 | |
16 | #include <algorithm> |
7704f096 |
17 | #include <map> |
c63fcc1d |
18 | |
19 | //______________________________________________________________________ |
20 | // KineTools |
21 | // |
c63fcc1d |
22 | using namespace Alieve; |
23 | using namespace std; |
24 | |
25 | ClassImp(KineTools) |
26 | |
27 | KineTools::KineTools() |
76461dad |
28 | {} |
c63fcc1d |
29 | |
30 | /**************************************************************************/ |
76461dad |
31 | |
84aff7a4 |
32 | void KineTools::SetDaughterPathMarks(TEveElement* cont, AliStack* stack, Bool_t recurse) |
c63fcc1d |
33 | { |
76461dad |
34 | // Import daughters birth points. |
35 | |
84aff7a4 |
36 | TEveElement::List_i iter = cont->BeginChildren(); |
c63fcc1d |
37 | |
38 | while(iter != cont->EndChildren()) |
39 | { |
84aff7a4 |
40 | TEveTrack* track = dynamic_cast<TEveTrack*>(*iter); |
c63fcc1d |
41 | TParticle* p = stack->Particle(track->GetLabel()); |
42 | if(p->GetNDaughters()) { |
43 | Int_t d0 = p->GetDaughter(0), d1 = p->GetDaughter(1); |
27aa96b0 |
44 | for(int d=d0; d>0 && d<=d1; ++d) |
c63fcc1d |
45 | { |
46 | TParticle* dp = stack->Particle(d); |
84aff7a4 |
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(); |
c63fcc1d |
51 | track->AddPathMark(pm); |
52 | } |
27aa96b0 |
53 | if (recurse) |
54 | SetDaughterPathMarks(track, stack, recurse); |
c63fcc1d |
55 | } |
56 | ++iter; |
57 | } |
58 | } |
59 | |
60 | /**************************************************************************/ |
61 | |
62 | namespace { |
974767e6 |
63 | struct cmp_pathmark |
64 | { |
84aff7a4 |
65 | bool operator()(TEvePathMark* const & a, TEvePathMark* const & b) |
66 | { return a->fTime < b->fTime; } |
c63fcc1d |
67 | }; |
c63fcc1d |
68 | |
84aff7a4 |
69 | void slurp_tracks(map<Int_t, TEveTrack*>& tracks, TEveElement* cont, Bool_t recurse) |
c63fcc1d |
70 | { |
84aff7a4 |
71 | TEveElement::List_i citer = cont->BeginChildren(); |
1d74e2b0 |
72 | while(citer != cont->EndChildren()) |
73 | { |
84aff7a4 |
74 | TEveTrack* track = dynamic_cast<TEveTrack*>(*citer); |
1d74e2b0 |
75 | tracks[track->GetLabel()] = track; |
974767e6 |
76 | if (recurse) |
77 | slurp_tracks(tracks, track, recurse); |
1d74e2b0 |
78 | ++citer; |
c63fcc1d |
79 | } |
974767e6 |
80 | } |
81 | |
82 | } |
83 | |
84aff7a4 |
84 | void KineTools::SetTrackReferences(TEveElement* cont, TTree* treeTR, Bool_t recurse) |
974767e6 |
85 | { |
86 | // set decay and reference points |
87 | |
84aff7a4 |
88 | static const TEveException eH("KineTools::ImportPathMarks"); |
974767e6 |
89 | |
90 | // Fill map |
84aff7a4 |
91 | map<Int_t, TEveTrack*> tracks; |
974767e6 |
92 | slurp_tracks(tracks, cont, recurse); |
1d74e2b0 |
93 | |
c63fcc1d |
94 | Int_t nPrimaries = (Int_t) treeTR->GetEntries(); |
95 | TIter next(treeTR->GetListOfBranches()); |
96 | TBranchElement* el; |
97 | Bool_t isRef = kTRUE; |
c63fcc1d |
98 | |
99 | while ((el = (TBranchElement*) next())) |
100 | { |
101 | if (strcmp("AliRun",el->GetName()) == 0) |
102 | isRef = kFALSE; |
103 | |
1d74e2b0 |
104 | TClonesArray* arr = 0; |
105 | el->SetAddress(&arr); |
c63fcc1d |
106 | for (Int_t iPrimPart = 0; iPrimPart<nPrimaries; iPrimPart++) |
107 | { |
1d74e2b0 |
108 | el->GetEntry(iPrimPart); |
109 | |
110 | Int_t last_label = -1; |
84aff7a4 |
111 | map<Int_t, TEveTrack*>::iterator iter = tracks.end(); |
1d74e2b0 |
112 | Int_t Nent = arr->GetEntriesFast(); |
113 | for (Int_t iTrackRef = 0; iTrackRef < Nent; iTrackRef++) |
c63fcc1d |
114 | { |
1d74e2b0 |
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()) { |
84aff7a4 |
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; |
1d74e2b0 |
133 | track->AddPathMark(pm); |
c63fcc1d |
134 | } |
135 | } // loop track refs |
c63fcc1d |
136 | } // loop primaries, clones arrays |
1d74e2b0 |
137 | delete arr; |
c63fcc1d |
138 | } // end loop through top branches |
27aa96b0 |
139 | } |
140 | |
84aff7a4 |
141 | void KineTools::SortPathMarks(TEveElement* cont, Bool_t recurse) |
27aa96b0 |
142 | { |
143 | // Sort path-marks for all tracks by time. |
144 | |
145 | // Fill map |
84aff7a4 |
146 | map<Int_t, TEveTrack*> tracks; |
27aa96b0 |
147 | slurp_tracks(tracks, cont, recurse); |
c63fcc1d |
148 | |
1d74e2b0 |
149 | // sort |
84aff7a4 |
150 | for(map<Int_t, TEveTrack*>::iterator j=tracks.begin(); j!=tracks.end(); ++j) |
974767e6 |
151 | { |
27aa96b0 |
152 | j->second->SortPathMarksByTime(); |
c63fcc1d |
153 | } |
154 | } |