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