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