]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG1/TOF/AliAnalysisTaskTOFqa.cxx
11c066614c1bdf5dbaf09576faa0417a9427b8da
[u/mrichter/AliRoot.git] / PWG1 / TOF / AliAnalysisTaskTOFqa.cxx
1 /*  created by fbellini@cern.ch on 14/09/2010 */
2 /*  last modified by fbellini   on 31/03/2010 */
3
4
5 #ifndef ALIANALYSISTASKTOFQA_CXX
6 #define ALIANALYSISTASKTOFQA_CXX
7
8 #include "TChain.h"
9 #include "TTree.h"
10 #include "TH1F.h"
11 #include "TH2F.h"
12 #include "TCanvas.h"
13 #include "AliAnalysisTaskSE.h"
14 #include "AliAnalysisManager.h"
15 #include "AliESDEvent.h"
16 #include "AliESDInputHandler.h"
17 #include "AliESDpid.h"
18 #include "AliAnalysisTaskTOFqa.h"
19 #include "AliAnalysisFilter.h"
20 #include "AliESDtrackCuts.h"
21 #include "AliLog.h"
22 #include "AliTOFRawStream.h"
23 #include "AliTOFGeometry.h"
24
25 ClassImp(AliAnalysisTaskTOFqa)
26
27 //________________________________________________________________________
28 AliAnalysisTaskTOFqa::AliAnalysisTaskTOFqa() :
29   fRunNumber(0), 
30   fESD(0x0), 
31   fTrackFilter(0x0), 
32   fVertex(0x0),
33   fESDpid(new AliESDpid()),
34   fNTOFtracks(0), 
35 //  fNPrimaryTracks(0), 
36   fHlist(0x0),
37   fHlistTimeZero(0x0),
38   fHlistPID(0x0)
39  {
40   // Default constructor
41    
42    for (Int_t j=0;j<3;j++ ) {
43      if (j<3) fT0[j]=0.0;
44      fSigmaSpecie[j]=0.0;
45      fTrkExpTimes[j]=0.0;
46      fThExpTimes[j]=0.0;
47    }
48  }
49 //________________________________________________________________________
50 AliAnalysisTaskTOFqa::AliAnalysisTaskTOFqa(const char *name) : 
51   AliAnalysisTaskSE(name), 
52   fRunNumber(0), 
53   fESD(0x0), 
54   fTrackFilter(0x0),
55   fVertex(0x0),
56 fESDpid(new AliESDpid()),
57   fNTOFtracks(0), 
58   // fNPrimaryTracks(0),  
59   fHlist(0x0),
60   fHlistTimeZero(0),
61   fHlistPID(0x0)
62  {
63   // Constructor
64   // Define input and output slots here
65    Info("AliAnalysisTaskTOFqa","Calling Constructor");
66    
67    for (Int_t j=0;j<5;j++ ) {
68      if (j<3) fT0[j]=0.0;
69      fSigmaSpecie[j]=0.0;
70      fTrkExpTimes[j]=0.0;
71      fThExpTimes[j]=0.0;
72    }
73    // Input slot #0 works with a TChain
74    DefineInput(0, TChain::Class());
75    
76    // Output slot #0 writes into a TH1 container
77    // Output slot #1 writes into a user defined  container
78    DefineOutput(1, TList::Class());
79    DefineOutput(2, TList::Class());
80    DefineOutput(3, TList::Class());
81  }
82
83 //________________________________________________________________________
84 AliAnalysisTaskTOFqa::AliAnalysisTaskTOFqa(const AliAnalysisTaskTOFqa& copy) 
85 : AliAnalysisTaskSE(), 
86   fRunNumber(copy.fRunNumber), 
87   fESD(copy.fESD), 
88   fTrackFilter(copy.fTrackFilter), 
89   fVertex(copy.fVertex),
90   fESDpid(copy.fESDpid),
91   fNTOFtracks(copy.fNTOFtracks), 
92   //fNPrimaryTracks(copy.fNPrimaryTracks), 
93   fHlist(copy.fHlist),
94   fHlistTimeZero(copy.fHlistTimeZero),
95   fHlistPID(copy.fHlistPID)
96 {
97   // Copy constructor
98    for (Int_t j=0;j<5;j++ ) {
99      if (j<3) fT0[j]=copy.fT0[j];
100      fSigmaSpecie[j]=copy.fSigmaSpecie[j];
101      fTrkExpTimes[j]=copy.fTrkExpTimes[j];
102      fThExpTimes[j]=copy.fThExpTimes[j];
103    }
104   
105
106 }
107
108 //___________________________________________________________________________
109 AliAnalysisTaskTOFqa& AliAnalysisTaskTOFqa::operator=(const AliAnalysisTaskTOFqa& copy) 
110 {
111   //
112   // Assignment operator
113   //
114   if (this!=&copy) {
115     AliAnalysisTaskSE::operator=(copy) ;
116     fRunNumber=copy.fRunNumber; 
117     fESD=copy.fESD;
118     fTrackFilter=copy.fTrackFilter;
119     fVertex=copy.fVertex;
120     fESDpid=copy.fESDpid;
121     fNTOFtracks=copy.fNTOFtracks; 
122     //fNPrimaryTracks=copy.fNPrimaryTracks; 
123     for (Int_t j=0;j<5;j++ ) {
124       if (j<3) fT0[j]=copy.fT0[j];
125       fSigmaSpecie[j]=copy.fSigmaSpecie[j];
126       fTrkExpTimes[j]=copy.fTrkExpTimes[j];
127       fThExpTimes[j]=copy.fThExpTimes[j];
128     }
129     fHlist=copy.fHlist;
130     fHlistTimeZero=copy.fHlistTimeZero;
131     fHlistPID=copy.fHlistPID;
132   }
133   return *this;
134 }
135
136 //___________________________________________________________________________
137 AliAnalysisTaskTOFqa::~AliAnalysisTaskTOFqa() {
138   //
139   //destructor
140   //
141
142   Info("~AliAnalysisTaskTOFqa","Calling Destructor");
143   if (fESDpid) delete fESDpid;
144   if (fVertex) delete fVertex;
145   if (fTrackFilter) delete fTrackFilter;
146
147   if (AliAnalysisManager::GetAnalysisManager()->IsProofMode()) return;
148   if (fHlist) {
149     delete fHlist;
150     fHlist = 0;
151   }
152   if (fHlistTimeZero) {
153     delete fHlistTimeZero;
154     fHlistTimeZero = 0;
155   }
156   if (fHlistPID){
157     delete fHlistPID;
158     fHlistPID = 0;
159   }
160 }
161
162 //________________________________________________________________________
163 void AliAnalysisTaskTOFqa::UserCreateOutputObjects()
164 {
165   //Defines output objects and histograms
166   Info("CreateOutputObjects","CreateOutputObjects (TList) of task %s", GetName());
167   OpenFile(1);
168   if (!fHlist) fHlist = new TList();    
169   fHlist->SetOwner(kTRUE);
170   if (!fHlistTimeZero) fHlistTimeZero = new TList();    
171   fHlistTimeZero->SetOwner(kTRUE);
172   if (!fHlistPID) fHlistPID = new TList();      
173   fHlistPID->SetOwner(kTRUE);
174
175 //0
176   TH1I* hTOFmatchedESDperEvt = new TH1I("hTOFmatchedPerEvt", "Matched TOF tracks per event (|#eta| #leq 0.9 and pT #geq 0.3 GeV/c);TOF-matched ESD tracks;Events", 100, 0, 100) ;  
177   hTOFmatchedESDperEvt->Sumw2() ;
178   hTOFmatchedESDperEvt->SetLineWidth(2);
179   hTOFmatchedESDperEvt->SetLineColor(kBlue);
180   hTOFmatchedESDperEvt->SetMarkerStyle(20);
181   hTOFmatchedESDperEvt->SetMarkerSize(0.8);
182   hTOFmatchedESDperEvt->SetMarkerColor(kBlue);
183   fHlist->AddLast(hTOFmatchedESDperEvt) ;
184   //1
185   TH1F* hTOFmatchedESDtime = new TH1F("hTOFmatchedESDtime", "Matched  ESDs tracks: TOF Time spectrum; t [ns];Counts", 250, 0., 610. ) ; 
186   hTOFmatchedESDtime->Sumw2() ;
187   hTOFmatchedESDtime->SetLineWidth(2);
188   hTOFmatchedESDtime->SetLineColor(kBlue);
189   hTOFmatchedESDtime->SetFillColor(kBlue);
190   hTOFmatchedESDtime->SetDrawOption("BAR");
191   fHlist->AddLast(hTOFmatchedESDtime) ;
192   //2
193   TH1F* hTOFmatchedESDrawTime = new TH1F("hTOFmatchedESDrawTime", "Matched ESDs tracks: TOF raw Time spectrum;t_{raw} [ns];Counts", 250, 0., 610.) ; 
194   hTOFmatchedESDrawTime->Sumw2() ;
195   hTOFmatchedESDrawTime->SetLineWidth(2);
196   hTOFmatchedESDrawTime->SetLineColor(kAzure+2);
197   hTOFmatchedESDrawTime->SetFillColor(kAzure+2);
198   hTOFmatchedESDrawTime->SetDrawOption("BAR");
199   fHlist->AddLast(hTOFmatchedESDrawTime) ;
200   //3
201   TH1F* hTOFmatchedESDToT = new TH1F("hTOFmatchedESDToT", "Matched ESDs tracks: TOF ToT spectrum; ToT [ns];Counts",100, 0., 48.8) ; 
202   hTOFmatchedESDToT->Sumw2() ;
203   hTOFmatchedESDToT->SetLineColor(kOrange+1);
204   hTOFmatchedESDToT->SetMarkerColor(kOrange+1);
205   hTOFmatchedESDToT->SetFillColor(kOrange+1);
206   hTOFmatchedESDToT->SetDrawOption("BAR");
207   fHlist->AddLast(hTOFmatchedESDToT) ;
208   //4
209   TH1F* hTOFmatchedESDtrkLength  = new TH1F("hTOFmatchedESDtrkLength", "Matched ESDs tracks length; Track length [cm];Counts", 1200, -400., 800) ; 
210   hTOFmatchedESDtrkLength->Sumw2();
211   hTOFmatchedESDtrkLength->SetLineColor(kViolet-3);
212   hTOFmatchedESDtrkLength->SetMarkerColor(kViolet-3);
213   hTOFmatchedESDtrkLength->SetFillColor(kViolet-3);
214   hTOFmatchedESDtrkLength->SetDrawOption("BAR"); 
215   fHlist->AddLast(hTOFmatchedESDtrkLength);
216   //5
217   TH1F* hTOFmatchedESDP  = new TH1F("hTOFmatchedESDP", "TPC-TOF matched tracks momentum distribution (GeV/c); p (GeV/c);tracks", 500,0.,5.) ;  
218   hTOFmatchedESDP->Sumw2() ;
219   hTOFmatchedESDP->SetLineColor(kBlue);
220   hTOFmatchedESDP->SetMarkerStyle(20);
221   hTOFmatchedESDP->SetMarkerSize(0.7);
222   hTOFmatchedESDP->SetMarkerColor(kBlue);
223   fHlist->AddLast(hTOFmatchedESDP) ; 
224   //6
225   TH1F* hTOFmatchedESDPt  = new TH1F("hTOFmatchedESDPt", "TPC-TOF matched tracks p_{T} distribution (GeV/c); p_{T}(GeV/c);tracks", 500,0.,5.) ;  
226   hTOFmatchedESDPt->Sumw2() ;
227   hTOFmatchedESDPt->SetLineColor(kBlue);
228   hTOFmatchedESDPt->SetMarkerStyle(21);
229   hTOFmatchedESDPt->SetMarkerSize(0.7);
230   hTOFmatchedESDPt->SetMarkerColor(kBlue);
231   fHlist->AddLast(hTOFmatchedESDPt) ; 
232
233   //7
234   TH1F* hTOFmatchedESDeta = new TH1F("hTOFmatchedESDeta", "Matched ESDtracks #eta (p_{T} #geq 0.5 GeV/c); #eta;Counts", 200, -1., 1.) ; 
235   hTOFmatchedESDeta->Sumw2();
236   hTOFmatchedESDeta->SetLineColor(kBlue);
237   fHlist->AddLast(hTOFmatchedESDeta) ; 
238   //8
239    TH1F* hTOFmatchedESDphi = new TH1F("hTOFmatchedESDphi", "Matched ESDtracks #phi; #phi (deg);Counts", 72, 0., 360.) ; 
240   hTOFmatchedESDphi->Sumw2();
241   hTOFmatchedESDphi->SetLineColor(kBlue);
242   fHlist->AddLast(hTOFmatchedESDphi) ; 
243
244   //9
245   TH1F* hESDprimaryTrackP = new TH1F("hESDprimaryTrackP", "All ESDs tracks p_{T} distribution (GeV/c); p_{T}(GeV/c);tracks", 500, 0., 5.0) ;  
246   hESDprimaryTrackP->Sumw2();
247   hESDprimaryTrackP->SetLineWidth(1);
248   hESDprimaryTrackP->SetMarkerStyle(24);
249   hESDprimaryTrackP->SetMarkerSize(0.7);
250   hESDprimaryTrackP->SetMarkerColor(kRed);
251   hESDprimaryTrackP->SetLineColor(kRed);
252   fHlist->AddLast(hESDprimaryTrackP);
253   //10
254   TH1F* hESDprimaryTrackPt = new TH1F("hESDprimaryTrackPt", "ESDs primary tracks p_{T} distribution (GeV/c); p_{T}(GeV/c);tracks", 500, 0.0, 5.0) ;  
255   hESDprimaryTrackPt->Sumw2();
256   hESDprimaryTrackPt->SetLineWidth(1);
257   hESDprimaryTrackPt->SetMarkerStyle(25);
258   hESDprimaryTrackPt->SetMarkerSize(0.7);
259   hESDprimaryTrackPt->SetLineColor(kRed);
260   hESDprimaryTrackPt->SetMarkerColor(kRed);
261   fHlist->AddLast(hESDprimaryTrackPt);
262   //11
263   TH1F* hTOFprimaryESDeta = new TH1F("hTOFprimaryESDeta", "Primary ESDtracks #eta (p_{T} #geq 0.5 GeV/c); #eta;Counts",200, -1., 1.) ; 
264   hTOFprimaryESDeta->Sumw2();
265   hTOFprimaryESDeta->SetLineColor(kRed);
266   fHlist->AddLast(hTOFprimaryESDeta) ; 
267   //12
268   TH1F* hTOFprimaryESDphi = new TH1F("hTOFprimaryESDphi", "Primary ESDtracks #phi;#phi (deg);Counts", 72, 0., 360.) ; 
269   hTOFprimaryESDphi->Sumw2();
270   hTOFprimaryESDphi->SetLineColor(kRed);
271   fHlist->AddLast(hTOFprimaryESDphi) ; 
272   //13
273   TH2F* hTOFmatchedDxVsPtPos = new TH2F("hTOFmatchedDxVsPtPos", "Dx vs p_{T} for positive tracks;p_{T} (GeV/c); Dx [cm]; hits", 500,0.,5.,200, -10., 10.) ; 
274   hTOFmatchedDxVsPtPos->Sumw2();
275   fHlist->AddLast(hTOFmatchedDxVsPtPos) ; 
276  //14
277   TH2F* hTOFmatchedDxVsPtNeg = new TH2F("hTOFmatchedDxVsPtNeg", "Dx vs p_{T} for negative tracks;p_{T} (GeV/c); Dx [cm]; hits", 500,0.,5.,200, -10., 10.) ; 
278   hTOFmatchedDxVsPtNeg->Sumw2();
279   fHlist->AddLast(hTOFmatchedDxVsPtNeg) ; 
280
281   //15
282   TH2F* hTOFmatchedDzVsStrip = new TH2F("hTOFmatchedDzVsStrip", "Dz vs strip; strip (#eta); Dz [cm]; hits", 92,0.,92.,200, -10., 10.) ; 
283   hTOFmatchedDzVsStrip->Sumw2();
284   fHlist->AddLast(hTOFmatchedDzVsStrip) ; 
285  
286  //----------------------------------------------timeZero QA plots
287   //TimeZero 0
288   TH1D* hEventT0DetAND = new TH1D("hEventT0DetAND", "Event timeZero from T0AC detector ; t0 [ps]; events", 1000, -25000., 25000. ) ; 
289   hEventT0DetAND->Sumw2() ;
290   hEventT0DetAND->SetLineWidth(2);
291   hEventT0DetAND->SetLineColor(kRed);
292   hEventT0DetAND->SetFillColor(kRed);
293   fHlistTimeZero->AddLast(hEventT0DetAND) ;
294
295   //TImeZero 1
296   TH1D* hEventT0DetA = new TH1D("hEventT0DetA", "Event timeZero from T0A detector; t0 [ps]; events", 1000, -25000., 25000. ) ; 
297   hEventT0DetA->Sumw2() ;
298   hEventT0DetA->SetLineWidth(2);
299   hEventT0DetA->SetLineColor(kBlue);
300   hEventT0DetA->SetFillColor(kBlue);
301   fHlistTimeZero->AddLast(hEventT0DetA) ;
302
303    //TImeZero 2
304   TH1D* hEventT0DetC = new TH1D("hEventT0DetC", "Event timeZero from T0C detector; t0 [ps]; events", 1000, -25000., 25000.) ; 
305   hEventT0DetC->Sumw2() ;
306   hEventT0DetC->SetLineWidth(2);
307   hEventT0DetC->SetLineColor(kGreen);
308   hEventT0DetC->SetFillColor(kGreen);
309   fHlistTimeZero->AddLast(hEventT0DetC);
310
311    //TimeZero 3
312   TH1F* hT0DetRes = new TH1F("hT0DetRes", "T0 detector (T0A-T0C)/2; (T0A-T0C)/2 [ps]; events", 200, -500.,500. ) ; 
313   hT0DetRes->Sumw2() ;
314   hT0DetRes->SetMarkerStyle(24);
315   hT0DetRes->SetMarkerSize(0.7);
316   hT0DetRes->SetMarkerColor(kMagenta+2);
317   hT0DetRes->SetLineColor(kMagenta+2);
318   hT0DetRes->SetFillColor(kMagenta+2);  
319   fHlistTimeZero->AddLast(hT0DetRes) ; 
320
321      //timeZero 4
322   TH1F* hT0fill = new TH1F("hT0fill", "Event timeZero of fill; t0 [ps]; events", 1000, -25000., 25000. ) ; 
323   hT0fill->Sumw2() ;
324   hT0fill->SetMarkerStyle(20);
325   hT0fill->SetMarkerColor(kBlack);
326   hT0fill->SetLineColor(kBlack);
327   fHlistTimeZero->AddLast(hT0fill) ; 
328
329   //TimeZero 5
330   TH1F* hT0TOF = new TH1F("hT0TOF", "Event timeZero estimated by TOF; t0 [ps]; events", 1000, -25000., 25000. ) ; 
331   hT0TOF->Sumw2() ;
332   hT0TOF->SetMarkerStyle(20);
333   hT0TOF->SetMarkerColor(kBlue);
334   hT0TOF->SetLineColor(kBlue);
335   hT0TOF->SetFillColor(kBlue);
336   fHlistTimeZero->AddLast(hT0TOF) ;
337
338
339    //timeZero 6
340   TH1F* hT0T0 = new TH1F("hT0T0", "Event timeZero measured by T0 detector (best between AC, A, C); t0 [ps]; events", 1000, -25000.,25000. ) ; 
341   hT0T0->Sumw2() ;
342   hT0T0->SetMarkerStyle(20);
343   hT0T0->SetMarkerColor(kGreen+1);
344   hT0T0->SetLineColor(kGreen+1);
345   hT0T0->SetFillColor(kGreen+1);
346   fHlistTimeZero->AddLast(hT0T0) ; 
347
348    //timeZero 7
349   TH1F* hT0best = new TH1F("hT0best", "Event timeZero estimated as T0best; t0 [ps]; events", 1000, -25000.,25000. ) ; 
350   hT0best->Sumw2() ;
351   hT0best->SetMarkerStyle(20);
352   hT0best->SetMarkerColor(kRed);
353   hT0best->SetLineColor(kRed);
354   hT0best->SetFillColor(kRed); 
355   fHlistTimeZero->AddLast(hT0best) ; 
356
357    //TimeZero 8
358   TH1F* hT0fillRes = new TH1F("hT0fillRes", "Resolution of fillT0; #sigma_{bestT0} [ps];events", 250, 0.,250. ) ; 
359   hT0fillRes->Sumw2() ;
360   hT0fillRes->SetMarkerStyle(21);
361   hT0fillRes->SetMarkerColor(kBlack);
362   hT0fillRes->SetLineColor(kBlack);
363   hT0fillRes->SetFillColor(kBlack); 
364   fHlistTimeZero->AddLast(hT0fillRes) ; 
365  
366   //TimeZero 9
367   TH1F* hT0TOFRes = new TH1F("hT0TOFRes", "Resolution of timeZero from TOF; #sigma_{TOFT0} [ps];events", 250, 0.,250. ) ; 
368   hT0TOFRes->Sumw2() ;
369   hT0TOFRes->SetLineWidth(1);
370   hT0TOFRes->SetMarkerStyle(21);
371   hT0TOFRes->SetMarkerColor(kBlue);
372   hT0TOFRes->SetLineColor(kBlue);
373   hT0TOFRes->SetFillColor(kBlue); 
374   fHlistTimeZero->AddLast(hT0TOFRes) ; 
375
376    //TimeZero 10
377   TH1F* hT0T0res = new TH1F("hT0T0res", "Resolution of timeZero from T0;#sigma_{T0T0}  [ps];events", 250, -0., 250. ) ; 
378   hT0T0res->Sumw2() ;
379   hT0T0res->SetMarkerStyle(21);
380   hT0T0res->SetMarkerColor(kGreen+1);
381   hT0T0res->SetLineColor(kGreen+1);
382   hT0T0res->SetFillColor(kGreen+1); 
383   fHlistTimeZero->AddLast(hT0T0res) ; 
384
385    //TimeZero 11
386   TH1F* hT0bestRes = new TH1F("hT0bestRes", "Resolution of bestT0; #sigma_{bestT0} [ps];events", 250, 0.,250. ) ; 
387   hT0bestRes->Sumw2() ;
388   hT0fillRes->SetMarkerStyle(21);
389   hT0fillRes->SetMarkerColor(kRed);
390   hT0fillRes->SetLineColor(kRed);
391   hT0fillRes->SetFillColor(kRed); 
392   fHlistTimeZero->AddLast(hT0bestRes) ; 
393
394   //timeZero 12
395   TH2F* hT0TOFvsNtrk = new TH2F("hT0TOFvsNtrk", "Event timeZero estimated by TOF vs. number of tracks in event;TOF-matching tracks; t0 [ps]", 100, 0., 100.,1000,-25000.,25000. ) ; 
396   hT0TOFvsNtrk->Sumw2() ;
397   fHlistTimeZero->AddLast(hT0TOFvsNtrk) ;
398
399 //--------------------------------------------- TOF PID QA plots
400   //PID 0
401   TH2F* hTOFmatchedESDpVsBeta  = new TH2F("hTOFmatchedESDpVsBeta", "Matched ESDs tracks beta vs. p; p(GeV/c); beta", 500, 0.0, 5.0, 150,0., 1.5) ; 
402   fHlistPID->AddLast(hTOFmatchedESDpVsBeta);
403   
404   //PID 1 
405   TH1F* hTOFmatchedMass= new TH1F("hTOFmatchedMass","Matched ESD tracks mass distribution - (L>0); M (GeV/c^{2}); entries", 500,0., 5. );
406   hTOFmatchedMass->Sumw2();
407   hTOFmatchedMass->SetLineWidth(2);
408   hTOFmatchedMass->SetLineColor(kBlue);
409   hTOFmatchedMass->SetLineColor(kBlue);
410   fHlistPID->AddLast(hTOFmatchedMass);
411   
412   //PID 2
413   TH2F* hTOFmatchedExpTimePiVsEta = new TH2F("hTOFmatchedExpTimePiVsEta", "ESDs t_{TOF}-t_{#pi,exp} (from tracking); strip (#eta); t_{TOF}-t_{#pi,exp} [ps]",92,0,92,2000, -5000., 5000. ) ; 
414   hTOFmatchedExpTimePiVsEta->Sumw2() ;
415   fHlistPID->AddLast(hTOFmatchedExpTimePiVsEta) ;
416   
417   //PID 3
418   TH1F* hTOFmatchedExpTimePi = new TH1F("hTOFmatchedExpTimePi", "ESDs t_{TOF}-t_{#pi,exp} (from tracking); t_{TOF}-t_{#pi,exp} [ps];Counts",5000, -25000., 25000. ) ; 
419   hTOFmatchedExpTimePi->Sumw2() ;
420   hTOFmatchedExpTimePi->SetLineWidth(1);
421   hTOFmatchedExpTimePi->SetLineColor(kRed);
422   hTOFmatchedExpTimePi->SetMarkerStyle(20);
423   hTOFmatchedExpTimePi->SetMarkerSize(0.8); 
424   hTOFmatchedExpTimePi->SetMarkerColor(kRed);
425   fHlistPID->AddLast(hTOFmatchedExpTimePi) ;
426   
427   //PID 4
428   TH2F* hTOFmatchedExpTimePiVsP = new TH2F("hTOFmatchedExpTimePiVsP", "ESDs t_{TOF}-t_{#pi,exp} (from tracking) Vs P ; p (GeV/c);t_{TOF}-t_{#pi,exp} [ps];Counts",500, 0.,5.,1000, -25000., 25000. ) ; 
429   hTOFmatchedExpTimePiVsP->Sumw2() ;
430   fHlistPID->AddLast(hTOFmatchedExpTimePiVsP) ;
431
432   //PID 5
433   TH1F* hTOFtheoreticalExpTimePi = new TH1F("hTOFtheoreticalExpTimePi", "ESDs t_{TOF}-t_{#pi,exp} (theoretical); t_{TOF}-t_{#pi,exp} [ps];Counts", 5000, -25000., 25000. ) ; 
434   hTOFtheoreticalExpTimePi->Sumw2() ;
435   hTOFtheoreticalExpTimePi->SetLineWidth(1);
436   hTOFtheoreticalExpTimePi->SetLineColor(kRed);
437   hTOFtheoreticalExpTimePi->SetMarkerStyle(24);
438   hTOFtheoreticalExpTimePi->SetMarkerSize(0.8); 
439   hTOFtheoreticalExpTimePi->SetMarkerColor(kRed);
440   fHlistPID->AddLast(hTOFtheoreticalExpTimePi) ;
441
442   //PID 6
443   TH2F* hTOFtheoreticalExpTimePiVsP = new TH2F("hTOFtheoreticalExpTimePiVsP", "ESDs t_{TOF}-t_{#pi,exp} (theoretical) Vs P ; p (GeV/c);t_{TOF}-t_{#pi,exp} [ps];Counts",500, 0.,5.,1000, -25000., 25000. ) ; 
444   hTOFtheoreticalExpTimePiVsP->Sumw2() ;
445   fHlistPID->AddLast(hTOFtheoreticalExpTimePiVsP) ;
446
447   //PID 7
448   TH2F* hTOFExpSigmaPi = new TH2F("hTOFExpSigmaPi", "ESDs TOF n#sigma_{PID,#pi} vs p_{T}; p_{T} (GeV/c); n#sigma_{PID,#pi};Tracks", 500,0.,5.,200, -10., 10. ) ; 
449   hTOFExpSigmaPi->Sumw2() ;
450   fHlistPID->AddLast(hTOFExpSigmaPi) ;
451
452   //PID 8
453   TH1F* hTOFmatchedExpTimeKa = new TH1F("hTOFmatchedExpTimeKa", "ESDs t_{TOF}-t_{K,exp} (from tracking); t_{TOF}-t_{K,exp} [ps];Counts", 500, -5000., 5000. ) ; 
454   hTOFmatchedExpTimeKa->Sumw2() ;
455   hTOFmatchedExpTimeKa->SetLineWidth(1);
456   hTOFmatchedExpTimeKa->SetLineColor(kBlue);
457   hTOFmatchedExpTimeKa->SetMarkerStyle(21);
458   hTOFmatchedExpTimeKa->SetMarkerSize(0.8); 
459   hTOFmatchedExpTimeKa->SetMarkerColor(kBlue);
460   fHlistPID->AddLast(hTOFmatchedExpTimeKa);
461
462   //PID 9
463   TH2F* hTOFmatchedExpTimeKaVsP = new TH2F("hTOFmatchedExpTimeKaVsP", "ESDs t_{TOF}-t_{K,exp} (from tracking) Vs P ; p (GeV/c);t_{TOF}-t_{K,exp} [ps];Counts",500, 0.,5.,1000, -25000., 25000. ) ; 
464   hTOFmatchedExpTimeKaVsP->Sumw2() ;
465   fHlistPID->AddLast(hTOFmatchedExpTimeKaVsP) ; 
466   
467   //PID 10
468   TH1F* hTOFtheoreticalExpTimeKa = new TH1F("hTOFtheoreticalExpTimeKa", "ESDs t_{TOF}-t_{K,exp} (theoretical); t_{TOF}-t_{K,exp} [ps];Counts", 5000, -25000., 25000. ) ; 
469   hTOFtheoreticalExpTimeKa->Sumw2() ;
470   hTOFtheoreticalExpTimeKa->SetLineWidth(1);
471   hTOFtheoreticalExpTimeKa->SetLineColor(kBlue);
472   hTOFtheoreticalExpTimeKa->SetMarkerStyle(24);
473   hTOFtheoreticalExpTimeKa->SetMarkerSize(0.8); 
474   hTOFtheoreticalExpTimeKa->SetMarkerColor(kBlue);
475   fHlistPID->AddLast(hTOFtheoreticalExpTimeKa) ;  
476   
477   //PID 11
478   TH2F* hTOFtheoreticalExpTimeKaVsP = new TH2F("hTOFtheoreticalExpTimeKaVsP", "ESDs t_{TOF}-t_{K,exp} (theoretical) Vs P ; p (GeV/c);t_{TOF}-t_{K,exp} [ps];Counts",500, 0.,5.,1000, -25000., 25000. ) ; 
479   hTOFtheoreticalExpTimeKaVsP->Sumw2() ;
480   fHlistPID->AddLast(hTOFtheoreticalExpTimeKaVsP) ; 
481   
482   //PID 12
483   TH2F* hTOFExpSigmaKa = new TH2F("hTOFExpSigmaKa", "ESDs TOF n#sigma_{PID,K} vs p_{T}; p_{T} (GeV/c);n#sigma_{PID,K};Tracks", 500, 0.,5.,200, -10., 10. ) ; 
484   hTOFExpSigmaKa->Sumw2() ;
485   fHlistPID->AddLast(hTOFExpSigmaKa) ;
486   
487   //PID 13
488   TH1F* hTOFmatchedExpTimePro = new TH1F("hTOFmatchedExpTimePro", "ESDs t_{TOF}-t_{p,exp} (from tracking); t_{TOF}-t_{p,exp} [ps];Counts", 500, -5000., 5000. ) ; 
489   hTOFmatchedExpTimePro->Sumw2() ;
490   hTOFmatchedExpTimePro->SetLineWidth(1);
491   hTOFmatchedExpTimePro->SetLineColor(kGreen+1);
492   hTOFmatchedExpTimePro->SetMarkerStyle(22);
493   hTOFmatchedExpTimePro->SetMarkerSize(0.8); 
494   hTOFmatchedExpTimePro->SetMarkerColor(kGreen+1);
495   fHlistPID->AddLast(hTOFmatchedExpTimePro) ;
496
497    //PID 14
498   TH2F* hTOFmatchedExpTimeProVsP = new TH2F("hTOFmatchedExpTimeProVsP", "ESDs t_{TOF}-t_{p,exp} (from tracking) Vs P ; p (GeV/c);t_{TOF}-t_{p,exp} [ps];Counts",500, 0.,5.,1000, -25000., 25000. ) ; 
499   hTOFmatchedExpTimeProVsP->Sumw2() ;
500   fHlistPID->AddLast(hTOFmatchedExpTimeProVsP) ;
501   
502   //PID 15
503   TH1F* hTOFtheoreticalExpTimePro = new TH1F("hTOFtheoreticalExpTimePro", "ESDs t_{TOF}-t_{p,exp} (theoretical); t_{TOF}-t_{p,exp} [ps];Counts", 500, -5000., 5000. ) ; 
504   hTOFtheoreticalExpTimePro->Sumw2() ;
505   hTOFtheoreticalExpTimePro->SetLineWidth(1);
506   hTOFtheoreticalExpTimePro->SetLineColor(kGreen+1);
507   hTOFtheoreticalExpTimePro->SetMarkerStyle(26);
508   hTOFtheoreticalExpTimePro->SetMarkerSize(0.8); 
509   hTOFtheoreticalExpTimePro->SetMarkerColor(kGreen+1);
510   fHlistPID->AddLast(hTOFtheoreticalExpTimePro) ;
511
512   //PID 16
513   TH2F* hTOFtheoreticalExpTimeProVsP = new TH2F("hTOFtheoreticalExpTimeProVsP", "ESDs t_{TOF}-t_{p,exp} (theoretical) Vs P ; p (GeV/c);t_{TOF}-t_{p,exp} [ps];Counts",500, 0.,5.,1000, -25000., 25000. ) ; 
514   hTOFtheoreticalExpTimeProVsP->Sumw2() ;
515   fHlistPID->AddLast(hTOFtheoreticalExpTimeProVsP) ;
516
517   //PID 17
518   TH2F* hTOFExpSigmaPro = new TH2F("hTOFExpSigmaPro", "ESDs TOF n#sigma_{PID,p} vs. p_{T}; p_{T} (GeV/c); n#sigma_{PID,p};Tracks", 500, 0.,5.,200, -10., 10. ) ; 
519   hTOFExpSigmaPro->Sumw2() ;
520   fHlistPID->AddLast(hTOFExpSigmaPro) ;
521
522   PostData(1, fHlist);
523   PostData(2, fHlistTimeZero);
524   PostData(3, fHlistPID);
525
526 }
527 //________________________________________________________________________
528 void AliAnalysisTaskTOFqa::UserExec(Option_t *) 
529
530   /* Main - executed for each event.
531     It extracts event information and track information after selecting 
532     primary tracks via standard cuts. */
533   
534   AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
535   if (!esdH) {
536     Printf("ERROR: Could not get ESDInputHandler");
537     return;
538   } else {
539     fESD = (AliESDEvent*) esdH->GetEvent();
540   } 
541   
542   if (!fESD) {
543     Printf("ERROR: fESD not available");
544     return;
545   }
546   
547   /* info from T0 detector QA */
548   for (Int_t j=0;j<3;j++){
549     fT0[j]= (Float_t) fESD->GetT0TOF(j);//ps
550     if (fT0[j]>90000.) fT0[j]=99999.;//fix old default values to the new one
551   }
552   Float_t t0cut = 90000.; 
553   //Float_t t0cut =3 * t0spread; //use this cut to check t0 used in tof response
554   // if(t0cut < 500) t0cut = 500;
555   
556   if(TMath::Abs(fT0[1]) < t0cut && TMath::Abs(fT0[2]) < t0cut ) {
557     //&& TMath::Abs(fT0[2]-fT0[1]) < 500)  //add this condition to check t0 used in tof response
558     ((TH1F*)fHlistTimeZero->At(3))->Fill((fT0[2]-fT0[1])*0.5);
559     ((TH1F*)fHlistTimeZero->At(0))->Fill(fT0[0]);  
560   } 
561   if(TMath::Abs(fT0[1]) < t0cut){
562     ((TH1F*)fHlistTimeZero->At(1))->Fill(fT0[1]);   
563   }
564   if(TMath::Abs(fT0[2]) < t0cut){
565     ((TH1F*)fHlistTimeZero->At(2))->Fill(fT0[2]);
566   }
567   
568   /*  event timeZero QA via AliESDpid::SetTOFResponse() */
569   Double_t timeZero[4]={99999.,99999.,99999.,99999.};
570   Double_t timeZeroRes[4]={99999.,99999.,99999.,99999.}; 
571   
572   for (Int_t j=0;j<4;j++){
573     fESDpid->SetTOFResponse(fESD, (AliESDpid::EStartTimeType_t) j);//(fill_t0, tof_t0, t0_t0, best_t0)
574     timeZero[j]=fESDpid->GetTOFResponse().GetStartTime(10.); //timeZero for bin pT>10GeV/c
575     timeZeroRes[j]=fESDpid->GetTOFResponse().GetStartTimeRes(10.); //timeZero for bin pT>10GeV/c
576     ((TH1D*)fHlistTimeZero->At(4+j))->Fill(timeZero[j]);
577     ((TH1D*)fHlistTimeZero->At(8+j))->Fill(timeZeroRes[j]);
578   }
579
580
581   /* loop over ESD tracks */
582   fNTOFtracks=0;
583   // fNPrimaryTracks=0;
584
585   for (Int_t iTracks = 0; iTracks < fESD->GetNumberOfTracks(); iTracks++) {
586     AliESDtrack* track = fESD->GetTrack(iTracks);
587     if (!track) {
588       Printf("ERROR: Could not receive track %d", iTracks);
589       continue;
590     }
591
592     //primary tracks selection: kTPCrefit and std cuts
593     if(!fTrackFilter->IsSelected(track)) continue;
594     Double_t eta=track->Eta();
595     if (TMath::Abs(eta)>0.9) continue; //cut for acceptance
596
597     Double_t mom=track->P();
598     Double_t mom2 = mom*mom;
599     Double_t length=track->GetIntegratedLength();
600     Double_t pT = track->Pt();
601     Double_t phi=track->Phi()*TMath::RadToDeg();
602     track->GetIntegratedTimes(fTrkExpTimes);
603       
604     ((TH1F*)fHlist->At(9))->Fill(mom); 
605     ((TH1F*)fHlist->At(10))->Fill(pT); 
606     if (pT>=0.5)
607       ((TH1F*)fHlist->At(11))->Fill(eta);
608     ((TH1F*)fHlist->At(12))->Fill(phi);
609     
610     //matched tracks selection: kTOFout and kTIME
611     if ((track->GetStatus() & AliESDtrack::kTOFout) &&
612         (track->GetStatus() & AliESDtrack::kTIME)) {      
613       
614       Double_t tofTime=track->GetTOFsignal();//in ps
615       Double_t tofTimeRaw=track->GetTOFsignalRaw();//in ps
616       Double_t tofToT=track->GetTOFsignalToT(); //in ps
617       Int_t channel=track->GetTOFCalChannel(); 
618       Int_t volId[5]; //(sector, plate,strip,padZ,padX)
619       AliTOFGeometry::GetVolumeIndices(channel,volId);
620       
621       if (pT>=0.3) fNTOFtracks++; //matched counter
622       Double_t tof= tofTime*1E-3; // ns, average T0 fill subtracted, no info from T0detector     
623       ((TH1F*)fHlist->At(1))->Fill(tof); //ns
624       ((TH1F*)fHlist->At(2))->Fill(tofTimeRaw*1E-3); //ns
625       ((TH1F*)fHlist->At(3))->Fill(tofToT);
626       ((TH1F*)fHlist->At(4))->Fill(length);  
627       ((TH1F*)fHlist->At(5))->Fill(mom);
628       ((TH1F*)fHlist->At(6))->Fill(pT);
629       if (pT>=0.5)
630         ((TH1F*)fHlist->At(7))->Fill(eta);
631       ((TH1F*)fHlist->At(8))->Fill(phi);
632       if (track->GetSign()>0)
633         ((TH2F*)fHlist->At(13))->Fill(pT,track->GetTOFsignalDx());
634       else ((TH2F*)fHlist->At(14))->Fill(pT,track->GetTOFsignalDx());
635       ((TH2F*)fHlist->At(15))->Fill((Int_t)GetStripIndex(volId),track->GetTOFsignalDz());
636
637       //basic PID performance check
638       if (tof<=0) {
639         printf("WARNING: track with negative TOF time found! Skipping this track for PID checks\n");
640         continue;
641       }
642       if (mom2==0) {
643         printf("WARNING: track with negative square momentum found! Skipping this track for PID checks\n");
644         continue;
645       }
646       if (length<=0){
647         printf("WARNING: track with negative length found!Skipping this track for PID checks\n");
648         continue;
649       }
650       Double_t c=TMath::C()*1.E-9;// m/ns
651       Double_t mass=0.; //GeV
652       length =length*0.01; // in meters
653       tof=tof*c;
654       Double_t beta=length/tof;
655       Double_t fact= (tof/length)*(tof/length) -1.;
656       if(fact<=0) {
657         mass = -mom*TMath::Sqrt(-fact);
658       }else{ 
659         mass = mom*TMath::Sqrt(fact); 
660       }
661       ((TH2F*)fHlistPID->At(0))->Fill(mom,beta);
662       ((TH1F*) fHlistPID->At(1))->Fill(mass);
663       
664       //PID sigmas
665       Bool_t isValidBeta[AliPID::kSPECIES]={0,0,0,0,0};
666       for (Int_t specie = 0; specie < AliPID::kSPECIES; specie++){
667         fSigmaSpecie[specie] = fESDpid->GetTOFResponse().GetExpectedSigma(mom, fTrkExpTimes[specie], AliPID::ParticleMass(specie));
668         beta=1/TMath::Sqrt(1+AliPID::ParticleMass(specie)*AliPID::ParticleMass(specie)/(mom2));
669         if (beta>0) {
670           fThExpTimes[specie]=length*1.E3/(beta*c);//ps
671           isValidBeta[specie]=kTRUE;
672         } else {
673           fThExpTimes[specie]=1E-10;
674           isValidBeta[specie]=kFALSE;
675         }
676       }
677       
678       if (isValidBeta[AliPID::kPion]){
679         ((TH2F*)fHlistPID->At(2))->Fill((Int_t)GetStripIndex(volId),tofTime-fTrkExpTimes[AliPID::kPion]);//ps
680         ((TH1F*)fHlistPID->At(3))->Fill(tofTime-fTrkExpTimes[AliPID::kPion]);//ps
681         ((TH2F*)fHlistPID->At(4))->Fill(mom,(tofTime-fTrkExpTimes[AliPID::kPion]));
682         ((TH1F*)fHlistPID->At(5))->Fill(tofTime-fThExpTimes[AliPID::kPion]);//ps
683         ((TH2F*)fHlistPID->At(6))->Fill(mom,(tofTime-fThExpTimes[AliPID::kPion]));      
684         ((TH2F*)fHlistPID->At(7))->Fill(pT,(tofTime-fTrkExpTimes[AliPID::kPion])/fSigmaSpecie[AliPID::kPion]);
685       }
686       
687       if (isValidBeta[AliPID::kKaon]){
688         ((TH1F*)fHlistPID->At(8))->Fill(tofTime-fTrkExpTimes[AliPID::kKaon]);//ps
689         ((TH2F*)fHlistPID->At(9))->Fill(mom,(tofTime-fTrkExpTimes[AliPID::kKaon]));
690         ((TH1F*)fHlistPID->At(10))->Fill(tofTime-fThExpTimes[AliPID::kKaon]);//ps
691         ((TH2F*)fHlistPID->At(11))->Fill(mom,(tofTime-fThExpTimes[AliPID::kKaon]));
692         ((TH2F*)fHlistPID->At(12))->Fill(pT,(tofTime-fTrkExpTimes[AliPID::kKaon])/fSigmaSpecie[AliPID::kKaon]);
693       }
694       if (isValidBeta[AliPID::kProton]){
695         ((TH1F*)fHlistPID->At(13))->Fill(tofTime-fTrkExpTimes[AliPID::kProton]);//ps
696         ((TH2F*)fHlistPID->At(14))->Fill(mom,(tofTime-fTrkExpTimes[AliPID::kProton]));
697         ((TH1F*)fHlistPID->At(15))->Fill(tofTime-fThExpTimes[AliPID::kProton]);//ps
698         ((TH2F*)fHlistPID->At(16))->Fill(mom,(tofTime-fThExpTimes[AliPID::kProton]));
699         ((TH2F*)fHlistPID->At(17))->Fill(pT,(tofTime-fTrkExpTimes[AliPID::kProton])/fSigmaSpecie[AliPID::kProton]);
700       }
701     }//matched
702   }//end loop on tracks
703   
704   ((TH1F*)fHlist->At(0))->Fill(fNTOFtracks) ;
705   ((TH2F*)fHlistTimeZero->At(12))->Fill(fNTOFtracks,timeZero[AliESDpid::kTOF_T0]);
706   
707   PostData(1, fHlist);
708   PostData(2, fHlistTimeZero);
709   PostData(3, fHlistPID);
710   
711   
712 }      
713
714 //________________________________________________________________________
715 void AliAnalysisTaskTOFqa::Terminate(Option_t *) 
716 {
717   //check on output validity
718   fHlist = dynamic_cast<TList*> (GetOutputData(1));
719   if (!fHlist || !fHlistTimeZero) {
720     Printf("ERROR: lists not available");
721     return;   
722   }   
723  
724 }
725
726 //---------------------------------------------------------------
727 Int_t AliAnalysisTaskTOFqa::GetStripIndex(const Int_t * const in)
728 {
729   /* return tof strip index between 0 and 91 */
730   
731   Int_t nStripA = AliTOFGeometry::NStripA();
732   Int_t nStripB = AliTOFGeometry::NStripB();
733   Int_t nStripC = AliTOFGeometry::NStripC();
734
735   Int_t iplate = in[1];
736   Int_t istrip = in[2];
737   
738   Int_t stripOffset = 0;
739   switch (iplate) {
740   case 0:
741     stripOffset = 0;
742       break;
743   case 1:
744     stripOffset = nStripC;
745     break;
746   case 2:
747     stripOffset = nStripC+nStripB;
748     break;
749   case 3:
750     stripOffset = nStripC+nStripB+nStripA;
751     break;
752   case 4:
753     stripOffset = nStripC+nStripB+nStripA+nStripB;
754     break;
755   default:
756     stripOffset=-1;
757     break;
758   };
759   
760   if (stripOffset<0 || stripOffset>92) return -1;
761   else 
762     return (stripOffset+istrip);
763 }
764
765 #endif