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