]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGHF/vertexingHF/AliAnalysisTaskSEHFQA.cxx
Protection against events with trigger mask =0
[u/mrichter/AliRoot.git] / PWGHF / vertexingHF / AliAnalysisTaskSEHFQA.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 /////////////////////////////////////////////////////////////
19 //
20 // AliAnalysisTaskSE for HF quality assurance
21 //
22 // Author: Chiara Bianchin, chiara.bianchin@pd.infn.it
23 /////////////////////////////////////////////////////////////
24
25 #include <Riostream.h>
26 #include <TClonesArray.h>
27 #include <TCanvas.h>
28 #include <TList.h>
29 #include <TH1F.h>
30 #include <TH2F.h>
31 #include <TH3F.h>
32 #include <TProfile2D.h>
33 #include <TDatabasePDG.h>
34
35 #include <AliAnalysisDataSlot.h>
36 #include <AliAnalysisDataContainer.h>
37 #include "AliAnalysisManager.h"
38 #include "AliESDtrack.h"
39 #include "AliESDVertex.h"
40 #include "AliVertexerTracks.h"
41 #include "AliPID.h"
42 #include "AliPIDResponse.h"
43 #include "AliTPCPIDResponse.h"
44 #include "AliAODHandler.h"
45 #include "AliAODEvent.h"
46 #include "AliAODVertex.h"
47 #include "AliAODTrack.h"
48 #include "AliAODMCParticle.h"
49 #include "AliAODMCHeader.h"
50 #include "AliAODRecoDecayHF2Prong.h"
51 #include "AliAODRecoCascadeHF.h"
52 #include "AliAnalysisVertexingHF.h"
53 #include "AliAnalysisTaskSE.h"
54 #include "AliCounterCollection.h"
55 #include "AliRDHFCuts.h"
56 #include "AliRDHFCutsDplustoKpipi.h"
57 #include "AliRDHFCutsD0toKpipipi.h"
58 #include "AliRDHFCutsDstoKKpi.h"
59 #include "AliRDHFCutsDStartoKpipi.h"
60 #include "AliRDHFCutsD0toKpi.h"
61 #include "AliRDHFCutsLctopKpi.h"
62 #include "AliRDHFCutsLctoV0.h"
63 #include "AliInputEventHandler.h"
64
65 #include "AliFlowEvent.h"
66 #include "AliFlowTrackCuts.h"
67 #include "AliFlowTrackSimple.h"
68 #include "AliFlowVector.h"
69
70 #include "AliAnalysisTaskSEHFQA.h"
71
72 using std::cout;
73 using std::endl;
74
75 ClassImp(AliAnalysisTaskSEHFQA)
76
77 //____________________________________________________________________________
78
79 AliAnalysisTaskSEHFQA::AliAnalysisTaskSEHFQA():AliAnalysisTaskSE(),
80   fNEntries(0x0),
81   fOutputPID(0x0),
82   fOutputTrack(0x0),
83   fOutputCounters(0x0),
84   fOutputCheckCentrality(0x0),
85   fOutputEvSelection(0x0),
86   fOutputFlowObs(0x0),
87   fDecayChannel(AliAnalysisTaskSEHFQA::kD0toKpi),
88   fCuts(0x0),
89   fFlowEvent(0x0),
90   fRFPcuts(0x0),
91   fEstimator(AliRDHFCuts::kCentTRK),
92   fReadMC(kFALSE),
93   fSimpleMode(kFALSE),
94   fUseSelectionBit(kTRUE),
95   fOnOff(),
96   fFillDistrTrackEffChecks(kFALSE)
97 {
98   //default constructor
99   fOnOff[0]=kTRUE;
100   fOnOff[1]=kTRUE;
101   fOnOff[2]=kTRUE;
102   fOnOff[3]=kTRUE;
103   fOnOff[4]=kTRUE;
104 }
105
106 //____________________________________________________________________________
107 AliAnalysisTaskSEHFQA::AliAnalysisTaskSEHFQA(const char *name, AliAnalysisTaskSEHFQA::DecChannel ch,AliRDHFCuts* cuts):
108   AliAnalysisTaskSE(name),
109   fNEntries(0x0),
110   fOutputPID(0x0),
111   fOutputTrack(0x0),
112   fOutputCounters(0x0),
113   fOutputCheckCentrality(0x0),
114   fOutputEvSelection(0x0),
115   fOutputFlowObs(0x0),
116   fDecayChannel(ch),
117   fCuts(0x0),
118   fFlowEvent(0x0),
119   fRFPcuts(0x0),
120   fEstimator(AliRDHFCuts::kCentTRK),
121   fReadMC(kFALSE),
122   fSimpleMode(kFALSE),
123   fUseSelectionBit(kTRUE),
124   fOnOff(),
125   fFillDistrTrackEffChecks(kFALSE)
126 {
127   //constructor
128
129   //SetCutObject(cuts);
130   fCuts=cuts;
131
132   fOnOff[0]=kTRUE;
133   fOnOff[1]=kTRUE;
134   fOnOff[2]=kTRUE;
135   fOnOff[3]=kTRUE;
136   fOnOff[4]=kTRUE;
137
138   // Output slot #1 writes into a TH1F container (number of events)
139   DefineOutput(1,TH1F::Class());  //My private output
140   // Output slot #2 writes into a TList container (PID)
141   if (fOnOff[1]) DefineOutput(2,TList::Class());  //My private output
142   // Output slot #3 writes into a TList container (Tracks)
143   if (fOnOff[0]) DefineOutput(3,TList::Class());  //My private output
144   // Output slot #4 writes into a AliRDHFCuts container (cuts)
145   switch(fDecayChannel){
146   case 0:
147     DefineOutput(4,AliRDHFCutsDplustoKpipi::Class());  //My private output
148     break;
149   case 1:
150     DefineOutput(4,AliRDHFCutsD0toKpi::Class());  //My private output
151     break;
152   case 2:
153     DefineOutput(4,AliRDHFCutsDStartoKpipi::Class());  //My private output
154     break;
155   case 3:
156     DefineOutput(4,AliRDHFCutsDstoKKpi::Class());  //My private output
157     break;
158   case 4:
159     DefineOutput(4,AliRDHFCutsD0toKpipipi::Class());  //My private output
160     break;
161   case 5:
162     DefineOutput(4,AliRDHFCutsLctopKpi::Class());  //My private output
163     break;
164   case kLambdactoV0:
165     DefineOutput(4,AliRDHFCutsLctoV0::Class());  //My private output
166     break;
167   }
168   if (fOnOff[2]) {
169     // Output slot #5 writes into a TList container (AliCounterCollection)
170     DefineOutput(5,TList::Class());  //My private output
171     // Output slot #6 writes into a TList container (TH1F)
172     DefineOutput(6,TList::Class());  //My private output
173   }
174
175   if(fOnOff[3]) DefineOutput(7,TList::Class());  //My private output
176   if(fOnOff[4]) DefineOutput(8,TList::Class());  //My private output
177
178 }
179
180 //___________________________________________________________________________
181 AliAnalysisTaskSEHFQA::~AliAnalysisTaskSEHFQA()
182 {
183   //destructor
184   delete fNEntries;
185
186   delete fOutputPID;
187
188   delete fOutputTrack;
189
190   delete fOutputCounters;
191
192   delete fOutputCheckCentrality;
193
194   delete fOutputEvSelection;
195
196   if(fOnOff[4]) {
197     delete fOutputFlowObs;
198     delete fFlowEvent;
199   }
200 }
201
202 //___________________________________________________________________________
203 void AliAnalysisTaskSEHFQA::Init(){
204
205   //initialization
206   if(fDebug > 1) printf("AnalysisTaskSEHFQA::Init() \n");
207   AliRDHFCuts *copycut = 0x0;
208
209   switch(fDecayChannel){
210   case 0:
211     {
212       copycut=new AliRDHFCutsDplustoKpipi(*(static_cast<AliRDHFCutsDplustoKpipi*>(fCuts)));
213     }
214     break;
215   case 1:
216     {
217       copycut=new AliRDHFCutsD0toKpi(*(static_cast<AliRDHFCutsD0toKpi*>(fCuts)));
218     }
219     break;
220   case 2:
221     {
222       copycut=new AliRDHFCutsDStartoKpipi(*(static_cast<AliRDHFCutsDStartoKpipi*>(fCuts)));
223     }
224     break;
225   case 3:
226     {
227       copycut=new AliRDHFCutsDstoKKpi(*(static_cast<AliRDHFCutsDstoKKpi*>(fCuts)));
228     }
229     break;
230   case 4:
231     {
232       copycut=new AliRDHFCutsD0toKpipipi(*(static_cast<AliRDHFCutsD0toKpipipi*>(fCuts)));
233     }
234     break;
235   case 5:
236     {
237       copycut=new AliRDHFCutsLctopKpi(*(static_cast<AliRDHFCutsLctopKpi*>(fCuts)));
238     }
239     break;
240   case kLambdactoV0:
241     {
242       copycut=new AliRDHFCutsLctoV0(*(static_cast<AliRDHFCutsLctoV0*>(fCuts)));
243     }
244     break;
245   default:
246     AliFatal("Bad initialization for the decay channe - Exiting...");
247     break;
248   }  
249
250   const char* nameoutput=GetOutputSlot(4)->GetContainer()->GetName();
251   if (copycut){
252     copycut->SetName(nameoutput);
253     
254     // Post the data
255     PostData(4,copycut);
256   }else{
257     AliFatal("Failing initializing AliRDHFCuts object - Exiting...");
258   }     
259
260   return;
261
262 }
263
264 //___________________________________________________________________________
265 void AliAnalysisTaskSEHFQA::UserCreateOutputObjects()
266 {
267
268   //create the output container
269   if(fDebug > 1) printf("AnalysisTaskSEHFQA::UserCreateOutputObjects() \n");
270
271   //count events
272
273   fNEntries=new TH1F(GetOutputSlot(1)->GetContainer()->GetName(), "Counts the number of events", 10,-0.5,9.5);
274   fNEntries->GetXaxis()->SetBinLabel(1,"nEventsAnal");
275   fNEntries->GetXaxis()->SetBinLabel(2,"Pile-up Rej");
276   fNEntries->GetXaxis()->SetBinLabel(3,"No VertexingHF");
277   fNEntries->GetXaxis()->SetBinLabel(4,"nCandidates(AnCuts)");
278   fNEntries->GetXaxis()->SetBinLabel(5,"EventsWithGoodVtx");
279   //fNEntries->GetXaxis()->SetBinLabel(6,"N. of 0SMH");
280   fNEntries->GetXaxis()->SetBinLabel(6,"N candidates");
281   if(fReadMC){
282     fNEntries->GetXaxis()->SetBinLabel(7,"MC Cand from c");
283     fNEntries->GetXaxis()->SetBinLabel(8,"MC Cand from b");
284     fNEntries->GetXaxis()->SetBinLabel(9,"N fake Trks");
285     fNEntries->GetXaxis()->SetBinLabel(10,"N true Trks");
286   }
287
288   fNEntries->GetXaxis()->SetNdivisions(1,kFALSE);
289
290   //PID
291   if(fOnOff[1]){
292     fOutputPID=new TList();
293     fOutputPID->SetOwner();
294     fOutputPID->SetName(GetOutputSlot(2)->GetContainer()->GetName());
295
296     //TOF pid
297     TH1F* hTOFflags=new TH1F("hTOFflags","TOF flags",7,-0.5,6.5);
298     hTOFflags->SetMinimum(0.);
299     hTOFflags->GetXaxis()->SetBinLabel(1,"All Tracks");
300     hTOFflags->GetXaxis()->SetBinLabel(2,"kTPCout");
301     hTOFflags->GetXaxis()->SetBinLabel(3,"kTOFout");
302     hTOFflags->GetXaxis()->SetBinLabel(4,"kTIME");
303     hTOFflags->GetXaxis()->SetBinLabel(5,"kTOFpid");
304     hTOFflags->GetXaxis()->SetBinLabel(6,"kTOFmismatch");
305     hTOFflags->GetXaxis()->SetBinLabel(7,"kDetPidOK");
306
307     TString hname="hTOFsig";
308     TH1F* hTOFsig=new TH1F(hname.Data(),"Distribution of TOF signal;TOF time [ps];Entries", 100, -2.e3,40.e3);
309
310     hname="hTOFstartTimeMask";
311     TH1F* hTOFstartTimeMask=new TH1F(hname.Data(),"TOF start time mask; Mask ;Entries", 8, -0.5,7.5);
312     hTOFstartTimeMask->GetXaxis()->SetBinLabel(1,"FILL");
313     hTOFstartTimeMask->GetXaxis()->SetBinLabel(2,"TOF");
314     hTOFstartTimeMask->GetXaxis()->SetBinLabel(3,"T0A");
315     hTOFstartTimeMask->GetXaxis()->SetBinLabel(4,"TOF.and.T0A");
316     hTOFstartTimeMask->GetXaxis()->SetBinLabel(5,"T0C");
317     hTOFstartTimeMask->GetXaxis()->SetBinLabel(6,"TOF.and.T0C");
318     hTOFstartTimeMask->GetXaxis()->SetBinLabel(7,"T0AC");
319     hTOFstartTimeMask->GetXaxis()->SetBinLabel(8,"TOF.and.T0AC");
320
321     hname="hTOFstartTimeRes";
322     TH1F* hTOFstartTimeRes=new TH1F(hname.Data(),"TOF start time resolution; Resolution (ps) ;Entries", 100, 0.,300.);
323
324     hname="hTOFstartTimeDistrib";
325     TH1F* hTOFstartTimeDistrib=new TH1F(hname.Data(),"TOF start time distribution; Start time ;Entries", 400, -1000.,1000.);
326
327     hname="hTOFtime";
328     TH1F* hTOFtime=new TH1F(hname.Data(),"Distribution of TOF time Kaon;TOF time(Kaon) [ps];Entries", 1000, 0.,50000.);
329
330     hname="hTOFtimeKaonHyptime";
331     TH2F* hTOFtimeKaonHyptime=new TH2F(hname.Data(),"TOFtime - timeHypothesisForKaon;p[GeV/c];TOFtime - timeHypothesisForKaon [ps]",500,0.,10.,1000,-20000.,20000.);
332
333     hname="hTOFtimeKaonHyptimeAC";
334     TH2F* hTOFtimeKaonHyptimeAC=new TH2F(hname.Data(),"TOFtime - timeHypothesisForKaon;p[GeV/c];TOFtime - timeHypothesisForKaon [ps]",500,0.,10.,1000,-20000.,20000.);
335
336     hname="hTOFsigmaKSigPid";
337     TH2F* hTOFsigmaKSigPid=new TH2F(hname.Data(),"(TOFsignal-timeK)/tofSigPid;p[GeV/c];(TOFsignal-timeK)/tofSigPid",500,0.,10.,400,-20,20);
338
339     hname="hTOFsigmaPionSigPid";
340     TH2F* hTOFsigmaPionSigPid=new TH2F(hname.Data(),"(TOFsignal-time#pi)/tofSigPid;p[GeV/c];(TOFsignal-time#pi)/tofSigPid",500,0.,10.,400,-20,20);
341
342     hname="hTOFsigmaProtonSigPid";
343     TH2F* hTOFsigmaProtonSigPid=new TH2F(hname.Data(),"(TOFsignal-timep)/tofSigPid;p[GeV/c];(TOFsignal-time p)/tofSigPid",500,0.,10.,400,-20,20);
344
345     hname="hTOFsigPid3sigPion";
346     TH1F* hTOFsigPid3sigPion=new TH1F(hname.Data(),"TOF PID resolution (#pi) [ps]",500,0.,1000.);
347
348     hname="hTOFsigPid3sigKaon";
349     TH1F* hTOFsigPid3sigKaon=new TH1F(hname.Data(),"TOF PID resolution (K) [ps]",500,0.,1000.);
350
351     hname="hTOFsigPid3sigProton";
352     TH1F* hTOFsigPid3sigProton=new TH1F(hname.Data(),"TOF PID resolution (p) [ps]",500,0.,1000.);
353
354
355     //TPC pid
356     hname="hTPCsig";
357     TH1F* hTPCsig=new TH1F(hname.Data(),"Distribution of TPC signal;TPC sig;Entries", 100, 35.,100.);
358
359     hname="hTPCsigvsp";
360     TH2F* hTPCsigvsp=new TH2F(hname.Data(),"TPCsig vs p;TPC p[GeV/c];TPCsig",500,0.,10.,1000,35.,100.);
361  
362     hname="hTPCsigvspAC";
363     TH2F* hTPCsigvspAC=new TH2F(hname.Data(),"TPCsig vs p;TPCp[GeV/c];TPCsig",500,0.,10.,1000,35.,100.);
364
365     hname="hTPCsigmaK";
366     TH2F* hTPCsigmaK=new TH2F(hname.Data(),"TPC Sigma for K as a function of momentum;p[GeV/c];Sigma Kaon",500,0.,10.,400,-20,20);
367
368     hname="hTPCsigmaPion";
369     TH2F* hTPCsigmaPion=new TH2F(hname.Data(),"TPC Sigma for #pi as a function of momentum;p[GeV/c];Sigma #pi",500,0.,10.,400,-20,20);
370
371     hname="hTPCsigmaProton";
372     TH2F* hTPCsigmaProton=new TH2F(hname.Data(),"TPC Sigma for proton as a function of momentum;p[GeV/c];Sigma Proton",500,0.,10.,400,-20,20);
373
374
375     fOutputPID->Add(hTOFflags);
376     fOutputPID->Add(hTOFsig);
377     fOutputPID->Add(hTPCsig);
378     fOutputPID->Add(hTOFstartTimeMask);
379     fOutputPID->Add(hTOFstartTimeRes);
380     fOutputPID->Add(hTOFstartTimeDistrib);
381     fOutputPID->Add(hTOFtime);
382     fOutputPID->Add(hTOFtimeKaonHyptime);
383     fOutputPID->Add(hTOFtimeKaonHyptimeAC);
384     fOutputPID->Add(hTOFsigmaKSigPid);
385     fOutputPID->Add(hTOFsigmaPionSigPid);
386     fOutputPID->Add(hTOFsigmaProtonSigPid);
387     fOutputPID->Add(hTOFsigPid3sigPion);
388     fOutputPID->Add(hTOFsigPid3sigKaon);
389     fOutputPID->Add(hTOFsigPid3sigProton);
390     fOutputPID->Add(hTPCsigvsp);
391     fOutputPID->Add(hTPCsigvspAC);
392     fOutputPID->Add(hTPCsigmaK);
393     fOutputPID->Add(hTPCsigmaPion);
394     fOutputPID->Add(hTPCsigmaProton);
395
396     if(fFillDistrTrackEffChecks){
397
398       hname="hTPCsigNvsPtAllTracks";
399       TH2F* hTPCsigNvsPtAllTracks=new TH2F(hname.Data(),"Distribution of n. points used for TPC dE/dx vs. p_{T};p_{T} [GeV/c]; n. points", 200, 0.,20.,161,-0.5,160.5);
400       
401       hname="hTPCsigNvsPhiAllTracks";
402       TH2F* hTPCsigNvsPhiAllTracks=new TH2F(hname.Data(),"Distribution of n. points used for TPC dE/dx vs. #phi;#phi [rad]; n. points", 100, 0.,2*TMath::Pi(),161,-0.5,160.5);
403       
404       hname="hTPCsigNvsEtaAllTracks";
405       TH2F* hTPCsigNvsEtaAllTracks=new TH2F(hname.Data(),"Distribution of n. points used for TPC dE/dx vs. #eta;eta; n. points", 80,-2.,2.,161,-0.5,160.5);
406       
407       hname="hTPCsigNvsPtDaughters";
408       TH2F* hTPCsigNvsPtDaughters=new TH2F(hname.Data(),"Distribution of n. points used for TPC dE/dx vs. p_{T};p_{T} [GeV/c]; n. points", 200, 0.,20.,161,-0.5,160.5);
409       
410       hname="hTPCsigNvsPhiDaughters";
411       TH2F* hTPCsigNvsPhiDaughters=new TH2F(hname.Data(),"Distribution of n. points used for TPC dE/dx vs. #phi;#phi [rad]; n. points", 100, 0.,2*TMath::Pi(),161,-0.5,160.5);
412       
413       hname="hTPCsigNvsEtaDaughters";
414       TH2F* hTPCsigNvsEtaDaughters=new TH2F(hname.Data(),"Distribution of n. points used for TPC dE/dx vs. #eta;eta; n. points", 80,-2.,2.,161,-0.5,160.5);
415       
416       fOutputPID->Add(hTPCsigNvsPtAllTracks);
417       fOutputPID->Add(hTPCsigNvsPhiAllTracks);
418       fOutputPID->Add(hTPCsigNvsEtaAllTracks);
419       fOutputPID->Add(hTPCsigNvsPtDaughters);
420       fOutputPID->Add(hTPCsigNvsPhiDaughters);
421       fOutputPID->Add(hTPCsigNvsEtaDaughters);
422     }
423     
424     
425     if(fReadMC){
426       //TOF
427       hname="hTOFsigmaMCKSigPid";
428       TH2F* hTOFsigmaMCKSigPid=new TH2F(hname.Data(),"(TOFsignal-timeK)/tofSigPid;p[GeV/c];(TOFsignal-timeK)/tofSigPid",500,0.,10.,400,-20,20);
429
430       hname="hTOFsigmaMCPionSigPid";
431       TH2F* hTOFsigmaMCPionSigPid=new TH2F(hname.Data(),"(TOFsignal-time#pi)/tofSigPid;p[GeV/c];(TOFsignal-time#pi)/tofSigPid",500,0.,10.,400,-20,20);
432
433       hname="hTOFsigmaMCProtonSigPid";
434       TH2F* hTOFsigmaMCProtonSigPid=new TH2F(hname.Data(),"(TOFsignal-timep)/tofSigPid;p[GeV/c];(TOFsignal-time p)/tofSigPid",500,0.,10.,400,-20,20);
435
436       //TPC
437       hname="hTPCsigmaMCK";
438       TH2F* hTPCsigmaMCK=new TH2F(hname.Data(),"TPC Sigma for K as a function of momentum;p[GeV/c];Sigma Kaon",500,0.,10.,400,-20,20);
439
440       hname="hTPCsigmaMCPion";
441       TH2F* hTPCsigmaMCPion=new TH2F(hname.Data(),"TPC Sigma for #pi as a function of momentum;p[GeV/c];Sigma #pi",500,0.,10.,400,-20,20);
442
443       hname="hTPCsigmaMCProton";
444       TH2F* hTPCsigmaMCProton=new TH2F(hname.Data(),"TPC Sigma for proton as a function of momentum;p[GeV/c];Sigma Proton",500,0.,10.,400,-20,20);
445
446       fOutputPID->Add(hTOFsigmaMCKSigPid);
447       fOutputPID->Add(hTOFsigmaMCPionSigPid);
448       fOutputPID->Add(hTOFsigmaMCProtonSigPid);
449       fOutputPID->Add(hTPCsigmaMCK);
450       fOutputPID->Add(hTPCsigmaMCPion);
451       fOutputPID->Add(hTPCsigmaMCProton);
452
453     }
454   }
455
456   //quality of the tracks
457   if(fOnOff[0]){
458     fOutputTrack=new TList();
459     fOutputTrack->SetOwner();
460     fOutputTrack->SetName(GetOutputSlot(3)->GetContainer()->GetName());
461
462     TString hname="hnClsITS";
463     TH1F* hnClsITS=new TH1F(hname.Data(),"Distribution of number of ITS clusters;nITScls;Entries",7,-0.5,6.5);
464
465     hname="hnClsITSselTr";
466     TH1F* hnClsITSselTr=new TH1F(hname.Data(),"Distribution of number of ITS clusters selected tracks;nITScls;Entries",7,-0.5,6.5);
467
468     hname="hnClsITS-SA";
469     TH1F* hnClsITSSA=new TH1F(hname.Data(),"Distribution of number of ITS clusters(ITS-SA);nITScls;Entries",7,-0.5,6.5);
470
471
472     hname="hnLayerITS";
473     TH1F* hnLayerITS=new TH1F(hname.Data(),"Number of tracks with point in layer;ITS layer;",7,-1.5,5.5);
474     hnLayerITS->GetXaxis()->SetBinLabel(1,"n tracks");
475     hnLayerITS->GetXaxis()->SetBinLabel(2,"SPDin");
476     hnLayerITS->GetXaxis()->SetBinLabel(3,"SPDout");
477     hnLayerITS->GetXaxis()->SetBinLabel(4,"SDDin");
478     hnLayerITS->GetXaxis()->SetBinLabel(5,"SDDout");
479     hnLayerITS->GetXaxis()->SetBinLabel(6,"SSDin");
480     hnLayerITS->GetXaxis()->SetBinLabel(7,"SSDout");
481
482     hname="hnLayerITSsa";
483     TH1F* hnLayerITSsa=new TH1F(hname.Data(),"Number of tracks with point in layer;ITS layer;",7,-1.5,5.5);
484     hnLayerITSsa->GetXaxis()->SetBinLabel(1,"n tracks");
485     hnLayerITSsa->GetXaxis()->SetBinLabel(2,"SPDin");
486     hnLayerITSsa->GetXaxis()->SetBinLabel(3,"SPDout");
487     hnLayerITSsa->GetXaxis()->SetBinLabel(4,"SDDin");
488     hnLayerITSsa->GetXaxis()->SetBinLabel(5,"SDDout");
489     hnLayerITSsa->GetXaxis()->SetBinLabel(6,"SSDin");
490     hnLayerITSsa->GetXaxis()->SetBinLabel(7,"SSDout");
491    
492     hname="hnClsSPD";
493     TH1F* hnClsSPD=new TH1F(hname.Data(),"Distribution of number of SPD clusters;nSPDcls;Entries",3,-0.5,2.5);
494
495     hname="hptGoodTr";
496     TH1F* hptGoodTr=new TH1F(hname.Data(),"Pt distribution of 'good' tracks;p_{t}[GeV];Entries/0.05 GeV/c",400,0.,20.);
497     hptGoodTr->SetTitleOffset(1.3,"Y");
498
499     if(!fSimpleMode){
500       hname="hptGoodTrFromDaugh";
501       TH1F* hptGoodTrFromDaugh=new TH1F(hname.Data(),"Pt distribution of 'good' candidate's daughters;p_{t}[GeV];Entries/0.05 GeV/c",400,0.,20.);
502       hptGoodTrFromDaugh->SetTitleOffset(1.3,"Y");
503       fOutputTrack->Add(hptGoodTrFromDaugh);
504     }
505
506     hname="hdistrGoodTr";
507     TH1F* hdistrGoodTr=new TH1F(hname.Data(),"Distribution of number of 'good' candidate's daughters per event;no.good-tracks/ev;Entries",4000,-0.5,3999.5);
508     hdistrGoodTr->SetTitleOffset(1.3,"Y");
509
510     hname="hdistrSelTr";
511     TH1F* hdistrSelTr=new TH1F(hname.Data(),"Distribution of number of Selected tracks per event;no.good-tracks/ev;Entries",4000,-0.5,3999.5);
512     hdistrSelTr->SetTitleOffset(1.3,"Y");
513
514     hname="hd0dau";
515     TH1F* hd0dau=new TH1F(hname.Data(),"Impact parameter (rphi) distribution of D daughter tracks;d_{0rphi}[cm];Entries/10^{3} cm",200,-0.1,0.1);
516
517     hname="hd0zdau";
518     TH1F* hd0zdau=new TH1F(hname.Data(),"Impact parameter (z) distribution of D daughter tracks;d_{0z}[cm];Entries/10^{3} cm",200,-0.1,0.1);
519
520     hname="hd0TracksSPDin";
521     TH1F* hd0TracksSPDin=new TH1F(hname.Data(),"Impact parameter (rphi) distribution of AOD tracks kITSrefit, SPDinner; d_{0rphi}[cm];Entries",200,-0.5,0.5);
522
523     hname="hd0TracksSPDany";
524     TH1F* hd0TracksSPDany=new TH1F(hname.Data(),"Impact parameter (rphi) distribution of AOD tracks kITSrefit, SPDany; d_{0rphi}[cm];Entries",200,-0.5,0.5);
525
526     hname="hd0TracksFilterBit4";
527     TH1F* hd0TracksFilterBit4=new TH1F(hname.Data(),"Impact parameter (rphi) distribution of AOD tracks FilterBit4; d_{0rphi}[cm];Entries",200,-0.5,0.5);
528
529     hname="hd0TracksTPCITSSPDany";
530     TH1F* hd0TracksTPCITSSPDany=new TH1F(hname.Data(),"Impact parameter (rphi) distribution of AOD tracks TPC+ITScuts+SPDany; d_{0rphi}[cm];Entries",200,-0.5,0.5);
531
532
533     if(fFillDistrTrackEffChecks){
534       hname="hPtDaughters";
535       TH1F *hPtDaughters=new TH1F(hname.Data(),"p_{T} distributions of the daughter tracks;p_{T} [GeV/c];Entries",200,0.,20.);
536
537       hname="hPhiDaughters";
538       TH1F *hPhiDaughters=new TH1F(hname.Data(),"#phi distribution of the daughter tracks;#phi [rad];Entries",100,0.,2*(TMath::Pi()));
539
540       hname="hEtaDaughters";
541       TH1F *hEtaDaughters=new TH1F(hname.Data(),"#eta distribution of the daughter tracks;#eta;Entries",80,-2.,2.);
542
543       hname="hEtavsPhiDaughters";
544       TH2F *hEtavsPhiDaughters=new TH2F(hname.Data(),"#eta vs #phi distribution of the daughter tracks;#phi;#eta",100,0.,2*(TMath::Pi()),80,-2.,2.);
545
546       hname="hNTPCclsvsPtDaughters";
547       TH2F *hNTPCclsvsPtDaughters=new TH2F(hname.Data(),"N TPC clusters vs p_{T} distribution of the daughter tracks;p_{T} [GeV/c];N TPC cls",200,0.,20.,85,-0.5,169.5);
548
549       hname="hNTPCclsvsPhiDaughters";
550       TH2F *hNTPCclsvsPhiDaughters=new TH2F(hname.Data(),"N TPC clusters vs #phi distribution of the daughter tracks;#phi [rad];N TPC cls",100,0.,2*(TMath::Pi()),85,-0.5,169.5);
551
552       hname="hNTPCclsvsEtaDaughters";
553       TH2F *hNTPCclsvsEtaDaughters=new TH2F(hname.Data(),"N TPC clusters vs #eta distribution of the daughter tracks;#eta;N TPC cls",80,-2.,2.,85,-0.5,169.5);
554
555       hname="hNTPCCrossedRowsvsPtDaughters";
556       TH2F *hNTPCCrossedRowsvsPtDaughters=new TH2F(hname.Data(),"N TPC crossed rows vs p_{T} distribution of the daughter tracks;p_{T} [GeV/c];N TPC cros. rows",200,0.,20.,100,-0.5,199.5);
557
558       hname="hNTPCCrossedRowsvsPhiDaughters";
559       TH2F *hNTPCCrossedRowsvsPhiDaughters=new TH2F(hname.Data(),"N TPC crossed rows vs #phi distribution of the daughter tracks;#phi [rad];N TPC cros. rows",100,0.,2*(TMath::Pi()),100,-0.5,199.5);
560
561       hname="hNTPCCrossedRowsvsEtaDaughters";
562       TH2F *hNTPCCrossedRowsvsEtaDaughters=new TH2F(hname.Data(),"N TPC crossed rows vs #eta distribution of the daughter tracks;#eta;N TPC cros. rows",80,-2.,2.,100,-0.5,199.5);
563
564       hname="hRatioCRowsOverFclsvsPtDaughters";
565       TH2F *hRatioCRowsOverFclsvsPtDaughters=new TH2F(hname.Data(),"CrossedRows/FindableClusters vs p_{T} distribution of the daughter tracks;p_{T} [GeV/c];CRows/FCls",200,0.,20,100,0.,1.);
566
567       hname="hRatioCRowsOverFclsvsPhiDaughters";
568       TH2F *hRatioCRowsOverFclsvsPhiDaughters=new TH2F(hname.Data(),"CrossedRows/FindableClusters vs #phi distribution of the daughter tracks;#phi [rad];CRows/FCls",100,0.,2*(TMath::Pi()),100,0.,1.);
569
570       hname="hRatioCRowsOverFclsvsEtaDaughters";
571       TH2F *hRatioCRowsOverFclsvsEtaDaughters=new TH2F(hname.Data(),"CrossedRows/FindableClusters vs #eta distribution of the daughter tracks;#eta;CRows/FCls",80,-2.,2.,100,0.,1.);
572
573       hname="hNITSclsvsPtDaughters";
574       TH2F *hNITSclsvsPtDaughters=new TH2F(hname.Data(),"N ITS clusters vs p_{T} distribution of the daughter tracks;p_{T} [GeV/c];N ITS cls",200,0.,20,7,-0.5,6.5);
575
576       hname="hNITSclsvsPhiDaughters";
577       TH2F *hNITSclsvsPhiDaughters=new TH2F(hname.Data(),"N ITS clusters vs #phi distribution of the daughter tracks;#phi [rad];N ITS cls",100,0.,2*(TMath::Pi()),7,-0.5,6.5);
578
579       hname="hNITSclsvsEtaDaughters";
580       TH2F *hNITSclsvsEtaDaughters=new TH2F(hname.Data(),"N ITS clusters vs #eta distribution of the daughter tracks;#eta;N ITS cls",80,-2.,2.,7,-0.5,6.5);
581
582       hname="hSPDclsDaughters";
583       TH1I *hSPDclsDaughters = new TH1I(hname.Data(),"N SPD points distribution;;Entries",4,0,4);
584       hSPDclsDaughters->GetXaxis()->SetBinLabel(1, "no SPD");
585       hSPDclsDaughters->GetXaxis()->SetBinLabel(2, "kOnlyFirst");
586       hSPDclsDaughters->GetXaxis()->SetBinLabel(3, "kOnlySecond");
587       hSPDclsDaughters->GetXaxis()->SetBinLabel(4, "kBoth");
588
589       hname="hPtAllTracks";
590       TH1F *hPtAllTracks=new TH1F(hname.Data(),"p_{T} distributions of the AOD tracks (ID>0);p_{T} [GeV/c];Entries",200,0.,20.);
591
592       hname="hPhiAllTracks";
593       TH1F *hPhiAllTracks=new TH1F(hname.Data(),"#phi distribution of the AOD tracks (ID>0);#phi [rad];Entries",100,0.,2*(TMath::Pi()));
594
595       hname="hEtaAllTracks";
596       TH1F *hEtaAllTracks=new TH1F(hname.Data(),"#eta distribution of the AOD tracks (ID>0);#eta;Entries",80,-2.,2.);
597
598       hname="hEtavsPhiAllTracks";
599       TH2F *hEtavsPhiAllTracks=new TH2F(hname.Data(),"#eta vs #phi distribution of the AOD tracks (ID>0);#phi;#eta",100,0.,2*(TMath::Pi()),80,-2.,2.);
600
601       hname="hNTPCclsvsPtAllTracks";
602       TH2F *hNTPCclsvsPtAllTracks=new TH2F(hname.Data(),"N TPC clusters vs p_{T} distribution of the AOD tracks (ID>0);p_{T} [GeV/c];N TPC cls",200,0.,20,85,-0.5,169.5);
603
604       hname="hNTPCclsvsPhiAllTracks";
605       TH2F *hNTPCclsvsPhiAllTracks=new TH2F(hname.Data(),"N TPC clusters vs #phi distribution of the AOD tracks (ID>0);#phi [rad];N TPC cls",100,0.,2*(TMath::Pi()),85,-0.5,169.5);
606
607       hname="hNTPCclsvsEtaAllTracks";
608       TH2F *hNTPCclsvsEtaAllTracks=new TH2F(hname.Data(),"N TPC clusters vs #eta distribution of the AOD tracks (ID>0);#eta;N TPC cls",80,-2.,2.,85,-0.5,169.5);
609
610       hname="hNTPCCrossedRowsvsPtAllTracks";
611       TH2F *hNTPCCrossedRowsvsPtAllTracks=new TH2F(hname.Data(),"N TPC crossed rows vs p_{T} distribution of the AOD tracks;p_{T} [GeV/c];N TPC cros. rows",200,0.,20.,100,-0.5,199.5);
612
613       hname="hNTPCCrossedRowsvsPhiAllTracks";
614       TH2F *hNTPCCrossedRowsvsPhiAllTracks=new TH2F(hname.Data(),"N TPC crossed rows vs #phi distribution of the AOD tracks;#phi [rad];N TPC cros. rows",100,0.,2*(TMath::Pi()),100,-0.5,199.5);
615
616       hname="hNTPCCrossedRowsvsEtaAllTracks";
617       TH2F *hNTPCCrossedRowsvsEtaAllTracks=new TH2F(hname.Data(),"N TPC crossed rows vs #eta distribution of the AOD tracks;#eta;N TPC cros. rows",80,-2.,2.,100,-0.5,199.5);
618
619       hname="hRatioCRowsOverFclsvsPtAllTracks";
620       TH2F *hRatioCRowsOverFclsvsPtAllTracks=new TH2F(hname.Data(),"CrossedRows/FindableClusters vs p_{T} distribution of the AOD tracks (ID>0);p_{T} [GeV/c];CRows/FCls",200,0.,20,100,0.,1.);
621
622       hname="hRatioCRowsOverFclsvsPhiAllTracks";
623       TH2F *hRatioCRowsOverFclsvsPhiAllTracks=new TH2F(hname.Data(),"CrossedRows/FindableClusters vs #phi distribution of the AOD tracks (ID>0);#phi [rad];CRows/FCls",100,0.,2*(TMath::Pi()),100,0.,1.);
624
625       hname="hRatioCRowsOverFclsvsEtaAllTracks";
626       TH2F *hRatioCRowsOverFclsvsEtaAllTracks=new TH2F(hname.Data(),"CrossedRows/FindableClusters vs #eta distribution of the AOD tracks (ID>0);#eta;CRows/FCls",80,-2.,2.,100,0.,1.);
627
628       hname="hNITSclsvsPtAllTracks";
629       TH2F *hNITSclsvsPtAllTracks=new TH2F(hname.Data(),"N ITS clusters vs p_{T} distribution of the AOD tracks (ID>0);p_{T} [GeV/c];N ITS cls",200,0.,20,7,-0.5,6.5);
630
631       hname="hNITSclsvsPhiAllTracks";
632       TH2F *hNITSclsvsPhiAllTracks=new TH2F(hname.Data(),"N ITS clusters vs #phi distribution of the AOD tracks (ID>0);#phi [rad];N ITS cls",100,0.,2*(TMath::Pi()),7,-0.5,6.5);
633
634       hname="hNITSclsvsEtaAllTracks";
635       TH2F *hNITSclsvsEtaAllTracks=new TH2F(hname.Data(),"N ITS clusters vs #eta distribution of the AOD tracks (ID>0);#eta;N ITS cls",80,-2.,2.,7,-0.5,6.5);
636
637       hname="hSPDclsAllTracks";
638       TH1I *hSPDclsAllTracks = new TH1I(hname.Data(),"N SPD points distribution AOD tracks (ID>0);;Entries",4,0,4);
639       hSPDclsAllTracks->GetXaxis()->SetBinLabel(1, "no SPD");
640       hSPDclsAllTracks->GetXaxis()->SetBinLabel(2, "kOnlyFirst");
641       hSPDclsAllTracks->GetXaxis()->SetBinLabel(3, "kOnlySecond");
642       hSPDclsAllTracks->GetXaxis()->SetBinLabel(4, "kBoth");
643
644
645       fOutputTrack->Add(hPtDaughters);
646       fOutputTrack->Add(hPhiDaughters);
647       fOutputTrack->Add(hEtaDaughters);
648       fOutputTrack->Add(hEtavsPhiDaughters);
649       fOutputTrack->Add(hNTPCclsvsPtDaughters);
650       fOutputTrack->Add(hNTPCclsvsPhiDaughters);
651       fOutputTrack->Add(hNTPCclsvsEtaDaughters);
652       fOutputTrack->Add(hNTPCCrossedRowsvsPtDaughters);
653       fOutputTrack->Add(hNTPCCrossedRowsvsPhiDaughters);
654       fOutputTrack->Add(hNTPCCrossedRowsvsEtaDaughters);
655       fOutputTrack->Add(hRatioCRowsOverFclsvsPtDaughters);
656       fOutputTrack->Add(hRatioCRowsOverFclsvsPhiDaughters);
657       fOutputTrack->Add(hRatioCRowsOverFclsvsEtaDaughters);
658       fOutputTrack->Add(hNITSclsvsPtDaughters);
659       fOutputTrack->Add(hNITSclsvsPhiDaughters);
660       fOutputTrack->Add(hNITSclsvsEtaDaughters);
661       fOutputTrack->Add(hSPDclsDaughters);
662       fOutputTrack->Add(hPtAllTracks);
663       fOutputTrack->Add(hPhiAllTracks);
664       fOutputTrack->Add(hEtaAllTracks);
665       fOutputTrack->Add(hEtavsPhiAllTracks);
666       fOutputTrack->Add(hNTPCclsvsPtAllTracks);
667       fOutputTrack->Add(hNTPCclsvsPhiAllTracks);
668       fOutputTrack->Add(hNTPCclsvsEtaAllTracks);
669       fOutputTrack->Add(hNTPCCrossedRowsvsPtAllTracks);
670       fOutputTrack->Add(hNTPCCrossedRowsvsPhiAllTracks);
671       fOutputTrack->Add(hNTPCCrossedRowsvsEtaAllTracks);
672       fOutputTrack->Add(hRatioCRowsOverFclsvsPtAllTracks);
673       fOutputTrack->Add(hRatioCRowsOverFclsvsPhiAllTracks);
674       fOutputTrack->Add(hRatioCRowsOverFclsvsEtaAllTracks);
675       fOutputTrack->Add(hNITSclsvsPtAllTracks);
676       fOutputTrack->Add(hNITSclsvsPhiAllTracks);
677       fOutputTrack->Add(hNITSclsvsEtaAllTracks);
678       fOutputTrack->Add(hSPDclsAllTracks);
679
680     }
681     
682     fOutputTrack->Add(hnClsITS);
683     fOutputTrack->Add(hnClsITSselTr);
684     fOutputTrack->Add(hnClsITSSA);
685     fOutputTrack->Add(hnLayerITS);
686     fOutputTrack->Add(hnLayerITSsa);
687     fOutputTrack->Add(hnClsSPD);
688     fOutputTrack->Add(hptGoodTr);
689     fOutputTrack->Add(hdistrGoodTr);
690     fOutputTrack->Add(hdistrSelTr);
691     fOutputTrack->Add(hd0TracksSPDin);
692     fOutputTrack->Add(hd0TracksSPDany);
693     fOutputTrack->Add(hd0TracksFilterBit4);
694     fOutputTrack->Add(hd0TracksTPCITSSPDany);
695     fOutputTrack->Add(hd0dau);
696     fOutputTrack->Add(hd0zdau);
697     
698
699     if(fReadMC){
700       hname="hdistrFakeTr";
701       TH1F* hdistrFakeTr=new TH1F(hname.Data(),"Distribution of number of fake tracks per event;no.fake-tracks/ev;Entries",4000,-0.5,3999.5);
702       hdistrFakeTr->SetTitleOffset(1.3,"Y");
703
704       hname="hd0f";
705       TH1F* hd0f=new TH1F(hname.Data(),"Impact parameter distribution of fake tracks;d_{0}[cm];Entries/10^{3} cm",200,-0.1,0.1);
706
707       hname="hptFakeTr";
708       TH1F* hptFakeTr=new TH1F(hname.Data(),"Pt distribution of fake tracks;p_{t}[GeV];Entries/0.05 GeV/c",400,0.,20.);
709       hptFakeTr->SetTitleOffset(1.3,"Y");
710       if(!fSimpleMode){
711         hname="hptFakeTrFromDaugh";
712         TH1F* hptFakeTrFromDaugh=new TH1F(hname.Data(),"Pt distribution of fake tracks from daughters;p_{t}[GeV];Entries/0.05 GeV/c",400,0.,20.);
713         hptFakeTrFromDaugh->SetTitleOffset(1.3,"Y");
714         fOutputTrack->Add(hptFakeTrFromDaugh);
715       }
716
717       fOutputTrack->Add(hptFakeTr);
718       fOutputTrack->Add(hdistrFakeTr);
719       fOutputTrack->Add(hd0f);
720    
721     }
722   }
723
724   
725   if(fOnOff[2] && fCuts->GetUseCentrality()){
726
727     //Centrality (Counters)
728     fOutputCounters=new TList();
729     fOutputCounters->SetOwner();
730     fOutputCounters->SetName(GetOutputSlot(5)->GetContainer()->GetName());
731
732     AliCounterCollection *stdEstimator=new AliCounterCollection("stdEstimator");
733     stdEstimator->AddRubric("run",500000);
734     stdEstimator->AddRubric("centralityclass","-10_0/0_10/10_20/20_30/30_40/40_50/50_60/60_70/70_80/80_90/90_100/-990_-980");
735     stdEstimator->Init();
736     AliCounterCollection *secondEstimator=new AliCounterCollection("secondEstimator");
737     secondEstimator->AddRubric("run",500000);
738     secondEstimator->AddRubric("centralityclass","-10_0/0_10/10_20/20_30/30_40/40_50/50_60/60_70/70_80/80_90/90_100/-990_-980");
739     secondEstimator->Init();
740  
741     fOutputCounters->Add(stdEstimator);
742     fOutputCounters->Add(secondEstimator);
743  
744     //Centrality (Checks)
745     fOutputCheckCentrality=new TList();
746     fOutputCheckCentrality->SetOwner();
747     fOutputCheckCentrality->SetName(GetOutputSlot(6)->GetContainer()->GetName());
748
749     TString hname="hNtrackletsIn";
750     TH1F* hNtrackletsIn=new TH1F(hname.Data(),"Number of tracklets in Centrality range;ntracklets;Entries",5000,-0.5,4999.5);
751
752     hname="hMultIn";
753     TH1F* hMultIn=new TH1F(hname.Data(),"Multiplicity;multiplicity in Centrality range;Entries",10000,-0.5,9999.5);
754
755     hname="hNtrackletsOut";
756     TH1F* hNtrackletsOut=new TH1F(hname.Data(),"Number of tracklets out of Centrality range;ntracklets;Entries",5000,-0.5,4999.5);
757
758     hname="hMultOut";
759     TH1F* hMultOut=new TH1F(hname.Data(),"Multiplicity out of Centrality range;multiplicity;Entries",10000,-0.5,9999.5);
760
761     hname="hMultvsPercentile";
762     TH2F* hMultvsPercentile=new TH2F(hname.Data(),"Multiplicity vs Percentile;multiplicity;percentile",10000,-0.5,9999.5,240,-10.,110);
763
764     hname="hntrklvsPercentile";
765     TH2F* hntrklvsPercentile=new TH2F(hname.Data(),"N tracklets vs Percentile;ntracklets;percentile",5000,-0.5,4999.5,240,-10.,110);
766
767     hname="hnTPCTracksvsPercentile";
768     TH2F* hnTPCTracksvsPercentile=new TH2F(hname.Data(),"N TPC tracks vs Percentile;nTPCTracks;percentile",5000,-0.5,9999.5,240,-10.,110);
769
770     hname="hnTPCITSTracksvsPercentile";
771     TH2F* hnTPCITSTracksvsPercentile=new TH2F(hname.Data(),"N TPC+ITS tracks vs Percentile;nTPCITSTracks;percentile",5000,-0.5,9999.5,240,-10.,110);
772
773     hname="hnTPCITS1SPDTracksvsPercentile";
774     TH2F* hnTPCITS1SPDTracksvsPercentile=new TH2F(hname.Data(),"N TPC+ITS+1SPD tracks vs Percentile;nTPCITS1SPDTracks;percentile",5000,-0.5,9999.5,240,-10.,110);
775
776     hname="hV0MultiplicityPercentile";
777     TH2F*hV0MultiplicityPercentile = new TH2F(hname.Data(),"V0 Multiplicity vs Percentile;V0 multiplicity;percentile",1000,-0.5,9999.5,120,-10.,110);
778
779     hname="hV0MultiplicityNtrackletsIn";
780     TH2F*hV0MultiplicityNtrackletsIn = new TH2F(hname.Data(),"V0 Multiplicity vs Number of tracklets in the CC;V0 multiplicity;percentile",1000,-0.5,9999.5,5000,-0.5,4999.5);
781
782     hname="hStdPercentileSPDPercentile";
783     TH2F* hStdPercentileSPDPercentile = new TH2F(hname.Data(),"Std estimator Percentile Vs SPD Percentile;Std estimator percentile;SPD percentile",120,-10.,110,120,-10.,110);
784
785     fOutputCheckCentrality->Add(hNtrackletsIn);
786     fOutputCheckCentrality->Add(hNtrackletsOut);
787     fOutputCheckCentrality->Add(hMultIn);
788     fOutputCheckCentrality->Add(hMultOut);
789     fOutputCheckCentrality->Add(hMultvsPercentile);
790     fOutputCheckCentrality->Add(hntrklvsPercentile);
791     fOutputCheckCentrality->Add(hnTPCTracksvsPercentile);
792     fOutputCheckCentrality->Add(hnTPCITSTracksvsPercentile);
793     fOutputCheckCentrality->Add(hnTPCITS1SPDTracksvsPercentile);
794     fOutputCheckCentrality->Add(hV0MultiplicityPercentile);
795     fOutputCheckCentrality->Add(hV0MultiplicityNtrackletsIn);
796     fOutputCheckCentrality->Add(hStdPercentileSPDPercentile);
797
798     PostData(6,fOutputCheckCentrality);
799   
800   } else{
801     if(fOnOff[0]){
802       TString hname="hNtracklets";
803       TH1F* hNtracklets=new TH1F(hname.Data(),"Number of tracklets;ntracklets;Entries",5000,-0.5,4999.5);
804
805       hname="hMult";
806       TH1F* hMult=new TH1F(hname.Data(),"Multiplicity;multiplicity;Entries",10000,-0.5,9999.5);
807       fOutputTrack->Add(hNtracklets);
808       fOutputTrack->Add(hMult);
809     }
810   }
811
812   //event selection (z vertex for the moment)
813   if(fOnOff[3]){
814     fOutputEvSelection=new TList();
815     fOutputEvSelection->SetOwner();
816     fOutputEvSelection->SetName(GetOutputSlot(7)->GetContainer()->GetName());
817     AliCounterCollection *evselection=new AliCounterCollection("evselection");
818     evselection->AddRubric("run",500000);
819     evselection->AddRubric("evnonsel","zvtx");
820     evselection->Init();
821
822     TH1F* hxvtx=new TH1F("hxvtx", "Distribution of x_{VTX};x_{VTX} [cm];Entries",800,-1,1);
823     TH1F* hyvtx=new TH1F("hyvtx", "Distribution of y_{VTX};y_{VTX} [cm];Entries",800,-1,1);
824     TH1F* hzvtx=new TH1F("hzvtx", "Distribution of z_{VTX};z_{VTX} [cm];Entries",800,-30,30);
825     TH1F* hxvtxSelEv=new TH1F("hxvtxSelEv", "Distribution of x_{VTX} Selected Ev;x_{VTX} [cm];Entries",800,-1,1);
826     TH1F* hyvtxSelEv=new TH1F("hyvtxSelEv", "Distribution of y_{VTX} Selected Ev;y_{VTX} [cm];Entries",800,-1,1);
827     TH1F* hzvtxSelEv=new TH1F("hzvtxSelEv", "Distribution of z_{VTX} Selected Ev;z_{VTX} [cm];Entries",800,-30,30);
828     TH1F* hWhichVert=new TH1F("hWhichVert","Vertex Type",4,-1.5,2.5);
829     hWhichVert->GetXaxis()->SetBinLabel(1,"Not found");
830     hWhichVert->GetXaxis()->SetBinLabel(2,"Track");
831     hWhichVert->GetXaxis()->SetBinLabel(3,"SPD-3D");
832     hWhichVert->GetXaxis()->SetBinLabel(4,"SPD-z");
833     TH1F* hWhichVertSelEv=new TH1F("hWhichVertSelEv","Vertex Type",4,-1.5,2.5);
834     hWhichVertSelEv->GetXaxis()->SetBinLabel(1,"Not found");
835     hWhichVertSelEv->GetXaxis()->SetBinLabel(2,"Track");
836     hWhichVertSelEv->GetXaxis()->SetBinLabel(3,"SPD-3D");
837     hWhichVertSelEv->GetXaxis()->SetBinLabel(4,"SPD-z");
838
839     TH2F* hTrigCent=new TH2F("hTrigCent","Centrality vs. Trigger types",14,-1.5,12.5,12,-10,110);
840     hTrigCent->GetXaxis()->SetBinLabel(1,"All");
841     hTrigCent->GetXaxis()->SetBinLabel(2,"kAny");
842     hTrigCent->GetXaxis()->SetBinLabel(3,"kMB");
843     hTrigCent->GetXaxis()->SetBinLabel(4,"kINT7");
844     hTrigCent->GetXaxis()->SetBinLabel(5,"kCINT5");
845     hTrigCent->GetXaxis()->SetBinLabel(6,"kCent");
846     hTrigCent->GetXaxis()->SetBinLabel(7,"kSemiCent");
847     hTrigCent->GetXaxis()->SetBinLabel(8,"kEMC1+7");
848     hTrigCent->GetXaxis()->SetBinLabel(9,"kEMCJET+GAMMA");
849     hTrigCent->GetXaxis()->SetBinLabel(10,"Muons");
850     hTrigCent->GetXaxis()->SetBinLabel(11,"PHOS");
851     hTrigCent->GetXaxis()->SetBinLabel(12,"TRD");
852     hTrigCent->GetXaxis()->SetBinLabel(13,"HighMult");
853     hTrigCent->GetXaxis()->SetBinLabel(14,"Others");
854
855     TH2F* hTrigMul=new TH2F("hTrigMul","Multiplicity vs. Trigger types",14,-1.5,12.5,100,0.,10000.);
856     hTrigMul->GetXaxis()->SetBinLabel(1,"All");
857     hTrigMul->GetXaxis()->SetBinLabel(2,"kAny");
858     hTrigMul->GetXaxis()->SetBinLabel(3,"kMB");
859     hTrigMul->GetXaxis()->SetBinLabel(4,"kINT7");
860     hTrigMul->GetXaxis()->SetBinLabel(5,"kCINT5");
861     hTrigMul->GetXaxis()->SetBinLabel(6,"kCent");
862     hTrigMul->GetXaxis()->SetBinLabel(7,"kSemiCent");
863     hTrigMul->GetXaxis()->SetBinLabel(8,"kEMC1+7");
864     hTrigMul->GetXaxis()->SetBinLabel(9,"kEMCJET+GAMMA");
865     hTrigMul->GetXaxis()->SetBinLabel(10,"Muons");
866     hTrigMul->GetXaxis()->SetBinLabel(11,"PHOS");
867     hTrigMul->GetXaxis()->SetBinLabel(12,"TRD");
868     hTrigMul->GetXaxis()->SetBinLabel(13,"HighMult");
869     hTrigMul->GetXaxis()->SetBinLabel(14,"Others");
870
871     TH2F* hTrigCentSel=new TH2F("hTrigCentSel","Trigger types",14,-1.5,12.5,12,-10,110);
872     hTrigCentSel->GetXaxis()->SetBinLabel(1,"All");
873     hTrigCentSel->GetXaxis()->SetBinLabel(2,"kAny");
874     hTrigCentSel->GetXaxis()->SetBinLabel(3,"kMB");
875     hTrigCentSel->GetXaxis()->SetBinLabel(4,"kINT7");
876     hTrigCentSel->GetXaxis()->SetBinLabel(5,"kCINT5");
877     hTrigCentSel->GetXaxis()->SetBinLabel(6,"kCent");
878     hTrigCentSel->GetXaxis()->SetBinLabel(7,"kSemiCent");
879     hTrigCentSel->GetXaxis()->SetBinLabel(8,"kEMC1+7");
880     hTrigCentSel->GetXaxis()->SetBinLabel(9,"kEMCJET+GAMMA");
881     hTrigCentSel->GetXaxis()->SetBinLabel(10,"Muons");
882     hTrigCentSel->GetXaxis()->SetBinLabel(11,"PHOS");
883     hTrigCentSel->GetXaxis()->SetBinLabel(12,"TRD");
884     hTrigCentSel->GetXaxis()->SetBinLabel(13,"HighMult");
885     hTrigCentSel->GetXaxis()->SetBinLabel(14,"Others");
886
887     AliCounterCollection *trigCounter=new AliCounterCollection("trigCounter");
888     trigCounter->AddRubric("run",500000);
889     trigCounter->AddRubric("triggerType","All/Any/MB/Cent/SemiCent/EMCAL/MUON/NoPhysSelMUON/NoPhysSelEvNot7/NoPhysSelCMUP1/NoPhysSelMB/NoPhysSelCent/NoPhysSelSemiCent/CINT7");
890     trigCounter->Init();
891
892     TH1F* hWhyEvRejected=new TH1F("hWhyEvRejected", "Why Event rejected",7,-1.5,5.5);
893
894     hWhyEvRejected->GetXaxis()->SetBinLabel(1,"N events");
895     hWhyEvRejected->GetXaxis()->SetBinLabel(2,"pileup");
896     hWhyEvRejected->GetXaxis()->SetBinLabel(3,"centrality");
897     hWhyEvRejected->GetXaxis()->SetBinLabel(4,"Vertex not found");
898     hWhyEvRejected->GetXaxis()->SetBinLabel(5,"trigger");
899     hWhyEvRejected->GetXaxis()->SetBinLabel(6,"z vertex out of 10 cm");
900     hWhyEvRejected->GetXaxis()->SetBinLabel(7,"physics sel");
901
902
903     fOutputEvSelection->Add(evselection);
904     fOutputEvSelection->Add(hxvtx);
905     fOutputEvSelection->Add(hyvtx);
906     fOutputEvSelection->Add(hzvtx);
907     fOutputEvSelection->Add(hxvtxSelEv);
908     fOutputEvSelection->Add(hyvtxSelEv);
909     fOutputEvSelection->Add(hzvtxSelEv);
910     fOutputEvSelection->Add(hWhichVert);
911     fOutputEvSelection->Add(hWhichVertSelEv);
912     fOutputEvSelection->Add(hTrigCent);
913     fOutputEvSelection->Add(hTrigMul);
914     fOutputEvSelection->Add(hTrigCentSel);
915     fOutputEvSelection->Add(trigCounter);
916     fOutputEvSelection->Add(hWhyEvRejected);
917
918   }
919   if(fOnOff[4]){ // FLOW OBSERVABLES
920     fOutputFlowObs=new TList();
921     fOutputFlowObs->SetOwner();
922     fOutputFlowObs->SetName(GetOutputSlot(8)->GetContainer()->GetName());
923
924     fFlowEvent = new AliFlowEvent(3000);
925     fRFPcuts = new AliFlowTrackCuts("rfpCuts");
926
927     TH2F *hFEvents = new TH2F("hFlowEvents","FlowEvent Selection",7,0,7,7,-10,60);
928     hFEvents->GetXaxis()->SetBinLabel(1,"REACHED");
929     hFEvents->GetXaxis()->SetBinLabel(2,"TRIGGERED");
930     hFEvents->GetXaxis()->SetBinLabel(3,"kMB");
931     hFEvents->GetXaxis()->SetBinLabel(4,"kCent");
932     hFEvents->GetXaxis()->SetBinLabel(5,"kSemiC");
933     hFEvents->GetXaxis()->SetBinLabel(6,"Triggered + vtx cut");
934     hFEvents->GetXaxis()->SetBinLabel(7,"UnexpectedBehaviour");
935     fOutputFlowObs->Add(hFEvents);
936
937     TProfile2D *hQ[3];
938     TH2F *hAngleQ[3];
939     TH3F *hPhiEta[3];
940     TString ref[3] = {"FB1","FB128","VZE"};
941     Int_t etabin[3] = {40,40,20};
942     Int_t etamax[3] = { 1, 1, 5};
943     for(Int_t i=0; i<3; ++i) {
944       hQ[i]= new TProfile2D( Form("h%s_Q",ref[i].Data()),
945                              Form("Q_{2} components for %s",ref[i].Data()),
946                              4,0,4,12,0,60,"s");
947       hQ[i]->GetXaxis()->SetBinLabel(1,"Qx^{-}");
948       hQ[i]->GetXaxis()->SetBinLabel(2,"Qy^{-}");
949       hQ[i]->GetXaxis()->SetBinLabel(3,"Qx^{+}");
950       hQ[i]->GetXaxis()->SetBinLabel(4,"Qy^{+}");
951       hQ[i]->GetYaxis()->SetTitle("Centrality");
952       fOutputFlowObs->Add(hQ[i]);
953
954       hAngleQ[i] = new TH2F( Form("h%s_AngleQ",ref[i].Data()),
955                              Form("#Psi_{2} for %s",ref[i].Data()),
956                              72,0,TMath::Pi(),12,0,60);
957       hAngleQ[i]->GetXaxis()->SetTitle( Form("#Psi_{2}^{%s}",ref[i].Data()) );
958       hAngleQ[i]->GetYaxis()->SetTitle("Centrality");
959       fOutputFlowObs->Add(hAngleQ[i]);
960
961       hPhiEta[i] = new TH3F( Form("h%s_PhiEta",ref[i].Data()),
962                              Form("Eta vs Phi for %s",ref[i].Data()),
963                              144,0,TMath::TwoPi(),etabin[i],-1.0*etamax[i],+1.0*etamax[i],12,0,60);
964       hPhiEta[i]->GetXaxis()->SetTitle("Phi");
965       hPhiEta[i]->GetYaxis()->SetTitle("Eta");
966       hPhiEta[i]->GetZaxis()->SetTitle("Centrality");
967       fOutputFlowObs->Add(hPhiEta[i]);
968
969     }
970     TH3F *hTPCVZE_AngleQ = new TH3F("hTPCVZE_AngleQ","#Psi_{2}^{VZERO} vs #Psi_{2}^{TPC}",   72,0,TMath::Pi(),72,0,TMath::Pi(),12,0,60);
971     hTPCVZE_AngleQ->GetXaxis()->SetTitle("#Psi_{2}^{TPC}");
972     hTPCVZE_AngleQ->GetYaxis()->SetTitle("#Psi_{2}^{VZE}");
973     hTPCVZE_AngleQ->GetZaxis()->SetTitle("Centrality");
974     fOutputFlowObs->Add(hTPCVZE_AngleQ);
975
976     TH2F *hCentVsMultRPS = new TH2F("hCentVsMultRPS", " Centrality Vs. Multiplicity RPs",5000, 0, 5000.,12,0,60 );
977     hCentVsMultRPS->GetXaxis()->SetTitle("Multiplicity RPs");
978     hCentVsMultRPS->GetYaxis()->SetTitle("Centrality");
979     fOutputFlowObs->Add(hCentVsMultRPS);
980   }
981
982   /*
983   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
984   AliInputEventHandler *inputHandler=(AliInputEventHandler*)mgr->GetInputEventHandler();
985   AliPIDResponse *pidResp=inputHandler->GetPIDResponse();
986   if (fCuts->GetIsUsePID() && fDecayChannel==kLambdactoV0) {
987     fCuts->GetPidHF()->SetPidResponse(pidResp);
988     AliRDHFCutsLctoV0* lccuts=dynamic_cast<AliRDHFCutsLctoV0*>(fCuts);
989     if(lccuts){
990       lccuts->GetPidV0pos()->SetPidResponse(pidResp);
991       lccuts->GetPidV0neg()->SetPidResponse(pidResp);
992       fCuts->GetPidHF()->SetOldPid(kFALSE);
993       lccuts->GetPidV0pos()->SetOldPid(kFALSE);
994       lccuts->GetPidV0neg()->SetOldPid(kFALSE);
995     }
996   }
997   */
998
999   // Post the data
1000   PostData(1,fNEntries);
1001
1002   if(fOnOff[1]) PostData(2,fOutputPID);
1003   if(fOnOff[0]) PostData(3,fOutputTrack);
1004   PostData(4,fCuts);
1005   if(fOnOff[2]) PostData(5,fOutputCounters);
1006   if(fOnOff[3]) PostData(7,fOutputEvSelection);
1007   if(fOnOff[4]) PostData(8,fOutputFlowObs);
1008
1009   if(!fOnOff[0] && !fOnOff[1] && !fOnOff[2]) AliError("Nothing will be filled!");
1010 }
1011
1012 //___________________________________________________________________________
1013 void AliAnalysisTaskSEHFQA::UserExec(Option_t */*option*/)
1014 {
1015   // Execute analysis for current event
1016
1017   AliAODEvent *aod = dynamic_cast<AliAODEvent*> (InputEvent());
1018   if(fDebug>2) printf("Analysing decay %d\n",fDecayChannel);
1019   // Post the data already here
1020   PostData(1,fNEntries);
1021   if(fOnOff[1]) PostData(2,fOutputPID);
1022   if(fOnOff[0]) PostData(3,fOutputTrack);
1023   PostData(4,fCuts);
1024   if(fOnOff[2]) {
1025     PostData(5,fOutputCounters);
1026     if(fCuts->GetUseCentrality()) PostData(6,fOutputCheckCentrality);
1027   }
1028
1029   TClonesArray *arrayProng =0;
1030   Int_t pdg=0;
1031   Int_t *pdgdaughters=0x0;
1032
1033   if(!aod && AODEvent() && IsStandardAOD()) { 
1034     // In case there is an AOD handler writing a standard AOD, use the AOD 
1035     // event in memory rather than the input (ESD) event.    
1036     aod = dynamic_cast<AliAODEvent*> (AODEvent());
1037     // in this case the braches in the deltaAOD (AliAOD.VertexingHF.root)
1038     // have to taken from the AOD event hold by the AliAODExtension
1039     AliAODHandler* aodHandler = (AliAODHandler*) 
1040       ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
1041     if(aodHandler->GetExtensions()) {
1042       
1043       AliAODExtension *ext = (AliAODExtension*)aodHandler->GetExtensions()->FindObject("AliAOD.VertexingHF.root");
1044       AliAODEvent *aodFromExt = ext->GetAOD();
1045    
1046    
1047       
1048       switch(fDecayChannel){
1049       case 0:
1050         arrayProng=(TClonesArray*)aodFromExt->GetList()->FindObject("Charm3Prong");
1051         pdg=411;
1052         if(fReadMC){
1053           pdgdaughters =new Int_t[3];
1054           pdgdaughters[0]=211;//pi
1055           pdgdaughters[1]=321;//K
1056           pdgdaughters[2]=211;//pi
1057         }
1058         break; 
1059       case 1:
1060         arrayProng=(TClonesArray*)aodFromExt->GetList()->FindObject("D0toKpi");
1061         pdg=421;
1062         if(fReadMC){
1063           pdgdaughters =new Int_t[2];
1064           pdgdaughters[0]=211;//pi 
1065           pdgdaughters[1]=321;//K
1066         }
1067         break; 
1068       case 2:
1069         arrayProng=(TClonesArray*)aodFromExt->GetList()->FindObject("Dstar");
1070         pdg=413;
1071         if(fReadMC){
1072           pdgdaughters =new Int_t[3];
1073           pdgdaughters[1]=211;//pi
1074           pdgdaughters[0]=321;//K
1075           pdgdaughters[2]=211;//pi (soft?)
1076         }
1077         break; 
1078       case 3:
1079         arrayProng=(TClonesArray*)aodFromExt->GetList()->FindObject("Charm3Prong");
1080         pdg=431;
1081         if(fReadMC){
1082           pdgdaughters =new Int_t[3];
1083           pdgdaughters[0]=321;//K
1084           pdgdaughters[1]=321;//K
1085           pdgdaughters[2]=211;//pi
1086         }
1087         break; 
1088       case 4:
1089         arrayProng=(TClonesArray*)aodFromExt->GetList()->FindObject("Charm4Prong");
1090         pdg=421;
1091         if(fReadMC){
1092           pdgdaughters =new Int_t[4];
1093           pdgdaughters[0]=321;
1094           pdgdaughters[1]=211;
1095           pdgdaughters[2]=211;
1096           pdgdaughters[3]=211;
1097         }
1098         break; 
1099       case 5:
1100         arrayProng=(TClonesArray*)aodFromExt->GetList()->FindObject("Charm3Prong");
1101         pdg=4122;
1102         if(fReadMC){
1103           pdgdaughters =new Int_t[3];
1104           pdgdaughters[0]=2212;//p
1105           pdgdaughters[1]=321;//K
1106           pdgdaughters[2]=211;//pi
1107         }
1108         break; 
1109       case kLambdactoV0:
1110         arrayProng=(TClonesArray*)aodFromExt->GetList()->FindObject("CascadesHF");
1111         pdg=4122;
1112         if(fReadMC){
1113           pdgdaughters =new Int_t[3];
1114           pdgdaughters[0]=2212;//p
1115           pdgdaughters[1]=211;//pi
1116           pdgdaughters[2]=211;//pi
1117         }
1118         break; 
1119       }
1120     }
1121   } else if(aod) {
1122     switch(fDecayChannel){
1123     case 0:
1124       arrayProng=(TClonesArray*)aod->GetList()->FindObject("Charm3Prong");
1125       pdg=411;
1126       if(fReadMC){
1127         pdgdaughters =new Int_t[3];
1128         pdgdaughters[0]=211;//pi
1129         pdgdaughters[1]=321;//K
1130         pdgdaughters[2]=211;//pi
1131       }
1132       break; 
1133     case 1:
1134       arrayProng=(TClonesArray*)aod->GetList()->FindObject("D0toKpi");
1135       pdg=421;
1136       if(fReadMC){
1137         pdgdaughters =new Int_t[2];
1138         pdgdaughters[0]=211;//pi 
1139         pdgdaughters[1]=321;//K
1140       }
1141       break; 
1142     case 2:
1143       arrayProng=(TClonesArray*)aod->GetList()->FindObject("Dstar");
1144       pdg=413;
1145       if(fReadMC){
1146         pdgdaughters =new Int_t[3];
1147         pdgdaughters[1]=211;//pi
1148         pdgdaughters[0]=321;//K
1149         pdgdaughters[2]=211;//pi (soft?)
1150       }
1151       break; 
1152     case 3:
1153       arrayProng=(TClonesArray*)aod->GetList()->FindObject("Charm3Prong");
1154       pdg=431;
1155       if(fReadMC){
1156         pdgdaughters =new Int_t[3];
1157         pdgdaughters[0]=321;//K
1158         pdgdaughters[1]=321;//K
1159         pdgdaughters[2]=211;//pi
1160       }
1161       break; 
1162     case 4:
1163       arrayProng=(TClonesArray*)aod->GetList()->FindObject("Charm4Prong");
1164       pdg=421;
1165       if(fReadMC){
1166         pdgdaughters =new Int_t[4];
1167         pdgdaughters[0]=321;
1168         pdgdaughters[1]=211;
1169         pdgdaughters[2]=211;
1170         pdgdaughters[3]=211;
1171       }
1172       break; 
1173     case 5:
1174       arrayProng=(TClonesArray*)aod->GetList()->FindObject("Charm3Prong");
1175       pdg=4122;
1176       if(fReadMC){
1177         pdgdaughters =new Int_t[3];
1178         pdgdaughters[0]=2212;//p
1179         pdgdaughters[1]=321;//K
1180         pdgdaughters[2]=211;//pi
1181       }
1182       break; 
1183       case kLambdactoV0:
1184         arrayProng=(TClonesArray*)aod->GetList()->FindObject("CascadesHF");
1185         pdg=4122;
1186         if(fReadMC){
1187           pdgdaughters =new Int_t[3];
1188           pdgdaughters[0]=2212;//p
1189           pdgdaughters[1]=211;//pi
1190           pdgdaughters[2]=211;//pi
1191         }
1192         break; 
1193     }
1194   }
1195   Bool_t isSimpleMode=fSimpleMode;
1196   if(!arrayProng) {
1197     AliInfo("Branch not found! The output will contain only track related histograms\n");
1198     isSimpleMode=kTRUE;
1199     fNEntries->Fill(2);
1200   }
1201   
1202   TClonesArray *mcArray = 0;
1203   AliAODMCHeader *mcHeader = 0;
1204
1205   if(!aod) {
1206     delete [] pdgdaughters;
1207     return;
1208   }
1209
1210   //check if MC
1211   if(fReadMC) {
1212     // load MC particles
1213     mcArray = (TClonesArray*)aod->GetList()->FindObject(AliAODMCParticle::StdBranchName());
1214     if(!mcArray) {
1215       printf("AliAnalysisTaskSEHFQA::UserExec: MC particles branch not found!\n");
1216       delete [] pdgdaughters;
1217       return;
1218     }
1219     
1220     // load MC header
1221     mcHeader = (AliAODMCHeader*)aod->GetList()->FindObject(AliAODMCHeader::StdBranchName());
1222     if(!mcHeader) {
1223       printf("AliAnalysisTaskSEHFQA::UserExec: MC header branch not found!\n");
1224       delete [] pdgdaughters;
1225       return;
1226     }
1227   }
1228
1229   
1230   UInt_t evSelMask=((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected();
1231   Double_t centrality=fCuts->GetCentrality(aod);
1232   Double_t multiplicity=aod->GetHeader()->GetRefMultiplicity();
1233   Int_t runNumber = aod->GetRunNumber();
1234   TString trigClass=aod->GetFiredTriggerClasses();
1235   Int_t nAODtracks=aod->GetNTracks();
1236   Int_t nSelTracksTPCOnly=0;
1237   Int_t nSelTracksTPCITS=0;
1238   Int_t nSelTracksTPCITS1SPD=0;
1239
1240   if(fReadMC) {
1241     if(aod->GetTriggerMask()==0 && 
1242        (runNumber>=195344 && runNumber<=195677)){
1243       AliDebug(3,"Event rejected because of null trigger mask");
1244       delete [] pdgdaughters;
1245       return;
1246     }
1247   }
1248
1249   for (Int_t k=0;k<nAODtracks;k++){
1250     AliAODTrack* track=aod->GetTrack(k);
1251     if(track->GetID()<0) continue;
1252     Int_t nclsTot=0,nclsSPD=0;
1253     for(Int_t l=0;l<6;l++) {
1254       if(TESTBIT(track->GetITSClusterMap(),l)) {
1255         nclsTot++; if(l<2) nclsSPD++;
1256       }
1257     }
1258     UShort_t nTPCClus=track->GetTPCClusterMap().CountBits();
1259     if(TMath::Abs(track->Eta())<0.8 && nTPCClus>=70 && track->GetStatus()&AliESDtrack::kTPCrefit){
1260       if(track->TestFilterBit(1))  nSelTracksTPCOnly++;
1261       if(track->GetStatus()&AliESDtrack::kITSrefit){
1262         nSelTracksTPCITS++;
1263         if(nclsSPD>0) nSelTracksTPCITS1SPD++;      
1264       }
1265     }
1266   }
1267
1268   if(fOnOff[4]) {
1269     FillFlowObs(aod);
1270     PostData(8,fOutputFlowObs);
1271   }
1272   if(fOnOff[3]){
1273     TH2F* hTrigC=(TH2F*)fOutputEvSelection->FindObject("hTrigCent");
1274     TH2F* hTrigM=(TH2F*)fOutputEvSelection->FindObject("hTrigMul");
1275     AliCounterCollection* trigCount=(AliCounterCollection*)fOutputEvSelection->FindObject("trigCounter");
1276
1277     hTrigC->Fill(-1.,centrality);
1278     hTrigM->Fill(-1.,multiplicity);
1279     trigCount->Count(Form("triggerType:All/Run:%d",runNumber));
1280     if(evSelMask==0){
1281       if(aod->GetEventType()!=7){
1282         trigCount->Count(Form("triggerType:NoPhysSelEvNot7/Run:%d",runNumber));
1283       }else if(trigClass.Contains("CMUP1")){
1284         trigCount->Count(Form("triggerType:NoPhysSelCMUP1/Run:%d",runNumber));
1285       }else if(trigClass.Contains("MUON")){
1286         trigCount->Count(Form("triggerType:NoPhysSelMUON/Run:%d",runNumber));
1287       }else if(trigClass.Contains("CPBI2_B1-B") || trigClass.Contains(" CPBI2WU_B1-B")){
1288         trigCount->Count(Form("triggerType:NoPhysSelMB/Run:%d",runNumber));
1289       }else if(trigClass.Contains("CCENT") || trigClass.Contains("CVHN")){
1290         trigCount->Count(Form("triggerType:NoPhysSelCent/Run:%d",runNumber));
1291       }else if(trigClass.Contains("CSEMI") || trigClass.Contains("CVLN")){
1292         trigCount->Count(Form("triggerType:NoPhysSelSemiCent/Run:%d",runNumber));
1293       }
1294     }
1295     if(evSelMask & AliVEvent::kAny){
1296       hTrigC->Fill(0.,centrality);
1297       hTrigM->Fill(0.,multiplicity);
1298       trigCount->Count(Form("triggerType:Any/Run:%d",runNumber));
1299     }  
1300     if(evSelMask & AliVEvent::kMB){
1301       hTrigC->Fill(1.,centrality);
1302       hTrigM->Fill(1.,multiplicity);
1303       trigCount->Count(Form("triggerType:MB/Run:%d",runNumber));
1304     }
1305     if(evSelMask & AliVEvent::kINT7){ 
1306       hTrigC->Fill(2.,centrality);
1307       hTrigM->Fill(2.,multiplicity);
1308       trigCount->Count(Form("triggerType:CINT7/Run:%d",runNumber));
1309     }
1310     if(evSelMask & AliVEvent::kCINT5){ 
1311       hTrigC->Fill(3.,centrality);
1312       hTrigM->Fill(3.,multiplicity);
1313     }
1314     if(evSelMask & AliVEvent::kCentral){
1315       hTrigC->Fill(4.,centrality);
1316       hTrigM->Fill(4.,multiplicity);
1317       trigCount->Count(Form("triggerType:Cent/Run:%d",runNumber));
1318     }
1319     if(evSelMask & AliVEvent::kSemiCentral){ 
1320       hTrigC->Fill(5.,centrality);
1321       hTrigM->Fill(5.,multiplicity);
1322       trigCount->Count(Form("triggerType:SemiCent/Run:%d",runNumber));
1323     }
1324     if(evSelMask & (AliVEvent::kEMC1 | AliVEvent::kEMC7)){
1325       hTrigC->Fill(6.,centrality);
1326       hTrigM->Fill(6.,multiplicity);
1327     }
1328     if(evSelMask & (AliVEvent::kEMCEJE | AliVEvent::kEMCEGA)){
1329       hTrigC->Fill(7.,centrality);
1330       hTrigM->Fill(7.,multiplicity);
1331       trigCount->Count(Form("triggerType:EMCAL/Run:%d",runNumber));
1332     }
1333     if(evSelMask & (((AliVEvent::kCMUS5 | AliVEvent::kMUSH7) | (AliVEvent::kMUL7 | AliVEvent::kMUU7)) |  (AliVEvent::kMUS7 | AliVEvent::kMUON))){
1334       hTrigC->Fill(8.,centrality);
1335       hTrigM->Fill(8.,multiplicity);
1336       trigCount->Count(Form("triggerType:MUON/Run:%d",runNumber));
1337     }
1338     if(evSelMask & (AliVEvent::kPHI1 | AliVEvent::kPHI7)){ 
1339       hTrigC->Fill(9.,centrality);
1340       hTrigM->Fill(9.,multiplicity);
1341     }
1342     if(evSelMask & (AliVEvent::kTRD)){
1343       hTrigC->Fill(10.,centrality);
1344       hTrigM->Fill(10.,multiplicity);
1345     }
1346     if(evSelMask & (AliVEvent::kHighMult)){
1347       hTrigC->Fill(11.,centrality);
1348       hTrigM->Fill(11.,multiplicity);
1349     }
1350     if(evSelMask & (AliVEvent::kDG5 | AliVEvent::kZED)){
1351       hTrigC->Fill(12.,centrality);
1352       hTrigM->Fill(12.,multiplicity);
1353     }
1354   }
1355   
1356
1357   // fix for temporary bug in ESDfilter 
1358   // the AODs with null vertex pointer didn't pass the PhysSel
1359   if(!aod->GetPrimaryVertex() || TMath::Abs(aod->GetMagneticField())<0.001) {
1360     delete [] pdgdaughters;
1361     return;
1362   }
1363
1364   // count event
1365   fNEntries->Fill(0); 
1366
1367   //count events with good vertex
1368   // AOD primary vertex
1369   AliAODVertex *vtx1 = (AliAODVertex*)aod->GetPrimaryVertex();
1370
1371   Double_t pos[3],cov[6];
1372   vtx1->GetXYZ(pos);
1373   vtx1->GetCovarianceMatrix(cov);
1374   const AliESDVertex vESD(pos,cov,100.,100);
1375
1376   TString primTitle = vtx1->GetTitle();
1377   if(primTitle.Contains("VertexerTracks") && vtx1->GetNContributors()>0) fNEntries->Fill(4);
1378
1379   // trigger class for PbPb C0SMH-B-NOPF-ALLNOTRD, C0SMH-B-NOPF-ALL
1380   //TString trigclass=aod->GetFiredTriggerClasses();
1381   //if(trigclass.Contains("C0SMH-B-NOPF-ALLNOTRD") || trigclass.Contains("C0SMH-B-NOPF-ALL")) fNEntries->Fill(5); //tmp
1382
1383
1384
1385
1386   Bool_t evSelbyCentrality=kTRUE,evSelected=kTRUE,evSelByVertex=kTRUE,evselByPileup=kTRUE,evSelByPS=kTRUE;
1387
1388   TH1F* hWhyEvRejected=0x0;
1389   if(fOnOff[3]){
1390     hWhyEvRejected=(TH1F*)fOutputEvSelection->FindObject("hWhyEvRejected");
1391      if(hWhyEvRejected) hWhyEvRejected->Fill(-1); 
1392   }
1393
1394   //select event
1395   if(!fCuts->IsEventSelected(aod)) {
1396     evSelected=kFALSE;
1397     if(fCuts->IsEventRejectedDueToPileupSPD()) {
1398       if(hWhyEvRejected) hWhyEvRejected->Fill(0); 
1399       evselByPileup=kFALSE;
1400     }// rejected for pileup
1401     if(fCuts->IsEventRejectedDueToCentrality()) {
1402       if(hWhyEvRejected) hWhyEvRejected->Fill(1); 
1403       evSelbyCentrality=kFALSE; //rejected by centrality
1404     }
1405     if(fCuts->IsEventRejectedDueToNotRecoVertex() ||
1406        fCuts->IsEventRejectedDueToVertexContributors()){ 
1407       evSelByVertex=kFALSE; 
1408       if(hWhyEvRejected) hWhyEvRejected->Fill(2);
1409     }
1410     if(fCuts->IsEventRejectedDueToTrigger()){
1411       if(hWhyEvRejected) hWhyEvRejected->Fill(3);
1412     }
1413     if(fCuts->IsEventRejectedDueToZVertexOutsideFiducialRegion()) {
1414       evSelByVertex=kFALSE; 
1415       if(fOnOff[3]) ((AliCounterCollection*)fOutputEvSelection->FindObject("evselection"))->Count(Form("evnonsel:zvtx/Run:%d",runNumber)); 
1416       if(hWhyEvRejected) hWhyEvRejected->Fill(4);
1417     }
1418     if(fCuts->IsEventRejectedDuePhysicsSelection()) { 
1419       evSelByPS=kFALSE;
1420       if(hWhyEvRejected) hWhyEvRejected->Fill(5); 
1421     }
1422   }
1423   if(evSelected && fOnOff[3]){
1424     TH2F* hTrigS=(TH2F*)fOutputEvSelection->FindObject("hTrigCentSel");
1425     hTrigS->Fill(-1.,centrality);
1426
1427     if(evSelMask & AliVEvent::kAny) hTrigS->Fill(0.,centrality);
1428     if(evSelMask & AliVEvent::kMB) hTrigS->Fill(1.,centrality);
1429     if(evSelMask & AliVEvent::kINT7) hTrigS->Fill(2.,centrality);
1430     if(evSelMask & AliVEvent::kCINT5) hTrigS->Fill(3.,centrality);
1431     if(evSelMask & AliVEvent::kCentral) hTrigS->Fill(4.,centrality);
1432     if(evSelMask & AliVEvent::kSemiCentral) hTrigS->Fill(5.,centrality);
1433     if(evSelMask & (AliVEvent::kEMC1 | AliVEvent::kEMC7)) hTrigS->Fill(6.,centrality);
1434     if(evSelMask & (AliVEvent::kEMCEJE | AliVEvent::kEMCEGA)) hTrigS->Fill(7.,centrality);
1435     if(evSelMask & (((AliVEvent::kCMUS5 | AliVEvent::kMUSH7) | (AliVEvent::kMUL7 | AliVEvent::kMUU7)) |  (AliVEvent::kMUS7 | AliVEvent::kMUON))) hTrigS->Fill(8.,centrality);
1436     if(evSelMask & (AliVEvent::kPHI1 | AliVEvent::kPHI7)) hTrigS->Fill(9.,centrality);
1437     if(evSelMask & (AliVEvent::kTRD)) hTrigS->Fill(10.,centrality);
1438     if(evSelMask & (AliVEvent::kHighMult)) hTrigS->Fill(11.,centrality);
1439     if(evSelMask & (AliVEvent::kDG5 | AliVEvent::kZED)) hTrigS->Fill(12.,centrality);
1440   }
1441   
1442   if(evSelected || (!evSelbyCentrality && evSelByVertex && evselByPileup && evSelByPS)){ //events selected or not selected because of centrality
1443     if(fOnOff[2] && fCuts->GetUseCentrality()){
1444
1445       Float_t stdCentf=fCuts->GetCentrality(aod);
1446       Int_t stdCent = (Int_t)(stdCentf+0.5);
1447       Float_t secondCentf =fCuts->GetCentrality(aod,fEstimator);
1448       Int_t secondCent = (Int_t)(secondCentf+0.5);
1449       Int_t mincent=stdCent-stdCent%10;
1450       AliAODVZERO *vzeroAOD = (AliAODVZERO*)aod->GetVZEROData();
1451       Float_t vzeroMult = vzeroAOD->GetMTotV0A() +  vzeroAOD->GetMTotV0C();
1452       AliCentrality *aodcent = aod->GetCentrality();
1453       Float_t spdCentf = aodcent->GetCentralityPercentile("CL1");
1454       if(stdCentf==-1) {
1455         mincent=-10; 
1456         stdCent=-1;
1457       }
1458       if(mincent==100)mincent--;
1459       ((AliCounterCollection*)fOutputCounters->FindObject("stdEstimator"))->Count(Form("centralityclass:%d_%d/Run:%d",mincent,mincent+10,runNumber));
1460
1461       mincent=secondCent-secondCent%10;
1462       if(secondCentf==-1) {
1463         mincent=-10;
1464         secondCent=-1;
1465       }
1466       if(mincent==100)mincent--;
1467       ((AliCounterCollection*)fOutputCounters->FindObject("secondEstimator"))->Count(Form("centralityclass:%d_%d/Run:%d",mincent,mincent+10,runNumber));
1468
1469       if(stdCent<fCuts->GetMinCentrality() || stdCent>fCuts->GetMaxCentrality()){
1470         ((TH1F*)fOutputCheckCentrality->FindObject("hNtrackletsOut"))->Fill(aod->GetTracklets()->GetNumberOfTracklets());
1471         ((TH1F*)fOutputCheckCentrality->FindObject("hMultOut"))->Fill(aod->GetHeader()->GetRefMultiplicity());
1472       }else{
1473         ((TH1F*)fOutputCheckCentrality->FindObject("hNtrackletsIn"))->Fill(aod->GetTracklets()->GetNumberOfTracklets());
1474         ((TH1F*)fOutputCheckCentrality->FindObject("hMultIn"))->Fill(aod->GetHeader()->GetRefMultiplicity());
1475       }
1476       ((TH2F*)fOutputCheckCentrality->FindObject("hMultvsPercentile"))->Fill(aod->GetHeader()->GetRefMultiplicity(),stdCentf);
1477       ((TH2F*)fOutputCheckCentrality->FindObject("hntrklvsPercentile"))->Fill(aod->GetTracklets()->GetNumberOfTracklets(),stdCentf);
1478       ((TH2F*)fOutputCheckCentrality->FindObject("hnTPCTracksvsPercentile"))->Fill(nSelTracksTPCOnly,stdCentf);
1479       ((TH2F*)fOutputCheckCentrality->FindObject("hnTPCITSTracksvsPercentile"))->Fill(nSelTracksTPCITS,stdCentf);
1480       ((TH2F*)fOutputCheckCentrality->FindObject("hnTPCITS1SPDTracksvsPercentile"))->Fill(nSelTracksTPCITS1SPD,stdCentf);
1481       ((TH2F*)fOutputCheckCentrality->FindObject("hV0MultiplicityPercentile"))->Fill(vzeroMult,stdCentf);
1482       ((TH2F*)fOutputCheckCentrality->FindObject("hV0MultiplicityNtrackletsIn"))->Fill(vzeroMult,aod->GetTracklets()->GetNumberOfTracklets());
1483       ((TH2F*)fOutputCheckCentrality->FindObject("hStdPercentileSPDPercentile"))->Fill(stdCentf,spdCentf);
1484
1485       PostData(6,fOutputCheckCentrality);
1486
1487     } else{
1488       if(fOnOff[0]){
1489         ((TH1F*)fOutputTrack->FindObject("hNtracklets"))->Fill(aod->GetTracklets()->GetNumberOfTracklets());
1490         ((TH1F*)fOutputTrack->FindObject("hMult"))->Fill(aod->GetHeader()->GetRefMultiplicity());
1491       }
1492     }
1493   }
1494
1495   if(fOnOff[3]){
1496     const AliVVertex *vertex = aod->GetPrimaryVertex();
1497     Double_t xvtx=vertex->GetX();
1498     Double_t yvtx=vertex->GetY();
1499     Double_t zvtx=vertex->GetZ();
1500     Int_t vtxTyp=0;
1501     if(vertex->GetNContributors()<=0) vtxTyp=-1;
1502     TString title=vertex->GetTitle();
1503     if(title.Contains("Z")) vtxTyp=2;
1504     if(title.Contains("3D")) vtxTyp=1;    
1505     ((TH1F*)fOutputEvSelection->FindObject("hxvtx"))->Fill(xvtx);
1506     ((TH1F*)fOutputEvSelection->FindObject("hyvtx"))->Fill(yvtx);
1507     ((TH1F*)fOutputEvSelection->FindObject("hzvtx"))->Fill(zvtx);
1508     ((TH1F*)fOutputEvSelection->FindObject("hWhichVert"))->Fill(vtxTyp);
1509     if(evSelected){
1510       ((TH1F*)fOutputEvSelection->FindObject("hxvtxSelEv"))->Fill(xvtx);
1511       ((TH1F*)fOutputEvSelection->FindObject("hyvtxSelEv"))->Fill(yvtx);
1512       ((TH1F*)fOutputEvSelection->FindObject("hzvtxSelEv"))->Fill(zvtx);
1513       ((TH1F*)fOutputEvSelection->FindObject("hWhichVertSelEv"))->Fill(vtxTyp);
1514     }
1515   }
1516
1517   if(!evSelected) {
1518     delete [] pdgdaughters;
1519     return; //discard all events not selected (vtx and/or centrality)
1520   }
1521
1522
1523   AliAODPidHF* pidHF=fCuts->GetPidHF();
1524   if(!pidHF) {
1525     delete [] pdgdaughters;
1526     return;
1527   }
1528   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1529   AliInputEventHandler *inputHandler=(AliInputEventHandler*)mgr->GetInputEventHandler();
1530   AliPIDResponse *pidResp=inputHandler->GetPIDResponse();
1531
1532   //AliPIDResponse* respF=pidHF->GetPidResponse();
1533   AliTPCPIDResponse* tpcres=new AliTPCPIDResponse();
1534   Bool_t oldPID=pidHF->GetOldPid();
1535   if(oldPID){ 
1536     Double_t alephParameters[5];
1537     pidHF->GetTPCBetheBlochParams(alephParameters);
1538     tpcres->SetBetheBlochParameters(alephParameters[0],alephParameters[1],alephParameters[2],alephParameters[3],alephParameters[4]);
1539   }
1540
1541
1542   Int_t ntracks=0;
1543   Int_t isGoodTrack=0, isFakeTrack=0, isSelTrack=0;
1544
1545   if(aod) ntracks=aod->GetNTracks();
1546
1547   if(fOnOff[0] || fOnOff[1]){
1548     //loop on tracks in the event
1549     for (Int_t k=0;k<ntracks;k++){
1550       AliAODTrack* track=aod->GetTrack(k);
1551
1552       // Track selection cuts
1553       if(track->GetID()<0) continue;
1554       Double_t d0z0[2],covd0z0[3];
1555       track->PropagateToDCA(vtx1,aod->GetMagneticField(),99999.,d0z0,covd0z0);
1556       if(track->TestFilterMask(AliAODTrack::kTrkGlobalNoDCA)){
1557         ((TH1F*)fOutputTrack->FindObject("hd0TracksFilterBit4"))->Fill(d0z0[0]);
1558       }
1559       ULong_t trStatus=track->GetStatus();
1560       if(trStatus&AliESDtrack::kITSrefit){
1561         if(track->HasPointOnITSLayer(0) || track->HasPointOnITSLayer(1)){
1562           ((TH1F*)fOutputTrack->FindObject("hd0TracksSPDany"))->Fill(d0z0[0]);
1563           if(track->HasPointOnITSLayer(0)){
1564             ((TH1F*)fOutputTrack->FindObject("hd0TracksSPDin"))->Fill(d0z0[0]);
1565           }
1566         }
1567       }
1568
1569       Bool_t selTrack=kTRUE;
1570        if (!((trStatus & AliVTrack::kTPCrefit) == AliVTrack::kTPCrefit) ||
1571           !((trStatus & AliVTrack::kITSrefit) == AliVTrack::kITSrefit)){
1572         selTrack=kFALSE;
1573       }
1574
1575       Float_t nCrossedRowsTPC = track->GetTPCClusterInfo(2,1);
1576       Float_t  ratioCrossedRowsOverFindableClustersTPC = 1.0;
1577       if (track->GetTPCNclsF()>0) {
1578         ratioCrossedRowsOverFindableClustersTPC = nCrossedRowsTPC/track->GetTPCNclsF();
1579       }
1580       if ( nCrossedRowsTPC<70 || ratioCrossedRowsOverFindableClustersTPC<.8 ){
1581         selTrack=kFALSE;        
1582       }
1583       if(selTrack){
1584         if(track->HasPointOnITSLayer(0) || track->HasPointOnITSLayer(1)){
1585           ((TH1F*)fOutputTrack->FindObject("hd0TracksTPCITSSPDany"))->Fill(d0z0[0]);
1586         }
1587       }
1588       
1589       AliAODPid *pid = track->GetDetPid();
1590       if(!pid && fDebug>1) cout<<"No AliAODPid found"<<endl;
1591
1592       if(pid && fOnOff[1]){
1593         Double_t times[AliPID::kSPECIES];
1594         pid->GetIntegratedTimes(times);
1595     
1596         Double_t tofRes[AliPID::kSPECIES];
1597         pid->GetTOFpidResolution(tofRes);
1598
1599         //check TOF
1600         TH1F* htmpfl=((TH1F*)fOutputPID->FindObject("hTOFflags"));
1601         htmpfl->Fill(0.);
1602         if (trStatus&AliESDtrack::kTPCout) htmpfl->Fill(1.);
1603         if (trStatus&AliESDtrack::kTOFout) htmpfl->Fill(2.);
1604         if (trStatus&AliESDtrack::kTIME) htmpfl->Fill(3.);
1605         if (trStatus&AliESDtrack::kTOFpid) htmpfl->Fill(4.);
1606         if (trStatus&AliESDtrack::kTOFmismatch) htmpfl->Fill(5.);
1607
1608         Bool_t isTOFok=kFALSE;
1609         if(pidResp){
1610           Double_t prob[AliPID::kSPECIES];
1611           if(pidResp->ComputeTOFProbability(track,AliPID::kSPECIES,prob)==AliPIDResponse::kDetPidOk){
1612             isTOFok=kTRUE;
1613             htmpfl->Fill(6.);
1614           }
1615         }
1616       
1617         if(selTrack && isTOFok){
1618           Double_t tofTime=pid->GetTOFsignal();
1619           AliTOFHeader* tofH=(AliTOFHeader*)aod->GetTOFHeader();
1620           if (tofH && (TMath::Abs(tofRes[0]) <= 1.E-16) ) { // new AOD
1621             // with new AOD we need to retrieve startTime, subtract it and retrieve correctly TOF PID resolutions  *PA*
1622             AliTOFPIDResponse tofResp=pidResp->GetTOFResponse();
1623             Double_t startTime = tofResp.GetStartTime(track->P());
1624             Float_t startTimeRes = tofResp.GetStartTimeRes(track->P());  
1625             Int_t startTimeMask = tofResp.GetStartTimeMask(track->P());  
1626             ((TH1F*)fOutputPID->FindObject("hTOFstartTimeDistrib"))->Fill(startTime);
1627             ((TH1F*)fOutputPID->FindObject("hTOFstartTimeMask"))->Fill(startTimeMask);
1628             ((TH1F*)fOutputPID->FindObject("hTOFstartTimeRes"))->Fill(startTimeRes);
1629             tofTime-=startTime;
1630             for (Int_t type=0;type<AliPID::kSPECIES;type++) tofRes[type]=tofResp.GetExpectedSigma(track->P(),times[type],AliPID::ParticleMassZ(type)); 
1631           }
1632           ((TH1F*)fOutputPID->FindObject("hTOFtime"))->Fill(times[AliPID::kProton]);
1633           ((TH2F*)fOutputPID->FindObject("hTOFtimeKaonHyptime"))->Fill(track->P(),tofTime-times[3]); //3 is kaon
1634           ((TH1F*)fOutputPID->FindObject("hTOFsig"))->Fill(tofTime);
1635           if (pid->GetTOFsignal()< 0) ((TH1F*)fOutputPID->FindObject("hTOFsig"))->Fill(-1);
1636
1637           Double_t nsigma[3]={-10,-10,-10};
1638           nsigma[0]=pidResp->NumberOfSigmasTOF(track,AliPID::kPion);
1639           nsigma[1]=pidResp->NumberOfSigmasTOF(track,AliPID::kKaon);
1640           nsigma[2]=pidResp->NumberOfSigmasTOF(track,AliPID::kProton);
1641
1642           ((TH2F*)fOutputPID->FindObject("hTOFsigmaKSigPid"))->Fill(track->P(),nsigma[1]);
1643           ((TH2F*)fOutputPID->FindObject("hTOFsigmaPionSigPid"))->Fill(track->P(),nsigma[0]);
1644           ((TH2F*)fOutputPID->FindObject("hTOFsigmaProtonSigPid"))->Fill(track->P(),nsigma[2]);
1645           if(fReadMC){
1646             Int_t label=track->GetLabel();
1647             if(label<=0) continue;
1648             AliMCParticle* mcpart=(AliMCParticle*)mcArray->At(label);
1649             if(mcpart){
1650               Int_t abspdgcode=TMath::Abs(mcpart->PdgCode());
1651               if(abspdgcode==211) ((TH2F*)fOutputPID->FindObject("hTOFsigmaMCPionSigPid"))->Fill(track->P(),nsigma[0]);
1652               if(abspdgcode==321) ((TH2F*)fOutputPID->FindObject("hTOFsigmaMCKSigPid"))->Fill(track->P(),nsigma[1]);
1653               if(abspdgcode==2212) ((TH2F*)fOutputPID->FindObject("hTOFsigmaMCProtonSigPid"))->Fill(track->P(),nsigma[2]);
1654
1655             }
1656           }
1657
1658           for (Int_t iS=2; iS<5; iS++){ //we plot TOF Pid resolution for 3-sigma identified particles
1659             if ( TMath::Abs(nsigma[iS-2])<3.){
1660               switch (iS) {
1661               case AliPID::kPion:
1662                 ((TH1F*)fOutputPID->FindObject("hTOFsigPid3sigPion"))->Fill(tofRes[iS]);
1663                 break;
1664               case AliPID::kKaon:
1665                 ((TH1F*)fOutputPID->FindObject("hTOFsigPid3sigKaon"))->Fill(tofRes[iS]);
1666                 break;
1667               case AliPID::kProton:
1668                 ((TH1F*)fOutputPID->FindObject("hTOFsigPid3sigProton"))->Fill(tofRes[iS]);
1669                 break;
1670               default:
1671                 break;
1672               }
1673             }
1674           }
1675         }//if TOF status
1676         //}
1677       
1678         if(pidHF && pidHF->CheckStatus(track,"TPC")){ 
1679
1680           Double_t TPCp=pid->GetTPCmomentum();
1681           Double_t TPCsignal=pid->GetTPCsignal();
1682           UShort_t TPCsignalN=pid->GetTPCsignalN();
1683           ((TH1F*)fOutputPID->FindObject("hTPCsig"))->Fill(TPCsignal);
1684           ((TH1F*)fOutputPID->FindObject("hTPCsigvsp"))->Fill(TPCp,TPCsignal);
1685           //if (pidHF->IsKaonRaw(track, "TOF"))
1686           Double_t nsigma[3]={-10,-10,-10};
1687           pidHF->GetnSigmaTPC(track,(Int_t)AliPID::kPion,nsigma[0]);     
1688           pidHF->GetnSigmaTPC(track,(Int_t)AliPID::kKaon,nsigma[1]);     
1689           pidHF->GetnSigmaTPC(track,(Int_t)AliPID::kProton,nsigma[2]);   
1690
1691           ((TH2F*)fOutputPID->FindObject("hTPCsigmaK"))->Fill(TPCp,nsigma[1]);
1692           
1693           ((TH2F*)fOutputPID->FindObject("hTPCsigmaPion"))->Fill(TPCp,nsigma[0]);         
1694           ((TH2F*)fOutputPID->FindObject("hTPCsigmaProton"))->Fill(TPCp,nsigma[2]);
1695           
1696           if(fReadMC){
1697             Int_t label=track->GetLabel();
1698             if(label<=0) continue;
1699             AliMCParticle* mcpart=(AliMCParticle*)mcArray->At(label);
1700             if(mcpart){
1701               Int_t abspdgcode=TMath::Abs(mcpart->PdgCode());
1702               if(abspdgcode==211) ((TH2F*)fOutputPID->FindObject("hTPCsigmaMCPion"))->Fill(track->P(),nsigma[0]);
1703               if(abspdgcode==321) ((TH2F*)fOutputPID->FindObject("hTPCsigmaMCK"))->Fill(track->P(),nsigma[1]);
1704               if(abspdgcode==2212) ((TH2F*)fOutputPID->FindObject("hTPCsigmaMCProton"))->Fill(track->P(),nsigma[2]);
1705
1706             }
1707
1708           }
1709           if(fFillDistrTrackEffChecks && track->GetStatus()&AliESDtrack::kITSrefit && track->GetStatus()&AliESDtrack::kTPCrefit){
1710             ((TH2F*)fOutputPID->FindObject("hTPCsigNvsPtAllTracks"))->Fill(track->Pt(),(Float_t)TPCsignalN);
1711             ((TH2F*)fOutputPID->FindObject("hTPCsigNvsPhiAllTracks"))->Fill(track->Phi(),(Float_t)TPCsignalN);
1712             ((TH2F*)fOutputPID->FindObject("hTPCsigNvsEtaAllTracks"))->Fill(track->Eta(),(Float_t)TPCsignalN);
1713           }
1714           
1715         }//if TPC status
1716       } //end PID histograms
1717       
1718       Int_t nclsTot=0,nclsSPD=0;
1719
1720       //check clusters of the tracks
1721       if(fOnOff[0]){
1722
1723         ((TH1F*)fOutputTrack->FindObject("hnLayerITS"))->Fill(-1);
1724         for(Int_t l=0;l<6;l++) {
1725           if(TESTBIT(track->GetITSClusterMap(),l)) {
1726             ((TH1F*)fOutputTrack->FindObject("hnLayerITS"))->Fill(l);
1727             nclsTot++; if(l<2) nclsSPD++;
1728           }
1729         }
1730         ((TH1F*)fOutputTrack->FindObject("hnClsITS"))->Fill(nclsTot);
1731         ((TH1F*)fOutputTrack->FindObject("hnClsSPD"))->Fill(nclsSPD);
1732         
1733         if(fFillDistrTrackEffChecks && track->GetStatus()&AliESDtrack::kITSrefit && track->GetStatus()&AliESDtrack::kTPCrefit){
1734
1735           ((TH1F*)fOutputTrack->FindObject("hPtAllTracks"))->Fill(track->Pt());
1736           ((TH1F*)fOutputTrack->FindObject("hPhiAllTracks"))->Fill(track->Phi());
1737           ((TH1F*)fOutputTrack->FindObject("hEtaAllTracks"))->Fill(track->Eta());
1738           ((TH2F*)fOutputTrack->FindObject("hEtavsPhiAllTracks"))->Fill(track->Phi(),track->Eta());
1739           ((TH2F*)fOutputTrack->FindObject("hNTPCclsvsPtAllTracks"))->Fill(track->Pt(),track->GetTPCNcls());
1740           ((TH2F*)fOutputTrack->FindObject("hNTPCclsvsPhiAllTracks"))->Fill(track->Phi(),track->GetTPCNcls());
1741           ((TH2F*)fOutputTrack->FindObject("hNTPCclsvsEtaAllTracks"))->Fill(track->Eta(),track->GetTPCNcls());
1742
1743           ((TH2F*)fOutputTrack->FindObject("hNTPCCrossedRowsvsPtAllTracks"))->Fill(track->Pt(),nCrossedRowsTPC);
1744           ((TH2F*)fOutputTrack->FindObject("hNTPCCrossedRowsvsPhiAllTracks"))->Fill(track->Phi(),nCrossedRowsTPC);
1745           ((TH2F*)fOutputTrack->FindObject("hNTPCCrossedRowsvsEtaAllTracks"))->Fill(track->Eta(),nCrossedRowsTPC);
1746
1747           ((TH2F*)fOutputTrack->FindObject("hRatioCRowsOverFclsvsPtAllTracks"))->Fill(track->Pt(),ratioCrossedRowsOverFindableClustersTPC);
1748           ((TH2F*)fOutputTrack->FindObject("hRatioCRowsOverFclsvsPhiAllTracks"))->Fill(track->Phi(),ratioCrossedRowsOverFindableClustersTPC);
1749           ((TH2F*)fOutputTrack->FindObject("hRatioCRowsOverFclsvsEtaAllTracks"))->Fill(track->Eta(),ratioCrossedRowsOverFindableClustersTPC);
1750
1751           if(!(track->HasPointOnITSLayer(0)) && !(track->HasPointOnITSLayer(1))){ //no SPD points
1752             ((TH1I*)fOutputTrack->FindObject("hSPDclsAllTracks"))->Fill(0);
1753           } 
1754           if(track->HasPointOnITSLayer(0) && !(track->HasPointOnITSLayer(1))){ //kOnlyFirst
1755             ((TH1I*)fOutputTrack->FindObject("hSPDclsAllTracks"))->Fill(1);
1756           } 
1757           if(!(track->HasPointOnITSLayer(0)) && track->HasPointOnITSLayer(1)){ //kOnlySecond
1758             ((TH1I*)fOutputTrack->FindObject("hSPDclsAllTracks"))->Fill(2);
1759           }
1760           if(track->HasPointOnITSLayer(0) && track->HasPointOnITSLayer(1)){ //kBoth
1761             ((TH1I*)fOutputTrack->FindObject("hSPDclsAllTracks"))->Fill(3);
1762           } 
1763           ((TH2F*)fOutputTrack->FindObject("hNITSclsvsPtAllTracks"))->Fill(track->Pt(), nclsTot);
1764           ((TH2F*)fOutputTrack->FindObject("hNITSclsvsPhiAllTracks"))->Fill(track->Phi(), nclsTot);
1765           ((TH2F*)fOutputTrack->FindObject("hNITSclsvsEtaAllTracks"))->Fill(track->Eta(), nclsTot);
1766
1767         }
1768         
1769         if(track->Pt()>0.3 &&
1770            TMath::Abs(track->Eta())<0.8 &&
1771            track->GetStatus()&AliESDtrack::kITSrefit &&
1772            track->GetStatus()&AliESDtrack::kTPCrefit &&
1773            nclsSPD>0){
1774           ((TH1F*)fOutputTrack->FindObject("hnClsITSselTr"))->Fill(nclsTot);
1775         }
1776         if(!(track->GetStatus()&AliESDtrack::kTPCin) && track->GetStatus()&AliESDtrack::kITSrefit && !(track->GetStatus()&AliESDtrack::kITSpureSA)){//tracks retrieved in the ITS and not reconstructed in the TPC
1777           ((TH1F*)fOutputTrack->FindObject("hnClsITS-SA"))->Fill(nclsTot);
1778           ((TH1F*)fOutputTrack->FindObject("hnLayerITS"))->Fill(-1);
1779           for(Int_t l=0;l<6;l++) {
1780             if(TESTBIT(track->GetITSClusterMap(),l)) {
1781               ((TH1F*)fOutputTrack->FindObject("hnLayerITSsa"))->Fill(l);
1782             }
1783           }
1784         }
1785         Int_t label=0;
1786         if(fReadMC){
1787           label=track->GetLabel();
1788           if (label<0)fNEntries->Fill(8);
1789           else fNEntries->Fill(9); 
1790         }
1791
1792
1793         if (track->Pt()>0.3 &&
1794             track->GetStatus()&AliESDtrack::kTPCrefit &&
1795             track->GetStatus()&AliESDtrack::kITSrefit &&
1796             /*nclsTot>3 &&*/
1797             nclsSPD>0) {//count good tracks
1798
1799         
1800           if(fReadMC && label<0) {
1801             ((TH1F*)fOutputTrack->FindObject("hptFakeTr"))->Fill(track->Pt());
1802             isFakeTrack++;      
1803           } else {
1804             ((TH1F*)fOutputTrack->FindObject("hptGoodTr"))->Fill(track->Pt());
1805             isGoodTrack++;
1806           }
1807         }
1808         if(fCuts->IsDaughterSelected(track,&vESD,fCuts->GetTrackCuts())){
1809           isSelTrack++;
1810         }//select tracks for our analyses
1811       } //fill track histos
1812     } //end loop on tracks
1813
1814     //fill once per event
1815     if(fOnOff[0]){
1816       if (fReadMC) ((TH1F*)fOutputTrack->FindObject("hdistrFakeTr"))->Fill(isFakeTrack);
1817       ((TH1F*)fOutputTrack->FindObject("hdistrGoodTr"))->Fill(isGoodTrack);
1818       ((TH1F*)fOutputTrack->FindObject("hdistrSelTr"))->Fill(isSelTrack);
1819     }
1820
1821     if(!isSimpleMode){
1822       // loop over candidates
1823       Int_t nCand = arrayProng->GetEntriesFast();
1824       Int_t ndaugh=3;
1825       if(fDecayChannel==AliAnalysisTaskSEHFQA::kD0toKpi) ndaugh=2;
1826       if(fDecayChannel==AliAnalysisTaskSEHFQA::kD0toKpipipi) ndaugh=4;
1827
1828       for (Int_t iCand = 0; iCand < nCand; iCand++) {
1829         AliAODRecoDecayHF *d = (AliAODRecoDecayHF*)arrayProng->UncheckedAt(iCand);
1830         if(fUseSelectionBit && d->GetSelectionMap()) {
1831           if(fDecayChannel==AliAnalysisTaskSEHFQA::kD0toKpi && !d->HasSelectionBit(AliRDHFCuts::kD0toKpiCuts)) continue; //skip the D0 from Dstar
1832           if(fDecayChannel==AliAnalysisTaskSEHFQA::kDplustoKpipi && !d->HasSelectionBit(AliRDHFCuts::kDplusCuts)) continue; //skip the 3 prong !D+
1833         }
1834
1835         if(fReadMC){ 
1836
1837           Int_t labD = -1;
1838           if (fDecayChannel==AliAnalysisTaskSEHFQA::kLambdactoV0 && (dynamic_cast<AliAODRecoCascadeHF*>(d))->Getv0()) {
1839
1840             Int_t pdgDgLctoV0bachelor[2]={2212,310};
1841             Int_t pdgDgV0toDaughters[2]={211,211};
1842             Int_t mcLabelK0S = (dynamic_cast<AliAODRecoCascadeHF*>(d))->MatchToMC(pdg,pdgDgLctoV0bachelor[1],pdgDgLctoV0bachelor,pdgDgV0toDaughters,mcArray,kTRUE); // Lc->K0S+p and cc
1843             pdgDgLctoV0bachelor[1]=3122, pdgDgLctoV0bachelor[0]=211;
1844             pdgDgV0toDaughters[0]=2212,  pdgDgV0toDaughters[1]=211;
1845             Int_t mcLabelLambda = (dynamic_cast<AliAODRecoCascadeHF*>(d))->MatchToMC(pdg,pdgDgLctoV0bachelor[1],pdgDgLctoV0bachelor,pdgDgV0toDaughters,mcArray,kTRUE); // Lc->Lambda+pi and cc
1846             if (mcLabelK0S!=-1 || mcLabelLambda!=-1) AliInfo(Form("mcLabelK0S=%d - mcLabelLambda=%d",mcLabelK0S,mcLabelLambda));
1847
1848             if (mcLabelK0S!=-1 && mcLabelLambda!=-1)
1849               AliInfo("Strange: current Lc->V0+bachelor candidate has two MC different labels!");
1850             else if (mcLabelK0S>-1 && mcLabelLambda==-1)
1851               labD = mcLabelK0S;
1852             else if (mcLabelLambda>-1 && mcLabelK0S==-1)
1853               labD = mcLabelLambda;
1854           }
1855           else
1856             labD = d->MatchToMC(pdg,mcArray,ndaugh,pdgdaughters);
1857
1858           if(labD>=0){
1859             AliAODMCParticle *partD = (AliAODMCParticle*)mcArray->At(labD);
1860             Int_t label=partD->GetMother();
1861             AliAODMCParticle *mot = (AliAODMCParticle*)mcArray->At(label);
1862             while(label>=0){//get first mother
1863               mot = (AliAODMCParticle*)mcArray->At(label);
1864               label=mot->GetMother();
1865             }
1866             if(mot){
1867               Int_t pdgMotCode = mot->GetPdgCode();
1868         
1869               if(TMath::Abs(pdgMotCode)==4) fNEntries->Fill(6); //from primary charm
1870               if(TMath::Abs(pdgMotCode)==5) fNEntries->Fill(7); //from beauty
1871             }
1872           }
1873         }//end MC
1874         fNEntries->Fill(5); //count the candidates (data and MC)
1875
1876         for(Int_t id=0;id<ndaugh;id++){
1877           //other histograms to be filled when the cut object is given
1878           AliAODTrack* track=0;
1879
1880           if (fDecayChannel==AliAnalysisTaskSEHFQA::kLambdactoV0 && (dynamic_cast<AliAODRecoCascadeHF*>(d))->Getv0()) {
1881             if (id==0)
1882               track=(AliAODTrack*)(dynamic_cast<AliAODRecoCascadeHF*>(d))->GetBachelor();
1883             else if (id==1)
1884               track=(AliAODTrack*)(dynamic_cast<AliAODRecoCascadeHF*>(d))->Getv0PositiveTrack();
1885             else if (id==2)
1886               track=(AliAODTrack*)(dynamic_cast<AliAODRecoCascadeHF*>(d))->Getv0NegativeTrack();
1887           }
1888           else 
1889             track=(AliAODTrack*)d->GetDaughter(id);
1890
1891           //track quality
1892
1893           if (fCuts->IsInFiducialAcceptance(d->Pt(),d->Y(pdg)) && fCuts->IsSelected(d,AliRDHFCuts::kTracks,aod)) {
1894             
1895             Int_t label=0;
1896             if(fReadMC)label=track->GetLabel();
1897             if(fOnOff[0]){
1898               
1899               if(fReadMC && label<0) {
1900                 isFakeTrack++;
1901                 ((TH1F*)fOutputTrack->FindObject("hptFakeTrFromDaugh"))->Fill(track->Pt());
1902            
1903                 ((TH1F*)fOutputTrack->FindObject("hd0f"))->Fill(d->Getd0Prong(id));
1904               } else {
1905                 ((TH1F*)fOutputTrack->FindObject("hptGoodTrFromDaugh"))->Fill(track->Pt());
1906                 ((TH1F*)fOutputTrack->FindObject("hd0dau"))->Fill(d->Getd0Prong(id));
1907                 Double_t d0rphiz[2],covd0[3];
1908                 Bool_t isDCA=track->PropagateToDCA(aod->GetPrimaryVertex(),aod->GetMagneticField(),9999.,d0rphiz,covd0);
1909                 if(isDCA) ((TH1F*)fOutputTrack->FindObject("hd0zdau"))->Fill(d0rphiz[1]);
1910               }
1911             }
1912
1913
1914             if(fFillDistrTrackEffChecks){
1915               Int_t nITScls = 0;
1916               Double_t nTPCCrossedRows = track->GetTPCClusterInfo(2,1);
1917               Double_t ratioCrossedRowsOverFcls = 1.0;
1918               if(track->GetTPCNclsF()>0){
1919                 ratioCrossedRowsOverFcls = (nTPCCrossedRows)/(track->GetTPCNclsF());
1920               }
1921               for(Int_t l=0;l<6;l++) {
1922                 if(TESTBIT(track->GetITSClusterMap(),l)) {
1923                   nITScls++;
1924                 }
1925               }
1926
1927               ((TH1F*)fOutputTrack->FindObject("hPtDaughters"))->Fill(track->Pt());
1928               ((TH1F*)fOutputTrack->FindObject("hPhiDaughters"))->Fill(track->Phi());
1929               ((TH1F*)fOutputTrack->FindObject("hEtaDaughters"))->Fill(track->Eta());
1930               ((TH2F*)fOutputTrack->FindObject("hEtavsPhiDaughters"))->Fill(track->Phi(),track->Eta());
1931
1932               ((TH2F*)fOutputTrack->FindObject("hNTPCclsvsPtDaughters"))->Fill(track->Pt(),track->GetTPCNcls());
1933               ((TH2F*)fOutputTrack->FindObject("hNTPCclsvsPhiDaughters"))->Fill(track->Phi(),track->GetTPCNcls());
1934               ((TH2F*)fOutputTrack->FindObject("hNTPCclsvsEtaDaughters"))->Fill(track->Eta(),track->GetTPCNcls());
1935
1936               ((TH2F*)fOutputTrack->FindObject("hNTPCCrossedRowsvsPtDaughters"))->Fill(track->Pt(),nTPCCrossedRows);
1937               ((TH2F*)fOutputTrack->FindObject("hNTPCCrossedRowsvsPhiDaughters"))->Fill(track->Phi(),nTPCCrossedRows);
1938               ((TH2F*)fOutputTrack->FindObject("hNTPCCrossedRowsvsEtaDaughters"))->Fill(track->Eta(),nTPCCrossedRows);
1939
1940               ((TH2F*)fOutputTrack->FindObject("hRatioCRowsOverFclsvsPtDaughters"))->Fill(track->Pt(),ratioCrossedRowsOverFcls);
1941               ((TH2F*)fOutputTrack->FindObject("hRatioCRowsOverFclsvsPhiDaughters"))->Fill(track->Phi(),ratioCrossedRowsOverFcls);
1942               ((TH2F*)fOutputTrack->FindObject("hRatioCRowsOverFclsvsEtaDaughters"))->Fill(track->Eta(),ratioCrossedRowsOverFcls);
1943
1944               ((TH2F*)fOutputTrack->FindObject("hNITSclsvsPtDaughters"))->Fill(track->Pt(), nITScls);
1945               ((TH2F*)fOutputTrack->FindObject("hNITSclsvsPhiDaughters"))->Fill(track->Phi(), nITScls);
1946               ((TH2F*)fOutputTrack->FindObject("hNITSclsvsEtaDaughters"))->Fill(track->Eta(), nITScls);
1947               if(!(track->HasPointOnITSLayer(0)) && !(track->HasPointOnITSLayer(1))){ //no SPD points
1948                 ((TH1I*)fOutputTrack->FindObject("hSPDclsDaughters"))->Fill(0);
1949               } 
1950               if(track->HasPointOnITSLayer(0) && !(track->HasPointOnITSLayer(1))){ //kOnlyFirst
1951                 ((TH1I*)fOutputTrack->FindObject("hSPDclsDaughters"))->Fill(1);
1952               } 
1953               if(!(track->HasPointOnITSLayer(0)) && track->HasPointOnITSLayer(1)){ //kOnlySecond
1954                 ((TH1I*)fOutputTrack->FindObject("hSPDclsDaughters"))->Fill(2);
1955               }
1956               if(track->HasPointOnITSLayer(0) && track->HasPointOnITSLayer(1)){ //kBoth
1957                 ((TH1I*)fOutputTrack->FindObject("hSPDclsDaughters"))->Fill(3);
1958               }
1959
1960
1961               if(fOnOff[1]){
1962                 AliAODPid *pid = track->GetDetPid();
1963                 if(pid){
1964                   if(pidHF && pidHF->CheckStatus(track,"TPC")){
1965                     ((TH2F*)fOutputPID->FindObject("hTPCsigNvsPtDaughters"))->Fill(track->Pt(),pid->GetTPCsignalN());
1966                     ((TH2F*)fOutputPID->FindObject("hTPCsigNvsPhiDaughters"))->Fill(track->Phi(),pid->GetTPCsignalN());
1967                     ((TH2F*)fOutputPID->FindObject("hTPCsigNvsEtaDaughters"))->Fill(track->Eta(),pid->GetTPCsignalN());
1968                   }
1969                 }
1970               }
1971             }
1972
1973
1974             if (fCuts->IsSelected(d,AliRDHFCuts::kAll,aod) && fOnOff[1]){
1975               fNEntries->Fill(3); //candidates passing analysis cuts         
1976
1977             AliAODPid *pid = track->GetDetPid();
1978               if(pid){
1979                 Double_t times[5];
1980                 pid->GetIntegratedTimes(times);
1981                 if(pidHF && pidHF->CheckStatus(track,"TOF")){
1982                   Double_t tofTime=pid->GetTOFsignal();
1983                   AliTOFHeader* tofH=(AliTOFHeader*)aod->GetTOFHeader();
1984                   Double_t tofRes[AliPID::kSPECIES];
1985                   pid->GetTOFpidResolution(tofRes);
1986                   if (tofH && (TMath::Abs(tofRes[0]) <= 1.E-16) ) { // new AOD
1987                     AliTOFPIDResponse tofResp=pidHF->GetPidResponse()->GetTOFResponse();
1988                     Double_t startTime=tofResp.GetStartTime(track->P());
1989                     tofTime-=startTime;
1990                   }
1991                   ((TH2F*)fOutputPID->FindObject("hTOFtimeKaonHyptimeAC"))->Fill(track->P(),tofTime-times[AliPID::kKaon]);
1992                 }
1993                 if(pidHF && pidHF->CheckStatus(track,"TPC")) ((TH2F*)fOutputPID->FindObject("hTPCsigvspAC"))->Fill(pid->GetTPCmomentum(),pid->GetTPCsignal());
1994               }
1995               
1996             } //end analysis cuts
1997           } //end acceptance and track cuts
1998         } //end loop on tracks in the candidate
1999       } //end loop on candidates
2000       
2001     }
2002   } //end if on pid or track histograms
2003
2004   delete tpcres;
2005   delete [] pdgdaughters;
2006   PostData(1,fNEntries);
2007   if(fOnOff[1]) PostData(2,fOutputPID);
2008   if(fOnOff[0]) PostData(3,fOutputTrack);
2009   PostData(4,fCuts);
2010   if(fOnOff[2]) PostData(5,fOutputCounters);
2011   //Post data 6 done in case of centrality on   
2012
2013 }
2014
2015 //____________________________________________________________________________
2016 void AliAnalysisTaskSEHFQA::FillFlowObs(AliAODEvent *aod){
2017   //fills the flow observables
2018   Double_t cc;
2019   cc = fCuts->GetCentrality(aod);
2020   ((TH2F*) fOutputFlowObs->FindObject("hFlowEvents"))->Fill(0., cc);
2021
2022   UInt_t mask=((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected();
2023   UInt_t trigger=AliVEvent::kMB | AliVEvent::kCentral | AliVEvent::kSemiCentral;
2024   if(mask & trigger) {
2025     ((TH2F*) fOutputFlowObs->FindObject("hFlowEvents"))->Fill(1.,cc); // fired
2026     if (mask & AliVEvent::kMB) ((TH2F*) fOutputFlowObs->FindObject("hFlowEvents"))->Fill(2.,cc);
2027     if (mask & AliVEvent::kCentral) ((TH2F*) fOutputFlowObs->FindObject("hFlowEvents"))->Fill(3.,cc);
2028     if (mask & AliVEvent::kSemiCentral) ((TH2F*) fOutputFlowObs->FindObject("hFlowEvents"))->Fill(4.,cc);
2029     Bool_t rejected=false;
2030     if(cc<0 || cc>60) rejected=true;
2031     const AliVVertex *vertex = aod->GetPrimaryVertex();
2032     Double_t zvtx=vertex->GetZ();
2033     if(TMath::Abs(zvtx)>fCuts->GetMaxVtxZ()) rejected=true;
2034     if(rejected) return; //not interesting for flow QA
2035   } else {
2036     return;
2037   }
2038
2039   // event accepted
2040   ((TH2F*) fOutputFlowObs->FindObject("hFlowEvents"))->Fill(5.,cc);
2041   fRFPcuts->SetParamType(AliFlowTrackCuts::kGlobal);
2042   fRFPcuts->SetPtRange(0.2,5.);
2043   fRFPcuts->SetEtaRange(-0.8,0.8);
2044   fRFPcuts->SetMinNClustersTPC(70);
2045   fRFPcuts->SetMinChi2PerClusterTPC(0.2);
2046   fRFPcuts->SetMaxChi2PerClusterTPC(4.0);
2047   fRFPcuts->SetAcceptKinkDaughters(kFALSE);
2048   fRFPcuts->SetEvent(aod);
2049
2050   TString ref[3] = {"FB1","FB128","VZE"};
2051   Double_t psi[3];
2052   for(Int_t i=0; i!=3; ++i) {
2053     if(i==0) { // switching to bit 1
2054       fRFPcuts->SetMinimalTPCdedx(10.);
2055       fRFPcuts->SetAODfilterBit(1);
2056     } else { // switching to bit 128
2057       fRFPcuts->SetMinimalTPCdedx(-1);
2058       fRFPcuts->SetAODfilterBit(128);
2059     }
2060     if(i>1) {
2061       fRFPcuts->SetParamType(AliFlowTrackCuts::kV0);
2062       fRFPcuts->SetEtaRange(-5,+5);
2063       fRFPcuts->SetPhiMin(0);
2064       fRFPcuts->SetPhiMax(TMath::TwoPi());
2065     }
2066     fFlowEvent->Fill(fRFPcuts,fRFPcuts);
2067     fFlowEvent->TagSubeventsInEta(-5,0,0,+5);
2068     // getting informationt
2069     AliFlowVector vQ, vQaQb[2];
2070     fFlowEvent->Get2Qsub(vQaQb,2);
2071     vQ = vQaQb[0]+vQaQb[1];
2072     Double_t dMa=vQaQb[0].GetMult();
2073     Double_t dMb=vQaQb[1].GetMult();
2074     if( dMa<2 || dMb<2 ) {
2075       ((TH2F*) fOutputFlowObs->FindObject("hFlowEvents"))->Fill(6.,cc); //???
2076       continue;
2077     }
2078     psi[i] = vQ.Phi()/2;
2079     // publishing
2080     ((TProfile2D*) fOutputFlowObs->FindObject( Form("h%s_Q",ref[i].Data())))->Fill(0,cc,vQaQb[0].X()/dMa,dMa); // Qx-
2081     ((TProfile2D*) fOutputFlowObs->FindObject( Form("h%s_Q",ref[i].Data())))->Fill(1,cc,vQaQb[0].Y()/dMa,dMa); // Qy-
2082     ((TProfile2D*) fOutputFlowObs->FindObject( Form("h%s_Q",ref[i].Data())))->Fill(2,cc,vQaQb[1].X()/dMb,dMb); // Qx+
2083     ((TProfile2D*) fOutputFlowObs->FindObject( Form("h%s_Q",ref[i].Data())))->Fill(3,cc,vQaQb[1].Y()/dMb,dMb); // Qy+
2084     ((TH2F*) fOutputFlowObs->FindObject( Form("h%s_AngleQ",ref[i].Data()) ))->Fill(psi[i],cc); // Psi
2085     AliFlowTrackSimple *track;
2086     for(Int_t t=0; t!=fFlowEvent->NumberOfTracks(); ++t) {
2087       track = (AliFlowTrackSimple*) fFlowEvent->GetTrack(t);
2088       if(!track) continue;
2089       if(!track->InRPSelection()) continue;
2090       ((TH3F*) fOutputFlowObs->FindObject( Form("h%s_PhiEta",ref[i].Data()) ))->Fill(track->Phi(),track->Eta(),cc,track->Weight()); //PhiEta
2091     }
2092   
2093   //histo filled only for TPCFB1
2094   if (i==0) {
2095     ((TH2F*) fOutputFlowObs->FindObject("hCentVsMultRPS"))->Fill(fFlowEvent->GetNumberOfRPs(),cc);
2096   }
2097   }
2098   // TPC vs VZERO
2099   ((TH3F*) fOutputFlowObs->FindObject( "hTPCVZE_AngleQ" ))->Fill(psi[0],psi[2],cc);
2100 }
2101
2102 //____________________________________________________________________________
2103 void AliAnalysisTaskSEHFQA::Terminate(Option_t */*option*/){
2104   //terminate analysis
2105
2106   fNEntries = dynamic_cast<TH1F*>(GetOutputData(1));
2107   if(!fNEntries){
2108     printf("ERROR: %s not available\n",GetOutputSlot(1)->GetContainer()->GetName());
2109     return;
2110   }
2111
2112   fOutputPID = dynamic_cast<TList*> (GetOutputData(2));
2113   if (!fOutputPID && fOnOff[1]) {     
2114     printf("ERROR: %s not available\n",GetOutputSlot(2)->GetContainer()->GetName());
2115     return;
2116   }
2117
2118   fOutputTrack = dynamic_cast<TList*> (GetOutputData(3));
2119   if (!fOutputTrack && fOnOff[0]) {     
2120     printf("ERROR: %s not available\n",GetOutputSlot(3)->GetContainer()->GetName());
2121     return;
2122   }
2123
2124 }
2125