]>
Commit | Line | Data |
---|---|---|
d810d0de | 1 | // $Id$ |
2 | // Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007 | |
3 | ||
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 | **************************************************************************/ |
16718cdc | 9 | |
38c0afa3 | 10 | /// \ingroup evemacros |
11 | /// \file kine_tracks.C | |
12 | /// \brief Import tracks from kinematics-tree / particle-stack. | |
13 | /// | |
14 | /// Preliminary/minimal solution. | |
15 | /// | |
16 | /// \author Matevz Tadel & Alja Mrak-Tadel: 2006, 2007 | |
1b337638 | 17 | |
15c12442 | 18 | #if !defined(__CINT__) || defined(__MAKECINT__) |
19 | ||
e383d8e4 | 20 | #include <TParticle.h> |
15c12442 | 21 | #include <TParticlePDG.h> |
22 | ||
3c2901eb | 23 | #include <TEveManager.h> |
24 | #include <TEveTrackPropagator.h> | |
25 | ||
26 | #include <EveBase/AliEveEventManager.h> | |
27 | #include <EveBase/AliEveMagField.h> | |
28 | #include <EveBase/AliEveTrack.h> | |
29 | #include <EveBase/AliEveKineTools.h> | |
30 | ||
31 | #include <AliRunLoader.h> | |
32 | #include <AliStack.h> | |
33 | #include <AliMagF.h> | |
34 | ||
15c12442 | 35 | #endif |
a7867742 | 36 | |
6336e5d7 | 37 | // Use magnetic-field as retrieved from GRP. |
38 | Bool_t g_kine_tracks_true_field = kTRUE; | |
39 | ||
40 | // Use Runge-Kutta track stepper. | |
41 | Bool_t g_kine_tracks_rk_stepper = kFALSE; | |
42 | ||
3c2901eb | 43 | //============================================================================== |
44 | ||
45 | void kine_track_propagator_setup(TEveTrackPropagator* trkProp); | |
46 | ||
47 | TEveTrackList* | |
48 | kine_tracks(Double_t min_pt = 0, Double_t min_p = 0, | |
49 | Bool_t pdg_col = kTRUE, Bool_t recurse = kTRUE, | |
50 | Bool_t use_track_refs = kTRUE); | |
51 | ||
52 | void kine_daughters(AliEveTrack* parent, AliStack* stack, | |
53 | Double_t min_pt, Double_t min_p, | |
54 | Bool_t pdg_col, Bool_t recurse); | |
55 | ||
56 | void set_track_color(AliEveTrack* t, Bool_t pdg_col); | |
57 | Color_t get_pdg_color(Int_t pdg); | |
58 | ||
59 | TEveElement* | |
60 | kine_track(Int_t label, | |
61 | Bool_t import_mother = kTRUE, Bool_t import_daughters = kTRUE, | |
62 | Bool_t pdg_col = kTRUE, Bool_t recurse = kTRUE, | |
63 | TEveElement* cont = 0); | |
64 | ||
65 | void kine_hide_neutrals(TEveElement* el=0, Int_t level=0); | |
6336e5d7 | 66 | |
67 | //============================================================================== | |
68 | ||
69 | void kine_track_propagator_setup(TEveTrackPropagator* trkProp) | |
70 | { | |
71 | AliMagF* fld = AliEveEventManager::AssertMagField(); | |
72 | ||
73 | if (g_kine_tracks_true_field) | |
74 | { | |
75 | trkProp->SetMagFieldObj(new AliEveMagField(fld)); | |
76 | } | |
77 | else | |
78 | { | |
79 | trkProp->SetMagField(-0.1*fld->SolenoidField()); | |
80 | } | |
81 | if (g_kine_tracks_rk_stepper) | |
82 | { | |
83 | trkProp->SetStepper(TEveTrackPropagator::kRungeKutta); | |
84 | } | |
85 | } | |
86 | ||
87 | //============================================================================== | |
88 | ||
84aff7a4 | 89 | TEveTrackList* |
3c2901eb | 90 | kine_tracks(Double_t min_pt, Double_t min_p, |
91 | Bool_t pdg_col, Bool_t recurse, | |
92 | Bool_t use_track_refs) | |
1b337638 | 93 | { |
d810d0de | 94 | AliRunLoader* rl = AliEveEventManager::AssertRunLoader(); |
1b337638 | 95 | rl->LoadKinematics(); |
96 | AliStack* stack = rl->Stack(); | |
8661a211 | 97 | if (!stack) |
98 | { | |
c505cf7c | 99 | Error("kine_tracks", "can not get kinematics."); |
1b337638 | 100 | return 0; |
101 | } | |
102 | ||
84aff7a4 | 103 | gEve->DisableRedraw(); |
51346b82 | 104 | |
105 | TEveTrackList* cont = new TEveTrackList("Kine Tracks"); | |
fbc350a3 | 106 | cont->SetMainColor(3); |
8661a211 | 107 | TEveTrackPropagator* trkProp = cont->GetPropagator(); |
108 | ||
6336e5d7 | 109 | kine_track_propagator_setup(trkProp); |
1b337638 | 110 | |
84aff7a4 | 111 | gEve->AddElement(cont); |
1b337638 | 112 | Int_t count = 0; |
92bd3b8a | 113 | Int_t Np = stack->GetNprimary(); |
114 | for (Int_t i = 0; i < Np; ++i) | |
43d68fc4 | 115 | { |
92bd3b8a | 116 | TParticle* p = stack->Particle(i); |
117 | if (p->GetStatusCode() <= 1) | |
43d68fc4 | 118 | { |
ef9d2241 | 119 | if (p->Pt() < min_pt && p->P() < min_p) continue; |
43d68fc4 | 120 | |
121 | ++count; | |
0e33c639 | 122 | AliEveTrack* track = new AliEveTrack(p, i, trkProp); |
51346b82 | 123 | |
43d68fc4 | 124 | //PH The line below is replaced waiting for a fix in Root |
125 | //PH which permits to use variable siza arguments in CINT | |
126 | //PH on some platforms (alphalinuxgcc, solariscc5, etc.) | |
127 | //PH track->SetName(Form("%s [%d]", p->GetName(), i)); | |
128 | char form[1000]; | |
129 | sprintf(form,"%s [%d]", p->GetName(), i); | |
130 | track->SetName(form); | |
fc9514f5 | 131 | track->SetStdTitle(); |
a77bb3bc | 132 | Int_t ml = p->GetMother(0); |
133 | if (ml != -1) | |
134 | { | |
135 | track->SetTitle(Form("%s\nMother label=%d\nMother Pdg=%d", | |
136 | track->GetElementTitle(), | |
137 | ml, stack->Particle(ml)->GetPdgCode())); | |
138 | } | |
fc9514f5 | 139 | set_track_color(track, pdg_col); |
140 | ||
84aff7a4 | 141 | gEve->AddElement(track, cont); |
ef9d2241 | 142 | |
143 | if (recurse) | |
144 | kine_daughters(track, stack, min_pt, min_p, pdg_col, recurse); | |
43d68fc4 | 145 | } |
1b337638 | 146 | } |
ef9d2241 | 147 | |
43d68fc4 | 148 | // set path marks |
51346b82 | 149 | AliEveKineTools kt; |
ef9d2241 | 150 | kt.SetDaughterPathMarks(cont, stack, recurse); |
32e219c2 | 151 | if (use_track_refs && rl->LoadTrackRefs() == 0) |
9a040a65 | 152 | { |
153 | kt.SetTrackReferences(cont, rl->TreeTR(), recurse); | |
8661a211 | 154 | trkProp->SetEditPathMarks(kTRUE); |
9a040a65 | 155 | } |
156 | kt.SortPathMarks(cont, recurse); | |
43d68fc4 | 157 | |
ef9d2241 | 158 | //PH const Text_t* tooltip = Form("min pT=%.2lf, min P=%.2lf), N=%d", min_pt, min_p, count); |
7be1e8cd | 159 | char tooltip[1000]; |
ef9d2241 | 160 | sprintf(tooltip,"min pT=%.2lf, min P=%.2lf), N=%d", min_pt, min_p, count); |
1b337638 | 161 | cont->SetTitle(tooltip); // Not broadcasted automatically ... |
1b337638 | 162 | |
ef9d2241 | 163 | cont->MakeTracks(recurse); |
84aff7a4 | 164 | gEve->EnableRedraw(); |
165 | gEve->Redraw3D(); | |
1b337638 | 166 | |
167 | return cont; | |
168 | } | |
a7867742 | 169 | |
0e33c639 | 170 | void kine_daughters(AliEveTrack* parent, AliStack* stack, |
ef9d2241 | 171 | Double_t min_pt, Double_t min_p, |
172 | Bool_t pdg_col, Bool_t recurse) | |
173 | { | |
174 | TParticle *p = stack->Particle(parent->GetLabel()); | |
51346b82 | 175 | if (p->GetNDaughters() > 0) |
ef9d2241 | 176 | { |
84aff7a4 | 177 | TEveTrackPropagator* rs = parent->GetPropagator(); |
51346b82 | 178 | for (int d=p->GetFirstDaughter(); d>0 && d<=p->GetLastDaughter(); ++d) |
179 | { | |
ef9d2241 | 180 | TParticle* dp = stack->Particle(d); |
181 | if (dp->Pt() < min_pt && dp->P() < min_p) continue; | |
182 | ||
0e33c639 | 183 | AliEveTrack* dtrack = new AliEveTrack(dp, d, rs); |
ef9d2241 | 184 | char form[1000]; |
185 | sprintf(form,"%s [%d]", dp->GetName(), d); | |
186 | dtrack->SetName(form); | |
fc9514f5 | 187 | dtrack->SetStdTitle(); |
188 | set_track_color(dtrack, pdg_col); | |
189 | ||
84aff7a4 | 190 | gEve->AddElement(dtrack, parent); |
ef9d2241 | 191 | |
192 | if (recurse) | |
193 | kine_daughters(dtrack, stack, min_pt, min_p, pdg_col, recurse); | |
194 | } | |
195 | } | |
196 | } | |
a7867742 | 197 | |
3c2901eb | 198 | //============================================================================== |
199 | ||
200 | void set_track_color(AliEveTrack* t, Bool_t pdg_col) | |
fc9514f5 | 201 | { |
202 | if (pdg_col) | |
203 | t->SetMainColor(get_pdg_color(t->GetPdg())); | |
204 | else | |
fbc350a3 | 205 | t->SetMainColor(30); |
fc9514f5 | 206 | } |
207 | ||
539d6798 | 208 | Color_t get_pdg_color(Int_t pdg) |
209 | { | |
fc9514f5 | 210 | // PDG color indices |
211 | static const Color_t DefCol = 30; | |
212 | static const Color_t ECol = 5; | |
213 | static const Color_t MuCol = 6; | |
51346b82 | 214 | static const Color_t GammaCol = 7; |
fc9514f5 | 215 | static const Color_t MesCol1 = 3; |
216 | static const Color_t MesCol2 = 38; | |
217 | static const Color_t BarCol = 10; | |
218 | ||
219 | Int_t pdga = TMath::Abs(pdg); | |
220 | Color_t col = DefCol; | |
a7867742 | 221 | |
222 | // elementary particles | |
223 | if (pdga < 100) { | |
224 | switch (pdga) { | |
51346b82 | 225 | case 11: |
226 | col = ECol; break; | |
a7867742 | 227 | case 12: |
228 | col = MuCol; break; | |
229 | case 22: | |
230 | col = GammaCol; break; | |
231 | } | |
232 | } | |
fc9514f5 | 233 | // mesons and barions |
234 | else if (pdga < 100000) { | |
a7867742 | 235 | Int_t i = pdga; |
3c2901eb | 236 | // Int_t i0 = i%10; // Not used at the moment. |
237 | i /= 10; | |
51346b82 | 238 | Int_t i1 = i%10; i /= 10; |
239 | Int_t i2 = i%10; i /= 10; | |
240 | Int_t i3 = i%10; i /= 10; | |
a7867742 | 241 | Int_t i4 = i%10; |
242 | //printf("pdg(%d) quark indices (%d,%d,%d,%d,%d) \n",pdg, i4,i3,i2, i1, i0); | |
243 | // meson | |
244 | if ((i3 == 0) && ( i4 < 2)){ | |
245 | col = MesCol1; // quarks: i1,i2 (spin = i0) | |
246 | if(i1 == 3 || i2 == 3) | |
247 | col = MesCol2; | |
248 | } // barion | |
249 | else if ( i2 >= i1 && i3 >= i2 ) { | |
250 | col = BarCol; // quarks: i1,i2, i3 (spin = i0)) | |
251 | } | |
252 | } | |
fc9514f5 | 253 | |
a7867742 | 254 | return col; |
255 | } | |
c7b57c0b | 256 | |
3c2901eb | 257 | //============================================================================== |
c7b57c0b | 258 | |
84aff7a4 | 259 | TEveElement* |
b65b3044 | 260 | kine_track(Int_t label, |
3c2901eb | 261 | Bool_t import_mother, Bool_t import_daughters, |
262 | Bool_t pdg_col, Bool_t recurse, | |
263 | TEveElement* cont) | |
c7b57c0b | 264 | { |
fc9514f5 | 265 | // Create mother and daughters tracks with given label. |
266 | // mother -> particle with label | |
267 | // daughters -> daughters of label | |
268 | ||
c7b57c0b | 269 | if (label < 0) { |
270 | Warning("kine_track", "label not set."); | |
271 | return 0; | |
272 | } | |
51346b82 | 273 | |
d810d0de | 274 | AliRunLoader* rl = AliEveEventManager::AssertRunLoader(); |
c7b57c0b | 275 | rl->LoadKinematics(); |
276 | AliStack* stack = rl->Stack(); | |
c505cf7c | 277 | if (!stack) |
278 | { | |
279 | Warning("kine_track", "can not get kinematics."); | |
280 | return 0; | |
281 | } | |
f1b2cd0b | 282 | if (label >= stack->GetNtrack()) |
283 | { | |
284 | Warning("kine_track", "label out of range."); | |
285 | return 0; | |
286 | } | |
287 | ||
c7b57c0b | 288 | TParticle* p = stack->Particle(label); |
289 | ||
b65b3044 | 290 | if (import_mother || (import_daughters && p->GetNDaughters())) |
c7b57c0b | 291 | { |
84aff7a4 | 292 | TEveTrackPropagator* rs = 0; |
2caed564 | 293 | |
b65b3044 | 294 | if (cont == 0) |
295 | { | |
84aff7a4 | 296 | TEveTrackList* tlist = new TEveTrackList |
ef9d2241 | 297 | (Form("Kinematics of %d", label, p->GetNDaughters())); |
298 | cont = tlist; | |
c7b57c0b | 299 | |
8661a211 | 300 | TEveTrackPropagator* trkProp = tlist->GetPropagator(); |
301 | ||
6336e5d7 | 302 | kine_track_propagator_setup(trkProp); |
8661a211 | 303 | |
c7b57c0b | 304 | char tooltip[1000]; |
b65b3044 | 305 | sprintf(tooltip,"Ndaughters=%d", p->GetNDaughters()); |
ef9d2241 | 306 | tlist->SetTitle(tooltip); |
9fa23a72 | 307 | trkProp->SetMaxOrbs(2); |
8661a211 | 308 | trkProp->SetEditPathMarks(kTRUE); |
fc9514f5 | 309 | |
84aff7a4 | 310 | gEve->AddElement(cont); |
311 | rs = tlist->GetPropagator(); | |
2caed564 | 312 | } |
ef9d2241 | 313 | else |
314 | { | |
0e33c639 | 315 | // check if container is TEveTrackList or AliEveTrack (has rnr-style) |
316 | AliEveTrack* t = dynamic_cast<AliEveTrack*>(cont); | |
fc9514f5 | 317 | if (t) { |
84aff7a4 | 318 | rs = t->GetPropagator(); |
fc9514f5 | 319 | } else { |
84aff7a4 | 320 | TEveTrackList* l = dynamic_cast<TEveTrackList*>(cont); |
fc9514f5 | 321 | if (l) |
84aff7a4 | 322 | rs = l->GetPropagator(); |
ef9d2241 | 323 | else |
2caed564 | 324 | Error("kine_tracks.C", "TrackRenderStyle not set."); |
2caed564 | 325 | } |
c7b57c0b | 326 | } |
2caed564 | 327 | |
b65b3044 | 328 | if (import_mother) |
329 | { | |
0e33c639 | 330 | AliEveTrack* track = new AliEveTrack(p, label, rs); |
c7b57c0b | 331 | char form[1000]; |
332 | sprintf(form,"%s [%d]", p->GetName(), label); | |
333 | track->SetName(form); | |
fc9514f5 | 334 | track->SetStdTitle(); |
335 | set_track_color(track, pdg_col); | |
2caed564 | 336 | |
fc9514f5 | 337 | track->MakeTrack(); |
84aff7a4 | 338 | gEve->AddElement(track, cont); |
fc9514f5 | 339 | cont = track; |
c7b57c0b | 340 | } |
341 | ||
51346b82 | 342 | if (import_daughters && p->GetNDaughters()) |
c7b57c0b | 343 | { |
51346b82 | 344 | for (int d=p->GetFirstDaughter(); d>0 && d<=p->GetLastDaughter(); ++d) |
345 | { | |
c7b57c0b | 346 | TParticle* dp = stack->Particle(d); |
0e33c639 | 347 | AliEveTrack* track = new AliEveTrack(dp, d, rs); |
c7b57c0b | 348 | char form[1000]; |
349 | sprintf(form,"%s [%d]", dp->GetName(), d); | |
350 | track->SetName(form); | |
fc9514f5 | 351 | track->SetStdTitle(); |
352 | set_track_color(track, pdg_col); | |
353 | ||
2caed564 | 354 | track->MakeTrack(); |
84aff7a4 | 355 | gEve->AddElement(track, cont); |
fc9514f5 | 356 | |
357 | if (recurse) | |
358 | kine_daughters(track, stack, 0, 0, pdg_col, recurse); | |
c7b57c0b | 359 | } |
360 | } | |
361 | } | |
362 | ||
84aff7a4 | 363 | gEve->Redraw3D(); |
c7b57c0b | 364 | return cont; |
365 | } | |
2caed564 | 366 | |
3c2901eb | 367 | //============================================================================== |
368 | ||
369 | void kine_hide_neutrals(TEveElement* el, Int_t level) | |
370 | { | |
371 | if (el == 0) | |
372 | { | |
373 | el = gEve->GetCurrentEvent()->FindChild("Kine Tracks"); | |
374 | if (!el) | |
375 | return; | |
376 | } | |
377 | ||
378 | TEveTrack* t = dynamic_cast<TEveTrack*>(el); | |
379 | if (t && t->GetCharge() == 0) | |
380 | t->SetRnrSelf(kFALSE); | |
381 | ||
382 | for (TEveElement::List_i i = el->BeginChildren(); i != el->EndChildren(); ++i) | |
383 | { | |
384 | kine_hide_neutrals(*i, level + 1); | |
385 | } | |
386 | ||
387 | if (level == 0) | |
388 | gEve->Redraw3D(); | |
389 | } |