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