Optimize reading of track references.
[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
b65b3044 6static Color_t DefCol = 30;
7static Color_t ECol = 5;
8static Color_t MuCol = 6;
a7867742 9static Color_t GamaCol = 7;
10static Color_t MesCol1 = 3;
11static Color_t MesCol2 = 38;
b65b3044 12static Color_t BarCol = 10;
a7867742 13
14
b65b3044 15Reve::TrackList*
16kine_tracks(Double_t min_pt=0.5, Double_t max_pt=100, Bool_t pdg_col= kFALSE)
1b337638 17{
18 AliRunLoader* rl = Alieve::Event::AssertRunLoader();
19 rl->LoadKinematics();
20 AliStack* stack = rl->Stack();
21 if (!stack) {
22 Error("kine_tracks.C", "can not get kinematics.");
23 return 0;
24 }
25
26 Reve::TrackList* cont = new Reve::TrackList("Kine Tracks");
27 cont->SetMainColor(Color_t(6));
28 Reve::TrackRnrStyle* rnrStyle = cont->GetRnrStyle();
29 rnrStyle->fColor = 8;
30 // !!! Watch the '-', apparently different sign convention then for ESD.
32aee3cf 31 rnrStyle->SetMagField( - gAlice->Field()->SolenoidField() );
1b337638 32
33 gReve->AddRenderElement(cont);
34
35 Int_t count = 0;
43d68fc4 36 Int_t N = stack->GetNtrack();
37 for (Int_t i=0; i<N; ++i)
38 {
39 if(stack->IsPhysicalPrimary(i))
40 {
41 TParticle* p = stack->Particle(i);
42 Double_t pT = p->Pt();
43 if (pT<min_pt || pT>max_pt) continue;
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);
a7867742 55 TParticlePDG* pdgp = p->GetPDG();
56 track->SetMainColor(get_pdg_color(pdgp->PdgCode()));
43d68fc4 57 gReve->AddRenderElement(cont, track);
58 }
1b337638 59 }
60
43d68fc4 61 // set path marks
62 Alieve::KineTools kt;
63 rl->LoadTrackRefs();
64 kt.SetPathMarks(cont,stack, rl->TreeTR());
65 cont->SetEditPathMarks(kTRUE);
66
67
7be1e8cd 68 //PH const Text_t* tooltip = Form("pT ~ (%.2lf, %.2lf), N=%d", min_pt, max_pt, count);
69 char tooltip[1000];
70 sprintf(tooltip,"pT ~ (%.2lf, %.2lf), N=%d", min_pt, max_pt, count);
1b337638 71 cont->SetTitle(tooltip); // Not broadcasted automatically ...
72 cont->UpdateItems();
73
74 cont->MakeTracks();
75 cont->MakeMarkers();
76 gReve->Redraw3D();
77
78 return cont;
79}
a7867742 80
81
82Color_t get_pdg_color(Int_t pdg){
83 Int_t pdga = TMath::Abs(pdg);
84 Color_t col = Reve::DefCol;
85
86 // elementary particles
87 if (pdga < 100) {
88 switch (pdga) {
89 case 11:
90 col = ECol; break;
91 case 12:
92 col = MuCol; break;
93 case 22:
94 col = GammaCol; break;
95 }
96 }
97 else if (pdga < 100000){
98 Int_t i = pdga;
99 Int_t i0 = i%10; i /= 10;
100 Int_t i1 = i%10; i /= 10;
101 Int_t i2 = i%10; i /= 10;
102 Int_t i3 = i%10; i /= 10;
103 Int_t i4 = i%10;
104 //printf("pdg(%d) quark indices (%d,%d,%d,%d,%d) \n",pdg, i4,i3,i2, i1, i0);
105 // meson
106 if ((i3 == 0) && ( i4 < 2)){
107 col = MesCol1; // quarks: i1,i2 (spin = i0)
108 if(i1 == 3 || i2 == 3)
109 col = MesCol2;
110 } // barion
111 else if ( i2 >= i1 && i3 >= i2 ) {
112 col = BarCol; // quarks: i1,i2, i3 (spin = i0))
113 }
114 }
115 return col;
116}
c7b57c0b 117
118
119// Create mother and daughters tracks with given label.
120
2caed564 121Reve::RenderElement*
b65b3044 122kine_track(Int_t label,
123 Bool_t import_mother = kTRUE,
2caed564 124 Bool_t import_daughters = kTRUE,
125 Reve::RenderElement* cont = 0)
126
c7b57c0b 127{
c7b57c0b 128 if (label < 0) {
129 Warning("kine_track", "label not set.");
130 return 0;
131 }
132
133 AliRunLoader* rl = Alieve::Event::AssertRunLoader();
134 rl->LoadKinematics();
135 AliStack* stack = rl->Stack();
136 TParticle* p = stack->Particle(label);
137
b65b3044 138 if (import_mother || (import_daughters && p->GetNDaughters()))
c7b57c0b 139 {
2caed564 140 Track* toptrack = 0;
141 TrackList* tracklist = 0;
142 TrackRnrStyle* rs = 0;
143
b65b3044 144 if (cont == 0)
145 {
146 cont = new TrackList(Form("Kinematics of %d", label, p->GetNDaughters()));
c7b57c0b 147
148 Reve::TrackRnrStyle* rnrStyle = cont->GetRnrStyle();
149 // !!! Watch the '-', apparently different sign convention then for ESD.
150 rnrStyle->SetMagField( - gAlice->Field()->SolenoidField() );
151 char tooltip[1000];
b65b3044 152 sprintf(tooltip,"Ndaughters=%d", p->GetNDaughters());
2caed564 153 cont->SetTitle(tooltip);
c7b57c0b 154 cont->SelectByPt(0.2, 100);
2caed564 155 rnrStyle->fColor = 8;
156 rnrStyle->fMaxOrbs = 8;
c7b57c0b 157 cont->SetEditPathMarks(kTRUE);
158 gReve->AddRenderElement(cont);
2caed564 159 rs = cont->GetRnrStyle();
160 }
161 else {
162 // check if argument is TrackList
163 Reve::Track* t = dynamic_cast<Reve::Track*>(cont);
164 if(t)
165 {
166 rs = t->GetRnrStyle();
167 }
168 else {
169 Reve::TrackList* l = dynamic_cast<Reve::TrackList*>(cont);
170 if(l)
171 {
172 rs = l->GetRnrStyle();
173 }
174 else {
175 Error("kine_tracks.C", "TrackRenderStyle not set.");
176 }
177 }
c7b57c0b 178 }
2caed564 179
b65b3044 180 if (import_mother)
181 {
2caed564 182 Track* track = new Reve::Track(p, label, rs);
c7b57c0b 183 char form[1000];
184 sprintf(form,"%s [%d]", p->GetName(), label);
185 track->SetName(form);
186 gReve->AddRenderElement(cont, track);
2caed564 187
c7b57c0b 188 }
189
b65b3044 190 if (import_daughters && p->GetNDaughters())
c7b57c0b 191 {
192 for (int d=p->GetFirstDaughter(); d>0 && d<=p->GetLastDaughter(); ++d)
193 {
194 TParticle* dp = stack->Particle(d);
2caed564 195 Track* track = new Reve::Track(dp, d, rs);
c7b57c0b 196 char form[1000];
197 sprintf(form,"%s [%d]", dp->GetName(), d);
198 track->SetName(form);
2caed564 199 track->MakeTrack();
c7b57c0b 200 gReve->AddRenderElement(cont, track);
201 }
202 }
203 }
204
2caed564 205 cont->UpdateItems();
c7b57c0b 206 gReve->Redraw3D();
207 return cont;
208}
2caed564 209