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