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