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