]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/vertexingHF/AliAnalysisTaskSED0Mass.cxx
Update (Chiara)
[u/mrichter/AliRoot.git] / PWG3 / vertexingHF / AliAnalysisTaskSED0Mass.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 /////////////////////////////////////////////////////////////
19 //
20 // AliAnalysisTaskSE for 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 /////////////////////////////////////////////////////////////
27
28 #include <Riostream.h>
29 #include <TClonesArray.h>
30 #include <TCanvas.h>
31 #include <TNtuple.h>
32 #include <TList.h>
33 #include <TH1F.h>
34 #include <TH2F.h>
35 #include <TDatabasePDG.h>
36
37 #include <AliAnalysisDataSlot.h>
38 #include <AliAnalysisDataContainer.h>
39 #include "AliAnalysisManager.h"
40 #include "AliESDtrack.h"
41 #include "AliVertexerTracks.h"
42 #include "AliAODHandler.h"
43 #include "AliAODEvent.h"
44 #include "AliAODVertex.h"
45 #include "AliAODTrack.h"
46 #include "AliAODMCHeader.h"
47 #include "AliAODMCParticle.h"
48 #include "AliAODRecoDecayHF2Prong.h"
49 #include "AliAODRecoCascadeHF.h"
50 #include "AliAnalysisVertexingHF.h"
51 #include "AliAnalysisTaskSE.h"
52 #include "AliAnalysisTaskSED0Mass.h"
53 #include "AliNormalizationCounter.h"
54
55 ClassImp(AliAnalysisTaskSED0Mass)
56
57
58 //________________________________________________________________________
59 AliAnalysisTaskSED0Mass::AliAnalysisTaskSED0Mass():
60 AliAnalysisTaskSE(),
61   fOutputMass(0),
62   fDistr(0),
63   fNentries(0), 
64   fCuts(0),
65   fArray(0),
66   fReadMC(0),
67   fCutOnDistr(0),
68   fUsePid4Distr(0),
69   fCounter(0),
70   fNPtBins(1),
71   fLsNormalization(1.),
72   fFillOnlyD0D0bar(0),
73   fDaughterTracks(),
74   fIsSelectedCandidate(0),
75   fFillVarHists(kTRUE),
76   fSys(0)
77 {
78   // Default constructor
79 }
80
81 //________________________________________________________________________
82 AliAnalysisTaskSED0Mass::AliAnalysisTaskSED0Mass(const char *name,AliRDHFCutsD0toKpi* cuts):
83   AliAnalysisTaskSE(name),
84   fOutputMass(0), 
85   fDistr(0),
86   fNentries(0),
87   fCuts(0),
88   fArray(0),
89   fReadMC(0),
90   fCutOnDistr(0),
91   fUsePid4Distr(0),
92   fCounter(0),
93   fNPtBins(1),
94   fLsNormalization(1.),
95   fFillOnlyD0D0bar(0),
96   fDaughterTracks(),
97   fIsSelectedCandidate(0),
98   fFillVarHists(kTRUE),
99   fSys(0)
100 {
101   // Default constructor
102
103   fNPtBins=cuts->GetNPtBins();
104     
105   fCuts=cuts;
106
107   // Output slot #1 writes into a TList container (mass with cuts)
108   DefineOutput(1,TList::Class());  //My private output
109   // Output slot #2 writes into a TList container (distributions)
110   if(fFillVarHists) DefineOutput(2,TList::Class());  //My private output
111   // Output slot #3 writes into a TH1F container (number of events)
112   DefineOutput(3,TH1F::Class());  //My private output
113   // Output slot #4 writes into a TList container (cuts)
114   DefineOutput(4,AliRDHFCutsD0toKpi::Class());  //My private output
115   // Output slot #5 writes Normalization Counter 
116   DefineOutput(5,AliNormalizationCounter::Class());
117 }
118
119 //________________________________________________________________________
120 AliAnalysisTaskSED0Mass::~AliAnalysisTaskSED0Mass()
121 {
122   if (fOutputMass) {
123     delete fOutputMass;
124     fOutputMass = 0;
125   }
126   if (fDistr) {
127     delete fDistr;
128     fDistr = 0;
129   }
130   if (fCuts) {
131     delete fCuts;
132     fCuts = 0;
133   }
134   if (fNentries){
135     delete fNentries;
136     fNentries = 0;
137   }
138   if(fCounter){
139     delete fCounter;
140     fCounter=0;
141   }
142  
143 }  
144
145 //________________________________________________________________________
146 void AliAnalysisTaskSED0Mass::Init()
147 {
148   // Initialization
149
150   if(fDebug > 1) printf("AnalysisTaskSED0Mass::Init() \n");
151
152   
153   AliRDHFCutsD0toKpi* copyfCuts=new AliRDHFCutsD0toKpi(*fCuts);
154   const char* nameoutput=GetOutputSlot(4)->GetContainer()->GetName();
155   copyfCuts->SetName(nameoutput);
156   // Post the data
157   PostData(4,copyfCuts);
158
159
160   return;
161 }
162
163 //________________________________________________________________________
164 void AliAnalysisTaskSED0Mass::UserCreateOutputObjects()
165 {
166
167   // Create the output container
168   //
169   if(fDebug > 1) printf("AnalysisTaskSED0Mass::UserCreateOutputObjects() \n");
170
171   // Several histograms are more conveniently managed in a TList
172   fOutputMass = new TList();
173   fOutputMass->SetOwner();
174   fOutputMass->SetName("listMass");
175
176   fDistr = new TList();
177   fDistr->SetOwner();
178   fDistr->SetName("distributionslist");
179
180   TString nameMass=" ",nameSgn27=" ",nameSgn=" ", nameBkg=" ", nameRfl=" ",nameMassNocutsS =" ",nameMassNocutsB =" ", namedistr=" ";
181
182   for(Int_t i=0;i<fCuts->GetNPtBins();i++){
183
184     nameMass="histMass_";
185     nameMass+=i;
186     nameSgn27="histSgn27_";
187     nameSgn27+=i;
188     nameSgn="histSgn_";
189     nameSgn+=i;
190     nameBkg="histBkg_";
191     nameBkg+=i;
192     nameRfl="histRfl_";
193     nameRfl+=i;
194     nameMassNocutsS="hMassS_";
195     nameMassNocutsS+=i;
196     nameMassNocutsB="hMassB_";
197     nameMassNocutsB+=i;
198
199     //histograms of cut variable distributions
200     if(fFillVarHists){
201       if(fReadMC){
202         //  dca
203         namedistr="hdcaS_";
204         namedistr+=i;
205         TH1F *hdcaS = new TH1F(namedistr.Data(), "DCA distribution;dca [cm]",200,0.,0.1);
206         // impact parameter
207         namedistr="hd0piS_";
208         namedistr+=i;
209         TH1F *hd0piS = new TH1F(namedistr.Data(), "Impact parameter distribution (pions);d0(#pi) [cm]",200,-0.1,0.1);
210
211         namedistr="hd0KS_";
212         namedistr+=i;
213         TH1F *hd0KS = new TH1F(namedistr.Data(), "Impact parameter distribution (kaons);d0(K) [cm]",200,-0.1,0.1);
214         namedistr="hd0d0S_";
215         namedistr+=i;
216         TH1F *hd0d0S = new TH1F(namedistr.Data(), "d_{0}#timesd_{0} distribution;d_{0}#timesd_{0} [cm^{2}]",200,-0.001,0.001);
217  
218         //decay lenght
219         namedistr="hdeclS_";
220         namedistr+=i;
221         TH1F *hdeclengthS = new TH1F(namedistr.Data(), "Decay Length^{2} distribution;Decay Length^{2} [cm]",200,0,0.015);
222
223         namedistr="hnormdeclS_";
224         namedistr+=i;
225         TH1F *hnormdeclengthS = new TH1F(namedistr.Data(), "Normalized Decay Length^{2} distribution;(Decay Length/Err)^{2} ",200,0,12.);
226
227         namedistr="hdeclxyS_";
228         namedistr+=i;
229         TH1F* hdeclxyS=new TH1F(namedistr.Data(),"Decay Length XY distribution;Decay Length XY [cm]",200,0,0.15);
230         namedistr="hnormdeclxyS_";
231         namedistr+=i;
232         TH1F* hnormdeclxyS=new TH1F(namedistr.Data(),"Normalized decay Length XY distribution;Decay Length XY/Err",200,0,6.); 
233
234         namedistr="hdeclxyd0d0S_";
235         namedistr+=i;
236         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);
237
238         namedistr="hnormdeclxyd0d0S_";
239         namedistr+=i;
240         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);
241
242         //  costhetapoint
243         namedistr="hcosthetapointS_";
244         namedistr+=i;
245         TH1F *hcosthetapointS = new TH1F(namedistr.Data(), "cos#theta_{Point} distribution;cos#theta_{Point}",200,0,1.);
246
247         namedistr="hcosthetapointxyS_";
248         namedistr+=i;
249         TH1F *hcosthetapointxyS = new TH1F(namedistr.Data(), "cos#theta_{Point} XYdistribution;cos#theta_{Point}",300,0.,1.);
250
251         TH1F* tmpMS = new TH1F(nameMassNocutsS.Data(),"D^{0} invariant mass; M [GeV]; Entries",300,1.5648,2.1648); //range (MD0-300MeV, mD0 + 300MeV)
252         tmpMS->Sumw2();
253
254
255         fDistr->Add(hdcaS);
256
257         fDistr->Add(hd0piS);
258         fDistr->Add(hd0KS);
259
260         fDistr->Add(hd0d0S);
261
262         fDistr->Add(hcosthetapointS);
263
264         fDistr->Add(hcosthetapointxyS);
265
266         fDistr->Add(hdeclengthS);
267
268         fDistr->Add(hnormdeclengthS);
269
270         fDistr->Add(hdeclxyS);
271
272         fDistr->Add(hnormdeclxyS);
273
274         fDistr->Add(hdeclxyd0d0S);
275         fDistr->Add(hnormdeclxyd0d0S);
276
277         fDistr->Add(tmpMS);
278       }
279
280       //  dca
281       namedistr="hdcaB_";
282       namedistr+=i;
283       TH1F *hdcaB = new TH1F(namedistr.Data(), "DCA distribution;dca [cm]",200,0.,0.1);
284
285       // impact parameter
286       namedistr="hd0B_";
287       namedistr+=i;
288       TH1F *hd0B = new TH1F(namedistr.Data(), "Impact parameter distribution (both);d0 [cm]",200,-0.1,0.1);
289  
290       namedistr="hd0d0B_";
291       namedistr+=i;
292       TH1F *hd0d0B = new TH1F(namedistr.Data(), "d_{0}#timesd_{0} distribution;d_{0}#timesd_{0} [cm^{2}]",200,-0.001,0.001);
293
294       //decay lenght
295       namedistr="hdeclB_";
296       namedistr+=i;
297       TH1F *hdeclengthB = new TH1F(namedistr.Data(), "Decay Length^{2} distribution;Decay Length^{2} [cm^{2}]",200,0,0.015);
298
299       namedistr="hnormdeclB_";
300       namedistr+=i;
301       TH1F *hnormdeclengthB = new TH1F(namedistr.Data(), "Normalized Decay Length distribution;(Decay Length/Err)^{2} ",200,0,12.);
302
303       namedistr="hdeclxyB_";
304       namedistr+=i;
305       TH1F* hdeclxyB=new TH1F(namedistr.Data(),"Decay Length XY distribution;Decay Length XY [cm]",200,0,0.15);
306       namedistr="hnormdeclxyB_";
307       namedistr+=i;
308       TH1F* hnormdeclxyB=new TH1F(namedistr.Data(),"Normalized decay Length XY distribution;Decay Length XY/Err",200,0,6.); 
309
310       namedistr="hdeclxyd0d0B_";
311       namedistr+=i;
312       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);
313
314       namedistr="hnormdeclxyd0d0B_";
315       namedistr+=i;
316       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);
317
318       //  costhetapoint
319       namedistr="hcosthetapointB_";
320       namedistr+=i;
321       TH1F *hcosthetapointB = new TH1F(namedistr.Data(), "cos#theta_{Point} distribution;cos#theta_{Point}",200,0,1.);
322
323       namedistr="hcosthetapointxyB_";
324       namedistr+=i;
325       TH1F *hcosthetapointxyB = new TH1F(namedistr.Data(), "cos#theta_{Point} XY distribution;cos#theta_{Point} XY",300,0.,1.);
326
327       TH1F* tmpMB = new TH1F(nameMassNocutsB.Data(),"D^{0} invariant mass; M [GeV]; Entries",300,1.5648,2.1648); //range (MD0-300MeV, mD0 + 300MeV)
328       tmpMB->Sumw2();
329
330
331
332       fDistr->Add(hdcaB);
333
334       fDistr->Add(hd0B);
335
336       fDistr->Add(hd0d0B);
337
338       fDistr->Add(hcosthetapointB);
339
340       fDistr->Add(hcosthetapointxyB);
341
342       fDistr->Add(hdeclengthB);
343
344       fDistr->Add(hnormdeclengthB);
345
346       fDistr->Add(hdeclxyB);
347
348       fDistr->Add(hnormdeclxyB);
349
350       fDistr->Add(hdeclxyd0d0B);
351       fDistr->Add(hnormdeclxyd0d0B);
352
353       fDistr->Add(tmpMB);
354
355       //histograms filled only when the secondary vertex is recalculated w/o the daughter tracks (as requested in the cut object)
356
357       if(fCuts->GetIsPrimaryWithoutDaughters()){
358         if(fReadMC){
359           namedistr="hd0vpiS_";
360           namedistr+=i;
361           TH1F *hd0vpiS = new TH1F(namedistr.Data(), "Impact parameter distribution (pions)(vtx w/o these tracks);d0(#pi) [cm]",200,-0.1,0.1);
362           
363           namedistr="hd0vKS_";
364           namedistr+=i;
365           TH1F *hd0vKS = new TH1F(namedistr.Data(), "Impact parameter distribution (kaons) (vtx w/o these tracks);d0(K) [cm]",200,-0.1,0.1);
366
367           namedistr="hd0d0vS_";
368           namedistr+=i;
369           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);
370  
371           namedistr="hdeclvS_";
372           namedistr+=i;
373           TH1F *hdeclengthvS = new TH1F(namedistr.Data(), "Decay Length distribution (vtx w/o tracks);Decay Length [cm]",200,0,0.6);
374
375           namedistr="hnormdeclvS_";
376           namedistr+=i;
377           TH1F *hnormdeclengthvS = new TH1F(namedistr.Data(), "Normalized Decay Length distribution (vtx w/o tracks);Decay Length/Err ",200,0,10.);
378
379           fDistr->Add(hd0vpiS);
380           fDistr->Add(hd0vKS);
381           fDistr->Add(hd0d0vS);
382           fDistr->Add(hdeclengthvS);
383           fDistr->Add(hnormdeclengthvS);
384
385         }
386
387         namedistr="hd0vmoresB_";
388         namedistr+=i;
389         TH1F *hd0vmoresB = new TH1F(namedistr.Data(), "Impact parameter distribution (both);d0 [cm]",200,-0.1,0.1);
390
391         namedistr="hd0d0vmoresB_";
392         namedistr+=i;
393         TH1F *hd0d0vmoresB = new TH1F(namedistr.Data(), "Impact parameter distribution (prong +);d0 [cm]",200,-0.001,0.001);
394
395
396         namedistr="hd0vB_";
397         namedistr+=i;
398         TH1F *hd0vB = new TH1F(namedistr.Data(), "Impact parameter distribution (vtx w/o these tracks);d0 [cm]",200,-0.1,0.1);
399
400         namedistr="hd0vp0B_";
401         namedistr+=i;
402         TH1F *hd0vp0B = new TH1F(namedistr.Data(), "Impact parameter distribution (prong + ** vtx w/o these tracks);d0 [cm]",200,-0.1,0.1);
403
404         namedistr="hd0vp1B_";
405         namedistr+=i;
406         TH1F *hd0vp1B = new TH1F(namedistr.Data(), "Impact parameter distribution (prong - ** vtx w/o these tracks);d0 [cm]",200,-0.1,0.1);
407
408         namedistr="hd0d0vB_";
409         namedistr+=i;
410         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);
411
412         namedistr="hdeclvB_";
413         namedistr+=i;
414         TH1F *hdeclengthvB = new TH1F(namedistr.Data(), "Decay Length distribution (vtx w/o tracks);Decay Length [cm]",200,0,0.6);
415
416         namedistr="hnormdeclvB_";
417         namedistr+=i;
418         TH1F *hnormdeclengthvB = new TH1F(namedistr.Data(), "Normalized Decay Length distribution (vtx w/o tracks);Decay Length/Err ",200,0,10.);
419
420         fDistr->Add(hd0vB);
421         fDistr->Add(hd0vp0B);
422         fDistr->Add(hd0vp1B);
423         fDistr->Add(hd0vmoresB);
424
425         fDistr->Add(hd0d0vB);
426         fDistr->Add(hd0d0vmoresB);
427
428         fDistr->Add(hdeclengthvB);
429
430         fDistr->Add(hnormdeclengthvB);
431       }
432
433
434     }
435     //histograms of invariant mass distributions
436
437
438     //MC signal
439     if(fReadMC){
440       TH1F* tmpSt = new TH1F(nameSgn.Data(), "D^{0} invariant mass - MC; M [GeV]; Entries",200,1.5648,2.1648);
441
442       TH1F *tmpSl=(TH1F*)tmpSt->Clone();
443       tmpSt->Sumw2();
444       tmpSl->Sumw2();
445
446       //Reflection: histo filled with D0Mass which pass the cut (also) as D0bar and with D0bar which pass (also) the cut as D0
447       TH1F* tmpRt = new TH1F(nameRfl.Data(), "Reflected signal invariant mass - MC; M [GeV]; Entries",200,1.5648,2.1648);
448       //TH1F *tmpRl=(TH1F*)tmpRt->Clone();
449       TH1F* tmpBt = new TH1F(nameBkg.Data(), "Background invariant mass - MC; M [GeV]; Entries",200,1.5648,2.1648);
450       //TH1F *tmpBl=(TH1F*)tmpBt->Clone();
451       tmpBt->Sumw2();
452       //tmpBl->Sumw2();
453       tmpRt->Sumw2();
454       //tmpRl->Sumw2();
455
456       fOutputMass->Add(tmpSt);
457       fOutputMass->Add(tmpRt);
458       fOutputMass->Add(tmpBt);
459
460     }
461
462     //mass
463     TH1F* tmpMt = new TH1F(nameMass.Data(),"D^{0} invariant mass; M [GeV]; Entries",200,1.5648,2.1648);
464     //TH1F *tmpMl=(TH1F*)tmpMt->Clone();
465     tmpMt->Sumw2();
466     //tmpMl->Sumw2();
467     //distribution w/o cuts large range
468     // TH1F* tmpMS = new TH1F(nameMassNocutsS.Data(),"D^{0} invariant mass; M [GeV]; Entries",300,0.7,3.);
469
470     fOutputMass->Add(tmpMt);
471
472     if(fSys==0){ //histograms filled only in pp to save time in PbPb
473       if(fFillVarHists){
474
475         if(fReadMC){
476           //  pT
477           namedistr="hptpiS_";
478           namedistr+=i;
479           TH1F *hptpiS = new TH1F(namedistr.Data(), "P_{T} distribution (pions);p_{T} [GeV/c]",200,0.,8.);
480         
481           namedistr="hptKS_";
482           namedistr+=i;
483           TH1F *hptKS = new TH1F(namedistr.Data(), "P_{T} distribution (kaons);p_{T} [GeV/c]",200,0.,8.);
484
485           //  costhetastar
486           namedistr="hcosthetastarS_";
487           namedistr+=i;
488           TH1F *hcosthetastarS = new TH1F(namedistr.Data(), "cos#theta* distribution;cos#theta*",200,-1.,1.);
489
490           //pT no mass cut
491
492           namedistr="hptpiSnoMcut_";
493           namedistr+=i;
494           TH1F *hptpiSnoMcut = new TH1F(namedistr.Data(), "P_{T} distribution (pions);p_{T} [GeV/c]",200,0.,8.);
495
496           namedistr="hptKSnoMcut_";
497           namedistr+=i;
498           TH1F *hptKSnoMcut = new TH1F(namedistr.Data(), "P_{T} distribution (kaons);p_{T} [GeV/c]",200,0.,8.);
499
500           fDistr->Add(hptpiS);
501           fDistr->Add(hptKS);
502           fDistr->Add(hcosthetastarS);
503
504           fDistr->Add(hptpiSnoMcut);
505           fDistr->Add(hptKSnoMcut);
506
507           //  costhetapoint vs d0 or d0d0
508           namedistr="hcosthpointd0S_";
509           namedistr+=i;
510           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);
511           namedistr="hcosthpointd0d0S_";
512           namedistr+=i;
513           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);
514
515           fDistr->Add(hcosthpointd0S);
516           fDistr->Add(hcosthpointd0d0S);
517
518           //to compare with AliAnalysisTaskCharmFraction
519           TH1F* tmpS27t = new TH1F(nameSgn27.Data(),"D^{0} invariant mass in M(D^{0}) +/- 27 MeV - MC; M [GeV]; Entries",200,1.5648,2.1648);
520           TH1F *tmpS27l=(TH1F*)tmpS27t->Clone();
521           tmpS27t->Sumw2();
522           tmpS27l->Sumw2();
523  
524           fOutputMass->Add(tmpS27t);
525           fOutputMass->Add(tmpS27l);
526
527         }
528
529         //  pT
530         namedistr="hptB_";
531         namedistr+=i;
532         TH1F *hptB = new TH1F(namedistr.Data(), "P_{T} distribution;p_{T} [GeV/c]",200,0.,8.);
533
534         //  costhetastar
535         namedistr="hcosthetastarB_";
536         namedistr+=i;
537         TH1F *hcosthetastarB = new TH1F(namedistr.Data(), "cos#theta* distribution;cos#theta*",200,-1.,1.);
538
539         //pT no mass cut
540         namedistr="hptB1prongnoMcut_";
541         namedistr+=i;
542         TH1F *hptB1pnoMcut = new TH1F(namedistr.Data(), "P_{T} distribution;p_{T} [GeV/c]",200,0.,8.);
543
544         namedistr="hptB2prongsnoMcut_";
545         namedistr+=i;
546         TH1F *hptB2pnoMcut = new TH1F(namedistr.Data(), "P_{T} distribution;p_{T} [GeV/c]",200,0.,8.);
547     
548         fDistr->Add(hptB);
549         fDistr->Add(hcosthetastarB);
550
551         fDistr->Add(hptB1pnoMcut);
552         fDistr->Add(hptB2pnoMcut);
553
554         //impact parameter of negative/positive track
555         namedistr="hd0p0B_";
556         namedistr+=i;
557         TH1F *hd0p0B = new TH1F(namedistr.Data(), "Impact parameter distribution (prong +);d0 [cm]",200,-0.1,0.1);
558
559         namedistr="hd0p1B_";
560         namedistr+=i;
561         TH1F *hd0p1B = new TH1F(namedistr.Data(), "Impact parameter distribution (prong -);d0 [cm]",200,-0.1,0.1);
562
563         //impact parameter corrected for strangeness
564         namedistr="hd0moresB_";
565         namedistr+=i;
566         TH1F *hd0moresB = new TH1F(namedistr.Data(), "Impact parameter distribution (both);d0 [cm]",200,-0.1,0.1);
567
568         namedistr="hd0d0moresB_";
569         namedistr+=i;
570         TH1F *hd0d0moresB = new TH1F(namedistr.Data(), "Impact parameter distribution (prong +);d0 [cm]",200,-0.001,0.001);
571
572     
573         namedistr="hcosthetapointmoresB_";
574         namedistr+=i;
575         TH1F *hcosthetapointmoresB = new TH1F(namedistr.Data(), "cos#theta_{Point} distribution;cos#theta_{Point}",200,0,1.);
576
577         //  costhetapoint vs d0 or d0d0
578         namedistr="hcosthpointd0B_";
579         namedistr+=i;
580         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);
581
582         namedistr="hcosthpointd0d0B_";
583         namedistr+=i;
584         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);
585
586         fDistr->Add(hd0p0B);
587         fDistr->Add(hd0p1B);
588
589         fDistr->Add(hd0moresB);
590         fDistr->Add(hd0d0moresB);
591         fDistr->Add(hcosthetapointmoresB);
592
593
594         fDistr->Add(hcosthpointd0B);
595
596
597         fDistr->Add(hcosthpointd0d0B);
598       }
599
600     } //end pp histo
601   }
602
603
604   //for Like sign analysis
605
606   if(fArray==1){
607     namedistr="hpospair";
608     TH1F* hpospair=new TH1F(namedistr.Data(),"Number of positive pairs",fCuts->GetNPtBins(),-0.5,fCuts->GetNPtBins()-0.5);
609     namedistr="hnegpair";
610     TH1F* hnegpair=new TH1F(namedistr.Data(),"Number of negative pairs",fCuts->GetNPtBins(),-0.5,fCuts->GetNPtBins()-0.5);
611     fOutputMass->Add(hpospair);
612     fOutputMass->Add(hnegpair);
613   }
614
615   const char* nameoutput=GetOutputSlot(3)->GetContainer()->GetName();
616
617   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", 16,-0.5,15.5);
618
619   fNentries->GetXaxis()->SetBinLabel(1,"nEventsAnal");
620   fNentries->GetXaxis()->SetBinLabel(2,"nCandSel(Cuts)");
621   if(fReadMC) fNentries->GetXaxis()->SetBinLabel(3,"nD0Selected");
622   else fNentries->GetXaxis()->SetBinLabel(3,"Dstar<-D0");
623   fNentries->GetXaxis()->SetBinLabel(4,"nEventsGoodVtxS");
624   fNentries->GetXaxis()->SetBinLabel(5,"ptbin = -1");
625   fNentries->GetXaxis()->SetBinLabel(6,"no daughter");
626   if(fSys==0) fNentries->GetXaxis()->SetBinLabel(7,"nCandSel(Tr)");
627   if(fFillVarHists){
628     fNentries->GetXaxis()->SetBinLabel(8,"PID=0");
629     fNentries->GetXaxis()->SetBinLabel(9,"PID=1");
630     fNentries->GetXaxis()->SetBinLabel(10,"PID=2");
631     fNentries->GetXaxis()->SetBinLabel(11,"PID=3");
632   }
633   if(fReadMC && fSys==0){
634     fNentries->GetXaxis()->SetBinLabel(12,"K");
635     fNentries->GetXaxis()->SetBinLabel(13,"Lambda");
636   }
637   fNentries->GetXaxis()->SetBinLabel(14,"Pile-up Rej");
638   fNentries->GetXaxis()->SetBinLabel(15,"N. of 0SMH");
639   if(fSys==1) fNentries->GetXaxis()->SetBinLabel(16,"Nev in centr");
640   fNentries->GetXaxis()->SetNdivisions(1,kFALSE);
641
642   fCounter = new AliNormalizationCounter(Form("%s",GetOutputSlot(5)->GetContainer()->GetName()));
643
644   // Post the data
645   PostData(1,fOutputMass);
646   if(fFillVarHists) PostData(2,fDistr);
647   PostData(3,fNentries);
648   PostData(5,fCounter);  
649   return;
650 }
651
652 //________________________________________________________________________
653 void AliAnalysisTaskSED0Mass::UserExec(Option_t */*option*/)
654 {
655   // Execute analysis for current event:
656   // heavy flavor candidates association to MC truth
657   //cout<<"I'm in UserExec"<<endl;
658
659
660   //cuts order
661   //       printf("    |M-MD0| [GeV]    < %f\n",fD0toKpiCuts[0]);
662   //     printf("    dca    [cm]  < %f\n",fD0toKpiCuts[1]);
663   //     printf("    cosThetaStar     < %f\n",fD0toKpiCuts[2]);
664   //     printf("    pTK     [GeV/c]    > %f\n",fD0toKpiCuts[3]);
665   //     printf("    pTpi    [GeV/c]    > %f\n",fD0toKpiCuts[4]);
666   //     printf("    |d0K|  [cm]  < %f\n",fD0toKpiCuts[5]);
667   //     printf("    |d0pi| [cm]  < %f\n",fD0toKpiCuts[6]);
668   //     printf("    d0d0  [cm^2] < %f\n",fD0toKpiCuts[7]);
669   //     printf("    cosThetaPoint    > %f\n",fD0toKpiCuts[8]);
670   
671
672   AliAODEvent *aod = dynamic_cast<AliAODEvent*> (InputEvent());
673
674   TString bname;
675   if(fArray==0){ //D0 candidates
676     // load D0->Kpi candidates
677     //cout<<"D0 candidates"<<endl;
678     bname="D0toKpi";
679   } else { //LikeSign candidates
680     // load like sign candidates
681     //cout<<"LS candidates"<<endl;
682     bname="LikeSign2Prong";
683   }
684
685   TClonesArray *inputArray=0;
686  
687   if(!aod && AODEvent() && IsStandardAOD()) {
688     // In case there is an AOD handler writing a standard AOD, use the AOD 
689     // event in memory rather than the input (ESD) event.    
690     aod = dynamic_cast<AliAODEvent*> (AODEvent());
691     // in this case the braches in the deltaAOD (AliAOD.VertexingHF.root)
692     // have to taken from the AOD event hold by the AliAODExtension
693     AliAODHandler* aodHandler = (AliAODHandler*) 
694       ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
695
696     if(aodHandler->GetExtensions()) {
697       AliAODExtension *ext = (AliAODExtension*)aodHandler->GetExtensions()->FindObject("AliAOD.VertexingHF.root");
698       AliAODEvent* aodFromExt = ext->GetAOD();
699       inputArray=(TClonesArray*)aodFromExt->GetList()->FindObject(bname.Data());
700     }
701   } else if(aod) {
702     inputArray=(TClonesArray*)aod->GetList()->FindObject(bname.Data());
703   }
704
705
706   if(!inputArray || !aod) {
707     printf("AliAnalysisTaskSED0Mass::UserExec: input branch not found!\n");
708     return;
709   }
710   
711   // fix for temporary bug in ESDfilter
712   // the AODs with null vertex pointer didn't pass the PhysSel
713   if(!aod->GetPrimaryVertex() || TMath::Abs(aod->GetMagneticField())<0.001) return;
714
715
716   TClonesArray *mcArray = 0;
717   AliAODMCHeader *mcHeader = 0;
718
719   if(fReadMC) {
720     // load MC particles
721     mcArray = (TClonesArray*)aod->GetList()->FindObject(AliAODMCParticle::StdBranchName());
722     if(!mcArray) {
723       printf("AliAnalysisTaskSED0Mass::UserExec: MC particles branch not found!\n");
724       return;
725     }
726     
727     // load MC header
728     mcHeader = (AliAODMCHeader*)aod->GetList()->FindObject(AliAODMCHeader::StdBranchName());
729     if(!mcHeader) {
730       printf("AliAnalysisTaskSED0Mass::UserExec: MC header branch not found!\n");
731       return;
732     }
733   }
734   
735   //printf("VERTEX Z %f %f\n",vtx1->GetZ(),mcHeader->GetVtxZ());
736   
737   //histogram filled with 1 for every AOD
738   fNentries->Fill(0);
739   fCounter->StoreEvent(aod,fReadMC); 
740
741   // trigger class for PbPb C0SMH-B-NOPF-ALLNOTRD, C0SMH-B-NOPF-ALL
742   TString trigclass=aod->GetFiredTriggerClasses();
743   if(trigclass.Contains("C0SMH-B-NOPF-ALLNOTRD") || trigclass.Contains("C0SMH-B-NOPF-ALL")) fNentries->Fill(14);
744
745   if(!fCuts->IsEventSelected(aod)) {
746     if(fCuts->GetWhyRejection()==1) // rejected for pileup
747       fNentries->Fill(13);
748     if(fSys==1 && (fCuts->GetWhyRejection()==2 || fCuts->GetWhyRejection()==3)) fNentries->Fill(15);
749     return;
750   }
751   
752   // AOD primary vertex
753   AliAODVertex *vtx1 = (AliAODVertex*)aod->GetPrimaryVertex();
754
755   Bool_t isGoodVtx=kFALSE;
756
757   //vtx1->Print();
758   TString primTitle = vtx1->GetTitle();
759   if(primTitle.Contains("VertexerTracks") && vtx1->GetNContributors()>0) {
760     isGoodVtx=kTRUE;
761     fNentries->Fill(3);
762   }
763
764   // loop over candidates
765   Int_t nInD0toKpi = inputArray->GetEntriesFast();
766   if(fDebug>2) printf("Number of D0->Kpi: %d\n",nInD0toKpi);
767
768   // FILE *f=fopen("4display.txt","a");
769   // fprintf(f,"Number of D0->Kpi: %d\n",nInD0toKpi);
770   Int_t nSelectedloose=0,nSelectedtight=0;  
771   for (Int_t iD0toKpi = 0; iD0toKpi < nInD0toKpi; iD0toKpi++) {
772     AliAODRecoDecayHF2Prong *d = (AliAODRecoDecayHF2Prong*)inputArray->UncheckedAt(iD0toKpi);
773  
774     if(d->GetSelectionMap()) if(!d->HasSelectionBit(AliRDHFCuts::kD0toKpiCuts)){
775         fNentries->Fill(2);     
776         continue; //skip the D0 from Dstar
777       }
778
779     Bool_t unsetvtx=kFALSE;
780     if(!d->GetOwnPrimaryVtx()) {
781       d->SetOwnPrimaryVtx(vtx1); // needed to compute all variables
782       unsetvtx=kTRUE;
783     }
784   
785     
786     if ( fCuts->IsInFiducialAcceptance(d->Pt(),d->Y(421)) ) {
787       nSelectedloose++;
788       nSelectedtight++;      
789       if(fSys==0){
790         if(fCuts->IsSelected(d,AliRDHFCuts::kTracks,aod))fNentries->Fill(6);       
791       }
792       Int_t ptbin=fCuts->PtBin(d->Pt());
793       if(ptbin==-1) {fNentries->Fill(4); continue;} //out of bounds
794       fIsSelectedCandidate=fCuts->IsSelected(d,AliRDHFCuts::kCandidate,aod); //selected
795       if(fFillVarHists) {
796         //if(!fCutOnDistr || (fCutOnDistr && fIsSelectedCandidate)) {
797         fDaughterTracks.AddAt((AliAODTrack*)d->GetDaughter(0),0);
798         fDaughterTracks.AddAt((AliAODTrack*)d->GetDaughter(1),1);
799         //check daughters
800         if(!fDaughterTracks.UncheckedAt(0) || !fDaughterTracks.UncheckedAt(1)) {
801           AliDebug(1,"at least one daughter not found!");
802           fNentries->Fill(5);
803           fDaughterTracks.Clear();
804           continue;
805         }
806         //}
807         FillVarHists(aod,d,mcArray,fCuts,fDistr);
808       }
809
810       FillMassHists(d,mcArray,fCuts,fOutputMass);
811     }
812   
813     fDaughterTracks.Clear();
814     if(unsetvtx) d->UnsetOwnPrimaryVtx();
815   } //end for prongs
816   fCounter->StoreCandidates(aod,nSelectedloose,kTRUE);  
817   fCounter->StoreCandidates(aod,nSelectedtight,kFALSE);  
818   // Post the data
819   PostData(1,fOutputMass);
820   if(fFillVarHists) PostData(2,fDistr);
821   PostData(3,fNentries);
822   PostData(5,fCounter);
823   return;
824 }
825
826 //____________________________________________________________________________
827 void AliAnalysisTaskSED0Mass::FillVarHists(AliAODEvent* aod,AliAODRecoDecayHF2Prong *part, TClonesArray *arrMC, AliRDHFCutsD0toKpi *cuts, TList *listout){
828   //
829   // function used in UserExec to fill variable histograms:
830   //
831
832
833   Int_t pdgDgD0toKpi[2]={321,211};
834   Int_t lab=-9999;
835   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)
836   //Double_t pt = d->Pt(); //mother pt
837   Int_t isSelectedPID=3;
838   if(!fReadMC || (fReadMC && fUsePid4Distr)) isSelectedPID=cuts->IsSelectedPID(part); //0 rejected,1 D0,2 Dobar, 3 both
839   if (isSelectedPID==0)fNentries->Fill(7);
840   if (isSelectedPID==1)fNentries->Fill(8);
841   if (isSelectedPID==2)fNentries->Fill(9);
842   if (isSelectedPID==3)fNentries->Fill(10);
843   //fNentries->Fill(8+isSelectedPID);
844
845   if(fCutOnDistr && !fIsSelectedCandidate) return; 
846   //printf("\nif no cuts or cuts passed\n");
847
848
849   //add distr here
850   UInt_t pdgs[2];
851     
852   Double_t mPDG=TDatabasePDG::Instance()->GetParticle(421)->Mass();
853   pdgs[0]=211;
854   pdgs[1]=321;
855   Double_t minvD0 = part->InvMassD0();
856   pdgs[1]=211;
857   pdgs[0]=321;
858   Double_t minvD0bar = part->InvMassD0bar();
859   //cout<<"inside mass cut"<<endl;
860
861   Double_t invmasscut=0.03;
862
863   TString fillthispi="",fillthisK="",fillthis="";
864
865   Int_t ptbin=cuts->PtBin(part->Pt());
866
867   Double_t dz1[2],dz2[2],covar1[3],covar2[3];//,d0xd0proper,errd0xd0proper;
868   dz1[0]=-99; dz2[0]=-99;
869   Double_t d0[2];
870   Double_t decl[2]={-99,-99};
871   Bool_t recalcvtx=kFALSE;
872
873
874
875   if(fCuts->GetIsPrimaryWithoutDaughters()){
876     recalcvtx=kTRUE;
877     //recalculate vertex
878     AliAODVertex *vtxProp=0x0;
879     vtxProp=GetPrimaryVtxSkipped(aod);
880     if(vtxProp) {
881       part->SetOwnPrimaryVtx(vtxProp);
882       //Bool_t unsetvtx=kTRUE;
883       //Calculate d0 for daughter tracks with Vtx Skipped
884       AliESDtrack *esdtrack1=new AliESDtrack((AliVTrack*)fDaughterTracks.UncheckedAt(0));
885       AliESDtrack *esdtrack2=new AliESDtrack((AliVTrack*)fDaughterTracks.UncheckedAt(1));
886       esdtrack1->PropagateToDCA(vtxProp,aod->GetMagneticField(),1.,dz1,covar1);
887       esdtrack2->PropagateToDCA(vtxProp,aod->GetMagneticField(),1.,dz2,covar2);
888       delete vtxProp; vtxProp=NULL;
889       delete esdtrack1;
890       delete esdtrack2;
891     }
892
893     d0[0]=dz1[0];
894     d0[1]=dz2[0];
895
896     decl[0]=part->DecayLength2();
897     decl[1]=part->NormalizedDecayLength2();
898     part->UnsetOwnPrimaryVtx();
899   
900   }
901
902   Double_t cosThetaStarD0 = 99;
903   Double_t cosThetaStarD0bar = 99;
904   Double_t cosPointingAngle = 99;
905   Double_t normalizedDecayLength2 = -1, normalizedDecayLengthxy=-1;
906   Double_t decayLength2 = -1, decayLengthxy=-1;
907   Double_t ptProng[2]={-99,-99};
908   Double_t d0Prong[2]={-99,-99};
909   
910
911   //disable the PID
912   if(!fUsePid4Distr) isSelectedPID=0;
913   if((lab>=0 && fReadMC) || (!fReadMC && isSelectedPID)){ //signal (from MC or PID)
914    
915     //check pdg of the prongs
916     AliAODTrack *prong0=(AliAODTrack*)fDaughterTracks.UncheckedAt(0);
917     AliAODTrack *prong1=(AliAODTrack*)fDaughterTracks.UncheckedAt(1);
918
919     if(!prong0 || !prong1) {
920       return;
921     }
922     Int_t labprong[2];
923     if(fReadMC){
924       labprong[0]=prong0->GetLabel();
925       labprong[1]=prong1->GetLabel();
926     }
927     AliAODMCParticle *mcprong=0;
928     Int_t pdgProng[2]={0,0};
929
930     for (Int_t iprong=0;iprong<2;iprong++){
931       if(fReadMC && labprong[iprong]>=0) {
932         mcprong= (AliAODMCParticle*)arrMC->At(labprong[iprong]);
933         pdgProng[iprong]=mcprong->GetPdgCode();
934       }
935     }
936     
937     if(fSys==0){
938       //no mass cut ditributions: ptbis
939         
940       fillthispi="hptpiSnoMcut_";
941       fillthispi+=ptbin;
942
943       fillthisK="hptKSnoMcut_";
944       fillthisK+=ptbin;
945
946       if ((TMath::Abs(pdgProng[0]) == 211 && TMath::Abs(pdgProng[1]) == 321)
947           || (isSelectedPID==1 || isSelectedPID==3)){
948         ((TH1F*)listout->FindObject(fillthispi))->Fill(prong0->Pt());
949         ((TH1F*)listout->FindObject(fillthisK))->Fill(prong1->Pt());
950       }
951
952       if ((TMath::Abs(pdgProng[0]) == 321 && TMath::Abs(pdgProng[1]) == 211)
953           || (isSelectedPID==2 || isSelectedPID==3)){
954         ((TH1F*)listout->FindObject(fillthisK))->Fill(prong0->Pt());
955         ((TH1F*)listout->FindObject(fillthispi))->Fill(prong1->Pt());
956       }
957     }
958
959     //no mass cut ditributions: mass
960     fillthis="hMassS_";
961     fillthis+=ptbin;
962       
963     if ((fReadMC && ((AliAODMCParticle*)arrMC->At(lab))->GetPdgCode() == 421)
964         || (!fReadMC && (isSelectedPID==1 || isSelectedPID==3))){//D0
965       ((TH1F*)listout->FindObject(fillthis))->Fill(minvD0);
966     }
967     else { //D0bar
968       if(fReadMC || (!fReadMC && isSelectedPID > 1))
969         ((TH1F*)listout->FindObject(fillthis))->Fill(minvD0bar);
970     }
971
972     //apply cut on invariant mass on the pair
973     if(TMath::Abs(minvD0-mPDG)<invmasscut || TMath::Abs(minvD0bar-mPDG)<invmasscut){
974
975       cosThetaStarD0 = part->CosThetaStarD0();
976       cosThetaStarD0bar = part->CosThetaStarD0bar();
977       cosPointingAngle = part->CosPointingAngle();
978       normalizedDecayLength2 = part->NormalizedDecayLength2();
979       decayLength2 = part->DecayLength2();
980       decayLengthxy = part->DecayLengthXY();
981       normalizedDecayLengthxy=decayLengthxy/part->DecayLengthXYError();
982
983       ptProng[0]=prong0->Pt(); ptProng[1]=prong1->Pt();
984       d0Prong[0]=part->Getd0Prong(0); d0Prong[1]=part->Getd0Prong(1);
985
986       if(fArray==1) cout<<"LS signal: ERROR"<<endl;
987       for (Int_t iprong=0; iprong<2; iprong++){
988         AliAODTrack *prong=(AliAODTrack*)fDaughterTracks.UncheckedAt(iprong);
989         if (fReadMC) labprong[iprong]=prong->GetLabel();
990           
991         //cout<<"prong name = "<<prong->GetName()<<" label = "<<prong->GetLabel()<<endl;
992         Int_t pdgprong=0;
993         if(fReadMC && labprong[iprong]>=0) {
994           mcprong= (AliAODMCParticle*)arrMC->At(labprong[iprong]);
995           pdgprong=mcprong->GetPdgCode();
996         }
997
998         Bool_t isPionHere[2]={(isSelectedPID==1 || isSelectedPID==3) ? kTRUE : kFALSE,(isSelectedPID==2 || isSelectedPID==3) ? kTRUE : kFALSE};
999
1000         if(TMath::Abs(pdgprong)==211 || isPionHere[iprong]) {
1001           //cout<<"pi"<<endl;
1002            
1003           if(fSys==0){ 
1004             fillthispi="hptpiS_";
1005             fillthispi+=ptbin;
1006             ((TH1F*)listout->FindObject(fillthispi))->Fill(ptProng[iprong]);
1007           }
1008           fillthispi="hd0piS_";
1009           fillthispi+=ptbin;
1010           ((TH1F*)listout->FindObject(fillthispi))->Fill(d0Prong[iprong]);
1011           if(recalcvtx) {
1012
1013             fillthispi="hd0vpiS_";
1014             fillthispi+=ptbin;
1015             ((TH1F*)listout->FindObject(fillthispi))->Fill(d0[iprong]);
1016           }
1017
1018         }
1019           
1020         if(TMath::Abs(pdgprong)==321 || !isPionHere[iprong]) {
1021           //cout<<"kappa"<<endl;
1022           if(fSys==0){
1023             fillthisK="hptKS_";
1024             fillthisK+=ptbin;
1025             ((TH1F*)listout->FindObject(fillthisK))->Fill(ptProng[iprong]);
1026           }
1027           fillthisK="hd0KS_";
1028           fillthisK+=ptbin;
1029           ((TH1F*)listout->FindObject(fillthisK))->Fill(d0Prong[iprong]);
1030           if (recalcvtx){
1031             fillthisK="hd0vKS_";
1032             fillthisK+=ptbin;
1033             ((TH1F*)listout->FindObject(fillthisK))->Fill(d0[iprong]);
1034           }
1035         }
1036
1037         if(fSys==0){
1038           fillthis="hcosthpointd0S_";
1039           fillthis+=ptbin;        
1040           ((TH1F*)listout->FindObject(fillthis))->Fill(cosPointingAngle,d0Prong[iprong]);
1041         }
1042       } //end loop on prongs
1043
1044       fillthis="hdcaS_";
1045       fillthis+=ptbin;    
1046       ((TH1F*)listout->FindObject(fillthis))->Fill(part->GetDCA());
1047
1048       fillthis="hcosthetapointS_";
1049       fillthis+=ptbin;    
1050       ((TH1F*)listout->FindObject(fillthis))->Fill(cosPointingAngle);
1051
1052       fillthis="hcosthetapointxyS_";
1053       fillthis+=ptbin;    
1054       ((TH1F*)listout->FindObject(fillthis))->Fill(part->CosPointingAngleXY());
1055
1056
1057       fillthis="hd0d0S_";
1058       fillthis+=ptbin;
1059       ((TH1F*)listout->FindObject(fillthis))->Fill(part->Prodd0d0());
1060
1061       fillthis="hdeclS_";
1062       fillthis+=ptbin;
1063       ((TH1F*)listout->FindObject(fillthis))->Fill(decayLength2);
1064
1065       fillthis="hnormdeclS_";
1066       fillthis+=ptbin;
1067       ((TH1F*)listout->FindObject(fillthis))->Fill(normalizedDecayLength2);
1068
1069       fillthis="hdeclxyS_";
1070       fillthis+=ptbin;
1071       ((TH1F*)listout->FindObject(fillthis))->Fill(decayLengthxy);
1072
1073       fillthis="hnormdeclxyS_";
1074       fillthis+=ptbin;
1075       ((TH1F*)listout->FindObject(fillthis))->Fill(normalizedDecayLengthxy);
1076
1077       fillthis="hdeclxyd0d0S_";
1078       fillthis+=ptbin;
1079       ((TH2F*)listout->FindObject(fillthis))->Fill(decayLengthxy,d0Prong[0]*d0Prong[1]);
1080
1081       fillthis="hnormdeclxyd0d0S_";
1082       fillthis+=ptbin;
1083       ((TH2F*)listout->FindObject(fillthis))->Fill(normalizedDecayLengthxy,d0Prong[0]*d0Prong[1]);
1084
1085       if(recalcvtx) {
1086         fillthis="hdeclvS_";
1087         fillthis+=ptbin;
1088         ((TH1F*)listout->FindObject(fillthis))->Fill(decl[0]);
1089
1090         fillthis="hnormdeclvS_";
1091         fillthis+=ptbin;
1092         ((TH1F*)listout->FindObject(fillthis))->Fill(decl[1]);
1093
1094         fillthis="hd0d0vS_";
1095         fillthis+=ptbin;
1096         ((TH1F*)listout->FindObject(fillthis))->Fill(d0[0]*d0[1]);
1097       }
1098
1099       if(fSys==0){
1100         fillthis="hcosthetastarS_";
1101         fillthis+=ptbin;
1102         if ((fReadMC && ((AliAODMCParticle*)arrMC->At(lab))->GetPdgCode() == 421)) ((TH1F*)listout->FindObject(fillthis))->Fill(cosThetaStarD0);
1103         else {
1104           if (fReadMC || isSelectedPID>1)((TH1F*)listout->FindObject(fillthis))->Fill(cosThetaStarD0bar);
1105           if(isSelectedPID==1 || isSelectedPID==3)((TH1F*)listout->FindObject(fillthis))->Fill(cosThetaStarD0);
1106         }
1107
1108         fillthis="hcosthpointd0d0S_";
1109         fillthis+=ptbin;          
1110         ((TH2F*)listout->FindObject(fillthis))->Fill(cosPointingAngle,part->Prodd0d0());
1111       }
1112
1113     } //end mass cut
1114     
1115   } else{ //Background or LS
1116     //if(!fReadMC){
1117     //cout<<"is background"<<endl;
1118      
1119     //no mass cut distributions: mass, ptbis
1120     fillthis="hMassB_";
1121     fillthis+=ptbin;
1122
1123     if (!fCutOnDistr || (fCutOnDistr && (fIsSelectedCandidate==1 || fIsSelectedCandidate==3))) ((TH1F*)listout->FindObject(fillthis))->Fill(minvD0);
1124     if (!fCutOnDistr || (fCutOnDistr && fIsSelectedCandidate>1)) ((TH1F*)listout->FindObject(fillthis))->Fill(minvD0bar);
1125     if(fSys==0){
1126       fillthis="hptB1prongnoMcut_";
1127       fillthis+=ptbin;
1128       
1129       ((TH1F*)listout->FindObject(fillthis))->Fill(((AliAODTrack*)fDaughterTracks.UncheckedAt(0))->Pt());
1130       
1131       fillthis="hptB2prongsnoMcut_";
1132       fillthis+=ptbin;
1133       ((TH1F*)listout->FindObject(fillthis))->Fill(((AliAODTrack*)fDaughterTracks.UncheckedAt(0))->Pt());
1134       ((TH1F*)listout->FindObject(fillthis))->Fill(((AliAODTrack*)fDaughterTracks.UncheckedAt(0))->Pt());
1135     }
1136     //apply cut on invariant mass on the pair
1137     if(TMath::Abs(minvD0-mPDG)<invmasscut || TMath::Abs(minvD0bar-mPDG)<invmasscut){
1138       if(fSys==0){
1139         ptProng[0]=((AliAODTrack*)fDaughterTracks.UncheckedAt(0))->Pt(); ptProng[1]=((AliAODTrack*)fDaughterTracks.UncheckedAt(0))->Pt();
1140         cosThetaStarD0 = part->CosThetaStarD0();
1141         cosThetaStarD0bar = part->CosThetaStarD0bar();
1142       }
1143
1144       cosPointingAngle = part->CosPointingAngle();
1145       normalizedDecayLength2 = part->NormalizedDecayLength2();
1146       decayLength2 = part->DecayLength2();
1147       decayLengthxy = part->DecayLengthXY();
1148       normalizedDecayLengthxy=decayLengthxy/part->DecayLengthXYError();
1149       d0Prong[0]=part->Getd0Prong(0); d0Prong[1]=part->Getd0Prong(1);
1150
1151
1152       AliAODTrack *prongg=(AliAODTrack*)fDaughterTracks.UncheckedAt(0);
1153       if(!prongg) {
1154         if(fDebug>2) cout<<"No daughter found";
1155         return;
1156       }
1157       else{
1158         if(fArray==1){
1159           if(prongg->Charge()==1) {
1160             //fTotPosPairs[ptbin]++;
1161             ((TH1F*)fDistr->FindObject("hpospair"))->Fill(ptbin);
1162           } else {
1163             //fTotNegPairs[ptbin]++;
1164             ((TH1F*)fDistr->FindObject("hnegpair"))->Fill(ptbin);
1165           }
1166         }
1167       }
1168         
1169       fillthis="hd0B_";
1170       fillthis+=ptbin;
1171       ((TH1F*)listout->FindObject(fillthis))->Fill(d0Prong[0]);
1172       ((TH1F*)listout->FindObject(fillthis))->Fill(d0Prong[1]);
1173
1174       if(fReadMC){
1175         Int_t pdgMother[2]={0,0};
1176         Double_t factor[2]={1,1};
1177
1178         for(Int_t iprong=0;iprong<2;iprong++){
1179           AliAODTrack *prong=(AliAODTrack*)fDaughterTracks.UncheckedAt(iprong);
1180           lab=prong->GetLabel();
1181           if(lab>=0){
1182             AliAODMCParticle* mcprong=(AliAODMCParticle*)arrMC->At(lab);
1183             if(mcprong){
1184               Int_t labmom=mcprong->GetMother();
1185               if(labmom>=0){
1186                 AliAODMCParticle* mcmother=(AliAODMCParticle*)arrMC->At(labmom);
1187                 if(mcmother) pdgMother[iprong]=mcmother->GetPdgCode();
1188               }
1189             }
1190           }
1191
1192           if(fSys==0){
1193
1194             fillthis="hd0moresB_";
1195             fillthis+=ptbin;
1196           
1197             if(TMath::Abs(pdgMother[iprong])==310 || TMath::Abs(pdgMother[iprong])==130 || TMath::Abs(pdgMother[iprong])==321){ //K^0_S, K^0_L, K^+-
1198               if(ptProng[iprong]<=1)factor[iprong]=1./.7;
1199               else factor[iprong]=1./.6;
1200               fNentries->Fill(11);
1201             }
1202             
1203             if(TMath::Abs(pdgMother[iprong])==3122) { //Lambda
1204               factor[iprong]=1./0.25;
1205               fNentries->Fill(12);
1206             }
1207             fillthis="hd0moresB_";
1208             fillthis+=ptbin;
1209
1210             ((TH1F*)listout->FindObject(fillthis))->Fill(d0Prong[iprong],factor[iprong]);
1211
1212             if(recalcvtx){
1213               fillthis="hd0vmoresB_";
1214               fillthis+=ptbin;
1215               ((TH1F*)listout->FindObject(fillthis))->Fill(d0[iprong],factor[iprong]);
1216             }
1217           }
1218         } //loop on prongs
1219
1220         if(fSys==0){
1221           fillthis="hd0d0moresB_";
1222           fillthis+=ptbin;
1223           ((TH1F*)listout->FindObject(fillthis))->Fill(part->Prodd0d0(),factor[0]*factor[1]);
1224
1225           fillthis="hcosthetapointmoresB_";
1226           fillthis+=ptbin;
1227           ((TH1F*)listout->FindObject(fillthis))->Fill(cosPointingAngle,factor[0]*factor[1]);
1228
1229           if(recalcvtx){
1230             fillthis="hd0d0vmoresB_";
1231             fillthis+=ptbin;
1232             ((TH1F*)listout->FindObject(fillthis))->Fill(d0[0]*d0[1],factor[0]*factor[1]);
1233           }
1234         }
1235       } //readMC
1236
1237       if(fSys==0){          
1238         //normalise pt distr to half afterwards
1239         fillthis="hptB_";
1240         fillthis+=ptbin;
1241         ((TH1F*)listout->FindObject(fillthis))->Fill(ptProng[0]);
1242         ((TH1F*)listout->FindObject(fillthis))->Fill(ptProng[1]);
1243
1244         fillthis="hcosthetastarB_";
1245         fillthis+=ptbin;
1246         if (!fCutOnDistr || (fCutOnDistr && (fIsSelectedCandidate==1 || fIsSelectedCandidate==3)))((TH1F*)listout->FindObject(fillthis))->Fill(cosThetaStarD0);
1247         if (!fCutOnDistr || (fCutOnDistr && fIsSelectedCandidate>1))((TH1F*)listout->FindObject(fillthis))->Fill(cosThetaStarD0bar);    
1248
1249
1250         fillthis="hd0p0B_";
1251         fillthis+=ptbin;
1252         ((TH1F*)listout->FindObject(fillthis))->Fill(d0Prong[0]);
1253         fillthis="hd0p1B_";
1254         fillthis+=ptbin;
1255         ((TH1F*)listout->FindObject(fillthis))->Fill(d0Prong[1]);
1256         
1257         fillthis="hcosthpointd0d0B_";
1258         fillthis+=ptbin;
1259         ((TH2F*)listout->FindObject(fillthis))->Fill(cosPointingAngle,part->Prodd0d0());
1260         
1261         fillthis="hcosthpointd0B_";
1262         fillthis+=ptbin;          
1263         ((TH1F*)listout->FindObject(fillthis))->Fill(cosPointingAngle,d0Prong[0]);
1264         ((TH1F*)listout->FindObject(fillthis))->Fill(cosPointingAngle,d0Prong[1]);
1265           
1266
1267         if(recalcvtx){
1268
1269           fillthis="hd0vp0B_";
1270           fillthis+=ptbin;
1271           ((TH1F*)listout->FindObject(fillthis))->Fill(d0[0]);
1272           fillthis="hd0vp1B_";
1273           fillthis+=ptbin;
1274           ((TH1F*)listout->FindObject(fillthis))->Fill(d0[1]);
1275           
1276           fillthis="hd0vB_";
1277           fillthis+=ptbin;
1278           ((TH1F*)listout->FindObject(fillthis))->Fill(d0[0]);
1279           ((TH1F*)listout->FindObject(fillthis))->Fill(d0[1]);
1280
1281         }
1282
1283       }  
1284
1285       fillthis="hdcaB_";
1286       fillthis+=ptbin;
1287       ((TH1F*)listout->FindObject(fillthis))->Fill(part->GetDCA());
1288
1289       fillthis="hd0d0B_";
1290       fillthis+=ptbin;
1291       ((TH1F*)listout->FindObject(fillthis))->Fill(d0Prong[0]*d0Prong[1]);
1292
1293       if(recalcvtx){
1294         fillthis="hd0d0vB_";
1295         fillthis+=ptbin;
1296         ((TH1F*)listout->FindObject(fillthis))->Fill(d0[0]*d0[1]);
1297       }
1298
1299       fillthis="hcosthetapointB_";
1300       fillthis+=ptbin;
1301       ((TH1F*)listout->FindObject(fillthis))->Fill(cosPointingAngle);
1302
1303       fillthis="hcosthetapointxyB_";
1304       fillthis+=ptbin;    
1305       ((TH1F*)listout->FindObject(fillthis))->Fill(part->CosPointingAngleXY());
1306
1307       fillthis="hdeclB_";
1308       fillthis+=ptbin;
1309       ((TH1F*)listout->FindObject(fillthis))->Fill(decayLength2);
1310
1311       fillthis="hnormdeclB_";
1312       fillthis+=ptbin;
1313       ((TH1F*)listout->FindObject(fillthis))->Fill(normalizedDecayLength2);
1314
1315       fillthis="hdeclxyB_";
1316       fillthis+=ptbin;
1317       ((TH1F*)listout->FindObject(fillthis))->Fill(decayLengthxy);
1318
1319       fillthis="hnormdeclxyB_";
1320       fillthis+=ptbin;
1321       ((TH1F*)listout->FindObject(fillthis))->Fill(normalizedDecayLengthxy);
1322
1323       fillthis="hdeclxyd0d0B_";
1324       fillthis+=ptbin;
1325       ((TH2F*)listout->FindObject(fillthis))->Fill(decayLengthxy,d0Prong[0]*d0Prong[1]);
1326
1327       fillthis="hnormdeclxyd0d0B_";
1328       fillthis+=ptbin;
1329       ((TH2F*)listout->FindObject(fillthis))->Fill(normalizedDecayLengthxy,d0Prong[0]*d0Prong[1]);      
1330
1331       if(recalcvtx) {
1332
1333         fillthis="hdeclvB_";
1334         fillthis+=ptbin;
1335         ((TH1F*)listout->FindObject(fillthis))->Fill(decl[0]);
1336
1337         fillthis="hnormdeclvB_";
1338         fillthis+=ptbin;
1339         ((TH1F*)listout->FindObject(fillthis))->Fill(decl[1]);
1340
1341
1342       }
1343     }//mass cut 
1344   }//else (background)
1345   
1346   return;
1347 }
1348 //____________________________________________________________________________
1349
1350 void AliAnalysisTaskSED0Mass::FillMassHists(AliAODRecoDecayHF2Prong *part, TClonesArray *arrMC, AliRDHFCutsD0toKpi* cuts, TList *listout){
1351   //
1352   // function used in UserExec to fill mass histograms:
1353   //
1354
1355
1356   Double_t mPDG=TDatabasePDG::Instance()->GetParticle(421)->Mass();
1357
1358   //cout<<"is selected = "<<fIsSelectedCandidate<<endl;
1359
1360   //cout<<"check cuts = "<<endl;
1361   //cuts->PrintAll();
1362   if (!fIsSelectedCandidate){
1363     //cout<<"Not Selected"<<endl;
1364     //cout<<"Rejected because "<<cuts->GetWhy()<<endl;
1365     return;
1366   }
1367
1368
1369   if(fDebug>2)  cout<<"Candidate selected"<<endl;
1370
1371   Double_t invmassD0 = part->InvMassD0(), invmassD0bar = part->InvMassD0bar();
1372   //printf("SELECTED\n");
1373   Int_t ptbin=cuts->PtBin(part->Pt());
1374
1375   // AliAODTrack *prong=(AliAODTrack*)fDaughterTracks.UncheckedAt(0);
1376   // if(!prong) {
1377   //   AliDebug(2,"No daughter found");
1378   //   return;
1379   // }
1380   // else{
1381     // if(prong->Charge()==1) {
1382     //   ((TH1F*)fDistr->FindObject("hpospair"))->Fill(fCuts->GetNPtBins()+ptbin);
1383     //   //fTotPosPairs[ptbin]++;
1384     // } else {
1385     //   ((TH1F*)fDistr->FindObject("hnegpair"))->Fill(fCuts->GetNPtBins()+ptbin);
1386     //   //fTotNegPairs[ptbin]++;
1387     // }
1388   //  }
1389  
1390   // for(Int_t it=0;it<2;it++){
1391  
1392   //    //request on spd points to be addes
1393   //   if(/*nSPD==2 && */part->Pt() > 5. && (TMath::Abs(invmassD0-mPDG)<0.01 || TMath::Abs(invmassD0bar-mPDG)<0.01)){
1394   //     FILE *f=fopen("4display.txt","a");
1395   //     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());
1396   //     fclose(f);
1397   //     //printf("PrimVtx NContributors: %d \n Prongs Rel Angle: %f \n \n",ncont,relangle);
1398   //   }
1399   // }
1400  
1401   TString fillthis="";
1402   Int_t pdgDgD0toKpi[2]={321,211};
1403   Int_t labD0=-1;
1404   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)
1405
1406   //count candidates selected by cuts
1407   fNentries->Fill(1);
1408   //count true D0 selected by cuts
1409   if (fReadMC && labD0>=0) fNentries->Fill(2);
1410
1411   if ((fIsSelectedCandidate==1 || fIsSelectedCandidate==3) && fFillOnlyD0D0bar<2) { //D0
1412     if(fReadMC){
1413       if(labD0>=0) {
1414         if(fArray==1) cout<<"LS signal ERROR"<<endl;
1415
1416         AliAODMCParticle *partD0 = (AliAODMCParticle*)arrMC->At(labD0);
1417         Int_t pdgD0 = partD0->GetPdgCode();
1418         //cout<<"pdg = "<<pdgD0<<endl;
1419         if (pdgD0==421){ //D0
1420           //cout<<"Fill S with D0"<<endl;
1421           fillthis="histSgn_";
1422           fillthis+=ptbin;
1423           ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0);
1424           if(fSys==0){
1425             if(TMath::Abs(invmassD0 - mPDG) < 0.027){
1426               fillthis="histSgn27_";
1427               fillthis+=ptbin;
1428               ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0);
1429             }
1430           }
1431         } else{ //it was a D0bar
1432           fillthis="histRfl_";
1433           fillthis+=ptbin;
1434           ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0);
1435         }
1436       } else {//background
1437         fillthis="histBkg_";
1438         fillthis+=ptbin;
1439         ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0);
1440       }
1441
1442     }else{
1443       fillthis="histMass_";
1444       fillthis+=ptbin;
1445       //cout<<"Filling "<<fillthis<<endl;
1446
1447       //printf("Fill mass with D0");
1448       ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0);
1449     }
1450      
1451   }
1452   if (fIsSelectedCandidate>1 && (fFillOnlyD0D0bar==0 || fFillOnlyD0D0bar==2)) { //D0bar
1453     if(fReadMC){
1454       if(labD0>=0) {
1455         if(fArray==1) cout<<"LS signal ERROR"<<endl;
1456         AliAODMCParticle *partD0 = (AliAODMCParticle*)arrMC->At(labD0);
1457         Int_t pdgD0 = partD0->GetPdgCode();
1458         //cout<<" pdg = "<<pdgD0<<endl;
1459         if (pdgD0==-421){ //D0bar
1460           fillthis="histSgn_";
1461           fillthis+=ptbin;
1462           ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0bar);
1463           // if (TMath::Abs(invmassD0bar - mPDG) < 0.027){
1464           //   fillthis="histSgn27_";
1465           //   fillthis+=ptbin;
1466           //   ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0bar);
1467           // }
1468
1469           
1470         } else{
1471           fillthis="histRfl_";
1472           fillthis+=ptbin;
1473           ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0bar);
1474         }
1475       } else {//background or LS
1476         fillthis="histBkg_";
1477         fillthis+=ptbin;
1478         ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0bar);
1479       }
1480     }else{
1481       fillthis="histMass_";
1482       fillthis+=ptbin;
1483       //printf("Fill mass with D0bar");
1484       ((TH1F*)listout->FindObject(fillthis))->Fill(invmassD0bar);
1485
1486     }
1487   }
1488
1489   return;
1490 }
1491
1492 //__________________________________________________________________________
1493 AliAODVertex* AliAnalysisTaskSED0Mass::GetPrimaryVtxSkipped(AliAODEvent *aodev){
1494   //Calculate the primary vertex w/o the daughter tracks of the candidate
1495   
1496   Int_t skipped[2];
1497   Int_t nTrksToSkip=2;
1498   AliAODTrack *dgTrack = (AliAODTrack*)fDaughterTracks.UncheckedAt(0);
1499   if(!dgTrack){
1500     AliDebug(2,"no daughter found!");
1501     return 0x0;
1502   }
1503   skipped[0]=dgTrack->GetID();
1504   dgTrack = (AliAODTrack*)fDaughterTracks.UncheckedAt(1);
1505   if(!dgTrack){
1506     AliDebug(2,"no daughter found!");
1507     return 0x0;
1508   }
1509   skipped[1]=dgTrack->GetID();
1510
1511   AliESDVertex *vertexESD=0x0;
1512   AliAODVertex *vertexAOD=0x0;
1513   AliVertexerTracks *vertexer = new AliVertexerTracks(aodev->GetMagneticField());
1514   
1515   //
1516   vertexer->SetSkipTracks(nTrksToSkip,skipped);
1517   vertexer->SetMinClusters(4);  
1518   vertexESD = (AliESDVertex*)vertexer->FindPrimaryVertex(aodev); 
1519   if(!vertexESD) return vertexAOD;
1520   if(vertexESD->GetNContributors()<=0) { 
1521     AliDebug(2,"vertexing failed"); 
1522     delete vertexESD; vertexESD=NULL;
1523     return vertexAOD;
1524   }
1525   
1526   delete vertexer; vertexer=NULL;
1527   
1528   
1529   // convert to AliAODVertex
1530   Double_t pos[3],cov[6],chi2perNDF;
1531   vertexESD->GetXYZ(pos); // position
1532   vertexESD->GetCovMatrix(cov); //covariance matrix
1533   chi2perNDF = vertexESD->GetChi2toNDF();
1534   delete vertexESD; vertexESD=NULL;
1535   
1536   vertexAOD = new AliAODVertex(pos,cov,chi2perNDF);
1537   return vertexAOD;
1538   
1539 }
1540
1541
1542 //________________________________________________________________________
1543 void AliAnalysisTaskSED0Mass::Terminate(Option_t */*option*/)
1544 {
1545   // Terminate analysis
1546   //
1547   if(fDebug > 1) printf("AnalysisTaskSED0Mass: Terminate() \n");
1548
1549
1550   fOutputMass = dynamic_cast<TList*> (GetOutputData(1));
1551   if (!fOutputMass) {     
1552     printf("ERROR: fOutputMass not available\n");
1553     return;
1554   }
1555   if(fFillVarHists){
1556     fDistr = dynamic_cast<TList*> (GetOutputData(2));
1557     if (!fDistr) {
1558       printf("ERROR: fDistr not available\n");
1559       return;
1560     }
1561   }
1562
1563   fNentries = dynamic_cast<TH1F*>(GetOutputData(3));
1564   
1565   if(!fNentries){
1566     printf("ERROR: fNEntries not available\n");
1567     return;
1568   }
1569   fCuts = dynamic_cast<AliRDHFCutsD0toKpi*>(GetOutputData(4));
1570   if(!fCuts){
1571     printf("ERROR: fCuts not available\n");
1572     return;
1573   }
1574   fCounter = dynamic_cast<AliNormalizationCounter*>(GetOutputData(5));    
1575   if (!fCounter) {
1576     printf("ERROR: fCounter not available\n");
1577     return;
1578   }
1579   Int_t nptbins=fCuts->GetNPtBins();
1580   for(Int_t ipt=0;ipt<nptbins;ipt++){ 
1581
1582     if(fArray==1 && fFillVarHists){ 
1583       fLsNormalization = 2.*TMath::Sqrt(((TH1F*)fDistr->FindObject("hpospair"))->Integral(nptbins+ipt+1,nptbins+ipt+2)*((TH1F*)fDistr->FindObject("hnegpair"))->Integral(nptbins+ipt+1,nptbins+ipt+2)); //after cuts
1584
1585
1586       if(fLsNormalization>1e-6) {
1587         
1588         TString massName="histMass_";
1589         massName+=ipt;
1590         ((TH1F*)fOutputMass->FindObject(massName))->Scale((1/fLsNormalization)*((TH1F*)fOutputMass->FindObject(massName))->GetEntries());
1591
1592       }
1593     
1594
1595       fLsNormalization = 2.*TMath::Sqrt(((TH1F*)fDistr->FindObject("hpospair"))->Integral(ipt+1,ipt+2)*((TH1F*)fDistr->FindObject("hnegpair"))->Integral(ipt+1,ipt+2)); 
1596       //fLsNormalization = 2.*TMath::Sqrt(fTotPosPairs[4]*fTotNegPairs[4]);
1597
1598       if(fLsNormalization>1e-6) {
1599
1600         TString nameDistr="hptB_";
1601         nameDistr+=ipt;
1602         ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
1603         nameDistr="hdcaB_";
1604         nameDistr+=ipt;
1605         ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
1606         nameDistr="hcosthetastarB_";
1607         nameDistr+=ipt;
1608         ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
1609         nameDistr="hd0B_";
1610         nameDistr+=ipt;
1611         ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
1612         nameDistr="hd0d0B_";
1613         nameDistr+=ipt;
1614         ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
1615         nameDistr="hcosthetapointB_";
1616         nameDistr+=ipt;
1617         ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
1618         if(fSys==0){
1619           nameDistr="hcosthpointd0d0B_";
1620           nameDistr+=ipt;
1621           ((TH2F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH2F*)fDistr->FindObject(nameDistr))->GetEntries());
1622         }
1623       }
1624     }
1625   }
1626   TString cvname,cstname;
1627
1628   if (fArray==0){
1629     cvname="D0invmass";
1630     cstname="cstat0";
1631   } else {
1632     cvname="LSinvmass";
1633     cstname="cstat1";
1634   }
1635
1636   TCanvas *cMass=new TCanvas(cvname,cvname);
1637   cMass->cd();
1638   ((TH1F*)fOutputMass->FindObject("histMass_3"))->Draw();
1639
1640   TCanvas* cStat=new TCanvas(cstname,Form("Stat%s",fArray ? "LS" : "D0"));
1641   cStat->cd();
1642   cStat->SetGridy();
1643   fNentries->Draw("htext0");
1644
1645   // TCanvas *ccheck=new TCanvas(Form("cc%d",fArray),Form("cc%d",fArray));
1646   // ccheck->cd();
1647
1648   return;
1649 }
1650