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