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