]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/alice-macros/esd_tracks.C
Add option to color tracks according to PDG code.
[u/mrichter/AliRoot.git] / EVE / alice-macros / esd_tracks.C
CommitLineData
5a5a1232 1// $Id$
2
d31ac39d 3Reve::Track* esd_make_track(Reve::TrackRnrStyle* rnrStyle,
4 Int_t index,
5 AliESDtrack* at,
86f12f78 6 AliExternalTrackParam* tp=0)
7{
a8600b56 8 // Helper function
86f12f78 9 Double_t pbuf[3], vbuf[3];
10 Reve::RecTrack rt;
11
12 if(tp == 0) tp = at;
13
d31ac39d 14 rt.label = at->GetLabel();
15 rt.index = index;
86f12f78 16 rt.status = (Int_t) at->GetStatus();
17 rt.sign = tp->GetSign();
18 tp->GetXYZ(vbuf);
19 rt.V.Set(vbuf);
20 tp->GetPxPyPz(pbuf);
21 rt.P.Set(pbuf);
22 Double_t ep = at->GetP(), mc = at->GetMass();
23 rt.beta = ep/TMath::Sqrt(ep*ep + mc*mc);
24
25 Reve::Track* track = new Reve::Track(&rt, rnrStyle);
7be1e8cd 26 //PH The line below is replaced waiting for a fix in Root
27 //PH which permits to use variable siza arguments in CINT
28 //PH on some platforms (alphalinuxgcc, solariscc5, etc.)
29 //PH track->SetName(Form("ESDTrack %d", rt.label));
30 //PH track->SetTitle(Form("pT=%.3f, pZ=%.3f; V=(%.3f, %.3f, %.3f)",
31 //PH rt.sign*TMath::Hypot(rt.P.x, rt.P.y), rt.P.z,
32 //PH rt.V.x, rt.V.y, rt.V.z));
33 char form[1000];
34 sprintf(form,"ESDTrack %d", rt.label);
35 track->SetName(form);
d31ac39d 36 sprintf(form,"idx=%d, lbl=%d; pT=%.3f, pZ=%.3f; V=(%.3f, %.3f, %.3f)",
37 index, rt.label,
7be1e8cd 38 rt.sign*TMath::Hypot(rt.P.x, rt.P.y), rt.P.z,
39 rt.V.x, rt.V.y, rt.V.z);
40 track->SetTitle(form);
86f12f78 41 return track;
42}
43
a8600b56 44Bool_t gkFixFailedITSExtr = kFALSE;
86f12f78 45
5a5a1232 46Reve::TrackList* esd_tracks(Double_t min_pt=0.1, Double_t max_pt=100)
47{
48 AliESD* esd = Alieve::Event::AssertESD();
5a5a1232 49
50 Double_t minptsq = min_pt*min_pt;
51 Double_t maxptsq = max_pt*max_pt;
52 Double_t ptsq;
53
5a5a1232 54 Reve::TrackList* cont = new Reve::TrackList("ESD Tracks");
55 cont->SetMainColor(Color_t(6));
86f12f78 56 Reve::TrackRnrStyle* rnrStyle = cont->GetRnrStyle();
57 rnrStyle->SetMagField( esd->GetMagneticField() );
5a5a1232 58
5b96ea20 59 gReve->AddRenderElement(cont);
5a5a1232 60
86f12f78 61 Int_t count = 0;
62 Double_t pbuf[3];
d31ac39d 63 for (Int_t n=0; n<esd->GetNumberOfTracks(); n++)
64 {
86f12f78 65 AliESDtrack* at = esd->GetTrack(n);
5a5a1232 66
67 // Here would be sweet to have TObjectFormula.
68 at->GetPxPyPz(pbuf);
69 ptsq = pbuf[0]*pbuf[0] + pbuf[1]*pbuf[1];
70 if(ptsq < minptsq || ptsq > maxptsq)
71 continue;
72
73 ++count;
74
a8600b56 75 // If gkFixFailedITSExtr is TRUE (FALSE by default) and
76 // if ITS refit failed, take track parameters at inner TPC radius.
86f12f78 77 AliExternalTrackParam* tp = at;
78 if (gkFixFailedITSExtr && !at->IsOn(AliESDtrack::kITSrefit)) {
79 tp = at->GetInnerParam();
80 }
5a5a1232 81
d31ac39d 82 Reve::Track* track = esd_make_track(rnrStyle, n, at, tp);
5b96ea20 83 gReve->AddRenderElement(cont, track);
5a5a1232 84 }
85
7be1e8cd 86 //PH The line below is replaced waiting for a fix in Root
87 //PH which permits to use variable siza arguments in CINT
88 //PH on some platforms (alphalinuxgcc, solariscc5, etc.)
89 //PH const Text_t* tooltip = Form("pT ~ (%.2lf, %.2lf), N=%d", min_pt, max_pt, count);
90 char tooltip[1000];
91 sprintf(tooltip,"pT ~ (%.2lf, %.2lf), N=%d", min_pt, max_pt, count);
5a5a1232 92 cont->SetTitle(tooltip); // Not broadcasted automatically ...
5b96ea20 93 cont->UpdateItems();
5a5a1232 94
95 cont->MakeTracks();
96 cont->MakeMarkers();
5b96ea20 97 gReve->Redraw3D();
5a5a1232 98
99 return cont;
100}
101
a8600b56 102/**************************************************************************/
103// esd_tracks_from_array()
104/**************************************************************************/
105
86f12f78 106Reve::TrackList* esd_tracks_from_array(TCollection* col, AliESD* esd=0)
5a5a1232 107{
108 // Retrieves AliESDTrack's from collection.
109 // See example usage with AliAnalysisTrackCuts in the next function.
110
86f12f78 111 if(esd == 0) esd = Alieve::Event::AssertESD();
86f12f78 112
5a5a1232 113 Reve::TrackList* cont = new Reve::TrackList("ESD Tracks");
114 cont->SetMainColor(Color_t(6));
86f12f78 115 Reve::TrackRnrStyle* rnrStyle = cont->GetRnrStyle();
116 rnrStyle->SetMagField( esd->GetMagneticField() );
5a5a1232 117
5b96ea20 118 gReve->AddRenderElement(cont);
5a5a1232 119
5a5a1232 120 Int_t count = 0;
121 TIter next(col);
122 TObject *obj;
d31ac39d 123 while((obj = next()) != 0)
124 {
5a5a1232 125 if(obj->IsA()->InheritsFrom("AliESDtrack") == kFALSE) {
126 Warning("Object '%s', '%s' is not an AliESDtrack.",
127 obj->GetName(), obj->GetTitle());
128 continue;
129 }
130
131 ++count;
86f12f78 132 AliESDtrack* at = (AliESDtrack*) obj;
5a5a1232 133
d31ac39d 134 Reve::Track* track = esd_make_track(rnrStyle, count, at);
5b96ea20 135 gReve->AddRenderElement(cont, track);
5a5a1232 136 }
137
7be1e8cd 138 //PH The line below is replaced waiting for a fix in Root
139 //PH which permits to use variable siza arguments in CINT
140 //PH on some platforms (alphalinuxgcc, solariscc5, etc.)
141 //PH const Text_t* tooltip = Form("N=%d", count);
142 const tooltip[1000];
143 sprintf(tooltip,"N=%d", count);
5a5a1232 144 cont->SetTitle(tooltip); // Not broadcasted automatically ...
5b96ea20 145 cont->UpdateItems();
5a5a1232 146
147 cont->MakeTracks();
148 cont->MakeMarkers();
5b96ea20 149 gReve->Redraw3D();
5a5a1232 150
151 return cont;
152}
153
154void esd_tracks_alianalcuts_demo()
155{
156 AliESD* esd = Alieve::Event::AssertESD();
86f12f78 157 gSystem->Load("libANALYSIS");
5a5a1232 158
159 AliAnalysisTrackCuts atc;
160 atc.SetPtRange(0.1, 5);
161 atc.SetRapRange(-1, 1);
162
86f12f78 163 esd_tracks_from_array(atc.GetAcceptedParticles(esd), esd);
5a5a1232 164}
a8600b56 165
166/**************************************************************************/
167// esd_tracks_vertex_cut
168/**************************************************************************/
169
170Float_t get_sigma_to_vertex(AliESDtrack* esdTrack)
171{
172 // Taken from: PWG0/esdTrackCuts/AliESDtrackCuts.cxx
173 // Float_t AliESDtrackCuts::GetSigmaToVertex(AliESDtrack* esdTrack)
174
175 Float_t b[2];
176 Float_t bRes[2];
177 Float_t bCov[3];
178 esdTrack->GetImpactParameters(b,bCov);
179 if (bCov[0]<=0 || bCov[2]<=0) {
d31ac39d 180 printf("Estimated b resolution lower or equal zero!\n");
a8600b56 181 bCov[0]=0; bCov[2]=0;
182 }
183 bRes[0] = TMath::Sqrt(bCov[0]);
184 bRes[1] = TMath::Sqrt(bCov[2]);
185
186 // -----------------------------------
187 // How to get to a n-sigma cut?
188 //
189 // The accumulated statistics from 0 to d is
190 //
191 // -> Erf(d/Sqrt(2)) for a 1-dim gauss (d = n_sigma)
192 // -> 1 - Exp(-d**2) for a 2-dim gauss (d*d = dx*dx + dy*dy != n_sigma)
193 //
194 // It means that for a 2-dim gauss: n_sigma(d) = Sqrt(2)*ErfInv(1 - Exp((-x**2)/2)
195 // Can this be expressed in a different way?
196
197 if (bRes[0] == 0 || bRes[1] ==0)
198 return -1;
199
200 Float_t d = TMath::Sqrt(TMath::Power(b[0]/bRes[0],2) + TMath::Power(b[1]/bRes[1],2));
201
202 // stupid rounding problem screws up everything:
203 // if d is too big, TMath::Exp(...) gets 0, and TMath::ErfInverse(1) that should be infinite, gets 0 :(
204 if (TMath::Exp(-d * d / 2) < 1e-10)
205 return 1000;
206
207 d = TMath::ErfInverse(1 - TMath::Exp(-d * d / 2)) * TMath::Sqrt(2);
208 return d;
209}
210
211Reve::RenderElementList* esd_tracks_vertex_cut()
212{
f206464b 213 // Import ESD tracks, separate them into five containers according to
214 // primary-vertex cut and ITS refit status.
a8600b56 215
216 AliESD* esd = Alieve::Event::AssertESD();
217
218 Reve::RenderElementList* cont = new Reve::RenderElementList("ESD Tracks", 0, kTRUE);
219 gReve->AddRenderElement(cont);
f206464b 220 Reve::TrackList *tl[5];
221 Int_t tc[5];
a8600b56 222 Int_t count = 0;
223
224 tl[0] = new Reve::TrackList("Sigma < 3");
a8600b56 225 tc[0] = 0;
226 tl[0]->GetRnrStyle()->SetMagField( esd->GetMagneticField() );
227 tl[0]->SetMainColor(Color_t(3));
228 gReve->AddRenderElement(cont, tl[0]);
229
230 tl[1] = new Reve::TrackList("3 < Sigma < 5");
231 tc[1] = 0;
232 tl[1]->GetRnrStyle()->SetMagField( esd->GetMagneticField() );
233 tl[1]->SetMainColor(Color_t(7));
234 gReve->AddRenderElement(cont, tl[1]);
235
236 tl[2] = new Reve::TrackList("5 < Sigma");
237 tc[2] = 0;
238 tl[2]->GetRnrStyle()->SetMagField( esd->GetMagneticField() );
239 tl[2]->SetMainColor(Color_t(46));
240 gReve->AddRenderElement(cont, tl[2]);
241
846b5c55 242 tl[3] = new Reve::TrackList("no ITS refit; Sigma < 5");
a8600b56 243 tc[3] = 0;
244 tl[3]->GetRnrStyle()->SetMagField( esd->GetMagneticField() );
245 tl[3]->SetMainColor(Color_t(41));
246 gReve->AddRenderElement(cont, tl[3]);
247
846b5c55 248 tl[4] = new Reve::TrackList("no ITS refit; Sigma > 5");
f206464b 249 tc[4] = 0;
250 tl[4]->GetRnrStyle()->SetMagField( esd->GetMagneticField() );
251 tl[4]->SetMainColor(Color_t(48));
252 gReve->AddRenderElement(cont, tl[4]);
253
d31ac39d 254 for (Int_t n=0; n<esd->GetNumberOfTracks(); n++)
255 {
a8600b56 256 AliESDtrack* at = esd->GetTrack(n);
257
258 Float_t s = get_sigma_to_vertex(at);
259 Int_t ti;
260 if (s < 3) ti = 0;
261 else if (s <= 5) ti = 1;
262 else ti = 2;
263
264 AliExternalTrackParam* tp = at;
f206464b 265 // If ITS refit failed, optionally take track parameters at inner
266 // TPC radius and put track in a special container.
a8600b56 267 // This ignores state of gkFixFailedITSExtr (used in esd_tracks()).
268 // Use BOTH functions to compare results.
269 if (!at->IsOn(AliESDtrack::kITSrefit)) {
f206464b 270 // tp = at->GetInnerParam();
271 ti = (ti == 2) ? 4 : 3;
a8600b56 272 }
273
274 Reve::TrackList* tlist = tl[ti];
275 ++tc[ti];
276 ++count;
277
d31ac39d 278 Reve::Track* track = esd_make_track(tlist->GetRnrStyle(), n, at, tp);
279
7be1e8cd 280 //PH The line below is replaced waiting for a fix in Root
281 //PH which permits to use variable siza arguments in CINT
282 //PH on some platforms (alphalinuxgcc, solariscc5, etc.)
283 //PH track->SetName(Form("track %d, sigma=%5.3f", at->GetLabel(), s));
284 char form[1000];
d31ac39d 285 sprintf(form,"Track lbl=%d, sigma=%5.3f", at->GetLabel(), s);
7be1e8cd 286 track->SetName(form);
a8600b56 287 gReve->AddRenderElement(tlist, track);
288 }
289
f206464b 290 for (Int_t ti=0; ti<5; ++ti) {
a8600b56 291 Reve::TrackList* tlist = tl[ti];
7be1e8cd 292 //PH The line below is replaced waiting for a fix in Root
293 //PH which permits to use variable siza arguments in CINT
294 //PH on some platforms (alphalinuxgcc, solariscc5, etc.)
295 //PH const Text_t* tooltip = Form("N tracks=%d", tc[ti]);
846b5c55 296 //MT Modified somewhat.
297 char buff[1000];
298 sprintf(buff, "%s [%d]", tlist->GetName(), tlist->GetNChildren());
299 tlist->SetName(buff);
300 sprintf(buff, "N tracks=%d", tc[ti]);
301 tlist->SetTitle(buff); // Not broadcasted automatically ...
a8600b56 302 tlist->UpdateItems();
303
304 tlist->MakeTracks();
305 tlist->MakeMarkers();
306 }
7be1e8cd 307 //PH The line below is replaced waiting for a fix in Root
308 //PH which permits to use variable siza arguments in CINT
309 //PH on some platforms (alphalinuxgcc, solariscc5, etc.)
310 //PH cont->SetTitle(Form("N all tracks = %d", count));
311 char form[1000];
312 sprintf(form,"N all tracks = %d", count);
313 cont->SetTitle(form);
a8600b56 314 cont->UpdateItems();
315 gReve->Redraw3D();
316
317 return cont;
318}