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