AliPhysics  3b4a69f (3b4a69f)
AliAnalysisTaskSED0Mass.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 // AliAnalysisTaskSE for D0 candidates invariant mass histogram
21 // and comparison with the MC truth and cut variables distributions.
22 //
23 // Authors: A.Dainese, andrea.dainese@lnl.infn.it
24 // Chiara Bianchin, chiara.bianchin@pd.infn.it (invariant mass)
25 // Carmelo Di Giglio, carmelo.digiglio@ba.infn.it (like sign)
26 // Jeremy Wilkinson, jwilkinson@physi.uni-heidelberg.de (weighted Bayesian
28 
29 #include <Riostream.h>
30 #include <TClonesArray.h>
31 #include <TObjArray.h>
32 #include <TCanvas.h>
33 #include <TNtuple.h>
34 #include <TTree.h>
35 #include <TList.h>
36 #include <TH1F.h>
37 #include <TH2F.h>
38 #include <TDatabasePDG.h>
39 #include <THnSparse.h>
40 #include "AliVertexingHFUtils.h"
41 #include <AliAnalysisDataSlot.h>
42 #include <AliAnalysisDataContainer.h>
43 #include "AliAnalysisManager.h"
44 #include "AliESDtrack.h"
45 #include "AliVertexerTracks.h"
46 #include "AliAODHandler.h"
47 #include "AliAODEvent.h"
48 #include "AliAODVertex.h"
49 #include "AliAODTrack.h"
50 #include "AliAODMCHeader.h"
51 #include "AliAODMCParticle.h"
53 #include "AliAODRecoCascadeHF.h"
54 #include "AliAnalysisVertexingHF.h"
55 #include "AliAnalysisTaskSE.h"
58 
59 using std::cout;
60 using std::endl;
61 
63 ClassImp(AliAnalysisTaskSED0Mass);
65 
66 //________________________________________________________________________
69  fOutputMass(0),
70  fOutputMassPt(0),
71  fOutputMassY(0),
72  fDistr(0),
73  fNentries(0),
74  fMCAccPrompt(0),
75  fMCAccBFeed(0),
76  fStepMCAcc(kTRUE),
77  fCuts(0),
78  fArray(0),
79  fReadMC(0),
80  fCutOnDistr(0),
81  fUsePid4Distr(0),
82  fCounter(0),
83  fNPtBins(1),
84  fLsNormalization(1.),
85  fFillOnlyD0D0bar(0),
86  fDaughterTracks(),
87  fIsSelectedCandidate(0),
88  fFillVarHists(kTRUE),
89  fSys(0),
90  fIsRejectSDDClusters(0),
91  fFillPtHist(kTRUE),
92  fFillYHist(kFALSE),
93  fFillImpParHist(kFALSE),
94  fFillSubSampleHist(kFALSE),
95  fEventCounter(0),
96  fUseSelectionBit(kTRUE),
97  fAODProtection(1),
98  fWriteVariableTree(kFALSE),
99  fVariablesTree(0),
100  fCandidateVariables(),
101  fPIDCheck(kFALSE),
102  fDrawDetSignal(kFALSE),
103  fUseQuarkTagInKine(kTRUE),
104  fFillSparses(0),
105  fhStudyImpParSingleTrackSign(0),
106  fhStudyImpParSingleTrackCand(0),
107  fhStudyImpParSingleTrackFd(0),
108  fDetSignal(0),
109  fhMultVZEROTPCoutTrackCorrNoCut(0x0),
110  fhMultVZEROTPCoutTrackCorr(0x0),
111  fEnablePileupRejVZEROTPCout(kFALSE)
112 {
114  for(Int_t ih=0; ih<5; ih++) fHistMassPtImpParTC[ih]=0x0;
115 
116 }
117 
118 //________________________________________________________________________
120  AliAnalysisTaskSE(name),
121  fOutputMass(0),
122  fOutputMassPt(0),
123  fOutputMassY(0),
124  fDistr(0),
125  fNentries(0),
126  fMCAccPrompt(0),
127  fMCAccBFeed(0),
128  fStepMCAcc(kTRUE),
129  fCuts(0),
130  fArray(0),
131  fReadMC(0),
132  fCutOnDistr(0),
133  fUsePid4Distr(0),
134  fCounter(0),
135  fNPtBins(1),
136  fLsNormalization(1.),
137  fFillOnlyD0D0bar(0),
138  fDaughterTracks(),
140  fFillVarHists(kTRUE),
141  fSys(0),
143  fFillPtHist(kTRUE),
144  fFillYHist(kFALSE),
145  fFillImpParHist(kFALSE),
146  fFillSubSampleHist(kFALSE),
147  fEventCounter(0),
148  fUseSelectionBit(kTRUE),
149  fAODProtection(1),
150  fWriteVariableTree(kFALSE),
151  fVariablesTree(0),
153  fPIDCheck(kFALSE),
154  fDrawDetSignal(kFALSE),
155  fUseQuarkTagInKine(kTRUE),
156  fFillSparses(0),
160  fDetSignal(0),
164 {
166 
167  fNPtBins=cuts->GetNPtBins();
168 
169  fCuts=cuts;
170  for(Int_t ih=0; ih<5; ih++) fHistMassPtImpParTC[ih]=0x0;
171 
172  // Output slot #1 writes into a TList container (mass with cuts)
173  DefineOutput(1,TList::Class()); //My private output
174  // Output slot #2 writes into a TList container (distributions)
175  DefineOutput(2,TList::Class()); //My private output
176  // Output slot #3 writes into a TH1F container (number of events)
177  DefineOutput(3,TH1F::Class()); //My private output
178  // Output slot #4 writes into a TList container (cuts)
179  DefineOutput(4,AliRDHFCutsD0toKpi::Class()); //My private output
180  // Output slot #5 writes Normalization Counter
181  DefineOutput(5,AliNormalizationCounter::Class());
182  // Output slot #6 stores the mass vs pt and impact parameter distributions
183  DefineOutput(6,TList::Class()); //My private output
184  // Output slot #7 keeps a tree of the candidate variables after track selection
185  DefineOutput(7,TTree::Class()); //My private outpu
186  // Output slot #8 writes into a TList container (Detector signals)
187  DefineOutput(8, TList::Class()); //My private output
188  // Output slot #9 stores the mass vs rapidity (y) distributions
189  DefineOutput(9, TList::Class()); //My private output
190 }
191 
192 //________________________________________________________________________
194 {
195  if (fOutputMass) {
196  delete fOutputMass;
197  fOutputMass = 0;
198  }
199  if (fOutputMassPt) {
200  delete fOutputMassPt;
201  fOutputMassPt = 0;
202  }
203  if (fOutputMassY) {
204  delete fOutputMassY;
205  fOutputMassY = 0;
206  }
207  if (fDistr) {
208  delete fDistr;
209  fDistr = 0;
210  }
211  if (fCuts) {
212  delete fCuts;
213  fCuts = 0;
214  }
215  for(Int_t i=0; i<5; i++){
216  if(fHistMassPtImpParTC[i]) delete fHistMassPtImpParTC[i];
217  }
218  if (fNentries){
219  delete fNentries;
220  fNentries = 0;
221  }
222  if(fCounter){
223  delete fCounter;
224  fCounter=0;
225  }
226  if(fVariablesTree){
227  delete fVariablesTree;
228  fVariablesTree = 0;
229  }
230  if (fDetSignal) {
231  delete fDetSignal;
232  fDetSignal = 0;
233  }
234  delete fMCAccPrompt;
235  delete fMCAccBFeed;
239 
243  }
247  }
248 
249 }
250 
251 //________________________________________________________________________
253 {
255 
256  if(fDebug > 1) printf("AnalysisTaskSED0Mass::Init() \n");
257 
258 
260  const char* nameoutput=GetOutputSlot(4)->GetContainer()->GetName();
261  copyfCuts->SetName(nameoutput);
262  // Post the data
263  PostData(4,copyfCuts);
264 
265 
266  return;
267 }
268 
269 //________________________________________________________________________
271 {
272 
274  //
275  if(fDebug > 1) printf("AnalysisTaskSED0Mass::UserCreateOutputObjects() \n");
276 
277  // Several histograms are more conveniently managed in a TList
278  fOutputMass = new TList();
279  fOutputMass->SetOwner();
280  fOutputMass->SetName("listMass");
281 
282  fOutputMassPt = new TList();
283  fOutputMassPt->SetOwner();
284  fOutputMassPt->SetName("listMassPt");
285 
286  fOutputMassY = new TList();
287  fOutputMassY->SetOwner();
288  fOutputMassY->SetName("listMassY");
289 
290  fDistr = new TList();
291  fDistr->SetOwner();
292  fDistr->SetName("distributionslist");
293 
294  fDetSignal = new TList();
295  fDetSignal->SetOwner();
296  fDetSignal->SetName("detectorsignals");
297 
298  TString nameMass=" ",nameSgn27=" ",nameSgn=" ", nameBkg=" ", nameRfl=" ",nameMassNocutsS =" ",nameMassNocutsB =" ", namedistr=" ";
299  TString nameMassPt="", nameSgnPt="", nameBkgPt="", nameRflPt="";
300  TString nameMassY="", nameSgnY="", nameBkgY="", nameRflY="";
301  TString nameMassSubSample="";
302  Int_t nbins2dPt=60; Float_t binInPt=0., binFinPt=30.;
303  Int_t nbins2dY=60; Float_t binInY=-1.5, binFinY=1.5;
304 
305  for(Int_t i=0;i<fCuts->GetNPtBins();i++){
306 
307  nameMass="histMass_";
308  nameMass+=i;
309  nameSgn27="histSgn27_";
310  nameSgn27+=i;
311  nameSgn="histSgn_";
312  nameSgn+=i;
313  nameBkg="histBkg_";
314  nameBkg+=i;
315  nameRfl="histRfl_";
316  nameRfl+=i;
317  nameMassNocutsS="hMassS_";
318  nameMassNocutsS+=i;
319  nameMassNocutsB="hMassB_";
320  nameMassNocutsB+=i;
321 
322  //histograms of cut variable distributions
323  if(fFillVarHists){
324  if(fReadMC){
325 
326  namedistr="hNclsD0vsptS_";
327  namedistr+=i;
328  TH2F *hNclsD0vsptS = new TH2F(namedistr.Data(),"N cls distrubution [S];p_{T} [GeV/c];N cls",200,0.,20.,100,0.,200.);
329  namedistr="hNclsD0barvsptS_";
330  namedistr+=i;
331  TH2F *hNclsD0barvsptS = new TH2F(namedistr.Data(),"N cls distrubution [S];p_{T} [GeV/c];N cls",200,0.,20.,100,0.,200.);
332 
333  namedistr="hNITSpointsD0vsptS_";
334  namedistr+=i;
335  TH2F *hNITSpointsD0vsptS = new TH2F(namedistr.Data(),"N ITS points distrubution [S];p_{T} [GeV/c];N points",200,0.,20.,7,0.,7.);
336 
337  namedistr="hNSPDpointsD0S_";
338  namedistr+=i;
339  TH1I *hNSPDpointsD0S = new TH1I(namedistr.Data(),"N SPD points distrubution [S]; ;N tracks",4,0,4);
340  hNSPDpointsD0S->GetXaxis()->SetBinLabel(1, "no SPD");
341  hNSPDpointsD0S->GetXaxis()->SetBinLabel(2, "kOnlyFirst");
342  hNSPDpointsD0S->GetXaxis()->SetBinLabel(3, "kOnlySecond");
343  hNSPDpointsD0S->GetXaxis()->SetBinLabel(4, "kBoth");
344 
345  namedistr="hptD0S_";
346  namedistr+=i;
347  TH1F *hptD0S = new TH1F(namedistr.Data(), "p_{T} distribution [S];p_{T} [GeV/c]",200,0.,20.);
348  namedistr="hptD0barS_";
349  namedistr+=i;
350  TH1F *hptD0barS = new TH1F(namedistr.Data(), "p_{T} distribution [S];p_{T} [GeV/c]",200,0.,20.);
351 
352  namedistr="hphiD0S_";
353  namedistr+=i;
354  TH1F *hphiD0S = new TH1F(namedistr.Data(), "#phi distribution [S];#phi [rad]",100,0.,2*TMath::Pi());
355  namedistr="hphiD0barS_";
356  namedistr+=i;
357  TH1F *hphiD0barS = new TH1F(namedistr.Data(), "#phi distribution [S];#phi [rad]",100,0.,2*TMath::Pi());
358 
359 
360  namedistr="hetaphiD0candidateS_";
361  namedistr+=i;
362  TH2F *hetaphiD0candidateS = new TH2F(namedistr.Data(), "D^{0} candidates #eta #phi distribution [S];#eta;#phi [rad]",100, -1.5, 1.5, 100, 0.,2*TMath::Pi());
363  namedistr="hetaphiD0barcandidateS_";
364  namedistr+=i;
365  TH2F *hetaphiD0barcandidateS = new TH2F(namedistr.Data(), "anti-D^{0} candidates #eta #phi distribution [S];#eta;#phi [rad]",100, -1.5, 1.5, 100, 0.,2*TMath::Pi());
366 
367  namedistr="hetaphiD0candidatesignalregionS_";
368  namedistr+=i;
369  TH2F *hetaphiD0candidatesignalregionS = new TH2F(namedistr.Data(), "D^{0} candidates #eta #phi distribution [S] [mass cut];#eta;#phi [rad]",100, -1.5, 1.5, 100, 0.,2*TMath::Pi());
370  namedistr="hetaphiD0barcandidatesignalregionS_";
371  namedistr+=i;
372  TH2F *hetaphiD0barcandidatesignalregionS = new TH2F(namedistr.Data(), "anti-D^{0} candidates #eta #phi distribution [S] [mass cut];#eta;#phi [rad]",100, -1.5, 1.5, 100, 0.,2*TMath::Pi());
373 
374  // dca
375  namedistr="hdcaS_";
376  namedistr+=i;
377  TH1F *hdcaS = new TH1F(namedistr.Data(), "DCA distribution;dca [cm]",200,0.,0.1);
378  // impact parameter
379  namedistr="hd0piS_";
380  namedistr+=i;
381  TH1F *hd0piS = new TH1F(namedistr.Data(), "Impact parameter distribution (pions);d0(#pi) [cm]",200,-0.1,0.1);
382 
383  namedistr="hd0KS_";
384  namedistr+=i;
385  TH1F *hd0KS = new TH1F(namedistr.Data(), "Impact parameter distribution (kaons);d0(K) [cm]",200,-0.1,0.1);
386  namedistr="hd0d0S_";
387  namedistr+=i;
388  TH1F *hd0d0S = new TH1F(namedistr.Data(), "d_{0}#timesd_{0} distribution;d_{0}#timesd_{0} [cm^{2}]",200,-0.001,0.001);
389 
390  //decay lenght
391  namedistr="hdeclS_";
392  namedistr+=i;
393  TH1F *hdeclengthS = new TH1F(namedistr.Data(), "Decay Length^{2} distribution;Decay Length^{2} [cm]",200,0,0.015);
394 
395  namedistr="hnormdeclS_";
396  namedistr+=i;
397  TH1F *hnormdeclengthS = new TH1F(namedistr.Data(), "Normalized Decay Length^{2} distribution;(Decay Length/Err)^{2} ",200,0,12.);
398 
399  namedistr="hdeclxyS_";
400  namedistr+=i;
401  TH1F* hdeclxyS=new TH1F(namedistr.Data(),"Decay Length XY distribution;Decay Length XY [cm]",200,0,0.15);
402  namedistr="hnormdeclxyS_";
403  namedistr+=i;
404  TH1F* hnormdeclxyS=new TH1F(namedistr.Data(),"Normalized decay Length XY distribution;Decay Length XY/Err",200,0,6.);
405 
406  namedistr="hdeclxyd0d0S_";
407  namedistr+=i;
408  TH2F* hdeclxyd0d0S=new TH2F(namedistr.Data(),"Correlation decay Length XY - d_{0}#times d_{0};Decay Length XY [cm];d_{0}#times d_{0}[cm^{2}]",200,0,0.15,200,-0.001,0.001);
409 
410  namedistr="hnormdeclxyd0d0S_";
411  namedistr+=i;
412  TH2F* hnormdeclxyd0d0S=new TH2F(namedistr.Data(),"Correlation normalized decay Length XY - d_{0}#times d_{0};Decay Length XY/Err;d_{0}#times d_{0}[cm^{2}]",200,0,6,200,-0.001,0.001);
413 
414  // costhetapoint
415  namedistr="hcosthetapointS_";
416  namedistr+=i;
417  TH1F *hcosthetapointS = new TH1F(namedistr.Data(), "cos#theta_{Point} distribution;cos#theta_{Point}",200,0,1.);
418 
419  namedistr="hcosthetapointxyS_";
420  namedistr+=i;
421  TH1F *hcosthetapointxyS = new TH1F(namedistr.Data(), "cos#theta_{Point} XYdistribution;cos#theta_{Point}",300,0.,1.);
422 
423  TH1F* tmpMS = new TH1F(nameMassNocutsS.Data(),"D^{0} invariant mass; M [GeV]; Entries",600,1.6248,2.2248); //range (MD0-300MeV, mD0 + 300MeV)
424  tmpMS->Sumw2();
425 
426  fDistr->Add(hNclsD0vsptS);
427  fDistr->Add(hNclsD0barvsptS);
428  fDistr->Add(hNITSpointsD0vsptS);
429  fDistr->Add(hNSPDpointsD0S);
430  fDistr->Add(hptD0S);
431  fDistr->Add(hphiD0S);
432  fDistr->Add(hptD0barS);
433  fDistr->Add(hphiD0barS);
434  fDistr->Add(hetaphiD0candidateS);
435  fDistr->Add(hetaphiD0candidatesignalregionS);
436  fDistr->Add(hetaphiD0barcandidateS);
437  fDistr->Add(hetaphiD0barcandidatesignalregionS);
438 
439  fDistr->Add(hdcaS);
440 
441  fDistr->Add(hd0piS);
442  fDistr->Add(hd0KS);
443 
444  fDistr->Add(hd0d0S);
445 
446  fDistr->Add(hcosthetapointS);
447 
448  fDistr->Add(hcosthetapointxyS);
449 
450  fDistr->Add(hdeclengthS);
451 
452  fDistr->Add(hnormdeclengthS);
453 
454  fDistr->Add(hdeclxyS);
455 
456  fDistr->Add(hnormdeclxyS);
457 
458  fDistr->Add(hdeclxyd0d0S);
459  fDistr->Add(hnormdeclxyd0d0S);
460 
461  fDistr->Add(tmpMS);
462  }
463 
464 
465  //Ncls, phi, pt distrubutions
466 
467  namedistr="hNclsD0vsptB_";
468  namedistr+=i;
469  TH2F *hNclsD0vsptB = new TH2F(namedistr.Data(),"N cls distrubution [B];p_{T} [GeV/c];N cls",200,0.,20.,100,0.,200.);
470  namedistr="hNclsD0barvsptB_";
471  namedistr+=i;
472  TH2F *hNclsD0barvsptB = new TH2F(namedistr.Data(),"N cls distrubution [B];p_{T} [GeV/c];N cls",200,0.,20.,100,0.,200.);
473 
474  namedistr="hNITSpointsD0vsptB_";
475  namedistr+=i;
476  TH2F *hNITSpointsD0vsptB = new TH2F(namedistr.Data(),"N ITS points distrubution [B];p_{T} [GeV/c];N points",200,0.,20.,7,0.,7.);
477 
478  namedistr="hNSPDpointsD0B_";
479  namedistr+=i;
480  TH1I *hNSPDpointsD0B = new TH1I(namedistr.Data(),"N SPD points distrubution [B]; ;N tracks",4,0,4);
481  hNSPDpointsD0B->GetXaxis()->SetBinLabel(1, "no SPD");
482  hNSPDpointsD0B->GetXaxis()->SetBinLabel(2, "kOnlyFirst");
483  hNSPDpointsD0B->GetXaxis()->SetBinLabel(3, "kOnlySecond");
484  hNSPDpointsD0B->GetXaxis()->SetBinLabel(4, "kBoth");
485 
486  namedistr="hptD0B_";
487  namedistr+=i;
488  TH1F *hptD0B = new TH1F(namedistr.Data(), "p_{T} distribution [B];p_{T} [GeV/c]",200,0.,20.);
489  namedistr="hptD0barB_";
490  namedistr+=i;
491  TH1F *hptD0barB = new TH1F(namedistr.Data(), "p_{T} distribution [B];p_{T} [GeV/c]",200,0.,20.);
492 
493  namedistr="hphiD0B_";
494  namedistr+=i;
495  TH1F *hphiD0B = new TH1F(namedistr.Data(), "#phi distribution [B];#phi [rad]",100,0.,2*TMath::Pi());
496  namedistr="hphiD0barB_";
497  namedistr+=i;
498  TH1F *hphiD0barB = new TH1F(namedistr.Data(), "#phi distribution [B];#phi [rad]",100,0.,2*TMath::Pi());
499 
500  namedistr="hetaphiD0candidateB_";
501  namedistr+=i;
502  TH2F *hetaphiD0candidateB = new TH2F(namedistr.Data(), "D^{0} candidates #eta #phi distribution [B];#eta;#phi [rad]",100, -1.5, 1.5, 100, 0.,2*TMath::Pi());
503  namedistr="hetaphiD0barcandidateB_";
504  namedistr+=i;
505  TH2F *hetaphiD0barcandidateB = new TH2F(namedistr.Data(), "anti-D^{0} candidates #eta #phi distribution [B];#eta;#phi [rad]",100, -1.5, 1.5, 100, 0.,2*TMath::Pi());
506 
507  namedistr="hetaphiD0candidatesignalregionB_";
508  namedistr+=i;
509  TH2F *hetaphiD0candidatesignalregionB = new TH2F(namedistr.Data(), "D^{0} candidates #eta #phi distribution [B] [mass cut];#eta;#phi [rad]",100, -1.5, 1.5, 100, 0.,2*TMath::Pi());
510  namedistr="hetaphiD0barcandidatesignalregionB_";
511  namedistr+=i;
512  TH2F *hetaphiD0barcandidatesignalregionB = new TH2F(namedistr.Data(), "anti-D^{0} candidates #eta #phi distribution [B] [mass cut];#eta;#phi [rad]",100, -1.5, 1.5, 100, 0.,2*TMath::Pi());
513 
514  // dca
515  namedistr="hdcaB_";
516  namedistr+=i;
517  TH1F *hdcaB = new TH1F(namedistr.Data(), "DCA distribution;dca [cm]",200,0.,0.1);
518 
519  // impact parameter
520  namedistr="hd0B_";
521  namedistr+=i;
522  TH1F *hd0B = new TH1F(namedistr.Data(), "Impact parameter distribution (both);d0 [cm]",200,-0.1,0.1);
523 
524  namedistr="hd0d0B_";
525  namedistr+=i;
526  TH1F *hd0d0B = new TH1F(namedistr.Data(), "d_{0}#timesd_{0} distribution;d_{0}#timesd_{0} [cm^{2}]",200,-0.001,0.001);
527 
528  //decay lenght
529  namedistr="hdeclB_";
530  namedistr+=i;
531  TH1F *hdeclengthB = new TH1F(namedistr.Data(), "Decay Length^{2} distribution;Decay Length^{2} [cm^{2}]",200,0,0.015);
532 
533  namedistr="hnormdeclB_";
534  namedistr+=i;
535  TH1F *hnormdeclengthB = new TH1F(namedistr.Data(), "Normalized Decay Length distribution;(Decay Length/Err)^{2} ",200,0,12.);
536 
537  namedistr="hdeclxyB_";
538  namedistr+=i;
539  TH1F* hdeclxyB=new TH1F(namedistr.Data(),"Decay Length XY distribution;Decay Length XY [cm]",200,0,0.15);
540  namedistr="hnormdeclxyB_";
541  namedistr+=i;
542  TH1F* hnormdeclxyB=new TH1F(namedistr.Data(),"Normalized decay Length XY distribution;Decay Length XY/Err",200,0,6.);
543 
544  namedistr="hdeclxyd0d0B_";
545  namedistr+=i;
546  TH2F* hdeclxyd0d0B=new TH2F(namedistr.Data(),"Correlation decay Length XY - d_{0}#times d_{0};Decay Length XY [cm];d_{0}#times d_{0}[cm^{2}]",200,0,0.15,200,-0.001,0.001);
547 
548  namedistr="hnormdeclxyd0d0B_";
549  namedistr+=i;
550  TH2F* hnormdeclxyd0d0B=new TH2F(namedistr.Data(),"Correlation normalized decay Length XY - d_{0}#times d_{0};Decay Length XY/Err;d_{0}#times d_{0}[cm^{2}]",200,0,6,200,-0.001,0.001);
551 
552  // costhetapoint
553  namedistr="hcosthetapointB_";
554  namedistr+=i;
555  TH1F *hcosthetapointB = new TH1F(namedistr.Data(), "cos#theta_{Point} distribution;cos#theta_{Point}",200,0,1.);
556 
557  namedistr="hcosthetapointxyB_";
558  namedistr+=i;
559  TH1F *hcosthetapointxyB = new TH1F(namedistr.Data(), "cos#theta_{Point} XY distribution;cos#theta_{Point} XY",300,0.,1.);
560 
561  TH1F* tmpMB = new TH1F(nameMassNocutsB.Data(),"D^{0} invariant mass; M [GeV]; Entries",600,1.6248,2.2248); //range (MD0-300MeV, mD0 + 300MeV)
562  tmpMB->Sumw2();
563 
564 
565  fDistr->Add(hNclsD0vsptB);
566  fDistr->Add(hNclsD0barvsptB);
567  fDistr->Add(hNITSpointsD0vsptB);
568  fDistr->Add(hNSPDpointsD0B);
569  fDistr->Add(hptD0B);
570  fDistr->Add(hphiD0B);
571  fDistr->Add(hptD0barB);
572  fDistr->Add(hphiD0barB);
573  fDistr->Add(hetaphiD0candidateB);
574  fDistr->Add(hetaphiD0candidatesignalregionB);
575  fDistr->Add(hetaphiD0barcandidateB);
576  fDistr->Add(hetaphiD0barcandidatesignalregionB);
577 
578  fDistr->Add(hdcaB);
579 
580  fDistr->Add(hd0B);
581 
582  fDistr->Add(hd0d0B);
583 
584  fDistr->Add(hcosthetapointB);
585 
586  fDistr->Add(hcosthetapointxyB);
587 
588  fDistr->Add(hdeclengthB);
589 
590  fDistr->Add(hnormdeclengthB);
591 
592  fDistr->Add(hdeclxyB);
593 
594  fDistr->Add(hnormdeclxyB);
595 
596  fDistr->Add(hdeclxyd0d0B);
597  fDistr->Add(hnormdeclxyd0d0B);
598 
599  fDistr->Add(tmpMB);
600 
601  //histograms filled only when the secondary vertex is recalculated w/o the daughter tracks (as requested in the cut object)
602 
604  if(fReadMC){
605  namedistr="hd0vpiS_";
606  namedistr+=i;
607  TH1F *hd0vpiS = new TH1F(namedistr.Data(), "Impact parameter distribution (pions)(vtx w/o these tracks);d0(#pi) [cm]",200,-0.1,0.1);
608 
609  namedistr="hd0vKS_";
610  namedistr+=i;
611  TH1F *hd0vKS = new TH1F(namedistr.Data(), "Impact parameter distribution (kaons) (vtx w/o these tracks);d0(K) [cm]",200,-0.1,0.1);
612 
613  namedistr="hd0d0vS_";
614  namedistr+=i;
615  TH1F *hd0d0vS = new TH1F(namedistr.Data(), "d_{0}#timesd_{0} distribution (vtx w/o these tracks);d_{0}#timesd_{0} [cm^{2}]",200,-0.001,0.001);
616 
617  namedistr="hdeclvS_";
618  namedistr+=i;
619  TH1F *hdeclengthvS = new TH1F(namedistr.Data(), "Decay Length distribution (vtx w/o tracks);Decay Length [cm]",200,0,0.6);
620 
621  namedistr="hnormdeclvS_";
622  namedistr+=i;
623  TH1F *hnormdeclengthvS = new TH1F(namedistr.Data(), "Normalized Decay Length distribution (vtx w/o tracks);Decay Length/Err ",200,0,10.);
624 
625  fDistr->Add(hd0vpiS);
626  fDistr->Add(hd0vKS);
627  fDistr->Add(hd0d0vS);
628  fDistr->Add(hdeclengthvS);
629  fDistr->Add(hnormdeclengthvS);
630 
631  }
632 
633  namedistr="hd0vmoresB_";
634  namedistr+=i;
635  TH1F *hd0vmoresB = new TH1F(namedistr.Data(), "Impact parameter distribution (both);d0 [cm]",200,-0.1,0.1);
636 
637  namedistr="hd0d0vmoresB_";
638  namedistr+=i;
639  TH1F *hd0d0vmoresB = new TH1F(namedistr.Data(), "Impact parameter distribution (prong +);d0 [cm]",200,-0.001,0.001);
640 
641 
642  namedistr="hd0vB_";
643  namedistr+=i;
644  TH1F *hd0vB = new TH1F(namedistr.Data(), "Impact parameter distribution (vtx w/o these tracks);d0 [cm]",200,-0.1,0.1);
645 
646  namedistr="hd0vp0B_";
647  namedistr+=i;
648  TH1F *hd0vp0B = new TH1F(namedistr.Data(), "Impact parameter distribution (prong + ** vtx w/o these tracks);d0 [cm]",200,-0.1,0.1);
649 
650  namedistr="hd0vp1B_";
651  namedistr+=i;
652  TH1F *hd0vp1B = new TH1F(namedistr.Data(), "Impact parameter distribution (prong - ** vtx w/o these tracks);d0 [cm]",200,-0.1,0.1);
653 
654  namedistr="hd0d0vB_";
655  namedistr+=i;
656  TH1F *hd0d0vB = new TH1F(namedistr.Data(), "d_{0}#timesd_{0} distribution (vtx w/o these tracks);d_{0}#timesd_{0} [cm^{2}]",200,-0.001,0.001);
657 
658  namedistr="hdeclvB_";
659  namedistr+=i;
660  TH1F *hdeclengthvB = new TH1F(namedistr.Data(), "Decay Length distribution (vtx w/o tracks);Decay Length [cm]",200,0,0.6);
661 
662  namedistr="hnormdeclvB_";
663  namedistr+=i;
664  TH1F *hnormdeclengthvB = new TH1F(namedistr.Data(), "Normalized Decay Length distribution (vtx w/o tracks);Decay Length/Err ",200,0,10.);
665 
666  fDistr->Add(hd0vB);
667  fDistr->Add(hd0vp0B);
668  fDistr->Add(hd0vp1B);
669  fDistr->Add(hd0vmoresB);
670 
671  fDistr->Add(hd0d0vB);
672  fDistr->Add(hd0d0vmoresB);
673 
674  fDistr->Add(hdeclengthvB);
675 
676  fDistr->Add(hnormdeclengthvB);
677  }
678 
679 
680  }
681  //histograms of invariant mass distributions
682 
683 
684  //MC signal
685  if(fReadMC){
686  TH1F* tmpSt = new TH1F(nameSgn.Data(), "D^{0} invariant mass - MC; M [GeV]; Entries",600,1.6248,2.2248);
687 
688  TH1F *tmpSl=(TH1F*)tmpSt->Clone();
689  tmpSt->Sumw2();
690  tmpSl->Sumw2();
691 
692  //Reflection: histo filled with D0Mass which pass the cut (also) as D0bar and with D0bar which pass (also) the cut as D0
693  TH1F* tmpRt = new TH1F(nameRfl.Data(), "Reflected signal invariant mass - MC; M [GeV]; Entries",600,1.6248,2.2248);
694  //TH1F *tmpRl=(TH1F*)tmpRt->Clone();
695  TH1F* tmpBt = new TH1F(nameBkg.Data(), "Background invariant mass - MC; M [GeV]; Entries",600,1.6248,2.2248);
696  //TH1F *tmpBl=(TH1F*)tmpBt->Clone();
697  tmpBt->Sumw2();
698  //tmpBl->Sumw2();
699  tmpRt->Sumw2();
700  //tmpRl->Sumw2();
701 
702  fOutputMass->Add(tmpSt);
703  fOutputMass->Add(tmpRt);
704  fOutputMass->Add(tmpBt);
705 
706  }
707 
708  //mass
709  TH1F* tmpMt = new TH1F(nameMass.Data(),"D^{0} invariant mass; M [GeV]; Entries",600,1.6248,2.2248);
710  //TH1F *tmpMl=(TH1F*)tmpMt->Clone();
711  tmpMt->Sumw2();
712  //tmpMl->Sumw2();
713  //distribution w/o cuts large range
714  // TH1F* tmpMS = new TH1F(nameMassNocutsS.Data(),"D^{0} invariant mass; M [GeV]; Entries",300,0.7,3.);
715 
716  fOutputMass->Add(tmpMt);
717 
718  //sub sample
719  if(fFillSubSampleHist){
720  nameMassSubSample="histMassvsSubSample_";
721  nameMassSubSample+=i;
722  TH2F* tmpMtSub = new TH2F(nameMassSubSample.Data(),"D^{0} invariant mass; M [GeV]; Sample ID; Entries",600,1.6248,2.2248,25,-0.5,24.5);
723  tmpMtSub->Sumw2();
724  fOutputMass->Add(tmpMtSub);
725  }
726 
727  if(fSys==0){ //histograms filled only in pp to save time in PbPb
728  if(fFillVarHists){
729 
730  if(fReadMC){
731  // pT
732  namedistr="hptpiS_";
733  namedistr+=i;
734  TH1F *hptpiS = new TH1F(namedistr.Data(), "P_{T} distribution (pions);p_{T} [GeV/c]",200,0.,8.);
735 
736  namedistr="hptKS_";
737  namedistr+=i;
738  TH1F *hptKS = new TH1F(namedistr.Data(), "P_{T} distribution (kaons);p_{T} [GeV/c]",200,0.,8.);
739 
740  // costhetastar
741  namedistr="hcosthetastarS_";
742  namedistr+=i;
743  TH1F *hcosthetastarS = new TH1F(namedistr.Data(), "cos#theta* distribution;cos#theta*",200,-1.,1.);
744 
745  //pT no mass cut
746 
747  namedistr="hptpiSnoMcut_";
748  namedistr+=i;
749  TH1F *hptpiSnoMcut = new TH1F(namedistr.Data(), "P_{T} distribution (pions);p_{T} [GeV/c]",200,0.,8.);
750 
751  namedistr="hptKSnoMcut_";
752  namedistr+=i;
753  TH1F *hptKSnoMcut = new TH1F(namedistr.Data(), "P_{T} distribution (kaons);p_{T} [GeV/c]",200,0.,8.);
754 
755  fDistr->Add(hptpiS);
756  fDistr->Add(hptKS);
757  fDistr->Add(hcosthetastarS);
758 
759  fDistr->Add(hptpiSnoMcut);
760  fDistr->Add(hptKSnoMcut);
761 
762  // costhetapoint vs d0 or d0d0
763  namedistr="hcosthpointd0S_";
764  namedistr+=i;
765  TH2F *hcosthpointd0S= new TH2F(namedistr.Data(),"Correlation cos#theta_{Point}-d_{0};cos#theta_{Point};d_{0} [cm^{2}]",200,0,1.,200,-0.001,0.001);
766  namedistr="hcosthpointd0d0S_";
767  namedistr+=i;
768  TH2F *hcosthpointd0d0S= new TH2F(namedistr.Data(),"Correlation cos#theta_{Point}-d_{0}#timesd_{0};cos#theta_{Point};d_{0}#timesd_{0} [cm^{2}]",200,0,1.,200,-0.001,0.001);
769 
770  fDistr->Add(hcosthpointd0S);
771  fDistr->Add(hcosthpointd0d0S);
772 
773  //to compare with AliAnalysisTaskCharmFraction
774  TH1F* tmpS27t = new TH1F(nameSgn27.Data(),"D^{0} invariant mass in M(D^{0}) +/- 27 MeV - MC; M [GeV]; Entries",600,1.6248,2.2248);
775  TH1F *tmpS27l=(TH1F*)tmpS27t->Clone();
776  tmpS27t->Sumw2();
777  tmpS27l->Sumw2();
778 
779  fOutputMass->Add(tmpS27t);
780  fOutputMass->Add(tmpS27l);
781 
782  }
783 
784  // pT
785  namedistr="hptB_";
786  namedistr+=i;
787  TH1F *hptB = new TH1F(namedistr.Data(), "P_{T} distribution;p_{T} [GeV/c]",200,0.,8.);
788 
789  // costhetastar
790  namedistr="hcosthetastarB_";
791  namedistr+=i;
792  TH1F *hcosthetastarB = new TH1F(namedistr.Data(), "cos#theta* distribution;cos#theta*",200,-1.,1.);
793 
794  //pT no mass cut
795  namedistr="hptB1prongnoMcut_";
796  namedistr+=i;
797  TH1F *hptB1pnoMcut = new TH1F(namedistr.Data(), "P_{T} distribution;p_{T} [GeV/c]",200,0.,8.);
798 
799  namedistr="hptB2prongsnoMcut_";
800  namedistr+=i;
801  TH1F *hptB2pnoMcut = new TH1F(namedistr.Data(), "P_{T} distribution;p_{T} [GeV/c]",200,0.,8.);
802 
803  fDistr->Add(hptB);
804  fDistr->Add(hcosthetastarB);
805 
806  fDistr->Add(hptB1pnoMcut);
807  fDistr->Add(hptB2pnoMcut);
808 
809  //impact parameter of negative/positive track
810  namedistr="hd0p0B_";
811  namedistr+=i;
812  TH1F *hd0p0B = new TH1F(namedistr.Data(), "Impact parameter distribution (prong +);d0 [cm]",200,-0.1,0.1);
813 
814  namedistr="hd0p1B_";
815  namedistr+=i;
816  TH1F *hd0p1B = new TH1F(namedistr.Data(), "Impact parameter distribution (prong -);d0 [cm]",200,-0.1,0.1);
817 
818  //impact parameter corrected for strangeness
819  namedistr="hd0moresB_";
820  namedistr+=i;
821  TH1F *hd0moresB = new TH1F(namedistr.Data(), "Impact parameter distribution (both);d0 [cm]",200,-0.1,0.1);
822 
823  namedistr="hd0d0moresB_";
824  namedistr+=i;
825  TH1F *hd0d0moresB = new TH1F(namedistr.Data(), "Impact parameter distribution (prong +);d0 [cm]",200,-0.001,0.001);
826 
827 
828  namedistr="hcosthetapointmoresB_";
829  namedistr+=i;
830  TH1F *hcosthetapointmoresB = new TH1F(namedistr.Data(), "cos#theta_{Point} distribution;cos#theta_{Point}",200,0,1.);
831 
832  // costhetapoint vs d0 or d0d0
833  namedistr="hcosthpointd0B_";
834  namedistr+=i;
835  TH2F *hcosthpointd0B= new TH2F(namedistr.Data(),"Correlation cos#theta_{Point}-d_{0};cos#theta_{Point};d_{0} [cm^{2}]",200,0,1.,200,-0.001,0.001);
836 
837  namedistr="hcosthpointd0d0B_";
838  namedistr+=i;
839  TH2F *hcosthpointd0d0B= new TH2F(namedistr.Data(),"Correlation cos#theta_{Point}-d_{0}#timesd_{0};cos#theta_{Point};d_{0}#timesd_{0} [cm^{2}]",200,0,1.,200,-0.001,0.001);
840 
841  fDistr->Add(hd0p0B);
842  fDistr->Add(hd0p1B);
843 
844  fDistr->Add(hd0moresB);
845  fDistr->Add(hd0d0moresB);
846  fDistr->Add(hcosthetapointmoresB);
847 
848 
849  fDistr->Add(hcosthpointd0B);
850 
851 
852  fDistr->Add(hcosthpointd0d0B);
853  }
854 
855  } //end pp histo
856  }
857  //create THnSparse for impact parameter analysis in DATA sample.
858  //pt, normImpParTrk1, normImpParTrk2, decLXY, normDecLXY, massd0, cut, pid, D0D0bar
859  if(fFillSparses){
860  Int_t nbinsImpParStudy[9]= {50, 40, 40, 20, 15, 600, 3,4,2};
861  Double_t limitLowImpParStudy[9]={0, -5, -5, 0, 0,1.6248,1,0,0};
862  Double_t limitUpImpParStudy[9]= {50., 5, 5, 0.2,15,2.2248,4,4,2};
863  TString axTit[9]={"#it{p}_{T} (GeV/c)","normalized imp par residual, trk1","normalized imp par residual, trk2","#it{L}_{xy} (cm)","norm #it{L}_{xy}","MassD0_{k#pi} (GeV/#it{c}^{2})", "cutSel","PIDinfo","D0D0bar"};
864  fhStudyImpParSingleTrackCand=new THnSparseF("fhStudyImpParSingleTrackCand","fhStudyImpParSingleTrackCand",9,nbinsImpParStudy,limitLowImpParStudy,limitUpImpParStudy);
865  for(Int_t iax=0; iax<9; iax++) fhStudyImpParSingleTrackCand->GetAxis(iax)->SetTitle(axTit[iax].Data());
867  }
868  if(fReadMC){
869 
870  if(fFillSparses){
871  //pt, ptB, normImpParTrk1, normImpParTrk2, decLXY, normDecLXY, iscut, ispid
872  Int_t nbinsImpParStudy[8]= {50,50,40, 40, 20, 15, 3, 4};
873  Double_t limitLowImpParStudy[8]={0, 0, -5,-5., 0., 0., 1.,0.};
874  Double_t limitUpImpParStudy[8]= {50.,50., 5, 5, 0.2, 15, 3.,4.};
875 
876  fhStudyImpParSingleTrackSign=new THnSparseF("fhStudyImpParSingleTrackSign","fhStudyImpParSingleTrackSign",8,nbinsImpParStudy,limitLowImpParStudy,limitUpImpParStudy);
877  TString axTitMC[8]={"#it{p}_{T} (GeV/c)","#it{p}_{T} (GeV/c)","normalized imp par residual, trk1","normalized imp par residual, trk2","#it{L}_{xy} (cm)","norm #it{L}_{xy}","cutSel","PIDinfo"};
878  for(Int_t iax=0; iax<8; iax++) fhStudyImpParSingleTrackSign->GetAxis(iax)->SetTitle(axTitMC[iax].Data());
880 
881 
882  fhStudyImpParSingleTrackFd=new THnSparseF("fhStudyImpParSingleTrackFd","fhStudyImpParSingleTrackFd",8,nbinsImpParStudy,limitLowImpParStudy,limitUpImpParStudy);
883  for(Int_t iax=0; iax<8; iax++) fhStudyImpParSingleTrackFd->GetAxis(iax)->SetTitle(axTitMC[iax].Data());
885  }
886 
888  }
889 
890 
891  //for Like sign analysis
892 
893  if(fArray==1){
894  namedistr="hpospair";
895  TH1F* hpospair=new TH1F(namedistr.Data(),"Number of positive pairs",fCuts->GetNPtBins(),-0.5,fCuts->GetNPtBins()-0.5);
896  namedistr="hnegpair";
897  TH1F* hnegpair=new TH1F(namedistr.Data(),"Number of negative pairs",fCuts->GetNPtBins(),-0.5,fCuts->GetNPtBins()-0.5);
898  fOutputMass->Add(hpospair);
899  fOutputMass->Add(hnegpair);
900  }
901 
902 
903  // 2D Pt distributions and impact parameter histograms
904  if(fFillPtHist) {
905 
906  nameMassPt="histMassPt";
907  nameSgnPt="histSgnPt";
908  nameBkgPt="histBkgPt";
909  nameRflPt="histRflPt";
910 
911  //MC signal
912  if(fReadMC){
913  TH2F* tmpStPt = new TH2F(nameSgnPt.Data(), "D^{0} invariant mass - MC; M [GeV]; Entries; Pt[GeV/c]",600,1.6248,2.2248,nbins2dPt,binInPt,binFinPt);
914  TH2F *tmpSlPt=(TH2F*)tmpStPt->Clone();
915  tmpStPt->Sumw2();
916  tmpSlPt->Sumw2();
917 
918  //Reflection: histo filled with D0MassV1 which pass the cut (also) as D0bar and with D0bar which pass (also) the cut as D0
919  TH2F* tmpRtPt = new TH2F(nameRflPt.Data(), "Reflected signal invariant mass - MC; M [GeV]; Entries; Pt[GeV/c]",600,1.6248,2.2248,nbins2dPt,binInPt,binFinPt);
920  TH2F* tmpBtPt = new TH2F(nameBkgPt.Data(), "Background invariant mass - MC; M [GeV]; Entries; Pt[GeV/c]",600,1.6248,2.2248,nbins2dPt,binInPt,binFinPt);
921  tmpBtPt->Sumw2();
922  tmpRtPt->Sumw2();
923 
924  fOutputMassPt->Add(tmpStPt);
925  fOutputMassPt->Add(tmpRtPt);
926  fOutputMassPt->Add(tmpBtPt);
927 
928  // cout<<endl<<endl<<"***************************************"<<endl;
929  // cout << " created and added to the list "<< nameSgnPt.Data() <<" "<< tmpStPt <<
930  // ", "<<nameRflPt.Data() <<" " << tmpRtPt<<", "<<nameBkgPt.Data()<< " " << tmpBtPt <<endl;
931  // cout<<"***************************************"<<endl<<endl;
932  }
933 
934  TH2F* tmpMtPt = new TH2F(nameMassPt.Data(),"D^{0} invariant mass; M [GeV]; Entries; Pt[GeV/c]",600,1.6248,2.2248,nbins2dPt,binInPt,binFinPt);
935  tmpMtPt->Sumw2();
936 
937  fOutputMassPt->Add(tmpMtPt);
938  }
939 
941 
942  // 2D Y distributions
943 
944  if(fFillYHist) {
945  for(Int_t i=0;i<fCuts->GetNPtBins();i++){
946  nameMassY="histMassY_";
947  nameMassY+=i;
948  nameSgnY="histSgnY_";
949  nameSgnY+=i;
950  nameBkgY="histBkgY_";
951  nameBkgY+=i;
952  nameRflY="histRflY_";
953  nameRflY+=i;
954  //MC signal
955  if(fReadMC){
956  TH2F* tmpStY = new TH2F(nameSgnY.Data(), "D^{0} invariant mass - MC; M [GeV]; Entries; y",600,1.6248,2.2248,nbins2dY,binInY,binFinY);
957  tmpStY->Sumw2();
958  //Reflection: histo filled with D0MassV1 which pass the cut (also) as D0bar and with D0bar which pass (also) the cut as D0
959  TH2F* tmpRtY = new TH2F(nameRflY.Data(), "Reflected signal invariant mass - MC; M [GeV]; Entries; y",600,1.6248,2.2248,nbins2dY,binInY,binFinY);
960  TH2F* tmpBtY = new TH2F(nameBkgY.Data(), "Background invariant mass - MC; M [GeV]; Entries; y",600,1.6248,2.2248,nbins2dY,binInY,binFinY);
961  tmpBtY->Sumw2();
962  tmpRtY->Sumw2();
963 
964  fOutputMassY->Add(tmpStY);
965  fOutputMassY->Add(tmpRtY);
966  fOutputMassY->Add(tmpBtY);
967  }
968  TH2F* tmpMtY = new TH2F(nameMassY.Data(),"D^{0} invariant mass; M [GeV]; Entries; y",600,1.6248,2.2248,nbins2dY,binInY,binFinY);
969  tmpMtY->Sumw2();
970  fOutputMassY->Add(tmpMtY);
971  }
972  }
973 
974 
975  const char* nameoutput=GetOutputSlot(3)->GetContainer()->GetName();
976 
977  fNentries=new TH1F(nameoutput, "Integral(1,2) = number of AODs *** Integral(2,3) = number of candidates selected with cuts *** Integral(3,4) = number of D0 selected with cuts *** Integral(4,5) = events with good vertex *** Integral(5,6) = pt out of bounds", 24,-0.5,23.5);
978 
979  fNentries->GetXaxis()->SetBinLabel(1,"nEventsAnal");
980  fNentries->GetXaxis()->SetBinLabel(2,"nCandSel(Cuts)");
981  if(fReadMC) fNentries->GetXaxis()->SetBinLabel(3,"nD0Selected");
982  else fNentries->GetXaxis()->SetBinLabel(3,"Dstar<-D0");
983  fNentries->GetXaxis()->SetBinLabel(4,"nEventsGoodVtxS");
984  fNentries->GetXaxis()->SetBinLabel(5,"ptbin = -1");
985  fNentries->GetXaxis()->SetBinLabel(6,"no daughter");
986  if(fSys==0) fNentries->GetXaxis()->SetBinLabel(7,"nCandSel(Tr)");
987  if(fFillVarHists || fPIDCheck){
988  fNentries->GetXaxis()->SetBinLabel(8,"PID=0");
989  fNentries->GetXaxis()->SetBinLabel(9,"PID=1");
990  fNentries->GetXaxis()->SetBinLabel(10,"PID=2");
991  fNentries->GetXaxis()->SetBinLabel(11,"PID=3");
992  }
993  if(fReadMC && fSys==0){
994  fNentries->GetXaxis()->SetBinLabel(12,"K");
995  fNentries->GetXaxis()->SetBinLabel(13,"Lambda");
996  }
997  fNentries->GetXaxis()->SetBinLabel(14,"Pile-up Rej");
998  fNentries->GetXaxis()->SetBinLabel(15,"N. of 0SMH");
999  if(fSys==1) fNentries->GetXaxis()->SetBinLabel(16,"Nev in centr");
1000  if(fIsRejectSDDClusters) fNentries->GetXaxis()->SetBinLabel(17,"SDD-Cls Rej");
1001  fNentries->GetXaxis()->SetBinLabel(18,"Phys.Sel.Rej");
1002  fNentries->GetXaxis()->SetBinLabel(19,"D0 failed to be filled");
1003  fNentries->GetXaxis()->SetBinLabel(20,"fisFilled is 0");
1004  fNentries->GetXaxis()->SetBinLabel(21,"fisFilled is 1");
1005  fNentries->GetXaxis()->SetBinLabel(22,"AOD/dAOD mismatch");
1006  fNentries->GetXaxis()->SetBinLabel(23,"AOD/dAOD #events ok");
1007  fNentries->GetXaxis()->SetBinLabel(24,"PreSelect rejection");
1008  fNentries->GetXaxis()->SetNdivisions(1,kFALSE);
1009 
1010  fCounter = new AliNormalizationCounter(Form("%s",GetOutputSlot(5)->GetContainer()->GetName()));
1011  fCounter->Init();
1012 
1013  //
1014  // Output slot 7 : tree of the candidate variables after track selection
1015  //
1016  nameoutput = GetOutputSlot(7)->GetContainer()->GetName();
1017  fVariablesTree = new TTree(nameoutput,"Candidates variables tree");
1018  Int_t nVar = 15;
1019  fCandidateVariables = new Double_t [nVar];
1020  TString * fCandidateVariableNames = new TString[nVar];
1021  fCandidateVariableNames[0] = "massD0";
1022  fCandidateVariableNames[1] = "massD0bar";
1023  fCandidateVariableNames[2] = "pt";
1024  fCandidateVariableNames[3] = "dca";
1025  fCandidateVariableNames[4] = "costhsD0";
1026  fCandidateVariableNames[5] = "costhsD0bar";
1027  fCandidateVariableNames[6] = "ptk";
1028  fCandidateVariableNames[7] = "ptpi";
1029  fCandidateVariableNames[8] = "d0k";
1030  fCandidateVariableNames[9] = "d0pi";
1031  fCandidateVariableNames[10] = "d0xd0";
1032  fCandidateVariableNames[11] = "costhp";
1033  fCandidateVariableNames[12] = "costhpxy";
1034  fCandidateVariableNames[13] = "lxy";
1035  fCandidateVariableNames[14] = "specialcuts";
1036  for(Int_t ivar=0; ivar<nVar; ivar++){
1037  fVariablesTree->Branch(fCandidateVariableNames[ivar].Data(),&fCandidateVariables[ivar],Form("%s/d",fCandidateVariableNames[ivar].Data()));
1038  }
1039 
1040 
1041  //
1042  // Output slot 8 : List for detector response histograms
1043  //
1044  if (fDrawDetSignal) {
1045  TH2F *TOFSigBefPID = new TH2F("TOFSigBefPID", "TOF signal of daughters before PID;p(daught)(GeV/c);Signal", 500, 0, 10, 5000, 0, 50e3);
1046  TH2F *TOFSigAftPID = new TH2F("TOFSigAftPID", "TOF signal after PID;p(daught)(GeV/c);Signal", 500, 0, 10, 5000, 0, 50e3);
1047 
1048  TH2F *TPCSigBefPID = new TH2F("TPCSigBefPID", "TPC dE/dx before PID;p(daught)(GeV/c);dE/dx (arb. units)", 1000, 0, 10, 1000, 0, 500);
1049  TH2F *TPCSigAftPID = new TH2F("TPCSigAftPID", "TPC dE/dx after PID;p(daught)(GeV/c);dE/dx (arb. units)", 1000, 0, 10, 1000, 0, 500);
1050 
1051  fDetSignal->Add(TOFSigBefPID);
1052  fDetSignal->Add(TOFSigAftPID);
1053  fDetSignal->Add(TPCSigBefPID);
1054  fDetSignal->Add(TPCSigAftPID);
1055  }
1056 
1057 
1058  fhMultVZEROTPCoutTrackCorrNoCut = new TH2F("hMultVZEROTPCoutTrackCorrNoCut", ";Tracks with kTPCout on;VZERO multiplicity", 1000, 0., 30000., 1000, 0., 40000.);
1059  fhMultVZEROTPCoutTrackCorr = new TH2F("hMultVZEROTPCoutTrackCorr", ";Tracks with kTPCout on;VZERO multiplicity", 1000, 0., 30000., 1000, 0., 40000.);
1062 
1063 
1064 
1065 
1066 
1067  // Post the data
1068  PostData(1,fOutputMass);
1069  PostData(2,fDistr);
1070  PostData(3,fNentries);
1071  PostData(5,fCounter);
1072  PostData(6,fOutputMassPt);
1073  PostData(7,fVariablesTree);
1074  PostData(8, fDetSignal);
1075  PostData(9,fOutputMassY);
1076 
1077  return;
1078 }
1079 
1080 //________________________________________________________________________
1082 
1083 {
1086 
1087  //cuts order
1088  // printf(" |M-MD0| [GeV] < %f\n",fD0toKpiCuts[0]);
1089  // printf(" dca [cm] < %f\n",fD0toKpiCuts[1]);
1090  // printf(" cosThetaStar < %f\n",fD0toKpiCuts[2]);
1091  // printf(" pTK [GeV/c] > %f\n",fD0toKpiCuts[3]);
1092  // printf(" pTpi [GeV/c] > %f\n",fD0toKpiCuts[4]);
1093  // printf(" |d0K| [cm] < %f\n",fD0toKpiCuts[5]);
1094  // printf(" |d0pi| [cm] < %f\n",fD0toKpiCuts[6]);
1095  // printf(" d0d0 [cm^2] < %f\n",fD0toKpiCuts[7]);
1096  // printf(" cosThetaPoint > %f\n",fD0toKpiCuts[8]);
1097 
1098  AliAODEvent *aod = dynamic_cast<AliAODEvent*> (InputEvent());
1099 
1100  if(fAODProtection>=0){
1101  // Protection against different number of events in the AOD and deltaAOD
1102  // In case of discrepancy the event is rejected.
1103  Int_t matchingAODdeltaAODlevel = AliRDHFCuts::CheckMatchingAODdeltaAODevents();
1104  if (matchingAODdeltaAODlevel<0 || (matchingAODdeltaAODlevel==0 && fAODProtection==1)) {
1105  // AOD/deltaAOD trees have different number of entries || TProcessID do not match while it was required
1106  fNentries->Fill(21);
1107  return;
1108  }
1109  fNentries->Fill(22);
1110  }
1111 
1112  TString bname;
1113  if(fArray==0){ //D0 candidates
1114  // load D0->Kpi candidates
1115  //cout<<"D0 candidates"<<endl;
1116  bname="D0toKpi";
1117  } else { //LikeSign candidates
1118  // load like sign candidates
1119  //cout<<"LS candidates"<<endl;
1120  bname="LikeSign2Prong";
1121  }
1122  TClonesArray *inputArray=0;
1123  if(!aod && AODEvent() && IsStandardAOD()) {
1124  // In case there is an AOD handler writing a standard AOD, use the AOD
1125  // event in memory rather than the input (ESD) event.
1126  aod = dynamic_cast<AliAODEvent*> (AODEvent());
1127  // in this case the braches in the deltaAOD (AliAOD.VertexingHF.root)
1128  // have to taken from the AOD event hold by the AliAODExtension
1129  AliAODHandler* aodHandler = (AliAODHandler*)
1130  ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
1131 
1132  if(aodHandler->GetExtensions()) {
1133  AliAODExtension *ext = (AliAODExtension*)aodHandler->GetExtensions()->FindObject("AliAOD.VertexingHF.root");
1134  AliAODEvent* aodFromExt = ext->GetAOD();
1135  inputArray=(TClonesArray*)aodFromExt->GetList()->FindObject(bname.Data());
1136  }
1137  } else if(aod) {
1138  inputArray=(TClonesArray*)aod->GetList()->FindObject(bname.Data());
1139  }
1140 
1141  if(!inputArray || !aod) {
1142  printf("AliAnalysisTaskSED0Mass::UserExec: input branch not found!\n");
1143  return;
1144  }
1145  // fix for temporary bug in ESDfilter
1146  // the AODs with null vertex pointer didn't pass the PhysSel
1147  if(!aod->GetPrimaryVertex() || TMath::Abs(aod->GetMagneticField())<0.001) return;
1148 
1149  TClonesArray *mcArray = 0;
1150  AliAODMCHeader *mcHeader = 0;
1151 
1152  if(fReadMC) {
1153  // load MC particles
1154  mcArray = (TClonesArray*)aod->GetList()->FindObject(AliAODMCParticle::StdBranchName());
1155  if(!mcArray) {
1156  printf("AliAnalysisTaskSED0Mass::UserExec: MC particles branch not found!\n");
1157  return;
1158  }
1159 
1160  // load MC header
1161  mcHeader = (AliAODMCHeader*)aod->GetList()->FindObject(AliAODMCHeader::StdBranchName());
1162  if(!mcHeader) {
1163  printf("AliAnalysisTaskSED0Mass::UserExec: MC header branch not found!\n");
1164  return;
1165  }
1166  }
1167  //printf("VERTEX Z %f %f\n",vtx1->GetZ(),mcHeader->GetVtxZ());
1168 
1169  Int_t nTPCout=0;
1170  Float_t mTotV0=0;
1171  AliAODVZERO* v0data=(AliAODVZERO*)((AliAODEvent*)aod)->GetVZEROData();
1172  Float_t mTotV0A=v0data->GetMTotV0A();
1173  Float_t mTotV0C=v0data->GetMTotV0C();
1174  mTotV0=mTotV0A+mTotV0C;
1175  Int_t ntracksEv = aod->GetNumberOfTracks();
1176  for(Int_t itrack=0; itrack<ntracksEv; itrack++) { // loop on tacks
1177  // ... get the track
1178  AliAODTrack * track = dynamic_cast<AliAODTrack*>(aod->GetTrack(itrack));
1179  if(!track) {AliFatal("Not a standard AOD");}
1180  if(track->GetID()<0)continue;
1181  if((track->GetFlags())&(AliESDtrack::kTPCout)) nTPCout++;
1182  else continue;
1183  }
1185  Float_t mV0Cut=-2200.+(2.5*nTPCout)+(0.000012*nTPCout*nTPCout);
1187  if(mTotV0<mV0Cut) return;
1188  }
1189 
1190  //histogram filled with 1 for every AOD
1191  fNentries->Fill(0);
1192 
1193 
1195  //fCounter->StoreEvent(aod,fReadMC);
1196  // trigger class for PbPb C0SMH-B-NOPF-ALLNOTRD, C0SMH-B-NOPF-ALL
1197  TString trigclass=aod->GetFiredTriggerClasses();
1198  if(trigclass.Contains("C0SMH-B-NOPF-ALLNOTRD") || trigclass.Contains("C0SMH-B-NOPF-ALL")) fNentries->Fill(14);
1199  if(fReadMC && fStepMCAcc){
1200  FillMCAcceptanceHistos(mcArray, mcHeader);
1201  }
1202 
1203  if(!fCuts->IsEventSelected(aod)) {
1204  if(fCuts->GetWhyRejection()==1) // rejected for pileup
1205  fNentries->Fill(13);
1206  if(fSys==1 && (fCuts->GetWhyRejection()==2 || fCuts->GetWhyRejection()==3)) fNentries->Fill(15);
1207  if(fCuts->GetWhyRejection()==7) fNentries->Fill(17);
1208  return;
1209  }
1210  // Check the Nb of SDD clusters
1211  if (fIsRejectSDDClusters) {
1212  Bool_t skipEvent = kFALSE;
1213  Int_t ntracks = 0;
1214  if (aod) ntracks = aod->GetNumberOfTracks();
1215  for(Int_t itrack=0; itrack<ntracks; itrack++) { // loop on tacks
1216  // ... get the track
1217  AliAODTrack * track = dynamic_cast<AliAODTrack*>(aod->GetTrack(itrack));
1218  if(!track) AliFatal("Not a standard AOD");
1219  if(TESTBIT(track->GetITSClusterMap(),2) || TESTBIT(track->GetITSClusterMap(),3) ){
1220  skipEvent=kTRUE;
1221  fNentries->Fill(16);
1222  break;
1223  }
1224  }
1225  if (skipEvent) return;
1226  }
1227 
1228 
1229  if(fhMultVZEROTPCoutTrackCorr)fhMultVZEROTPCoutTrackCorr->Fill(nTPCout,mTotV0);
1230 
1231 
1232  // AOD primary vertex
1233  AliAODVertex *vtx1 = (AliAODVertex*)aod->GetPrimaryVertex();
1234 
1235  Bool_t isGoodVtx=kFALSE;
1236 
1237  //vtx1->Print();
1238  TString primTitle = vtx1->GetTitle();
1239  if(primTitle.Contains("VertexerTracks") && vtx1->GetNContributors()>0) {
1240  isGoodVtx=kTRUE;
1241  fNentries->Fill(3);
1242  }
1243 
1244  fEventCounter++;
1245 
1246  // loop over candidates
1247  Int_t nInD0toKpi = inputArray->GetEntriesFast();
1248  if(fDebug>2) printf("Number of D0->Kpi: %d\n",nInD0toKpi);
1249 
1250  // FILE *f=fopen("4display.txt","a");
1251  // printf("Number of D0->Kpi: %d\n",nInD0toKpi);
1252  Int_t nSelectedloose=0,nSelectedtight=0;
1253 
1254  // vHF object is needed to call the method that refills the missing info of the candidates
1255  // if they have been deleted in dAOD reconstruction phase
1256  // in order to reduce the size of the file
1258 
1259  for (Int_t iD0toKpi = 0; iD0toKpi < nInD0toKpi; iD0toKpi++) {
1260  AliAODRecoDecayHF2Prong *d = (AliAODRecoDecayHF2Prong*)inputArray->UncheckedAt(iD0toKpi);
1261 
1263  fNentries->Fill(2);
1264  continue; //skip the D0 from Dstar
1265  }
1266  if(d->GetIsFilled()==0)fNentries->Fill(19);//tmp check
1267  if(d->GetIsFilled()==1)fNentries->Fill(20);//tmp check
1268  TObjArray arrTracks(2);
1269  Float_t xy[2],z[2];
1270  Float_t px[2],py[2];
1271  for(Int_t ipr=0;ipr<2;ipr++){
1272  AliAODTrack *tr=vHF->GetProng(aod,d,ipr);
1273  arrTracks.AddAt(tr,ipr);
1274  tr->GetImpactParameters(xy[ipr],z[ipr]);
1275  px[ipr]=tr->Px();
1276  py[ipr]=tr->Py();
1277  }
1278 
1279  if(!fCuts->PreSelect(arrTracks)){
1280  fNentries->Fill(23);
1281  continue;
1282  }
1283  if(!(vHF->FillRecoCand(aod,d))) {//Fill the data members of the candidate only if they are empty.
1284  fNentries->Fill(18); //monitor how often this fails
1285  continue;
1286  }
1287 
1288  if ( fCuts->IsInFiducialAcceptance(d->Pt(),d->Y(421)) ) {
1289  nSelectedloose++;
1290  nSelectedtight++;
1291  if(fSys==0){
1292  if(fCuts->IsSelected(d,AliRDHFCuts::kTracks,aod))fNentries->Fill(6);
1293  }
1294  Int_t ptbin=fCuts->PtBin(d->Pt());
1295  if(ptbin==-1) {fNentries->Fill(4); continue;} //out of bounds
1297  if(fFillVarHists) {
1298  //if(!fCutOnDistr || (fCutOnDistr && fIsSelectedCandidate)) {
1299  fDaughterTracks.AddAt((AliAODTrack*)d->GetDaughter(0),0);
1300  fDaughterTracks.AddAt((AliAODTrack*)d->GetDaughter(1),1);
1301  //check daughters
1302  if(!fDaughterTracks.UncheckedAt(0) || !fDaughterTracks.UncheckedAt(1)) {
1303  AliDebug(1,"at least one daughter not found!");
1304  fNentries->Fill(5);
1305  fDaughterTracks.Clear();
1306  continue;
1307  }
1308  //}
1309  FillVarHists(aod,d,mcArray,fCuts,fDistr);
1310  }
1311 
1312  if (fDrawDetSignal) {
1314  }
1315  FillMassHists(d,mcArray,mcHeader,fCuts,fOutputMass);
1316  if(fFillSparses) NormIPvar(aod, d,mcArray);
1317  if (fPIDCheck) {
1318  Int_t isSelectedPIDfill = 3;
1319  if (!fReadMC || (fReadMC && fUsePid4Distr)) isSelectedPIDfill = fCuts->IsSelectedPID(d); //0 rejected,1 D0,2 Dobar, 3 both
1320 
1321  if (isSelectedPIDfill == 0)fNentries->Fill(7);
1322  if (isSelectedPIDfill == 1)fNentries->Fill(8);
1323  if (isSelectedPIDfill == 2)fNentries->Fill(9);
1324  if (isSelectedPIDfill == 3)fNentries->Fill(10);
1325  }
1326 
1327  }
1328 
1329  fDaughterTracks.Clear();
1330  //if(unsetvtx) d->UnsetOwnPrimaryVtx();
1331  } //end for prongs
1332  fCounter->StoreCandidates(aod,nSelectedloose,kTRUE);
1333  fCounter->StoreCandidates(aod,nSelectedtight,kFALSE);
1334  delete vHF;
1335  // Post the data
1336  PostData(1,fOutputMass);
1337  PostData(2,fDistr);
1338  PostData(3,fNentries);
1339  PostData(5,fCounter);
1340  PostData(6,fOutputMassPt);
1341  PostData(7,fVariablesTree);
1342  PostData(8, fDetSignal);
1343 
1344  return;
1345 }
1346 
1347 //____________________________________________________________________________
1349 {
1350  //
1352  //
1353  fDaughterTracks.AddAt((AliAODTrack*)part->GetDaughter(0), 0);
1354  fDaughterTracks.AddAt((AliAODTrack*)part->GetDaughter(1), 1);
1355 
1356  AliESDtrack *esdtrack1 = new AliESDtrack((AliVTrack*)fDaughterTracks.UncheckedAt(0));
1357  AliESDtrack *esdtrack2 = new AliESDtrack((AliVTrack*)fDaughterTracks.UncheckedAt(1));
1358 
1359 
1360  //For filling detector histograms
1361  Int_t isSelectedPIDfill = 3;
1362  if (!fReadMC || (fReadMC && fUsePid4Distr)) isSelectedPIDfill = fCuts->IsSelectedPID(part); //0 rejected,1 D0,2 Dobar, 3 both
1363 
1364 
1365  //fill "before PID" histos with every daughter
1366  ((TH2F*)ListDetSignal->FindObject("TOFSigBefPID"))->Fill(esdtrack1->P(), esdtrack1->GetTOFsignal());
1367  ((TH2F*)ListDetSignal->FindObject("TOFSigBefPID"))->Fill(esdtrack2->P(), esdtrack2->GetTOFsignal());
1368  ((TH2F*)ListDetSignal->FindObject("TPCSigBefPID"))->Fill(esdtrack1->P(), esdtrack1->GetTPCsignal());
1369  ((TH2F*)ListDetSignal->FindObject("TPCSigBefPID"))->Fill(esdtrack2->P(), esdtrack2->GetTPCsignal());
1370 
1371  if (isSelectedPIDfill != 0) { //fill "After PID" with everything that's not rejected
1372  ((TH2F*)ListDetSignal->FindObject("TOFSigAftPID"))->Fill(esdtrack1->P(), esdtrack1->GetTOFsignal());
1373  ((TH2F*)ListDetSignal->FindObject("TOFSigAftPID"))->Fill(esdtrack2->P(), esdtrack2->GetTOFsignal());
1374  ((TH2F*)ListDetSignal->FindObject("TPCSigAftPID"))->Fill(esdtrack1->P(), esdtrack1->GetTPCsignal());
1375  ((TH2F*)ListDetSignal->FindObject("TPCSigAftPID"))->Fill(esdtrack2->P(), esdtrack2->GetTPCsignal());
1376 
1377  }
1378 
1379  delete esdtrack1;
1380  delete esdtrack2;
1381 
1382  return;
1383 }
1384 
1385 //____________________________________________________________________________
1387  //
1389  //
1390 
1391 
1392  Int_t pdgDgD0toKpi[2]={321,211};
1393  Int_t lab=-9999;
1394  if(fReadMC) lab=part->MatchToMC(421,arrMC,2,pdgDgD0toKpi); //return MC particle label if the array corresponds to a D0, -1 if not (cf. AliAODRecoDecay.cxx)
1395  //Double_t pt = d->Pt(); //mother pt
1396  Int_t isSelectedPID=3;
1397  if(!fReadMC || (fReadMC && fUsePid4Distr)) isSelectedPID=cuts->IsSelectedPID(part); //0 rejected,1 D0,2 Dobar, 3 both
1398  if (!fPIDCheck) { //if fPIDCheck, this is already filled elsewhere
1399  if (isSelectedPID==0)fNentries->Fill(7);
1400  if (isSelectedPID==1)fNentries->Fill(8);
1401  if (isSelectedPID==2)fNentries->Fill(9);
1402  if (isSelectedPID==3)fNentries->Fill(10);
1403  //fNentries->Fill(8+isSelectedPID);
1404  }
1405 
1406  if(fCutOnDistr && !fIsSelectedCandidate) return;
1407  //printf("\nif no cuts or cuts passed\n");
1408 
1409 
1410  //add distr here
1411  UInt_t pdgs[2];
1412 
1413  Double_t mPDG=TDatabasePDG::Instance()->GetParticle(421)->Mass();
1414  pdgs[0]=211;
1415  pdgs[1]=321;
1416  Double_t minvD0 = part->InvMassD0();
1417  pdgs[1]=211;
1418  pdgs[0]=321;
1419  Double_t minvD0bar = part->InvMassD0bar();
1420  //cout<<"inside mass cut"<<endl;
1421 
1422  Double_t invmasscut=0.03;
1423 
1424  TString fillthispi="",fillthisK="",fillthis="", fillthispt="", fillthisetaphi="";
1425 
1426  Int_t ptbin=cuts->PtBin(part->Pt());
1427  Double_t pt = part->Pt();
1428 
1429  Double_t dz1[2],dz2[2],covar1[3],covar2[3];//,d0xd0proper,errd0xd0proper;
1430  dz1[0]=-99; dz2[0]=-99;
1431  Double_t d0[2];
1432  Double_t decl[2]={-99,-99};
1433  Bool_t recalcvtx=kFALSE;
1434 
1435 
1436 
1438  recalcvtx=kTRUE;
1439  //recalculate vertex
1440  AliAODVertex *vtxProp=0x0;
1441  vtxProp=GetPrimaryVtxSkipped(aod);
1442  if(vtxProp) {
1443  part->SetOwnPrimaryVtx(vtxProp);
1444  //Bool_t unsetvtx=kTRUE;
1445  //Calculate d0 for daughter tracks with Vtx Skipped
1446  AliESDtrack *esdtrack1=new AliESDtrack((AliVTrack*)fDaughterTracks.UncheckedAt(0));
1447  AliESDtrack *esdtrack2=new AliESDtrack((AliVTrack*)fDaughterTracks.UncheckedAt(1));
1448  esdtrack1->PropagateToDCA(vtxProp,aod->GetMagneticField(),1.,dz1,covar1);
1449  esdtrack2->PropagateToDCA(vtxProp,aod->GetMagneticField(),1.,dz2,covar2);
1450  delete vtxProp; vtxProp=NULL;
1451  delete esdtrack1;
1452  delete esdtrack2;
1453  }
1454 
1455  d0[0]=dz1[0];
1456  d0[1]=dz2[0];
1457 
1458  decl[0]=part->DecayLength2();
1459  decl[1]=part->NormalizedDecayLength2();
1460  part->UnsetOwnPrimaryVtx();
1461 
1462  }
1463 
1464  Double_t cosThetaStarD0 = 99;
1465  Double_t cosThetaStarD0bar = 99;
1466  Double_t cosPointingAngle = 99;
1467  Double_t normalizedDecayLength2 = -1, normalizedDecayLengthxy=-1;
1468  Double_t decayLength2 = -1, decayLengthxy=-1;
1469  Double_t ptProng[2]={-99,-99};
1470  Double_t d0Prong[2]={-99,-99};
1471  Double_t etaD = 99.;
1472  Double_t phiD = 99.;
1473 
1474 
1475  //disable the PID
1476  if(!fUsePid4Distr) isSelectedPID=0;
1477  if((lab>=0 && fReadMC) || (!fReadMC && isSelectedPID)){ //signal (from MC or PID)
1478 
1479  //check pdg of the prongs
1480  AliAODTrack *prong0=(AliAODTrack*)fDaughterTracks.UncheckedAt(0);
1481  AliAODTrack *prong1=(AliAODTrack*)fDaughterTracks.UncheckedAt(1);
1482 
1483  if(!prong0 || !prong1) {
1484  return;
1485  }
1486  Int_t labprong[2];
1487  if(fReadMC){
1488  labprong[0]=prong0->GetLabel();
1489  labprong[1]=prong1->GetLabel();
1490  }
1491  AliAODMCParticle *mcprong=0;
1492  Int_t pdgProng[2]={0,0};
1493 
1494  for (Int_t iprong=0;iprong<2;iprong++){
1495  if(fReadMC && labprong[iprong]>=0) {
1496  mcprong= (AliAODMCParticle*)arrMC->At(labprong[iprong]);
1497  pdgProng[iprong]=mcprong->GetPdgCode();
1498  }
1499  }
1500 
1501  if(fSys==0){
1502  //no mass cut ditributions: ptbis
1503 
1504  fillthispi="hptpiSnoMcut_";
1505  fillthispi+=ptbin;
1506 
1507  fillthisK="hptKSnoMcut_";
1508  fillthisK+=ptbin;
1509 
1510  if ((TMath::Abs(pdgProng[0]) == 211 && TMath::Abs(pdgProng[1]) == 321)
1511  || (isSelectedPID==1 || isSelectedPID==3)){
1512  ((TH1F*)listout->FindObject(fillthispi))->Fill(prong0->Pt());
1513  ((TH1F*)listout->FindObject(fillthisK))->Fill(prong1->Pt());
1514  }
1515 
1516  if ((TMath::Abs(pdgProng[0]) == 321 && TMath::Abs(pdgProng[1]) == 211)
1517  || (isSelectedPID==2 || isSelectedPID==3)){
1518  ((TH1F*)listout->FindObject(fillthisK))->Fill(prong0->Pt());
1519  ((TH1F*)listout->FindObject(fillthispi))->Fill(prong1->Pt());
1520  }
1521  }
1522 
1523  //no mass cut ditributions: mass
1524 
1525  etaD = part->Eta();
1526  phiD = part->Phi();
1527 
1528 
1529  fillthis="hMassS_";
1530  fillthis+=ptbin;
1531  fillthispt="histSgnPt";
1532 
1533  if ((fReadMC && ((AliAODMCParticle*)arrMC->At(lab))->GetPdgCode() == 421)
1534  || (!fReadMC && (isSelectedPID==1 || isSelectedPID==3))){//D0
1535  ((TH1F*)listout->FindObject(fillthis))->Fill(minvD0);
1536  if(fFillPtHist && fReadMC) ((TH2F*)fOutputMassPt->FindObject(fillthispt))->Fill(minvD0,pt);
1537 
1538  fillthisetaphi="hetaphiD0candidateS_";
1539  fillthisetaphi+=ptbin;
1540  ((TH2F*)listout->FindObject(fillthisetaphi))->Fill(etaD, phiD);
1541 
1542  if(TMath::Abs(minvD0-mPDG)<0.05){
1543  fillthisetaphi="hetaphiD0candidatesignalregionS_";
1544  fillthisetaphi+=ptbin;
1545  ((TH2F*)listout->FindObject(fillthisetaphi))->Fill(etaD, phiD);
1546  }
1547 
1548  }
1549  else { //D0bar
1550  if(fReadMC || (!fReadMC && isSelectedPID > 1)){
1551  ((TH1F*)listout->FindObject(fillthis))->Fill(minvD0bar);
1552  if(fFillPtHist && fReadMC) ((TH2F*)fOutputMassPt->FindObject(fillthispt))->Fill(minvD0bar,pt);
1553 
1554  fillthisetaphi="hetaphiD0barcandidateS_";
1555  fillthisetaphi+=ptbin;
1556  ((TH2F*)listout->FindObject(fillthisetaphi))->Fill(etaD, phiD);
1557 
1558  if(TMath::Abs(minvD0bar-mPDG)<0.05){
1559  fillthisetaphi="hetaphiD0barcandidatesignalregionS_";
1560  fillthisetaphi+=ptbin;
1561  ((TH2F*)listout->FindObject(fillthisetaphi))->Fill(etaD, phiD);
1562  }
1563 
1564  }
1565  }
1566 
1567  //apply cut on invariant mass on the pair
1568  if(TMath::Abs(minvD0-mPDG)<invmasscut || TMath::Abs(minvD0bar-mPDG)<invmasscut){
1569 
1570  cosThetaStarD0 = part->CosThetaStarD0();
1571  cosThetaStarD0bar = part->CosThetaStarD0bar();
1572  cosPointingAngle = part->CosPointingAngle();
1573  normalizedDecayLength2 = part->NormalizedDecayLength2();
1574  decayLength2 = part->DecayLength2();
1575  decayLengthxy = part->DecayLengthXY();
1576  normalizedDecayLengthxy=decayLengthxy/part->DecayLengthXYError();
1577 
1578  ptProng[0]=prong0->Pt(); ptProng[1]=prong1->Pt();
1579  d0Prong[0]=part->Getd0Prong(0); d0Prong[1]=part->Getd0Prong(1);
1580 
1581  if(fArray==1) cout<<"LS signal: ERROR"<<endl;
1582  for (Int_t iprong=0; iprong<2; iprong++){
1583  AliAODTrack *prong=(AliAODTrack*)fDaughterTracks.UncheckedAt(iprong);
1584  if (fReadMC) labprong[iprong]=prong->GetLabel();
1585 
1586  //cout<<"prong name = "<<prong->GetName()<<" label = "<<prong->GetLabel()<<endl;
1587  Int_t pdgprong=0;
1588  if(fReadMC && labprong[iprong]>=0) {
1589  mcprong= (AliAODMCParticle*)arrMC->At(labprong[iprong]);
1590  pdgprong=mcprong->GetPdgCode();
1591  }
1592 
1593  Bool_t isPionHere[2]={(isSelectedPID==1 || isSelectedPID==3) ? kTRUE : kFALSE,(isSelectedPID==2 || isSelectedPID==3) ? kTRUE : kFALSE};
1594 
1595  if(TMath::Abs(pdgprong)==211 || isPionHere[iprong]) {
1596  //cout<<"pi"<<endl;
1597 
1598  if(fSys==0){
1599  fillthispi="hptpiS_";
1600  fillthispi+=ptbin;
1601  ((TH1F*)listout->FindObject(fillthispi))->Fill(ptProng[iprong]);
1602  }
1603 
1604  fillthispi="hd0piS_";
1605  fillthispi+=ptbin;
1606  ((TH1F*)listout->FindObject(fillthispi))->Fill(d0Prong[iprong]);
1607  if(recalcvtx) {
1608 
1609  fillthispi="hd0vpiS_";
1610  fillthispi+=ptbin;
1611  ((TH1F*)listout->FindObject(fillthispi))->Fill(d0[iprong]);
1612  }
1613 
1614  }
1615 
1616  if(TMath::Abs(pdgprong)==321 || !isPionHere[iprong]) {
1617  //cout<<"kappa"<<endl;
1618  if(fSys==0){
1619  fillthisK="hptKS_";
1620  fillthisK+=ptbin;
1621  ((TH1F*)listout->FindObject(fillthisK))->Fill(ptProng[iprong]);
1622  }
1623 
1624 
1625  fillthisK="hd0KS_";
1626  fillthisK+=ptbin;
1627  ((TH1F*)listout->FindObject(fillthisK))->Fill(d0Prong[iprong]);
1628  if (recalcvtx){
1629  fillthisK="hd0vKS_";
1630  fillthisK+=ptbin;
1631  ((TH1F*)listout->FindObject(fillthisK))->Fill(d0[iprong]);
1632  }
1633  }
1634 
1635  if(fSys==0){
1636  fillthis="hcosthpointd0S_";
1637  fillthis+=ptbin;
1638  ((TH1F*)listout->FindObject(fillthis))->Fill(cosPointingAngle,d0Prong[iprong]);
1639  }
1640  } //end loop on prongs
1641 
1642  fillthis="hdcaS_";
1643  fillthis+=ptbin;
1644  ((TH1F*)listout->FindObject(fillthis))->Fill(part->GetDCA());
1645 
1646  fillthis="hcosthetapointS_";
1647  fillthis+=ptbin;
1648  ((TH1F*)listout->FindObject(fillthis))->Fill(cosPointingAngle);
1649 
1650  fillthis="hcosthetapointxyS_";
1651  fillthis+=ptbin;
1652  ((TH1F*)listout->FindObject(fillthis))->Fill(part->CosPointingAngleXY());
1653 
1654 
1655  fillthis="hd0d0S_";
1656  fillthis+=ptbin;
1657  ((TH1F*)listout->FindObject(fillthis))->Fill(part->Prodd0d0());
1658 
1659  fillthis="hdeclS_";
1660  fillthis+=ptbin;
1661  ((TH1F*)listout->FindObject(fillthis))->Fill(decayLength2);
1662 
1663  fillthis="hnormdeclS_";
1664  fillthis+=ptbin;
1665  ((TH1F*)listout->FindObject(fillthis))->Fill(normalizedDecayLength2);
1666 
1667  fillthis="hdeclxyS_";
1668  fillthis+=ptbin;
1669  ((TH1F*)listout->FindObject(fillthis))->Fill(decayLengthxy);
1670 
1671  fillthis="hnormdeclxyS_";
1672  fillthis+=ptbin;
1673  ((TH1F*)listout->FindObject(fillthis))->Fill(normalizedDecayLengthxy);
1674 
1675  fillthis="hdeclxyd0d0S_";
1676  fillthis+=ptbin;
1677  ((TH2F*)listout->FindObject(fillthis))->Fill(decayLengthxy,d0Prong[0]*d0Prong[1]);
1678 
1679  fillthis="hnormdeclxyd0d0S_";
1680  fillthis+=ptbin;
1681  ((TH2F*)listout->FindObject(fillthis))->Fill(normalizedDecayLengthxy,d0Prong[0]*d0Prong[1]);
1682 
1683  if(recalcvtx) {
1684  fillthis="hdeclvS_";
1685  fillthis+=ptbin;
1686  ((TH1F*)listout->FindObject(fillthis))->Fill(decl[0]);
1687 
1688  fillthis="hnormdeclvS_";
1689  fillthis+=ptbin;
1690  ((TH1F*)listout->FindObject(fillthis))->Fill(decl[1]);
1691 
1692  fillthis="hd0d0vS_";
1693  fillthis+=ptbin;
1694  ((TH1F*)listout->FindObject(fillthis))->Fill(d0[0]*d0[1]);
1695  }
1696 
1697  if(fSys==0){
1698  fillthis="hcosthetastarS_";
1699  fillthis+=ptbin;
1700  if ((fReadMC && ((AliAODMCParticle*)arrMC->At(lab))->GetPdgCode() == 421)) ((TH1F*)listout->FindObject(fillthis))->Fill(cosThetaStarD0);
1701  else {
1702  if (fReadMC || isSelectedPID>1)((TH1F*)listout->FindObject(fillthis))->Fill(cosThetaStarD0bar);
1703  if(isSelectedPID==1 || isSelectedPID==3)((TH1F*)listout->FindObject(fillthis))->Fill(cosThetaStarD0);
1704  }
1705 
1706  fillthis="hcosthpointd0d0S_";
1707  fillthis+=ptbin;
1708  ((TH2F*)listout->FindObject(fillthis))->Fill(cosPointingAngle,part->Prodd0d0());
1709  }
1710 
1711  if ((fReadMC && ((AliAODMCParticle*)arrMC->At(lab))->GetPdgCode() == 421)){
1712  for(Int_t it=0; it<2; it++){
1713  fillthis="hptD0S_";
1714  fillthis+=ptbin;
1715  ((TH1F*)listout->FindObject(fillthis))->Fill(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->Pt());
1716  fillthis="hphiD0S_";
1717  fillthis+=ptbin;
1718  ((TH1F*)listout->FindObject(fillthis))->Fill(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->Phi());
1719  Int_t nPointsITS = 0;
1720  for (Int_t il=0; il<6; il++){
1721  if(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(il)) nPointsITS++;
1722  }
1723  fillthis="hNITSpointsD0vsptS_";
1724  fillthis+=ptbin;
1725  ((TH2F*)listout->FindObject(fillthis))->Fill(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->Pt(),nPointsITS);
1726  fillthis="hNSPDpointsD0S_";
1727  fillthis+=ptbin;
1728  if(!(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(0)) && !(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(1))){ //no SPD points
1729  ((TH1I*)listout->FindObject(fillthis))->Fill(0);
1730  }
1731  if(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(0) && !(((AliAODTrack*)(fDaughterTracks.UncheckedAt(it)))->HasPointOnITSLayer(1))){ //kOnlyFirst
1732  ((TH1I*)listout->FindObject(fillthis))->Fill(1);
1733  }
1734  if(!(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(0)) && ((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(1)){ //kOnlySecond
1735  ((TH1I*)listout->FindObject(fillthis))->Fill(2);
1736  }
1737  if(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(0) && ((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(1)){ //kboth
1738  ((TH1I*)listout->FindObject(fillthis))->Fill(3);
1739  }
1740  fillthis="hNclsD0vsptS_";
1741  fillthis+=ptbin;
1742  Float_t mom = ((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->Pt();
1743  Float_t ncls = (Float_t)((AliAODTrack*)fDaughterTracks.UncheckedAt(0))->GetTPCNcls();
1744  ((TH2F*)listout->FindObject(fillthis))->Fill(mom, ncls);
1745  }
1746  }
1747  else {
1748  if (fReadMC || isSelectedPID>1){
1749  for(Int_t it=0; it<2; it++){
1750  fillthis="hptD0barS_";
1751  fillthis+=ptbin;
1752  ((TH1F*)listout->FindObject(fillthis))->Fill(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->Pt());
1753  fillthis="hphiD0barS_";
1754  fillthis+=ptbin;
1755  ((TH1F*)listout->FindObject(fillthis))->Fill(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->Phi());
1756  fillthis="hNclsD0barvsptS_";
1757  fillthis+=ptbin;
1758  Float_t mom = ((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->Pt();
1759  Float_t ncls = (Float_t)((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->GetTPCNcls();
1760  ((TH2F*)listout->FindObject(fillthis))->Fill(mom, ncls);
1761  }
1762  }
1763  if(isSelectedPID==1 || isSelectedPID==3){
1764  for(Int_t it=0; it<2; it++){
1765  fillthis="hptD0S_";
1766  fillthis+=ptbin;
1767  ((TH1F*)listout->FindObject(fillthis))->Fill(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->Pt());
1768  fillthis="hphiD0S_";
1769  fillthis+=ptbin;
1770  ((TH1F*)listout->FindObject(fillthis))->Fill(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->Phi());
1771  Int_t nPointsITS = 0;
1772  for (Int_t il=0; il<6; il++){
1773  if(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(il)) nPointsITS++;
1774  }
1775  fillthis="hNITSpointsD0vsptS_";
1776  fillthis+=ptbin;
1777  ((TH2F*)listout->FindObject(fillthis))->Fill(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->Pt(), nPointsITS);
1778  fillthis="hNSPDpointsD0S_";
1779  fillthis+=ptbin;
1780  if(!(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(0)) && !(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(1))){ //no SPD points
1781  ((TH1I*)listout->FindObject(fillthis))->Fill(0);
1782  }
1783  if(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(0) && !(((AliAODTrack*)(fDaughterTracks.UncheckedAt(it)))->HasPointOnITSLayer(1))){ //kOnlyFirst
1784  ((TH1I*)listout->FindObject(fillthis))->Fill(1);
1785  }
1786  if(!(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(0)) && ((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(1)){ //kOnlySecond
1787  ((TH1I*)listout->FindObject(fillthis))->Fill(2);
1788  }
1789  if(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(0) && ((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(1)){ //kboth
1790  ((TH1I*)listout->FindObject(fillthis))->Fill(3);
1791  }
1792  fillthis="hNclsD0vsptS_";
1793  fillthis+=ptbin;
1794  Float_t mom = ((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->Pt();
1795  Float_t ncls = (Float_t)((AliAODTrack*)fDaughterTracks.UncheckedAt(0))->GetTPCNcls();
1796  ((TH2F*)listout->FindObject(fillthis))->Fill(mom, ncls);
1797  }
1798  }
1799  }
1800 
1801 
1802  } //end mass cut
1803 
1804  } else{ //Background or LS
1805  //if(!fReadMC){
1806  //cout<<"is background"<<endl;
1807 
1808  etaD = part->Eta();
1809  phiD = part->Phi();
1810 
1811  //no mass cut distributions: mass, ptbis
1812  fillthis="hMassB_";
1813  fillthis+=ptbin;
1814  fillthispt="histBkgPt";
1815 
1817  ((TH1F*)listout->FindObject(fillthis))->Fill(minvD0);
1818  if(fFillPtHist && fReadMC) ((TH2F*)fOutputMassPt->FindObject(fillthispt))->Fill(minvD0,pt);
1819 
1820  fillthisetaphi="hetaphiD0candidateB_";
1821  fillthisetaphi+=ptbin;
1822  ((TH2F*)listout->FindObject(fillthisetaphi))->Fill(etaD, phiD);
1823 
1824  if(TMath::Abs(minvD0-mPDG)<0.05){
1825  fillthisetaphi="hetaphiD0candidatesignalregionB_";
1826  fillthisetaphi+=ptbin;
1827  ((TH2F*)listout->FindObject(fillthisetaphi))->Fill(etaD, phiD);
1828  }
1829  }
1830  if (!fCutOnDistr || (fCutOnDistr && fIsSelectedCandidate>1)) {
1831  ((TH1F*)listout->FindObject(fillthis))->Fill(minvD0bar);
1832  if(fFillPtHist && fReadMC) ((TH2F*)fOutputMassPt->FindObject(fillthispt))->Fill(minvD0bar,pt);
1833 
1834  fillthisetaphi="hetaphiD0barcandidateB_";
1835  fillthisetaphi+=ptbin;
1836  ((TH2F*)listout->FindObject(fillthisetaphi))->Fill(etaD, phiD);
1837 
1838  if(TMath::Abs(minvD0bar-mPDG)<0.05){
1839  fillthisetaphi="hetaphiD0barcandidatesignalregionB_";
1840  fillthisetaphi+=ptbin;
1841  ((TH2F*)listout->FindObject(fillthisetaphi))->Fill(etaD, phiD);
1842  }
1843 
1844  }
1845  if(fSys==0){
1846  fillthis="hptB1prongnoMcut_";
1847  fillthis+=ptbin;
1848 
1849  ((TH1F*)listout->FindObject(fillthis))->Fill(((AliAODTrack*)fDaughterTracks.UncheckedAt(0))->Pt());
1850 
1851  fillthis="hptB2prongsnoMcut_";
1852  fillthis+=ptbin;
1853  ((TH1F*)listout->FindObject(fillthis))->Fill(((AliAODTrack*)fDaughterTracks.UncheckedAt(0))->Pt());
1854  ((TH1F*)listout->FindObject(fillthis))->Fill(((AliAODTrack*)fDaughterTracks.UncheckedAt(0))->Pt());
1855  }
1856 
1857 
1858  //apply cut on invariant mass on the pair
1859  if(TMath::Abs(minvD0-mPDG)<invmasscut || TMath::Abs(minvD0bar-mPDG)<invmasscut){
1860  if(fSys==0){
1861  ptProng[0]=((AliAODTrack*)fDaughterTracks.UncheckedAt(0))->Pt(); ptProng[1]=((AliAODTrack*)fDaughterTracks.UncheckedAt(0))->Pt();
1862  cosThetaStarD0 = part->CosThetaStarD0();
1863  cosThetaStarD0bar = part->CosThetaStarD0bar();
1864  }
1865 
1866  cosPointingAngle = part->CosPointingAngle();
1867  normalizedDecayLength2 = part->NormalizedDecayLength2();
1868  decayLength2 = part->DecayLength2();
1869  decayLengthxy = part->DecayLengthXY();
1870  normalizedDecayLengthxy=decayLengthxy/part->DecayLengthXYError();
1871  d0Prong[0]=part->Getd0Prong(0); d0Prong[1]=part->Getd0Prong(1);
1872 
1873 
1874  AliAODTrack *prongg=(AliAODTrack*)fDaughterTracks.UncheckedAt(0);
1875  if(!prongg) {
1876  if(fDebug>2) cout<<"No daughter found";
1877  return;
1878  }
1879  else{
1880  if(fArray==1){
1881  if(prongg->Charge()==1) {
1882  //fTotPosPairs[ptbin]++;
1883  ((TH1F*)fOutputMass->FindObject("hpospair"))->Fill(ptbin);
1884  } else {
1885  //fTotNegPairs[ptbin]++;
1886  ((TH1F*)fOutputMass->FindObject("hnegpair"))->Fill(ptbin);
1887  }
1888  }
1889  }
1890 
1891  //fill pt and phi distrib for prongs with M cut
1892 
1894  for(Int_t it=0; it<2; it++){
1895  fillthis="hptD0B_";
1896  fillthis+=ptbin;
1897  ((TH1F*)listout->FindObject(fillthis))->Fill(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->Pt());
1898  fillthis="hphiD0B_";
1899  fillthis+=ptbin;
1900  ((TH1F*)listout->FindObject(fillthis))->Fill(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->Phi());
1901 
1902  Int_t nPointsITS = 0;
1903  for (Int_t il=0; il<6; il++){
1904  if(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(il)) nPointsITS++;
1905  }
1906  fillthis="hNITSpointsD0vsptB_";
1907  fillthis+=ptbin;
1908  ((TH2F*)listout->FindObject(fillthis))->Fill(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->Pt(), nPointsITS);
1909  fillthis="hNSPDpointsD0B_";
1910  fillthis+=ptbin;
1911  if(!(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(0)) && !(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(1))){ //no SPD points
1912  ((TH1I*)listout->FindObject(fillthis))->Fill(0);
1913  }
1914  if(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(0) && !(((AliAODTrack*)(fDaughterTracks.UncheckedAt(it)))->HasPointOnITSLayer(1))){ //kOnlyFirst
1915  ((TH1I*)listout->FindObject(fillthis))->Fill(1);
1916  }
1917  if(!(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(0)) && ((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(1)){ //kOnlySecond
1918  ((TH1I*)listout->FindObject(fillthis))->Fill(2);
1919  }
1920  if(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(0) && ((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->HasPointOnITSLayer(1)){ //kboth
1921  ((TH1I*)listout->FindObject(fillthis))->Fill(3);
1922  }
1923  fillthis="hNclsD0vsptB_";
1924  fillthis+=ptbin;
1925  Float_t mom = ((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->Pt();
1926  Float_t ncls = (Float_t)((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->GetTPCNcls();
1927  ((TH2F*)listout->FindObject(fillthis))->Fill(mom, ncls);
1928  }
1929 
1930 
1931  }
1932 
1933  if (!fCutOnDistr || (fCutOnDistr && fIsSelectedCandidate>1)) {
1934  for(Int_t it=0; it<2; it++){
1935  fillthis="hptD0barB_";
1936  fillthis+=ptbin;
1937  ((TH1F*)listout->FindObject(fillthis))->Fill(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->Pt());
1938  fillthis="hphiD0barB_";
1939  fillthis+=ptbin;
1940  ((TH1F*)listout->FindObject(fillthis))->Fill(((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->Phi());
1941  fillthis="hNclsD0barvsptB_";
1942  fillthis+=ptbin;
1943  Float_t mom = ((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->Pt();
1944  Float_t ncls = (Float_t)((AliAODTrack*)fDaughterTracks.UncheckedAt(it))->GetTPCNcls();
1945  ((TH2F*)listout->FindObject(fillthis))->Fill(mom, ncls);
1946  }
1947  }
1948 
1949  fillthis="hd0B_";
1950  fillthis+=ptbin;
1951  ((TH1F*)listout->FindObject(fillthis))->Fill(d0Prong[0]);
1952  ((TH1F*)listout->FindObject(fillthis))->Fill(d0Prong[1]);
1953 
1954  if(fReadMC){
1955  Int_t pdgMother[2]={0,0};
1956  Double_t factor[2]={1,1};
1957 
1958  for(Int_t iprong=0;iprong<2;iprong++){
1959  AliAODTrack *prong=(AliAODTrack*)fDaughterTracks.UncheckedAt(iprong);
1960  lab=prong->GetLabel();
1961  if(lab>=0){
1962  AliAODMCParticle* mcprong=(AliAODMCParticle*)arrMC->At(lab);
1963  if(mcprong){
1964  Int_t labmom=mcprong->GetMother();
1965  if(labmom>=0){
1966  AliAODMCParticle* mcmother=(AliAODMCParticle*)arrMC->At(labmom);
1967  if(mcmother) pdgMother[iprong]=mcmother->GetPdgCode();
1968  }
1969  }
1970  }
1971 
1972  if(fSys==0){
1973 
1974  fillthis="hd0moresB_";
1975  fillthis+=ptbin;
1976 
1977  if(TMath::Abs(pdgMother[iprong])==310 || TMath::Abs(pdgMother[iprong])==130 || TMath::Abs(pdgMother[iprong])==321){ //K^0_S, K^0_L, K^+-
1978  if(ptProng[iprong]<=1)factor[iprong]=1./.7;
1979  else factor[iprong]=1./.6;
1980  fNentries->Fill(11);
1981  }
1982 
1983  if(TMath::Abs(pdgMother[iprong])==3122) { //Lambda
1984  factor[iprong]=1./0.25;
1985  fNentries->Fill(12);
1986  }
1987  fillthis="hd0moresB_";
1988  fillthis+=ptbin;
1989 
1990  ((TH1F*)listout->FindObject(fillthis))->Fill(d0Prong[iprong],factor[iprong]);
1991 
1992  if(recalcvtx){
1993  fillthis="hd0vmoresB_";
1994  fillthis+=ptbin;
1995  ((TH1F*)listout->FindObject(fillthis))->Fill(d0[iprong],factor[iprong]);
1996  }
1997  }
1998  } //loop on prongs
1999 
2000  if(fSys==0){
2001  fillthis="hd0d0moresB_";
2002  fillthis+=ptbin;
2003  ((TH1F*)listout->FindObject(fillthis))->Fill(part->Prodd0d0(),factor[0]*factor[1]);
2004 
2005  fillthis="hcosthetapointmoresB_";
2006  fillthis+=ptbin;
2007  ((TH1F*)listout->FindObject(fillthis))->Fill(cosPointingAngle,factor[0]*factor[1]);
2008 
2009  if(recalcvtx){
2010  fillthis="hd0d0vmoresB_";
2011  fillthis+=ptbin;
2012  ((TH1F*)listout->FindObject(fillthis))->Fill(d0[0]*d0[1],factor[0]*factor[1]);
2013  }
2014  }
2015  } //readMC
2016 
2017  if(fSys==0){
2018  //normalise pt distr to half afterwards
2019  fillthis="hptB_";
2020  fillthis+=ptbin;
2021  ((TH1F*)listout->FindObject(fillthis))->Fill(ptProng[0]);
2022  ((TH1F*)listout->FindObject(fillthis))->Fill(ptProng[1]);
2023 
2024  fillthis="hcosthetastarB_";
2025  fillthis+=ptbin;
2026  if (!fCutOnDistr || (fCutOnDistr && (fIsSelectedCandidate==1 || fIsSelectedCandidate==3)))((TH1F*)listout->FindObject(fillthis))->Fill(cosThetaStarD0);
2027  if (!fCutOnDistr || (fCutOnDistr && fIsSelectedCandidate>1))((TH1F*)listout->FindObject(fillthis))->Fill(cosThetaStarD0bar);
2028 
2029 
2030  fillthis="hd0p0B_";
2031  fillthis+=ptbin;
2032  ((TH1F*)listout->FindObject(fillthis))->Fill(d0Prong[0]);
2033  fillthis="hd0p1B_";
2034  fillthis+=ptbin;
2035  ((TH1F*)listout->FindObject(fillthis))->Fill(d0Prong[1]);
2036 
2037  fillthis="hcosthpointd0d0B_";
2038  fillthis+=ptbin;
2039  ((TH2F*)listout->FindObject(fillthis))->Fill(cosPointingAngle,part->Prodd0d0());
2040 
2041  fillthis="hcosthpointd0B_";
2042  fillthis+=ptbin;
2043  ((TH1F*)listout->FindObject(fillthis))->Fill(cosPointingAngle,d0Prong[0]);
2044  ((TH1F*)listout->FindObject(fillthis))->Fill(cosPointingAngle,d0Prong[1]);
2045 
2046 
2047  if(recalcvtx){
2048 
2049  fillthis="hd0vp0B_";
2050  fillthis+=ptbin;
2051  ((TH1F*)listout->FindObject(fillthis))->Fill(d0[0]);
2052  fillthis="hd0vp1B_";
2053  fillthis+=ptbin;
2054  ((TH1F*)listout->FindObject(fillthis))->Fill(d0[1]);
2055 
2056  fillthis="hd0vB_";
2057  fillthis+=ptbin;
2058  ((TH1F*)listout->FindObject(fillthis))->Fill(d0[0]);
2059  ((TH1F*)listout->FindObject(fillthis))->Fill(d0[1]);
2060 
2061  }
2062 
2063  }
2064 
2065  fillthis="hdcaB_";
2066  fillthis+=ptbin;
2067  ((TH1F*)listout->FindObject(fillthis))->Fill(part->GetDCA());
2068 
2069  fillthis="hd0d0B_";
2070  fillthis+=ptbin;
2071  ((TH1F*)listout->FindObject(fillthis))->Fill(d0Prong[0]*d0Prong[1]);
2072 
2073  if(recalcvtx){
2074  fillthis="hd0d0vB_";
2075  fillthis+=ptbin;
2076  ((TH1F*)listout->FindObject(fillthis))->Fill(d0[0]*d0[1]);
2077  }
2078 
2079  fillthis="hcosthetapointB_";
2080  fillthis+=ptbin;
2081  ((TH1F*)listout->FindObject(fillthis))->Fill(cosPointingAngle);
2082 
2083  fillthis="hcosthetapointxyB_";
2084  fillthis+=ptbin;
2085  ((TH1F*)listout->FindObject(fillthis))->Fill(part->CosPointingAngleXY());
2086 
2087  fillthis="hdeclB_";
2088  fillthis+=ptbin;
2089  ((TH1F*)listout->FindObject(fillthis))->Fill(decayLength2);
2090 
2091  fillthis="hnormdeclB_";
2092  fillthis+=ptbin;
2093  ((TH1F*)listout->FindObject(fillthis))->Fill(normalizedDecayLength2);
2094 
2095  fillthis="hdeclxyB_";
2096  fillthis+=ptbin;
2097  ((TH1F*)listout->FindObject(fillthis))->Fill(decayLengthxy);
2098 
2099  fillthis="hnormdeclxyB_";
2100  fillthis+=ptbin;
2101  ((TH1F*)listout->FindObject(fillthis))->Fill(normalizedDecayLengthxy);
2102 
2103  fillthis="hdeclxyd0d0B_";
2104  fillthis+=ptbin;
2105  ((TH2F*)listout->FindObject(fillthis))->Fill(decayLengthxy,d0Prong[0]*d0Prong[1]);
2106 
2107  fillthis="hnormdeclxyd0d0B_";
2108  fillthis+=ptbin;
2109  ((TH2F*)listout->FindObject(fillthis))->Fill(normalizedDecayLengthxy,d0Prong[0]*d0Prong[1]);
2110 
2111 
2112  if(recalcvtx) {
2113 
2114  fillthis="hdeclvB_";
2115  fillthis+=ptbin;
2116  ((TH1F*)listout->FindObject(fillthis))->Fill(decl[0]);
2117 
2118  fillthis="hnormdeclvB_";
2119  fillthis+=ptbin;
2120  ((TH1F*)listout->FindObject(fillthis))->Fill(decl[1]);
2121 
2122 
2123  }
2124  }//mass cut
2125  }//else (background)
2126 
2127  return;
2128 }
2129 
2130 //____________________________________________________________________________
2131 void AliAnalysisTaskSED0Mass::FillMassHists(AliAODRecoDecayHF2Prong *part, TClonesArray *arrMC, AliAODMCHeader *mcHeader, AliRDHFCutsD0toKpi* cuts, TList *listout){
2132  //
2134  //
2135 
2136 
2137  Double_t mPDG=TDatabasePDG::Instance()->GetParticle(421)->Mass();
2138 
2139  //cout<<"is selected = "<<fIsSelectedCandidate<<endl;
2140 
2141  // Fill candidate variable Tree (track selection, no candidate selection)
2142  if( fWriteVariableTree && !part->HasBadDaughters()
2143  && fCuts->AreDaughtersSelected(part) && fCuts->IsSelectedPID(part) ){
2144  fCandidateVariables[0] = part->InvMassD0();
2145  fCandidateVariables[1] = part->InvMassD0bar();
2146  fCandidateVariables[2] = part->Pt();
2147  fCandidateVariables[3] = part->GetDCA();
2148  Double_t ctsD0=0. ,ctsD0bar=0.; part->CosThetaStarD0(ctsD0,ctsD0bar);
2149  fCandidateVariables[4] = ctsD0;
2150  fCandidateVariables[5] = ctsD0bar;
2151  fCandidateVariables[6] = part->Pt2Prong(0);
2152  fCandidateVariables[7] = part->Pt2Prong(1);
2153  fCandidateVariables[8] = part->Getd0Prong(0);
2154  fCandidateVariables[9] = part->Getd0Prong(1);
2155  fCandidateVariables[10] = part->Prodd0d0();
2156  fCandidateVariables[11] = part->CosPointingAngle();
2160  fVariablesTree->Fill();
2161  }
2162 
2163  //cout<<"check cuts = "<<endl;
2164  //cuts->PrintAll();
2165  if (!fIsSelectedCandidate){
2166  //cout<<" cut " << cuts << " Rejected because "<<cuts->GetWhy()<<endl;
2167  return;
2168  }
2169 
2170 
2171  if(fDebug>2) cout<<"Candidate selected"<<endl;
2172 
2173  Double_t invmassD0 = part->InvMassD0(), invmassD0bar = part->InvMassD0bar();
2174  //printf("SELECTED\n");
2175  Int_t ptbin=cuts->PtBin(part->Pt());
2176  Double_t pt = part->Pt();
2177  Double_t y = part->YD0();
2178 
2179  Double_t impparXY=part->ImpParXY()*10000.;
2180  Double_t trueImpParXY=0.;
2181  Double_t arrayForSparse[3]={invmassD0,pt,impparXY};
2182  Double_t arrayForSparseTrue[3]={invmassD0,pt,trueImpParXY};
2183 
2184 
2185  // AliAODTrack *prong=(AliAODTrack*)fDaughterTracks.UncheckedAt(0);
2186  // if(!prong) {
2187  // AliDebug(2,"No daughter found");
2188  // return;
2189  // }
2190  // else{
2191  // if(prong->Charge()==1) {
2192  // ((TH1F*)fDistr->FindObject("hpospair"))->Fill(fCuts->GetNPtBins()+ptbin);
2193  // //fTotPosPairs[ptbin]++;
2194  // } else {
2195  // ((TH1F*)fDistr->FindObject("hnegpair"))->Fill(fCuts->GetNPtBins()+ptbin);
2196  // //fTotNegPairs[ptbin]++;
2197  // }
2198  // }
2199 
2200  // for(Int_t it=0;it<2;it++){
2201 
2202  // //request on spd points to be addes
2203  // if(/*nSPD==2 && */part->Pt() > 5. && (TMath::Abs(invmassD0-mPDG)<0.01 || TMath::Abs(invmassD0bar-mPDG)<0.01)){
2204  // FILE *f=fopen("4display.txt","a");
2205  // fprintf(f,"pt: %f \n Rapidity: %f \t Period Number: %x \t Run Number: %d \t BunchCrossNumb: %d \t OrbitNumber: %d\n",part->Pt(),part->Y(421),aod->GetPeriodNumber(),aod->GetRunNumber(),aod->GetBunchCrossNumber(),aod->GetOrbitNumber());
2206  // fclose(f);
2207  // //printf("PrimVtx NContributors: %d \n Prongs Rel Angle: %f \n \n",ncont,relangle);
2208  // }
2209  // }
2210 
2211  TString fillthis="", fillthispt="", fillthismasspt="", fillthismassy="", fillthissub="";
2212  Int_t pdgDgD0toKpi[2]={321,211};
2213  Int_t labD0=-1;
2214  Bool_t isPrimary=kTRUE;
2215  if (fReadMC) labD0 = part->MatchToMC(421,arrMC,2,pdgDgD0toKpi); //return MC particle label if the array corresponds to a D0, -1 if not (cf. AliAODRecoDecay.cxx)
2216 
2217  //Define weights for Bayesian (if appropriate)
2218 
2219  Double_t weigD0=1.;
2220  Double_t weigD0bar=1.;
2222  weigD0=fCuts->GetWeightsNegative()[AliPID::kKaon] * fCuts->GetWeightsPositive()[AliPID::kPion];
2223  weigD0bar=fCuts->GetWeightsPositive()[AliPID::kKaon] * fCuts->GetWeightsNegative()[AliPID::kPion];
2224  if (weigD0 > 1.0 || weigD0 < 0.) {weigD0 = 0.;}
2225  if (weigD0bar > 1.0 || weigD0bar < 0.) {weigD0bar = 0.;} //Prevents filling with weight > 1, or < 0
2226  }
2227 
2228  //count candidates selected by cuts
2229  fNentries->Fill(1);
2230  //count true D0 selected by cuts
2231  if (fReadMC && labD0>=0) fNentries->Fill(2);
2232 
2233  if ((fIsSelectedCandidate==1 || fIsSelectedCandidate==3) && fFillOnlyD0D0bar<2) { //D0
2234 
2235  arrayForSparse[0]=invmassD0; arrayForSparse[2]=impparXY;
2236 
2237  if(fReadMC){
2238  if(labD0>=0) {
2239  if(fArray==1) cout<<"LS signal ERROR"<<endl;
2240 
2241  AliAODMCParticle *partD0 = (AliAODMCParticle*)arrMC->At(labD0);
2242  Int_t pdgD0 = partD0->GetPdgCode();
2243  // cout<<"pdg = "<<pdgD0<<endl;
2244 
2245  // old function if(CheckOrigin(arrMC,partD0)==5) isPrimary=kFALSE;
2246  if(AliVertexingHFUtils::CheckOrigin(arrMC,partD0,fUseQuarkTagInKine)==5) isPrimary=kFALSE;
2247  if(!isPrimary)
2248  trueImpParXY=GetTrueImpactParameter(mcHeader,arrMC,partD0)*10000.;
2249  arrayForSparseTrue[0]=invmassD0; arrayForSparseTrue[2]=trueImpParXY;
2250 
2251  if (pdgD0==421){ //D0
2252  // cout<<"Fill S with D0"<<endl;
2253  fillthis="histSgn_";
2254  fillthis+=ptbin;
2255  ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0,weigD0);
2256 
2257  if(fFillPtHist){
2258  fillthismasspt="histSgnPt";
2259  ((TH2F*)(fOutputMassPt->FindObject(fillthismasspt)))->Fill(invmassD0,pt,weigD0);
2260  }
2261  if(fFillImpParHist){
2262  if(isPrimary) fHistMassPtImpParTC[1]->Fill(arrayForSparse,weigD0);
2263  else {
2264  fHistMassPtImpParTC[2]->Fill(arrayForSparse,weigD0);
2265  fHistMassPtImpParTC[3]->Fill(arrayForSparseTrue,weigD0);
2266  }
2267  }
2268 
2269  if(fFillYHist){
2270  fillthismassy="histSgnY_";
2271  fillthismassy+=ptbin;
2272  ((TH2F*)(fOutputMassY->FindObject(fillthismassy)))->Fill(invmassD0,y,weigD0);
2273  }
2274 
2275  if(fSys==0){
2276  if(TMath::Abs(invmassD0 - mPDG) < 0.027 && fFillVarHists){
2277  fillthis="histSgn27_";
2278  fillthis+=ptbin;
2279  ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0,weigD0);
2280  }
2281  }
2282  } else{ //it was a D0bar
2283  fillthis="histRfl_";
2284  fillthis+=ptbin;
2285  ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0,weigD0);
2286 
2287  if(fFillPtHist){
2288  fillthismasspt="histRflPt";
2289  // cout << " Filling "<<fillthismasspt<<" D0bar"<<endl;
2290  ((TH2F*)(fOutputMassPt->FindObject(fillthismasspt)))->Fill(invmassD0,pt,weigD0);
2291  }
2292 
2293  if(fFillYHist){
2294  fillthismassy="histRflY_";
2295  fillthismassy+=ptbin;
2296  // cout << " Filling "<<fillthismassy<<" D0bar"<<endl;
2297  ((TH2F*)(fOutputMassY->FindObject(fillthismassy)))->Fill(invmassD0,y,weigD0);
2298  }
2299 
2300  }
2301  } else {//background
2302  fillthis="histBkg_";
2303  fillthis+=ptbin;
2304  ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0,weigD0);
2305 
2306  if(fFillPtHist){
2307  fillthismasspt="histBkgPt";
2308  // cout << " Filling "<<fillthismasspt<<" D0bar"<<endl;
2309  ((TH2F*)(fOutputMassPt->FindObject(fillthismasspt)))->Fill(invmassD0,pt,weigD0);
2310  }
2311  if(fFillImpParHist) fHistMassPtImpParTC[4]->Fill(arrayForSparse,weigD0);
2312 
2313  if(fFillYHist){
2314  fillthismassy="histBkgY_";
2315  fillthismassy+=ptbin;
2316  // cout << " Filling "<<fillthismassy<<" D0bar"<<endl;
2317  ((TH2F*)(fOutputMassY->FindObject(fillthismassy)))->Fill(invmassD0,y,weigD0);
2318  }
2319 
2320  }
2321 
2322  }else{
2323  fillthis="histMass_";
2324  fillthis+=ptbin;
2325  // cout<<"Filling "<<fillthis<<endl;
2326 
2327  // printf("Fill mass with D0");
2328  ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0,weigD0);
2329 
2330  if(fFillSubSampleHist){
2331  fillthissub="histMassvsSubSample_";
2332  fillthissub+=ptbin;
2333  ((TH2F*)(listout->FindObject(fillthissub)))->Fill(invmassD0,(Double_t)(fEventCounter%24),weigD0);
2334  }
2335 
2336  if(fFillPtHist){
2337  fillthismasspt="histMassPt";
2338  // cout<<"Filling "<<fillthismasspt<<endl;
2339  ((TH2F*)(fOutputMassPt->FindObject(fillthismasspt)))->Fill(invmassD0,pt,weigD0);
2340  }
2341  if(fFillImpParHist) {
2342  // cout << "Filling fHistMassPtImpParTC[0]"<<endl;
2343  fHistMassPtImpParTC[0]->Fill(arrayForSparse,weigD0);
2344  }
2345 
2346  if(fFillYHist){
2347  fillthismassy="histMassY_";
2348  fillthismassy+=ptbin;
2349  // cout<<"Filling "<<fillthismassy<<endl;
2350  ((TH2F*)(fOutputMassY->FindObject(fillthismassy)))->Fill(invmassD0,y,weigD0);
2351  }
2352 
2353  }
2354 
2355  }
2356  if (fIsSelectedCandidate>1 && (fFillOnlyD0D0bar==0 || fFillOnlyD0D0bar==2)) { //D0bar
2357 
2358  arrayForSparse[0]=invmassD0bar; arrayForSparse[2]=impparXY;
2359 
2360  if(fReadMC){
2361  if(labD0>=0) {
2362  if(fArray==1) cout<<"LS signal ERROR"<<endl;
2363  AliAODMCParticle *partD0 = (AliAODMCParticle*)arrMC->At(labD0);
2364  Int_t pdgD0 = partD0->GetPdgCode();
2365  // cout<<" pdg = "<<pdgD0<<endl;
2366 
2367  //old function if(CheckOrigin(arrMC,partD0)==5) isPrimary=kFALSE;
2368  if(AliVertexingHFUtils::CheckOrigin(arrMC,partD0,fUseQuarkTagInKine)==5) isPrimary=kFALSE;
2369  if(!isPrimary)
2370  trueImpParXY=GetTrueImpactParameter(mcHeader,arrMC,partD0)*10000.;
2371  arrayForSparseTrue[0]=invmassD0bar; arrayForSparseTrue[2]=trueImpParXY;
2372 
2373  if (pdgD0==-421){ //D0bar
2374  fillthis="histSgn_";
2375  fillthis+=ptbin;
2376  ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0bar,weigD0bar);
2377  // if (TMath::Abs(invmassD0bar - mPDG) < 0.027){
2378  // fillthis="histSgn27_";
2379  // fillthis+=ptbin;
2380  // ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0bar);
2381  // }
2382 
2383  if(fFillPtHist){
2384  fillthismasspt="histSgnPt";
2385  // cout<<" Filling "<< fillthismasspt << endl;
2386  ((TH2F*)(fOutputMassPt->FindObject(fillthismasspt)))->Fill(invmassD0bar,pt,weigD0bar);
2387  }
2388  if(fFillImpParHist){
2389  // cout << " Filling impact parameter thnsparse"<<endl;
2390  if(isPrimary) fHistMassPtImpParTC[1]->Fill(arrayForSparse,weigD0bar);
2391  else {
2392  fHistMassPtImpParTC[2]->Fill(arrayForSparse,weigD0bar);
2393  fHistMassPtImpParTC[3]->Fill(arrayForSparseTrue,weigD0bar);
2394  }
2395  }
2396 
2397  if(fFillYHist){
2398  fillthismassy="histSgnY_";
2399  fillthismassy+=ptbin;
2400  // cout<<" Filling "<< fillthismassy << endl;
2401  ((TH2F*)(fOutputMassY->FindObject(fillthismassy)))->Fill(invmassD0bar,y,weigD0bar);
2402  }
2403 
2404  } else{
2405  fillthis="histRfl_";
2406  fillthis+=ptbin;
2407  ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0bar,weigD0bar);
2408  if(fFillPtHist){
2409  fillthismasspt="histRflPt";
2410  // cout << " Filling "<<fillthismasspt<<endl;
2411  ((TH2F*)(fOutputMassPt->FindObject(fillthismasspt)))->Fill(invmassD0bar,pt,weigD0bar);
2412  }
2413  if(fFillYHist){
2414  fillthismassy="histRflY_";
2415  fillthismassy+=ptbin;
2416  // cout << " Filling "<<fillthismassy<<endl;
2417  ((TH2F*)(fOutputMassY->FindObject(fillthismassy)))->Fill(invmassD0bar,y,weigD0bar);
2418  }
2419  }
2420  } else {//background or LS
2421  fillthis="histBkg_";
2422  fillthis+=ptbin;
2423  ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0bar,weigD0bar);
2424 
2425  if(fFillPtHist){
2426  fillthismasspt="histBkgPt";
2427  // cout<<" Filling "<< fillthismasspt << endl;
2428  ((TH2F*)(fOutputMassPt->FindObject(fillthismasspt)))->Fill(invmassD0bar,pt,weigD0bar);
2429  }
2430  if(fFillImpParHist) fHistMassPtImpParTC[4]->Fill(arrayForSparse,weigD0bar);
2431  if(fFillYHist){
2432  fillthismassy="histBkgY_";
2433  fillthismassy+=ptbin;
2434  // cout<<" Filling "<< fillthismassy << endl;
2435  ((TH2F*)(fOutputMassY->FindObject(fillthismassy)))->Fill(invmassD0bar,y,weigD0bar);
2436  }
2437  }
2438  }else{
2439  fillthis="histMass_";
2440  fillthis+=ptbin;
2441  // printf("Fill mass with D0bar");
2442 
2443  ((TH1F*)listout->FindObject(fillthis))->Fill(invmassD0bar,weigD0bar);
2444 
2445  if(fFillSubSampleHist){
2446  fillthissub="histMassvsSubSample_";
2447  fillthissub+=ptbin;
2448  ((TH2F*)(listout->FindObject(fillthissub)))->Fill(invmassD0bar,(Double_t)(fEventCounter%24),weigD0);
2449  }
2450 
2451  if(fFillPtHist){
2452  fillthismasspt="histMassPt";
2453  // cout<<" Filling "<< fillthismasspt << endl;
2454  ((TH2F*)(fOutputMassPt->FindObject(fillthismasspt)))->Fill(invmassD0bar,pt,weigD0bar);
2455  }
2456  if(fFillImpParHist) fHistMassPtImpParTC[0]->Fill(arrayForSparse,weigD0bar);
2457  if(fFillYHist){
2458  fillthismassy="histMassY_";
2459  fillthismassy+=ptbin;
2460  // cout<<" Filling "<< fillthismassy << endl;
2461  ((TH2F*)(fOutputMassY->FindObject(fillthismassy)))->Fill(invmassD0bar,y,weigD0bar);
2462  }
2463  }
2464  }
2465 
2466  return;
2467 }
2468 
2469 //__________________________________________________________________________
2472 
2473  Int_t skipped[2];
2474  Int_t nTrksToSkip=2;
2475  AliAODTrack *dgTrack = (AliAODTrack*)fDaughterTracks.UncheckedAt(0);
2476  if(!dgTrack){
2477  AliDebug(2,"no daughter found!");
2478  return 0x0;
2479  }
2480  skipped[0]=dgTrack->GetID();
2481  dgTrack = (AliAODTrack*)fDaughterTracks.UncheckedAt(1);
2482  if(!dgTrack){
2483  AliDebug(2,"no daughter found!");
2484  return 0x0;
2485  }
2486  skipped[1]=dgTrack->GetID();
2487 
2488  AliESDVertex *vertexESD=0x0;
2489  AliAODVertex *vertexAOD=0x0;
2490  AliVertexerTracks *vertexer = new AliVertexerTracks(aodev->GetMagneticField());
2491 
2492  //
2493  vertexer->SetSkipTracks(nTrksToSkip,skipped);
2494  vertexer->SetMinClusters(4);
2495  vertexESD = (AliESDVertex*)vertexer->FindPrimaryVertex(aodev);
2496  if(!vertexESD) return vertexAOD;
2497  if(vertexESD->GetNContributors()<=0) {
2498  AliDebug(2,"vertexing failed");
2499  delete vertexESD; vertexESD=NULL;
2500  return vertexAOD;
2501  }
2502 
2503  delete vertexer; vertexer=NULL;
2504 
2505 
2506  // convert to AliAODVertex
2507  Double_t pos[3],cov[6],chi2perNDF;
2508  vertexESD->GetXYZ(pos); // position
2509  vertexESD->GetCovMatrix(cov); //covariance matrix
2510  chi2perNDF = vertexESD->GetChi2toNDF();
2511  delete vertexESD; vertexESD=NULL;
2512 
2513  vertexAOD = new AliAODVertex(pos,cov,chi2perNDF);
2514  return vertexAOD;
2515 
2516 }
2517 
2518 
2519 //________________________________________________________________________
2521 {
2523  //
2524  if(fDebug > 1) printf("AnalysisTaskSED0Mass: Terminate() \n");
2525 
2526 
2527  fOutputMass = dynamic_cast<TList*> (GetOutputData(1));
2528  if (!fOutputMass) {
2529  printf("ERROR: fOutputMass not available\n");
2530  return;
2531  }
2532  fOutputMassPt = dynamic_cast<TList*> (GetOutputData(6));
2533  if ((fFillPtHist || fFillImpParHist) && !fOutputMassPt) {
2534  printf("ERROR: fOutputMass not available\n");
2535  return;
2536  }
2537 
2538  if(fFillVarHists){
2539  fDistr = dynamic_cast<TList*> (GetOutputData(2));
2540  if (!fDistr) {
2541  printf("ERROR: fDistr not available\n");
2542  return;
2543  }
2544  }
2545 
2546  fNentries = dynamic_cast<TH1F*>(GetOutputData(3));
2547 
2548  if(!fNentries){
2549  printf("ERROR: fNEntries not available\n");
2550  return;
2551  }
2552  fCuts = dynamic_cast<AliRDHFCutsD0toKpi*>(GetOutputData(4));
2553  if(!fCuts){
2554  printf("ERROR: fCuts not available\n");
2555  return;
2556  }
2557  fCounter = dynamic_cast<AliNormalizationCounter*>(GetOutputData(5));
2558  if (!fCounter) {
2559  printf("ERROR: fCounter not available\n");
2560  return;
2561  }
2562  if (fDrawDetSignal) {
2563  fDetSignal = dynamic_cast<TList*>(GetOutputData(8));
2564  if (!fDetSignal) {
2565  printf("ERROR: fDetSignal not available\n");
2566  return;
2567  }
2568  }
2569  if(fFillYHist){
2570  fOutputMassY = dynamic_cast<TList*> (GetOutputData(9));
2571  if (fFillYHist && !fOutputMassY) {
2572  printf("ERROR: fOutputMassY not available\n");
2573  return;
2574  }
2575  }
2576 
2578  for(Int_t ipt=0;ipt<nptbins;ipt++){
2579 
2580  if(fArray==1 && fFillVarHists){
2581  fLsNormalization = 2.*TMath::Sqrt(((TH1F*)fOutputMass->FindObject("hpospair"))->Integral(nptbins+ipt+1,nptbins+ipt+2)*((TH1F*)fOutputMass->FindObject("hnegpair"))->Integral(nptbins+ipt+1,nptbins+ipt+2)); //after cuts
2582 
2583 
2584  if(fLsNormalization>1e-6) {
2585 
2586  TString massName="histMass_";
2587  massName+=ipt;
2588  ((TH1F*)fOutputMass->FindObject(massName))->Scale((1/fLsNormalization)*((TH1F*)fOutputMass->FindObject(massName))->GetEntries());
2589 
2590  }
2591 
2592 
2593  fLsNormalization = 2.*TMath::Sqrt(((TH1F*)fOutputMass->FindObject("hpospair"))->Integral(ipt+1,ipt+2)*((TH1F*)fOutputMass->FindObject("hnegpair"))->Integral(ipt+1,ipt+2));
2594  //fLsNormalization = 2.*TMath::Sqrt(fTotPosPairs[4]*fTotNegPairs[4]);
2595 
2596  if(fLsNormalization>1e-6) {
2597 
2598  TString nameDistr="hdcaB_";
2599  nameDistr+=ipt;
2600  ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
2601  nameDistr="hd0B_";
2602  nameDistr+=ipt;
2603  ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
2604  nameDistr="hd0d0B_";
2605  nameDistr+=ipt;
2606  ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
2607  nameDistr="hcosthetapointB_";
2608  nameDistr+=ipt;
2609  ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
2610  if(fSys==0){
2611  nameDistr="hptB_";
2612  nameDistr+=ipt;
2613  ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
2614  nameDistr="hcosthetastarB_";
2615  nameDistr+=ipt;
2616  ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
2617  nameDistr="hcosthpointd0d0B_";
2618  nameDistr+=ipt;
2619  ((TH2F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH2F*)fDistr->FindObject(nameDistr))->GetEntries());
2620  }
2621  }
2622  }
2623  }
2624  TString cvname,cstname;
2625 
2626  if (fArray==0){
2627  cvname="D0invmass";
2628  cstname="cstat0";
2629  } else {
2630  cvname="LSinvmass";
2631  cstname="cstat1";
2632  }
2633 
2634  TCanvas *cMass=new TCanvas(cvname,cvname);
2635  cMass->cd();
2636  ((TH1F*)fOutputMass->FindObject("histMass_3"))->Draw();
2637 
2638  TCanvas* cStat=new TCanvas(cstname,Form("Stat%s",fArray ? "LS" : "D0"));
2639  cStat->cd();
2640  cStat->SetGridy();
2641  fNentries->Draw("htext0");
2642 
2643  // TCanvas *ccheck=new TCanvas(Form("cc%d",fArray),Form("cc%d",fArray));
2644  // ccheck->cd();
2645 
2646  return;
2647 }
2648 
2649 
2650 //________________________________________________________________________
2653 
2654  Int_t nmassbins=200;
2655  Double_t fLowmasslimit=1.5648, fUpmasslimit=2.1648;
2656  Int_t fNImpParBins=400;
2657  Double_t fLowerImpPar=-2000., fHigherImpPar=2000.;
2658  Int_t nbins[3]={nmassbins,200,fNImpParBins};
2659  Double_t xmin[3]={fLowmasslimit,0.,fLowerImpPar};
2660  Double_t xmax[3]={fUpmasslimit,20.,fHigherImpPar};
2661 
2662 
2663  fHistMassPtImpParTC[0]=new THnSparseF("hMassPtImpParAll",
2664  "Mass vs. pt vs.imppar - All",
2665  3,nbins,xmin,xmax);
2666  fHistMassPtImpParTC[1]=new THnSparseF("hMassPtImpParPrompt",
2667  "Mass vs. pt vs.imppar - promptD",
2668  3,nbins,xmin,xmax);
2669  fHistMassPtImpParTC[2]=new THnSparseF("hMassPtImpParBfeed",
2670  "Mass vs. pt vs.imppar - DfromB",
2671  3,nbins,xmin,xmax);
2672  fHistMassPtImpParTC[3]=new THnSparseF("hMassPtImpParTrueBfeed",
2673  "Mass vs. pt vs.true imppar -DfromB",
2674  3,nbins,xmin,xmax);
2675  fHistMassPtImpParTC[4]=new THnSparseF("hMassPtImpParBkg",
2676  "Mass vs. pt vs.imppar - backgr.",
2677  3,nbins,xmin,xmax);
2678 
2679  for(Int_t i=0; i<5;i++){
2681  }
2682 }
2683 
2684 //_________________________________________________________________________________________________
2685 Float_t AliAnalysisTaskSED0Mass::GetTrueImpactParameter(AliAODMCHeader *mcHeader, TClonesArray* arrayMC, AliAODMCParticle *partD0) const {
2687 
2688  printf(" AliAnalysisTaskSED0MassV1::GetTrueImpactParameter() \n");
2689 
2690  Double_t vtxTrue[3];
2691  mcHeader->GetVertex(vtxTrue);
2692  Double_t origD[3];
2693  partD0->XvYvZv(origD);
2694  Short_t charge=partD0->Charge();
2695  Double_t pXdauTrue[2],pYdauTrue[2],pZdauTrue[2];
2696  for(Int_t iDau=0; iDau<2; iDau++){
2697  pXdauTrue[iDau]=0.;
2698  pYdauTrue[iDau]=0.;
2699  pZdauTrue[iDau]=0.;
2700  }
2701 
2702  // Int_t nDau=partD0->GetNDaughters();
2703  Int_t labelFirstDau = partD0->GetDaughter(0);
2704 
2705  for(Int_t iDau=0; iDau<2; iDau++){
2706  Int_t ind = labelFirstDau+iDau;
2707  AliAODMCParticle* part = dynamic_cast<AliAODMCParticle*>(arrayMC->At(ind));
2708  if(!part) continue;
2709  Int_t pdgCode = TMath::Abs( part->GetPdgCode() );
2710  if(!part){
2711  AliError("Daughter particle not found in MC array");
2712  return 99999.;
2713  }
2714  if(pdgCode==211 || pdgCode==321){
2715  pXdauTrue[iDau]=part->Px();
2716  pYdauTrue[iDau]=part->Py();
2717  pZdauTrue[iDau]=part->Pz();
2718  }
2719  }
2720 
2721  Double_t d0dummy[2]={0.,0.};
2722  AliAODRecoDecayHF aodDzeroMC(vtxTrue,origD,2,charge,pXdauTrue,pYdauTrue,pZdauTrue,d0dummy);
2723  return aodDzeroMC.ImpParXY();
2724 
2725 }
2726 
2727 //_________________________________________________________________________________________________
2728 Int_t AliAnalysisTaskSED0Mass::CheckOrigin(TClonesArray* arrayMC, AliAODMCParticle *mcPartCandidate) const {
2729  // obsolete method
2731  //
2732  printf(" AliAnalysisTaskSED0Mass V1::CheckOrigin() \n");
2733 
2734  Int_t pdgGranma = 0;
2735  Int_t mother = 0;
2736  mother = mcPartCandidate->GetMother();
2737  Int_t istep = 0;
2738  Int_t abspdgGranma =0;
2739  Bool_t isFromB=kFALSE;
2740  Bool_t isQuarkFound=kFALSE;
2741  while (mother >0 ){
2742  istep++;
2743  AliAODMCParticle* mcGranma = dynamic_cast<AliAODMCParticle*>(arrayMC->At(mother));
2744  if (mcGranma){
2745  pdgGranma = mcGranma->GetPdgCode();
2746  abspdgGranma = TMath::Abs(pdgGranma);
2747  if ((abspdgGranma > 500 && abspdgGranma < 600) || (abspdgGranma > 5000 && abspdgGranma < 6000)){
2748  isFromB=kTRUE;
2749  }
2750  if(abspdgGranma==4 || abspdgGranma==5) isQuarkFound=kTRUE;
2751  mother = mcGranma->GetMother();
2752  }else{
2753  AliError("Failed casting the mother particle!");
2754  break;
2755  }
2756  }
2757 
2758  if(isFromB) return 5;
2759  else return 4;
2760 }
2761 //_______________________________________
2764 
2765  const Int_t nVarPrompt = 2;
2766  const Int_t nVarFD = 3;
2767 
2768  Int_t nbinsPrompt[nVarPrompt]={200,100};
2769  Int_t nbinsFD[nVarFD]={200,100,200};
2770 
2771  Double_t xminPrompt[nVarPrompt] = {0.,-1.};
2772  Double_t xmaxPrompt[nVarPrompt] = {40.,1.};
2773 
2774  Double_t xminFD[nVarFD] = {0.,-1.,0.};
2775  Double_t xmaxFD[nVarFD] = {40.,1.,40.};
2776 
2777  //pt, y
2778  fMCAccPrompt = new THnSparseF("hMCAccPrompt","kStepMCAcceptance pt vs. y - promptD",nVarPrompt,nbinsPrompt,xminPrompt,xmaxPrompt);
2779  fMCAccPrompt->GetAxis(0)->SetTitle("p_{T} (GeV/c)");
2780  fMCAccPrompt->GetAxis(1)->SetTitle("y");
2781 
2782  //pt,y,ptB
2783  fMCAccBFeed = new THnSparseF("hMCAccBFeed","kStepMCAcceptance pt vs. y vs. ptB - DfromB",nVarFD,nbinsFD,xminFD,xmaxFD);
2784  fMCAccBFeed->GetAxis(0)->SetTitle("p_{T} (GeV/c)");
2785  fMCAccBFeed->GetAxis(1)->SetTitle("y");
2786  fMCAccBFeed->GetAxis(2)->SetTitle("p_{T}^{B} (GeV/c)");
2787 
2788  fOutputMass->Add(fMCAccPrompt);
2789  fOutputMass->Add(fMCAccBFeed);
2790 }
2791 //___________________________________________________________________________________________________
2792 void AliAnalysisTaskSED0Mass::FillMCAcceptanceHistos(TClonesArray *arrayMC, AliAODMCHeader *mcHeader){
2794  const Int_t nProng = 2;
2795  Double_t zMCVertex = mcHeader->GetVtxZ(); //vertex MC
2796 
2797  for(Int_t iPart=0; iPart<arrayMC->GetEntriesFast(); iPart++){
2798  AliAODMCParticle* mcPart = dynamic_cast<AliAODMCParticle*>(arrayMC->At(iPart));
2799  if (TMath::Abs(mcPart->GetPdgCode()) == 421){
2800 
2801  Int_t orig=AliVertexingHFUtils::CheckOrigin(arrayMC,mcPart,fUseQuarkTagInKine);//Prompt = 4, FeedDown = 5
2802 
2803  Int_t deca = 0;
2804  Bool_t isGoodDecay=kFALSE;
2805  Int_t labDau[4]={-1,-1,-1,-1};
2806  Bool_t isInAcc = kFALSE;
2807  Bool_t isFidAcc = kFALSE;
2808 
2809  deca=AliVertexingHFUtils::CheckD0Decay(arrayMC,mcPart,labDau);
2810  if(deca > 0) isGoodDecay=kTRUE;
2811 
2812  if(labDau[0]==-1){
2813  continue; //protection against unfilled array of labels
2814  }
2815 
2816  isFidAcc=fCuts->IsInFiducialAcceptance(mcPart->Pt(),mcPart->Y());
2817  isInAcc=CheckAcc(arrayMC,nProng,labDau);
2818 
2819  if(isGoodDecay && TMath::Abs(zMCVertex) < fCuts->GetMaxVtxZ() && isFidAcc && isInAcc) {
2820  //for prompt
2821  if(orig == 4){
2822  //fill histo for prompt
2823  Double_t arrayMCprompt[2] = {mcPart->Pt(),mcPart->Y()};
2824  fMCAccPrompt->Fill(arrayMCprompt);
2825  }
2826  //for FD
2827  else if(orig == 5){
2828  Double_t ptB = AliVertexingHFUtils::GetBeautyMotherPt(arrayMC,mcPart);
2829  //fill histo for FD
2830  Double_t arrayMCFD[3] = {mcPart->Pt(),mcPart->Y(),ptB};
2831  fMCAccBFeed->Fill(arrayMCFD);
2832  }
2833  else
2834  continue;
2835  }
2836  }
2837  }
2838 }
2839 //______________________________________________________________________
2840 Bool_t AliAnalysisTaskSED0Mass::CheckAcc(TClonesArray* arrayMC,Int_t nProng, Int_t *labDau){
2842  for (Int_t iProng = 0; iProng<nProng; iProng++){
2843  AliAODMCParticle* mcPartDaughter=dynamic_cast<AliAODMCParticle*>(arrayMC->At(labDau[iProng]));
2844  if(!mcPartDaughter) return kFALSE;
2845  Double_t eta = mcPartDaughter->Eta();
2846  Double_t pt = mcPartDaughter->Pt();
2847  if (TMath::Abs(eta) > 0.9 || pt < 0.1) return kFALSE;
2848  }
2849  return kTRUE;
2850 }
2851 //________________________________________
2853  Double_t normIP[2];
2854  Double_t pointD0[9];
2855  Double_t pointD0bar[9];
2856  Double_t pointD0MC[9];
2857  Float_t ptB;
2858  Int_t signalType=0;//background
2859 
2860  //fill variables
2861  Double_t diffIP[2], errdiffIP[2];
2862  part->Getd0MeasMinusExpProng(0,aod->GetMagneticField(),diffIP[0],errdiffIP[0]);
2863  part->Getd0MeasMinusExpProng(1,aod->GetMagneticField(),diffIP[1],errdiffIP[1]);
2864  normIP[0]=diffIP[0]/errdiffIP[0];
2865  normIP[1]=diffIP[1]/errdiffIP[1];
2866 
2867  AliAODVertex* secvtx=part->GetSecondaryVtx();
2868  AliAODVertex *primvtx=part->GetPrimaryVtx();
2869  Double_t err2decaylength=secvtx->Error2DistanceXYToVertex(primvtx);
2870  Double_t lxy=part->AliAODRecoDecay::DecayLengthXY(primvtx);
2871  Bool_t ispid=fCuts->GetIsUsePID();
2872 
2873  if(fReadMC){
2874  // MC THnSparse
2875  Int_t pdgDgD0toKpi[2]={321,211};
2876  Int_t lab=-9999;
2877  lab=part->MatchToMC(421,arrMC,2,pdgDgD0toKpi); //return MC particle label if the array corresponds to a D0, -1 if not (cf. AliAODRecoDecay.cxx)
2878  if(lab>=0){
2879  signalType=1;//signal
2880  AliAODMCParticle *partD0 = (AliAODMCParticle*)arrMC->At(lab);
2882  if(orig==4)signalType=1;//prompt
2883  else if(orig==5)signalType=2;//feed down
2884  //pt, ptB, normImpParTrk1, normImpParTrk2, decLXY, normDecLXY, iscut, ispid
2885  if(ispid)fCuts->SetUsePID(kFALSE);// if PID on, switch it off
2886  Int_t isCuts=fCuts->IsSelected(part,AliRDHFCuts::kAll,aod);
2887  if(ispid)fCuts->SetUsePID(kTRUE);//if PID was on, switch it on
2888  if(!isCuts) return;
2889  Int_t isPid= fCuts->IsSelectedPID(part);
2890  ptB=AliVertexingHFUtils::GetBeautyMotherPt(arrMC,partD0);
2891  Double_t arrayMC[8]={part->Pt(), ptB,normIP[0], normIP[1], lxy, lxy/TMath::Sqrt(err2decaylength),(Double_t)isCuts, (Double_t)isPid};
2892 
2893  //fill pointD0MC
2894  for(Int_t i=0; i<8; i++){
2895  pointD0MC[i]=arrayMC[i];
2896  }
2897  if(signalType==1)fhStudyImpParSingleTrackSign->Fill(pointD0MC);
2898  if(signalType==2){
2899  fhStudyImpParSingleTrackFd->Fill(pointD0MC);
2900  }
2901  }
2902  }else{
2903  // data
2904  if(ispid)fCuts->SetUsePID(kFALSE);// if PID on, switch it off
2905  Int_t IsSelectedPIDoff=fCuts->IsSelected(part,AliRDHFCuts::kAll,aod);
2906  if(ispid)fCuts->SetUsePID(kTRUE);//if PID was on, switch it on
2907  if(!IsSelectedPIDoff) return;
2908  Int_t pid=fCuts->IsSelectedPID(part);
2909  if((IsSelectedPIDoff==1 || IsSelectedPIDoff==3) && fFillOnlyD0D0bar<2){
2910  Double_t array[9]={part->Pt(),normIP[0],normIP[1],lxy,lxy/TMath::Sqrt(err2decaylength),part->InvMassD0(),(Double_t)IsSelectedPIDoff,(Double_t)pid,0.};
2911  for(Int_t i=0;i<9;i++){
2912  pointD0[i]=array[i];
2913  }
2914  fhStudyImpParSingleTrackCand->Fill(pointD0);
2915  }
2916  if (IsSelectedPIDoff>1 && (fFillOnlyD0D0bar==0 || fFillOnlyD0D0bar==2)){
2917  Double_t arrayD0bar[9]={part->Pt(),normIP[0],normIP[1],lxy,lxy/TMath::Sqrt(err2decaylength),part->InvMassD0bar(),(Double_t)IsSelectedPIDoff,(Double_t)pid,1.};
2918  for(Int_t i=0;i<9;i++){
2919  pointD0bar[i]=arrayD0bar[i];
2920  }
2921  fhStudyImpParSingleTrackCand->Fill(pointD0bar);
2922  }
2923  }
2924 }
Int_t charge
THnSparseF * fMCAccBFeed
!histo for StepMCAcc for D0 FD (pt,y,ptB)
Double_t NormalizedDecayLengthXY() const
AliAODTrack * GetProng(AliVEvent *event, AliAODRecoDecayHF *rd, Int_t iprong)
static Int_t CheckD0Decay(AliMCEvent *mcEvent, Int_t label, Int_t *arrayDauLab)
Bool_t fFillSubSampleHist
flag to fill Pt and Impact Parameter Histograms
TList * fOutputMassPt
! list send on output slot 6
Bool_t fDrawDetSignal
flag to decide whether to fill "PID = x" bins in fNentrie
double Double_t
Definition: External.C:58
void Draw(const char *filename, const char *title="", const char *others="ALL", const char *options="DEFAULT", const char *outFlg="ALL", UShort_t rebin=5, Float_t eff=0, const char *base="")
Definition: DrawdNdeta.C:3603
Bool_t fFillYHist
flag to fill Pt and Impact Parameter Histograms
void StoreCandidates(AliVEvent *, Int_t nCand=0, Bool_t flagFilter=kTRUE)
Definition: External.C:236
void Getd0MeasMinusExpProng(Int_t ip, Double_t magf, Double_t &d0diff, Double_t &errd0diff) const
void FillVarHists(AliAODEvent *aodev, AliAODRecoDecayHF2Prong *part, TClonesArray *arrMC, AliRDHFCutsD0toKpi *cuts, TList *listout)
Bool_t GetCombPID() const
Double_t * fCandidateVariables
! variables to be written to the tree
Bool_t HasSelectionBit(Int_t i) const
Double_t NormalizedDecayLength2() const
Double_t ImpParXY() const
Int_t fAODProtection
flag to check or not the selection bit
static Int_t CheckMatchingAODdeltaAODevents()
TList * fDistr
! list send on output slot 2
void NormIPvar(AliAODEvent *aod, AliAODRecoDecayHF2Prong *part, TClonesArray *arrMC)
Int_t GetWhyRejection() const
Definition: AliRDHFCuts.h:317
TList * fDetSignal
!Detector signal histograms (on output slot 8)
Double_t CosPointingAngleXY() const
Bool_t fUseSelectionBit
event counter used for sub sample test
Bool_t FillRecoCand(AliVEvent *event, AliAODRecoDecayHF3Prong *rd3)
void FillMCAcceptanceHistos(TClonesArray *arrayMC, AliAODMCHeader *mcHeader)
Int_t fSys
flag to enable filling variable histos
ULong_t GetSelectionMap() const
TList * fOutputMass
! list send on output slot 1
virtual Bool_t IsInFiducialAcceptance(Double_t pt, Double_t y) const
Bool_t CheckAcc(TClonesArray *arrayMC, Int_t nProng, Int_t *labDau)
Bool_t fReadMC
can be D0 or Like Sign candidates
static Int_t CheckOrigin(TClonesArray *arrayMC, AliAODMCParticle *mcPart, Bool_t searchUpToQuark=kTRUE)
Functions to check the decay tree.
Double_t GetMaxVtxZ() const
Definition: AliRDHFCuts.h:258
Int_t GetBayesianStrategy() const
Bool_t HasBadDaughters() const
THnSparseF * fHistMassPtImpParTC[5]
! histograms for impact paramter studies
TH1F * fNentries
! histogram with number of events on output slot 3
virtual void UserCreateOutputObjects()
Implementation of interface methods.
Bool_t fFillPtHist
flag to reject events with SDD clusters
Bool_t fFillImpParHist
flag to fill Y Histograms
int Int_t
Definition: External.C:63
Definition: External.C:204
unsigned int UInt_t
Definition: External.C:33
Int_t GetIsFilled() const
Double_t CosThetaStarD0bar() const
angle of K
float Float_t
Definition: External.C:68
Bool_t fUseQuarkTagInKine
flag to decide whether to draw the TPC dE/dx and TOF signal before/after PID
Bool_t fIsRejectSDDClusters
fSys=0 -> p-p; fSys=1 ->PbPb (in this case fFillVarHists=kFALSE by default: set it to kTRUE after if ...
Int_t CheckOrigin(TClonesArray *arrayMC, AliAODMCParticle *mcPartCandidate) const
virtual void Terminate(Option_t *option)
Float_t GetTrueImpactParameter(AliAODMCHeader *mcHeader, TClonesArray *arrayMC, AliAODMCParticle *partD0) const
void DrawDetSignal(AliAODRecoDecayHF2Prong *part, TList *ListDetSignal)
Double_t fLsNormalization
number of pt bins
Bool_t fUsePid4Distr
flag to decide if apply cut also on distributions: 0 no cuts, 1 looser cuts, 2 tighter/ cuts ...
Double_t DecayLength2() const
kinematics & topology
THnSparseF * fhStudyImpParSingleTrackFd
! sparse with imp par residual cuts for MC
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
Bool_t fCutOnDistr
flag for MC array: kTRUE = read it, kFALSE = do not read it
AliAODVertex * GetPrimaryVtxSkipped(AliAODEvent *aodev)
short Short_t
Definition: External.C:23
Int_t IsSelectedSpecialCuts(AliAODRecoDecayHF *d) const
THnSparseF * fhStudyImpParSingleTrackSign
! sparse with imp par residual cuts for MC
void SetOwnPrimaryVtx(const AliAODVertex *vtx)
Double_t DecayLengthXY() const
static Double_t GetBeautyMotherPt(TClonesArray *arrayMC, AliAODMCParticle *mcPart)
void FillMassHists(AliAODRecoDecayHF2Prong *part, TClonesArray *arrMC, AliAODMCHeader *mcHeader, AliRDHFCutsD0toKpi *cuts, TList *listout)
Int_t fIsSelectedCandidate
keeps the daughter tracks
Bool_t GetIsPrimaryWithoutDaughters() const
Definition: AliRDHFCuts.h:279
Double_t * GetWeightsPositive() const
Bool_t AreDaughtersSelected(AliAODRecoDecayHF *rd, const AliAODEvent *aod=0x0) const
Bool_t IsEventSelected(AliVEvent *event)
void StoreEvent(AliVEvent *, AliRDHFCuts *, Bool_t mc=kFALSE, Int_t multiplicity=-9999, Double_t spherocity=-99.)
void SetUsePID(Bool_t flag=kTRUE)
Definition: AliRDHFCuts.h:210
THnSparseF * fhStudyImpParSingleTrackCand
! sparse with imp par residual cuts for Data
virtual Int_t IsSelectedPID(AliAODRecoDecayHF *rd)
TList * fOutputMassY
! list send on output slot 9
TTree * fVariablesTree
flag to decide whether to write the candidate variables on a tree variables
TH2 * Scale(TH2 *h, TH1 *g)
virtual Int_t IsSelected(TObject *obj, Int_t selectionLevel)
Bool_t GetIsUsePID() const
Definition: AliRDHFCuts.h:271
const char Option_t
Definition: External.C:48
Int_t GetNPtBins() const
Definition: AliRDHFCuts.h:250
AliAODVertex * GetPrimaryVtx() const
virtual void UserExec(Option_t *option)
TObjArray fDaughterTracks
flag to fill mass histogram with D0/D0bar only (0 = fill with both, 1 = fill with D0 only...
const Int_t nbins
bool Bool_t
Definition: External.C:53
Double_t CosPointingAngle() const
Double_t DecayLengthXYError() const
virtual Int_t PreSelect(TObjArray aodtracks)
Int_t fFillOnlyD0D0bar
normalization
THnSparseF * fMCAccPrompt
!histo for StepMCAcc for D0 prompt (pt,y,ptB)
Int_t PtBin(Double_t pt) const
Int_t nptbins
Bool_t fFillVarHists
selection outcome
AliNormalizationCounter * fCounter
! AliNormalizationCounter on output slot 5
Double_t * GetWeightsNegative() const
Int_t fEventCounter
flag to fill SubSample histogram