AliPhysics  a6017e1 (a6017e1)
AliAnalysisTaskSEHFTreeCreator.cxx
Go to the documentation of this file.
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 
19 //
20 //
21 //
22 // Authors:
23 // Andrea Festanti andrea.festanti@cern.ch
24 // Fabrizio Grosa fabrizio.grosa@cern.ch
25 // Gian Michele Innocenti gian.michele.innocenti@cern.ch
27 
28 #include <Riostream.h>
29 #include <TClonesArray.h>
30 #include <TCanvas.h>
31 #include <TNtuple.h>
32 #include <TTree.h>
33 #include <TList.h>
34 #include <TH1F.h>
35 #include <TH2F.h>
36 #include <TDatabasePDG.h>
37 #include <THnSparse.h>
38 #include <AliAnalysisDataSlot.h>
39 #include <AliAnalysisDataContainer.h>
40 #include "TChain.h"
41 #include "AliVertexingHFUtils.h"
42 #include "AliAnalysisManager.h"
43 #include "AliESDtrack.h"
44 #include "AliVertexerTracks.h"
45 #include "AliAODHandler.h"
46 #include "AliAODEvent.h"
47 #include "AliAODVertex.h"
48 #include "AliAODTrack.h"
49 #include "AliAODMCHeader.h"
50 #include "AliAODMCParticle.h"
51 #include "AliAODRecoDecay.h"
54 #include "AliAODRecoCascadeHF.h"
55 #include "AliAODPidHF.h"
56 #include "AliAnalysisVertexingHF.h"
58 #include "AliAnalysisTaskSE.h"
60 
61 using std::cout;
62 using std::endl;
63 
67 
68 //________________________________________________________________________
71 fNentries(0x0),
72 fListCuts(0x0),
73 fFiltCutsD0toKpi(0x0),
74 fFiltCutsDstoKKpi(0x0),
75 fFiltCutsDplustoKpipi(0x0),
76 fCutsD0toKpi(0x0),
77 fCutsDstoKKpi(0x0),
78 fCutsDplustoKpipi(0x0),
79 fReadMC(0),
80 fListCounter(0x0),
81 fCounter(0x0),
82 fUseSelectionBit(kTRUE),
83 fSys(0),
84 fAODProtection(1),
85 fListTree(0),
86 fWriteVariableTreeD0(0),
87 fWriteVariableTreeDs(0),
88 fWriteVariableTreeDplus(0),
89 fVariablesTreeD0(0x0),
90 fVariablesTreeDs(0x0),
91 fVariablesTreeDplus(0x0),
92 fWriteOnlySignal(kFALSE),
93 fTreeHandlerD0(0x0),
94 fTreeHandlerDs(0x0),
95 fTreeHandlerDplus(0x0),
96 fPIDoptD0(AliHFCutOptTreeHandler::kNsigmaPIDchar),
97 fPIDoptDs(AliHFCutOptTreeHandler::kNsigmaPIDchar),
98 fPIDoptDplus(AliHFCutOptTreeHandler::kNsigmaPIDchar)
99 {
100 
102 
103 }
104 //________________________________________________________________________
106 AliAnalysisTaskSE(name),
107 fNentries(0x0),
108 fListCuts(0x0),
109 fFiltCutsD0toKpi(0x0),
110 fFiltCutsDstoKKpi(0x0),
112 fCutsD0toKpi(0x0),
113 fCutsDstoKKpi(0x0),
114 fCutsDplustoKpipi(0x0),
115 fReadMC(0),
116 fListCounter(0x0),
117 fCounter(0x0),
118 fUseSelectionBit(kTRUE),
119 fSys(0),
120 fAODProtection(1),
124 fListTree(0x0),
125 fVariablesTreeD0(0x0),
126 fVariablesTreeDs(0x0),
128 fWriteOnlySignal(kFALSE),
129 fTreeHandlerD0(0x0),
130 fTreeHandlerDs(0x0),
131 fTreeHandlerDplus(0x0),
132 fPIDoptD0(AliHFCutOptTreeHandler::kNsigmaPIDchar),
133 fPIDoptDs(AliHFCutOptTreeHandler::kNsigmaPIDchar),
134 fPIDoptDplus(AliHFCutOptTreeHandler::kNsigmaPIDchar)
135 {
137 
138 
139  if(fFiltCutsD0toKpi){
141  }
142  if(fFiltCutsDstoKKpi){
144  }
147  }
148  if(fCutsD0toKpi){
149  delete fCutsD0toKpi;fCutsD0toKpi=NULL;
150  }
151  if(fCutsDstoKKpi){
152  delete fCutsDstoKKpi;fCutsDstoKKpi=NULL;
153  }
154  if(fCutsDplustoKpipi){
156  }
157 
158  fListCuts=cutsList;
159 
160  fFiltCutsD0toKpi =(AliRDHFCutsD0toKpi*)fListCuts->FindObject("D0toKpiFilteringCuts");
161  fFiltCutsDstoKKpi =(AliRDHFCutsDstoKKpi*)fListCuts->FindObject("DstoKKpiFilteringCuts");
162  fFiltCutsDplustoKpipi=(AliRDHFCutsDplustoKpipi*)fListCuts->FindObject("DplustoKpipiFilteringCuts");
163  fCutsD0toKpi =(AliRDHFCutsD0toKpi*)fListCuts->FindObject("D0toKpiAnalysisCuts");
164  fCutsDstoKKpi =(AliRDHFCutsDstoKKpi*)fListCuts->FindObject("DstoKKpiAnalysisCuts");
165  fCutsDplustoKpipi =(AliRDHFCutsDplustoKpipi*)fListCuts->FindObject("DplustoKpipiAnalysisCuts");
166 
167 
168  DefineInput(0, TChain::Class());
169  // Output slot #1 writes into a TH1F container (number of events)
170  DefineOutput(1,TH1F::Class());
171  // Output slot #2 writes into a TList container (cuts)
172  DefineOutput(2,TList::Class());
173  // Output slot #3 writes Normalization Counter
174  DefineOutput(3,TList::Class());
175  // Output slot #4 stores the tree of the candidate variables after track selection
176  DefineOutput(4,TList::Class());
177 
178 }
179 //________________________________________________________________________
181 {
182  if (fListCuts) {
183  delete fListCuts;
184  fListCuts = 0;
185  }
186  if (fFiltCutsD0toKpi) {
187  delete fFiltCutsD0toKpi;
188  fFiltCutsD0toKpi = 0;
189  }
190  if (fFiltCutsDstoKKpi) {
191  delete fFiltCutsDstoKKpi;
192  fFiltCutsDstoKKpi = 0;
193  }
194  if (fFiltCutsDplustoKpipi) {
195  delete fFiltCutsDplustoKpipi;
197  }
198  if (fCutsD0toKpi) {
199  delete fCutsD0toKpi;
200  fCutsD0toKpi = 0;
201  }
202  if (fCutsDstoKKpi) {
203  delete fCutsDstoKKpi;
204  fCutsDstoKKpi = 0;
205  }
206  if (fCutsDplustoKpipi) {
207  delete fCutsDplustoKpipi;
208  fCutsDplustoKpipi = 0;
209  }
210  if (fNentries){
211  delete fNentries;
212  fNentries = 0;
213  }
214  if (fListCounter) {
215  delete fListCounter;
216  fListCounter = 0;
217  }
218  if(fCounter){
219  delete fCounter;
220  fCounter=0;
221  }
222  if (fListTree) {
223  delete fListTree;
224  fListTree = 0;
225  }
226  if(fTreeHandlerD0) {
227  delete fTreeHandlerD0;
228  fTreeHandlerD0 = 0;
229  }
230  if(fTreeHandlerDs) {
231  delete fTreeHandlerDs;
232  fTreeHandlerDs = 0;
233  }
234  if(fTreeHandlerDplus) {
235  delete fTreeHandlerDplus;
236  fTreeHandlerDplus = 0;
237  }
238 
239 }
240 
241 //________________________________________________________________________
243 {
245 
246  if(fDebug > 1) printf("AliAnalysisTaskSEHFTreeCreator::Init() \n");
247 
248  PostData(2,fListCuts);
249 
250  return;
251 }
252 
253 //________________________________________________________________________
255 {
256 
258  //
259  if(fDebug > 1) printf("AliAnalysisTaskSEHFTreeCreator::UserCreateOutputObjects() \n");
260 
261  const char* nameoutput=GetOutputSlot(1)->GetContainer()->GetName();
262  fNentries=new TH1F(nameoutput, "Number of events", 23,-0.5,22.5);
263  fNentries->GetXaxis()->SetBinLabel(1,"n. evt. read");
264  fNentries->GetXaxis()->SetBinLabel(2,"n. evt. matched dAOD");
265  fNentries->GetXaxis()->SetBinLabel(3,"n. evt. mismatched dAOD");
266  fNentries->GetXaxis()->SetBinLabel(4,"n. evt. analised");
267  fNentries->GetXaxis()->SetBinLabel(5,"n. evt. passing IsEvSelected");
268  fNentries->GetXaxis()->SetBinLabel(6,"n. evt. rejected due to trigger");
269  fNentries->GetXaxis()->SetBinLabel(7,"n. evt. rejected due to not reco vertex");
270  fNentries->GetXaxis()->SetBinLabel(8,"n. evt. rejected for contr vertex");
271  fNentries->GetXaxis()->SetBinLabel(9,"n. evt. rejected for vertex out of accept");
272  fNentries->GetXaxis()->SetBinLabel(10,"n. evt. rejected for pileup events");
273  fNentries->GetXaxis()->SetBinLabel(11,"n. evt. of out centrality events");
274  fNentries->GetXaxis()->SetBinLabel(12,"n. of 2 prong candidates");
275  fNentries->GetXaxis()->SetBinLabel(13,"n. D0 after filtering");
276  fNentries->GetXaxis()->SetBinLabel(14,"n. D0 after selection");
277  fNentries->GetXaxis()->SetBinLabel(15,"n. of not on-the-fly rec D0");
278  fNentries->GetXaxis()->SetBinLabel(16,"n. of 3 prong candidates");
279  fNentries->GetXaxis()->SetBinLabel(17,"n. Ds after filtering");
280  fNentries->GetXaxis()->SetBinLabel(18,"n. Ds after selection");
281  fNentries->GetXaxis()->SetBinLabel(19,"n. of not on-the-fly rec Ds");
282  fNentries->GetXaxis()->SetBinLabel(20,"n. Dplus after filtering");
283  fNentries->GetXaxis()->SetBinLabel(21,"n. Dplus after selection");
284  fNentries->GetXaxis()->SetBinLabel(22,"n. of not on-the-fly rec Dplus");
285 
286 
287  fListCounter=new TList();
288  fListCounter->SetOwner(kTRUE);
289  fListCounter->SetName("NormCounter");
290  fCounter = new AliNormalizationCounter("norm_counter");
291  fCounter->Init();
292  fListCounter->Add(fCounter);
293 
294 
295  //
296  // Output slot 4 : list of trees of the candidate variables after track selection
297  //
298 
299  fListTree=new TList();
300  fListTree->SetOwner(kTRUE);
301  fListTree->SetName("Trees");
302 
304  TString nameoutput = "tree_D0";
310  fVariablesTreeD0 = (TTree*)fTreeHandlerD0->BuildTree(nameoutput,nameoutput);
312  }
314  TString nameoutput = "tree_Ds";
320  fVariablesTreeDs = (TTree*)fTreeHandlerDs->BuildTree(nameoutput,nameoutput);
322  }
324  TString nameoutput = "tree_Dplus";
330  fVariablesTreeDplus = (TTree*)fTreeHandlerDplus->BuildTree(nameoutput,nameoutput);
332  }
333 
334  // Post the data
335  PostData(1,fNentries);
336  PostData(3,fListCounter);
337  PostData(4,fListTree);
338 
339 
340  return;
341 }
342 
343 //________________________________________________________________________
345 
346 {
348 
349  AliAODEvent *aod = dynamic_cast<AliAODEvent*> (InputEvent());
350 
351  fNentries->Fill(0); // all events
352  if(fAODProtection>=0){
353  // Protection against different number of events in the AOD and deltaAOD
354  // In case of discrepancy the event is rejected.
355  Int_t matchingAODdeltaAODlevel = AliRDHFCuts::CheckMatchingAODdeltaAODevents();
356  if (matchingAODdeltaAODlevel<0 || (matchingAODdeltaAODlevel==0 && fAODProtection==1)) {
357  // AOD/deltaAOD trees have different number of entries || TProcessID do not match while it was required
358  fNentries->Fill(2);
359  return;
360  }
361  fNentries->Fill(1);
362  }
363 
364 
365  TString candidates2prongArrayName="D0toKpi";
366  TString candidates3prongArrayName="Charm3Prong";
367  TClonesArray *array2prong=0;
368  TClonesArray *array3Prong=0;
369 
370  if(!aod && AODEvent() && IsStandardAOD()) {
371  // In case there is an AOD handler writing a standard AOD, use the AOD
372  // event in memory rather than the input (ESD) event.
373  aod = dynamic_cast<AliAODEvent*> (AODEvent());
374  // in this case the braches in the deltaAOD (AliAOD.VertexingHF.root)
375  // have to taken from the AOD event hold by the AliAODExtension
376  AliAODHandler* aodHandler = (AliAODHandler*)
377  ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
378 
379  if(aodHandler->GetExtensions()) {
380  AliAODExtension *ext = (AliAODExtension*)aodHandler->GetExtensions()->FindObject("AliAOD.VertexingHF.root");
381  AliAODEvent* aodFromExt = ext->GetAOD();
382  array2prong=(TClonesArray*)aodFromExt->GetList()->FindObject(candidates2prongArrayName.Data());
383  array3Prong=(TClonesArray*)aodFromExt->GetList()->FindObject(candidates3prongArrayName.Data());
384  }
385  } else if(aod) {
386  array2prong=(TClonesArray*)aod->GetList()->FindObject(candidates2prongArrayName.Data());
387  array3Prong=(TClonesArray*)aod->GetList()->FindObject(candidates3prongArrayName.Data());
388  }
389 
390  if(!array2prong || !array3Prong || !aod) {
391  printf("AliAnalysisTaskSEHFTreeCreator::UserExec: input branches not found!\n");
392  return;
393  }
394  // fix for temporary bug in ESDfilter
395  // the AODs with null vertex pointer didn't pass the PhysSel
396  if(!aod->GetPrimaryVertex() || TMath::Abs(aod->GetMagneticField())<0.001) return;
397 
398  fNentries->Fill(3); // count events
399 
406 
407  TClonesArray *mcArray = 0;
408  AliAODMCHeader *mcHeader = 0;
409 
410  if(fReadMC) {
411  // load MC particles
412  mcArray = (TClonesArray*)aod->GetList()->FindObject(AliAODMCParticle::StdBranchName());
413  if(!mcArray) {
414  printf("AliAnalysisTaskSEHFTreeCreator::UserExec: MC particles branch not found!\n");
415  return;
416  }
417 
418  // load MC header
419  mcHeader = (AliAODMCHeader*)aod->GetList()->FindObject(AliAODMCHeader::StdBranchName());
420  if(!mcHeader) {
421  printf("AliAnalysisTaskSEHFTreeCreator::UserExec: MC header branch not found!\n");
422  return;
423  }
424  }
425  //Printf("CHECKING EVENT SELECTION");
429  Bool_t isSameEvSel=isSameEvSelD0 && isSameEvSelDs && isSameEvSelDplus;
430  if(!isSameEvSel) {
431  Printf("AliAnalysisTaskSEHFTreeCreator::UserExec: differences in the event selection cuts same meson");
432  return;
433  }
435  Printf("AliAnalysisTaskSEHFTreeCreator::UserExec: differences in the event selection cuts different meson");
436  return;
437  }
438 
441  if(!isEvSel)return;
442  fNentries->Fill(4);
443 
444  Float_t ntracks=aod->GetNumberOfTracks();
445  Float_t evCentr=fFiltCutsD0toKpi->GetCentrality(aod);
446  Int_t runNumber=aod->GetRunNumber();
447 
448  //Printf("Process2Prong");
449  if(fWriteVariableTreeD0) Process2Prong(array2prong,aod,mcArray,evCentr);
450 
451  //Printf("Process3Prong");
452  if(fWriteVariableTreeDs || fWriteVariableTreeDplus) Process3Prong(array3Prong,aod,mcArray,evCentr);
453 
454 
455  // Post the data
456  PostData(1,fNentries);
457  PostData(3,fListCounter);
458  PostData(4,fListTree);
459 
460  return;
461 }
462 //________________________________________________________________________
464 {
466  //
467  if(fDebug > 1) printf("AliAnalysisTaskSEHFTreeCreator: Terminate() \n");
468 
469 
470  fNentries = dynamic_cast<TH1F*>(GetOutputData(1));
471  if(!fNentries){
472  printf("ERROR: fNEntries not available\n");
473  return;
474  }
475  fListCuts = dynamic_cast<TList*>(GetOutputData(2));
476  if(!fListCuts){
477  printf("ERROR: fListCuts not available\n");
478  return;
479  }
480  fListCounter = dynamic_cast<TList*>(GetOutputData(3));
481  if(!fListCounter){
482  printf("ERROR: fListCounter not available\n");
483  return;
484  }
485  fListTree = dynamic_cast<TList*>(GetOutputData(4));
486  if(!fListTree){
487  printf("ERROR: fListTree not available\n");
488  return;
489  }
490  return;
491 }
492 //--------------------------------------------------------
493 void AliAnalysisTaskSEHFTreeCreator::Process2Prong(TClonesArray *array2prong, AliAODEvent *aod, TClonesArray *arrMC, Float_t centrality){
494 
495  Int_t n2prong = array2prong->GetEntriesFast();
496  if(fDebug>2) printf("Number of D0->Kpi: %d\n",n2prong);
497 
498  Int_t nSelectedD0=0;
499  Int_t nFilteredD0=0;
500 
501  AliAODPidHF* pidHF = fCutsD0toKpi->GetPidHF();
502  if(!pidHF) pidHF=0x0;
503 
504 
505  // vHF object is needed to call the method that refills the missing info of the candidates
506  // if they have been deleted in dAOD reconstruction phase
507  // in order to reduce the size of the file
509 
510  for (Int_t i2prong = 0; i2prong < n2prong; i2prong++) {
511  AliAODRecoDecayHF2Prong *d = (AliAODRecoDecayHF2Prong*)array2prong->UncheckedAt(i2prong);
512  fNentries->Fill(11);
513 
515  continue;
516  }
517  fNentries->Fill(12);
518  nFilteredD0++;
519  if(!(vHF->FillRecoCand(aod,d))) {//Fill the data members of the candidate only if they are empty.
520  fNentries->Fill(14); //monitor how often this fails
521  continue;
522  }
523 
524  //fiducial acceptance
525  Bool_t isFidAcc=fFiltCutsD0toKpi->IsInFiducialAcceptance(d->Pt(),d->Y(421));
526 
527  if(isFidAcc){
528  Int_t isSelectedFilt = fFiltCutsD0toKpi->IsSelected(d,AliRDHFCuts::kAll,aod); //selected
529  Int_t isSelectedAnalysis = fCutsD0toKpi->IsSelected(d,AliRDHFCuts::kAll,aod); //selected
530  if(isSelectedFilt){
531  fNentries->Fill(13);
532  nSelectedD0++;
533  }
534  if(!isSelectedFilt) continue;
535 
536  Int_t pdgDgD0toKpi[2]={321,211};
537  Int_t labD0=-1;
538  if(fReadMC) labD0 = d->MatchToMC(421,arrMC,2,pdgDgD0toKpi); //return MC particle label if the array corresponds to a D0, -1 if not (cf. AliAODRecoDecay.cxx)
539 
540  Bool_t issignal=kFALSE;
541  Bool_t isprompt=kFALSE;
542  Bool_t isrefl=kFALSE;
543  Int_t masshypo=0;
544 
545 
546  if (isSelectedFilt==1 || isSelectedFilt==3) { //D0
548  masshypo=0;
549  if(fReadMC){
550  if(labD0>=0){
551  AliAODMCParticle *partD0 = (AliAODMCParticle*)arrMC->At(labD0);
552  Int_t pdgD0 = partD0->GetPdgCode();
553  Int_t origin=AliVertexingHFUtils::CheckOrigin(arrMC,partD0,kTRUE);
554  if(origin==4) isprompt=kTRUE;
555  else if(origin==5) isprompt=kFALSE;
556 
557  if(pdgD0==421){
558  issignal=kTRUE;
559  isrefl=kFALSE;
560  }
561  else {
562  issignal=kTRUE;
563  isrefl=kTRUE;
564  }
565  }//end labD0check
566  else{//background
567  issignal=kFALSE;
568  isrefl=kFALSE;
569  }
571  //Printf("Before filling tree D0 SIG");
572  fTreeHandlerD0->SetCandidateType(issignal,isprompt,isrefl);
573  fTreeHandlerD0->SetIsSelectedStd(isSelectedAnalysis);
574  // Printf("after caniddate type tree D0 BKG");
575  fTreeHandlerD0->SetVariables(d,masshypo,pidHF,0x0);
576  // Printf("after setting variables tree D0 BKG");
578  // Printf("after filling tree D0 SIG");
579  }
580  }//end read MC
581  else{
582  issignal=kFALSE;
583  isrefl=kFALSE;
585  //Printf("Before filling tree D0 BKG");
586  fTreeHandlerD0->SetIsSelectedStd(isSelectedAnalysis);
587  fTreeHandlerD0->SetVariables(d,masshypo,pidHF,0x0);
588  // Printf("after setting variables tree D0 BKG");
590  // Printf("After filling tree D0 BKG");
591  }
592  }
593 
594  }//end D0
595  if (isSelectedFilt>1){//D0bar
597  masshypo=1;
598  if(fReadMC){
599  if(labD0>=0){
600  AliAODMCParticle *partD0 = (AliAODMCParticle*)arrMC->At(labD0);
601  Int_t pdgD0 = partD0->GetPdgCode();
602  Int_t origin=AliVertexingHFUtils::CheckOrigin(arrMC,partD0,kTRUE);
603  if(origin==4) isprompt=kTRUE;
604  else if(origin==5) isprompt=kFALSE;
605 
606  if(pdgD0==-421){
607  issignal=kTRUE;
608  isrefl=kFALSE;
609  }
610  else {
611  issignal=kTRUE;
612  isrefl=kTRUE;
613  }
614  } //end label check
615  else{ //background MC
616  issignal=kFALSE;
617  isrefl=kFALSE;
618  }
620  //Printf("Before filling tree D0bar SIG");
621  fTreeHandlerD0->SetCandidateType(issignal,isprompt,isrefl);
622  fTreeHandlerD0->SetIsSelectedStd(isSelectedAnalysis);
623  fTreeHandlerD0->SetVariables(d,masshypo,pidHF,0x0);
625  //Printf("After filling tree D0bar SIG");
626  }
627  }//end readMC
628  else{
629  issignal=kFALSE;
630  isrefl=kFALSE;
632  //Printf("Before filling tree D0bar BKG");
633  fTreeHandlerD0->SetIsSelectedStd(isSelectedAnalysis);
634  fTreeHandlerD0->SetVariables(d,masshypo,pidHF,0x0);
636  //Printf("After filling tree D0bar BKG");
637  }
638  }
639  }//end D0bar
640  }//end is fid acc
641 
642  }//end loop on candidates
643 
644  delete vHF;
645  return;
646 }
647 
648 //--------------------------------------------------------
649 void AliAnalysisTaskSEHFTreeCreator::Process3Prong(TClonesArray *array3Prong, AliAODEvent *aod, TClonesArray *arrMC, Float_t centrality){
650 
651  AliAODVertex *vtx1 = (AliAODVertex*)aod->GetPrimaryVertex();
652 
653  Int_t n3prong = array3Prong->GetEntriesFast();
654  if(fDebug>1) printf("Number of Ds->KKpi: %d\n",n3prong);
655 
656  Int_t pdgDstoKKpi[3]={321,321,211};
657  Int_t nSelectedDs=0;
658  Int_t nFilteredDs=0;
659  Double_t massPhi=TDatabasePDG::Instance()->GetParticle(333)->Mass();
660 
661  AliAODPidHF* pidHFDs = fFiltCutsDstoKKpi->GetPidHF();
662  if(!pidHFDs) pidHFDs=0x0;
663  AliAODPidHF* pidHFDplus = fFiltCutsDplustoKpipi->GetPidHF();
664  if(!pidHFDplus) pidHFDplus=0x0;
665 
666  Int_t pdgDgDplustoKpipi[3]={321,211,211};
667  Int_t nSelectedDplus=0;
668  Int_t nFilteredDplus=0;
669 
670 
671  // vHF object is needed to call the method that refills the missing info of the candidates
672  // if they have been deleted in dAOD reconstruction phase
673  // in order to reduce the size of the file
675 
676  for (Int_t i3prong = 0; i3prong < n3prong; i3prong++) {
677  fNentries->Fill(15);
678 
679  //Ds
680  Bool_t isDstagged=kTRUE;
681  AliAODRecoDecayHF3Prong *ds = (AliAODRecoDecayHF3Prong*)array3Prong->UncheckedAt(i3prong);
683  isDstagged=kFALSE;
684  }
685 
686  if(isDstagged){
687  fNentries->Fill(16);
688  nFilteredDs++;
689  if((vHF->FillRecoCand(aod,ds))) {
690 
691  Bool_t isFidAcc=fFiltCutsDstoKKpi->IsInFiducialAcceptance(ds->Pt(),ds->YDs());
692  if(isFidAcc){
693  //Printf("Ds ");
694  Int_t isSelectedFilt=fFiltCutsDstoKKpi->IsSelected(ds,AliRDHFCuts::kAll,aod);
695  //Printf("Filtering %d",i3prong);
696  Int_t isSelectedAnalysis=fCutsDstoKKpi->IsSelected(ds,AliRDHFCuts::kAll,aod);
697  //Printf("Analysis %d",i3prong);
698  Int_t isSelectedCandidateNoRes=isSelectedFilt;
700  if(origRes){
702  isSelectedCandidateNoRes=fFiltCutsDstoKKpi->IsSelected(ds,AliRDHFCuts::kAll,aod);
704  }
705 
706  Int_t isKKpi=isSelectedFilt&1;
707  Int_t ispiKK=isSelectedFilt&2;
708  Int_t isPhiKKpi=isSelectedFilt&4;
709  Int_t isPhipiKK=isSelectedFilt&8;
710  Int_t isK0starKKpi=isSelectedFilt&16;
711  Int_t isK0starpiKK=isSelectedFilt&32;
712 
713  if(isSelectedFilt>0){
714 
715  fNentries->Fill(17);
716  nSelectedDs++;
717 
718  Bool_t unsetvtx=kFALSE;
719  if(!ds->GetOwnPrimaryVtx()){
720  ds->SetOwnPrimaryVtx(vtx1);
721  unsetvtx=kTRUE;
722  // NOTE: the ow primary vertex should be unset, otherwise there is a memory leak
723  // Pay attention if you use continue inside this loop!!!
724  }
725  Bool_t recVtx=kFALSE;
726  AliAODVertex *origownvtx=0x0;
728  if(ds->GetOwnPrimaryVtx()) origownvtx=new AliAODVertex(*ds->GetOwnPrimaryVtx());
729  if(fFiltCutsDstoKKpi->RecalcOwnPrimaryVtx(ds,aod))recVtx=kTRUE;
730  else fFiltCutsDstoKKpi->CleanOwnPrimaryVtx(ds,aod,origownvtx);
731  }
732 
733  Int_t labDs=-1;
734  Int_t labDplus=-1;
735  Int_t pdgCode0=-999;
736  Int_t orig=0;
737 
738  if(fReadMC){
739 
740  AliAODMCParticle *partDs = 0x0;
741 
742 
743  labDs = ds->MatchToMC(431,arrMC,3,pdgDstoKKpi);
744  labDplus = ds->MatchToMC(411,arrMC,3,pdgDstoKKpi);
745 
746  if(labDs>=0){
747  Int_t labDau0=((AliAODTrack*)ds->GetDaughter(0))->GetLabel();
748  AliAODMCParticle* p=(AliAODMCParticle*)arrMC->UncheckedAt(TMath::Abs(labDau0));
749  pdgCode0=TMath::Abs(p->GetPdgCode());
750 
751  partDs = (AliAODMCParticle*)arrMC->At(labDs);
752 
753  }
754  else{
755  if(labDplus>=0) {
756  Int_t labDau0=((AliAODTrack*)ds->GetDaughter(0))->GetLabel();
757  AliAODMCParticle* p=(AliAODMCParticle*)arrMC->UncheckedAt(TMath::Abs(labDau0));
758  pdgCode0=TMath::Abs(p->GetPdgCode());
759 
760  partDs = (AliAODMCParticle*)arrMC->At(labDplus);
761  }
762  }
763  if(partDs) orig = AliVertexingHFUtils::CheckOrigin(arrMC,partDs,kTRUE);
764  }
765 
767  if ((fWriteVariableTreeDs==1 && (isPhiKKpi || isPhipiKK)) || (fWriteVariableTreeDs==2 && (isK0starKKpi || isK0starpiKK)) || (fWriteVariableTreeDs==3 && (isKKpi || ispiKK))){
768  if(fSys>0) fTreeHandlerDs->SetCentrality((Char_t)centrality);
769 
770  Bool_t issignal = kFALSE;
771  Bool_t isprompt = kFALSE;
772  Bool_t isrefl = kFALSE;
773 
774  if(isKKpi || isPhiKKpi || isK0starKKpi) {
775  if(fReadMC) {
776  if(labDs>=0) issignal=kTRUE;
777  else issignal=kFALSE;
778 
779  if(orig==4) isprompt=kTRUE;
780  else if(orig==5) isprompt=kFALSE;
781 
782  if(pdgCode0==211) isrefl=kTRUE;
783  else isrefl=kFALSE;
784 
785  fTreeHandlerDs->SetIsSelectedStd(isSelectedAnalysis);
786  fTreeHandlerDs->SetCandidateType(issignal,isprompt,isrefl);
787  fTreeHandlerDs->SetVariables(ds,0,pidHFDs,0x0);
789  }
790  else { //real data
791  fTreeHandlerDs->SetVariables(ds,0,pidHFDs,0x0);
793  }
794  }
795  if(ispiKK || isPhipiKK || isK0starpiKK) {
796  if(fReadMC) {
797  if(labDs>=0) issignal=kTRUE;
798  else issignal=kFALSE;
799 
800  if(orig==4) isprompt=kTRUE;
801  else if(orig==5) isprompt=kFALSE;
802 
803  if(pdgCode0==321) isrefl=kTRUE;
804  else isrefl=kFALSE;
805 
806  fTreeHandlerDs->SetIsSelectedStd(isSelectedAnalysis);
807  fTreeHandlerDs->SetCandidateType(issignal,isprompt,isrefl);
808  fTreeHandlerDs->SetVariables(ds,1,pidHFDs,0x0);
810  }
811  else { //real data
812  fTreeHandlerDs->SetIsSelectedStd(isSelectedAnalysis);
813  fTreeHandlerDs->SetVariables(ds,1,pidHFDs,0x0);
815  }
816  }
817  }
818  }//end fill tree
819  if(recVtx)fFiltCutsDstoKKpi->CleanOwnPrimaryVtx(ds,aod,origownvtx);
820  if(unsetvtx) ds->UnsetOwnPrimaryVtx();
821  }//end is selected
822  }//fid acc
823  }
824  else{
825  fNentries->Fill(18); //monitor how often this fails
826  }
827  }//end Ds
828 
829 
830  //*************************************
831  //Dplus
832  Bool_t isDplustagged=kTRUE;
833  AliAODRecoDecayHF3Prong *dplus = (AliAODRecoDecayHF3Prong*)array3Prong->UncheckedAt(i3prong);
835  isDplustagged=kFALSE;
836  }
837  if(isDplustagged){
838  nFilteredDplus++;
839  fNentries->Fill(19);
840  if((vHF->FillRecoCand(aod,dplus))) {
841 
842  Bool_t isFidAcc=fFiltCutsDplustoKpipi->IsInFiducialAcceptance(dplus->Pt(),dplus->YDplus());
843  if(isFidAcc){//is fid acc
844 
845  Int_t isSelectedFilt =fFiltCutsDplustoKpipi->IsSelected(dplus,AliRDHFCuts::kAll,aod);
846  Int_t isSelectedAnalysis=fCutsDplustoKpipi->IsSelected(dplus,AliRDHFCuts::kAll,aod);
847  if(isSelectedFilt){
848  nSelectedDplus++;
849 
850  Bool_t unsetvtx=kFALSE;
851  if(!dplus->GetOwnPrimaryVtx()){
852  dplus->SetOwnPrimaryVtx(vtx1);
853  unsetvtx=kTRUE;
854  }
855  Bool_t recVtx=kFALSE;
856  AliAODVertex *origownvtx=0x0;
858  if(dplus->GetOwnPrimaryVtx()) origownvtx=new AliAODVertex(*dplus->GetOwnPrimaryVtx());
859  if(fFiltCutsDplustoKpipi->RecalcOwnPrimaryVtx(dplus,aod))recVtx=kTRUE;
860  else fFiltCutsDplustoKpipi->CleanOwnPrimaryVtx(dplus,aod,origownvtx);
861  }
862 
863  Int_t labDp=-1;
864  Bool_t isPrimary=kFALSE;
865  Bool_t isFeeddown=kFALSE;
866  Int_t pdgCode=-2;
867  //read MC
868  if(fReadMC){
869  labDp = dplus->MatchToMC(411,arrMC,3,pdgDgDplustoKpipi);
870  if(labDp>=0){
871  AliAODMCParticle *partDp = (AliAODMCParticle*)arrMC->At(labDp);
872  Int_t orig=AliVertexingHFUtils::CheckOrigin(arrMC,partDp,kTRUE);//Prompt = 4, FeedDown = 5
873  pdgCode=TMath::Abs(partDp->GetPdgCode());
874  if(orig==4){
875  isPrimary=kTRUE;
876  isFeeddown=kFALSE;
877  }else if(orig==5){
878  isPrimary=kFALSE;
879  isFeeddown=kTRUE;
880  }else{
881  pdgCode=-3;
882  }
883  }else{
884  pdgCode=-1;
885  }
886  } //end read MC
887 
888  // fill tree
890  Bool_t issignal = kFALSE;
891  if(labDp>=0) issignal=kTRUE;
892  fTreeHandlerDplus->SetIsSelectedStd(isSelectedAnalysis);
893  fTreeHandlerDplus->SetCandidateType(issignal,isPrimary,kFALSE);
894  fTreeHandlerDplus->SetVariables(dplus,0,pidHFDplus,0x0);
895  if(fSys>0) fTreeHandlerDplus->SetCentrality(centrality);
897  }//end fill tree
898 
899  if(recVtx)fFiltCutsDplustoKpipi->CleanOwnPrimaryVtx(dplus,aod,origownvtx);
900  if(unsetvtx) dplus->UnsetOwnPrimaryVtx();
901  } //end topol and PID cuts
902 
903 
904  }//end is fid acc
905 
906  }//end ok fill reco cand
907  else{
908  fNentries->Fill(21); //monitor how often this fails
909  }
910  }//end Dplus
911 
912 
913  }//end loop on cadidates
914 
915 
916  delete vHF;
917  return;
918 
919 }
920 
Bool_t IsEventRejectedDueToCentrality() const
Definition: AliRDHFCuts.h:335
TTree * fVariablesTreeD0
! tree of the candidate variables
Bool_t IsEventRejectedDueToZVertexOutsideFiducialRegion() const
Definition: AliRDHFCuts.h:329
void SetFillOnlySignal(bool fillopt=true)
Bool_t IsEventRejectedDueToNotRecoVertex() const
Definition: AliRDHFCuts.h:320
double Double_t
Definition: External.C:58
TList * fListCounter
! list for normalization counter on output slot 3
TTree * fVariablesTreeDs
! tree of the candidate variables
Bool_t HasSelectionBit(Int_t i) const
bool SetVariables(AliAODRecoDecayHF *d, int masshypo, AliAODPidHF *pidHF=0x0, TClonesArray *arrayMC=0x0)
centrality
char Char_t
Definition: External.C:18
static Int_t CheckMatchingAODdeltaAODevents()
Bool_t IsEventRejectedDueToVertexContributors() const
Definition: AliRDHFCuts.h:323
virtual void UserCreateOutputObjects()
Implementation of interface methods.
Bool_t FillRecoCand(AliVEvent *event, AliAODRecoDecayHF3Prong *rd3)
void Process3Prong(TClonesArray *array3Prong, AliAODEvent *aod, TClonesArray *arrMC, Float_t centrality)
ULong_t GetSelectionMap() const
virtual Bool_t IsInFiducialAcceptance(Double_t pt, Double_t y) const
virtual Bool_t IsInFiducialAcceptance(Double_t pt, Double_t y) const
virtual Bool_t IsInFiducialAcceptance(Double_t pt, Double_t y) const
static Int_t CheckOrigin(TClonesArray *arrayMC, AliAODMCParticle *mcPart, Bool_t searchUpToQuark=kTRUE)
Functions to check the decay tree.
void SetUseSelectedStdFlag(bool useselflag=true)
AliAODPidHF * GetPidHF() const
Definition: AliRDHFCuts.h:247
Class for cuts on AOD reconstructed D+->Kpipi.
AliHFCutOptTreeHandler * fTreeHandlerDplus
! helper object for the tree with topological variables
int Int_t
Definition: External.C:63
virtual Int_t IsSelected(TObject *obj, Int_t selectionLevel)
float Float_t
Definition: External.C:68
void SetIsSelectedStd(bool isselected=true)
AliAODVertex * GetOwnPrimaryVtx() const
virtual Int_t IsSelected(TObject *obj, Int_t selectionLevel)
void SetIsMC(bool isMC=true)
AliHFCutOptTreeHandler * fTreeHandlerD0
! helper object for the tree with topological variables
Float_t GetCentrality(AliAODEvent *aodEvent)
Definition: AliRDHFCuts.h:258
Bool_t IsEventRejectedDueToPileup() const
Definition: AliRDHFCuts.h:332
TTree * fVariablesTreeDplus
! tree of the candidate variables
AliNormalizationCounter * fCounter
! AliNormalizationCounter
Bool_t IsCutOnResonancesApplied() const
void SetOwnPrimaryVtx(const AliAODVertex *vtx)
AliHFCutOptTreeHandler * fTreeHandlerDs
! helper object for the tree with topological variables
void SetCentrality(char centrality)
Bool_t GetIsPrimaryWithoutDaughters() const
Definition: AliRDHFCuts.h:278
Bool_t IsEventSelected(AliVEvent *event)
void StoreEvent(AliVEvent *, AliRDHFCuts *, Bool_t mc=kFALSE, Int_t multiplicity=-9999, Double_t spherocity=-99.)
void SetUseCentrality(bool usecent=true)
void CleanOwnPrimaryVtx(AliAODRecoDecayHF *d, AliAODEvent *aod, AliAODVertex *origownvtx) const
virtual Int_t IsSelected(TObject *obj, Int_t selectionLevel)
const char Option_t
Definition: External.C:48
Bool_t IsEventRejectedDueToTrigger() const
Definition: AliRDHFCuts.h:317
bool Bool_t
Definition: External.C:53
AliRDHFCutsDplustoKpipi * fFiltCutsDplustoKpipi
Bool_t RecalcOwnPrimaryVtx(AliAODRecoDecayHF *d, AliAODEvent *aod) const
void SetCandidateType(bool issignal, bool isprompt, bool isreflected)
void Process2Prong(TClonesArray *array2prong, AliAODEvent *aod, TClonesArray *arrMC, Float_t centrality)
TTree * BuildTree(TString name="tree", TString title="tree")
void ApplyCutOnResonances(Bool_t opt=kTRUE)
TH1F * fNentries
! histogram with number of events on output slot 1