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