-- added EsdCollector and change AliReconstruction options so that the ProcessHLTOUT...
[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
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.
38Bool_t g_kine_tracks_true_field = kTRUE;
39
40// Use Runge-Kutta track stepper.
41Bool_t g_kine_tracks_rk_stepper = kFALSE;
42
3c2901eb 43//==============================================================================
44
45void kine_track_propagator_setup(TEveTrackPropagator* trkProp);
46
47TEveTrackList*
48kine_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
52void kine_daughters(AliEveTrack* parent, AliStack* stack,
53 Double_t min_pt, Double_t min_p,
54 Bool_t pdg_col, Bool_t recurse);
55
56void set_track_color(AliEveTrack* t, Bool_t pdg_col);
57Color_t get_pdg_color(Int_t pdg);
58
59TEveElement*
60kine_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
65void kine_hide_neutrals(TEveElement* el=0, Int_t level=0);
6336e5d7 66
67//==============================================================================
68
69void 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 89TEveTrackList*
3c2901eb 90kine_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 {
1b337638 99 Error("kine_tracks.C", "can not get kinematics.");
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 170void 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
200void 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 208Color_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 259TEveElement*
b65b3044 260kine_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();
f1b2cd0b 277 if (label >= stack->GetNtrack())
278 {
279 Warning("kine_track", "label out of range.");
280 return 0;
281 }
282
c7b57c0b 283 TParticle* p = stack->Particle(label);
284
b65b3044 285 if (import_mother || (import_daughters && p->GetNDaughters()))
c7b57c0b 286 {
84aff7a4 287 TEveTrackPropagator* rs = 0;
2caed564 288
b65b3044 289 if (cont == 0)
290 {
84aff7a4 291 TEveTrackList* tlist = new TEveTrackList
ef9d2241 292 (Form("Kinematics of %d", label, p->GetNDaughters()));
293 cont = tlist;
c7b57c0b 294
8661a211 295 TEveTrackPropagator* trkProp = tlist->GetPropagator();
296
6336e5d7 297 kine_track_propagator_setup(trkProp);
8661a211 298
c7b57c0b 299 char tooltip[1000];
b65b3044 300 sprintf(tooltip,"Ndaughters=%d", p->GetNDaughters());
ef9d2241 301 tlist->SetTitle(tooltip);
9fa23a72 302 trkProp->SetMaxOrbs(2);
8661a211 303 trkProp->SetEditPathMarks(kTRUE);
fc9514f5 304
84aff7a4 305 gEve->AddElement(cont);
306 rs = tlist->GetPropagator();
2caed564 307 }
ef9d2241 308 else
309 {
0e33c639 310 // check if container is TEveTrackList or AliEveTrack (has rnr-style)
311 AliEveTrack* t = dynamic_cast<AliEveTrack*>(cont);
fc9514f5 312 if (t) {
84aff7a4 313 rs = t->GetPropagator();
fc9514f5 314 } else {
84aff7a4 315 TEveTrackList* l = dynamic_cast<TEveTrackList*>(cont);
fc9514f5 316 if (l)
84aff7a4 317 rs = l->GetPropagator();
ef9d2241 318 else
2caed564 319 Error("kine_tracks.C", "TrackRenderStyle not set.");
2caed564 320 }
c7b57c0b 321 }
2caed564 322
b65b3044 323 if (import_mother)
324 {
0e33c639 325 AliEveTrack* track = new AliEveTrack(p, label, rs);
c7b57c0b 326 char form[1000];
327 sprintf(form,"%s [%d]", p->GetName(), label);
328 track->SetName(form);
fc9514f5 329 track->SetStdTitle();
330 set_track_color(track, pdg_col);
2caed564 331
fc9514f5 332 track->MakeTrack();
84aff7a4 333 gEve->AddElement(track, cont);
fc9514f5 334 cont = track;
c7b57c0b 335 }
336
51346b82 337 if (import_daughters && p->GetNDaughters())
c7b57c0b 338 {
51346b82 339 for (int d=p->GetFirstDaughter(); d>0 && d<=p->GetLastDaughter(); ++d)
340 {
c7b57c0b 341 TParticle* dp = stack->Particle(d);
0e33c639 342 AliEveTrack* track = new AliEveTrack(dp, d, rs);
c7b57c0b 343 char form[1000];
344 sprintf(form,"%s [%d]", dp->GetName(), d);
345 track->SetName(form);
fc9514f5 346 track->SetStdTitle();
347 set_track_color(track, pdg_col);
348
2caed564 349 track->MakeTrack();
84aff7a4 350 gEve->AddElement(track, cont);
fc9514f5 351
352 if (recurse)
353 kine_daughters(track, stack, 0, 0, pdg_col, recurse);
c7b57c0b 354 }
355 }
356 }
357
84aff7a4 358 gEve->Redraw3D();
c7b57c0b 359 return cont;
360}
2caed564 361
3c2901eb 362//==============================================================================
363
364void kine_hide_neutrals(TEveElement* el, Int_t level)
365{
366 if (el == 0)
367 {
368 el = gEve->GetCurrentEvent()->FindChild("Kine Tracks");
369 if (!el)
370 return;
371 }
372
373 TEveTrack* t = dynamic_cast<TEveTrack*>(el);
374 if (t && t->GetCharge() == 0)
375 t->SetRnrSelf(kFALSE);
376
377 for (TEveElement::List_i i = el->BeginChildren(); i != el->EndChildren(); ++i)
378 {
379 kine_hide_neutrals(*i, level + 1);
380 }
381
382 if (level == 0)
383 gEve->Redraw3D();
384}