d810d0de |
1 | // $Id$ |
2 | // Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007 |
c63fcc1d |
3 | |
d810d0de |
4 | /************************************************************************** |
5 | * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. * |
6 | * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for * |
51346b82 |
7 | * full copyright notice. * |
d810d0de |
8 | **************************************************************************/ |
9 | |
10 | #include "AliEveKineTools.h" |
c63fcc1d |
11 | |
12 | #include <TObject.h> |
13 | #include <TTree.h> |
14 | #include <TBranchElement.h> |
7704f096 |
15 | #include <TClonesArray.h> |
16 | |
c63fcc1d |
17 | #include <AliStack.h> |
18 | #include <AliTrackReference.h> |
19 | |
84aff7a4 |
20 | #include <TEveTrack.h> |
21 | #include <TEveElement.h> |
c63fcc1d |
22 | |
7704f096 |
23 | #include <map> |
c63fcc1d |
24 | |
57ffa5fb |
25 | //______________________________________________________________________________ |
d810d0de |
26 | // AliEveKineTools |
c63fcc1d |
27 | // |
40790e5b |
28 | // Tools for import of kinematics. Preliminary version. |
29 | // |
d810d0de |
30 | |
c63fcc1d |
31 | using namespace std; |
32 | |
d810d0de |
33 | ClassImp(AliEveKineTools) |
c63fcc1d |
34 | |
c63fcc1d |
35 | |
40790e5b |
36 | namespace { |
37 | |
38 | typedef std::map<Int_t, TEveTrack*> TrackMap_t; |
39 | |
40 | void MapTracks(TrackMap_t& map, TEveElement* cont, Bool_t recurse) |
41 | { |
42 | TEveElement::List_i i = cont->BeginChildren(); |
43 | while (i != cont->EndChildren()) { |
44 | TEveTrack* track = dynamic_cast<TEveTrack*>(*i); |
45 | map[track->GetLabel()] = track; |
46 | if (recurse) |
47 | MapTracks(map, track, recurse); |
48 | ++i; |
49 | } |
50 | } |
51 | } |
52 | |
53 | /**************************************************************************/ |
76461dad |
54 | |
d810d0de |
55 | void AliEveKineTools::SetDaughterPathMarks(TEveElement* cont, AliStack* stack, Bool_t recurse) |
c63fcc1d |
56 | { |
76461dad |
57 | // Import daughters birth points. |
58 | |
84aff7a4 |
59 | TEveElement::List_i iter = cont->BeginChildren(); |
c63fcc1d |
60 | while(iter != cont->EndChildren()) |
61 | { |
51346b82 |
62 | TEveTrack* track = dynamic_cast<TEveTrack*>(*iter); |
c63fcc1d |
63 | TParticle* p = stack->Particle(track->GetLabel()); |
64 | if(p->GetNDaughters()) { |
65 | Int_t d0 = p->GetDaughter(0), d1 = p->GetDaughter(1); |
51346b82 |
66 | for(int d=d0; d>0 && d<=d1; ++d) |
67 | { |
c63fcc1d |
68 | TParticle* dp = stack->Particle(d); |
84aff7a4 |
69 | TEvePathMark* pm = new TEvePathMark(TEvePathMark::kDaughter); |
70 | pm->fV.Set(dp->Vx(), dp->Vy(), dp->Vz()); |
51346b82 |
71 | pm->fP.Set(dp->Px(), dp->Py(), dp->Pz()); |
84aff7a4 |
72 | pm->fTime = dp->T(); |
c63fcc1d |
73 | track->AddPathMark(pm); |
74 | } |
27aa96b0 |
75 | if (recurse) |
76 | SetDaughterPathMarks(track, stack, recurse); |
c63fcc1d |
77 | } |
78 | ++iter; |
79 | } |
80 | } |
81 | |
40790e5b |
82 | /**************************************************************************/ |
974767e6 |
83 | |
d810d0de |
84 | void AliEveKineTools::SetTrackReferences(TEveElement* cont, TTree* treeTR, Bool_t recurse) |
974767e6 |
85 | { |
40790e5b |
86 | // Set decay and track reference path-marks. |
974767e6 |
87 | |
d810d0de |
88 | static const TEveException eH("AliEveKineTools::ImportPathMarks"); |
974767e6 |
89 | |
40790e5b |
90 | TrackMap_t map; |
91 | MapTracks(map, cont, recurse); |
51346b82 |
92 | |
c63fcc1d |
93 | Int_t nPrimaries = (Int_t) treeTR->GetEntries(); |
94 | TIter next(treeTR->GetListOfBranches()); |
95 | TBranchElement* el; |
96 | Bool_t isRef = kTRUE; |
c63fcc1d |
97 | |
98 | while ((el = (TBranchElement*) next())) |
99 | { |
100 | if (strcmp("AliRun",el->GetName()) == 0) |
101 | isRef = kFALSE; |
102 | |
1d74e2b0 |
103 | TClonesArray* arr = 0; |
104 | el->SetAddress(&arr); |
51346b82 |
105 | for (Int_t iPrimPart = 0; iPrimPart<nPrimaries; iPrimPart++) |
c63fcc1d |
106 | { |
1d74e2b0 |
107 | el->GetEntry(iPrimPart); |
108 | |
109 | Int_t last_label = -1; |
40790e5b |
110 | TrackMap_t::iterator iter = map.end(); |
1d74e2b0 |
111 | Int_t Nent = arr->GetEntriesFast(); |
51346b82 |
112 | for (Int_t iTrackRef = 0; iTrackRef < Nent; iTrackRef++) |
c63fcc1d |
113 | { |
1d74e2b0 |
114 | AliTrackReference* atr = (AliTrackReference*)arr->UncheckedAt(iTrackRef); |
115 | |
116 | Int_t label = atr->GetTrack(); |
117 | if (label < 0) |
118 | throw(eH + Form("negative label for entry %d in branch %s.", |
119 | iTrackRef, el->GetName())); |
51346b82 |
120 | |
1d74e2b0 |
121 | if(label != last_label) { |
40790e5b |
122 | iter = map.find(label); |
1d74e2b0 |
123 | last_label = label; |
124 | } |
125 | |
40790e5b |
126 | if (iter != map.end()) { |
84aff7a4 |
127 | TEvePathMark* pm = new TEvePathMark(isRef ? TEvePathMark::kReference : TEvePathMark::kDecay); |
128 | pm->fV.Set(atr->X(),atr->Y(), atr->Z()); |
51346b82 |
129 | pm->fP.Set(atr->Px(),atr->Py(), atr->Pz()); |
84aff7a4 |
130 | pm->fTime = atr->GetTime(); |
131 | TEveTrack* track = iter->second; |
1d74e2b0 |
132 | track->AddPathMark(pm); |
c63fcc1d |
133 | } |
51346b82 |
134 | } // loop track refs |
40790e5b |
135 | } // loop primaries in clones arrays |
1d74e2b0 |
136 | delete arr; |
c63fcc1d |
137 | } // end loop through top branches |
27aa96b0 |
138 | } |
139 | |
40790e5b |
140 | /**************************************************************************/ |
141 | |
142 | void AliEveKineTools::SortPathMarks(TEveElement* el, Bool_t recurse) |
27aa96b0 |
143 | { |
144 | // Sort path-marks for all tracks by time. |
145 | |
40790e5b |
146 | TEveTrack* track = dynamic_cast<TEveTrack*>(el); |
147 | if(track) track->SortPathMarksByTime(); |
c63fcc1d |
148 | |
40790e5b |
149 | TEveElement::List_i i = el->BeginChildren(); |
150 | while (i != el->EndChildren() && recurse) { |
151 | track = dynamic_cast<TEveTrack*>(el); |
152 | if (track) track->SortPathMarksByTime(); |
153 | i++; |
c63fcc1d |
154 | } |
155 | } |