Updates
[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   fEnableAdvancedCheck(kFALSE),
37   fExpTimeBinWidth(24.4),
38   fExpTimeRangeMin(-25010.),
39   fExpTimeRangeMax(25010.),
40   fExpTimeSmallRangeMin(-5002.),
41   fExpTimeSmallRangeMax(5002.),
42   fHlist(0x0),
43   fHlistTimeZero(0x0),
44   fHlistPID(0x0),
45   fHpos(0x0),
46   fHneg(0x0)
47  {
48   // Default constructor
49    
50    for (Int_t j=0;j<3;j++ ) {
51      if (j<3) fT0[j]=0.0;
52      fSigmaSpecie[j]=0.0;
53      fTrkExpTimes[j]=0.0;
54      fThExpTimes[j]=0.0;
55    }
56  }
57 //________________________________________________________________________
58 AliAnalysisTaskTOFqa::AliAnalysisTaskTOFqa(const char *name) : 
59   AliAnalysisTaskSE(name), 
60   fRunNumber(0), 
61   fESD(0x0), 
62   fTrackFilter(0x0),
63   fVertex(0x0),
64   fESDpid(new AliESDpid()),
65   fNTOFtracks(0), 
66   // fNPrimaryTracks(0),
67   fEnableAdvancedCheck(kFALSE),
68   fExpTimeBinWidth(24.4),
69   fExpTimeRangeMin(-25010.),
70   fExpTimeRangeMax(25010.),
71   fExpTimeSmallRangeMin(-5002.),
72   fExpTimeSmallRangeMax(5002.),
73   fHlist(0x0),
74   fHlistTimeZero(0),
75   fHlistPID(0x0),
76   fHpos(0x0),
77   fHneg(0x0)
78  {
79   // Constructor
80   // Define input and output slots here
81    Info("AliAnalysisTaskTOFqa","Calling Constructor");
82    
83    for (Int_t j=0;j<5;j++ ) {
84      if (j<3) fT0[j]=0.0;
85      fSigmaSpecie[j]=0.0;
86      fTrkExpTimes[j]=0.0;
87      fThExpTimes[j]=0.0;
88    }
89    // Input slot #0 works with a TChain
90    DefineInput(0, TChain::Class());
91    
92    // Output slot #0 writes into a TH1 container
93    // Output slot #1 writes into a user defined  container
94    DefineOutput(1, TList::Class());
95    DefineOutput(2, TList::Class());
96    DefineOutput(3, TList::Class());
97    DefineOutput(4, TList::Class());
98    DefineOutput(5, TList::Class());
99  }
100
101 //________________________________________________________________________
102 AliAnalysisTaskTOFqa::AliAnalysisTaskTOFqa(const AliAnalysisTaskTOFqa& copy) 
103 : AliAnalysisTaskSE(), 
104   fRunNumber(copy.fRunNumber), 
105   fESD(copy.fESD), 
106   fTrackFilter(copy.fTrackFilter), 
107   fVertex(copy.fVertex),
108   fESDpid(copy.fESDpid),
109   fNTOFtracks(copy.fNTOFtracks), 
110   //fNPrimaryTracks(copy.fNPrimaryTracks), 
111   fEnableAdvancedCheck(copy.fEnableAdvancedCheck),
112   fExpTimeBinWidth(copy.fExpTimeBinWidth),
113   fExpTimeRangeMin(copy.fExpTimeRangeMin),
114   fExpTimeRangeMax(copy.fExpTimeRangeMax),
115   fExpTimeSmallRangeMin(copy.fExpTimeSmallRangeMin),
116   fExpTimeSmallRangeMax(copy.fExpTimeSmallRangeMax),
117   fHlist(copy.fHlist),
118   fHlistTimeZero(copy.fHlistTimeZero),
119   fHlistPID(copy.fHlistPID),
120   fHpos(copy.fHpos),
121   fHneg(copy.fHneg)
122 {
123   // Copy constructor
124    for (Int_t j=0;j<5;j++ ) {
125      if (j<3) fT0[j]=copy.fT0[j];
126      fSigmaSpecie[j]=copy.fSigmaSpecie[j];
127      fTrkExpTimes[j]=copy.fTrkExpTimes[j];
128      fThExpTimes[j]=copy.fThExpTimes[j];
129    }
130   
131
132 }
133
134 //___________________________________________________________________________
135 AliAnalysisTaskTOFqa& AliAnalysisTaskTOFqa::operator=(const AliAnalysisTaskTOFqa& copy) 
136 {
137   //
138   // Assignment operator
139   //
140   if (this!=&copy) {
141     AliAnalysisTaskSE::operator=(copy) ;
142     fRunNumber=copy.fRunNumber; 
143     fESD=copy.fESD;
144     fTrackFilter=copy.fTrackFilter;
145     fVertex=copy.fVertex;
146     fESDpid=copy.fESDpid;
147     fNTOFtracks=copy.fNTOFtracks; 
148     fEnableAdvancedCheck=copy.fEnableAdvancedCheck;
149     fEnableAdvancedCheck=copy.fEnableAdvancedCheck;
150     fExpTimeBinWidth=copy.fExpTimeBinWidth;
151     fExpTimeRangeMin=copy.fExpTimeRangeMin;
152     fExpTimeRangeMax=copy.fExpTimeRangeMax;
153     fExpTimeSmallRangeMin=copy.fExpTimeSmallRangeMin;
154     fExpTimeSmallRangeMax=copy.fExpTimeSmallRangeMax;
155     
156     //fNPrimaryTracks=copy.fNPrimaryTracks; 
157     for (Int_t j=0;j<5;j++ ) {
158       if (j<3) fT0[j]=copy.fT0[j];
159       fSigmaSpecie[j]=copy.fSigmaSpecie[j];
160       fTrkExpTimes[j]=copy.fTrkExpTimes[j];
161       fThExpTimes[j]=copy.fThExpTimes[j];
162     }
163     fHlist=copy.fHlist;
164     fHlistTimeZero=copy.fHlistTimeZero;
165     fHlistPID=copy.fHlistPID;
166     fHpos=copy.fHpos;
167     fHneg=copy.fHneg;
168   }
169   return *this;
170 }
171
172 //___________________________________________________________________________
173 AliAnalysisTaskTOFqa::~AliAnalysisTaskTOFqa() {
174   //
175   //destructor
176   //
177
178   Info("~AliAnalysisTaskTOFqa","Calling Destructor");
179   if (fESDpid) delete fESDpid;
180   if (fVertex) delete fVertex;
181   if (fTrackFilter) delete fTrackFilter;
182   if (AliAnalysisManager::GetAnalysisManager()->IsProofMode()) return;  
183   if (fHlist) {
184     delete fHlist;
185     fHlist = 0;
186   }
187   if (fHlistTimeZero) {
188     delete fHlistTimeZero;
189     fHlistTimeZero = 0;
190   }
191   if (fHlistPID){
192     delete fHlistPID;
193     fHlistPID = 0;
194   }
195   if (fHpos){
196     delete fHpos;
197     fHpos = 0;
198   }
199   if (fHneg){
200     delete fHneg;
201     fHneg = 0;
202   }
203 }
204
205 //________________________________________________________________________
206 void AliAnalysisTaskTOFqa::UserCreateOutputObjects()
207 {
208   //Defines output objects and histograms
209   Info("CreateOutputObjects","CreateOutputObjects (TList) of task %s", GetName());
210   OpenFile(1);
211   if (!fHlist) fHlist = new TList();    
212   fHlist->SetOwner(kTRUE);
213   if (!fHlistTimeZero) fHlistTimeZero = new TList();    
214   fHlistTimeZero->SetOwner(kTRUE);
215   if (!fHlistPID) fHlistPID = new TList();      
216   fHlistPID->SetOwner(kTRUE);
217   if (!fHpos) fHpos = new TList();      
218   fHpos->SetOwner(kTRUE);
219   if (!fHneg) fHneg = new TList();      
220   fHneg->SetOwner(kTRUE);
221
222   Int_t nExpTimeBins=1;
223   Int_t nExpTimeSmallBins=1;
224   
225   if (fExpTimeRangeMax<fExpTimeRangeMin) {
226     SetExpTimeHistoRange(-25010.,25010.);
227   }
228   nExpTimeBins = TMath::Nint((fExpTimeRangeMax - fExpTimeRangeMin)/fExpTimeBinWidth);//ps
229   fExpTimeRangeMax=fExpTimeRangeMin+nExpTimeBins*fExpTimeBinWidth;//ps
230   
231   if (fExpTimeSmallRangeMax<fExpTimeSmallRangeMin) {
232     SetExpTimeHistoSmallRange(-5002.,5002.);
233   }
234   nExpTimeSmallBins = TMath::Nint((fExpTimeSmallRangeMax - fExpTimeSmallRangeMin)/fExpTimeBinWidth);//ps
235   fExpTimeSmallRangeMax=fExpTimeSmallRangeMin+nExpTimeSmallBins*fExpTimeBinWidth;//ps
236   
237   //  nExpTimeSmallBins, fExpTimeSmallRangeMin, fExpTimeSmallRangeMax
238   //  nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax
239
240 //0
241   TH1I* hTOFmatchedESDperEvt = new TH1I("hTOFmatchedPerEvt", "Matched TOF tracks per event (|#eta| #leq 0.8 and pT #geq 0.3 GeV/c);TOF-matched ESD tracks;Events", 100, 0, 100) ;  
242   hTOFmatchedESDperEvt->Sumw2() ;
243   hTOFmatchedESDperEvt->SetLineWidth(2);
244   hTOFmatchedESDperEvt->SetLineColor(kBlue);
245   hTOFmatchedESDperEvt->SetMarkerStyle(20);
246   hTOFmatchedESDperEvt->SetMarkerSize(0.8);
247   hTOFmatchedESDperEvt->SetMarkerColor(kBlue);
248   fHlist->AddLast(hTOFmatchedESDperEvt) ;
249   //1
250   TH1F* hTOFmatchedESDtime = new TH1F("hTOFmatchedESDtime", "Matched  ESDs tracks: TOF Time spectrum; t [ns];Counts", 250, 0., 610. ) ; 
251   hTOFmatchedESDtime->Sumw2() ;
252   hTOFmatchedESDtime->SetLineWidth(2);
253   hTOFmatchedESDtime->SetLineColor(kBlue);
254   hTOFmatchedESDtime->SetFillColor(kBlue);
255   hTOFmatchedESDtime->SetDrawOption("BAR");
256   fHlist->AddLast(hTOFmatchedESDtime) ;
257   //2
258   TH1F* hTOFmatchedESDrawTime = new TH1F("hTOFmatchedESDrawTime", "Matched ESDs tracks: TOF raw Time spectrum;t_{raw} [ns];Counts", 250, 0., 610.) ; 
259   hTOFmatchedESDrawTime->Sumw2() ;
260   hTOFmatchedESDrawTime->SetLineWidth(2);
261   hTOFmatchedESDrawTime->SetLineColor(kAzure+2);
262   hTOFmatchedESDrawTime->SetFillColor(kAzure+2);
263   hTOFmatchedESDrawTime->SetDrawOption("BAR");
264   fHlist->AddLast(hTOFmatchedESDrawTime) ;
265   //3
266   TH1F* hTOFmatchedESDToT = new TH1F("hTOFmatchedESDToT", "Matched ESDs tracks: TOF ToT spectrum; ToT [ns];Counts",100, 0., 48.8) ; 
267   hTOFmatchedESDToT->Sumw2() ;
268   hTOFmatchedESDToT->SetLineColor(kOrange+1);
269   hTOFmatchedESDToT->SetMarkerColor(kOrange+1);
270   hTOFmatchedESDToT->SetFillColor(kOrange+1);
271   hTOFmatchedESDToT->SetDrawOption("BAR");
272   fHlist->AddLast(hTOFmatchedESDToT) ;
273   //4
274   TH1F* hTOFmatchedESDtrkLength  = new TH1F("hTOFmatchedESDtrkLength", "Matched ESDs tracks length; Track length [cm];Counts", 1200, -400., 800) ; 
275   hTOFmatchedESDtrkLength->Sumw2();
276   hTOFmatchedESDtrkLength->SetLineColor(kViolet-3);
277   hTOFmatchedESDtrkLength->SetMarkerColor(kViolet-3);
278   hTOFmatchedESDtrkLength->SetFillColor(kViolet-3);
279   hTOFmatchedESDtrkLength->SetDrawOption("BAR"); 
280   fHlist->AddLast(hTOFmatchedESDtrkLength);
281   //5
282   TH1F* hTOFmatchedESDP  = new TH1F("hTOFmatchedESDP", "TPC-TOF matched tracks momentum distribution (GeV/c); p (GeV/c);tracks", 500,0.,5.) ;  
283   hTOFmatchedESDP->Sumw2() ;
284   hTOFmatchedESDP->SetLineColor(kBlue);
285   hTOFmatchedESDP->SetMarkerStyle(20);
286   hTOFmatchedESDP->SetMarkerSize(0.7);
287   hTOFmatchedESDP->SetMarkerColor(kBlue);
288   fHlist->AddLast(hTOFmatchedESDP) ; 
289   //6
290   TH1F* hTOFmatchedESDPt  = new TH1F("hTOFmatchedESDPt", "TPC-TOF matched tracks p_{T} distribution (GeV/c); p_{T}(GeV/c);tracks", 500,0.,5.) ;  
291   hTOFmatchedESDPt->Sumw2() ;
292   hTOFmatchedESDPt->SetLineColor(kBlue);
293   hTOFmatchedESDPt->SetMarkerStyle(21);
294   hTOFmatchedESDPt->SetMarkerSize(0.7);
295   hTOFmatchedESDPt->SetMarkerColor(kBlue);
296   fHlist->AddLast(hTOFmatchedESDPt) ; 
297
298   //7
299   TH1F* hTOFmatchedESDeta = new TH1F("hTOFmatchedESDeta", "Matched ESDtracks #eta (p_{T} #geq 0.5 GeV/c); #eta;Counts", 200, -1., 1.) ; 
300   hTOFmatchedESDeta->Sumw2();
301   hTOFmatchedESDeta->SetLineColor(kBlue);
302   fHlist->AddLast(hTOFmatchedESDeta) ; 
303   //8
304    TH1F* hTOFmatchedESDphi = new TH1F("hTOFmatchedESDphi", "Matched ESDtracks #phi; #phi (deg);Counts", 72, 0., 360.) ; 
305   hTOFmatchedESDphi->Sumw2();
306   hTOFmatchedESDphi->SetLineColor(kBlue);
307   fHlist->AddLast(hTOFmatchedESDphi) ; 
308
309   //9
310   TH1F* hESDprimaryTrackP = new TH1F("hESDprimaryTrackP", "All ESDs tracks p distribution (GeV/c); p(GeV/c);tracks", 500, 0., 5.0) ;  
311   hESDprimaryTrackP->Sumw2();
312   hESDprimaryTrackP->SetLineWidth(1);
313   hESDprimaryTrackP->SetMarkerStyle(24);
314   hESDprimaryTrackP->SetMarkerSize(0.7);
315   hESDprimaryTrackP->SetMarkerColor(kRed);
316   hESDprimaryTrackP->SetLineColor(kRed);
317   fHlist->AddLast(hESDprimaryTrackP);
318   //10
319   TH1F* hESDprimaryTrackPt = new TH1F("hESDprimaryTrackPt", "ESDs primary tracks p_{T} distribution (GeV/c); p_{T}(GeV/c);tracks", 500, 0.0, 5.0) ;  
320   hESDprimaryTrackPt->Sumw2();
321   hESDprimaryTrackPt->SetLineWidth(1);
322   hESDprimaryTrackPt->SetMarkerStyle(25);
323   hESDprimaryTrackPt->SetMarkerSize(0.7);
324   hESDprimaryTrackPt->SetLineColor(kRed);
325   hESDprimaryTrackPt->SetMarkerColor(kRed);
326   fHlist->AddLast(hESDprimaryTrackPt);
327   //11
328   TH1F* hTOFprimaryESDeta = new TH1F("hTOFprimaryESDeta", "Primary ESDtracks #eta (p_{T} #geq 0.5 GeV/c); #eta;Counts",200, -1., 1.) ; 
329   hTOFprimaryESDeta->Sumw2();
330   hTOFprimaryESDeta->SetLineColor(kRed);
331   fHlist->AddLast(hTOFprimaryESDeta) ; 
332   //12
333   TH1F* hTOFprimaryESDphi = new TH1F("hTOFprimaryESDphi", "Primary ESDtracks #phi;#phi (deg);Counts", 72, 0., 360.) ; 
334   hTOFprimaryESDphi->Sumw2();
335   hTOFprimaryESDphi->SetLineColor(kRed);
336   fHlist->AddLast(hTOFprimaryESDphi) ; 
337   //13
338   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.) ; 
339   hTOFmatchedDxVsPtPos->Sumw2();
340   fHlist->AddLast(hTOFmatchedDxVsPtPos) ; 
341  //14
342   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.) ; 
343   hTOFmatchedDxVsPtNeg->Sumw2();
344   fHlist->AddLast(hTOFmatchedDxVsPtNeg) ; 
345
346   //15
347   TH2F* hTOFmatchedDzVsStrip = new TH2F("hTOFmatchedDzVsStrip", "Dz vs strip; strip (#eta); Dz [cm]; hits", 92,0.,92.,200, -10., 10.) ; 
348   hTOFmatchedDzVsStrip->Sumw2();
349   fHlist->AddLast(hTOFmatchedDzVsStrip) ; 
350  
351  //----------------------------------------------timeZero QA plots
352   //TimeZero 0
353   TH1D* hEventT0DetAND = new TH1D("hEventT0DetAND", "Event timeZero from T0AC detector ; t0 [ps]; events", 1000, -25000., 25000. ) ; 
354   hEventT0DetAND->Sumw2() ;
355   hEventT0DetAND->SetLineWidth(2);
356   hEventT0DetAND->SetLineColor(kRed);
357   hEventT0DetAND->SetFillColor(kRed);
358   fHlistTimeZero->AddLast(hEventT0DetAND) ;
359
360   //TImeZero 1
361   TH1D* hEventT0DetA = new TH1D("hEventT0DetA", "Event timeZero from T0A detector; t0 [ps]; events", 1000, -25000., 25000. ) ; 
362   hEventT0DetA->Sumw2() ;
363   hEventT0DetA->SetLineWidth(2);
364   hEventT0DetA->SetLineColor(kBlue);
365   hEventT0DetA->SetFillColor(kBlue);
366   fHlistTimeZero->AddLast(hEventT0DetA) ;
367
368    //TImeZero 2
369   TH1D* hEventT0DetC = new TH1D("hEventT0DetC", "Event timeZero from T0C detector; t0 [ps]; events", 1000, -25000., 25000.) ; 
370   hEventT0DetC->Sumw2() ;
371   hEventT0DetC->SetLineWidth(2);
372   hEventT0DetC->SetLineColor(kGreen);
373   hEventT0DetC->SetFillColor(kGreen);
374   fHlistTimeZero->AddLast(hEventT0DetC);
375
376    //TimeZero 3
377   TH1F* hT0DetRes = new TH1F("hT0DetRes", "T0 detector (T0A-T0C)/2; (T0A-T0C)/2 [ps]; events", 200, -500.,500. ) ; 
378   hT0DetRes->Sumw2() ;
379   hT0DetRes->SetMarkerStyle(24);
380   hT0DetRes->SetMarkerSize(0.7);
381   hT0DetRes->SetMarkerColor(kMagenta+2);
382   hT0DetRes->SetLineColor(kMagenta+2);
383   hT0DetRes->SetFillColor(kMagenta+2);  
384   fHlistTimeZero->AddLast(hT0DetRes) ; 
385
386      //timeZero 4
387   TH1F* hT0fill = new TH1F("hT0fill", "Event timeZero of fill; t0 [ps]; events", 1000, -25000., 25000. ) ; 
388   hT0fill->Sumw2() ;
389   hT0fill->SetMarkerStyle(20);
390   hT0fill->SetMarkerColor(kBlack);
391   hT0fill->SetLineColor(kBlack);
392   fHlistTimeZero->AddLast(hT0fill) ; 
393
394   //TimeZero 5
395   TH1F* hT0TOF = new TH1F("hT0TOF", "Event timeZero estimated by TOF; t0 [ps]; events", 1000, -25000., 25000. ) ; 
396   hT0TOF->Sumw2() ;
397   hT0TOF->SetMarkerStyle(20);
398   hT0TOF->SetMarkerColor(kBlue);
399   hT0TOF->SetLineColor(kBlue);
400   hT0TOF->SetFillColor(kBlue);
401   fHlistTimeZero->AddLast(hT0TOF) ;
402
403
404    //timeZero 6
405   TH1F* hT0T0 = new TH1F("hT0T0", "Event timeZero measured by T0 detector (best between AC, A, C); t0 [ps]; events", 1000, -25000.,25000. ) ; 
406   hT0T0->Sumw2() ;
407   hT0T0->SetMarkerStyle(20);
408   hT0T0->SetMarkerColor(kGreen+1);
409   hT0T0->SetLineColor(kGreen+1);
410   hT0T0->SetFillColor(kGreen+1);
411   fHlistTimeZero->AddLast(hT0T0) ; 
412
413    //timeZero 7
414   TH1F* hT0best = new TH1F("hT0best", "Event timeZero estimated as T0best; t0 [ps]; events", 1000, -25000.,25000. ) ; 
415   hT0best->Sumw2() ;
416   hT0best->SetMarkerStyle(20);
417   hT0best->SetMarkerColor(kRed);
418   hT0best->SetLineColor(kRed);
419   hT0best->SetFillColor(kRed); 
420   fHlistTimeZero->AddLast(hT0best) ; 
421
422    //TimeZero 8
423   TH1F* hT0fillRes = new TH1F("hT0fillRes", "Resolution of fillT0; #sigma_{fillT0} [ps];events", 250, 0.,250. ) ; 
424   hT0fillRes->Sumw2() ;
425   hT0fillRes->SetMarkerStyle(21);
426   hT0fillRes->SetMarkerColor(kBlack);
427   hT0fillRes->SetLineColor(kBlack);
428   hT0fillRes->SetFillColor(kBlack); 
429   fHlistTimeZero->AddLast(hT0fillRes) ; 
430  
431   //TimeZero 9
432   TH1F* hT0TOFRes = new TH1F("hT0TOFRes", "Resolution of timeZero from TOF; #sigma_{TOFT0} [ps];events", 250, 0.,250. ) ; 
433   hT0TOFRes->Sumw2() ;
434   hT0TOFRes->SetLineWidth(1);
435   hT0TOFRes->SetMarkerStyle(21);
436   hT0TOFRes->SetMarkerColor(kBlue);
437   hT0TOFRes->SetLineColor(kBlue);
438   hT0TOFRes->SetFillColor(kBlue); 
439   fHlistTimeZero->AddLast(hT0TOFRes) ; 
440
441    //TimeZero 10
442   TH1F* hT0T0Res = new TH1F("hT0T0Res", "Resolution of timeZero from T0;#sigma_{T0T0}  [ps];events", 250, -0., 250. ) ; 
443   hT0T0Res->Sumw2() ;
444   hT0T0Res->SetMarkerStyle(21);
445   hT0T0Res->SetMarkerColor(kGreen+1);
446   hT0T0Res->SetLineColor(kGreen+1);
447   hT0T0Res->SetFillColor(kGreen+1); 
448   fHlistTimeZero->AddLast(hT0T0Res) ; 
449
450    //TimeZero 11
451   TH1F* hT0bestRes = new TH1F("hT0bestRes", "Resolution of bestT0; #sigma_{bestT0} [ps];events", 250, 0.,250. ) ; 
452   hT0bestRes->Sumw2() ;
453   hT0bestRes->SetMarkerStyle(21);
454   hT0bestRes->SetMarkerColor(kRed);
455   hT0bestRes->SetLineColor(kRed);
456   hT0bestRes->SetFillColor(kRed); 
457   fHlistTimeZero->AddLast(hT0bestRes) ; 
458
459   //timeZero 12
460   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. ) ; 
461   hT0TOFvsNtrk->Sumw2() ;
462   fHlistTimeZero->AddLast(hT0TOFvsNtrk) ;
463
464  //TimeZero 13
465   TH2F* hEventT0MeanVsVtx = new TH2F("hEventT0MeanVsVtx", "T0 detector: mean vs vertex ; (t0_{A}-t0_{C})/2 [ns]; (t0_{A}+t0_{C})/2 [ns]; events", 500, -25., 25., 500, -25., 25. ) ; 
466   hEventT0MeanVsVtx->Sumw2() ;
467   fHlistTimeZero->AddLast(hEventT0MeanVsVtx) ;
468
469  //TimeZero 14
470   TH2F* hEventV0MeanVsVtx = new TH2F("hEventV0MeanVsVtx", "V0 detector: mean vs vertex ; (V0_{A}-V0_{C})/2 [ns]; (V0_{A}+V0_{C})/2 [ns]; events", 500, -50., 50., 500, -50., 50. ) ; 
471   hEventV0MeanVsVtx->Sumw2() ;
472   fHlistTimeZero->AddLast(hEventV0MeanVsVtx) ;
473 //--------------------------------------------- TOF PID QA plots
474   //PID 0
475   TH2F* hTOFmatchedESDpVsBeta  = new TH2F("hTOFmatchedESDpVsBeta", "Matched ESDs tracks beta vs. p; p(GeV/c); beta", 500, 0.0, 5.0, 150, 0., 1.5) ; 
476   fHlistPID->AddLast(hTOFmatchedESDpVsBeta);
477   
478   //PID 1 
479   TH1F* hTOFmatchedMass= new TH1F("hTOFmatchedMass","Matched ESD tracks mass distribution - (L>0); M (GeV/c^{2}); entries", 500, 0., 5. );
480   hTOFmatchedMass->Sumw2();
481   hTOFmatchedMass->SetLineWidth(2);
482   hTOFmatchedMass->SetLineColor(kBlue);
483   hTOFmatchedMass->SetLineColor(kBlue);
484   fHlistPID->AddLast(hTOFmatchedMass);
485   
486   //PID 2
487   TH2F* hTOFmatchedExpTimePiVsEta = new TH2F("hTOFmatchedExpTimePiVsEta", "ESDs t_{TOF}-t_{#pi,exp} (from tracking); strip (#eta); t_{TOF}-t_{#pi,exp} [ps]", 92, 0, 92,  nExpTimeSmallBins, fExpTimeSmallRangeMin, fExpTimeSmallRangeMax) ; 
488   hTOFmatchedExpTimePiVsEta->Sumw2() ;
489   fHlistPID->AddLast(hTOFmatchedExpTimePiVsEta) ;
490   
491   //PID 3
492   TH1F* hTOFmatchedExpTimePi = new TH1F("hTOFmatchedExpTimePi", "ESDs t_{TOF}-t_{#pi,exp} (from tracking); t_{TOF}-t_{#pi,exp} [ps];Counts", nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax) ; 
493   hTOFmatchedExpTimePi->Sumw2() ;
494   hTOFmatchedExpTimePi->SetLineWidth(1);
495   hTOFmatchedExpTimePi->SetLineColor(kRed);
496   hTOFmatchedExpTimePi->SetMarkerStyle(20);
497   hTOFmatchedExpTimePi->SetMarkerSize(0.8); 
498   hTOFmatchedExpTimePi->SetMarkerColor(kRed);
499   fHlistPID->AddLast(hTOFmatchedExpTimePi) ;
500   
501   //PID 4
502   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., nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax) ; 
503   hTOFmatchedExpTimePiVsP->Sumw2() ;
504   fHlistPID->AddLast(hTOFmatchedExpTimePiVsP) ;
505
506   //PID 5
507   TH1F* hTOFtheoreticalExpTimePi = new TH1F("hTOFtheoreticalExpTimePi", "ESDs t_{TOF}-t_{#pi,exp} (theoretical); t_{TOF}-t_{#pi,exp} [ps];Counts", nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax) ; 
508   hTOFtheoreticalExpTimePi->Sumw2() ;
509   hTOFtheoreticalExpTimePi->SetLineWidth(1);
510   hTOFtheoreticalExpTimePi->SetLineColor(kRed);
511   hTOFtheoreticalExpTimePi->SetMarkerStyle(24);
512   hTOFtheoreticalExpTimePi->SetMarkerSize(0.8); 
513   hTOFtheoreticalExpTimePi->SetMarkerColor(kRed);
514   fHlistPID->AddLast(hTOFtheoreticalExpTimePi) ;
515
516   //PID 6
517   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., nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax) ; 
518   hTOFtheoreticalExpTimePiVsP->Sumw2() ;
519   fHlistPID->AddLast(hTOFtheoreticalExpTimePiVsP) ;
520
521   //PID 7
522   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. ) ; 
523   hTOFExpSigmaPi->Sumw2() ;
524   fHlistPID->AddLast(hTOFExpSigmaPi) ;
525
526   //PID 8
527   TH1F* hTOFmatchedExpTimeKa = new TH1F("hTOFmatchedExpTimeKa", "ESDs t_{TOF}-t_{K,exp} (from tracking); t_{TOF}-t_{K,exp} [ps];Counts", nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax) ; 
528   hTOFmatchedExpTimeKa->Sumw2() ;
529   hTOFmatchedExpTimeKa->SetLineWidth(1);
530   hTOFmatchedExpTimeKa->SetLineColor(kBlue);
531   hTOFmatchedExpTimeKa->SetMarkerStyle(21);
532   hTOFmatchedExpTimeKa->SetMarkerSize(0.8); 
533   hTOFmatchedExpTimeKa->SetMarkerColor(kBlue);
534   fHlistPID->AddLast(hTOFmatchedExpTimeKa);
535
536   //PID 9
537   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.,nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax) ; 
538   hTOFmatchedExpTimeKaVsP->Sumw2() ;
539   fHlistPID->AddLast(hTOFmatchedExpTimeKaVsP) ; 
540   
541   //PID 10
542   TH1F* hTOFtheoreticalExpTimeKa = new TH1F("hTOFtheoreticalExpTimeKa", "ESDs t_{TOF}-t_{K,exp} (theoretical); t_{TOF}-t_{K,exp} [ps];Counts", nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax) ; 
543   hTOFtheoreticalExpTimeKa->Sumw2() ;
544   hTOFtheoreticalExpTimeKa->SetLineWidth(1);
545   hTOFtheoreticalExpTimeKa->SetLineColor(kBlue);
546   hTOFtheoreticalExpTimeKa->SetMarkerStyle(24);
547   hTOFtheoreticalExpTimeKa->SetMarkerSize(0.8); 
548   hTOFtheoreticalExpTimeKa->SetMarkerColor(kBlue);
549   fHlistPID->AddLast(hTOFtheoreticalExpTimeKa) ;  
550   
551   //PID 11
552   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., nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax) ; 
553   hTOFtheoreticalExpTimeKaVsP->Sumw2() ;
554   fHlistPID->AddLast(hTOFtheoreticalExpTimeKaVsP) ; 
555   
556   //PID 12
557   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. ) ; 
558   hTOFExpSigmaKa->Sumw2() ;
559   fHlistPID->AddLast(hTOFExpSigmaKa) ;
560   
561   //PID 13
562   TH1F* hTOFmatchedExpTimePro = new TH1F("hTOFmatchedExpTimePro", "ESDs t_{TOF}-t_{p,exp} (from tracking); t_{TOF}-t_{p,exp} [ps];Counts", nExpTimeBins, fExpTimeRangeMin,fExpTimeRangeMax) ; 
563   hTOFmatchedExpTimePro->Sumw2() ;
564   hTOFmatchedExpTimePro->SetLineWidth(1);
565   hTOFmatchedExpTimePro->SetLineColor(kGreen+1);
566   hTOFmatchedExpTimePro->SetMarkerStyle(22);
567   hTOFmatchedExpTimePro->SetMarkerSize(0.8); 
568   hTOFmatchedExpTimePro->SetMarkerColor(kGreen+1);
569   fHlistPID->AddLast(hTOFmatchedExpTimePro) ;
570
571    //PID 14
572   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., nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax) ; 
573   hTOFmatchedExpTimeProVsP->Sumw2() ;
574   fHlistPID->AddLast(hTOFmatchedExpTimeProVsP) ;
575   
576   //PID 15
577   TH1F* hTOFtheoreticalExpTimePro = new TH1F("hTOFtheoreticalExpTimePro", "ESDs t_{TOF}-t_{p,exp} (theoretical); t_{TOF}-t_{p,exp} [ps];Counts", nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax) ; 
578   hTOFtheoreticalExpTimePro->Sumw2() ;
579   hTOFtheoreticalExpTimePro->SetLineWidth(1);
580   hTOFtheoreticalExpTimePro->SetLineColor(kGreen+1);
581   hTOFtheoreticalExpTimePro->SetMarkerStyle(26);
582   hTOFtheoreticalExpTimePro->SetMarkerSize(0.8); 
583   hTOFtheoreticalExpTimePro->SetMarkerColor(kGreen+1);
584   fHlistPID->AddLast(hTOFtheoreticalExpTimePro) ;
585
586   //PID 16
587   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., nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax) ; 
588   hTOFtheoreticalExpTimeProVsP->Sumw2() ;
589   fHlistPID->AddLast(hTOFtheoreticalExpTimeProVsP) ;
590
591   //PID 17
592   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. ) ; 
593   hTOFExpSigmaPro->Sumw2() ;
594   fHlistPID->AddLast(hTOFExpSigmaPro) ;
595
596    //PID 18
597   TH2F* hTOFmatchedExpTimePiVsPTRDPos = new TH2F("hTOFmatchedExpTimePiVsPTRDPos", "ESDs t_{TOF}-t_{p,exp} (from tracking) Vs P (#phi_{outerTPC}#leq 30 || 150 #leq#phi_{outerTPC}#leq 230 || #phi_{outerTPC}#geq 310 ) ; p (GeV/c);t_{TOF}-t_{p,exp} [ps];Counts",500, 0.,5., nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax) ; 
598   hTOFmatchedExpTimePiVsPTRDPos->Sumw2() ;
599   if (fEnableAdvancedCheck)
600     fHlistPID->AddLast(hTOFmatchedExpTimePiVsPTRDPos) ;
601
602    //PID 19
603   TH2F* hTOFmatchedExpTimePiVsPNoTRDPos = new TH2F("hTOFmatchedExpTimePiVsPNoTRDPos", "ESDs t_{TOF}-t_{p,exp} (from tracking) Vs P (50 #leq#phi_{outerTPC}#leq 130 || 250 #leq#phi_{outerTPC}#leq 290); p (GeV/c);t_{TOF}-t_{p,exp} [ps];Counts",500, 0.,5., nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax) ; 
604   hTOFmatchedExpTimePiVsPNoTRDPos->Sumw2() ;
605   if (fEnableAdvancedCheck)
606     fHlistPID->AddLast(hTOFmatchedExpTimePiVsPNoTRDPos) ;
607
608    //PID 20
609   TH2F* hTOFmatchedExpTimePiVsPTRDNeg = new TH2F("hTOFmatchedExpTimePiVsPTRDNeg", "ESDs t_{TOF}-t_{p,exp} (from tracking) Vs P (#phi_{outerTPC}#leq 30 || 150 #leq#phi_{outerTPC}#leq 230 || #phi_{outerTPC}#geq 310 ) ; p (GeV/c);t_{TOF}-t_{p,exp} [ps];Counts",500, 0.,5., nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax) ; 
610   hTOFmatchedExpTimePiVsPTRDNeg->Sumw2() ;
611   if (fEnableAdvancedCheck)
612     fHlistPID->AddLast(hTOFmatchedExpTimePiVsPTRDNeg) ;
613
614    //PID 21
615   TH2F* hTOFmatchedExpTimePiVsPNoTRDNeg = new TH2F("hTOFmatchedExpTimePiVsPNoTRDNeg", "ESDs t_{TOF}-t_{p,exp} (from tracking) Vs P (50 #leq#phi_{outerTPC}#leq 130 || 250 #leq#phi_{outerTPC}#leq 290); p (GeV/c);t_{TOF}-t_{p,exp} [ps];Counts",500, 0.,5.,nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax) ; 
616   hTOFmatchedExpTimePiVsPNoTRDNeg->Sumw2() ;
617   if (fEnableAdvancedCheck)
618     fHlistPID->AddLast(hTOFmatchedExpTimePiVsPNoTRDNeg) ;
619   
620  //PID 22
621   TH2F* hTOFmatchedExpTimeKaVsPTRDPos = new TH2F("hTOFmatchedExpTimeKaVsPTRDPos", "ESDs t_{TOF}-t_{p,exp} (from tracking) Vs P (#phi_{outerTPC}#leq 30 || 150 #leq#phi_{outerTPC}#leq 230 || #phi_{outerTPC}#geq 310 ) ; p (GeV/c);t_{TOF}-t_{p,exp} [ps];Counts",500, 0.,5.,nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax) ; 
622   hTOFmatchedExpTimeKaVsPTRDPos->Sumw2() ;
623   if (fEnableAdvancedCheck)
624     fHlistPID->AddLast(hTOFmatchedExpTimeKaVsPTRDPos) ;
625   
626    //PID 23
627   TH2F* hTOFmatchedExpTimeKaVsPNoTRDPos = new TH2F("hTOFmatchedExpTimeKaVsPNoTRDPos", "ESDs t_{TOF}-t_{p,exp} (from tracking) Vs P (50 #leq#phi_{outerTPC}#leq 130 || 250 #leq#phi_{outerTPC}#leq 290); p (GeV/c);t_{TOF}-t_{p,exp} [ps];Counts",500, 0.,5.,nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax) ; 
628   hTOFmatchedExpTimeKaVsPNoTRDPos->Sumw2() ;
629     if (fEnableAdvancedCheck)
630       fHlistPID->AddLast(hTOFmatchedExpTimeKaVsPNoTRDPos) ;
631
632    //PID 24
633   TH2F* hTOFmatchedExpTimeKaVsPTRDNeg = new TH2F("hTOFmatchedExpTimeKaVsPTRDNeg", "ESDs t_{TOF}-t_{p,exp} (from tracking) Vs P (#phi_{outerTPC}#leq 30 || 150 #leq#phi_{outerTPC}#leq 230 || #phi_{outerTPC}#geq 310 ) ; p (GeV/c);t_{TOF}-t_{p,exp} [ps];Counts",500, 0.,5.,nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax) ; 
634   hTOFmatchedExpTimeKaVsPTRDNeg->Sumw2() ;
635   if (fEnableAdvancedCheck)
636     fHlistPID->AddLast(hTOFmatchedExpTimeKaVsPTRDNeg) ;
637
638    //PID 25
639   TH2F* hTOFmatchedExpTimeKaVsPNoTRDNeg = new TH2F("hTOFmatchedExpTimeKaVsPNoTRDNeg", "ESDs t_{TOF}-t_{p,exp} (from tracking) Vs P (50 #leq#phi_{outerTPC}#leq 130 || 250 #leq#phi_{outerTPC}#leq 290); p (GeV/c);t_{TOF}-t_{p,exp} [ps];Counts",500, 0.,5.,nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax) ; 
640   hTOFmatchedExpTimeKaVsPNoTRDNeg->Sumw2() ;
641   if (fEnableAdvancedCheck)
642     fHlistPID->AddLast(hTOFmatchedExpTimeKaVsPNoTRDNeg) ;
643     
644  //PID 26
645   TH2F* hTOFmatchedExpTimeProVsPTRDPos = new TH2F("hTOFmatchedExpTimeProVsPTRDPos", "ESDs t_{TOF}-t_{p,exp} (from tracking) Vs P (#phi_{outerTPC}#leq 30 || 150 #leq#phi_{outerTPC}#leq 230 || #phi_{outerTPC}#geq 310 ) ; p (GeV/c);t_{TOF}-t_{p,exp} [ps];Counts",500, 0.,5.,nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax) ; 
646   hTOFmatchedExpTimeProVsPTRDPos->Sumw2() ;
647   if (fEnableAdvancedCheck)
648     fHlistPID->AddLast(hTOFmatchedExpTimeProVsPTRDPos) ;
649   
650    //PID 27
651   TH2F* hTOFmatchedExpTimeProVsPNoTRDPos = new TH2F("hTOFmatchedExpTimeProVsPNoTRDPos", "ESDs t_{TOF}-t_{p,exp} (from tracking) Vs P (50 #leq#phi_{outerTPC}#leq 130 || 250 #leq#phi_{outerTPC}#leq 290); p (GeV/c);t_{TOF}-t_{p,exp} [ps];Counts",500, 0.,5.,nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax) ; 
652   hTOFmatchedExpTimeProVsPNoTRDPos->Sumw2() ;
653     if (fEnableAdvancedCheck)
654       fHlistPID->AddLast(hTOFmatchedExpTimeProVsPNoTRDPos) ;
655     
656     //PID 28
657    TH2F* hTOFmatchedExpTimeProVsPTRDNeg = new TH2F("hTOFmatchedExpTimeProVsPTRDNeg", "ESDs t_{TOF}-t_{p,exp} (from tracking) Vs P (#phi_{outerTPC}#leq 30 || 150 #leq#phi_{outerTPC}#leq 230 || #phi_{outerTPC}#geq 310 ) ; p (GeV/c);t_{TOF}-t_{p,exp} [ps];Counts",500, 0.,5.,nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax) ; 
658     hTOFmatchedExpTimeProVsPTRDNeg->Sumw2() ;
659     if (fEnableAdvancedCheck)
660       fHlistPID->AddLast(hTOFmatchedExpTimeProVsPTRDNeg) ;
661
662    //PID 29
663   TH2F* hTOFmatchedExpTimeProVsPNoTRDNeg = new TH2F("hTOFmatchedExpTimeProVsPNoTRDNeg", "ESDs t_{TOF}-t_{p,exp} (from tracking) Vs P (50 #leq#phi_{outerTPC}#leq 130 || 250 #leq#phi_{outerTPC}#leq 290); p (GeV/c);t_{TOF}-t_{p,exp} [ps];Counts",500, 0.,5.,nExpTimeBins, fExpTimeRangeMin, fExpTimeRangeMax) ; 
664   hTOFmatchedExpTimeProVsPNoTRDNeg->Sumw2() ;
665   if (fEnableAdvancedCheck)
666     fHlistPID->AddLast(hTOFmatchedExpTimeProVsPNoTRDNeg) ;
667
668   //----------------------------------------------------------POSITIVE TRACKS
669   //0
670   TH1F* hTOFmatchedESDtrkLengthPos  = new TH1F("hTOFmatchedESDtrkLengthPos", "Matched positive ESDs tracks length; Track length [cm];Counts", 1600, -800., 800) ; 
671   hTOFmatchedESDtrkLengthPos->Sumw2();
672   hTOFmatchedESDtrkLengthPos->SetLineColor(kRed);
673   hTOFmatchedESDtrkLengthPos->SetMarkerColor(kRed);
674   hTOFmatchedESDtrkLengthPos->SetFillColor(kRed);
675   hTOFmatchedESDtrkLengthPos->SetDrawOption("BAR"); 
676   if (fEnableAdvancedCheck)
677     fHpos->AddLast(hTOFmatchedESDtrkLengthPos);
678   //1
679   TH1F* hTOFmatchedESDPPos  = new TH1F("hTOFmatchedESDPPos", "TPC-TOF matched positive tracks momentum distribution (GeV/c); p (GeV/c);tracks", 500,0.,5.) ;  
680   hTOFmatchedESDPPos->Sumw2() ;
681   hTOFmatchedESDPPos->SetLineColor(kRed);
682   hTOFmatchedESDPPos->SetMarkerStyle(20);
683   hTOFmatchedESDPPos->SetMarkerSize(0.7);
684   hTOFmatchedESDPPos->SetMarkerColor(kRed);
685   if (fEnableAdvancedCheck)
686     fHpos->AddLast(hTOFmatchedESDPPos) ; 
687   //2
688   TH1F* hTOFmatchedESDPtPos  = new TH1F("hTOFmatchedESDPtPos", "TPC-TOF positive matched tracks p_{T} distribution (GeV/c); p_{T}(GeV/c);tracks", 500,0.,5.) ;  
689   hTOFmatchedESDPtPos->Sumw2() ;
690   hTOFmatchedESDPtPos->SetLineColor(kRed);
691   hTOFmatchedESDPtPos->SetMarkerStyle(21);
692   hTOFmatchedESDPtPos->SetMarkerSize(0.7);
693   hTOFmatchedESDPtPos->SetMarkerColor(kRed);
694   if (fEnableAdvancedCheck)
695     fHpos->AddLast(hTOFmatchedESDPtPos) ; 
696
697   //3
698   TH1F* hTOFmatchedESDetaPos = new TH1F("hTOFmatchedESDetaPos", "Matched positive ESD tracks #eta (p_{T} #geq 0.5 GeV/c); eta;Counts", 200, -1., 1.) ; 
699   hTOFmatchedESDetaPos->Sumw2();
700   hTOFmatchedESDetaPos->SetLineColor(kRed);
701     if (fEnableAdvancedCheck)
702 fHpos->AddLast(hTOFmatchedESDetaPos) ; 
703   //4
704    TH1F* hTOFmatchedESDphiPos = new TH1F("hTOFmatchedESDphiPos", "Matched Positive ESD tracks #phi; #phi (deg);Counts", 72, 0., 360.) ; 
705   hTOFmatchedESDphiPos->Sumw2();
706   hTOFmatchedESDphiPos->SetLineColor(kRed);
707   if (fEnableAdvancedCheck)
708   fHpos->AddLast(hTOFmatchedESDphiPos) ; 
709
710   //5
711   TH1F* hESDmatchedTrackPtPosTRDout = new TH1F("hESDmatchedTrackPtPosTRDout", "ESDs Pos matched tracks p_{T} with kTRDout distribution (GeV/c); p_{T}(GeV/c);tracks", 500, 0.0, 5.0) ;  
712   hESDmatchedTrackPtPosTRDout->Sumw2();
713   hESDmatchedTrackPtPosTRDout->SetLineWidth(1);
714   hESDmatchedTrackPtPosTRDout->SetMarkerStyle(20);
715   hESDmatchedTrackPtPosTRDout->SetMarkerSize(0.7);
716   hESDmatchedTrackPtPosTRDout->SetLineColor(kRed);
717   hESDmatchedTrackPtPosTRDout->SetMarkerColor(kRed);
718   if (fEnableAdvancedCheck)
719   fHpos->AddLast(hESDmatchedTrackPtPosTRDout);
720
721   //6
722   TH1F* hESDmatchedTrackPtPosNoTRDout = new TH1F("hESDmatchedTrackPtPosNoTRDout", "ESDs Pos matched tracks p_{T} with !kTRDout distribution (GeV/c); p_{T}(GeV/c);tracks", 500, 0.0, 5.0) ;  
723   hESDmatchedTrackPtPosNoTRDout->Sumw2();
724   hESDmatchedTrackPtPosNoTRDout->SetLineWidth(1);
725   hESDmatchedTrackPtPosNoTRDout->SetMarkerStyle(25);
726   hESDmatchedTrackPtPosNoTRDout->SetMarkerSize(0.7);
727   hESDmatchedTrackPtPosNoTRDout->SetLineColor(kRed);
728   hESDmatchedTrackPtPosNoTRDout->SetMarkerColor(kRed);
729   if (fEnableAdvancedCheck)
730   fHpos->AddLast(hESDmatchedTrackPtPosNoTRDout);
731
732   //7
733   TH1F* hESDprimaryTrackPPos = new TH1F("hESDprimaryTrackPPos", "All Pos ESDs tracks p distribution (GeV/c); p(GeV/c);tracks", 500, 0., 5.0) ;  
734   hESDprimaryTrackPPos->Sumw2();
735   hESDprimaryTrackPPos->SetLineWidth(1);
736   hESDprimaryTrackPPos->SetMarkerStyle(24);
737   hESDprimaryTrackPPos->SetMarkerSize(0.7);
738   hESDprimaryTrackPPos->SetMarkerColor(kRed);
739   hESDprimaryTrackPPos->SetLineColor(kRed);
740   if (fEnableAdvancedCheck)
741   fHpos->AddLast(hESDprimaryTrackPPos);
742   //8
743   TH1F* hESDprimaryTrackPtPos = new TH1F("hESDprimaryTrackPtPos", "ESDs Pos primary tracks p_{T} distribution (GeV/c); p_{T}(GeV/c);tracks", 500, 0.0, 5.0) ;  
744   hESDprimaryTrackPtPos->Sumw2();
745   hESDprimaryTrackPtPos->SetLineWidth(1);
746   hESDprimaryTrackPtPos->SetMarkerStyle(25);
747   hESDprimaryTrackPtPos->SetMarkerSize(0.7);
748   hESDprimaryTrackPtPos->SetLineColor(kRed);
749   hESDprimaryTrackPtPos->SetMarkerColor(kRed);
750   if (fEnableAdvancedCheck)
751   fHpos->AddLast(hESDprimaryTrackPtPos);
752   //9
753   TH1F* hTOFprimaryESDetaPos = new TH1F("hTOFprimaryESDetaPos", "Primary ESD Pos tracks #eta (p_{T} #geq 0.5 GeV/c); #eta;Counts", 200, -1., 1.) ; 
754   hTOFprimaryESDetaPos->Sumw2();
755   hTOFprimaryESDetaPos->SetLineColor(kRed);
756   if (fEnableAdvancedCheck)
757   fHpos->AddLast(hTOFprimaryESDetaPos) ; 
758   //10
759   TH1F* hTOFprimaryESDphiPos = new TH1F("hTOFprimaryESDphiPos", "Primary ESD Pos tracks #phi;#phi (deg);Counts", 72, 0., 360.) ; 
760   hTOFprimaryESDphiPos->Sumw2();
761   hTOFprimaryESDphiPos->SetLineColor(kRed);
762   if (fEnableAdvancedCheck)
763   fHpos->AddLast(hTOFprimaryESDphiPos) ; 
764
765   //11
766   TH1F* hESDprimaryTrackPtPosTRDout = new TH1F("hESDprimaryTrackPtPosTRDout", "ESDs Pos primary tracks p_{T} with kTRDout distribution (GeV/c); p_{T}(GeV/c);tracks", 500, 0.0, 5.0) ;  
767   hESDprimaryTrackPtPosTRDout->Sumw2();
768   hESDprimaryTrackPtPosTRDout->SetLineWidth(1);
769   hESDprimaryTrackPtPosTRDout->SetMarkerStyle(20);
770   hESDprimaryTrackPtPosTRDout->SetMarkerSize(0.7);
771   hESDprimaryTrackPtPosTRDout->SetLineColor(kRed);
772   hESDprimaryTrackPtPosTRDout->SetMarkerColor(kRed);
773   if (fEnableAdvancedCheck)
774   fHpos->AddLast(hESDprimaryTrackPtPosTRDout);
775
776   //12
777   TH1F* hESDprimaryTrackPtPosNoTRDout = new TH1F("hESDprimaryTrackPtPosNoTRDout", "ESDs Pos primary tracks p_{T} with !kTRDout distribution (GeV/c); p_{T}(GeV/c);tracks", 500, 0.0, 5.0) ;  
778   hESDprimaryTrackPtPosNoTRDout->Sumw2();
779   hESDprimaryTrackPtPosNoTRDout->SetLineWidth(1);
780   hESDprimaryTrackPtPosNoTRDout->SetMarkerStyle(25);
781   hESDprimaryTrackPtPosNoTRDout->SetMarkerSize(0.7);
782   hESDprimaryTrackPtPosNoTRDout->SetLineColor(kRed);
783   hESDprimaryTrackPtPosNoTRDout->SetMarkerColor(kRed);
784   if (fEnableAdvancedCheck)
785   fHpos->AddLast(hESDprimaryTrackPtPosNoTRDout);
786
787     //13
788   TH1F* hESDprimaryTrackEtaPosTRDout = new TH1F("hESDprimaryTrackEtaPosTRDout", "ESDs Pos primary tracks #eta with kTRDout distribution; #eta;tracks", 200, -1.0, 1.0) ;  
789   hESDprimaryTrackEtaPosTRDout->Sumw2();
790   hESDprimaryTrackEtaPosTRDout->SetLineWidth(1);
791   hESDprimaryTrackEtaPosTRDout->SetMarkerStyle(20);
792   hESDprimaryTrackEtaPosTRDout->SetMarkerSize(0.7);
793   hESDprimaryTrackEtaPosTRDout->SetLineColor(kBlue);
794   hESDprimaryTrackEtaPosTRDout->SetMarkerColor(kBlue);
795   if (fEnableAdvancedCheck)
796   fHpos->AddLast(hESDprimaryTrackEtaPosTRDout);
797
798   //14
799   TH1F* hESDprimaryTrackEtaPosNoTRDout = new TH1F("hESDprimaryTrackEtaPosNoTRDout", "ESDs Pos primary tracks #eta with !kTRDout distribution;#eta;tracks", 200, -1.0, 1.0) ;  
800   hESDprimaryTrackEtaPosNoTRDout->Sumw2();
801   hESDprimaryTrackEtaPosNoTRDout->SetLineWidth(1);
802   hESDprimaryTrackEtaPosNoTRDout->SetMarkerStyle(25);
803   hESDprimaryTrackEtaPosNoTRDout->SetMarkerSize(0.7);
804   hESDprimaryTrackEtaPosNoTRDout->SetLineColor(kBlue);
805   hESDprimaryTrackEtaPosNoTRDout->SetMarkerColor(kBlue);
806   if (fEnableAdvancedCheck)
807   fHpos->AddLast(hESDprimaryTrackEtaPosNoTRDout);
808
809   //15
810   TH1F* hESDprimaryTrackPhiPosTRDout = new TH1F("hESDprimaryTrackPhiPosTRDout", "ESDs Pos primary tracks #phi with kTRDout distribution; #phi(deg);tracks", 72, 0., 360.) ;  
811   hESDprimaryTrackPhiPosTRDout->Sumw2();
812   hESDprimaryTrackPhiPosTRDout->SetLineWidth(1);
813   hESDprimaryTrackPhiPosTRDout->SetMarkerStyle(20);
814   hESDprimaryTrackPhiPosTRDout->SetMarkerSize(0.7);
815   hESDprimaryTrackPhiPosTRDout->SetLineColor(kBlue);
816   hESDprimaryTrackPhiPosTRDout->SetMarkerColor(kBlue);
817   if (fEnableAdvancedCheck)
818   fHpos->AddLast(hESDprimaryTrackPhiPosTRDout);
819
820   //16
821   TH1F* hESDprimaryTrackPhiPosNoTRDout = new TH1F("hESDprimaryTrackPhiPosNoTRDout", "ESDs Pos primary tracks #phi with !kTRDout distribution; #phi(deg);tracks", 72, 0., 360.) ;  
822   hESDprimaryTrackPhiPosNoTRDout->Sumw2();
823   hESDprimaryTrackPhiPosNoTRDout->SetLineWidth(1);
824   hESDprimaryTrackPhiPosNoTRDout->SetMarkerStyle(25);
825   hESDprimaryTrackPhiPosNoTRDout->SetMarkerSize(0.7);
826   hESDprimaryTrackPhiPosNoTRDout->SetLineColor(kBlue);
827   hESDprimaryTrackPhiPosNoTRDout->SetMarkerColor(kBlue);
828   if (fEnableAdvancedCheck)
829   fHpos->AddLast(hESDprimaryTrackPhiPosNoTRDout);
830
831   //POS 17
832   TH2F* hTOFmatchedExpTimeProVsPhiPos = new TH2F("hTOFmatchedExpTimeProVsPhiPos", "ESDs t_{TOF}-t_{p,exp} vs #phi at TOF (r=378.cm) (p_{T}<1GeV/c);#phi (deg); t_{TOF}-t_{p,exp} [ps];Counts",72, 0.,360., 500, -5000., 5000. ) ; 
833   hTOFmatchedExpTimeProVsPhiPos->Sumw2() ;
834   if (fEnableAdvancedCheck)
835   fHpos->AddLast(hTOFmatchedExpTimeProVsPhiPos) ;
836
837   //POS 18
838   TH2F* hTOFmatchedExpTimeProVsPhiVertexPos = new TH2F("hTOFmatchedExpTimeProVsPhiVertexPos", "ESDs t_{TOF}-t_{p,exp} vs #phi at vtx (p_{T}<1GeV/c);#phi (deg); t_{TOF}-t_{p,exp} [ps];Counts",72, 0.,360., nExpTimeSmallBins, fExpTimeSmallRangeMin, fExpTimeSmallRangeMax) ; 
839   hTOFmatchedExpTimeProVsPhiVertexPos->Sumw2() ;
840   if (fEnableAdvancedCheck)
841   fHpos->AddLast(hTOFmatchedExpTimeProVsPhiVertexPos) ;
842
843   //POS 19
844   TH2F* hTOFmatchedExpTimeProVsPhiTPCPos = new TH2F("hTOFmatchedExpTimeProVsPhiTPCPos", "ESDs t_{TOF}-t_{p,exp} vs #phi at outer TPC (p_{T}<1GeV/c);#phi (deg); t_{TOF}-t_{p,exp} [ps];Counts",72, 0.,360., nExpTimeSmallBins, fExpTimeSmallRangeMin, fExpTimeSmallRangeMax) ; 
845   hTOFmatchedExpTimeProVsPhiTPCPos->Sumw2() ;
846   if (fEnableAdvancedCheck)
847   fHpos->AddLast(hTOFmatchedExpTimeProVsPhiTPCPos) ;
848
849    //20
850   TH1F* hESDmatchedTrackEtaPosTRDout = new TH1F("hESDmatchedTrackEtaPosTRDout", "ESDs Pos matched tracks #eta with kTRDout distribution; #eta;tracks", 200, -1.0, 1.0) ;  
851   hESDmatchedTrackEtaPosTRDout->Sumw2();
852   hESDmatchedTrackEtaPosTRDout->SetLineWidth(1);
853   hESDmatchedTrackEtaPosTRDout->SetMarkerStyle(20);
854   hESDmatchedTrackEtaPosTRDout->SetMarkerSize(0.7);
855   hESDmatchedTrackEtaPosTRDout->SetLineColor(kBlue);
856   hESDmatchedTrackEtaPosTRDout->SetMarkerColor(kBlue);
857   if (fEnableAdvancedCheck)
858   fHpos->AddLast(hESDmatchedTrackEtaPosTRDout);
859
860   //21
861   TH1F* hESDmatchedTrackEtaPosNoTRDout = new TH1F("hESDmatchedTrackEtaPosNoTRDout", "ESDs Pos matched tracks #eta with !kTRDout distribution;#eta;tracks", 200, -1.0, 1.0) ;  
862   hESDmatchedTrackEtaPosNoTRDout->Sumw2();
863   hESDmatchedTrackEtaPosNoTRDout->SetLineWidth(1);
864   hESDmatchedTrackEtaPosNoTRDout->SetMarkerStyle(25);
865   hESDmatchedTrackEtaPosNoTRDout->SetMarkerSize(0.7);
866   hESDmatchedTrackEtaPosNoTRDout->SetLineColor(kBlue);
867   hESDmatchedTrackEtaPosNoTRDout->SetMarkerColor(kBlue);
868   if (fEnableAdvancedCheck)
869   fHpos->AddLast(hESDmatchedTrackEtaPosNoTRDout);
870
871   //22
872   TH1F* hESDmatchedTrackPhiPosTRDout = new TH1F("hESDmatchedTrackPhiPosTRDout", "ESDs Pos matched tracks #phi with kTRDout distribution; #phi(deg);tracks", 72, 0., 360.) ;  
873   hESDmatchedTrackPhiPosTRDout->Sumw2();
874   hESDmatchedTrackPhiPosTRDout->SetLineWidth(1);
875   hESDmatchedTrackPhiPosTRDout->SetMarkerStyle(20);
876   hESDmatchedTrackPhiPosTRDout->SetMarkerSize(0.7);
877   hESDmatchedTrackPhiPosTRDout->SetLineColor(kBlue);
878   hESDmatchedTrackPhiPosTRDout->SetMarkerColor(kBlue);
879   if (fEnableAdvancedCheck)
880   fHpos->AddLast(hESDmatchedTrackPhiPosTRDout);
881
882   //23
883   TH1F* hESDmatchedTrackPhiPosNoTRDout = new TH1F("hESDmatchedTrackPhiPosNoTRDout", "ESDs Pos matched tracks #phi with !kTRDout distribution; #phi(deg);tracks", 72, 0., 360.) ;  
884   hESDmatchedTrackPhiPosNoTRDout->Sumw2();
885   hESDmatchedTrackPhiPosNoTRDout->SetLineWidth(1);
886   hESDmatchedTrackPhiPosNoTRDout->SetMarkerStyle(25);
887   hESDmatchedTrackPhiPosNoTRDout->SetMarkerSize(0.7);
888   hESDmatchedTrackPhiPosNoTRDout->SetLineColor(kBlue);
889   hESDmatchedTrackPhiPosNoTRDout->SetMarkerColor(kBlue);
890   if (fEnableAdvancedCheck)
891   fHpos->AddLast(hESDmatchedTrackPhiPosNoTRDout);
892
893   //POS 24
894   TH2F* hTOFmatchedExpTimePiVsPhiTPCPos = new TH2F("hTOFmatchedExpTimePiVsPhiTPCPos", "ESDs t_{TOF}-t_{#pi,exp} vs #phi at outer TPC (p_{T}<1GeV/c);#phi (deg); t_{TOF}-t_{p,exp} [ps];Counts",72, 0.,360., nExpTimeSmallBins, fExpTimeSmallRangeMin, fExpTimeSmallRangeMax) ; 
895   hTOFmatchedExpTimePiVsPhiTPCPos->Sumw2() ;
896   if (fEnableAdvancedCheck)
897   fHpos->AddLast(hTOFmatchedExpTimePiVsPhiTPCPos) ;
898
899   //POS 25
900   TH2F* hTOFmatchedExpTimeKaVsPhiTPCPos = new TH2F("hTOFmatchedExpTimeKaVsPhiTPCPos", "ESDs t_{TOF}-t_{K,exp} vs #phi at outer TPC (p_{T}<1GeV/c);#phi (deg); t_{TOF}-t_{p,exp} [ps];Counts",72, 0.,360., nExpTimeSmallBins, fExpTimeSmallRangeMin, fExpTimeSmallRangeMax) ; 
901   hTOFmatchedExpTimeKaVsPhiTPCPos->Sumw2() ;
902   if (fEnableAdvancedCheck)
903   fHpos->AddLast(hTOFmatchedExpTimeKaVsPhiTPCPos) ;
904
905 //----------------------------------------------------------NEGATIVE TRACKS
906   //0
907   TH1F* hTOFmatchedESDtrkLengthNeg  = new TH1F("hTOFmatchedESDtrkLengthNeg", "Matched positive ESDs tracks length; Track length [cm];Counts", 1600, -800., 800) ; 
908   hTOFmatchedESDtrkLengthNeg->Sumw2();
909   hTOFmatchedESDtrkLengthNeg->SetLineColor(kBlue);
910   hTOFmatchedESDtrkLengthNeg->SetMarkerColor(kBlue);
911   hTOFmatchedESDtrkLengthNeg->SetFillColor(kBlue);
912   hTOFmatchedESDtrkLengthNeg->SetDrawOption("BAR"); 
913   if (fEnableAdvancedCheck)
914   fHneg->AddLast(hTOFmatchedESDtrkLengthNeg);
915   //1
916   TH1F* hTOFmatchedESDPNeg  = new TH1F("hTOFmatchedESDPNeg", "TPC-TOF matched positive tracks momentum distribution (GeV/c); p (GeV/c);tracks", 500,0.,5.) ;  
917   hTOFmatchedESDPNeg->Sumw2() ;
918   hTOFmatchedESDPNeg->SetLineColor(kBlue);
919   hTOFmatchedESDPNeg->SetMarkerStyle(20);
920   hTOFmatchedESDPNeg->SetMarkerSize(0.7);
921   hTOFmatchedESDPNeg->SetMarkerColor(kBlue);
922   if (fEnableAdvancedCheck)
923   fHneg->AddLast(hTOFmatchedESDPNeg) ; 
924   //2
925   TH1F* hTOFmatchedESDPtNeg  = new TH1F("hTOFmatchedESDPtNeg", "TPC-TOF positive matched tracks p_{T} distribution (GeV/c); p_{T}(GeV/c);tracks", 500,0.,5.) ;  
926   hTOFmatchedESDPtNeg->Sumw2() ;
927   hTOFmatchedESDPtNeg->SetLineColor(kBlue);
928   hTOFmatchedESDPtNeg->SetMarkerStyle(21);
929   hTOFmatchedESDPtNeg->SetMarkerSize(0.7);
930   hTOFmatchedESDPtNeg->SetMarkerColor(kBlue);
931   if (fEnableAdvancedCheck)
932   fHneg->AddLast(hTOFmatchedESDPtNeg) ; 
933
934   //3
935   TH1F* hTOFmatchedESDetaNeg = new TH1F("hTOFmatchedESDetaNeg", "Matched positive ESD tracks #eta (p_{T} #geq 0.5 GeV/c); eta;Counts", 200, -1., 1.) ; 
936   hTOFmatchedESDetaNeg->Sumw2();
937   hTOFmatchedESDetaNeg->SetLineColor(kBlue);
938   if (fEnableAdvancedCheck)
939   fHneg->AddLast(hTOFmatchedESDetaNeg) ; 
940   //4
941    TH1F* hTOFmatchedESDphiNeg = new TH1F("hTOFmatchedESDphiNeg", "Matched Negitive ESD tracks #phi; #phi (deg);Counts", 72, 0., 360.) ; 
942   hTOFmatchedESDphiNeg->Sumw2();
943   hTOFmatchedESDphiNeg->SetLineColor(kBlue);
944   if (fEnableAdvancedCheck)
945   fHneg->AddLast(hTOFmatchedESDphiNeg) ; 
946
947   //5
948   TH1F* hESDmatchedTrackPtNegTRDout = new TH1F("hESDmatchedTrackPtNegTRDout", "ESDs Neg matched tracks p_{T} with kTRDout distribution (GeV/c); p_{T}(GeV/c);tracks", 500, 0.0, 5.0) ;  
949   hESDmatchedTrackPtNegTRDout->Sumw2();
950   hESDmatchedTrackPtNegTRDout->SetLineWidth(1);
951   hESDmatchedTrackPtNegTRDout->SetMarkerStyle(20);
952   hESDmatchedTrackPtNegTRDout->SetMarkerSize(0.7);
953   hESDmatchedTrackPtNegTRDout->SetLineColor(kBlue);
954   hESDmatchedTrackPtNegTRDout->SetMarkerColor(kBlue);
955   if (fEnableAdvancedCheck)
956   fHneg->AddLast(hESDmatchedTrackPtNegTRDout);
957
958   //6
959   TH1F* hESDmatchedTrackPtNegNoTRDout = new TH1F("hESDmatchedTrackPtNegNoTRDout", "ESDs Neg matched tracks p_{T} with !kTRDout distribution (GeV/c); p_{T}(GeV/c);tracks", 500, 0.0, 5.0) ;  
960   hESDmatchedTrackPtNegNoTRDout->Sumw2();
961   hESDmatchedTrackPtNegNoTRDout->SetLineWidth(1);
962   hESDmatchedTrackPtNegNoTRDout->SetMarkerStyle(25);
963   hESDmatchedTrackPtNegNoTRDout->SetMarkerSize(0.7);
964   hESDmatchedTrackPtNegNoTRDout->SetLineColor(kBlue);
965   hESDmatchedTrackPtNegNoTRDout->SetMarkerColor(kBlue);
966   if (fEnableAdvancedCheck)
967   fHneg->AddLast(hESDmatchedTrackPtNegNoTRDout);
968
969   //7
970   TH1F* hESDprimaryTrackPNeg = new TH1F("hESDprimaryTrackPNeg", "All Neg ESDs tracks p distribution (GeV/c); p(GeV/c);tracks", 500, 0., 5.0) ;  
971   hESDprimaryTrackPNeg->Sumw2();
972   hESDprimaryTrackPNeg->SetLineWidth(1);
973   hESDprimaryTrackPNeg->SetMarkerStyle(24);
974   hESDprimaryTrackPNeg->SetMarkerSize(0.7);
975   hESDprimaryTrackPNeg->SetMarkerColor(kBlue);
976   hESDprimaryTrackPNeg->SetLineColor(kBlue);
977   if (fEnableAdvancedCheck)
978   fHneg->AddLast(hESDprimaryTrackPNeg);
979   //8
980   TH1F* hESDprimaryTrackPtNeg = new TH1F("hESDprimaryTrackPtNeg", "ESDs Neg primary tracks p_{T} distribution (GeV/c); p_{T}(GeV/c);tracks", 500, 0.0, 5.0) ;  
981   hESDprimaryTrackPtNeg->Sumw2();
982   hESDprimaryTrackPtNeg->SetLineWidth(1);
983   hESDprimaryTrackPtNeg->SetMarkerStyle(25);
984   hESDprimaryTrackPtNeg->SetMarkerSize(0.7);
985   hESDprimaryTrackPtNeg->SetLineColor(kBlue);
986   hESDprimaryTrackPtNeg->SetMarkerColor(kBlue);
987   if (fEnableAdvancedCheck)
988   fHneg->AddLast(hESDprimaryTrackPtNeg);
989   //9
990   TH1F* hTOFprimaryESDetaNeg = new TH1F("hTOFprimaryESDetaNeg", "Primary ESD Neg tracks #eta (p_{T} #geq 0.5 GeV/c); #eta;Counts", 200, -1., 1.) ; 
991   hTOFprimaryESDetaNeg->Sumw2();
992   hTOFprimaryESDetaNeg->SetLineColor(kBlue);
993   if (fEnableAdvancedCheck)
994   fHneg->AddLast(hTOFprimaryESDetaNeg) ; 
995   //10
996   TH1F* hTOFprimaryESDphiNeg = new TH1F("hTOFprimaryESDphiNeg", "Primary ESD Neg tracks #phi;#phi (deg);Counts", 72, 0., 360.) ; 
997   hTOFprimaryESDphiNeg->Sumw2();
998   hTOFprimaryESDphiNeg->SetLineColor(kBlue);
999   if (fEnableAdvancedCheck)
1000   fHneg->AddLast(hTOFprimaryESDphiNeg) ; 
1001
1002  //11
1003   TH1F* hESDprimaryTrackPtNegTRDout = new TH1F("hESDprimaryTrackPtNegTRDout", "ESDs Neg primary tracks p_{T} with kTRDout distribution (GeV/c); p_{T}(GeV/c);tracks", 500, 0.0, 5.0) ;  
1004   hESDprimaryTrackPtNegTRDout->Sumw2();
1005   hESDprimaryTrackPtNegTRDout->SetLineWidth(1);
1006   hESDprimaryTrackPtNegTRDout->SetMarkerStyle(20);
1007   hESDprimaryTrackPtNegTRDout->SetMarkerSize(0.7);
1008   hESDprimaryTrackPtNegTRDout->SetLineColor(kBlue);
1009   hESDprimaryTrackPtNegTRDout->SetMarkerColor(kBlue);
1010   if (fEnableAdvancedCheck)
1011   fHneg->AddLast(hESDprimaryTrackPtNegTRDout);
1012
1013   //12
1014   TH1F* hESDprimaryTrackPtNegNoTRDout = new TH1F("hESDprimaryTrackPtNegNoTRDout", "ESDs Neg primary tracks p_{T} with !kTRDout distribution (GeV/c); p_{T}(GeV/c);tracks", 500, 0.0, 5.0) ;  
1015   hESDprimaryTrackPtNegNoTRDout->Sumw2();
1016   hESDprimaryTrackPtNegNoTRDout->SetLineWidth(1);
1017   hESDprimaryTrackPtNegNoTRDout->SetMarkerStyle(25);
1018   hESDprimaryTrackPtNegNoTRDout->SetMarkerSize(0.7);
1019   hESDprimaryTrackPtNegNoTRDout->SetLineColor(kBlue);
1020   hESDprimaryTrackPtNegNoTRDout->SetMarkerColor(kBlue);
1021   if (fEnableAdvancedCheck)
1022   fHneg->AddLast(hESDprimaryTrackPtNegNoTRDout);
1023
1024   //13
1025   TH1F* hESDprimaryTrackEtaNegTRDout = new TH1F("hESDprimaryTrackEtaNegTRDout", "ESDs Neg primary tracks #eta with kTRDout distribution; #eta;tracks", 200, -1.0, 1.0) ;  
1026   hESDprimaryTrackEtaNegTRDout->Sumw2();
1027   hESDprimaryTrackEtaNegTRDout->SetLineWidth(1);
1028   hESDprimaryTrackEtaNegTRDout->SetMarkerStyle(20);
1029   hESDprimaryTrackEtaNegTRDout->SetMarkerSize(0.7);
1030   hESDprimaryTrackEtaNegTRDout->SetLineColor(kBlue);
1031   hESDprimaryTrackEtaNegTRDout->SetMarkerColor(kBlue);
1032   if (fEnableAdvancedCheck)
1033   fHneg->AddLast(hESDprimaryTrackEtaNegTRDout);
1034
1035   //14
1036   TH1F* hESDprimaryTrackEtaNegNoTRDout = new TH1F("hESDprimaryTrackEtaNegNoTRDout", "ESDs Neg primary tracks #eta with !kTRDout distribution;#eta;tracks", 200, -1.0, 1.0) ;  
1037   hESDprimaryTrackEtaNegNoTRDout->Sumw2();
1038   hESDprimaryTrackEtaNegNoTRDout->SetLineWidth(1);
1039   hESDprimaryTrackEtaNegNoTRDout->SetMarkerStyle(25);
1040   hESDprimaryTrackEtaNegNoTRDout->SetMarkerSize(0.7);
1041   hESDprimaryTrackEtaNegNoTRDout->SetLineColor(kBlue);
1042   hESDprimaryTrackEtaNegNoTRDout->SetMarkerColor(kBlue);
1043   if (fEnableAdvancedCheck)
1044   fHneg->AddLast(hESDprimaryTrackEtaNegNoTRDout);
1045
1046   //15
1047   TH1F* hESDprimaryTrackPhiNegTRDout = new TH1F("hESDprimaryTrackPhiNegTRDout", "ESDs Neg primary tracks #phi with kTRDout distribution; #phi(deg);tracks", 72, 0., 360.) ;  
1048   hESDprimaryTrackPhiNegTRDout->Sumw2();
1049   hESDprimaryTrackPhiNegTRDout->SetLineWidth(1);
1050   hESDprimaryTrackPhiNegTRDout->SetMarkerStyle(20);
1051   hESDprimaryTrackPhiNegTRDout->SetMarkerSize(0.7);
1052   hESDprimaryTrackPhiNegTRDout->SetLineColor(kBlue);
1053   hESDprimaryTrackPhiNegTRDout->SetMarkerColor(kBlue);
1054   if (fEnableAdvancedCheck)
1055   fHneg->AddLast(hESDprimaryTrackPhiNegTRDout);
1056
1057   //16
1058   TH1F* hESDprimaryTrackPhiNegNoTRDout = new TH1F("hESDprimaryTrackPhiNegNoTRDout", "ESDs Neg primary tracks #phi with !kTRDout distribution; #phi(deg);tracks", 72, 0., 360.) ;  
1059   hESDprimaryTrackPhiNegNoTRDout->Sumw2();
1060   hESDprimaryTrackPhiNegNoTRDout->SetLineWidth(1);
1061   hESDprimaryTrackPhiNegNoTRDout->SetMarkerStyle(25);
1062   hESDprimaryTrackPhiNegNoTRDout->SetMarkerSize(0.7);
1063   hESDprimaryTrackPhiNegNoTRDout->SetLineColor(kBlue);
1064   hESDprimaryTrackPhiNegNoTRDout->SetMarkerColor(kBlue);
1065   if (fEnableAdvancedCheck)
1066   fHneg->AddLast(hESDprimaryTrackPhiNegNoTRDout);
1067
1068   //NEG 17
1069   TH2F* hTOFmatchedExpTimeProVsPhiNeg = new TH2F("hTOFmatchedExpTimeProVsPhiNeg", "ESDs t_{TOF}-t_{p,exp} vs #phi at TOF (r=378.cm) (p_{T}<1GeV/c);#phi (deg); t_{TOF}-t_{p,exp} [ps];Counts",72, 0.,360., nExpTimeSmallBins, fExpTimeSmallRangeMin, fExpTimeSmallRangeMax) ; 
1070   hTOFmatchedExpTimeProVsPhiNeg->Sumw2() ;
1071   if (fEnableAdvancedCheck)
1072   fHneg->AddLast(hTOFmatchedExpTimeProVsPhiNeg) ;
1073
1074   //NEG 18
1075   TH2F* hTOFmatchedExpTimeProVsPhiVertexNeg = new TH2F("hTOFmatchedExpTimeProVsPhiVertexNeg", "ESDs t_{TOF}-t_{p,exp} vs #phi at vtx (p_{T}<1GeV/c);#phi (deg); t_{TOF}-t_{p,exp} [ps];Counts",72, 0.,360., nExpTimeSmallBins, fExpTimeSmallRangeMin, fExpTimeSmallRangeMax) ; 
1076   hTOFmatchedExpTimeProVsPhiVertexNeg->Sumw2() ;
1077   if (fEnableAdvancedCheck)
1078   fHneg->AddLast(hTOFmatchedExpTimeProVsPhiVertexNeg) ;
1079
1080   //NEG 19
1081   TH2F* hTOFmatchedExpTimeProVsPhiTPCNeg = new TH2F("hTOFmatchedExpTimeProVsPhiTPCNeg", "ESDs t_{TOF}-t_{p,exp} vs #phi at outer TPC (p_{T}<1GeV/c);#phi (deg); t_{TOF}-t_{p,exp} [ps];Counts",72, 0.,360., nExpTimeSmallBins, fExpTimeSmallRangeMin, fExpTimeSmallRangeMax) ; 
1082   hTOFmatchedExpTimeProVsPhiTPCNeg->Sumw2() ;
1083   if (fEnableAdvancedCheck)
1084   fHneg->AddLast(hTOFmatchedExpTimeProVsPhiTPCNeg) ;
1085
1086
1087   //20
1088   TH1F* hESDmatchedTrackEtaNegTRDout = new TH1F("hESDmatchedTrackEtaNegTRDout", "ESDs Neg matched tracks #eta with kTRDout distribution; #eta;tracks", 200, -1.0, 1.0) ;  
1089   hESDmatchedTrackEtaNegTRDout->Sumw2();
1090   hESDmatchedTrackEtaNegTRDout->SetLineWidth(1);
1091   hESDmatchedTrackEtaNegTRDout->SetMarkerStyle(20);
1092   hESDmatchedTrackEtaNegTRDout->SetMarkerSize(0.7);
1093   hESDmatchedTrackEtaNegTRDout->SetLineColor(kBlue);
1094   hESDmatchedTrackEtaNegTRDout->SetMarkerColor(kBlue);
1095   if (fEnableAdvancedCheck)
1096   fHneg->AddLast(hESDmatchedTrackEtaNegTRDout);
1097
1098   //21
1099   TH1F* hESDmatchedTrackEtaNegNoTRDout = new TH1F("hESDmatchedTrackEtaNegNoTRDout", "ESDs Neg matched tracks #eta with !kTRDout distribution;#eta;tracks", 200, -1.0, 1.0) ;  
1100   hESDmatchedTrackEtaNegNoTRDout->Sumw2();
1101   hESDmatchedTrackEtaNegNoTRDout->SetLineWidth(1);
1102   hESDmatchedTrackEtaNegNoTRDout->SetMarkerStyle(25);
1103   hESDmatchedTrackEtaNegNoTRDout->SetMarkerSize(0.7);
1104   hESDmatchedTrackEtaNegNoTRDout->SetLineColor(kBlue);
1105   hESDmatchedTrackEtaNegNoTRDout->SetMarkerColor(kBlue);
1106   if (fEnableAdvancedCheck)
1107   fHneg->AddLast(hESDmatchedTrackEtaNegNoTRDout);
1108
1109   //22
1110   TH1F* hESDmatchedTrackPhiNegTRDout = new TH1F("hESDmatchedTrackPhiNegTRDout", "ESDs Neg matched tracks #phi with kTRDout distribution; #phi(deg);tracks", 72, 0., 360.) ;  
1111   hESDmatchedTrackPhiNegTRDout->Sumw2();
1112   hESDmatchedTrackPhiNegTRDout->SetLineWidth(1);
1113   hESDmatchedTrackPhiNegTRDout->SetMarkerStyle(20);
1114   hESDmatchedTrackPhiNegTRDout->SetMarkerSize(0.7);
1115   hESDmatchedTrackPhiNegTRDout->SetLineColor(kBlue);
1116   hESDmatchedTrackPhiNegTRDout->SetMarkerColor(kBlue);
1117   if (fEnableAdvancedCheck)
1118   fHneg->AddLast(hESDmatchedTrackPhiNegTRDout);
1119
1120   //23
1121   TH1F* hESDmatchedTrackPhiNegNoTRDout = new TH1F("hESDmatchedTrackPhiNegNoTRDout", "ESDs Neg matched tracks #phi with !kTRDout distribution; #phi(deg);tracks", 72, 0., 360.) ;  
1122   hESDmatchedTrackPhiNegNoTRDout->Sumw2();
1123   hESDmatchedTrackPhiNegNoTRDout->SetLineWidth(1);
1124   hESDmatchedTrackPhiNegNoTRDout->SetMarkerStyle(25);
1125   hESDmatchedTrackPhiNegNoTRDout->SetMarkerSize(0.7);
1126   hESDmatchedTrackPhiNegNoTRDout->SetLineColor(kBlue);
1127   hESDmatchedTrackPhiNegNoTRDout->SetMarkerColor(kBlue);
1128   if (fEnableAdvancedCheck)
1129   fHneg->AddLast(hESDmatchedTrackPhiNegNoTRDout);
1130  
1131  //NEG 24
1132   TH2F* hTOFmatchedExpTimePiVsPhiTPCNeg = new TH2F("hTOFmatchedExpTimePiVsPhiTPCNeg", "ESDs t_{TOF}-t_{#pi,exp} vs #phi at outer TPC (p_{T}<1GeV/c);#phi (deg); t_{TOF}-t_{p,exp} [ps];Counts",72, 0.,360., nExpTimeSmallBins, fExpTimeSmallRangeMin, fExpTimeSmallRangeMax) ; 
1133   hTOFmatchedExpTimePiVsPhiTPCNeg->Sumw2() ;
1134   if (fEnableAdvancedCheck)
1135   fHneg->AddLast(hTOFmatchedExpTimePiVsPhiTPCNeg) ;
1136
1137   //NEG 25
1138   TH2F* hTOFmatchedExpTimeKaVsPhiTPCNeg = new TH2F("hTOFmatchedExpTimeKaVsPhiTPCNeg", "ESDs t_{TOF}-t_{K,exp} vs #phi at outer TPC (p_{T}<1GeV/c);#phi (deg); t_{TOF}-t_{p,exp} [ps];Counts",72, 0.,360., nExpTimeSmallBins, fExpTimeSmallRangeMin, fExpTimeSmallRangeMax) ; 
1139   hTOFmatchedExpTimeKaVsPhiTPCNeg->Sumw2() ;
1140   if (fEnableAdvancedCheck)
1141   fHneg->AddLast(hTOFmatchedExpTimeKaVsPhiTPCNeg) ;
1142
1143   PostData(1, fHlist);
1144   PostData(2, fHlistTimeZero);
1145   PostData(3, fHlistPID);
1146   PostData(4, fHpos);
1147   PostData(5, fHneg);
1148 }
1149 //________________________________________________________________________
1150 void AliAnalysisTaskTOFqa::UserExec(Option_t *) 
1151
1152   /* Main - executed for each event.
1153     It extracts event information and track information after selecting 
1154     primary tracks via standard cuts. */
1155   
1156   AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
1157   if (!esdH) {
1158     Printf("ERROR: Could not get ESDInputHandler");
1159     return;
1160   } else {
1161     fESD = (AliESDEvent*) esdH->GetEvent();
1162   } 
1163   
1164   if (!fESD) {
1165     Printf("ERROR: fESD not available");
1166     return;
1167   }
1168
1169   // info from V0 detector QA 
1170   AliESDVZERO * vzero = fESD->GetVZEROData();
1171   Float_t V0Atime = vzero->GetV0ATime();
1172   Float_t V0Ctime = vzero->GetV0CTime(); 
1173   ((TH2F*)fHlistTimeZero->FindObject("hEventV0MeanVsVtx"))->Fill((V0Atime-V0Ctime)*0.5,(V0Atime+V0Ctime)*0.5);
1174
1175   
1176   // info from T0 detector QA 
1177   for (Int_t j=0;j<3;j++){
1178     fT0[j]= (Float_t) fESD->GetT0TOF(j);//ps
1179     if (fT0[j]>90000.) fT0[j]=99999.;//fix old default values to the new one
1180   }
1181   Float_t t0cut = 90000.; 
1182   //Float_t t0cut =3 * t0spread; //use this cut to check t0 used in tof response
1183   // if(t0cut < 500) t0cut = 500;
1184   
1185   if(TMath::Abs(fT0[1]) < t0cut && TMath::Abs(fT0[2]) < t0cut ) {
1186     //&& TMath::Abs(fT0[2]-fT0[1]) < 500)  //add this condition to check t0 used in tof response
1187     ((TH1F*)fHlistTimeZero->FindObject("hT0DetRes"))->Fill((fT0[2]-fT0[1])*0.5);
1188     ((TH1F*)fHlistTimeZero->FindObject("hEventT0DetAND"))->Fill(fT0[0]);  
1189     ((TH2F*)fHlistTimeZero->FindObject("hEventT0MeanVsVtx"))->Fill((fT0[2]-fT0[1])*0.5,(fT0[2]+fT0[1])*0.5);
1190   } 
1191   if(TMath::Abs(fT0[1]) < t0cut){
1192     ((TH1F*)fHlistTimeZero->FindObject("hEventT0DetA"))->Fill(fT0[1]);   
1193   }
1194   if(TMath::Abs(fT0[2]) < t0cut){
1195           ((TH1F*)fHlistTimeZero->FindObject("hEventT0DetC"))->Fill(fT0[2]);
1196   }
1197   
1198   //  event timeZero QA via AliESDpid::SetTOFResponse() 
1199   Double_t timeZero[4]={99999.,99999.,99999.,99999.};
1200   Double_t timeZeroRes[4]={99999.,99999.,99999.,99999.}; 
1201   
1202   TString timeZeroHisto[4]={"hT0fill","hT0TOF","hT0T0","hT0best"};
1203   TString timeZeroHistoRes[4]={"hT0fillRes","hT0TOFRes","hT0T0Res","hT0bestRes"};
1204   for (Int_t j=0;j<4;j++){
1205     fESDpid->SetTOFResponse(fESD, (AliESDpid::EStartTimeType_t) j);//(fill_t0, tof_t0, t0_t0, best_t0)
1206     timeZero[j]=fESDpid->GetTOFResponse().GetStartTime(10.); //timeZero for bin pT>10GeV/c
1207     timeZeroRes[j]=fESDpid->GetTOFResponse().GetStartTimeRes(10.); //timeZero for bin pT>10GeV/c
1208     ((TH1D*)(fHlistTimeZero->FindObject(timeZeroHisto[j].Data())))->Fill(timeZero[j]);
1209     ((TH1D*)(fHlistTimeZero->FindObject(timeZeroHistoRes[j].Data())))->Fill(timeZeroRes[j]);
1210   }
1211
1212   //re-set response tof_t0 for all other checks
1213   fESDpid->SetTOFResponse(fESD,AliESDpid::kTOF_T0);//(fill_t0, tof_t0, t0_t0, best_t0)
1214   
1215   // loop over ESD tracks 
1216   fNTOFtracks=0;
1217   // fNPrimaryTracks=0;
1218
1219   for (Int_t iTracks = 0; iTracks < fESD->GetNumberOfTracks(); iTracks++) {
1220     AliESDtrack* track = fESD->GetTrack(iTracks);
1221     if (!track) {
1222       Printf("ERROR: Could not receive track %d", iTracks);
1223       continue;
1224     }
1225
1226     //primary tracks selection: kTPCrefit and std cuts
1227     if (fTrackFilter){
1228             if(!fTrackFilter->IsSelected(track)) continue;
1229     }
1230     else{
1231             Printf("No track filter found, skipping the track loop");
1232             break;
1233     }
1234
1235     Double_t eta=track->Eta();
1236     if (TMath::Abs(eta)>0.8) continue; //cut for acceptance
1237
1238     Double_t mom=track->P();
1239     Double_t mom2 = mom*mom;
1240     Double_t length=track->GetIntegratedLength();
1241     Double_t pT = track->Pt();
1242     Double_t phi=track->Phi()*TMath::RadToDeg();
1243     track->GetIntegratedTimes(fTrkExpTimes);
1244       
1245     ((TH1F*)fHlist->FindObject("hESDprimaryTrackP"))->Fill(mom); 
1246     ((TH1F*)fHlist->FindObject("hESDprimaryTrackPt"))->Fill(pT); 
1247     if (pT>=0.5)
1248       ((TH1F*)fHlist->FindObject("hTOFprimaryESDeta"))->Fill(eta);
1249     ((TH1F*)fHlist->FindObject("hTOFprimaryESDphi"))->Fill(phi);
1250     
1251      //evaluate sign  
1252      if (fEnableAdvancedCheck){
1253        if (track->GetSign()>0){
1254         ((TH1F*)fHpos->FindObject("hESDprimaryTrackPPos"))->Fill(mom); 
1255         ((TH1F*)fHpos->FindObject("hESDprimaryTrackPtPos"))->Fill(pT);  
1256         if (pT>=0.5){
1257           ((TH1F*)fHpos->FindObject("hTOFprimaryESDetaPos"))->Fill(eta);
1258           ((TH1F*)fHpos->FindObject("hTOFprimaryESDphiPos"))->Fill(phi);
1259         }
1260         if ( (track->IsOn(AliESDtrack::kTRDout)) && (track->IsOn(AliESDtrack::kTPCout)) ) {
1261           ((TH1F*)fHpos->FindObject("hESDprimaryTrackPtPosTRDout"))->Fill(pT);
1262           if (pT>=0.5) {
1263             ((TH1F*)fHpos->FindObject("hESDprimaryTrackEtaPosTRDout"))->Fill(eta);
1264             ((TH1F*)fHpos->FindObject("hESDprimaryTrackPhiPosTRDout"))->Fill(phi);
1265           }
1266         }
1267         if ((!(track->IsOn(AliESDtrack::kTRDout)))  && (track->IsOn(AliESDtrack::kTPCout)) ) {
1268           ((TH1F*)fHpos->FindObject("hESDprimaryTrackPtPosNoTRDout"))->Fill(pT);
1269           if (pT>=0.5) {
1270             ((TH1F*)fHpos->FindObject("hESDprimaryTrackEtaPosNoTRDout"))->Fill(eta);
1271           ((TH1F*)fHpos->FindObject("hESDprimaryTrackPhiPosNoTRDout"))->Fill(phi);
1272           }
1273         }
1274        } //end positive 
1275        else {
1276                ((TH1F*)fHneg->FindObject("hESDprimaryTrackPNeg"))->Fill(mom); 
1277         ((TH1F*)fHneg->FindObject("hESDprimaryTrackPtNeg"))->Fill(pT); 
1278         if (pT>=0.5){
1279           ((TH1F*)fHneg->FindObject("hTOFprimaryESDetaNeg"))->Fill(eta);
1280           ((TH1F*)fHneg->FindObject("hTOFprimaryESDphiNeg"))->Fill(phi);                
1281         }
1282         if ((track->IsOn(AliESDtrack::kTRDout))  && (track->IsOn(AliESDtrack::kTPCout)) ) {
1283           ((TH1F*)fHneg->FindObject("hESDprimaryTrackPtNegTRDout"))->Fill(pT);
1284           if (pT>0.5) {
1285             ((TH1F*)fHneg->FindObject("hESDprimaryTrackEtaNegTRDout"))->Fill(eta);
1286             ((TH1F*)fHneg->FindObject("hESDprimaryTrackPhiNegTRDout"))->Fill(phi); 
1287           }
1288         }
1289         if  ((!(track->IsOn(AliESDtrack::kTRDout)))  && (track->IsOn(AliESDtrack::kTPCout)) ) {
1290           ((TH1F*)fHneg->FindObject("hESDprimaryTrackPtNegNoTRDout"))->Fill(pT);
1291           if (pT>0.5){
1292             ((TH1F*)fHneg->FindObject("hESDprimaryTrackEtaNegNoTRDout"))->Fill(eta);
1293             ((TH1F*)fHneg->FindObject("hESDprimaryTrackPhiNegNoTRDout"))->Fill(phi);
1294           }
1295         }
1296        }//end negative
1297      }//end flag advanced check
1298
1299     //matched tracks selection: kTOFout and kTIME
1300     if ( (track->IsOn(AliESDtrack::kTOFout)) &&
1301          (track->IsOn(AliESDtrack::kTIME)) &&
1302          (track->IsOn(AliESDtrack::kTPCout))  ) {      
1303       
1304       Double_t tofTime=track->GetTOFsignal();//in ps
1305       Double_t tofTimeRaw=track->GetTOFsignalRaw();//in ps
1306       Double_t tofToT=track->GetTOFsignalToT(); //in ps
1307       Int_t channel=track->GetTOFCalChannel(); 
1308       Int_t volId[5]; //(sector, plate,strip,padZ,padX)
1309       AliTOFGeometry::GetVolumeIndices(channel,volId);
1310       
1311       if (pT>=0.3) fNTOFtracks++; //matched counter
1312       Double_t tof= tofTime*1E-3; // ns, average T0 fill subtracted, no info from T0detector     
1313       ((TH1F*)fHlist->FindObject("hTOFmatchedESDtime"))->Fill(tof); //ns
1314       ((TH1F*)fHlist->FindObject("hTOFmatchedESDrawTime"))->Fill(tofTimeRaw*1E-3); //ns
1315       ((TH1F*)fHlist->FindObject("hTOFmatchedESDToT"))->Fill(tofToT);
1316       ((TH1F*)fHlist->FindObject("hTOFmatchedESDtrkLength"))->Fill(length);  
1317       ((TH1F*)fHlist->FindObject("hTOFmatchedESDP"))->Fill(mom);
1318       ((TH1F*)fHlist->FindObject("hTOFmatchedESDPt"))->Fill(pT);
1319       if (pT>=0.5)
1320         ((TH1F*)fHlist->FindObject("hTOFmatchedESDeta"))->Fill(eta);
1321       ((TH1F*)fHlist->FindObject("hTOFmatchedESDphi"))->Fill(phi);
1322       if (track->GetSign()>0)
1323         ((TH2F*)fHlist->FindObject("hTOFmatchedDxVsPtPos"))->Fill(pT,track->GetTOFsignalDx());
1324       else ((TH2F*)fHlist->FindObject("hTOFmatchedDxVsPtNeg"))->Fill(pT,track->GetTOFsignalDx());
1325       ((TH2F*)fHlist->FindObject("hTOFmatchedDzVsStrip"))->Fill((Int_t)GetStripIndex(volId),track->GetTOFsignalDz());
1326
1327       //evaluate sign
1328       if (fEnableAdvancedCheck){
1329         if (track->GetSign()>0){
1330           ((TH1F*)fHpos->FindObject("hTOFmatchedESDtrkLengthPos"))->Fill(length);  
1331           ((TH1F*)fHpos->FindObject("hTOFmatchedESDPPos"))->Fill(mom); 
1332           ((TH1F*)fHpos->FindObject("hTOFmatchedESDPtPos"))->Fill(pT); 
1333           if (pT>=0.5){
1334             ((TH1F*)fHpos->FindObject("hTOFmatchedESDetaPos"))->Fill(eta);
1335             ((TH1F*)fHpos->FindObject("hTOFmatchedESDphiPos"))->Fill(phi);
1336           }     
1337           if ( (track->IsOn(AliESDtrack::kTRDout))  && (track->IsOn(AliESDtrack::kTPCout)) ) {
1338             ((TH1F*)fHpos->FindObject("hESDmatchedTrackPtPosTRDout"))->Fill(pT);
1339             if (pT>=0.5){
1340               ((TH1F*)fHpos->FindObject("hESDmatchedTrackEtaPosTRDout"))->Fill(eta);
1341               ((TH1F*)fHpos->FindObject("hESDmatchedTrackPhiPosTRDout"))->Fill(phi);
1342             }
1343           } 
1344           if ((!(track->IsOn(AliESDtrack::kTRDout)))  && (track->IsOn(AliESDtrack::kTPCout)) ) {
1345             ((TH1F*)fHpos->FindObject("hESDmatchedTrackPtPosNoTRDout"))->Fill(pT);
1346             if (pT>=0.5) {
1347               ((TH1F*)fHpos->FindObject("hESDmatchedTrackEtaPosNoTRDout"))->Fill(eta);
1348               ((TH1F*)fHpos->FindObject("hESDmatchedTrackPhiPosNoTRDout"))->Fill(phi);
1349             }
1350           }
1351        }// END POSITIVE
1352        else {   
1353          ((TH1F*)fHneg->FindObject("hTOFmatchedESDtrkLengthNeg"))->Fill(length);  
1354          ((TH1F*)fHneg->FindObject("hTOFmatchedESDPNeg"))->Fill(mom); 
1355          ((TH1F*)fHneg->FindObject("hTOFmatchedESDPtNeg"))->Fill(pT); 
1356          if (pT>=0.5) {
1357            ((TH1F*)fHneg->FindObject("hTOFmatchedESDetaNeg"))->Fill(eta);
1358            ((TH1F*)fHneg->FindObject("hTOFmatchedESDphiNeg"))->Fill(phi);
1359          }        
1360          if ((track->IsOn(AliESDtrack::kTRDout))  && (track->IsOn(AliESDtrack::kTPCout)) ) {
1361            ((TH1F*)fHneg->FindObject("hESDmatchedTrackPtNegTRDout"))->Fill(pT);
1362            if (pT>=0.5) {
1363              ((TH1F*)fHneg->FindObject("hESDmatchedTrackEtaNegTRDout"))->Fill(eta);
1364              ((TH1F*)fHneg->FindObject("hESDmatchedTrackPhiNegTRDout"))->Fill(phi);         
1365            }
1366          }
1367          if ((!(track->IsOn(AliESDtrack::kTRDout)))  && (track->IsOn(AliESDtrack::kTPCout)) ) {
1368            ((TH1F*)fHneg->FindObject("hESDmatchedTrackPtNegNoTRDout"))->Fill(pT);
1369            if (pT>=0.5) {
1370              ((TH1F*)fHneg->FindObject("hESDmatchedTrackEtaNegNoTRDout"))->Fill(eta);
1371              ((TH1F*)fHneg->FindObject("hESDmatchedTrackPhiNegNoTRDout"))->Fill(phi);
1372            }
1373          }        
1374        }//end negative
1375       }//end advanced check
1376
1377       //basic PID performance check
1378       if (tof<=0) {
1379         printf("WARNING: track with negative TOF time found! Skipping this track for PID checks\n");
1380         continue;
1381       }
1382       if (mom2==0) {
1383         printf("WARNING: track with negative square momentum found! Skipping this track for PID checks\n");
1384         continue;
1385       }
1386       if (length<=0){
1387         printf("WARNING: track with negative length found!Skipping this track for PID checks\n");
1388         continue;
1389       }
1390       Double_t c=TMath::C()*1.E-9;// m/ns
1391       Double_t mass=0.; //GeV
1392       length =length*0.01; // in meters
1393       tof=tof*c;
1394       Double_t beta=length/tof;
1395       Double_t fact= (tof/length)*(tof/length) -1.;
1396       if(fact<=0) {
1397         mass = -mom*TMath::Sqrt(-fact);
1398       }else{ 
1399         mass = mom*TMath::Sqrt(fact); 
1400       }
1401       ((TH2F*)fHlistPID->FindObject("hTOFmatchedESDpVsBeta"))->Fill(mom,beta);
1402       ((TH1F*) fHlistPID->FindObject("hTOFmatchedMass"))->Fill(mass);
1403       
1404       //PID sigmas
1405       Bool_t isValidBeta[AliPID::kSPECIES]={0,0,0,0,0};
1406       for (Int_t specie = 0; specie < AliPID::kSPECIES; specie++){
1407         fSigmaSpecie[specie] = fESDpid->GetTOFResponse().GetExpectedSigma(mom, fTrkExpTimes[specie], AliPID::ParticleMass(specie));
1408         beta=1/TMath::Sqrt(1+AliPID::ParticleMass(specie)*AliPID::ParticleMass(specie)/(mom2));
1409         if (beta>0) {
1410           fThExpTimes[specie]=length*1.E3/(beta*c);//ps
1411           isValidBeta[specie]=kTRUE;
1412         } else {
1413           fThExpTimes[specie]=1E-10;
1414           isValidBeta[specie]=kFALSE;
1415         }
1416       }
1417       
1418       if (isValidBeta[AliPID::kPion]){
1419         ((TH2F*)fHlistPID->FindObject("hTOFmatchedExpTimePiVsEta"))->Fill((Int_t)GetStripIndex(volId),tofTime-fTrkExpTimes[AliPID::kPion]);//ps
1420         ((TH1F*)fHlistPID->FindObject("hTOFmatchedExpTimePi"))->Fill(tofTime-fTrkExpTimes[AliPID::kPion]);//ps
1421         ((TH2F*)fHlistPID->FindObject("hTOFmatchedExpTimePiVsP"))->Fill(mom,(tofTime-fTrkExpTimes[AliPID::kPion]));
1422         ((TH1F*)fHlistPID->FindObject("hTOFtheoreticalExpTimePi"))->Fill(tofTime-fThExpTimes[AliPID::kPion]);//ps
1423         ((TH2F*)fHlistPID->FindObject("hTOFtheoreticalExpTimePiVsP"))->Fill(mom,(tofTime-fThExpTimes[AliPID::kPion]));  
1424         ((TH2F*)fHlistPID->FindObject("hTOFExpSigmaPi"))->Fill(pT,(tofTime-fTrkExpTimes[AliPID::kPion])/fSigmaSpecie[AliPID::kPion]);
1425       }
1426       
1427       if (isValidBeta[AliPID::kKaon]){
1428         ((TH1F*)fHlistPID->FindObject("hTOFmatchedExpTimeKa"))->Fill(tofTime-fTrkExpTimes[AliPID::kKaon]);//ps
1429         ((TH2F*)fHlistPID->FindObject("hTOFmatchedExpTimeKaVsP"))->Fill(mom,(tofTime-fTrkExpTimes[AliPID::kKaon]));
1430         ((TH1F*)fHlistPID->FindObject("hTOFtheoreticalExpTimeKa"))->Fill(tofTime-fThExpTimes[AliPID::kKaon]);//ps
1431         ((TH2F*)fHlistPID->FindObject("hTOFtheoreticalExpTimeKaVsP"))->Fill(mom,(tofTime-fThExpTimes[AliPID::kKaon]));
1432         ((TH2F*)fHlistPID->FindObject("hTOFExpSigmaKa"))->Fill(pT,(tofTime-fTrkExpTimes[AliPID::kKaon])/fSigmaSpecie[AliPID::kKaon]);
1433       }
1434       if (isValidBeta[AliPID::kProton]){
1435         ((TH1F*)fHlistPID->FindObject("hTOFmatchedExpTimePro"))->Fill(tofTime-fTrkExpTimes[AliPID::kProton]);//ps
1436         ((TH2F*)fHlistPID->FindObject("hTOFmatchedExpTimeProVsP"))->Fill(mom,(tofTime-fTrkExpTimes[AliPID::kProton]));
1437         ((TH1F*)fHlistPID->FindObject("hTOFtheoreticalExpTimePro"))->Fill(tofTime-fThExpTimes[AliPID::kProton]);//ps
1438         ((TH2F*)fHlistPID->FindObject("hTOFtheoreticalExpTimeProVsP"))->Fill(mom,(tofTime-fThExpTimes[AliPID::kProton]));
1439         ((TH2F*)fHlistPID->FindObject("hTOFExpSigmaPro"))->Fill(pT,(tofTime-fTrkExpTimes[AliPID::kProton])/fSigmaSpecie[AliPID::kProton]);
1440       }
1441
1442       if (fEnableAdvancedCheck && (pT<1.)) {
1443         Double_t pos[3]={0.,0.,0.};
1444         track->GetXYZAt(378.,5.,pos);
1445         if ((pos[0]==0.)&&(pos[1]==0.)&&(pos[2]==0.))continue;
1446         
1447         Double_t phiTOF=TMath::ATan2(pos[1],pos[0])*TMath::RadToDeg();
1448         if (phiTOF<0) phiTOF+= (2*TMath::Pi()*TMath::RadToDeg());
1449         
1450         if (isValidBeta[AliPID::kProton]){
1451           if (track->GetSign()>0){
1452             ((TH2F*)fHpos->FindObject("hTOFmatchedExpTimeProVsPhiPos"))->Fill(phiTOF,tofTime-fTrkExpTimes[AliPID::kProton]);//ps
1453             ((TH2F*)fHpos->FindObject("hTOFmatchedExpTimeProVsPhiVertexPos"))->Fill(phi,tofTime-fTrkExpTimes[AliPID::kProton]);//ps
1454           } else {
1455             ((TH2F*)fHneg->FindObject("hTOFmatchedExpTimeProVsPhiNeg"))->Fill(phiTOF,tofTime-fTrkExpTimes[AliPID::kProton]);//ps
1456             ((TH2F*)fHneg->FindObject("hTOFmatchedExpTimeProVsPhiVertexNeg"))->Fill(phi,tofTime-fTrkExpTimes[AliPID::kProton]);//ps
1457           }
1458         }
1459         
1460         track->GetOuterXYZ(pos);
1461         Double_t phiOuterTPC=TMath::ATan2(pos[1],pos[0])*TMath::RadToDeg();
1462         if (phiOuterTPC<0) phiOuterTPC+= (2*TMath::Pi()*TMath::RadToDeg());
1463         
1464         if (track->GetSign()>0){
1465           if (isValidBeta[AliPID::kProton])
1466             ((TH2F*)fHpos->FindObject("hTOFmatchedExpTimeProVsPhiTPCPos"))->Fill(phiOuterTPC,tofTime-fTrkExpTimes[AliPID::kProton]);//ps
1467           if (isValidBeta[AliPID::kPion])
1468             ((TH2F*)fHpos->FindObject("hTOFmatchedExpTimePiVsPhiTPCPos"))->Fill(phiOuterTPC,tofTime-fTrkExpTimes[AliPID::kPion]);//ps
1469           if (isValidBeta[AliPID::kKaon])
1470             ((TH2F*)fHpos->FindObject("hTOFmatchedExpTimeKaVsPhiTPCPos"))->Fill(phiOuterTPC,tofTime-fTrkExpTimes[AliPID::kKaon]);//ps
1471           
1472           if ((phiOuterTPC<=30) || ((phiOuterTPC>=150)&&(phiOuterTPC<=230)) || (phiOuterTPC>=310) ) { //TRD sectors
1473             if (isValidBeta[AliPID::kPion])
1474               ((TH2F*)fHlistPID->FindObject("hTOFmatchedExpTimePiVsPTRDPos"))->Fill(mom,(tofTime-fTrkExpTimes[AliPID::kPion]));
1475             if (isValidBeta[AliPID::kKaon])
1476               ((TH2F*)fHlistPID->FindObject("hTOFmatchedExpTimeKaVsPTRDPos"))->Fill(mom,(tofTime-fTrkExpTimes[AliPID::kKaon]));
1477             if (isValidBeta[AliPID::kProton])
1478               ((TH2F*)fHlistPID->FindObject("hTOFmatchedExpTimeProVsPTRDPos"))->Fill(mom,(tofTime-fTrkExpTimes[AliPID::kProton]));
1479           }
1480           if ( ((phiOuterTPC>=50)&&(phiOuterTPC<=130)) || ((phiOuterTPC>=250)&&(phiOuterTPC<=290)) ) {//no TRD sectors
1481             if (isValidBeta[AliPID::kPion])
1482               ((TH2F*)fHlistPID->FindObject("hTOFmatchedExpTimePiVsPNoTRDPos"))->Fill(mom,(tofTime-fTrkExpTimes[AliPID::kPion]));
1483             if (isValidBeta[AliPID::kKaon])
1484               ((TH2F*)fHlistPID->FindObject("hTOFmatchedExpTimeKaVsPNoTRDPos"))->Fill(mom,(tofTime-fTrkExpTimes[AliPID::kKaon]));
1485             if (isValidBeta[AliPID::kProton])
1486               ((TH2F*)fHlistPID->FindObject("hTOFmatchedExpTimeProVsPNoTRDPos"))->Fill(mom,(tofTime-fTrkExpTimes[AliPID::kProton]));
1487           }
1488         }else{
1489           if (isValidBeta[AliPID::kPion])
1490             ((TH2F*)fHneg->FindObject("hTOFmatchedExpTimePiVsPhiTPCNeg"))->Fill(phiOuterTPC,tofTime-fTrkExpTimes[AliPID::kPion]);//ps
1491           if (isValidBeta[AliPID::kKaon])
1492             ((TH2F*)fHneg->FindObject("hTOFmatchedExpTimeKaVsPhiTPCNeg"))->Fill(phiOuterTPC,tofTime-fTrkExpTimes[AliPID::kKaon]);//ps
1493           if (isValidBeta[AliPID::kProton])
1494             ((TH2F*)fHneg->FindObject("hTOFmatchedExpTimeProVsPhiTPCNeg"))->Fill(phiOuterTPC,tofTime-fTrkExpTimes[AliPID::kProton]);//ps
1495           
1496           if ((phiOuterTPC<=30) || ((phiOuterTPC>=150)&&(phiOuterTPC<=230)) || (phiOuterTPC>=310) ) { //TRD sectors
1497             if (isValidBeta[AliPID::kPion])
1498               ((TH2F*)fHlistPID->FindObject("hTOFmatchedExpTimePiVsPTRDNeg"))->Fill(mom,(tofTime-fTrkExpTimes[AliPID::kPion]));
1499             if (isValidBeta[AliPID::kKaon])
1500               ((TH2F*)fHlistPID->FindObject("hTOFmatchedExpTimeKaVsPTRDNeg"))->Fill(mom,(tofTime-fTrkExpTimes[AliPID::kKaon]));
1501             if (isValidBeta[AliPID::kProton])
1502               ((TH2F*)fHlistPID->FindObject("hTOFmatchedExpTimeProVsPTRDNeg"))->Fill(mom,(tofTime-fTrkExpTimes[AliPID::kProton]));
1503           }
1504           if ( ((phiOuterTPC>=50)&&(phiOuterTPC<=130)) || ((phiOuterTPC>=250)&&(phiOuterTPC<=290)) ) {//no TRD sectors
1505             if (isValidBeta[AliPID::kPion])
1506               ((TH2F*)fHlistPID->FindObject("hTOFmatchedExpTimePiVsPNoTRDNeg"))->Fill(mom,(tofTime-fTrkExpTimes[AliPID::kPion]));
1507               if (isValidBeta[AliPID::kKaon])
1508                 ((TH2F*)fHlistPID->FindObject("hTOFmatchedExpTimeKaVsPNoTRDNeg"))->Fill(mom,(tofTime-fTrkExpTimes[AliPID::kKaon]));
1509               if (isValidBeta[AliPID::kProton])
1510                 ((TH2F*)fHlistPID->FindObject("hTOFmatchedExpTimeProVsPNoTRDNeg"))->Fill(mom,(tofTime-fTrkExpTimes[AliPID::kProton]));
1511           }
1512         }
1513         
1514       }//end advanced checks && cut on pT for t-texp phi distrib      
1515     }//matched
1516   }//end loop on tracks
1517   
1518   ((TH1F*)fHlist->FindObject("hTOFmatchedPerEvt"))->Fill(fNTOFtracks) ;
1519   ((TH2F*)fHlistTimeZero->FindObject("hT0TOFvsNtrk"))->Fill(fNTOFtracks,timeZero[AliESDpid::kTOF_T0]);
1520   
1521   PostData(1, fHlist);
1522   PostData(2, fHlistTimeZero);
1523   PostData(3, fHlistPID);
1524   PostData(4, fHpos);
1525   PostData(5, fHneg);
1526   
1527 }      
1528
1529 //________________________________________________________________________
1530 void AliAnalysisTaskTOFqa::Terminate(Option_t *) 
1531 {
1532   //check on output validity
1533   fHlist = dynamic_cast<TList*> (GetOutputData(1));
1534   if (!fHlist || !fHlistTimeZero) {
1535     Printf("ERROR: lists not available");
1536     return;   
1537   }   
1538  
1539 }
1540
1541 //---------------------------------------------------------------
1542 Int_t AliAnalysisTaskTOFqa::GetStripIndex(const Int_t * const in)
1543 {
1544   /* return tof strip index between 0 and 91 */
1545   
1546   Int_t nStripA = AliTOFGeometry::NStripA();
1547   Int_t nStripB = AliTOFGeometry::NStripB();
1548   Int_t nStripC = AliTOFGeometry::NStripC();
1549
1550   Int_t iplate = in[1];
1551   Int_t istrip = in[2];
1552   
1553   Int_t stripOffset = 0;
1554   switch (iplate) {
1555   case 0:
1556     stripOffset = 0;
1557       break;
1558   case 1:
1559     stripOffset = nStripC;
1560     break;
1561   case 2:
1562     stripOffset = nStripC+nStripB;
1563     break;
1564   case 3:
1565     stripOffset = nStripC+nStripB+nStripA;
1566     break;
1567   case 4:
1568     stripOffset = nStripC+nStripB+nStripA+nStripB;
1569     break;
1570   default:
1571     stripOffset=-1;
1572     break;
1573   };
1574   
1575   if (stripOffset<0 || stripOffset>92) return -1;
1576   else 
1577     return (stripOffset+istrip);
1578 }
1579
1580 #endif