Hardwired "ideal" coordinates replaced with those from the DCDB.
[u/mrichter/AliRoot.git] / EVE / alice-macros / kine_tracks.C
CommitLineData
1b337638 1// Import tracks from kinematics-tree / particle-stack.
2// Preliminary/minimal solution.
a7867742 3#include "TParticlePDG.h"
1b337638 4
a7867742 5// PDG color indices
539d6798 6static Color_t DefCol = 30;
7static Color_t ECol = 5;
8static Color_t MuCol = 6;
9static Color_t GammaCol = 7;
10static Color_t MesCol1 = 3;
11static Color_t MesCol2 = 38;
12static Color_t BarCol = 10;
a7867742 13
b65b3044 14Reve::TrackList*
ef9d2241 15kine_tracks(Double_t min_pt = 0.1, Double_t min_p = 0.2,
9a040a65 16 Bool_t pdg_col = kTRUE, Bool_t recurse = kTRUE,
17 Bool_t use_track_refs = kTRUE)
1b337638 18{
19 AliRunLoader* rl = Alieve::Event::AssertRunLoader();
20 rl->LoadKinematics();
21 AliStack* stack = rl->Stack();
22 if (!stack) {
23 Error("kine_tracks.C", "can not get kinematics.");
24 return 0;
25 }
26
af4b8b4b 27 gReve->DisableRedraw();
28
1b337638 29 Reve::TrackList* cont = new Reve::TrackList("Kine Tracks");
30 cont->SetMainColor(Color_t(6));
31 Reve::TrackRnrStyle* rnrStyle = cont->GetRnrStyle();
32 rnrStyle->fColor = 8;
33 // !!! Watch the '-', apparently different sign convention then for ESD.
32aee3cf 34 rnrStyle->SetMagField( - gAlice->Field()->SolenoidField() );
1b337638 35
36 gReve->AddRenderElement(cont);
1b337638 37 Int_t count = 0;
43d68fc4 38 Int_t N = stack->GetNtrack();
39 for (Int_t i=0; i<N; ++i)
40 {
41 if(stack->IsPhysicalPrimary(i))
42 {
43 TParticle* p = stack->Particle(i);
ef9d2241 44 if (p->Pt() < min_pt && p->P() < min_p) continue;
43d68fc4 45
46 ++count;
47 Reve::Track* track = new Reve::Track(p, i, rnrStyle);
48
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);
ef9d2241 56 if (pdg_col && p->GetPDG())
57 track->SetMainColor(get_pdg_color(p->GetPDG()->PdgCode()));
43d68fc4 58 gReve->AddRenderElement(cont, track);
ef9d2241 59
60 if (recurse)
61 kine_daughters(track, stack, min_pt, min_p, pdg_col, recurse);
43d68fc4 62 }
1b337638 63 }
ef9d2241 64
43d68fc4 65 // set path marks
66 Alieve::KineTools kt;
ef9d2241 67 kt.SetDaughterPathMarks(cont, stack, recurse);
9a040a65 68 if (use_track_refs && rl->LoadTrackRefs())
69 {
70 kt.SetTrackReferences(cont, rl->TreeTR(), recurse);
71 cont->SetEditPathMarks(kTRUE);
72 }
73 kt.SortPathMarks(cont, recurse);
43d68fc4 74
ef9d2241 75 //PH const Text_t* tooltip = Form("min pT=%.2lf, min P=%.2lf), N=%d", min_pt, min_p, count);
7be1e8cd 76 char tooltip[1000];
ef9d2241 77 sprintf(tooltip,"min pT=%.2lf, min P=%.2lf), N=%d", min_pt, min_p, count);
1b337638 78 cont->SetTitle(tooltip); // Not broadcasted automatically ...
79 cont->UpdateItems();
80
ef9d2241 81 cont->MakeTracks(recurse);
1b337638 82 cont->MakeMarkers();
af4b8b4b 83
84 gReve->EnableRedraw();
1b337638 85 gReve->Redraw3D();
86
87 return cont;
88}
a7867742 89
ef9d2241 90void kine_daughters(Reve::Track* parent, AliStack* stack,
91 Double_t min_pt, Double_t min_p,
92 Bool_t pdg_col, Bool_t recurse)
93{
94 TParticle *p = stack->Particle(parent->GetLabel());
95 if (p->GetNDaughters() > 0)
96 {
97 Reve::TrackRnrStyle* rs = parent->GetRnrStyle();
98 for (int d=p->GetFirstDaughter(); d>0 && d<=p->GetLastDaughter(); ++d)
99 {
100 TParticle* dp = stack->Particle(d);
101 if (dp->Pt() < min_pt && dp->P() < min_p) continue;
102
103 Track* dtrack = new Reve::Track(dp, d, rs);
104 char form[1000];
105 sprintf(form,"%s [%d]", dp->GetName(), d);
106 dtrack->SetName(form);
107 if (pdg_col && dp->GetPDG())
108 dtrack->SetMainColor(get_pdg_color(dp->GetPDG()->PdgCode()));
109 gReve->AddRenderElement(parent, dtrack);
110
111 if (recurse)
112 kine_daughters(dtrack, stack, min_pt, min_p, pdg_col, recurse);
113 }
114 }
115}
a7867742 116
539d6798 117Color_t get_pdg_color(Int_t pdg)
118{
a7867742 119 Int_t pdga = TMath::Abs(pdg);
120 Color_t col = Reve::DefCol;
121
122 // elementary particles
123 if (pdga < 100) {
124 switch (pdga) {
125 case 11:
126 col = ECol; break;
127 case 12:
128 col = MuCol; break;
129 case 22:
130 col = GammaCol; break;
131 }
132 }
133 else if (pdga < 100000){
134 Int_t i = pdga;
135 Int_t i0 = i%10; i /= 10;
136 Int_t i1 = i%10; i /= 10;
137 Int_t i2 = i%10; i /= 10;
138 Int_t i3 = i%10; i /= 10;
139 Int_t i4 = i%10;
140 //printf("pdg(%d) quark indices (%d,%d,%d,%d,%d) \n",pdg, i4,i3,i2, i1, i0);
141 // meson
142 if ((i3 == 0) && ( i4 < 2)){
143 col = MesCol1; // quarks: i1,i2 (spin = i0)
144 if(i1 == 3 || i2 == 3)
145 col = MesCol2;
146 } // barion
147 else if ( i2 >= i1 && i3 >= i2 ) {
148 col = BarCol; // quarks: i1,i2, i3 (spin = i0))
149 }
150 }
151 return col;
152}
c7b57c0b 153
154
155// Create mother and daughters tracks with given label.
156
2caed564 157Reve::RenderElement*
b65b3044 158kine_track(Int_t label,
159 Bool_t import_mother = kTRUE,
2caed564 160 Bool_t import_daughters = kTRUE,
539d6798 161 Reve::RenderElement* cont = 0)
2caed564 162
c7b57c0b 163{
c7b57c0b 164 if (label < 0) {
165 Warning("kine_track", "label not set.");
166 return 0;
167 }
168
169 AliRunLoader* rl = Alieve::Event::AssertRunLoader();
170 rl->LoadKinematics();
171 AliStack* stack = rl->Stack();
172 TParticle* p = stack->Particle(label);
173
b65b3044 174 if (import_mother || (import_daughters && p->GetNDaughters()))
c7b57c0b 175 {
2caed564 176 Track* toptrack = 0;
177 TrackList* tracklist = 0;
178 TrackRnrStyle* rs = 0;
179
b65b3044 180 if (cont == 0)
181 {
ef9d2241 182 Reve::TrackList* tlist = new Reve::TrackList
183 (Form("Kinematics of %d", label, p->GetNDaughters()));
184 cont = tlist;
c7b57c0b 185
ef9d2241 186 Reve::TrackRnrStyle* rnrStyle = tlist->GetRnrStyle();
c7b57c0b 187 // !!! Watch the '-', apparently different sign convention then for ESD.
188 rnrStyle->SetMagField( - gAlice->Field()->SolenoidField() );
189 char tooltip[1000];
b65b3044 190 sprintf(tooltip,"Ndaughters=%d", p->GetNDaughters());
ef9d2241 191 tlist->SetTitle(tooltip);
192 tlist->SelectByPt(0.2, 100);
2caed564 193 rnrStyle->fColor = 8;
194 rnrStyle->fMaxOrbs = 8;
ef9d2241 195 tlist->SetEditPathMarks(kTRUE);
c7b57c0b 196 gReve->AddRenderElement(cont);
ef9d2241 197 rs = tlist->GetRnrStyle();
2caed564 198 }
ef9d2241 199 else
200 {
2caed564 201 // check if argument is TrackList
202 Reve::Track* t = dynamic_cast<Reve::Track*>(cont);
203 if(t)
204 {
205 rs = t->GetRnrStyle();
206 }
ef9d2241 207 else
208 {
2caed564 209 Reve::TrackList* l = dynamic_cast<Reve::TrackList*>(cont);
210 if(l)
211 {
212 rs = l->GetRnrStyle();
213 }
ef9d2241 214 else
215 {
2caed564 216 Error("kine_tracks.C", "TrackRenderStyle not set.");
217 }
218 }
c7b57c0b 219 }
2caed564 220
b65b3044 221 if (import_mother)
222 {
2caed564 223 Track* track = new Reve::Track(p, label, rs);
c7b57c0b 224 char form[1000];
225 sprintf(form,"%s [%d]", p->GetName(), label);
226 track->SetName(form);
227 gReve->AddRenderElement(cont, track);
2caed564 228
c7b57c0b 229 }
230
b65b3044 231 if (import_daughters && p->GetNDaughters())
c7b57c0b 232 {
233 for (int d=p->GetFirstDaughter(); d>0 && d<=p->GetLastDaughter(); ++d)
234 {
235 TParticle* dp = stack->Particle(d);
2caed564 236 Track* track = new Reve::Track(dp, d, rs);
c7b57c0b 237 char form[1000];
238 sprintf(form,"%s [%d]", dp->GetName(), d);
239 track->SetName(form);
2caed564 240 track->MakeTrack();
c7b57c0b 241 gReve->AddRenderElement(cont, track);
242 }
243 }
244 }
245
2caed564 246 cont->UpdateItems();
c7b57c0b 247 gReve->Redraw3D();
248 return cont;
249}
2caed564 250