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