]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGHF/vertexingHF/AliAnalysisTaskSEHFQA.cxx
Added histograms for primary vertex QA
[u/mrichter/AliRoot.git] / PWGHF / vertexingHF / AliAnalysisTaskSEHFQA.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 /////////////////////////////////////////////////////////////
19 //
20 // AliAnalysisTaskSE for HF quality assurance
21 //
22 // Author: Chiara Bianchin, chiara.bianchin@pd.infn.it
23 /////////////////////////////////////////////////////////////
24
25 #include <Riostream.h>
26 #include <TClonesArray.h>
27 #include <TCanvas.h>
28 #include <TList.h>
29 #include <TH1F.h>
30 #include <TH2F.h>
31 #include <TH3F.h>
32 #include <TProfile2D.h>
33 #include <TDatabasePDG.h>
34
35 #include <AliAnalysisDataSlot.h>
36 #include <AliAnalysisDataContainer.h>
37 #include "AliAnalysisManager.h"
38 #include "AliESDtrack.h"
39 #include "AliESDVertex.h"
40 #include "AliVertexerTracks.h"
41 #include "AliPID.h"
42 #include "AliPIDResponse.h"
43 #include "AliTPCPIDResponse.h"
44 #include "AliAODHandler.h"
45 #include "AliAODEvent.h"
46 #include "AliAODVertex.h"
47 #include "AliAODTrack.h"
48 #include "AliAODMCParticle.h"
49 #include "AliAODMCHeader.h"
50 #include "AliAODRecoDecayHF2Prong.h"
51 #include "AliAODRecoCascadeHF.h"
52 #include "AliAnalysisVertexingHF.h"
53 #include "AliAnalysisTaskSE.h"
54 #include "AliCounterCollection.h"
55 #include "AliRDHFCuts.h"
56 #include "AliRDHFCutsDplustoKpipi.h"
57 #include "AliRDHFCutsD0toKpipipi.h"
58 #include "AliRDHFCutsDstoKKpi.h"
59 #include "AliRDHFCutsDStartoKpipi.h"
60 #include "AliRDHFCutsD0toKpi.h"
61 #include "AliRDHFCutsLctopKpi.h"
62 #include "AliRDHFCutsLctoV0.h"
63 #include "AliInputEventHandler.h"
64
65 #include "AliFlowEvent.h"
66 #include "AliFlowTrackCuts.h"
67 #include "AliFlowTrackSimple.h"
68 #include "AliFlowVector.h"
69
70 #include "AliAnalysisTaskSEHFQA.h"
71
72 using std::cout;
73 using std::endl;
74
75 ClassImp(AliAnalysisTaskSEHFQA)
76
77 //____________________________________________________________________________
78
79 AliAnalysisTaskSEHFQA::AliAnalysisTaskSEHFQA():AliAnalysisTaskSE(),
80   fNEntries(0x0),
81   fOutputPID(0x0),
82   fOutputTrack(0x0),
83   fOutputCounters(0x0),
84   fOutputCheckCentrality(0x0),
85   fOutputEvSelection(0x0),
86   fOutputFlowObs(0x0),
87   fDecayChannel(AliAnalysisTaskSEHFQA::kD0toKpi),
88   fCuts(0x0),
89   fFlowEvent(0x0),
90   fRFPcuts(0x0),
91   fEstimator(AliRDHFCuts::kCentTRK),
92   fReadMC(kFALSE),
93   fSimpleMode(kFALSE),
94   fOnOff()
95 {
96   //default constructor
97   fOnOff[0]=kTRUE;
98   fOnOff[1]=kTRUE;
99   fOnOff[2]=kTRUE;
100   fOnOff[3]=kTRUE;
101   fOnOff[4]=kTRUE;
102 }
103
104 //____________________________________________________________________________
105 AliAnalysisTaskSEHFQA::AliAnalysisTaskSEHFQA(const char *name, AliAnalysisTaskSEHFQA::DecChannel ch,AliRDHFCuts* cuts):
106   AliAnalysisTaskSE(name),
107   fNEntries(0x0),
108   fOutputPID(0x0),
109   fOutputTrack(0x0),
110   fOutputCounters(0x0),
111   fOutputCheckCentrality(0x0),
112   fOutputEvSelection(0x0),
113   fOutputFlowObs(0x0),
114   fDecayChannel(ch),
115   fCuts(0x0),
116   fFlowEvent(0x0),
117   fRFPcuts(0x0),
118   fEstimator(AliRDHFCuts::kCentTRK),
119   fReadMC(kFALSE),
120   fSimpleMode(kFALSE),
121   fOnOff()
122 {
123   //constructor
124
125   //SetCutObject(cuts);
126   fCuts=cuts;
127
128   fOnOff[0]=kTRUE;
129   fOnOff[1]=kTRUE;
130   fOnOff[2]=kTRUE;
131   fOnOff[3]=kTRUE;
132   fOnOff[4]=kTRUE;
133
134   // Output slot #1 writes into a TH1F container (number of events)
135   DefineOutput(1,TH1F::Class());  //My private output
136   // Output slot #2 writes into a TList container (PID)
137   if (fOnOff[1]) DefineOutput(2,TList::Class());  //My private output
138   // Output slot #3 writes into a TList container (Tracks)
139   if (fOnOff[0]) DefineOutput(3,TList::Class());  //My private output
140   // Output slot #4 writes into a AliRDHFCuts container (cuts)
141   switch(fDecayChannel){
142   case 0:
143     DefineOutput(4,AliRDHFCutsDplustoKpipi::Class());  //My private output
144     break;
145   case 1:
146     DefineOutput(4,AliRDHFCutsD0toKpi::Class());  //My private output
147     break;
148   case 2:
149     DefineOutput(4,AliRDHFCutsDStartoKpipi::Class());  //My private output
150     break;
151   case 3:
152     DefineOutput(4,AliRDHFCutsDstoKKpi::Class());  //My private output
153     break;
154   case 4:
155     DefineOutput(4,AliRDHFCutsD0toKpipipi::Class());  //My private output
156     break;
157   case 5:
158     DefineOutput(4,AliRDHFCutsLctopKpi::Class());  //My private output
159     break;
160   case kLambdactoV0:
161     DefineOutput(4,AliRDHFCutsLctoV0::Class());  //My private output
162     break;
163   }
164   if (fOnOff[2]) {
165     // Output slot #5 writes into a TList container (AliCounterCollection)
166     DefineOutput(5,TList::Class());  //My private output
167     // Output slot #6 writes into a TList container (TH1F)
168     DefineOutput(6,TList::Class());  //My private output
169   }
170
171   if(fOnOff[3]) DefineOutput(7,TList::Class());  //My private output
172   if(fOnOff[4]) DefineOutput(8,TList::Class());  //My private output
173
174 }
175
176 //___________________________________________________________________________
177 AliAnalysisTaskSEHFQA::~AliAnalysisTaskSEHFQA()
178 {
179   //destructor
180   delete fNEntries;
181
182   delete fOutputPID;
183
184   delete fOutputTrack;
185
186   delete fOutputCounters;
187
188   delete fOutputCheckCentrality;
189
190   delete fOutputEvSelection;
191
192   if(fOnOff[4]) {
193     delete fOutputFlowObs;
194     delete fFlowEvent;
195   }
196 }
197
198 //___________________________________________________________________________
199 void AliAnalysisTaskSEHFQA::Init(){
200
201   //initialization
202   if(fDebug > 1) printf("AnalysisTaskSEHFQA::Init() \n");
203
204   switch(fDecayChannel){
205   case 0:
206     {
207       AliRDHFCutsDplustoKpipi* copycut=new AliRDHFCutsDplustoKpipi(*(static_cast<AliRDHFCutsDplustoKpipi*>(fCuts)));
208       // Post the data
209       PostData(4,copycut);
210     }
211     break;
212   case 1:
213     {
214       AliRDHFCutsD0toKpi* copycut=new AliRDHFCutsD0toKpi(*(static_cast<AliRDHFCutsD0toKpi*>(fCuts)));
215       // Post the data
216       PostData(4,copycut);
217     }
218     break;
219   case 2:
220     {
221       AliRDHFCutsDStartoKpipi* copycut=new AliRDHFCutsDStartoKpipi(*(static_cast<AliRDHFCutsDStartoKpipi*>(fCuts)));
222       // Post the data
223       PostData(4,copycut);
224     }
225     break;
226   case 3:
227     {
228       AliRDHFCutsDstoKKpi* copycut=new AliRDHFCutsDstoKKpi(*(static_cast<AliRDHFCutsDstoKKpi*>(fCuts)));
229       // Post the data
230       PostData(4,copycut);
231     }
232     break;
233   case 4:
234     {
235       AliRDHFCutsD0toKpipipi* copycut=new AliRDHFCutsD0toKpipipi(*(static_cast<AliRDHFCutsD0toKpipipi*>(fCuts)));
236       // Post the data
237       PostData(4,copycut);
238     }
239     break;
240   case 5:
241     {
242       AliRDHFCutsLctopKpi* copycut=new AliRDHFCutsLctopKpi(*(static_cast<AliRDHFCutsLctopKpi*>(fCuts)));
243       // Post the data
244       PostData(4,copycut);
245     }
246     break;
247   case kLambdactoV0:
248     {
249       AliRDHFCutsLctoV0* copycut=new AliRDHFCutsLctoV0(*(static_cast<AliRDHFCutsLctoV0*>(fCuts)));
250       // Post the data
251       PostData(4,copycut);
252     }
253     break;
254
255   default:
256     return;
257   }
258
259
260
261 }
262
263 //___________________________________________________________________________
264 void AliAnalysisTaskSEHFQA::UserCreateOutputObjects()
265 {
266
267   //create the output container
268   if(fDebug > 1) printf("AnalysisTaskSEHFQA::UserCreateOutputObjects() \n");
269
270   //count events
271
272   fNEntries=new TH1F(GetOutputSlot(1)->GetContainer()->GetName(), "Counts the number of events", 10,-0.5,9.5);
273   fNEntries->GetXaxis()->SetBinLabel(1,"nEventsAnal");
274   fNEntries->GetXaxis()->SetBinLabel(2,"Pile-up Rej");
275   fNEntries->GetXaxis()->SetBinLabel(3,"No VertexingHF");
276   fNEntries->GetXaxis()->SetBinLabel(4,"nCandidates(AnCuts)");
277   fNEntries->GetXaxis()->SetBinLabel(5,"EventsWithGoodVtx");
278   //fNEntries->GetXaxis()->SetBinLabel(6,"N. of 0SMH");
279   fNEntries->GetXaxis()->SetBinLabel(6,"N. of CSH1");
280   if(fReadMC){
281     fNEntries->GetXaxis()->SetBinLabel(7,"MC Cand from c");
282     fNEntries->GetXaxis()->SetBinLabel(8,"MC Cand from b");
283     fNEntries->GetXaxis()->SetBinLabel(9,"N fake Trks");
284     fNEntries->GetXaxis()->SetBinLabel(10,"N true Trks");
285   } else{
286     fNEntries->GetXaxis()->SetBinLabel(7,"N candidates");
287   }
288
289   fNEntries->GetXaxis()->SetNdivisions(1,kFALSE);
290
291   //PID
292   if(fOnOff[1]){
293     fOutputPID=new TList();
294     fOutputPID->SetOwner();
295     fOutputPID->SetName(GetOutputSlot(2)->GetContainer()->GetName());
296
297     //TOF pid
298     TH1F* hTOFflags=new TH1F("hTOFflags","TOF flags",6,-0.5,5.5);
299     hTOFflags->SetMinimum(0.);
300     hTOFflags->GetXaxis()->SetBinLabel(1,"All Tracks");
301     hTOFflags->GetXaxis()->SetBinLabel(2,"kTPCout");
302     hTOFflags->GetXaxis()->SetBinLabel(3,"kTOFout");
303     hTOFflags->GetXaxis()->SetBinLabel(4,"kTIME");
304     hTOFflags->GetXaxis()->SetBinLabel(5,"kTOFpid");
305     hTOFflags->GetXaxis()->SetBinLabel(6,"kTOFmismatch");
306
307     TString hname="hTOFsig";
308     TH1F* hTOFsig=new TH1F(hname.Data(),"Distribution of TOF signal;TOF time [ps];Entries", 100, -2.e3,40.e3);
309
310     hname="hTOFtime";
311     TH1F* hTOFtime=new TH1F(hname.Data(),"Distribution of TOF time Kaon;TOF time(Kaon) [ps];Entries", 1000, 0.,50000.);
312
313     hname="hTOFtimeKaonHyptime";
314     TH2F* hTOFtimeKaonHyptime=new TH2F(hname.Data(),"TOFtime - timeHypothesisForKaon;p[GeV/c];TOFtime - timeHypothesisForKaon [ps]",500,0.,10.,1000,-20000.,20000.);
315
316     hname="hTOFtimeKaonHyptimeAC";
317     TH2F* hTOFtimeKaonHyptimeAC=new TH2F(hname.Data(),"TOFtime - timeHypothesisForKaon;p[GeV/c];TOFtime - timeHypothesisForKaon [ps]",500,0.,10.,1000,-20000.,20000.);
318
319     hname="hTOFsigmaKSigPid";
320     TH2F* hTOFsigmaKSigPid=new TH2F(hname.Data(),"(TOFsignal-timeK)/tofSigPid;p[GeV/c];(TOFsignal-timeK)/tofSigPid",500,0.,10.,400,-20,20);
321
322     hname="hTOFsigmaPionSigPid";
323     TH2F* hTOFsigmaPionSigPid=new TH2F(hname.Data(),"(TOFsignal-time#pi)/tofSigPid;p[GeV/c];(TOFsignal-time#pi)/tofSigPid",500,0.,10.,400,-20,20);
324
325     hname="hTOFsigmaProtonSigPid";
326     TH2F* hTOFsigmaProtonSigPid=new TH2F(hname.Data(),"(TOFsignal-timep)/tofSigPid;p[GeV/c];(TOFsignal-time p)/tofSigPid",500,0.,10.,400,-20,20);
327
328     hname="hTOFsigPid3sigPion";
329     TH1F* hTOFsigPid3sigPion=new TH1F(hname.Data(),"TOF PID resolution (#pi) [ps]",500,0.,1000.);
330
331     hname="hTOFsigPid3sigKaon";
332     TH1F* hTOFsigPid3sigKaon=new TH1F(hname.Data(),"TOF PID resolution (K) [ps]",500,0.,1000.);
333
334     hname="hTOFsigPid3sigProton";
335     TH1F* hTOFsigPid3sigProton=new TH1F(hname.Data(),"TOF PID resolution (p) [ps]",500,0.,1000.);
336
337
338     //TPC pid
339     hname="hTPCsig";
340     TH1F* hTPCsig=new TH1F(hname.Data(),"Distribution of TPC signal;TPC sig;Entries", 100, 35.,100.);
341
342     hname="hTPCsigvsp";
343     TH2F* hTPCsigvsp=new TH2F(hname.Data(),"TPCsig vs p;TPC p[GeV/c];TPCsig",500,0.,10.,1000,35.,100.);
344  
345     hname="hTPCsigvspAC";
346     TH2F* hTPCsigvspAC=new TH2F(hname.Data(),"TPCsig vs p;TPCp[GeV/c];TPCsig",500,0.,10.,1000,35.,100.);
347
348     hname="hTPCsigmaK";
349     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);
350
351     hname="hTPCsigmaPion";
352     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);
353
354     hname="hTPCsigmaProton";
355     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);
356
357     fOutputPID->Add(hTOFflags);
358     fOutputPID->Add(hTOFsig);
359     fOutputPID->Add(hTPCsig);
360     fOutputPID->Add(hTOFtime);
361     fOutputPID->Add(hTOFtimeKaonHyptime);
362     fOutputPID->Add(hTOFtimeKaonHyptimeAC);
363     fOutputPID->Add(hTOFsigmaKSigPid);
364     fOutputPID->Add(hTOFsigmaPionSigPid);
365     fOutputPID->Add(hTOFsigmaProtonSigPid);
366     fOutputPID->Add(hTOFsigPid3sigPion);
367     fOutputPID->Add(hTOFsigPid3sigKaon);
368     fOutputPID->Add(hTOFsigPid3sigProton);
369     fOutputPID->Add(hTPCsigvsp);
370     fOutputPID->Add(hTPCsigvspAC);
371     fOutputPID->Add(hTPCsigmaK);
372     fOutputPID->Add(hTPCsigmaPion);
373     fOutputPID->Add(hTPCsigmaProton);
374
375     if(fReadMC){
376       //TOF
377       hname="hTOFsigmaMCKSigPid";
378       TH2F* hTOFsigmaMCKSigPid=new TH2F(hname.Data(),"(TOFsignal-timeK)/tofSigPid;p[GeV/c];(TOFsignal-timeK)/tofSigPid",500,0.,10.,400,-20,20);
379
380       hname="hTOFsigmaMCPionSigPid";
381       TH2F* hTOFsigmaMCPionSigPid=new TH2F(hname.Data(),"(TOFsignal-time#pi)/tofSigPid;p[GeV/c];(TOFsignal-time#pi)/tofSigPid",500,0.,10.,400,-20,20);
382
383       hname="hTOFsigmaMCProtonSigPid";
384       TH2F* hTOFsigmaMCProtonSigPid=new TH2F(hname.Data(),"(TOFsignal-timep)/tofSigPid;p[GeV/c];(TOFsignal-time p)/tofSigPid",500,0.,10.,400,-20,20);
385
386       //TPC
387       hname="hTPCsigmaMCK";
388       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);
389
390       hname="hTPCsigmaMCPion";
391       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);
392
393       hname="hTPCsigmaMCProton";
394       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);
395
396       fOutputPID->Add(hTOFsigmaMCKSigPid);
397       fOutputPID->Add(hTOFsigmaMCPionSigPid);
398       fOutputPID->Add(hTOFsigmaMCProtonSigPid);
399       fOutputPID->Add(hTPCsigmaMCK);
400       fOutputPID->Add(hTPCsigmaMCPion);
401       fOutputPID->Add(hTPCsigmaMCProton);
402
403     }
404   }
405
406   //quality of the tracks
407   if(fOnOff[0]){
408     fOutputTrack=new TList();
409     fOutputTrack->SetOwner();
410     fOutputTrack->SetName(GetOutputSlot(3)->GetContainer()->GetName());
411
412     TString hname="hnClsITS";
413     TH1F* hnClsITS=new TH1F(hname.Data(),"Distribution of number of ITS clusters;nITScls;Entries",7,-0.5,6.5);
414
415     hname="hnClsITSselTr";
416     TH1F* hnClsITSselTr=new TH1F(hname.Data(),"Distribution of number of ITS clusters selected tracks;nITScls;Entries",7,-0.5,6.5);
417
418     hname="hnClsITS-SA";
419     TH1F* hnClsITSSA=new TH1F(hname.Data(),"Distribution of number of ITS clusters(ITS-SA);nITScls;Entries",7,-0.5,6.5);
420
421
422     hname="hnLayerITS";
423     TH1F* hnLayerITS=new TH1F(hname.Data(),"Number of tracks with point in layer;ITS layer;",7,-1.5,5.5);
424     hnLayerITS->GetXaxis()->SetBinLabel(1,"n tracks");
425     hnLayerITS->GetXaxis()->SetBinLabel(2,"SPDin");
426     hnLayerITS->GetXaxis()->SetBinLabel(3,"SPDout");
427     hnLayerITS->GetXaxis()->SetBinLabel(4,"SDDin");
428     hnLayerITS->GetXaxis()->SetBinLabel(5,"SDDout");
429     hnLayerITS->GetXaxis()->SetBinLabel(6,"SSDin");
430     hnLayerITS->GetXaxis()->SetBinLabel(7,"SSDout");
431
432     hname="hnLayerITSsa";
433     TH1F* hnLayerITSsa=new TH1F(hname.Data(),"Number of tracks with point in layer;ITS layer;",7,-1.5,5.5);
434     hnLayerITSsa->GetXaxis()->SetBinLabel(1,"n tracks");
435     hnLayerITSsa->GetXaxis()->SetBinLabel(2,"SPDin");
436     hnLayerITSsa->GetXaxis()->SetBinLabel(3,"SPDout");
437     hnLayerITSsa->GetXaxis()->SetBinLabel(4,"SDDin");
438     hnLayerITSsa->GetXaxis()->SetBinLabel(5,"SDDout");
439     hnLayerITSsa->GetXaxis()->SetBinLabel(6,"SSDin");
440     hnLayerITSsa->GetXaxis()->SetBinLabel(7,"SSDout");
441    
442     hname="hnClsSPD";
443     TH1F* hnClsSPD=new TH1F(hname.Data(),"Distribution of number of SPD clusters;nSPDcls;Entries",3,-0.5,2.5);
444
445     hname="hptGoodTr";
446     TH1F* hptGoodTr=new TH1F(hname.Data(),"Pt distribution of 'good' tracks;p_{t}[GeV];Entries/0.05 GeV/c",400,0.,20.);
447     hptGoodTr->SetTitleOffset(1.3,"Y");
448
449     if(!fSimpleMode){
450       hname="hptGoodTrFromDaugh";
451       TH1F* hptGoodTrFromDaugh=new TH1F(hname.Data(),"Pt distribution of 'good' candidate's daughters;p_{t}[GeV];Entries/0.05 GeV/c",400,0.,20.);
452       hptGoodTrFromDaugh->SetTitleOffset(1.3,"Y");
453       fOutputTrack->Add(hptGoodTrFromDaugh);
454     }
455
456     hname="hdistrGoodTr";
457     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);
458     hdistrGoodTr->SetTitleOffset(1.3,"Y");
459
460     hname="hdistrSelTr";
461     TH1F* hdistrSelTr=new TH1F(hname.Data(),"Distribution of number of Selected tracks per event;no.good-tracks/ev;Entries",4000,-0.5,3999.5);
462     hdistrSelTr->SetTitleOffset(1.3,"Y");
463
464     hname="hd0";
465     TH1F* hd0=new TH1F(hname.Data(),"Impact parameter (rphi) distribution of 'good' tracks;d_{0rphi}[cm];Entries/10^{3} cm",200,-0.1,0.1);
466
467     hname="hd0z";
468     TH1F* hd0z=new TH1F(hname.Data(),"Impact parameter (z) distribution of 'good' tracks;d_{0z}[cm];Entries/10^{3} cm",200,-0.1,0.1);
469
470     fOutputTrack->Add(hnClsITS);
471     fOutputTrack->Add(hnClsITSselTr);
472     fOutputTrack->Add(hnClsITSSA);
473     fOutputTrack->Add(hnLayerITS);
474     fOutputTrack->Add(hnLayerITSsa);
475     fOutputTrack->Add(hnClsSPD);
476     fOutputTrack->Add(hptGoodTr);
477     fOutputTrack->Add(hdistrGoodTr);
478     fOutputTrack->Add(hdistrSelTr);
479     fOutputTrack->Add(hd0);
480     fOutputTrack->Add(hd0z);
481
482     if(fReadMC){
483       hname="hdistrFakeTr";
484       TH1F* hdistrFakeTr=new TH1F(hname.Data(),"Distribution of number of fake tracks per event;no.fake-tracks/ev;Entries",4000,-0.5,3999.5);
485       hdistrFakeTr->SetTitleOffset(1.3,"Y");
486
487       hname="hd0f";
488       TH1F* hd0f=new TH1F(hname.Data(),"Impact parameter distribution of fake tracks;d_{0}[cm];Entries/10^{3} cm",200,-0.1,0.1);
489
490       hname="hptFakeTr";
491       TH1F* hptFakeTr=new TH1F(hname.Data(),"Pt distribution of fake tracks;p_{t}[GeV];Entries/0.05 GeV/c",400,0.,20.);
492       hptFakeTr->SetTitleOffset(1.3,"Y");
493       if(!fSimpleMode){
494         hname="hptFakeTrFromDaugh";
495         TH1F* hptFakeTrFromDaugh=new TH1F(hname.Data(),"Pt distribution of fake tracks from daughters;p_{t}[GeV];Entries/0.05 GeV/c",400,0.,20.);
496         hptFakeTrFromDaugh->SetTitleOffset(1.3,"Y");
497         fOutputTrack->Add(hptFakeTrFromDaugh);
498       }
499
500       fOutputTrack->Add(hptFakeTr);
501       fOutputTrack->Add(hdistrFakeTr);
502       fOutputTrack->Add(hd0f);
503    
504     }
505   }
506
507   
508   if(fOnOff[2] && fCuts->GetUseCentrality()){
509
510     //Centrality (Counters)
511     fOutputCounters=new TList();
512     fOutputCounters->SetOwner();
513     fOutputCounters->SetName(GetOutputSlot(5)->GetContainer()->GetName());
514
515     AliCounterCollection *stdEstimator=new AliCounterCollection("stdEstimator");
516     stdEstimator->AddRubric("run",500000);
517     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");
518     stdEstimator->Init();
519     AliCounterCollection *secondEstimator=new AliCounterCollection("secondEstimator");
520     secondEstimator->AddRubric("run",500000);
521     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");
522     secondEstimator->Init();
523  
524     fOutputCounters->Add(stdEstimator);
525     fOutputCounters->Add(secondEstimator);
526  
527     //Centrality (Checks)
528     fOutputCheckCentrality=new TList();
529     fOutputCheckCentrality->SetOwner();
530     fOutputCheckCentrality->SetName(GetOutputSlot(6)->GetContainer()->GetName());
531
532     TString hname="hNtrackletsIn";
533     TH1F* hNtrackletsIn=new TH1F(hname.Data(),"Number of tracklets in Centrality range;ntracklets;Entries",5000,-0.5,4999.5);
534
535     hname="hMultIn";
536     TH1F* hMultIn=new TH1F(hname.Data(),"Multiplicity;multiplicity in Centrality range;Entries",10000,-0.5,9999.5);
537
538     hname="hNtrackletsOut";
539     TH1F* hNtrackletsOut=new TH1F(hname.Data(),"Number of tracklets out of Centrality range;ntracklets;Entries",5000,-0.5,4999.5);
540
541     hname="hMultOut";
542     TH1F* hMultOut=new TH1F(hname.Data(),"Multiplicity out of Centrality range;multiplicity;Entries",10000,-0.5,9999.5);
543
544     hname="hMultvsPercentile";
545     TH2F* hMultvsPercentile=new TH2F(hname.Data(),"Multiplicity vs Percentile;multiplicity;percentile",10000,-0.5,9999.5,240,-10.,110);
546
547     hname="hntrklvsPercentile";
548     TH2F* hntrklvsPercentile=new TH2F(hname.Data(),"N tracklets vs Percentile;ntracklets;percentile",5000,-0.5,4999.5,240,-10.,110);
549
550     hname="hnTPCTracksvsPercentile";
551     TH2F* hnTPCTracksvsPercentile=new TH2F(hname.Data(),"N TPC tracks vs Percentile;nTPCTracks;percentile",5000,-0.5,9999.5,240,-10.,110);
552
553     hname="hnTPCITSTracksvsPercentile";
554     TH2F* hnTPCITSTracksvsPercentile=new TH2F(hname.Data(),"N TPC+ITS tracks vs Percentile;nTPCITSTracks;percentile",5000,-0.5,9999.5,240,-10.,110);
555
556     hname="hnTPCITS1SPDTracksvsPercentile";
557     TH2F* hnTPCITS1SPDTracksvsPercentile=new TH2F(hname.Data(),"N TPC+ITS+1SPD tracks vs Percentile;nTPCITS1SPDTracks;percentile",5000,-0.5,9999.5,240,-10.,110);
558
559     hname="hV0MultiplicityPercentile";
560     TH2F*hV0MultiplicityPercentile = new TH2F(hname.Data(),"V0 Multiplicity vs Percentile;V0 multiplicity;percentile",1000,-0.5,9999.5,120,-10.,110);
561
562     hname="hV0MultiplicityNtrackletsIn";
563     TH2F*hV0MultiplicityNtrackletsIn = new TH2F(hname.Data(),"V0 Multiplicity vs Number of tracklets in the CC;V0 multiplicity;percentile",1000,-0.5,9999.5,5000,-0.5,4999.5);
564
565     hname="hStdPercentileSPDPercentile";
566     TH2F* hStdPercentileSPDPercentile = new TH2F(hname.Data(),"Std estimator Percentile Vs SPD Percentile;Std estimator percentile;SPD percentile",120,-10.,110,120,-10.,110);
567
568     fOutputCheckCentrality->Add(hNtrackletsIn);
569     fOutputCheckCentrality->Add(hNtrackletsOut);
570     fOutputCheckCentrality->Add(hMultIn);
571     fOutputCheckCentrality->Add(hMultOut);
572     fOutputCheckCentrality->Add(hMultvsPercentile);
573     fOutputCheckCentrality->Add(hntrklvsPercentile);
574     fOutputCheckCentrality->Add(hnTPCTracksvsPercentile);
575     fOutputCheckCentrality->Add(hnTPCITSTracksvsPercentile);
576     fOutputCheckCentrality->Add(hnTPCITS1SPDTracksvsPercentile);
577     fOutputCheckCentrality->Add(hV0MultiplicityPercentile);
578     fOutputCheckCentrality->Add(hV0MultiplicityNtrackletsIn);
579     fOutputCheckCentrality->Add(hStdPercentileSPDPercentile);
580
581     PostData(6,fOutputCheckCentrality);
582   
583   } else{
584     if(fOnOff[0]){
585       TString hname="hNtracklets";
586       TH1F* hNtracklets=new TH1F(hname.Data(),"Number of tracklets;ntracklets;Entries",5000,-0.5,4999.5);
587
588       hname="hMult";
589       TH1F* hMult=new TH1F(hname.Data(),"Multiplicity;multiplicity;Entries",10000,-0.5,9999.5);
590       fOutputTrack->Add(hNtracklets);
591       fOutputTrack->Add(hMult);
592     }
593   }
594
595   //event selection (z vertex for the moment)
596   if(fOnOff[3]){
597     fOutputEvSelection=new TList();
598     fOutputEvSelection->SetOwner();
599     fOutputEvSelection->SetName(GetOutputSlot(7)->GetContainer()->GetName());
600     AliCounterCollection *evselection=new AliCounterCollection("evselection");
601     evselection->AddRubric("run",500000);
602     evselection->AddRubric("evnonsel","zvtx");
603     evselection->Init();
604
605     TH1F* hxvtx=new TH1F("hxvtx", "Distribution of x_{VTX};x_{VTX} [cm];Entries",100,-1,1);
606     TH1F* hyvtx=new TH1F("hyvtx", "Distribution of y_{VTX};y_{VTX} [cm];Entries",100,-1,1);
607     TH1F* hzvtx=new TH1F("hzvtx", "Distribution of z_{VTX};z_{VTX} [cm];Entries",100,-30,30);
608     TH1F* hxvtxSelEv=new TH1F("hxvtxSelEv", "Distribution of x_{VTX} Selected Ev;x_{VTX} [cm];Entries",100,-1,1);
609     TH1F* hyvtxSelEv=new TH1F("hyvtxSelEv", "Distribution of y_{VTX} Selected Ev;y_{VTX} [cm];Entries",100,-1,1);
610     TH1F* hzvtxSelEv=new TH1F("hzvtxSelEv", "Distribution of z_{VTX} Selected Ev;z_{VTX} [cm];Entries",100,-30,30);
611     TH1F* hWhichVert=new TH1F("hWhichVert","Vertex Type",4,-1.5,2.5);
612     hWhichVert->GetXaxis()->SetBinLabel(1,"Not found");
613     hWhichVert->GetXaxis()->SetBinLabel(2,"Track");
614     hWhichVert->GetXaxis()->SetBinLabel(3,"SPD-3D");
615     hWhichVert->GetXaxis()->SetBinLabel(4,"SPD-z");
616     TH1F* hWhichVertSelEv=new TH1F("hWhichVertSelEv","Vertex Type",4,-1.5,2.5);
617     hWhichVertSelEv->GetXaxis()->SetBinLabel(1,"Not found");
618     hWhichVertSelEv->GetXaxis()->SetBinLabel(2,"Track");
619     hWhichVertSelEv->GetXaxis()->SetBinLabel(3,"SPD-3D");
620     hWhichVertSelEv->GetXaxis()->SetBinLabel(4,"SPD-z");
621
622     TH2F* hTrigCent=new TH2F("hTrigCent","Centrality vs. Trigger types",12,-1.5,10.5,12,-10,110);
623     hTrigCent->GetXaxis()->SetBinLabel(1,"All");
624     hTrigCent->GetXaxis()->SetBinLabel(2,"kAny");
625     hTrigCent->GetXaxis()->SetBinLabel(3,"kMB");
626     hTrigCent->GetXaxis()->SetBinLabel(4,"kINT7");
627     hTrigCent->GetXaxis()->SetBinLabel(5,"kCINT5");
628     hTrigCent->GetXaxis()->SetBinLabel(6,"kCent");
629     hTrigCent->GetXaxis()->SetBinLabel(7,"kSemiCent");
630     hTrigCent->GetXaxis()->SetBinLabel(8,"kEMC1+7");
631     hTrigCent->GetXaxis()->SetBinLabel(9,"kEMCJET+GAMMA");
632     hTrigCent->GetXaxis()->SetBinLabel(10,"Muons");
633     hTrigCent->GetXaxis()->SetBinLabel(11,"PHOS");
634     hTrigCent->GetXaxis()->SetBinLabel(12,"Others");
635
636     TH2F* hTrigMul=new TH2F("hTrigMul","Multiplicity vs. Trigger types",12,-1.5,10.5,100,0.,10000.);
637     hTrigMul->GetXaxis()->SetBinLabel(1,"All");
638     hTrigMul->GetXaxis()->SetBinLabel(2,"kAny");
639     hTrigMul->GetXaxis()->SetBinLabel(3,"kMB");
640     hTrigMul->GetXaxis()->SetBinLabel(4,"kINT7");
641     hTrigMul->GetXaxis()->SetBinLabel(5,"kCINT5");
642     hTrigMul->GetXaxis()->SetBinLabel(6,"kCent");
643     hTrigMul->GetXaxis()->SetBinLabel(7,"kSemiCent");
644     hTrigMul->GetXaxis()->SetBinLabel(8,"kEMC1+7");
645     hTrigMul->GetXaxis()->SetBinLabel(9,"kEMCJET+GAMMA");
646     hTrigMul->GetXaxis()->SetBinLabel(10,"Muons");
647     hTrigMul->GetXaxis()->SetBinLabel(11,"PHOS");
648     hTrigMul->GetXaxis()->SetBinLabel(12,"Others");
649
650     TH2F* hTrigCentSel=new TH2F("hTrigCentSel","Trigger types",12,-1.5,10.5,12,-10,110);
651     hTrigCentSel->GetXaxis()->SetBinLabel(1,"All");
652     hTrigCentSel->GetXaxis()->SetBinLabel(2,"kAny");
653     hTrigCentSel->GetXaxis()->SetBinLabel(3,"kMB");
654     hTrigCentSel->GetXaxis()->SetBinLabel(4,"kINT7");
655     hTrigCentSel->GetXaxis()->SetBinLabel(5,"kCINT5");
656     hTrigCentSel->GetXaxis()->SetBinLabel(6,"kCent");
657     hTrigCentSel->GetXaxis()->SetBinLabel(7,"kSemiCent");
658     hTrigCentSel->GetXaxis()->SetBinLabel(8,"kEMC1+7");
659     hTrigCentSel->GetXaxis()->SetBinLabel(9,"kEMCJET+GAMMA");
660     hTrigCentSel->GetXaxis()->SetBinLabel(10,"Muons");
661     hTrigCentSel->GetXaxis()->SetBinLabel(11,"PHOS");
662     hTrigCentSel->GetXaxis()->SetBinLabel(12,"Others");
663
664     AliCounterCollection *trigCounter=new AliCounterCollection("trigCounter");
665     trigCounter->AddRubric("run",500000);
666     trigCounter->AddRubric("triggerType","All/Any/MB/Cent/SemiCent/EMCAL/MUON/NoPhysSelMUON/NoPhysSelEvNot7/NoPhysSelCMUP1/NoPhysSelMB/NoPhysSelCent/NoPhysSelSemiCent");
667     trigCounter->Init();
668
669     fOutputEvSelection->Add(evselection);
670     fOutputEvSelection->Add(hxvtx);
671     fOutputEvSelection->Add(hyvtx);
672     fOutputEvSelection->Add(hzvtx);
673     fOutputEvSelection->Add(hxvtxSelEv);
674     fOutputEvSelection->Add(hyvtxSelEv);
675     fOutputEvSelection->Add(hzvtxSelEv);
676     fOutputEvSelection->Add(hWhichVert);
677     fOutputEvSelection->Add(hWhichVertSelEv);
678     fOutputEvSelection->Add(hTrigCent);
679     fOutputEvSelection->Add(hTrigMul);
680     fOutputEvSelection->Add(hTrigCentSel);
681     fOutputEvSelection->Add(trigCounter);
682   }
683   if(fOnOff[4]){ // FLOW OBSERVABLES
684     fOutputFlowObs=new TList();
685     fOutputFlowObs->SetOwner();
686     fOutputFlowObs->SetName(GetOutputSlot(8)->GetContainer()->GetName());
687
688     fFlowEvent = new AliFlowEvent(3000);
689     fRFPcuts = new AliFlowTrackCuts("rfpCuts");
690
691     TH2F *hFEvents = new TH2F("hFlowEvents","FlowEvent Selection",7,0,7,7,-10,60);
692     hFEvents->GetXaxis()->SetBinLabel(1,"REACHED");
693     hFEvents->GetXaxis()->SetBinLabel(2,"TRIGGERED");
694     hFEvents->GetXaxis()->SetBinLabel(3,"kMB");
695     hFEvents->GetXaxis()->SetBinLabel(4,"kCent");
696     hFEvents->GetXaxis()->SetBinLabel(5,"kSemiC");
697     hFEvents->GetXaxis()->SetBinLabel(6,"Triggered + vtx cut");
698     hFEvents->GetXaxis()->SetBinLabel(7,"UnexpectedBehaviour");
699     fOutputFlowObs->Add(hFEvents);
700
701     TProfile2D *hQ[3];
702     TH2F *hAngleQ[3];
703     TH3F *hPhiEta[3];
704     TString ref[3] = {"FB1","FB128","VZE"};
705     Int_t etabin[3] = {40,40,20};
706     Int_t etamax[3] = { 1, 1, 5};
707     for(Int_t i=0; i<3; ++i) {
708       hQ[i]= new TProfile2D( Form("h%s_Q",ref[i].Data()),
709                              Form("Q_{2} components for %s",ref[i].Data()),
710                              4,0,4,12,0,60,"s");
711       hQ[i]->GetXaxis()->SetBinLabel(1,"Qx^{-}");
712       hQ[i]->GetXaxis()->SetBinLabel(2,"Qy^{-}");
713       hQ[i]->GetXaxis()->SetBinLabel(3,"Qx^{+}");
714       hQ[i]->GetXaxis()->SetBinLabel(4,"Qy^{+}");
715       hQ[i]->GetYaxis()->SetTitle("Centrality");
716       fOutputFlowObs->Add(hQ[i]);
717
718       hAngleQ[i] = new TH2F( Form("h%s_AngleQ",ref[i].Data()),
719                              Form("#Psi_{2} for %s",ref[i].Data()),
720                              72,0,TMath::Pi(),12,0,60);
721       hAngleQ[i]->GetXaxis()->SetTitle( Form("#Psi_{2}^{%s}",ref[i].Data()) );
722       hAngleQ[i]->GetYaxis()->SetTitle("Centrality");
723       fOutputFlowObs->Add(hAngleQ[i]);
724
725       hPhiEta[i] = new TH3F( Form("h%s_PhiEta",ref[i].Data()),
726                              Form("Eta vs Phi for %s",ref[i].Data()),
727                              144,0,TMath::TwoPi(),etabin[i],-1.0*etamax[i],+1.0*etamax[i],12,0,60);
728       hPhiEta[i]->GetXaxis()->SetTitle("Phi");
729       hPhiEta[i]->GetYaxis()->SetTitle("Eta");
730       hPhiEta[i]->GetZaxis()->SetTitle("Centrality");
731       fOutputFlowObs->Add(hPhiEta[i]);
732
733     }
734     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);
735     hTPCVZE_AngleQ->GetXaxis()->SetTitle("#Psi_{2}^{TPC}");
736     hTPCVZE_AngleQ->GetYaxis()->SetTitle("#Psi_{2}^{VZE}");
737     hTPCVZE_AngleQ->GetZaxis()->SetTitle("Centrality");
738     fOutputFlowObs->Add(hTPCVZE_AngleQ);
739
740     TH2F *hCentVsMultRPS = new TH2F("hCentVsMultRPS", " Centrality Vs. Multiplicity RPs",5000, 0, 5000.,12,0,60 );
741     hCentVsMultRPS->GetXaxis()->SetTitle("Multiplicity RPs");
742     hCentVsMultRPS->GetYaxis()->SetTitle("Centrality");
743     fOutputFlowObs->Add(hCentVsMultRPS);
744   }
745
746   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
747   AliInputEventHandler *inputHandler=(AliInputEventHandler*)mgr->GetInputEventHandler();
748   AliPIDResponse *pidResp=inputHandler->GetPIDResponse();
749   if (fCuts->GetIsUsePID() && fDecayChannel==kLambdactoV0) {
750     fCuts->GetPidHF()->SetPidResponse(pidResp);
751     (dynamic_cast<AliRDHFCutsLctoV0*>(fCuts))->GetPidV0pos()->SetPidResponse(pidResp);
752     (dynamic_cast<AliRDHFCutsLctoV0*>(fCuts))->GetPidV0neg()->SetPidResponse(pidResp);
753     fCuts->GetPidHF()->SetOldPid(kFALSE);
754     (dynamic_cast<AliRDHFCutsLctoV0*>(fCuts))->GetPidV0pos()->SetOldPid(kFALSE);
755     (dynamic_cast<AliRDHFCutsLctoV0*>(fCuts))->GetPidV0neg()->SetOldPid(kFALSE);
756   }
757
758   // Post the data
759   PostData(1,fNEntries);
760
761   if(fOnOff[1]) PostData(2,fOutputPID);
762   if(fOnOff[0]) PostData(3,fOutputTrack);
763   PostData(4,fCuts);
764   if(fOnOff[2]) PostData(5,fOutputCounters);
765   if(fOnOff[3]) PostData(7,fOutputEvSelection);
766   if(fOnOff[4]) PostData(8,fOutputFlowObs);
767
768   if(!fOnOff[0] && !fOnOff[1] && !fOnOff[2]) AliError("Nothing will be filled!");
769 }
770
771 //___________________________________________________________________________
772 void AliAnalysisTaskSEHFQA::UserExec(Option_t */*option*/)
773 {
774   // Execute analysis for current event
775
776   AliAODEvent *aod = dynamic_cast<AliAODEvent*> (InputEvent());
777   if(fDebug>2) printf("Analysing decay %d\n",fDecayChannel);
778   // Post the data already here
779   PostData(1,fNEntries);
780   if(fOnOff[1]) PostData(2,fOutputPID);
781   if(fOnOff[0]) PostData(3,fOutputTrack);
782   PostData(4,fCuts);
783   if(fOnOff[2]) {
784     PostData(5,fOutputCounters);
785     if(fCuts->GetUseCentrality()) PostData(6,fOutputCheckCentrality);
786   }
787
788   TClonesArray *arrayProng =0;
789   Int_t pdg=0;
790   Int_t *pdgdaughters=0x0;
791
792   if(!aod && AODEvent() && IsStandardAOD()) { 
793     // In case there is an AOD handler writing a standard AOD, use the AOD 
794     // event in memory rather than the input (ESD) event.    
795     aod = dynamic_cast<AliAODEvent*> (AODEvent());
796     // in this case the braches in the deltaAOD (AliAOD.VertexingHF.root)
797     // have to taken from the AOD event hold by the AliAODExtension
798     AliAODHandler* aodHandler = (AliAODHandler*) 
799       ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
800     if(aodHandler->GetExtensions()) {
801       
802       AliAODExtension *ext = (AliAODExtension*)aodHandler->GetExtensions()->FindObject("AliAOD.VertexingHF.root");
803       AliAODEvent *aodFromExt = ext->GetAOD();
804    
805    
806       
807       switch(fDecayChannel){
808       case 0:
809         arrayProng=(TClonesArray*)aodFromExt->GetList()->FindObject("Charm3Prong");
810         pdg=411;
811         if(fReadMC){
812           pdgdaughters =new Int_t[3];
813           pdgdaughters[0]=211;//pi
814           pdgdaughters[1]=321;//K
815           pdgdaughters[2]=211;//pi
816         }
817         break; 
818       case 1:
819         arrayProng=(TClonesArray*)aodFromExt->GetList()->FindObject("D0toKpi");
820         pdg=421;
821         if(fReadMC){
822           pdgdaughters =new Int_t[2];
823           pdgdaughters[0]=211;//pi 
824           pdgdaughters[1]=321;//K
825         }
826         break; 
827       case 2:
828         arrayProng=(TClonesArray*)aodFromExt->GetList()->FindObject("Dstar");
829         pdg=413;
830         if(fReadMC){
831           pdgdaughters =new Int_t[3];
832           pdgdaughters[1]=211;//pi
833           pdgdaughters[0]=321;//K
834           pdgdaughters[2]=211;//pi (soft?)
835         }
836         break; 
837       case 3:
838         arrayProng=(TClonesArray*)aodFromExt->GetList()->FindObject("Charm3Prong");
839         pdg=431;
840         if(fReadMC){
841           pdgdaughters =new Int_t[3];
842           pdgdaughters[0]=321;//K
843           pdgdaughters[1]=321;//K
844           pdgdaughters[2]=211;//pi
845         }
846         break; 
847       case 4:
848         arrayProng=(TClonesArray*)aodFromExt->GetList()->FindObject("Charm4Prong");
849         pdg=421;
850         if(fReadMC){
851           pdgdaughters =new Int_t[4];
852           pdgdaughters[0]=321;
853           pdgdaughters[1]=211;
854           pdgdaughters[2]=211;
855           pdgdaughters[3]=211;
856         }
857         break; 
858       case 5:
859         arrayProng=(TClonesArray*)aodFromExt->GetList()->FindObject("Charm3Prong");
860         pdg=4122;
861         if(fReadMC){
862           pdgdaughters =new Int_t[3];
863           pdgdaughters[0]=2212;//p
864           pdgdaughters[1]=321;//K
865           pdgdaughters[2]=211;//pi
866         }
867         break; 
868       case kLambdactoV0:
869         arrayProng=(TClonesArray*)aodFromExt->GetList()->FindObject("CascadesHF");
870         pdg=4122;
871         if(fReadMC){
872           pdgdaughters =new Int_t[3];
873           pdgdaughters[0]=2212;//p
874           pdgdaughters[1]=211;//pi
875           pdgdaughters[2]=211;//pi
876         }
877         break; 
878       }
879     }
880   } else if(aod) {
881     switch(fDecayChannel){
882     case 0:
883       arrayProng=(TClonesArray*)aod->GetList()->FindObject("Charm3Prong");
884       pdg=411;
885       if(fReadMC){
886         pdgdaughters =new Int_t[3];
887         pdgdaughters[0]=211;//pi
888         pdgdaughters[1]=321;//K
889         pdgdaughters[2]=211;//pi
890       }
891       break; 
892     case 1:
893       arrayProng=(TClonesArray*)aod->GetList()->FindObject("D0toKpi");
894       pdg=421;
895       if(fReadMC){
896         pdgdaughters =new Int_t[2];
897         pdgdaughters[0]=211;//pi 
898         pdgdaughters[1]=321;//K
899       }
900       break; 
901     case 2:
902       arrayProng=(TClonesArray*)aod->GetList()->FindObject("Dstar");
903       pdg=413;
904       if(fReadMC){
905         pdgdaughters =new Int_t[3];
906         pdgdaughters[1]=211;//pi
907         pdgdaughters[0]=321;//K
908         pdgdaughters[2]=211;//pi (soft?)
909       }
910       break; 
911     case 3:
912       arrayProng=(TClonesArray*)aod->GetList()->FindObject("Charm3Prong");
913       pdg=431;
914       if(fReadMC){
915         pdgdaughters =new Int_t[3];
916         pdgdaughters[0]=321;//K
917         pdgdaughters[1]=321;//K
918         pdgdaughters[2]=211;//pi
919       }
920       break; 
921     case 4:
922       arrayProng=(TClonesArray*)aod->GetList()->FindObject("Charm4Prong");
923       pdg=421;
924       if(fReadMC){
925         pdgdaughters =new Int_t[4];
926         pdgdaughters[0]=321;
927         pdgdaughters[1]=211;
928         pdgdaughters[2]=211;
929         pdgdaughters[3]=211;
930       }
931       break; 
932     case 5:
933       arrayProng=(TClonesArray*)aod->GetList()->FindObject("Charm3Prong");
934       pdg=4122;
935       if(fReadMC){
936         pdgdaughters =new Int_t[3];
937         pdgdaughters[0]=2212;//p
938         pdgdaughters[1]=321;//K
939         pdgdaughters[2]=211;//pi
940       }
941       break; 
942       case kLambdactoV0:
943         arrayProng=(TClonesArray*)aod->GetList()->FindObject("CascadesHF");
944         pdg=4122;
945         if(fReadMC){
946           pdgdaughters =new Int_t[3];
947           pdgdaughters[0]=2212;//p
948           pdgdaughters[1]=211;//pi
949           pdgdaughters[2]=211;//pi
950         }
951         break; 
952     }
953   }
954   Bool_t isSimpleMode=fSimpleMode;
955   if(!arrayProng) {
956     AliInfo("Branch not found! The output will contain only trak related histograms\n");
957     isSimpleMode=kTRUE;
958     fNEntries->Fill(2);
959   }
960   
961   TClonesArray *mcArray = 0;
962   AliAODMCHeader *mcHeader = 0;
963
964   if(!aod) {
965     delete [] pdgdaughters;
966     return;
967   }
968
969   //check if MC
970   if(fReadMC) {
971     // load MC particles
972     mcArray = (TClonesArray*)aod->GetList()->FindObject(AliAODMCParticle::StdBranchName());
973     if(!mcArray) {
974       printf("AliAnalysisTaskSEHFQA::UserExec: MC particles branch not found!\n");
975       delete [] pdgdaughters;
976       return;
977     }
978     
979     // load MC header
980     mcHeader = (AliAODMCHeader*)aod->GetList()->FindObject(AliAODMCHeader::StdBranchName());
981     if(!mcHeader) {
982       printf("AliAnalysisTaskSEHFQA::UserExec: MC header branch not found!\n");
983       delete [] pdgdaughters;
984       return;
985     }
986   }
987
988   
989   UInt_t evSelMask=((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected();
990   Double_t centrality=fCuts->GetCentrality(aod);
991   Double_t multiplicity=aod->GetHeader()->GetRefMultiplicity();
992   Int_t runNumber = aod->GetRunNumber();
993   TString trigClass=aod->GetFiredTriggerClasses();
994   Int_t nAODtracks=aod->GetNTracks();
995   Int_t nSelTracksTPCOnly=0;
996   Int_t nSelTracksTPCITS=0;
997   Int_t nSelTracksTPCITS1SPD=0;
998
999   for (Int_t k=0;k<nAODtracks;k++){
1000     AliAODTrack* track=aod->GetTrack(k);
1001     if(track->GetID()<0) continue;
1002     Int_t nclsTot=0,nclsSPD=0;
1003     for(Int_t l=0;l<6;l++) {
1004       if(TESTBIT(track->GetITSClusterMap(),l)) {
1005         nclsTot++; if(l<2) nclsSPD++;
1006       }
1007     }
1008     UShort_t nTPCClus=track->GetTPCClusterMap().CountBits();
1009     if(TMath::Abs(track->Eta())<0.8 && nTPCClus>=70 && track->GetStatus()&AliESDtrack::kTPCrefit){
1010       if(track->TestFilterBit(1))  nSelTracksTPCOnly++;
1011       if(track->GetStatus()&AliESDtrack::kITSrefit){
1012         nSelTracksTPCITS++;
1013         if(nclsSPD>0) nSelTracksTPCITS1SPD++;      
1014       }
1015     }
1016   }
1017
1018   if(fOnOff[4]) {
1019     FillFlowObs(aod);
1020     PostData(8,fOutputFlowObs);
1021   }
1022   if(fOnOff[3]){
1023     TH2F* hTrigC=(TH2F*)fOutputEvSelection->FindObject("hTrigCent");
1024     TH2F* hTrigM=(TH2F*)fOutputEvSelection->FindObject("hTrigMul");
1025     AliCounterCollection* trigCount=(AliCounterCollection*)fOutputEvSelection->FindObject("trigCounter");
1026
1027     hTrigC->Fill(-1.,centrality);
1028     hTrigM->Fill(-1.,multiplicity);
1029     trigCount->Count(Form("triggerType:All/Run:%d",runNumber));
1030     if(evSelMask==0){
1031       if(aod->GetEventType()!=7){
1032         trigCount->Count(Form("triggerType:NoPhysSelEvNot7/Run:%d",runNumber));
1033       }else if(trigClass.Contains("CMUP1")){
1034         trigCount->Count(Form("triggerType:NoPhysSelCMUP1/Run:%d",runNumber));
1035       }else if(trigClass.Contains("MUON")){
1036         trigCount->Count(Form("triggerType:NoPhysSelMUON/Run:%d",runNumber));
1037       }else if(trigClass.Contains("CPBI2_B1-B") || trigClass.Contains(" CPBI2WU_B1-B")){
1038         trigCount->Count(Form("triggerType:NoPhysSelMB/Run:%d",runNumber));
1039       }else if(trigClass.Contains("CCENT") || trigClass.Contains("CVHN")){
1040         trigCount->Count(Form("triggerType:NoPhysSelCent/Run:%d",runNumber));
1041       }else if(trigClass.Contains("CSEMI") || trigClass.Contains("CVLN")){
1042         trigCount->Count(Form("triggerType:NoPhysSelSemiCent/Run:%d",runNumber));
1043       }
1044     }
1045     if(evSelMask & AliVEvent::kAny){
1046       hTrigC->Fill(0.,centrality);
1047       hTrigM->Fill(0.,multiplicity);
1048       trigCount->Count(Form("triggerType:Any/Run:%d",runNumber));
1049     }  
1050     if(evSelMask & AliVEvent::kMB){
1051       hTrigC->Fill(1.,centrality);
1052       hTrigM->Fill(1.,multiplicity);
1053       trigCount->Count(Form("triggerType:MB/Run:%d",runNumber));
1054     }
1055     if(evSelMask & AliVEvent::kINT7){ 
1056       hTrigC->Fill(2.,centrality);
1057       hTrigM->Fill(2.,multiplicity);
1058     }
1059     if(evSelMask & AliVEvent::kCINT5){ 
1060       hTrigC->Fill(3.,centrality);
1061       hTrigM->Fill(3.,multiplicity);
1062     }
1063     if(evSelMask & AliVEvent::kCentral){
1064       hTrigC->Fill(4.,centrality);
1065       hTrigM->Fill(4.,multiplicity);
1066       trigCount->Count(Form("triggerType:Cent/Run:%d",runNumber));
1067     }
1068     if(evSelMask & AliVEvent::kSemiCentral){ 
1069       hTrigC->Fill(5.,centrality);
1070       hTrigM->Fill(5.,multiplicity);
1071       trigCount->Count(Form("triggerType:SemiCent/Run:%d",runNumber));
1072     }
1073     if(evSelMask & (AliVEvent::kEMC1 | AliVEvent::kEMC7)){
1074       hTrigC->Fill(6.,centrality);
1075       hTrigM->Fill(6.,multiplicity);
1076     }
1077     if(evSelMask & (AliVEvent::kEMCEJE | AliVEvent::kEMCEGA)){
1078       hTrigC->Fill(7.,centrality);
1079       hTrigM->Fill(7.,multiplicity);
1080       trigCount->Count(Form("triggerType:EMCAL/Run:%d",runNumber));
1081     }
1082     if(evSelMask & (((AliVEvent::kCMUS5 | AliVEvent::kMUSH7) | (AliVEvent::kMUL7 | AliVEvent::kMUU7)) |  (AliVEvent::kMUS7 | AliVEvent::kMUON))){
1083       hTrigC->Fill(8.,centrality);
1084       hTrigM->Fill(8.,multiplicity);
1085       trigCount->Count(Form("triggerType:MUON/Run:%d",runNumber));
1086     }
1087     if(evSelMask & (AliVEvent::kPHI1 | AliVEvent::kPHI7)){ 
1088       hTrigC->Fill(9.,centrality);
1089       hTrigM->Fill(9.,multiplicity);
1090     }
1091     if(evSelMask & (AliVEvent::kDG5 | AliVEvent::kZED)){
1092       hTrigC->Fill(10.,centrality);
1093       hTrigM->Fill(10.,multiplicity);
1094     }
1095   }
1096   
1097
1098   // fix for temporary bug in ESDfilter 
1099   // the AODs with null vertex pointer didn't pass the PhysSel
1100   if(!aod->GetPrimaryVertex() || TMath::Abs(aod->GetMagneticField())<0.001) {
1101     delete [] pdgdaughters;
1102     return;
1103   }
1104
1105   // count event
1106   fNEntries->Fill(0); 
1107
1108   //count events with good vertex
1109   // AOD primary vertex
1110   AliAODVertex *vtx1 = (AliAODVertex*)aod->GetPrimaryVertex();
1111
1112   Double_t pos[3],cov[6];
1113   vtx1->GetXYZ(pos);
1114   vtx1->GetCovarianceMatrix(cov);
1115   const AliESDVertex vESD(pos,cov,100.,100);
1116
1117   TString primTitle = vtx1->GetTitle();
1118   if(primTitle.Contains("VertexerTracks") && vtx1->GetNContributors()>0) fNEntries->Fill(4);
1119
1120   // trigger class for PbPb C0SMH-B-NOPF-ALLNOTRD, C0SMH-B-NOPF-ALL
1121   //TString trigclass=aod->GetFiredTriggerClasses();
1122   //if(trigclass.Contains("C0SMH-B-NOPF-ALLNOTRD") || trigclass.Contains("C0SMH-B-NOPF-ALL")) fNEntries->Fill(5); //tmp
1123
1124
1125
1126
1127   Bool_t evSelbyCentrality=kTRUE,evSelected=kTRUE,evSelByVertex=kTRUE,evselByPileup=kTRUE,evSelByPS=kTRUE;
1128   //select event
1129   if(!fCuts->IsEventSelected(aod)) {
1130     evSelected=kFALSE;
1131     if(fCuts->GetWhyRejection()==1) {fNEntries->Fill(1); evselByPileup=kFALSE;}// rejected for pileup
1132     if(fCuts->GetWhyRejection()==2 || fCuts->GetWhyRejection()==3) evSelbyCentrality=kFALSE; //rejected by centrality
1133     if(fCuts->GetWhyRejection()==4) evSelByVertex=kFALSE; //rejected by vertex
1134     if(fCuts->GetWhyRejection()==5) fNEntries->Fill(5);//tmp
1135     if(fCuts->GetWhyRejection()==6 && fOnOff[3]) ((AliCounterCollection*)fOutputEvSelection->FindObject("evselection"))->Count(Form("evnonsel:zvtx/Run:%d",runNumber));
1136     if(fCuts->GetWhyRejection()==7) { evSelByPS=kFALSE; }
1137   }
1138   if(evSelected){
1139     TH2F* hTrigS=(TH2F*)fOutputEvSelection->FindObject("hTrigCentSel");
1140     hTrigS->Fill(-1.,centrality);
1141
1142     if(evSelMask & AliVEvent::kAny) hTrigS->Fill(0.,centrality);
1143     if(evSelMask & AliVEvent::kMB) hTrigS->Fill(1.,centrality);
1144     if(evSelMask & AliVEvent::kINT7) hTrigS->Fill(2.,centrality);
1145     if(evSelMask & AliVEvent::kCINT5) hTrigS->Fill(3.,centrality);
1146     if(evSelMask & AliVEvent::kCentral) hTrigS->Fill(4.,centrality);
1147     if(evSelMask & AliVEvent::kSemiCentral) hTrigS->Fill(5.,centrality);
1148     if(evSelMask & (AliVEvent::kEMC1 | AliVEvent::kEMC7)) hTrigS->Fill(6.,centrality);
1149     if(evSelMask & (AliVEvent::kEMCEJE | AliVEvent::kEMCEGA)) hTrigS->Fill(7.,centrality);
1150     if(evSelMask & (((AliVEvent::kCMUS5 | AliVEvent::kMUSH7) | (AliVEvent::kMUL7 | AliVEvent::kMUU7)) |  (AliVEvent::kMUS7 | AliVEvent::kMUON))) hTrigS->Fill(8.,centrality);
1151     if(evSelMask & (AliVEvent::kPHI1 | AliVEvent::kPHI7)) hTrigS->Fill(9.,centrality);
1152     if(evSelMask & (AliVEvent::kDG5 | AliVEvent::kZED)) hTrigS->Fill(10.,centrality);
1153   }
1154   
1155   if(evSelected || (!evSelbyCentrality && evSelByVertex && evselByPileup && evSelByPS)){ //events selected or not selected because of centrality
1156     if(fOnOff[2] && fCuts->GetUseCentrality()){
1157
1158       Float_t stdCentf=fCuts->GetCentrality(aod);
1159       Int_t stdCent = (Int_t)(stdCentf+0.5);
1160       Float_t secondCentf =fCuts->GetCentrality(aod,fEstimator);
1161       Int_t secondCent = (Int_t)(secondCentf+0.5);
1162       Int_t mincent=stdCent-stdCent%10;
1163       AliAODVZERO *vzeroAOD = (AliAODVZERO*)aod->GetVZEROData();
1164       Float_t vzeroMult = vzeroAOD->GetMTotV0A() +  vzeroAOD->GetMTotV0C();
1165       AliCentrality *aodcent = aod->GetCentrality();
1166       Float_t spdCentf = aodcent->GetCentralityPercentile("CL1");
1167       if(stdCentf==-1) {
1168         mincent=-10; 
1169         stdCent=-1;
1170       }
1171       if(mincent==100)mincent--;
1172       ((AliCounterCollection*)fOutputCounters->FindObject("stdEstimator"))->Count(Form("centralityclass:%d_%d/Run:%d",mincent,mincent+10,runNumber));
1173
1174       mincent=secondCent-secondCent%10;
1175       if(secondCentf==-1) {
1176         mincent=-10;
1177         secondCent=-1;
1178       }
1179       if(mincent==100)mincent--;
1180       ((AliCounterCollection*)fOutputCounters->FindObject("secondEstimator"))->Count(Form("centralityclass:%d_%d/Run:%d",mincent,mincent+10,runNumber));
1181
1182       if(stdCent<fCuts->GetMinCentrality() || stdCent>fCuts->GetMaxCentrality()){
1183         ((TH1F*)fOutputCheckCentrality->FindObject("hNtrackletsOut"))->Fill(aod->GetTracklets()->GetNumberOfTracklets());
1184         ((TH1F*)fOutputCheckCentrality->FindObject("hMultOut"))->Fill(aod->GetHeader()->GetRefMultiplicity());
1185       }else{
1186         ((TH1F*)fOutputCheckCentrality->FindObject("hNtrackletsIn"))->Fill(aod->GetTracklets()->GetNumberOfTracklets());
1187         ((TH1F*)fOutputCheckCentrality->FindObject("hMultIn"))->Fill(aod->GetHeader()->GetRefMultiplicity());
1188       }
1189       ((TH2F*)fOutputCheckCentrality->FindObject("hMultvsPercentile"))->Fill(aod->GetHeader()->GetRefMultiplicity(),stdCentf);
1190       ((TH2F*)fOutputCheckCentrality->FindObject("hntrklvsPercentile"))->Fill(aod->GetTracklets()->GetNumberOfTracklets(),stdCentf);
1191       ((TH2F*)fOutputCheckCentrality->FindObject("hnTPCTracksvsPercentile"))->Fill(nSelTracksTPCOnly,stdCentf);
1192       ((TH2F*)fOutputCheckCentrality->FindObject("hnTPCITSTracksvsPercentile"))->Fill(nSelTracksTPCITS,stdCentf);
1193       ((TH2F*)fOutputCheckCentrality->FindObject("hnTPCITS1SPDTracksvsPercentile"))->Fill(nSelTracksTPCITS1SPD,stdCentf);
1194       ((TH2F*)fOutputCheckCentrality->FindObject("hV0MultiplicityPercentile"))->Fill(vzeroMult,stdCentf);
1195       ((TH2F*)fOutputCheckCentrality->FindObject("hV0MultiplicityNtrackletsIn"))->Fill(vzeroMult,aod->GetTracklets()->GetNumberOfTracklets());
1196       ((TH2F*)fOutputCheckCentrality->FindObject("hStdPercentileSPDPercentile"))->Fill(stdCentf,spdCentf);
1197
1198       PostData(6,fOutputCheckCentrality);
1199
1200     } else{
1201       if(fOnOff[0]){
1202         ((TH1F*)fOutputTrack->FindObject("hNtracklets"))->Fill(aod->GetTracklets()->GetNumberOfTracklets());
1203         ((TH1F*)fOutputTrack->FindObject("hMult"))->Fill(aod->GetHeader()->GetRefMultiplicity());
1204       }
1205     }
1206   }
1207
1208   if(fOnOff[3]){
1209     const AliVVertex *vertex = aod->GetPrimaryVertex();
1210     Double_t xvtx=vertex->GetX();
1211     Double_t yvtx=vertex->GetY();
1212     Double_t zvtx=vertex->GetZ();
1213     Int_t vtxTyp=0;
1214     if(vertex->GetNContributors()<=0) vtxTyp=-1;
1215     TString title=vertex->GetTitle();
1216     if(title.Contains("Z")) vtxTyp=3;
1217     if(title.Contains("3D")) vtxTyp=2;    
1218     ((TH1F*)fOutputEvSelection->FindObject("hxvtx"))->Fill(xvtx);
1219     ((TH1F*)fOutputEvSelection->FindObject("hyvtx"))->Fill(yvtx);
1220     ((TH1F*)fOutputEvSelection->FindObject("hzvtx"))->Fill(zvtx);
1221     ((TH1F*)fOutputEvSelection->FindObject("hWhichVert"))->Fill(vtxTyp);
1222     if(evSelected){
1223       ((TH1F*)fOutputEvSelection->FindObject("hxvtxSelEv"))->Fill(xvtx);
1224       ((TH1F*)fOutputEvSelection->FindObject("hyvtxSelEv"))->Fill(yvtx);
1225       ((TH1F*)fOutputEvSelection->FindObject("hzvtxSelEv"))->Fill(zvtx);
1226       ((TH1F*)fOutputEvSelection->FindObject("hWhichVertSelEv"))->Fill(vtxTyp);
1227     }
1228   }
1229
1230   if(!evSelected) {
1231     delete [] pdgdaughters;
1232     return; //discard all events not selected (vtx and/or centrality)
1233   }
1234
1235
1236   AliAODPidHF* pidHF=fCuts->GetPidHF();
1237   if(!pidHF) {
1238     delete [] pdgdaughters;
1239     return;
1240   }
1241   //AliPIDResponse* respF=pidHF->GetPidResponse();
1242   AliTPCPIDResponse* tpcres=new AliTPCPIDResponse();
1243   Bool_t oldPID=pidHF->GetOldPid();
1244   if(oldPID){ 
1245     Double_t alephParameters[5];
1246     pidHF->GetTPCBetheBlochParams(alephParameters);
1247     tpcres->SetBetheBlochParameters(alephParameters[0],alephParameters[1],alephParameters[2],alephParameters[3],alephParameters[4]);
1248   }
1249
1250
1251   Int_t ntracks=0;
1252   Int_t isGoodTrack=0, isFakeTrack=0, isSelTrack=0;
1253
1254   if(aod) ntracks=aod->GetNTracks();
1255
1256   if(fOnOff[0] || fOnOff[1]){
1257     //loop on tracks in the event
1258     for (Int_t k=0;k<ntracks;k++){
1259       AliAODTrack* track=aod->GetTrack(k);
1260       if(track->GetID()<0) continue;
1261       AliAODPid *pid = track->GetDetPid();
1262       if(!pid && fDebug>1) cout<<"No AliAODPid found"<<endl;
1263
1264       if(pid && fOnOff[1]){
1265         Double_t times[AliPID::kSPECIES];
1266         pid->GetIntegratedTimes(times);
1267     
1268         Double_t tofRes[AliPID::kSPECIES];
1269         pid->GetTOFpidResolution(tofRes);
1270
1271         //check TOF
1272         TH1F* htmpfl=((TH1F*)fOutputPID->FindObject("hTOFflags"));
1273         htmpfl->Fill(0.);
1274         if (track->GetStatus()&AliESDtrack::kTPCout) htmpfl->Fill(1.);
1275         if (track->GetStatus()&AliESDtrack::kTOFout) htmpfl->Fill(2.);
1276         if (track->GetStatus()&AliESDtrack::kTIME) htmpfl->Fill(3.);
1277         if (track->GetStatus()&AliESDtrack::kTOFpid) htmpfl->Fill(4.);
1278         if (track->GetStatus()&AliESDtrack::kTOFmismatch) htmpfl->Fill(5.);
1279
1280         if(pidHF && pidHF->CheckStatus(track,"TOF")){
1281           ((TH1F*)fOutputPID->FindObject("hTOFtime"))->Fill(times[AliPID::kProton]);
1282           ((TH2F*)fOutputPID->FindObject("hTOFtimeKaonHyptime"))->Fill(track->P(),pid->GetTOFsignal()-times[3]); //3 is kaon
1283           ((TH1F*)fOutputPID->FindObject("hTOFsig"))->Fill(pid->GetTOFsignal());
1284           if (pid->GetTOFsignal()< 0) ((TH1F*)fOutputPID->FindObject("hTOFsig"))->Fill(-1);
1285
1286           Double_t nsigma[3]={-10,-10,-10};
1287           pidHF->GetnSigmaTOF(track,(Int_t)AliPID::kPion,nsigma[0]);     
1288           pidHF->GetnSigmaTOF(track,(Int_t)AliPID::kKaon,nsigma[1]);     
1289           pidHF->GetnSigmaTOF(track,(Int_t)AliPID::kProton,nsigma[2]);   
1290
1291           ((TH2F*)fOutputPID->FindObject("hTOFsigmaKSigPid"))->Fill(track->P(),nsigma[1]);
1292           ((TH2F*)fOutputPID->FindObject("hTOFsigmaPionSigPid"))->Fill(track->P(),nsigma[0]);
1293           ((TH2F*)fOutputPID->FindObject("hTOFsigmaProtonSigPid"))->Fill(track->P(),nsigma[2]);
1294           if(fReadMC){
1295             Int_t label=track->GetLabel();
1296             if(label<=0) continue;
1297             AliMCParticle* mcpart=(AliMCParticle*)mcArray->At(label);
1298             if(mcpart){
1299               Int_t abspdgcode=TMath::Abs(mcpart->PdgCode());
1300               if(abspdgcode==211) ((TH2F*)fOutputPID->FindObject("hTOFsigmaMCPionSigPid"))->Fill(track->P(),nsigma[0]);
1301               if(abspdgcode==321) ((TH2F*)fOutputPID->FindObject("hTOFsigmaMCKSigPid"))->Fill(track->P(),nsigma[1]);
1302               if(abspdgcode==2212) ((TH2F*)fOutputPID->FindObject("hTOFsigmaMCProtonSigPid"))->Fill(track->P(),nsigma[2]);
1303
1304             }
1305           }
1306
1307           for (Int_t iS=2; iS<5; iS++){ //we plot TOF Pid resolution for 3-sigma identified particles
1308             if ( TMath::Abs(nsigma[iS-2])<3.){
1309               switch (iS) {
1310               case AliPID::kPion:
1311                 ((TH1F*)fOutputPID->FindObject("hTOFsigPid3sigPion"))->Fill(tofRes[iS]);
1312                 break;
1313               case AliPID::kKaon:
1314                 ((TH1F*)fOutputPID->FindObject("hTOFsigPid3sigKaon"))->Fill(tofRes[iS]);
1315                 break;
1316               case AliPID::kProton:
1317                 ((TH1F*)fOutputPID->FindObject("hTOFsigPid3sigProton"))->Fill(tofRes[iS]);
1318                 break;
1319               default:
1320                 break;
1321               }
1322             }
1323           }
1324         }//if TOF status
1325         //}
1326
1327         if(pidHF && pidHF->CheckStatus(track,"TPC")){ 
1328
1329           Double_t TPCp=pid->GetTPCmomentum();
1330           Double_t TPCsignal=pid->GetTPCsignal();
1331           ((TH1F*)fOutputPID->FindObject("hTPCsig"))->Fill(TPCsignal);
1332           ((TH1F*)fOutputPID->FindObject("hTPCsigvsp"))->Fill(TPCp,TPCsignal);
1333           //if (pidHF->IsKaonRaw(track, "TOF"))
1334           Double_t nsigma[3]={-10,-10,-10};
1335           pidHF->GetnSigmaTPC(track,(Int_t)AliPID::kPion,nsigma[0]);     
1336           pidHF->GetnSigmaTPC(track,(Int_t)AliPID::kKaon,nsigma[1]);     
1337           pidHF->GetnSigmaTPC(track,(Int_t)AliPID::kProton,nsigma[2]);   
1338
1339           ((TH2F*)fOutputPID->FindObject("hTPCsigmaK"))->Fill(TPCp,nsigma[1]);
1340           
1341           ((TH2F*)fOutputPID->FindObject("hTPCsigmaPion"))->Fill(TPCp,nsigma[0]);         
1342           ((TH2F*)fOutputPID->FindObject("hTPCsigmaProton"))->Fill(TPCp,nsigma[2]);
1343           
1344           if(fReadMC){
1345             Int_t label=track->GetLabel();
1346             if(label<=0) continue;
1347             AliMCParticle* mcpart=(AliMCParticle*)mcArray->At(label);
1348             if(mcpart){
1349               Int_t abspdgcode=TMath::Abs(mcpart->PdgCode());
1350               if(abspdgcode==211) ((TH2F*)fOutputPID->FindObject("hTPCsigmaMCPion"))->Fill(track->P(),nsigma[0]);
1351               if(abspdgcode==321) ((TH2F*)fOutputPID->FindObject("hTPCsigmaMCK"))->Fill(track->P(),nsigma[1]);
1352               if(abspdgcode==2212) ((TH2F*)fOutputPID->FindObject("hTPCsigmaMCProton"))->Fill(track->P(),nsigma[2]);
1353
1354             }
1355
1356           }
1357
1358
1359         }//if TPC status
1360       } //end PID histograms
1361
1362       Int_t nclsTot=0,nclsSPD=0;
1363
1364       //check clusters of the tracks
1365       if(fOnOff[0]){
1366
1367         ((TH1F*)fOutputTrack->FindObject("hnLayerITS"))->Fill(-1);
1368         for(Int_t l=0;l<6;l++) {
1369           if(TESTBIT(track->GetITSClusterMap(),l)) {
1370             ((TH1F*)fOutputTrack->FindObject("hnLayerITS"))->Fill(l);
1371             nclsTot++; if(l<2) nclsSPD++;
1372           }
1373         }
1374         ((TH1F*)fOutputTrack->FindObject("hnClsITS"))->Fill(nclsTot);
1375         ((TH1F*)fOutputTrack->FindObject("hnClsSPD"))->Fill(nclsSPD);
1376         if(track->Pt()>0.3 &&
1377            TMath::Abs(track->Eta())<0.8 &&
1378            track->GetStatus()&AliESDtrack::kITSrefit &&
1379            track->GetStatus()&AliESDtrack::kTPCrefit &&
1380            nclsSPD>0){
1381           ((TH1F*)fOutputTrack->FindObject("hnClsITSselTr"))->Fill(nclsTot);
1382         }
1383         if(!(track->GetStatus()&AliESDtrack::kTPCin) && track->GetStatus()&AliESDtrack::kITSrefit && !(track->GetStatus()&AliESDtrack::kITSpureSA)){//tracks retrieved in the ITS and not reconstructed in the TPC
1384           ((TH1F*)fOutputTrack->FindObject("hnClsITS-SA"))->Fill(nclsTot);
1385           ((TH1F*)fOutputTrack->FindObject("hnLayerITS"))->Fill(-1);
1386           for(Int_t l=0;l<6;l++) {
1387             if(TESTBIT(track->GetITSClusterMap(),l)) {
1388               ((TH1F*)fOutputTrack->FindObject("hnLayerITSsa"))->Fill(l);
1389             }
1390           }
1391         }
1392         Int_t label=0;
1393         if(fReadMC){
1394           label=track->GetLabel();
1395           if (label<0)fNEntries->Fill(8);
1396           else fNEntries->Fill(9); 
1397         }
1398
1399
1400         if (track->Pt()>0.3 &&
1401             track->GetStatus()&AliESDtrack::kTPCrefit &&
1402             track->GetStatus()&AliESDtrack::kITSrefit &&
1403             /*nclsTot>3 &&*/
1404             nclsSPD>0) {//count good tracks
1405
1406             
1407           if(fReadMC && label<0) {
1408             ((TH1F*)fOutputTrack->FindObject("hptFakeTr"))->Fill(track->Pt());
1409             isFakeTrack++;      
1410           } else {
1411             ((TH1F*)fOutputTrack->FindObject("hptGoodTr"))->Fill(track->Pt());
1412             isGoodTrack++;
1413           }
1414         }
1415         if(fCuts->IsDaughterSelected(track,&vESD,fCuts->GetTrackCuts())){
1416           isSelTrack++;
1417         }//select tracks for our analyses
1418       } //fill track histos
1419     } //end loop on tracks
1420
1421     //fill once per event
1422     if(fOnOff[0]){
1423       if (fReadMC) ((TH1F*)fOutputTrack->FindObject("hdistrFakeTr"))->Fill(isFakeTrack);
1424       ((TH1F*)fOutputTrack->FindObject("hdistrGoodTr"))->Fill(isGoodTrack);
1425       ((TH1F*)fOutputTrack->FindObject("hdistrSelTr"))->Fill(isSelTrack);
1426     }
1427
1428     if(!isSimpleMode){
1429       // loop over candidates
1430       Int_t nCand = arrayProng->GetEntriesFast();
1431       Int_t ndaugh=3;
1432       if(fDecayChannel==AliAnalysisTaskSEHFQA::kD0toKpi) ndaugh=2;
1433       if(fDecayChannel==AliAnalysisTaskSEHFQA::kD0toKpipipi) ndaugh=4;
1434
1435       for (Int_t iCand = 0; iCand < nCand; iCand++) {
1436         AliAODRecoDecayHF *d = (AliAODRecoDecayHF*)arrayProng->UncheckedAt(iCand);
1437         if(d->GetSelectionMap()) {
1438           if(fDecayChannel==AliAnalysisTaskSEHFQA::kD0toKpi && !d->HasSelectionBit(AliRDHFCuts::kD0toKpiCuts)) continue; //skip the D0 from Dstar
1439           if(fDecayChannel==AliAnalysisTaskSEHFQA::kDplustoKpipi && !d->HasSelectionBit(AliRDHFCuts::kDplusCuts)) continue; //skip the 3 prong !D+
1440         }
1441
1442         if(fReadMC){ 
1443
1444           Int_t labD = -1;
1445           if (fDecayChannel==AliAnalysisTaskSEHFQA::kLambdactoV0 && (dynamic_cast<AliAODRecoCascadeHF*>(d))->Getv0()) {
1446
1447             Int_t pdgDgLctoV0bachelor[2]={310,2212};
1448             Int_t pdgDgV0toDaughters[2]={211,211};
1449             Int_t mcLabelK0S = (dynamic_cast<AliAODRecoCascadeHF*>(d))->MatchToMC(pdg,pdgDgLctoV0bachelor[0],pdgDgLctoV0bachelor,pdgDgV0toDaughters,mcArray,kTRUE); // Lc->K0S+p and cc
1450             pdgDgLctoV0bachelor[0]=3122, pdgDgLctoV0bachelor[1]=211;
1451             pdgDgV0toDaughters[0]=2212,  pdgDgV0toDaughters[1]=211;
1452             Int_t mcLabelLambda = (dynamic_cast<AliAODRecoCascadeHF*>(d))->MatchToMC(pdg,pdgDgLctoV0bachelor[0],pdgDgLctoV0bachelor,pdgDgV0toDaughters,mcArray,kTRUE); // Lc->Lambda+pi and cc
1453             if (mcLabelK0S!=-1 || mcLabelLambda!=-1) AliInfo(Form("mcLabelK0S=%d - mcLabelLambda=%d",mcLabelK0S,mcLabelLambda));
1454
1455             if (mcLabelK0S!=-1 && mcLabelLambda!=-1)
1456               AliInfo("Strange: current Lc->V0+bachelor candidate has two MC different labels!");
1457             else if (mcLabelK0S>-1 && mcLabelLambda==-1)
1458               labD = mcLabelK0S;
1459             else if (mcLabelLambda>-1 && mcLabelK0S==-1)
1460               labD = mcLabelLambda;
1461           }
1462           else
1463             labD = d->MatchToMC(pdg,mcArray,ndaugh,pdgdaughters);
1464
1465           if(labD>=0){
1466             AliAODMCParticle *partD = (AliAODMCParticle*)mcArray->At(labD);
1467             Int_t label=partD->GetMother();
1468             AliAODMCParticle *mot = (AliAODMCParticle*)mcArray->At(label);
1469             while(label>=0){//get first mother
1470               mot = (AliAODMCParticle*)mcArray->At(label);
1471               label=mot->GetMother();
1472             }
1473             if(mot){
1474               Int_t pdgMotCode = mot->GetPdgCode();
1475         
1476               if(TMath::Abs(pdgMotCode)==4) fNEntries->Fill(6); //from primary charm
1477               if(TMath::Abs(pdgMotCode)==5) fNEntries->Fill(7); //from beauty
1478             }
1479           }
1480         }//end MC
1481         else fNEntries->Fill(6); //count the candidates (data)
1482
1483         for(Int_t id=0;id<ndaugh;id++){
1484           //other histograms to be filled when the cut object is given
1485           AliAODTrack* track=0;
1486
1487           if (fDecayChannel==AliAnalysisTaskSEHFQA::kLambdactoV0 && (dynamic_cast<AliAODRecoCascadeHF*>(d))->Getv0()) {
1488             if (id==0)
1489               track=(AliAODTrack*)(dynamic_cast<AliAODRecoCascadeHF*>(d))->GetBachelor();
1490             else if (id==1)
1491               track=(AliAODTrack*)(dynamic_cast<AliAODRecoCascadeHF*>(d))->Getv0PositiveTrack();
1492             else if (id==2)
1493               track=(AliAODTrack*)(dynamic_cast<AliAODRecoCascadeHF*>(d))->Getv0NegativeTrack();
1494           }
1495           else 
1496             track=(AliAODTrack*)d->GetDaughter(id);
1497
1498           //track quality
1499
1500           if (fCuts->IsInFiducialAcceptance(d->Pt(),d->Y(pdg)) && fCuts->IsSelected(d,AliRDHFCuts::kTracks,aod)) {
1501             
1502             Int_t label=0;
1503             if(fReadMC)label=track->GetLabel();
1504             if(fOnOff[0]){
1505               
1506               if(fReadMC && label<0) {
1507                 isFakeTrack++;
1508                 ((TH1F*)fOutputTrack->FindObject("hptFakeTrFromDaugh"))->Fill(track->Pt());
1509            
1510                 ((TH1F*)fOutputTrack->FindObject("hd0f"))->Fill(d->Getd0Prong(id));
1511               } else {
1512                 ((TH1F*)fOutputTrack->FindObject("hptGoodTrFromDaugh"))->Fill(track->Pt());
1513                 ((TH1F*)fOutputTrack->FindObject("hd0"))->Fill(d->Getd0Prong(id));
1514                 Double_t d0rphiz[2],covd0[3];
1515                 Bool_t isDCA=track->PropagateToDCA(aod->GetPrimaryVertex(),aod->GetMagneticField(),9999.,d0rphiz,covd0);
1516                 if(isDCA) ((TH1F*)fOutputTrack->FindObject("hd0z"))->Fill(d0rphiz[1]);
1517               }
1518             }
1519             if (fCuts->IsSelected(d,AliRDHFCuts::kAll,aod) && fOnOff[1]){
1520           
1521               AliAODPid *pid = track->GetDetPid();
1522               if(pid){
1523                 Double_t times[5];
1524                 pid->GetIntegratedTimes(times);
1525                 if(pidHF && pidHF->CheckStatus(track,"TOF")) ((TH2F*)fOutputPID->FindObject("hTOFtimeKaonHyptimeAC"))->Fill(track->P(),pid->GetTOFsignal()-times[AliPID::kKaon]);
1526                 if(pidHF && pidHF->CheckStatus(track,"TPC")) ((TH2F*)fOutputPID->FindObject("hTPCsigvspAC"))->Fill(pid->GetTPCmomentum(),pid->GetTPCsignal());
1527               }
1528               fNEntries->Fill(3);
1529             } //end analysis cuts
1530           } //end acceptance and track cuts
1531         } //end loop on tracks in the candidate
1532       } //end loop on candidates
1533       
1534     }
1535   } //end if on pid or track histograms
1536
1537   delete tpcres;
1538   delete [] pdgdaughters;
1539   PostData(1,fNEntries);
1540   if(fOnOff[1]) PostData(2,fOutputPID);
1541   if(fOnOff[0]) PostData(3,fOutputTrack);
1542   PostData(4,fCuts);
1543   if(fOnOff[2]) PostData(5,fOutputCounters);
1544   //Post data 6 done in case of centrality on   
1545
1546 }
1547
1548 //____________________________________________________________________________
1549 void AliAnalysisTaskSEHFQA::FillFlowObs(AliAODEvent *aod){
1550   //fills the flow observables
1551   Double_t cc;
1552   cc = fCuts->GetCentrality(aod);
1553   ((TH2F*) fOutputFlowObs->FindObject("hFlowEvents"))->Fill(0., cc);
1554
1555   UInt_t mask=((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected();
1556   UInt_t trigger=AliVEvent::kMB | AliVEvent::kCentral | AliVEvent::kSemiCentral;
1557   if(mask & trigger) {
1558     ((TH2F*) fOutputFlowObs->FindObject("hFlowEvents"))->Fill(1.,cc); // fired
1559     if (mask & AliVEvent::kMB) ((TH2F*) fOutputFlowObs->FindObject("hFlowEvents"))->Fill(2.,cc);
1560     if (mask & AliVEvent::kCentral) ((TH2F*) fOutputFlowObs->FindObject("hFlowEvents"))->Fill(3.,cc);
1561     if (mask & AliVEvent::kSemiCentral) ((TH2F*) fOutputFlowObs->FindObject("hFlowEvents"))->Fill(4.,cc);
1562     Bool_t rejected=false;
1563     if(cc<0 || cc>60) rejected=true;
1564     const AliVVertex *vertex = aod->GetPrimaryVertex();
1565     Double_t zvtx=vertex->GetZ();
1566     if(TMath::Abs(zvtx)>fCuts->GetMaxVtxZ()) rejected=true;
1567     if(rejected) return; //not interesting for flow QA
1568   } else {
1569     return;
1570   }
1571
1572   // event accepted
1573   ((TH2F*) fOutputFlowObs->FindObject("hFlowEvents"))->Fill(5.,cc);
1574   fRFPcuts->SetParamType(AliFlowTrackCuts::kGlobal);
1575   fRFPcuts->SetPtRange(0.2,5.);
1576   fRFPcuts->SetEtaRange(-0.8,0.8);
1577   fRFPcuts->SetMinNClustersTPC(70);
1578   fRFPcuts->SetMinChi2PerClusterTPC(0.2);
1579   fRFPcuts->SetMaxChi2PerClusterTPC(4.0);
1580   fRFPcuts->SetAcceptKinkDaughters(kFALSE);
1581   fRFPcuts->SetEvent(aod);
1582
1583   TString ref[3] = {"FB1","FB128","VZE"};
1584   Double_t psi[3];
1585   for(Int_t i=0; i!=3; ++i) {
1586     if(i==0) { // switching to bit 1
1587       fRFPcuts->SetMinimalTPCdedx(10.);
1588       fRFPcuts->SetAODfilterBit(1);
1589     } else { // switching to bit 128
1590       fRFPcuts->SetMinimalTPCdedx(-1);
1591       fRFPcuts->SetAODfilterBit(128);
1592     }
1593     if(i>1) {
1594       fRFPcuts->SetParamType(AliFlowTrackCuts::kV0);
1595       fRFPcuts->SetEtaRange(-5,+5);
1596       fRFPcuts->SetPhiMin(0);
1597       fRFPcuts->SetPhiMax(TMath::TwoPi());
1598     }
1599     fFlowEvent->Fill(fRFPcuts,fRFPcuts);
1600     fFlowEvent->TagSubeventsInEta(-5,0,0,+5);
1601     // getting informationt
1602     AliFlowVector vQ, vQaQb[2];
1603     fFlowEvent->Get2Qsub(vQaQb,2);
1604     vQ = vQaQb[0]+vQaQb[1];
1605     Double_t dMa=vQaQb[0].GetMult();
1606     Double_t dMb=vQaQb[1].GetMult();
1607     if( dMa<2 || dMb<2 ) {
1608       ((TH2F*) fOutputFlowObs->FindObject("hFlowEvents"))->Fill(6.,cc); //???
1609       continue;
1610     }
1611     psi[i] = vQ.Phi()/2;
1612     // publishing
1613     ((TProfile2D*) fOutputFlowObs->FindObject( Form("h%s_Q",ref[i].Data())))->Fill(0,cc,vQaQb[0].X()/dMa,dMa); // Qx-
1614     ((TProfile2D*) fOutputFlowObs->FindObject( Form("h%s_Q",ref[i].Data())))->Fill(1,cc,vQaQb[0].Y()/dMa,dMa); // Qy-
1615     ((TProfile2D*) fOutputFlowObs->FindObject( Form("h%s_Q",ref[i].Data())))->Fill(2,cc,vQaQb[1].X()/dMb,dMb); // Qx+
1616     ((TProfile2D*) fOutputFlowObs->FindObject( Form("h%s_Q",ref[i].Data())))->Fill(3,cc,vQaQb[1].Y()/dMb,dMb); // Qy+
1617     ((TH2F*) fOutputFlowObs->FindObject( Form("h%s_AngleQ",ref[i].Data()) ))->Fill(psi[i],cc); // Psi
1618     AliFlowTrackSimple *track;
1619     for(Int_t t=0; t!=fFlowEvent->NumberOfTracks(); ++t) {
1620       track = (AliFlowTrackSimple*) fFlowEvent->GetTrack(t);
1621       if(!track) continue;
1622       if(!track->InRPSelection()) continue;
1623       ((TH3F*) fOutputFlowObs->FindObject( Form("h%s_PhiEta",ref[i].Data()) ))->Fill(track->Phi(),track->Eta(),cc,track->Weight()); //PhiEta
1624     }
1625   
1626   //histo filled only for TPCFB1
1627   if (i==0) {
1628     ((TH2F*) fOutputFlowObs->FindObject("hCentVsMultRPS"))->Fill(fFlowEvent->GetNumberOfRPs(),cc);
1629   }
1630   }
1631   // TPC vs VZERO
1632   ((TH3F*) fOutputFlowObs->FindObject( "hTPCVZE_AngleQ" ))->Fill(psi[0],psi[2],cc);
1633 }
1634
1635 //____________________________________________________________________________
1636 void AliAnalysisTaskSEHFQA::Terminate(Option_t */*option*/){
1637   //terminate analysis
1638
1639   fNEntries = dynamic_cast<TH1F*>(GetOutputData(1));
1640   if(!fNEntries){
1641     printf("ERROR: %s not available\n",GetOutputSlot(1)->GetContainer()->GetName());
1642     return;
1643   }
1644
1645   fOutputPID = dynamic_cast<TList*> (GetOutputData(2));
1646   if (!fOutputPID && fOnOff[1]) {     
1647     printf("ERROR: %s not available\n",GetOutputSlot(2)->GetContainer()->GetName());
1648     return;
1649   }
1650
1651   fOutputTrack = dynamic_cast<TList*> (GetOutputData(3));
1652   if (!fOutputTrack && fOnOff[0]) {     
1653     printf("ERROR: %s not available\n",GetOutputSlot(3)->GetContainer()->GetName());
1654     return;
1655   }
1656
1657 }
1658