]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/vertexingHF/AliAnalysisTaskSEHFQA.cxx
Updates for proper treatment of fQuality flag in centrality selection and for usage...
[u/mrichter/AliRoot.git] / PWG3 / 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 <TDatabasePDG.h>
32
33 #include <AliAnalysisDataSlot.h>
34 #include <AliAnalysisDataContainer.h>
35 #include "AliAnalysisManager.h"
36 #include "AliESDtrack.h"
37 #include "AliVertexerTracks.h"
38 #include "AliPID.h"
39 #include "AliTPCPIDResponse.h"
40 #include "AliAODHandler.h"
41 #include "AliAODEvent.h"
42 #include "AliAODVertex.h"
43 #include "AliAODTrack.h"
44 #include "AliAODMCParticle.h"
45 #include "AliAODMCHeader.h"
46 #include "AliAODRecoDecayHF2Prong.h"
47 #include "AliAODRecoCascadeHF.h"
48 #include "AliAnalysisVertexingHF.h"
49 #include "AliAnalysisTaskSE.h"
50 #include "AliCounterCollection.h"
51 #include "AliRDHFCuts.h"
52 #include "AliRDHFCutsDplustoKpipi.h"
53 #include "AliRDHFCutsD0toKpipipi.h"
54 #include "AliRDHFCutsDstoKKpi.h"
55 #include "AliRDHFCutsDStartoKpipi.h"
56 #include "AliRDHFCutsD0toKpi.h"
57 #include "AliRDHFCutsLctopKpi.h"
58
59 #include "AliAnalysisTaskSEHFQA.h"
60
61 ClassImp(AliAnalysisTaskSEHFQA)
62
63 //____________________________________________________________________________
64
65 AliAnalysisTaskSEHFQA::AliAnalysisTaskSEHFQA():AliAnalysisTaskSE(),
66   fNEntries(0x0),
67   fOutputPID(0x0),
68   fOutputTrack(0x0),
69   fOutputCounters(0x0),
70   fOutputCheckCentrality(0x0),
71   fDecayChannel(AliAnalysisTaskSEHFQA::kD0toKpi),
72   fCuts(0x0),
73   fEstimator(AliRDHFCuts::kCentTRK),
74   fReadMC(kFALSE),
75   fSimpleMode(kFALSE),
76   fOnOff()
77 {
78   //default constructor
79   fOnOff[0]=kTRUE;
80   fOnOff[1]=kTRUE;
81   fOnOff[2]=kTRUE;
82 }
83
84 //____________________________________________________________________________
85 AliAnalysisTaskSEHFQA::AliAnalysisTaskSEHFQA(const char *name, AliAnalysisTaskSEHFQA::DecChannel ch,AliRDHFCuts* cuts):
86   AliAnalysisTaskSE(name),
87   fNEntries(0x0),
88   fOutputPID(0x0),
89   fOutputTrack(0x0),
90   fOutputCounters(0x0),
91   fOutputCheckCentrality(0x0),
92   fDecayChannel(ch),
93   fCuts(0x0),
94   fEstimator(AliRDHFCuts::kCentTRK),
95   fReadMC(kFALSE),
96   fSimpleMode(kFALSE),
97   fOnOff()
98 {
99   //constructor
100
101   //SetCutObject(cuts);
102   fCuts=cuts;
103
104   fOnOff[0]=kTRUE;
105   fOnOff[1]=kTRUE;
106   fOnOff[2]=kTRUE;
107
108   // Output slot #1 writes into a TH1F container (number of events)
109   DefineOutput(1,TH1F::Class());  //My private output
110   // Output slot #2 writes into a TList container (PID)
111   if (fOnOff[1]) DefineOutput(2,TList::Class());  //My private output
112   // Output slot #3 writes into a TList container (Tracks)
113   if (fOnOff[0]) DefineOutput(3,TList::Class());  //My private output
114   // Output slot #4 writes into a AliRDHFCuts container (cuts)
115   switch(fDecayChannel){
116   case 0:
117     DefineOutput(4,AliRDHFCutsDplustoKpipi::Class());  //My private output
118     break;
119   case 1:
120     DefineOutput(4,AliRDHFCutsD0toKpi::Class());  //My private output
121     break;
122   case 2:
123     DefineOutput(4,AliRDHFCutsDStartoKpipi::Class());  //My private output
124     break;
125   case 3:
126     DefineOutput(4,AliRDHFCutsDstoKKpi::Class());  //My private output
127     break;
128   case 4:
129     DefineOutput(4,AliRDHFCutsD0toKpipipi::Class());  //My private output
130     break;
131   case 5:
132     DefineOutput(4,AliRDHFCutsLctopKpi::Class());  //My private output
133     break;
134   }
135   if (fOnOff[2]) {
136     // Output slot #5 writes into a TList container (AliCounterCollection)
137     DefineOutput(5,TList::Class());  //My private output
138     // Output slot #6 writes into a TList container (TH1F)
139     DefineOutput(6,TList::Class());  //My private output
140   }
141 }
142
143 //___________________________________________________________________________
144 AliAnalysisTaskSEHFQA::~AliAnalysisTaskSEHFQA()
145 {
146   //destructor
147   delete fNEntries;
148
149   delete fOutputPID;
150
151   delete fOutputTrack;
152
153   delete fOutputCounters;
154
155   delete fOutputCheckCentrality;
156
157 }
158
159 //___________________________________________________________________________
160 void AliAnalysisTaskSEHFQA::Init(){
161
162   //initialization
163   if(fDebug > 1) printf("AnalysisTaskSEHFQA::Init() \n");
164
165   switch(fDecayChannel){
166   case 0:
167     {
168       AliRDHFCutsDplustoKpipi* copycut=new AliRDHFCutsDplustoKpipi(*(static_cast<AliRDHFCutsDplustoKpipi*>(fCuts)));
169       // Post the data
170       PostData(4,copycut);
171     }
172     break;
173   case 1:
174     {
175       AliRDHFCutsD0toKpi* copycut=new AliRDHFCutsD0toKpi(*(static_cast<AliRDHFCutsD0toKpi*>(fCuts)));
176       // Post the data
177       PostData(4,copycut);
178     }
179     break;
180   case 2:
181     {
182       AliRDHFCutsDStartoKpipi* copycut=new AliRDHFCutsDStartoKpipi(*(static_cast<AliRDHFCutsDStartoKpipi*>(fCuts)));
183       // Post the data
184       PostData(4,copycut);
185     }
186     break;
187   case 3:
188     {
189       AliRDHFCutsDstoKKpi* copycut=new AliRDHFCutsDstoKKpi(*(static_cast<AliRDHFCutsDstoKKpi*>(fCuts)));
190       // Post the data
191       PostData(4,copycut);
192     }
193     break;
194   case 4:
195     {
196       AliRDHFCutsD0toKpipipi* copycut=new AliRDHFCutsD0toKpipipi(*(static_cast<AliRDHFCutsD0toKpipipi*>(fCuts)));
197       // Post the data
198       PostData(4,copycut);
199     }
200     break;
201   case 5:
202     {
203       AliRDHFCutsLctopKpi* copycut=new AliRDHFCutsLctopKpi(*(static_cast<AliRDHFCutsLctopKpi*>(fCuts)));
204       // Post the data
205       PostData(4,copycut);
206     }
207     break;
208
209   default:
210     return;
211   }
212
213
214
215 }
216
217 //___________________________________________________________________________
218 void AliAnalysisTaskSEHFQA::UserCreateOutputObjects()
219 {
220
221   //create the output container
222   if(fDebug > 1) printf("AnalysisTaskSEHFQA::UserCreateOutputObjects() \n");
223
224   //count events
225
226   fNEntries=new TH1F(GetOutputSlot(1)->GetContainer()->GetName(), "Counts the number of events", 10,-0.5,9.5);
227   fNEntries->GetXaxis()->SetBinLabel(1,"nEventsAnal");
228   fNEntries->GetXaxis()->SetBinLabel(2,"Pile-up Rej");
229   fNEntries->GetXaxis()->SetBinLabel(3,"No VertexingHF");
230   fNEntries->GetXaxis()->SetBinLabel(4,"nCandidates(AnCuts)");
231   fNEntries->GetXaxis()->SetBinLabel(5,"EventsWithGoodVtx");
232   //fNEntries->GetXaxis()->SetBinLabel(6,"N. of 0SMH");
233   fNEntries->GetXaxis()->SetBinLabel(6,"N. of CSH1");
234   if(fReadMC){
235     fNEntries->GetXaxis()->SetBinLabel(7,"MC Cand from c");
236     fNEntries->GetXaxis()->SetBinLabel(8,"MC Cand from b");
237     fNEntries->GetXaxis()->SetBinLabel(9,"N fake Trks");
238     fNEntries->GetXaxis()->SetBinLabel(10,"N true Trks");
239   } else{
240     fNEntries->GetXaxis()->SetBinLabel(7,"N candidates");
241   }
242
243   fNEntries->GetXaxis()->SetNdivisions(1,kFALSE);
244
245   //PID
246   if(fOnOff[1]){
247     fOutputPID=new TList();
248     fOutputPID->SetOwner();
249     fOutputPID->SetName(GetOutputSlot(2)->GetContainer()->GetName());
250
251     //TOF pid
252     TString hname="hTOFsig";
253     TH1F* hTOFsig=new TH1F(hname.Data(),"Distribution of TOF signal;TOF time [ps];Entries", 100, -2.e3,40.e3);
254
255     hname="hTOFtime";
256     TH1F* hTOFtime=new TH1F(hname.Data(),"Distribution of TOF time Kaon;TOF time(Kaon) [ps];Entries", 1000, 0.,50000.);
257
258     hname="hTOFtimeKaonHyptime";
259     TH2F* hTOFtimeKaonHyptime=new TH2F(hname.Data(),"TOFtime - timeHypothesisForKaon;p[GeV/c];TOFtime - timeHypothesisForKaon [ps]",200,0.,4.,1000,-20000.,20000.);
260
261     hname="hTOFtimeKaonHyptimeAC";
262     TH2F* hTOFtimeKaonHyptimeAC=new TH2F(hname.Data(),"TOFtime - timeHypothesisForKaon;p[GeV/c];TOFtime - timeHypothesisForKaon [ps]",200,0.,4.,1000,-20000.,20000.);
263
264     hname="hTOFsigmaK160";
265     TH2F* hTOFsigmaK160=new TH2F(hname.Data(),"(TOFsignal-timeK)/160 ps;p[GeV/c];(TOFsignal-timeK)/160 ps",200,0.,4.,100,-5,5);
266
267     hname="hTOFsigmaPion160";
268     TH2F* hTOFsigmaPion160=new TH2F(hname.Data(),"(TOFsignal-time#pi)/160 ps;p[GeV/c];(TOFsignal-time#pi)/160 ps",200,0.,4.,100,-5,5);
269
270     hname="hTOFsigmaProton160";
271     TH2F* hTOFsigmaProton160=new TH2F(hname.Data(),"(TOFsignal-timep)/160 ps;p[GeV/c];(TOFsignal-time p)/160 ps",200,0.,4.,100,-5,5);
272
273     hname="hTOFsigmaKSigPid";
274     TH2F* hTOFsigmaKSigPid=new TH2F(hname.Data(),"(TOFsignal-timeK)/tofSigPid;p[GeV/c];(TOFsignal-timeK)/tofSigPid",200,0.,4.,100,-5,5);
275
276     hname="hTOFsigmaPionSigPid";
277     TH2F* hTOFsigmaPionSigPid=new TH2F(hname.Data(),"(TOFsignal-time#pi)/tofSigPid;p[GeV/c];(TOFsignal-time#pi)/tofSigPid",200,0.,4.,100,-5,5);
278
279     hname="hTOFsigmaProtonSigPid";
280     TH2F* hTOFsigmaProtonSigPid=new TH2F(hname.Data(),"(TOFsignal-timep)/tofSigPid;p[GeV/c];(TOFsignal-time p)/tofSigPid",200,0.,4.,100,-5,5);
281
282     hname="hTOFsigPid3sigPion";
283     TH1F* hTOFsigPid3sigPion=new TH1F(hname.Data(),"TOF PID resolution (#pi) [ps]",500,0.,1000.);
284
285     hname="hTOFsigPid3sigKaon";
286     TH1F* hTOFsigPid3sigKaon=new TH1F(hname.Data(),"TOF PID resolution (K) [ps]",500,0.,1000.);
287
288     hname="hTOFsigPid3sigProton";
289     TH1F* hTOFsigPid3sigProton=new TH1F(hname.Data(),"TOF PID resolution (p) [ps]",500,0.,1000.);
290
291
292     //TPC pid
293     hname="hTPCsig";
294     TH1F* hTPCsig=new TH1F(hname.Data(),"Distribution of TPC signal;TPC sig;Entries", 100, 35.,100.);
295
296     hname="hTPCsigvsp";
297     TH2F* hTPCsigvsp=new TH2F(hname.Data(),"TPCsig vs p;TPC p[GeV/c];TPCsig",200,0.,4.,1000,35.,100.);
298  
299     hname="hTPCsigvspAC";
300     TH2F* hTPCsigvspAC=new TH2F(hname.Data(),"TPCsig vs p;TPCp[GeV/c];TPCsig",200,0.,4.,1000,35.,100.);
301
302     hname="hTPCsigmaK";
303     TH2F* hTPCsigmaK=new TH2F(hname.Data(),"TPC Sigma for K as a function of momentum;p[GeV/c];Sigma Kaon",200,0.,4.,200,-5,5);
304
305     hname="hTPCsigmaPion";
306     TH2F* hTPCsigmaPion=new TH2F(hname.Data(),"TPC Sigma for #pi as a function of momentum;p[GeV/c];Sigma #pi",200,0.,4.,200,-5,5);
307
308     hname="hTPCsigmaProton";
309     TH2F* hTPCsigmaProton=new TH2F(hname.Data(),"TPC Sigma for proton as a function of momentum;p[GeV/c];Sigma Proton",200,0.,4.,200,-5,5);
310
311     fOutputPID->Add(hTOFsig);
312     fOutputPID->Add(hTPCsig);
313     fOutputPID->Add(hTOFtime);
314     fOutputPID->Add(hTOFtimeKaonHyptime);
315     fOutputPID->Add(hTOFtimeKaonHyptimeAC);
316     fOutputPID->Add(hTOFsigmaK160);
317     fOutputPID->Add(hTOFsigmaPion160);
318     fOutputPID->Add(hTOFsigmaProton160);
319     fOutputPID->Add(hTOFsigmaKSigPid);
320     fOutputPID->Add(hTOFsigmaPionSigPid);
321     fOutputPID->Add(hTOFsigmaProtonSigPid);
322     fOutputPID->Add(hTOFsigPid3sigPion);
323     fOutputPID->Add(hTOFsigPid3sigKaon);
324     fOutputPID->Add(hTOFsigPid3sigProton);
325     fOutputPID->Add(hTPCsigvsp);
326     fOutputPID->Add(hTPCsigvspAC);
327     fOutputPID->Add(hTPCsigmaK);
328     fOutputPID->Add(hTPCsigmaPion);
329     fOutputPID->Add(hTPCsigmaProton);
330   }
331
332   //quality of the tracks
333   if(fOnOff[0]){
334     fOutputTrack=new TList();
335     fOutputTrack->SetOwner();
336     fOutputTrack->SetName(GetOutputSlot(3)->GetContainer()->GetName());
337
338     TString hname="hnClsITS";
339     TH1F* hnClsITS=new TH1F(hname.Data(),"Distribution of number of ITS clusters;nITScls;Entries",7,-0.5,6.5);
340
341     hname="hnClsITS-SA";
342     TH1F* hnClsITSSA=new TH1F(hname.Data(),"Distribution of number of ITS clusters(ITS-SA);nITScls;Entries",7,-0.5,6.5);
343
344     hname="hnClsSPD";
345     TH1F* hnClsSPD=new TH1F(hname.Data(),"Distribution of number of SPD clusters;nSPDcls;Entries",3,-0.5,2.5);
346
347     hname="hptGoodTr";
348     TH1F* hptGoodTr=new TH1F(hname.Data(),"Pt distribution of 'good' tracks;p_{t}[GeV];Entries/0.05 GeV/c",400,0.,20.);
349     hptGoodTr->SetTitleOffset(1.3,"Y");
350
351     hname="hdistrGoodTr";
352     TH1F* hdistrGoodTr=new TH1F(hname.Data(),"Distribution of number of 'good' tracks per event;no.good-tracks/ev;Entries",4000,-0.5,3999.5);
353     hdistrGoodTr->SetTitleOffset(1.3,"Y");
354
355     hname="hd0";
356     TH1F* hd0=new TH1F(hname.Data(),"Impact parameter distribution of 'good' tracks;d_{0}[cm];Entries/10^{3} cm",200,-0.1,0.1);
357
358     fOutputTrack->Add(hnClsITS);
359     fOutputTrack->Add(hnClsITSSA);
360     fOutputTrack->Add(hnClsSPD);
361     fOutputTrack->Add(hptGoodTr);
362     fOutputTrack->Add(hdistrGoodTr);
363     fOutputTrack->Add(hd0);
364
365     if(fReadMC){
366       hname="hdistrFakeTr";
367       TH1F* hdistrFakeTr=new TH1F(hname.Data(),"Distribution of number of fake tracks per event;no.fake-tracks/ev;Entries",4000,-0.5,3999.5);
368       hdistrGoodTr->SetTitleOffset(1.3,"Y");
369
370       hname="hd0f";
371       TH1F* hd0f=new TH1F(hname.Data(),"Impact parameter distribution of fake tracks;d_{0}[cm];Entries/10^{3} cm",200,-0.1,0.1);
372
373       hname="hptFakeTr";
374       TH1F* hptFakeTr=new TH1F(hname.Data(),"Pt distribution of fake tracks;p_{t}[GeV];Entries/0.05 GeV/c",400,0.,20.);
375       hptGoodTr->SetTitleOffset(1.3,"Y");
376
377       fOutputTrack->Add(hptFakeTr);
378       fOutputTrack->Add(hdistrFakeTr);
379       fOutputTrack->Add(hd0f);
380    
381     }
382   }
383
384   
385   if(fOnOff[2] && fCuts->GetUseCentrality()){
386
387     //Centrality (Counters)
388     fOutputCounters=new TList();
389     fOutputCounters->SetOwner();
390     fOutputCounters->SetName(GetOutputSlot(5)->GetContainer()->GetName());
391
392     AliCounterCollection *stdEstimator=new AliCounterCollection("stdEstimator");
393     stdEstimator->AddRubric("run",500000);
394     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");
395     stdEstimator->Init();
396     AliCounterCollection *secondEstimator=new AliCounterCollection("secondEstimator");
397     secondEstimator->AddRubric("run",500000);
398     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");
399     secondEstimator->Init();
400
401     fOutputCounters->Add(stdEstimator);
402     fOutputCounters->Add(secondEstimator);
403
404     //Centrality (Checks)
405     fOutputCheckCentrality=new TList();
406     fOutputCheckCentrality->SetOwner();
407     fOutputCheckCentrality->SetName(GetOutputSlot(6)->GetContainer()->GetName());
408
409     TString hname="hNtrackletsIn";
410     TH1F* hNtrackletsIn=new TH1F(hname.Data(),"Number of tracklets in Centrality range;ntracklets;Entries",5000,-0.5,4999.5);
411
412     hname="hMultIn";
413     TH1F* hMultIn=new TH1F(hname.Data(),"Multiplicity;multiplicity in Centrality range;Entries",10000,-0.5,9999.5);
414
415     hname="hNtrackletsOut";
416     TH1F* hNtrackletsOut=new TH1F(hname.Data(),"Number of tracklets out of Centrality range;ntracklets;Entries",5000,-0.5,4999.5);
417
418     hname="hMultOut";
419     TH1F* hMultOut=new TH1F(hname.Data(),"Multiplicity out of Centrality range;multiplicity;Entries",10000,-0.5,9999.5);
420
421     hname="hMultvsPercentile";
422     TH2F* hMultvsPercentile=new TH2F(hname.Data(),"Multiplicity vs Percentile;multiplicity;percentile",10000,-0.5,9999.5,12,-10.,110);
423
424     fOutputCheckCentrality->Add(hNtrackletsIn);
425     fOutputCheckCentrality->Add(hNtrackletsOut);
426     fOutputCheckCentrality->Add(hMultIn);
427     fOutputCheckCentrality->Add(hMultOut);
428     fOutputCheckCentrality->Add(hMultvsPercentile);
429
430     PostData(6,fOutputCheckCentrality);
431   
432   } else{
433     if(fOnOff[0]){
434       TString hname="hNtracklets";
435       TH1F* hNtracklets=new TH1F(hname.Data(),"Number of tracklets;ntracklets;Entries",5000,-0.5,4999.5);
436
437       hname="hMult";
438       TH1F* hMult=new TH1F(hname.Data(),"Multiplicity;multiplicity;Entries",10000,-0.5,9999.5);
439       fOutputTrack->Add(hNtracklets);
440       fOutputTrack->Add(hMult);
441     }
442   }
443
444   // Post the data
445   PostData(1,fNEntries);
446   if(fOnOff[1]) PostData(2,fOutputPID);
447   if(fOnOff[0]) PostData(3,fOutputTrack);
448   PostData(4,fCuts);
449   if(fOnOff[2]) PostData(5,fOutputCounters);
450   
451   if(!fOnOff[0] && !fOnOff[1] && !fOnOff[2]) AliError("Nothing will be filled!");
452 }
453
454 //___________________________________________________________________________
455 void AliAnalysisTaskSEHFQA::UserExec(Option_t */*option*/)
456 {
457   // Execute analysis for current event
458
459   AliAODEvent *aod = dynamic_cast<AliAODEvent*> (InputEvent());
460   if(fDebug>2) printf("Analysing decay %d\n",fDecayChannel);
461   // Post the data already here
462   PostData(1,fNEntries);
463   if(fOnOff[1]) PostData(2,fOutputPID);
464   if(fOnOff[0]) PostData(3,fOutputTrack);
465   PostData(4,fCuts);
466   if(fOnOff[2]) {
467     PostData(5,fOutputCounters);
468     if(fCuts->GetUseCentrality()) PostData(6,fOutputCheckCentrality);
469   }
470
471   TClonesArray *arrayProng =0;
472   Int_t pdg=0;
473   Int_t *pdgdaughters=0x0;
474
475   if(!aod && AODEvent() && IsStandardAOD()) { 
476     // In case there is an AOD handler writing a standard AOD, use the AOD 
477     // event in memory rather than the input (ESD) event.    
478     aod = dynamic_cast<AliAODEvent*> (AODEvent());
479     // in this case the braches in the deltaAOD (AliAOD.VertexingHF.root)
480     // have to taken from the AOD event hold by the AliAODExtension
481     AliAODHandler* aodHandler = (AliAODHandler*) 
482       ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
483     if(aodHandler->GetExtensions()) {
484       
485       AliAODExtension *ext = (AliAODExtension*)aodHandler->GetExtensions()->FindObject("AliAOD.VertexingHF.root");
486       AliAODEvent *aodFromExt = ext->GetAOD();
487    
488    
489       
490       switch(fDecayChannel){
491       case 0:
492         arrayProng=(TClonesArray*)aodFromExt->GetList()->FindObject("Charm3Prong");
493         pdg=411;
494         if(fReadMC){
495           pdgdaughters =new Int_t[3];
496           pdgdaughters[0]=211;//pi
497           pdgdaughters[1]=321;//K
498           pdgdaughters[2]=211;//pi
499         }
500         break; 
501       case 1:
502         arrayProng=(TClonesArray*)aodFromExt->GetList()->FindObject("D0toKpi");
503         pdg=421;
504         if(fReadMC){
505           pdgdaughters =new Int_t[2];
506           pdgdaughters[0]=211;//pi 
507           pdgdaughters[1]=321;//K
508         }
509         break; 
510       case 2:
511         arrayProng=(TClonesArray*)aodFromExt->GetList()->FindObject("Dstar");
512         pdg=413;
513         if(fReadMC){
514           pdgdaughters =new Int_t[3];
515           pdgdaughters[1]=211;//pi
516           pdgdaughters[0]=321;//K
517           pdgdaughters[2]=211;//pi (soft?)
518         }
519         break; 
520       case 3:
521         arrayProng=(TClonesArray*)aodFromExt->GetList()->FindObject("Charm3Prong");
522         pdg=431;
523         if(fReadMC){
524           pdgdaughters =new Int_t[3];
525           pdgdaughters[0]=321;//K
526           pdgdaughters[1]=321;//K
527           pdgdaughters[2]=211;//pi
528         }
529         break; 
530       case 4:
531         arrayProng=(TClonesArray*)aodFromExt->GetList()->FindObject("Charm4Prong");
532         pdg=421;
533         if(fReadMC){
534           pdgdaughters =new Int_t[4];
535           pdgdaughters[0]=321;
536           pdgdaughters[1]=211;
537           pdgdaughters[2]=211;
538           pdgdaughters[3]=211;
539         }
540         break; 
541       case 5:
542         arrayProng=(TClonesArray*)aodFromExt->GetList()->FindObject("Charm3Prong");
543         pdg=4122;
544         if(fReadMC){
545           pdgdaughters =new Int_t[3];
546           pdgdaughters[0]=2212;//p
547           pdgdaughters[1]=321;//K
548           pdgdaughters[2]=211;//pi
549         }
550         break; 
551       }
552     }
553   } else if(aod) {
554     switch(fDecayChannel){
555     case 0:
556       arrayProng=(TClonesArray*)aod->GetList()->FindObject("Charm3Prong");
557       pdg=411;
558       if(fReadMC){
559         pdgdaughters =new Int_t[3];
560         pdgdaughters[0]=211;//pi
561         pdgdaughters[1]=321;//K
562         pdgdaughters[2]=211;//pi
563       }
564       break; 
565     case 1:
566       arrayProng=(TClonesArray*)aod->GetList()->FindObject("D0toKpi");
567       pdg=421;
568       if(fReadMC){
569         pdgdaughters =new Int_t[2];
570         pdgdaughters[0]=211;//pi 
571         pdgdaughters[1]=321;//K
572       }
573       break; 
574     case 2:
575       arrayProng=(TClonesArray*)aod->GetList()->FindObject("Dstar");
576       pdg=413;
577       if(fReadMC){
578         pdgdaughters =new Int_t[3];
579         pdgdaughters[1]=211;//pi
580         pdgdaughters[0]=321;//K
581         pdgdaughters[2]=211;//pi (soft?)
582       }
583       break; 
584     case 3:
585       arrayProng=(TClonesArray*)aod->GetList()->FindObject("Charm3Prong");
586       pdg=431;
587       if(fReadMC){
588         pdgdaughters =new Int_t[3];
589         pdgdaughters[0]=321;//K
590         pdgdaughters[1]=321;//K
591         pdgdaughters[2]=211;//pi
592       }
593       break; 
594     case 4:
595       arrayProng=(TClonesArray*)aod->GetList()->FindObject("Charm4Prong");
596       pdg=421;
597       if(fReadMC){
598         pdgdaughters =new Int_t[4];
599         pdgdaughters[0]=321;
600         pdgdaughters[1]=211;
601         pdgdaughters[2]=211;
602         pdgdaughters[3]=211;
603       }
604       break; 
605     case 5:
606       arrayProng=(TClonesArray*)aod->GetList()->FindObject("Charm3Prong");
607       pdg=4122;
608       if(fReadMC){
609         pdgdaughters =new Int_t[3];
610         pdgdaughters[0]=2212;//p
611         pdgdaughters[1]=321;//K
612         pdgdaughters[2]=211;//pi
613       }
614       break; 
615     }
616   }
617   Bool_t isSimpleMode=fSimpleMode;
618   if(!arrayProng) {
619     AliInfo("Branch not found! The output will contain only trak related histograms\n");
620     isSimpleMode=kTRUE;
621     fNEntries->Fill(2);
622   }
623   
624   TClonesArray *mcArray = 0;
625   AliAODMCHeader *mcHeader = 0;
626
627   //check if MC
628   if(fReadMC) {
629     // load MC particles
630     mcArray = (TClonesArray*)aod->GetList()->FindObject(AliAODMCParticle::StdBranchName());
631     if(!mcArray) {
632       printf("AliAnalysisTaskSEHFQA::UserExec: MC particles branch not found!\n");
633       delete [] pdgdaughters;
634       return;
635     }
636     
637     // load MC header
638     mcHeader = (AliAODMCHeader*)aod->GetList()->FindObject(AliAODMCHeader::StdBranchName());
639     if(!mcHeader) {
640       printf("AliAnalysisTaskSEHFQA::UserExec: MC header branch not found!\n");
641       delete [] pdgdaughters;
642       return;
643     }
644   }
645   if(!aod) {delete [] pdgdaughters;return;}
646   // fix for temporary bug in ESDfilter 
647   // the AODs with null vertex pointer didn't pass the PhysSel
648   if(!aod->GetPrimaryVertex() || TMath::Abs(aod->GetMagneticField())<0.001) return;
649
650   // count event
651   fNEntries->Fill(0); 
652
653   //count events with good vertex
654   // AOD primary vertex
655   AliAODVertex *vtx1 = (AliAODVertex*)aod->GetPrimaryVertex();
656   TString primTitle = vtx1->GetTitle();
657   if(primTitle.Contains("VertexerTracks") && vtx1->GetNContributors()>0) fNEntries->Fill(4);
658
659   // trigger class for PbPb C0SMH-B-NOPF-ALLNOTRD, C0SMH-B-NOPF-ALL
660   //TString trigclass=aod->GetFiredTriggerClasses();
661   //if(trigclass.Contains("C0SMH-B-NOPF-ALLNOTRD") || trigclass.Contains("C0SMH-B-NOPF-ALL")) fNEntries->Fill(5); //tmp
662
663   Bool_t evSelbyCentrality=kTRUE,evSelected=kTRUE,evSelByVertex=kTRUE,evselByPileup=kFALSE;
664   //select event
665   if(!fCuts->IsEventSelected(aod)) {
666     evSelected=kFALSE;
667     if(fCuts->GetWhyRejection()==1) {fNEntries->Fill(1); evselByPileup=kTRUE;}// rejected for pileup
668     if(fCuts->GetWhyRejection()==2 || fCuts->GetWhyRejection()==3) evSelbyCentrality=kFALSE; //rejected by centrality
669     if(fCuts->GetWhyRejection()==4) evSelByVertex=kFALSE; //rejected by vertex
670     if(fCuts->GetWhyRejection()==5) fNEntries->Fill(5);//tmp
671   }
672   if(evSelected || (!evSelected && !evSelbyCentrality && evSelByVertex && !evselByPileup)){ //events selected or not selected because of vtx or pileup
673     if(fOnOff[2] && fCuts->GetUseCentrality()){
674       Int_t runNumber = aod->GetRunNumber();
675       Float_t stdCentf=fCuts->GetCentrality(aod);
676       Int_t stdCent = (Int_t)(stdCentf+0.5);
677       Float_t secondCentf =fCuts->GetCentrality(aod,fEstimator);
678       Int_t secondCent = (Int_t)(secondCentf+0.5);
679       Int_t mincent=stdCent-stdCent%10;
680       if(stdCentf==-1) {
681         mincent=-1; 
682         stdCent=-1;
683       }
684       ((AliCounterCollection*)fOutputCounters->FindObject("stdEstimator"))->Count(Form("centralityclass:%d_%d/Run:%d",mincent,mincent+10,runNumber));
685
686       mincent=secondCent-secondCent%10;
687       if(secondCentf==-1) {
688         mincent=-1;
689         secondCent=-1;
690       }
691       ((AliCounterCollection*)fOutputCounters->FindObject("secondEstimator"))->Count(Form("centralityclass:%d_%d/Run:%d",mincent,mincent+10,runNumber));
692
693       if(stdCent<fCuts->GetMinCentrality() || stdCent>fCuts->GetMaxCentrality()){
694         ((TH1F*)fOutputCheckCentrality->FindObject("hNtrackletsOut"))->Fill(aod->GetTracklets()->GetNumberOfTracklets());
695         ((TH1F*)fOutputCheckCentrality->FindObject("hMultOut"))->Fill(aod->GetHeader()->GetRefMultiplicity());
696       }else{
697         ((TH1F*)fOutputCheckCentrality->FindObject("hNtrackletsIn"))->Fill(aod->GetTracklets()->GetNumberOfTracklets());
698         ((TH1F*)fOutputCheckCentrality->FindObject("hMultIn"))->Fill(aod->GetHeader()->GetRefMultiplicity());
699       }
700       ((TH2F*)fOutputCheckCentrality->FindObject("hMultvsPercentile"))->Fill(aod->GetHeader()->GetRefMultiplicity(),stdCentf);
701
702       PostData(6,fOutputCheckCentrality);
703
704     } else{
705       if(fOnOff[0]){
706         ((TH1F*)fOutputTrack->FindObject("hNtracklets"))->Fill(aod->GetTracklets()->GetNumberOfTracklets());
707         ((TH1F*)fOutputTrack->FindObject("hMult"))->Fill(aod->GetHeader()->GetRefMultiplicity());
708       }
709     }
710   }
711
712   if(!evSelected) {
713     delete [] pdgdaughters;
714     return; //discard all events not selected (vtx and/or centrality)
715   }
716
717   Int_t ntracks=0;
718   Int_t isGoodTrack=0, isFakeTrack=0;
719
720   if(aod) ntracks=aod->GetNTracks();
721
722   if(fOnOff[0] || fOnOff[1]){
723     //loop on tracks in the event
724     for (Int_t k=0;k<ntracks;k++){
725       AliAODTrack* track=aod->GetTrack(k);
726       AliAODPidHF* pidHF=fCuts->GetPidHF();
727       AliAODPid *pid = track->GetDetPid();
728
729
730       if(fOnOff[1]){
731         if(!pid)  {if (fDebug>1)cout<<"No AliAODPid found"<<endl; continue;}
732         Double_t times[AliPID::kSPECIES];
733         pid->GetIntegratedTimes(times);
734     
735         Double_t tofRes[AliPID::kSPECIES];
736         pid->GetTOFpidResolution(tofRes);
737
738         //check TOF
739         if(pidHF && pidHF->CheckStatus(track,"TOF")){
740           ((TH1F*)fOutputPID->FindObject("hTOFtime"))->Fill(times[AliPID::kProton]);
741           ((TH2F*)fOutputPID->FindObject("hTOFtimeKaonHyptime"))->Fill(track->P(),pid->GetTOFsignal()-times[3]); //3 is kaon
742           ((TH1F*)fOutputPID->FindObject("hTOFsig"))->Fill(pid->GetTOFsignal());
743           if (pid->GetTOFsignal()< 0) ((TH1F*)fOutputPID->FindObject("hTOFsig"))->Fill(-1);
744
745           // test a "simple" 160 ps TOF sigma PID
746           ((TH2F*)fOutputPID->FindObject("hTOFsigmaK160"))->Fill(track->P(),(pid->GetTOFsignal()-times[AliPID::kKaon])/160);
747           ((TH2F*)fOutputPID->FindObject("hTOFsigmaPion160"))->Fill(track->P(),(pid->GetTOFsignal()-times[AliPID::kPion])/160);
748           ((TH2F*)fOutputPID->FindObject("hTOFsigmaProton160"))->Fill(track->P(),(pid->GetTOFsignal()-times[AliPID::kProton])/160);
749       
750           // test TOF sigma PID
751           if (tofRes[2] != 0.) {   // protection against 'old' AODs...
752             ((TH2F*)fOutputPID->FindObject("hTOFsigmaKSigPid"))->Fill(track->P(),(pid->GetTOFsignal()-times[AliPID::kKaon])/tofRes[3]);
753             ((TH2F*)fOutputPID->FindObject("hTOFsigmaPionSigPid"))->Fill(track->P(),(pid->GetTOFsignal()-times[AliPID::kPion])/tofRes[2]);
754             ((TH2F*)fOutputPID->FindObject("hTOFsigmaProtonSigPid"))->Fill(track->P(),(pid->GetTOFsignal()-times[AliPID::kProton])/tofRes[4]);
755             for (Int_t iS=2; iS<5; iS++){ //we plot TOF Pid resolution for 3-sigma identified particles
756               if ( (TMath::Abs(times[iS]-pid->GetTOFsignal())/tofRes[iS])<3.){
757                 switch (iS) {
758                 case AliPID::kPion:
759                   ((TH1F*)fOutputPID->FindObject("hTOFsigPid3sigPion"))->Fill(tofRes[iS]);
760                   break;
761                 case AliPID::kKaon:
762                   ((TH1F*)fOutputPID->FindObject("hTOFsigPid3sigKaon"))->Fill(tofRes[iS]);
763                   break;
764                 case AliPID::kProton:
765                   ((TH1F*)fOutputPID->FindObject("hTOFsigPid3sigProton"))->Fill(tofRes[iS]);
766                   break;
767                 default:
768                   break;
769                 }
770               }
771             }
772           }
773         }//if TOF status
774
775         if(pidHF && pidHF->CheckStatus(track,"TPC")){ 
776           Double_t alephParameters[5];
777           /*
778           //this is recommended for LHC10d
779           alephParameters[0] = 1.34490e+00/50.;
780           alephParameters[1] =  2.69455e+01;
781           alephParameters[2] =  TMath::Exp(-2.97552e+01);
782           alephParameters[3] = 2.35339e+00;
783           alephParameters[4] = 5.98079e+00;
784           */
785       
786           //this is recommended for PbPb (LHC10h)
787           alephParameters[0] = 1.25202/50.; 
788           alephParameters[1] = 2.74992e+01; 
789           alephParameters[2] = TMath::Exp(-3.31517e+01); 
790           alephParameters[3] = 2.46246; 
791           alephParameters[4] = 6.78938;
792       
793           /*
794           //this is recommended for LHC10bc
795           alephParameters[0] = 0.0283086/0.97;
796           alephParameters[1] = 2.63394e+01;
797           alephParameters[2] = 5.04114e-11;
798           alephParameters[3] = 2.12543e+00;
799           alephParameters[4] = 4.88663e+00;
800           */
801
802           AliTPCPIDResponse* tpcres=new AliTPCPIDResponse();
803           tpcres->SetBetheBlochParameters(alephParameters[0],alephParameters[1],alephParameters[2],alephParameters[3],alephParameters[4]);
804           Double_t TPCp=pid->GetTPCmomentum();
805           Double_t TPCsignal=pid->GetTPCsignal();
806           ((TH1F*)fOutputPID->FindObject("hTPCsig"))->Fill(TPCsignal);
807           ((TH1F*)fOutputPID->FindObject("hTPCsigvsp"))->Fill(TPCp,TPCsignal);
808           //if (pidHF->IsKaonRaw(track, "TOF"))
809           ((TH2F*)fOutputPID->FindObject("hTPCsigmaK"))->Fill(TPCp,tpcres->GetNumberOfSigmas(TPCp,TPCsignal,track->GetTPCNcls(),AliPID::kKaon));
810           //if (pidHF->IsPionRaw(track, "TOF"))
811           ((TH2F*)fOutputPID->FindObject("hTPCsigmaPion"))->Fill(TPCp,tpcres->GetNumberOfSigmas(TPCp,TPCsignal,track->GetTPCNcls(),AliPID::kPion));
812           //if (pidHF->IsProtonRaw(track,"TOF"))
813           ((TH2F*)fOutputPID->FindObject("hTPCsigmaProton"))->Fill(TPCp,tpcres->GetNumberOfSigmas(TPCp,TPCsignal,track->GetTPCNcls(),AliPID::kProton));
814           delete tpcres;
815         }//if TPC status
816       } //end PID histograms
817
818       Int_t nclsTot=0,nclsSPD=0;
819
820       //check clusters of the tracks
821       if(fOnOff[0]){
822
823         for(Int_t l=0;l<6;l++) {
824           if(TESTBIT(track->GetITSClusterMap(),l)) {
825             nclsTot++; if(l<2) nclsSPD++;
826           }
827         }
828         ((TH1F*)fOutputTrack->FindObject("hnClsITS"))->Fill(nclsTot);
829         ((TH1F*)fOutputTrack->FindObject("hnClsSPD"))->Fill(nclsSPD);
830
831         if(!(track->GetStatus()&AliESDtrack::kTPCin) && track->GetStatus()&AliESDtrack::kITSrefit && !(track->GetStatus()&AliESDtrack::kITSpureSA)){//tracks retrieved in the ITS and not reconstructed in the TPC
832           ((TH1F*)fOutputTrack->FindObject("hnClsITS-SA"))->Fill(nclsTot);
833         }
834         Int_t label=0;
835         if(fReadMC){
836           label=track->GetLabel();
837           if (label<0)fNEntries->Fill(8);
838           else fNEntries->Fill(9); 
839         }
840
841         if(isSimpleMode){
842
843           if (track->Pt()>0.3 &&
844               track->GetStatus()&AliESDtrack::kTPCrefit &&
845               track->GetStatus()&AliESDtrack::kITSrefit &&
846               /*nclsTot>3 &&*/
847               nclsSPD>0) {//count good tracks
848
849             
850             if(fReadMC && label<0) {
851               ((TH1F*)fOutputTrack->FindObject("hptFakeTr"))->Fill(track->Pt());
852               isFakeTrack++;    
853             } else {
854               ((TH1F*)fOutputTrack->FindObject("hptGoodTr"))->Fill(track->Pt());
855               isGoodTrack++;
856             }
857           }//simple mode: no IsSelected on tracks: use "manual" cuts
858         }    
859       }
860     } //end loop on tracks
861
862       //fill once per event
863     if(fOnOff[0]){
864       if (fReadMC) ((TH1F*)fOutputTrack->FindObject("hdistrFakeTr"))->Fill(isFakeTrack);
865       ((TH1F*)fOutputTrack->FindObject("hdistrGoodTr"))->Fill(isGoodTrack);
866     }
867
868     if(!isSimpleMode){
869       // loop over candidates
870       Int_t nCand = arrayProng->GetEntriesFast();
871       Int_t ndaugh=3;
872       if(fDecayChannel==AliAnalysisTaskSEHFQA::kD0toKpi) ndaugh=2;
873       if(fDecayChannel==AliAnalysisTaskSEHFQA::kD0toKpipipi) ndaugh=4;
874
875       for (Int_t iCand = 0; iCand < nCand; iCand++) {
876         AliAODRecoDecayHF *d = (AliAODRecoDecayHF*)arrayProng->UncheckedAt(iCand);
877         if(d->GetSelectionMap()) {
878           if(fDecayChannel==AliAnalysisTaskSEHFQA::kD0toKpi && !d->HasSelectionBit(AliRDHFCuts::kD0toKpiCuts)) continue; //skip the D0 from Dstar
879           if(fDecayChannel==AliAnalysisTaskSEHFQA::kDplustoKpipi && !d->HasSelectionBit(AliRDHFCuts::kDplusCuts)) continue; //skip the 3 prong !D+
880         }
881
882         if(fReadMC){ 
883           Int_t labD = d->MatchToMC(pdg,mcArray,ndaugh,pdgdaughters);
884           if(labD>=0){
885             AliAODMCParticle *partD = (AliAODMCParticle*)mcArray->At(labD);
886             Int_t label=partD->GetMother();
887             AliAODMCParticle *mot = (AliAODMCParticle*)mcArray->At(label);
888             while(label>=0){//get first mother
889               mot = (AliAODMCParticle*)mcArray->At(label);
890               label=mot->GetMother();
891             }
892             Int_t pdgMotCode = mot->GetPdgCode();
893         
894             if(TMath::Abs(pdgMotCode)==4) fNEntries->Fill(6); //from primary charm
895             if(TMath::Abs(pdgMotCode)==5) fNEntries->Fill(7); //from beauty
896
897           }
898         }//end MC
899         else fNEntries->Fill(6); //count the candidates (data)
900
901         for(Int_t id=0;id<ndaugh;id++){
902
903           //other histograms to be filled when the cut object is given
904           AliAODTrack* track=(AliAODTrack*)d->GetDaughter(id);
905
906           //track quality
907
908           if (fCuts->IsInFiducialAcceptance(d->Pt(),d->Y(pdg)) && fCuts->IsSelected(d,AliRDHFCuts::kTracks,aod)) {
909             
910             Int_t label=0;
911             if(fReadMC)label=track->GetLabel();
912             if(fReadMC && label<0 && fOnOff[0]) {
913               isFakeTrack++;
914               ((TH1F*)fOutputTrack->FindObject("hptFakeTr"))->Fill(track->Pt());
915            
916               ((TH1F*)fOutputTrack->FindObject("hd0f"))->Fill(d->Getd0Prong(id));
917             } else {
918               isGoodTrack++;
919               ((TH1F*)fOutputTrack->FindObject("hptGoodTr"))->Fill(track->Pt());
920             
921               ((TH1F*)fOutputTrack->FindObject("hd0"))->Fill(d->Getd0Prong(id));
922             }
923           
924             if (fCuts->IsSelected(d,AliRDHFCuts::kAll,aod) && fOnOff[1]){
925           
926               AliAODPid *pid = track->GetDetPid();
927               AliAODPidHF* pidHF=fCuts->GetPidHF();
928               Double_t times[5];
929               pid->GetIntegratedTimes(times);
930               if(pidHF && pidHF->CheckStatus(track,"TOF")) ((TH2F*)fOutputPID->FindObject("hTOFtimeKaonHyptimeAC"))->Fill(track->P(),pid->GetTOFsignal()-times[AliPID::kKaon]);
931               if(pidHF && pidHF->CheckStatus(track,"TPC")) ((TH2F*)fOutputPID->FindObject("hTPCsigvspAC"))->Fill(pid->GetTPCmomentum(),pid->GetTPCsignal());
932
933               fNEntries->Fill(3);
934             } //end analysis cuts
935           } //end acceptance and track cuts
936         } //end loop on tracks in the candidate
937       } //end loop on candidates
938       if(fOnOff[0]){
939         if(fReadMC) ((TH1F*)fOutputTrack->FindObject("hdistrFakeTr"))->Fill(isFakeTrack);
940         ((TH1F*)fOutputTrack->FindObject("hdistrGoodTr"))->Fill(isGoodTrack);
941       }
942     }
943   } //end if on pid or track histograms
944
945   delete [] pdgdaughters;
946   PostData(1,fNEntries);
947   if(fOnOff[1]) PostData(2,fOutputPID);
948   if(fOnOff[0]) PostData(3,fOutputTrack);
949   PostData(4,fCuts);
950   if(fOnOff[2]) PostData(5,fOutputCounters);
951   //Post data 6 done in case of centrality on   
952
953 }
954
955 //____________________________________________________________________________
956 void AliAnalysisTaskSEHFQA::Terminate(Option_t */*option*/){
957   //terminate analysis
958
959   fNEntries = dynamic_cast<TH1F*>(GetOutputData(1));
960   if(!fNEntries){
961     printf("ERROR: %s not available\n",GetOutputSlot(1)->GetContainer()->GetName());
962     return;
963   }
964
965   fOutputPID = dynamic_cast<TList*> (GetOutputData(2));
966   if (!fOutputPID && fOnOff[1]) {     
967     printf("ERROR: %s not available\n",GetOutputSlot(2)->GetContainer()->GetName());
968     return;
969   }
970
971   fOutputTrack = dynamic_cast<TList*> (GetOutputData(3));
972   if (!fOutputTrack && fOnOff[0]) {     
973     printf("ERROR: %s not available\n",GetOutputSlot(3)->GetContainer()->GetName());
974     return;
975   }
976
977 }
978