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