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