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