Updates (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     fDistr->Add(hpospair);
612     fDistr->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   fNentries->GetXaxis()->SetBinLabel(3,"nD0Selected");
622   fNentries->GetXaxis()->SetBinLabel(4,"nEventsGoodVtxS");
623   fNentries->GetXaxis()->SetBinLabel(5,"ptbin = -1");
624   fNentries->GetXaxis()->SetBinLabel(6,"no daughter");
625   if(fSys==0) fNentries->GetXaxis()->SetBinLabel(7,"nCandSel(Tr)");
626   if(fFillVarHists){
627     fNentries->GetXaxis()->SetBinLabel(8,"PID=0");
628     fNentries->GetXaxis()->SetBinLabel(9,"PID=1");
629     fNentries->GetXaxis()->SetBinLabel(10,"PID=2");
630     fNentries->GetXaxis()->SetBinLabel(11,"PID=3");
631   }
632   if(fReadMC && fSys==0){
633     fNentries->GetXaxis()->SetBinLabel(12,"K");
634     fNentries->GetXaxis()->SetBinLabel(13,"Lambda");
635   }
636   fNentries->GetXaxis()->SetBinLabel(14,"Pile-up Rej");
637   fNentries->GetXaxis()->SetBinLabel(15,"N. of 0SMH");
638   if(fSys==1) fNentries->GetXaxis()->SetBinLabel(16,"Nev in centr");
639   fNentries->GetXaxis()->SetNdivisions(1,kFALSE);
640
641   fCounter = new AliNormalizationCounter(Form("%s",GetOutputSlot(5)->GetContainer()->GetName()));
642
643   // Post the data
644   PostData(1,fOutputMass);
645   if(fFillVarHists) PostData(2,fDistr);
646   PostData(3,fNentries);
647   PostData(5,fCounter);  
648   return;
649 }
650
651 //________________________________________________________________________
652 void AliAnalysisTaskSED0Mass::UserExec(Option_t */*option*/)
653 {
654   // Execute analysis for current event:
655   // heavy flavor candidates association to MC truth
656   //cout<<"I'm in UserExec"<<endl;
657
658
659   //cuts order
660   //       printf("    |M-MD0| [GeV]    < %f\n",fD0toKpiCuts[0]);
661   //     printf("    dca    [cm]  < %f\n",fD0toKpiCuts[1]);
662   //     printf("    cosThetaStar     < %f\n",fD0toKpiCuts[2]);
663   //     printf("    pTK     [GeV/c]    > %f\n",fD0toKpiCuts[3]);
664   //     printf("    pTpi    [GeV/c]    > %f\n",fD0toKpiCuts[4]);
665   //     printf("    |d0K|  [cm]  < %f\n",fD0toKpiCuts[5]);
666   //     printf("    |d0pi| [cm]  < %f\n",fD0toKpiCuts[6]);
667   //     printf("    d0d0  [cm^2] < %f\n",fD0toKpiCuts[7]);
668   //     printf("    cosThetaPoint    > %f\n",fD0toKpiCuts[8]);
669   
670
671   AliAODEvent *aod = dynamic_cast<AliAODEvent*> (InputEvent());
672
673   TString bname;
674   if(fArray==0){ //D0 candidates
675     // load D0->Kpi candidates
676     //cout<<"D0 candidates"<<endl;
677     bname="D0toKpi";
678   } else { //LikeSign candidates
679     // load like sign candidates
680     //cout<<"LS candidates"<<endl;
681     bname="LikeSign2Prong";
682   }
683
684   TClonesArray *inputArray=0;
685  
686   if(!aod && AODEvent() && IsStandardAOD()) {
687     // In case there is an AOD handler writing a standard AOD, use the AOD 
688     // event in memory rather than the input (ESD) event.    
689     aod = dynamic_cast<AliAODEvent*> (AODEvent());
690     // in this case the braches in the deltaAOD (AliAOD.VertexingHF.root)
691     // have to taken from the AOD event hold by the AliAODExtension
692     AliAODHandler* aodHandler = (AliAODHandler*) 
693       ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
694
695     if(aodHandler->GetExtensions()) {
696       AliAODExtension *ext = (AliAODExtension*)aodHandler->GetExtensions()->FindObject("AliAOD.VertexingHF.root");
697       AliAODEvent* aodFromExt = ext->GetAOD();
698       inputArray=(TClonesArray*)aodFromExt->GetList()->FindObject(bname.Data());
699     }
700   } else if(aod) {
701     inputArray=(TClonesArray*)aod->GetList()->FindObject(bname.Data());
702   }
703
704
705   if(!inputArray || !aod) {
706     printf("AliAnalysisTaskSED0Mass::UserExec: input branch not found!\n");
707     return;
708   }
709   
710   // fix for temporary bug in ESDfilter
711   // the AODs with null vertex pointer didn't pass the PhysSel
712   if(!aod->GetPrimaryVertex() || TMath::Abs(aod->GetMagneticField())<0.001) return;
713
714
715   TClonesArray *mcArray = 0;
716   AliAODMCHeader *mcHeader = 0;
717
718   if(fReadMC) {
719     // load MC particles
720     mcArray = (TClonesArray*)aod->GetList()->FindObject(AliAODMCParticle::StdBranchName());
721     if(!mcArray) {
722       printf("AliAnalysisTaskSED0Mass::UserExec: MC particles branch not found!\n");
723       return;
724     }
725     
726     // load MC header
727     mcHeader = (AliAODMCHeader*)aod->GetList()->FindObject(AliAODMCHeader::StdBranchName());
728     if(!mcHeader) {
729       printf("AliAnalysisTaskSED0Mass::UserExec: MC header branch not found!\n");
730       return;
731     }
732   }
733   
734   //printf("VERTEX Z %f %f\n",vtx1->GetZ(),mcHeader->GetVtxZ());
735   
736   //histogram filled with 1 for every AOD
737   fNentries->Fill(0);
738   fCounter->StoreEvent(aod,fReadMC); 
739
740   // trigger class for PbPb C0SMH-B-NOPF-ALLNOTRD, C0SMH-B-NOPF-ALL
741   TString trigclass=aod->GetFiredTriggerClasses();
742   if(trigclass.Contains("C0SMH-B-NOPF-ALLNOTRD") || trigclass.Contains("C0SMH-B-NOPF-ALL")) fNentries->Fill(14);
743
744   if(!fCuts->IsEventSelected(aod)) {
745     if(fCuts->GetWhyRejection()==1) // rejected for pileup
746       fNentries->Fill(13);
747     if(fSys==1 && (fCuts->GetWhyRejection()==2 || fCuts->GetWhyRejection()==3)) fNentries->Fill(15);
748     return;
749   }
750   
751   // AOD primary vertex
752   AliAODVertex *vtx1 = (AliAODVertex*)aod->GetPrimaryVertex();
753
754   Bool_t isGoodVtx=kFALSE;
755
756   //vtx1->Print();
757   TString primTitle = vtx1->GetTitle();
758   if(primTitle.Contains("VertexerTracks") && vtx1->GetNContributors()>0) {
759     isGoodVtx=kTRUE;
760     fNentries->Fill(3);
761   }
762
763   // loop over candidates
764   Int_t nInD0toKpi = inputArray->GetEntriesFast();
765   if(fDebug>2) printf("Number of D0->Kpi: %d\n",nInD0toKpi);
766
767   // FILE *f=fopen("4display.txt","a");
768   // fprintf(f,"Number of D0->Kpi: %d\n",nInD0toKpi);
769   Int_t nSelectedloose=0,nSelectedtight=0;  
770   for (Int_t iD0toKpi = 0; iD0toKpi < nInD0toKpi; iD0toKpi++) {
771     AliAODRecoDecayHF2Prong *d = (AliAODRecoDecayHF2Prong*)inputArray->UncheckedAt(iD0toKpi);
772
773     if(d->GetSelectionMap()) if(!d->HasSelectionBit(AliRDHFCuts::kD0toKpiCuts)) continue; //skip the D0 from Dstar
774
775     Bool_t unsetvtx=kFALSE;
776     if(!d->GetOwnPrimaryVtx()) {
777       d->SetOwnPrimaryVtx(vtx1); // needed to compute all variables
778       unsetvtx=kTRUE;
779     }
780   
781     
782     if ( fCuts->IsInFiducialAcceptance(d->Pt(),d->Y(421)) ) {
783       nSelectedloose++;
784       nSelectedtight++;      
785       if(fSys==0){
786         if(fCuts->IsSelected(d,AliRDHFCuts::kTracks,aod))fNentries->Fill(6);       
787       }
788       Int_t ptbin=fCuts->PtBin(d->Pt());
789       if(ptbin==-1) {fNentries->Fill(4); continue;} //out of bounds
790       fIsSelectedCandidate=fCuts->IsSelected(d,AliRDHFCuts::kCandidate,aod); //selected
791       if(fFillVarHists) {
792         //if(!fCutOnDistr || (fCutOnDistr && fIsSelectedCandidate)) {
793         fDaughterTracks.AddAt((AliAODTrack*)d->GetDaughter(0),0);
794         fDaughterTracks.AddAt((AliAODTrack*)d->GetDaughter(1),1);
795         //check daughters
796         if(!fDaughterTracks.UncheckedAt(0) || !fDaughterTracks.UncheckedAt(1)) {
797           AliDebug(1,"at least one daughter not found!");
798           fNentries->Fill(5);
799           fDaughterTracks.Clear();
800           continue;
801         }
802         //}
803         FillVarHists(aod,d,mcArray,fCuts,fDistr);
804       }
805
806       FillMassHists(d,mcArray,fCuts,fOutputMass);
807     }
808   
809     fDaughterTracks.Clear();
810     if(unsetvtx) d->UnsetOwnPrimaryVtx();
811   } //end for prongs
812   fCounter->StoreCandidates(aod,nSelectedloose,kTRUE);  
813   fCounter->StoreCandidates(aod,nSelectedtight,kFALSE);  
814   // Post the data
815   PostData(1,fOutputMass);
816   if(fFillVarHists) PostData(2,fDistr);
817   PostData(3,fNentries);
818   PostData(5,fCounter);
819   return;
820 }
821
822 //____________________________________________________________________________
823 void AliAnalysisTaskSED0Mass::FillVarHists(AliAODEvent* aod,AliAODRecoDecayHF2Prong *part, TClonesArray *arrMC, AliRDHFCutsD0toKpi *cuts, TList *listout){
824   //
825   // function used in UserExec to fill variable histograms:
826   //
827
828
829   Int_t pdgDgD0toKpi[2]={321,211};
830   Int_t lab=-9999;
831   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)
832   //Double_t pt = d->Pt(); //mother pt
833   Int_t isSelectedPID=3;
834   if(!fReadMC || (fReadMC && fUsePid4Distr)) isSelectedPID=cuts->IsSelectedPID(part); //0 rejected,1 D0,2 Dobar, 3 both
835   if (isSelectedPID==0)fNentries->Fill(7);
836   if (isSelectedPID==1)fNentries->Fill(8);
837   if (isSelectedPID==2)fNentries->Fill(9);
838   if (isSelectedPID==3)fNentries->Fill(10);
839   //fNentries->Fill(8+isSelectedPID);
840
841   if(fCutOnDistr && !fIsSelectedCandidate) return; 
842   //printf("\nif no cuts or cuts passed\n");
843
844
845   //add distr here
846   UInt_t pdgs[2];
847     
848   Double_t mPDG=TDatabasePDG::Instance()->GetParticle(421)->Mass();
849   pdgs[0]=211;
850   pdgs[1]=321;
851   Double_t minvD0 = part->InvMassD0();
852   pdgs[1]=211;
853   pdgs[0]=321;
854   Double_t minvD0bar = part->InvMassD0bar();
855   //cout<<"inside mass cut"<<endl;
856
857   Double_t invmasscut=0.03;
858
859   TString fillthispi="",fillthisK="",fillthis="";
860
861   Int_t ptbin=cuts->PtBin(part->Pt());
862
863   Double_t dz1[2],dz2[2],covar1[3],covar2[3];//,d0xd0proper,errd0xd0proper;
864   dz1[0]=-99; dz2[0]=-99;
865   Double_t d0[2];
866   Double_t decl[2]={-99,-99};
867   Bool_t recalcvtx=kFALSE;
868
869
870
871   if(fCuts->GetIsPrimaryWithoutDaughters()){
872     recalcvtx=kTRUE;
873     //recalculate vertex
874     AliAODVertex *vtxProp=0x0;
875     vtxProp=GetPrimaryVtxSkipped(aod);
876     if(vtxProp) {
877       part->SetOwnPrimaryVtx(vtxProp);
878       //Bool_t unsetvtx=kTRUE;
879       //Calculate d0 for daughter tracks with Vtx Skipped
880       AliESDtrack *esdtrack1=new AliESDtrack((AliVTrack*)fDaughterTracks.UncheckedAt(0));
881       AliESDtrack *esdtrack2=new AliESDtrack((AliVTrack*)fDaughterTracks.UncheckedAt(1));
882       esdtrack1->PropagateToDCA(vtxProp,aod->GetMagneticField(),1.,dz1,covar1);
883       esdtrack2->PropagateToDCA(vtxProp,aod->GetMagneticField(),1.,dz2,covar2);
884       delete vtxProp; vtxProp=NULL;
885       delete esdtrack1;
886       delete esdtrack2;
887     }
888
889     d0[0]=dz1[0];
890     d0[1]=dz2[0];
891
892     decl[0]=part->DecayLength2();
893     decl[1]=part->NormalizedDecayLength2();
894     part->UnsetOwnPrimaryVtx();
895   
896   }
897
898   Double_t cosThetaStarD0 = 99;
899   Double_t cosThetaStarD0bar = 99;
900   Double_t cosPointingAngle = 99;
901   Double_t normalizedDecayLength2 = -1, normalizedDecayLengthxy=-1;
902   Double_t decayLength2 = -1, decayLengthxy=-1;
903   Double_t ptProng[2]={-99,-99};
904   Double_t d0Prong[2]={-99,-99};
905   
906
907   //disable the PID
908   if(!fUsePid4Distr) isSelectedPID=0;
909   if((lab>=0 && fReadMC) || (!fReadMC && isSelectedPID)){ //signal (from MC or PID)
910    
911     //check pdg of the prongs
912     AliAODTrack *prong0=(AliAODTrack*)fDaughterTracks.UncheckedAt(0);
913     AliAODTrack *prong1=(AliAODTrack*)fDaughterTracks.UncheckedAt(1);
914
915     if(!prong0 || !prong1) {
916       return;
917     }
918     Int_t labprong[2];
919     if(fReadMC){
920       labprong[0]=prong0->GetLabel();
921       labprong[1]=prong1->GetLabel();
922     }
923     AliAODMCParticle *mcprong=0;
924     Int_t pdgProng[2]={0,0};
925
926     for (Int_t iprong=0;iprong<2;iprong++){
927       if(fReadMC && labprong[iprong]>=0) {
928         mcprong= (AliAODMCParticle*)arrMC->At(labprong[iprong]);
929         pdgProng[iprong]=mcprong->GetPdgCode();
930       }
931     }
932     
933     if(fSys==0){
934       //no mass cut ditributions: ptbis
935         
936       fillthispi="hptpiSnoMcut_";
937       fillthispi+=ptbin;
938
939       fillthisK="hptKSnoMcut_";
940       fillthisK+=ptbin;
941
942       if ((TMath::Abs(pdgProng[0]) == 211 && TMath::Abs(pdgProng[1]) == 321)
943           || (isSelectedPID==1 || isSelectedPID==3)){
944         ((TH1F*)listout->FindObject(fillthispi))->Fill(prong0->Pt());
945         ((TH1F*)listout->FindObject(fillthisK))->Fill(prong1->Pt());
946       }
947
948       if ((TMath::Abs(pdgProng[0]) == 321 && TMath::Abs(pdgProng[1]) == 211)
949           || (isSelectedPID==2 || isSelectedPID==3)){
950         ((TH1F*)listout->FindObject(fillthisK))->Fill(prong0->Pt());
951         ((TH1F*)listout->FindObject(fillthispi))->Fill(prong1->Pt());
952       }
953     }
954
955     //no mass cut ditributions: mass
956     fillthis="hMassS_";
957     fillthis+=ptbin;
958       
959     if ((fReadMC && ((AliAODMCParticle*)arrMC->At(lab))->GetPdgCode() == 421)
960         || (!fReadMC && (isSelectedPID==1 || isSelectedPID==3))){//D0
961       ((TH1F*)listout->FindObject(fillthis))->Fill(minvD0);
962     }
963     else { //D0bar
964       if(fReadMC || (!fReadMC && isSelectedPID > 1))
965         ((TH1F*)listout->FindObject(fillthis))->Fill(minvD0bar);
966     }
967
968     //apply cut on invariant mass on the pair
969     if(TMath::Abs(minvD0-mPDG)<invmasscut || TMath::Abs(minvD0bar-mPDG)<invmasscut){
970
971       cosThetaStarD0 = part->CosThetaStarD0();
972       cosThetaStarD0bar = part->CosThetaStarD0bar();
973       cosPointingAngle = part->CosPointingAngle();
974       normalizedDecayLength2 = part->NormalizedDecayLength2();
975       decayLength2 = part->DecayLength2();
976       decayLengthxy = part->DecayLengthXY();
977       normalizedDecayLengthxy=decayLengthxy/part->DecayLengthXYError();
978
979       ptProng[0]=prong0->Pt(); ptProng[1]=prong1->Pt();
980       // ptProng[0]=part->PtProng(0); ptProng[1]=part->PtProng(1);
981       d0Prong[0]=part->Getd0Prong(0); d0Prong[1]=part->Getd0Prong(1);
982  
983
984       if(fArray==1) cout<<"LS signal: ERROR"<<endl;
985       for (Int_t iprong=0; iprong<2; iprong++){
986         AliAODTrack *prong=(AliAODTrack*)fDaughterTracks.UncheckedAt(iprong);
987         if (fReadMC) labprong[iprong]=prong->GetLabel();
988           
989         //cout<<"prong name = "<<prong->GetName()<<" label = "<<prong->GetLabel()<<endl;
990         Int_t pdgprong=0;
991         if(fReadMC && labprong[iprong]>=0) {
992           mcprong= (AliAODMCParticle*)arrMC->At(labprong[iprong]);
993           pdgprong=mcprong->GetPdgCode();
994         }
995
996         Bool_t isPionHere[2]={(isSelectedPID==1 || isSelectedPID==3) ? kTRUE : kFALSE,(isSelectedPID==2 || isSelectedPID==3) ? kTRUE : kFALSE};
997
998         if(TMath::Abs(pdgprong)==211 || isPionHere[iprong]) {
999           //cout<<"pi"<<endl;
1000            
1001           if(fSys==0){ 
1002             fillthispi="hptpiS_";
1003             fillthispi+=ptbin;
1004             ((TH1F*)listout->FindObject(fillthispi))->Fill(ptProng[iprong]);
1005           }
1006           fillthispi="hd0piS_";
1007           fillthispi+=ptbin;
1008           ((TH1F*)listout->FindObject(fillthispi))->Fill(d0Prong[iprong]);
1009           if(recalcvtx) {
1010
1011             fillthispi="hd0vpiS_";
1012             fillthispi+=ptbin;
1013             ((TH1F*)listout->FindObject(fillthispi))->Fill(d0[iprong]);
1014           }
1015
1016         }
1017           
1018         if(TMath::Abs(pdgprong)==321 || !isPionHere[iprong]) {
1019           //cout<<"kappa"<<endl;
1020           if(fSys==0){
1021             fillthisK="hptKS_";
1022             fillthisK+=ptbin;
1023             ((TH1F*)listout->FindObject(fillthisK))->Fill(ptProng[iprong]);
1024           }
1025           fillthisK="hd0KS_";
1026           fillthisK+=ptbin;
1027           ((TH1F*)listout->FindObject(fillthisK))->Fill(d0Prong[iprong]);
1028           if (recalcvtx){
1029             fillthisK="hd0vKS_";
1030             fillthisK+=ptbin;
1031             ((TH1F*)listout->FindObject(fillthisK))->Fill(d0[iprong]);
1032           }
1033         }
1034
1035         if(fSys==0){
1036           fillthis="hcosthpointd0S_";
1037           fillthis+=ptbin;        
1038           ((TH1F*)listout->FindObject(fillthis))->Fill(cosPointingAngle,d0Prong[iprong]);
1039         }
1040       } //end loop on prongs
1041
1042       fillthis="hdcaS_";
1043       fillthis+=ptbin;    
1044       ((TH1F*)listout->FindObject(fillthis))->Fill(part->GetDCA());
1045
1046       fillthis="hcosthetapointS_";
1047       fillthis+=ptbin;    
1048       ((TH1F*)listout->FindObject(fillthis))->Fill(cosPointingAngle);
1049
1050       fillthis="hcosthetapointxyS_";
1051       fillthis+=ptbin;    
1052       ((TH1F*)listout->FindObject(fillthis))->Fill(part->CosPointingAngleXY());
1053
1054
1055       fillthis="hd0d0S_";
1056       fillthis+=ptbin;
1057       ((TH1F*)listout->FindObject(fillthis))->Fill(part->Prodd0d0());
1058
1059       fillthis="hdeclS_";
1060       fillthis+=ptbin;
1061       ((TH1F*)listout->FindObject(fillthis))->Fill(decayLength2);
1062
1063       fillthis="hnormdeclS_";
1064       fillthis+=ptbin;
1065       ((TH1F*)listout->FindObject(fillthis))->Fill(normalizedDecayLength2);
1066
1067       fillthis="hdeclxyS_";
1068       fillthis+=ptbin;
1069       ((TH1F*)listout->FindObject(fillthis))->Fill(decayLengthxy);
1070
1071       fillthis="hnormdeclxyS_";
1072       fillthis+=ptbin;
1073       ((TH1F*)listout->FindObject(fillthis))->Fill(normalizedDecayLengthxy);
1074
1075       fillthis="hdeclxyd0d0S_";
1076       fillthis+=ptbin;
1077       ((TH2F*)listout->FindObject(fillthis))->Fill(decayLengthxy,d0Prong[0]*d0Prong[1]);
1078
1079       fillthis="hnormdeclxyd0d0S_";
1080       fillthis+=ptbin;
1081       ((TH2F*)listout->FindObject(fillthis))->Fill(normalizedDecayLengthxy,d0Prong[0]*d0Prong[1]);
1082
1083       if(recalcvtx) {
1084         fillthis="hdeclvS_";
1085         fillthis+=ptbin;
1086         ((TH1F*)listout->FindObject(fillthis))->Fill(decl[0]);
1087
1088         fillthis="hnormdeclvS_";
1089         fillthis+=ptbin;
1090         ((TH1F*)listout->FindObject(fillthis))->Fill(decl[1]);
1091
1092         fillthis="hd0d0vS_";
1093         fillthis+=ptbin;
1094         ((TH1F*)listout->FindObject(fillthis))->Fill(d0[0]*d0[1]);
1095       }
1096
1097       if(fSys==0){
1098         fillthis="hcosthetastarS_";
1099         fillthis+=ptbin;
1100         if ((fReadMC && ((AliAODMCParticle*)arrMC->At(lab))->GetPdgCode() == 421)) ((TH1F*)listout->FindObject(fillthis))->Fill(cosThetaStarD0);
1101         else {
1102           if (fReadMC || isSelectedPID>1)((TH1F*)listout->FindObject(fillthis))->Fill(cosThetaStarD0bar);
1103           if(isSelectedPID==1 || isSelectedPID==3)((TH1F*)listout->FindObject(fillthis))->Fill(cosThetaStarD0);
1104         }
1105
1106         fillthis="hcosthpointd0d0S_";
1107         fillthis+=ptbin;          
1108         ((TH2F*)listout->FindObject(fillthis))->Fill(cosPointingAngle,part->Prodd0d0());
1109       }
1110
1111     } //end mass cut
1112     
1113   } else{ //Background or LS
1114     //if(!fReadMC){
1115     //cout<<"is background"<<endl;
1116      
1117     //no mass cut distributions: mass, ptbis
1118     fillthis="hMassB_";
1119     fillthis+=ptbin;
1120
1121     if (!fCutOnDistr || (fCutOnDistr && (fIsSelectedCandidate==1 || fIsSelectedCandidate==3))) ((TH1F*)listout->FindObject(fillthis))->Fill(minvD0);
1122     if (!fCutOnDistr || (fCutOnDistr && fIsSelectedCandidate>1)) ((TH1F*)listout->FindObject(fillthis))->Fill(minvD0bar);
1123     if(fSys==0){
1124       fillthis="hptB1prongnoMcut_";
1125       fillthis+=ptbin;
1126       
1127       ((TH1F*)listout->FindObject(fillthis))->Fill(((AliAODTrack*)fDaughterTracks.UncheckedAt(0))->Pt());
1128       
1129       fillthis="hptB2prongsnoMcut_";
1130       fillthis+=ptbin;
1131       ((TH1F*)listout->FindObject(fillthis))->Fill(((AliAODTrack*)fDaughterTracks.UncheckedAt(0))->Pt());
1132     ((TH1F*)listout->FindObject(fillthis))->Fill(((AliAODTrack*)fDaughterTracks.UncheckedAt(0))->Pt());
1133     }
1134     //apply cut on invariant mass on the pair
1135     if(TMath::Abs(minvD0-mPDG)<invmasscut || TMath::Abs(minvD0bar-mPDG)<invmasscut){
1136       if(fSys==0){
1137         //ptProng[0]=part->PtProng(0); ptProng[1]=part->PtProng(1);
1138         ptProng[0]=((AliAODTrack*)fDaughterTracks.UncheckedAt(0))->Pt(); ptProng[1]=((AliAODTrack*)fDaughterTracks.UncheckedAt(0))->Pt(); 
1139         cosThetaStarD0 = part->CosThetaStarD0();
1140         cosThetaStarD0bar = part->CosThetaStarD0bar();
1141       }
1142
1143       cosPointingAngle = part->CosPointingAngle();
1144       normalizedDecayLength2 = part->NormalizedDecayLength2();
1145       decayLength2 = part->DecayLength2();
1146       decayLengthxy = part->DecayLengthXY();
1147       normalizedDecayLengthxy=decayLengthxy/part->DecayLengthXYError();
1148       d0Prong[0]=part->Getd0Prong(0); d0Prong[1]=part->Getd0Prong(1);
1149
1150
1151       AliAODTrack *prongg=(AliAODTrack*)fDaughterTracks.UncheckedAt(0);
1152       if(!prongg) {
1153         if(fDebug>2) cout<<"No daughter found";
1154         return;
1155       }
1156       else{
1157         if(fArray==1){
1158           if(prongg->Charge()==1) {
1159             //fTotPosPairs[ptbin]++;
1160             ((TH1F*)fDistr->FindObject("hpospair"))->Fill(ptbin);
1161           } else {
1162             //fTotNegPairs[ptbin]++;
1163             ((TH1F*)fDistr->FindObject("hnegpair"))->Fill(ptbin);
1164           }
1165         }
1166       }
1167         
1168       fillthis="hd0B_";
1169       fillthis+=ptbin;
1170       ((TH1F*)listout->FindObject(fillthis))->Fill(d0Prong[0]);
1171       ((TH1F*)listout->FindObject(fillthis))->Fill(d0Prong[1]);
1172
1173       if(fReadMC){
1174         Int_t pdgMother[2]={0,0};
1175         Double_t factor[2]={1,1};
1176
1177         for(Int_t iprong=0;iprong<2;iprong++){
1178           AliAODTrack *prong=(AliAODTrack*)fDaughterTracks.UncheckedAt(iprong);
1179           lab=prong->GetLabel();
1180           if(lab>=0){
1181             AliAODMCParticle* mcprong=(AliAODMCParticle*)arrMC->At(lab);
1182             if(mcprong){
1183               Int_t labmom=mcprong->GetMother();
1184               if(labmom>=0){
1185                 AliAODMCParticle* mcmother=(AliAODMCParticle*)arrMC->At(labmom);
1186                 if(mcmother) pdgMother[iprong]=mcmother->GetPdgCode();
1187               }
1188             }
1189           }
1190
1191           if(fSys==0){
1192
1193             fillthis="hd0moresB_";
1194             fillthis+=ptbin;
1195           
1196             if(TMath::Abs(pdgMother[iprong])==310 || TMath::Abs(pdgMother[iprong])==130 || TMath::Abs(pdgMother[iprong])==321){ //K^0_S, K^0_L, K^+-
1197               if(ptProng[iprong]<=1)factor[iprong]=1./.7;
1198               else factor[iprong]=1./.6;
1199               fNentries->Fill(11);
1200             }
1201             
1202             if(TMath::Abs(pdgMother[iprong])==3122) { //Lambda
1203               factor[iprong]=1./0.25;
1204               fNentries->Fill(12);
1205             }
1206             fillthis="hd0moresB_";
1207             fillthis+=ptbin;
1208
1209             ((TH1F*)listout->FindObject(fillthis))->Fill(d0Prong[iprong],factor[iprong]);
1210
1211             if(recalcvtx){
1212               fillthis="hd0vmoresB_";
1213               fillthis+=ptbin;
1214               ((TH1F*)listout->FindObject(fillthis))->Fill(d0[iprong],factor[iprong]);
1215             }
1216           }
1217         } //loop on prongs
1218
1219         if(fSys==0){
1220           fillthis="hd0d0moresB_";
1221           fillthis+=ptbin;
1222           ((TH1F*)listout->FindObject(fillthis))->Fill(part->Prodd0d0(),factor[0]*factor[1]);
1223
1224           fillthis="hcosthetapointmoresB_";
1225           fillthis+=ptbin;
1226           ((TH1F*)listout->FindObject(fillthis))->Fill(cosPointingAngle,factor[0]*factor[1]);
1227
1228           if(recalcvtx){
1229             fillthis="hd0d0vmoresB_";
1230             fillthis+=ptbin;
1231             ((TH1F*)listout->FindObject(fillthis))->Fill(d0[0]*d0[1],factor[0]*factor[1]);
1232           }
1233         }
1234       } //readMC
1235
1236       if(fSys==0){          
1237         //normalise pt distr to half afterwards
1238         fillthis="hptB_";
1239         fillthis+=ptbin;
1240         ((TH1F*)listout->FindObject(fillthis))->Fill(ptProng[0]);
1241         ((TH1F*)listout->FindObject(fillthis))->Fill(ptProng[1]);
1242
1243         fillthis="hcosthetastarB_";
1244         fillthis+=ptbin;
1245         if (!fCutOnDistr || (fCutOnDistr && (fIsSelectedCandidate==1 || fIsSelectedCandidate==3)))((TH1F*)listout->FindObject(fillthis))->Fill(cosThetaStarD0);
1246         if (!fCutOnDistr || (fCutOnDistr && fIsSelectedCandidate>1))((TH1F*)listout->FindObject(fillthis))->Fill(cosThetaStarD0bar);    
1247
1248
1249         fillthis="hd0p0B_";
1250         fillthis+=ptbin;
1251         ((TH1F*)listout->FindObject(fillthis))->Fill(d0Prong[0]);
1252         fillthis="hd0p1B_";
1253         fillthis+=ptbin;
1254         ((TH1F*)listout->FindObject(fillthis))->Fill(d0Prong[1]);
1255         
1256         fillthis="hcosthpointd0d0B_";
1257         fillthis+=ptbin;
1258         ((TH2F*)listout->FindObject(fillthis))->Fill(cosPointingAngle,part->Prodd0d0());
1259         
1260         fillthis="hcosthpointd0B_";
1261         fillthis+=ptbin;          
1262         ((TH1F*)listout->FindObject(fillthis))->Fill(cosPointingAngle,d0Prong[0]);
1263         ((TH1F*)listout->FindObject(fillthis))->Fill(cosPointingAngle,d0Prong[1]);
1264           
1265
1266         if(recalcvtx){
1267
1268           fillthis="hd0vp0B_";
1269           fillthis+=ptbin;
1270           ((TH1F*)listout->FindObject(fillthis))->Fill(d0[0]);
1271           fillthis="hd0vp1B_";
1272           fillthis+=ptbin;
1273           ((TH1F*)listout->FindObject(fillthis))->Fill(d0[1]);
1274           
1275           fillthis="hd0vB_";
1276           fillthis+=ptbin;
1277           ((TH1F*)listout->FindObject(fillthis))->Fill(d0[0]);
1278           ((TH1F*)listout->FindObject(fillthis))->Fill(d0[1]);
1279
1280         }
1281
1282       }  
1283
1284       fillthis="hdcaB_";
1285       fillthis+=ptbin;
1286       ((TH1F*)listout->FindObject(fillthis))->Fill(part->GetDCA());
1287
1288       fillthis="hd0d0B_";
1289       fillthis+=ptbin;
1290       ((TH1F*)listout->FindObject(fillthis))->Fill(d0Prong[0]*d0Prong[1]);
1291
1292       if(recalcvtx){
1293         fillthis="hd0d0vB_";
1294         fillthis+=ptbin;
1295         ((TH1F*)listout->FindObject(fillthis))->Fill(d0[0]*d0[1]);
1296       }
1297
1298       fillthis="hcosthetapointB_";
1299       fillthis+=ptbin;
1300       ((TH1F*)listout->FindObject(fillthis))->Fill(cosPointingAngle);
1301
1302       fillthis="hcosthetapointxyB_";
1303       fillthis+=ptbin;    
1304       ((TH1F*)listout->FindObject(fillthis))->Fill(part->CosPointingAngleXY());
1305
1306       fillthis="hdeclB_";
1307       fillthis+=ptbin;
1308       ((TH1F*)listout->FindObject(fillthis))->Fill(decayLength2);
1309
1310       fillthis="hnormdeclB_";
1311       fillthis+=ptbin;
1312       ((TH1F*)listout->FindObject(fillthis))->Fill(normalizedDecayLength2);
1313
1314       fillthis="hdeclxyB_";
1315       fillthis+=ptbin;
1316       ((TH1F*)listout->FindObject(fillthis))->Fill(decayLengthxy);
1317
1318       fillthis="hnormdeclxyB_";
1319       fillthis+=ptbin;
1320       ((TH1F*)listout->FindObject(fillthis))->Fill(normalizedDecayLengthxy);
1321
1322       fillthis="hdeclxyd0d0B_";
1323       fillthis+=ptbin;
1324       ((TH2F*)listout->FindObject(fillthis))->Fill(decayLengthxy,d0Prong[0]*d0Prong[1]);
1325
1326       fillthis="hnormdeclxyd0d0B_";
1327       fillthis+=ptbin;
1328       ((TH2F*)listout->FindObject(fillthis))->Fill(normalizedDecayLengthxy,d0Prong[0]*d0Prong[1]);      
1329
1330       if(recalcvtx) {
1331
1332         fillthis="hdeclvB_";
1333         fillthis+=ptbin;
1334         ((TH1F*)listout->FindObject(fillthis))->Fill(decl[0]);
1335
1336         fillthis="hnormdeclvB_";
1337         fillthis+=ptbin;
1338         ((TH1F*)listout->FindObject(fillthis))->Fill(decl[1]);
1339
1340
1341       }
1342     }//mass cut 
1343   }//else (background)
1344   
1345   return;
1346 }
1347 //____________________________________________________________________________
1348
1349 void AliAnalysisTaskSED0Mass::FillMassHists(AliAODRecoDecayHF2Prong *part, TClonesArray *arrMC, AliRDHFCutsD0toKpi* cuts, TList *listout){
1350   //
1351   // function used in UserExec to fill mass histograms:
1352   //
1353
1354
1355   Double_t mPDG=TDatabasePDG::Instance()->GetParticle(421)->Mass();
1356
1357   //cout<<"is selected = "<<fIsSelectedCandidate<<endl;
1358
1359   //cout<<"check cuts = "<<endl;
1360   //cuts->PrintAll();
1361   if (!fIsSelectedCandidate){
1362     //cout<<"Not Selected"<<endl;
1363     //cout<<"Rejected because "<<cuts->GetWhy()<<endl;
1364     return;
1365   }
1366
1367
1368   if(fDebug>2)  cout<<"Candidate selected"<<endl;
1369
1370   Double_t invmassD0 = part->InvMassD0(), invmassD0bar = part->InvMassD0bar();
1371   //printf("SELECTED\n");
1372   Int_t ptbin=cuts->PtBin(part->Pt());
1373
1374   AliAODTrack *prong=(AliAODTrack*)fDaughterTracks.UncheckedAt(0);
1375   if(!prong) {
1376     AliDebug(2,"No daughter found");
1377     return;
1378   }
1379   else{
1380     // if(prong->Charge()==1) {
1381     //   ((TH1F*)fDistr->FindObject("hpospair"))->Fill(fCuts->GetNPtBins()+ptbin);
1382     //   //fTotPosPairs[ptbin]++;
1383     // } else {
1384     //   ((TH1F*)fDistr->FindObject("hnegpair"))->Fill(fCuts->GetNPtBins()+ptbin);
1385     //   //fTotNegPairs[ptbin]++;
1386     // }
1387   }
1388  
1389   // for(Int_t it=0;it<2;it++){
1390  
1391   //    //request on spd points to be addes
1392   //   if(/*nSPD==2 && */part->Pt() > 5. && (TMath::Abs(invmassD0-mPDG)<0.01 || TMath::Abs(invmassD0bar-mPDG)<0.01)){
1393   //     FILE *f=fopen("4display.txt","a");
1394   //     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());
1395   //     fclose(f);
1396   //     //printf("PrimVtx NContributors: %d \n Prongs Rel Angle: %f \n \n",ncont,relangle);
1397   //   }
1398   // }
1399  
1400   TString fillthis="";
1401   Int_t pdgDgD0toKpi[2]={321,211};
1402   Int_t labD0=-1;
1403   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)
1404
1405   //count candidates selected by cuts
1406   fNentries->Fill(1);
1407   //count true D0 selected by cuts
1408   if (fReadMC && labD0>=0) fNentries->Fill(2);
1409
1410   if ((fIsSelectedCandidate==1 || fIsSelectedCandidate==3) && fFillOnlyD0D0bar<2) { //D0
1411     if(fReadMC){
1412       if(labD0>=0) {
1413         if(fArray==1) cout<<"LS signal ERROR"<<endl;
1414
1415         AliAODMCParticle *partD0 = (AliAODMCParticle*)arrMC->At(labD0);
1416         Int_t pdgD0 = partD0->GetPdgCode();
1417         //cout<<"pdg = "<<pdgD0<<endl;
1418         if (pdgD0==421){ //D0
1419           //cout<<"Fill S with D0"<<endl;
1420           fillthis="histSgn_";
1421           fillthis+=ptbin;
1422           ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0);
1423           if(fSys==0){
1424             if(TMath::Abs(invmassD0 - mPDG) < 0.027){
1425               fillthis="histSgn27_";
1426               fillthis+=ptbin;
1427               ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0);
1428             }
1429           }
1430         } else{ //it was a D0bar
1431           fillthis="histRfl_";
1432           fillthis+=ptbin;
1433           ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0);
1434         }
1435       } else {//background
1436         fillthis="histBkg_";
1437         fillthis+=ptbin;
1438         ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0);
1439       }
1440
1441     }else{
1442       fillthis="histMass_";
1443       fillthis+=ptbin;
1444       //cout<<"Filling "<<fillthis<<endl;
1445
1446       //printf("Fill mass with D0");
1447       ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0);
1448     }
1449      
1450   }
1451   if (fIsSelectedCandidate>1 && (fFillOnlyD0D0bar==0 || fFillOnlyD0D0bar==2)) { //D0bar
1452     if(fReadMC){
1453       if(labD0>=0) {
1454         if(fArray==1) cout<<"LS signal ERROR"<<endl;
1455         AliAODMCParticle *partD0 = (AliAODMCParticle*)arrMC->At(labD0);
1456         Int_t pdgD0 = partD0->GetPdgCode();
1457         //cout<<" pdg = "<<pdgD0<<endl;
1458         if (pdgD0==-421){ //D0bar
1459           fillthis="histSgn_";
1460           fillthis+=ptbin;
1461           ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0bar);
1462           // if (TMath::Abs(invmassD0bar - mPDG) < 0.027){
1463           //   fillthis="histSgn27_";
1464           //   fillthis+=ptbin;
1465           //   ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0bar);
1466           // }
1467
1468           
1469         } else{
1470           fillthis="histRfl_";
1471           fillthis+=ptbin;
1472           ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0bar);
1473         }
1474       } else {//background or LS
1475         fillthis="histBkg_";
1476         fillthis+=ptbin;
1477         ((TH1F*)(listout->FindObject(fillthis)))->Fill(invmassD0bar);
1478       }
1479     }else{
1480       fillthis="histMass_";
1481       fillthis+=ptbin;
1482       //printf("Fill mass with D0bar");
1483       ((TH1F*)listout->FindObject(fillthis))->Fill(invmassD0bar);
1484
1485     }
1486   }
1487
1488   return;
1489 }
1490
1491 //__________________________________________________________________________
1492 AliAODVertex* AliAnalysisTaskSED0Mass::GetPrimaryVtxSkipped(AliAODEvent *aodev){
1493   //Calculate the primary vertex w/o the daughter tracks of the candidate
1494   
1495   Int_t skipped[2];
1496   Int_t nTrksToSkip=2;
1497   AliAODTrack *dgTrack = (AliAODTrack*)fDaughterTracks.UncheckedAt(0);
1498   if(!dgTrack){
1499     AliDebug(2,"no daughter found!");
1500     return 0x0;
1501   }
1502   skipped[0]=dgTrack->GetID();
1503   dgTrack = (AliAODTrack*)fDaughterTracks.UncheckedAt(1);
1504   if(!dgTrack){
1505     AliDebug(2,"no daughter found!");
1506     return 0x0;
1507   }
1508   skipped[1]=dgTrack->GetID();
1509
1510   AliESDVertex *vertexESD=0x0;
1511   AliAODVertex *vertexAOD=0x0;
1512   AliVertexerTracks *vertexer = new AliVertexerTracks(aodev->GetMagneticField());
1513   
1514   //
1515   vertexer->SetSkipTracks(nTrksToSkip,skipped);
1516   vertexer->SetMinClusters(4);  
1517   vertexESD = (AliESDVertex*)vertexer->FindPrimaryVertex(aodev); 
1518   if(!vertexESD) return vertexAOD;
1519   if(vertexESD->GetNContributors()<=0) { 
1520     AliDebug(2,"vertexing failed"); 
1521     delete vertexESD; vertexESD=NULL;
1522     return vertexAOD;
1523   }
1524   
1525   delete vertexer; vertexer=NULL;
1526   
1527   
1528   // convert to AliAODVertex
1529   Double_t pos[3],cov[6],chi2perNDF;
1530   vertexESD->GetXYZ(pos); // position
1531   vertexESD->GetCovMatrix(cov); //covariance matrix
1532   chi2perNDF = vertexESD->GetChi2toNDF();
1533   delete vertexESD; vertexESD=NULL;
1534   
1535   vertexAOD = new AliAODVertex(pos,cov,chi2perNDF);
1536   return vertexAOD;
1537   
1538 }
1539
1540
1541 //________________________________________________________________________
1542 void AliAnalysisTaskSED0Mass::Terminate(Option_t */*option*/)
1543 {
1544   // Terminate analysis
1545   //
1546   if(fDebug > 1) printf("AnalysisTaskSED0Mass: Terminate() \n");
1547
1548
1549   fOutputMass = dynamic_cast<TList*> (GetOutputData(1));
1550   if (!fOutputMass) {     
1551     printf("ERROR: fOutputMass not available\n");
1552     return;
1553   }
1554   if(fFillVarHists){
1555     fDistr = dynamic_cast<TList*> (GetOutputData(2));
1556     if (!fDistr) {
1557       printf("ERROR: fDistr not available\n");
1558       return;
1559     }
1560   }
1561
1562   fNentries = dynamic_cast<TH1F*>(GetOutputData(3));
1563   
1564   if(!fNentries){
1565     printf("ERROR: fNEntries not available\n");
1566     return;
1567   }
1568   fCuts = dynamic_cast<AliRDHFCutsD0toKpi*>(GetOutputData(4));
1569   if(!fCuts){
1570     printf("ERROR: fCuts not available\n");
1571     return;
1572   }
1573   fCounter = dynamic_cast<AliNormalizationCounter*>(GetOutputData(5));    
1574   if (!fCounter) {
1575     printf("ERROR: fCounter not available\n");
1576     return;
1577   }
1578   Int_t nptbins=fCuts->GetNPtBins();
1579   for(Int_t ipt=0;ipt<nptbins;ipt++){ 
1580
1581     if(fArray==1 && fFillVarHists){ 
1582       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
1583
1584
1585       if(fLsNormalization>1e-6) {
1586         
1587         TString massName="histMass_";
1588         massName+=ipt;
1589         ((TH1F*)fOutputMass->FindObject(massName))->Scale((1/fLsNormalization)*((TH1F*)fOutputMass->FindObject(massName))->GetEntries());
1590
1591       }
1592     
1593
1594       fLsNormalization = 2.*TMath::Sqrt(((TH1F*)fDistr->FindObject("hpospair"))->Integral(ipt+1,ipt+2)*((TH1F*)fDistr->FindObject("hnegpair"))->Integral(ipt+1,ipt+2)); 
1595       //fLsNormalization = 2.*TMath::Sqrt(fTotPosPairs[4]*fTotNegPairs[4]);
1596
1597       if(fLsNormalization>1e-6) {
1598
1599         TString nameDistr="hptB_";
1600         nameDistr+=ipt;
1601         ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
1602         nameDistr="hdcaB_";
1603         nameDistr+=ipt;
1604         ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
1605         nameDistr="hcosthetastarB_";
1606         nameDistr+=ipt;
1607         ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
1608         nameDistr="hd0B_";
1609         nameDistr+=ipt;
1610         ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
1611         nameDistr="hd0d0B_";
1612         nameDistr+=ipt;
1613         ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
1614         nameDistr="hcosthetapointB_";
1615         nameDistr+=ipt;
1616         ((TH1F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH1F*)fDistr->FindObject(nameDistr))->GetEntries());
1617         if(fSys==0){
1618           nameDistr="hcosthpointd0d0B_";
1619           nameDistr+=ipt;
1620           ((TH2F*)fDistr->FindObject(nameDistr))->Scale((1/fLsNormalization)*((TH2F*)fDistr->FindObject(nameDistr))->GetEntries());
1621         }
1622       }
1623     }
1624   }
1625   TString cvname,cstname;
1626
1627   if (fArray==0){
1628     cvname="D0invmass";
1629     cstname="cstat0";
1630   } else {
1631     cvname="LSinvmass";
1632     cstname="cstat1";
1633   }
1634
1635   TCanvas *cMass=new TCanvas(cvname,cvname);
1636   cMass->cd();
1637   ((TH1F*)fOutputMass->FindObject("histMass_3"))->Draw();
1638
1639   TCanvas* cStat=new TCanvas(cstname,Form("Stat%s",fArray ? "LS" : "D0"));
1640   cStat->cd();
1641   cStat->SetGridy();
1642   fNentries->Draw("htext0");
1643
1644   // TCanvas *ccheck=new TCanvas(Form("cc%d",fArray),Form("cc%d",fArray));
1645   // ccheck->cd();
1646
1647   return;
1648 }
1649