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