ffd831b73c684922a72a3ccee32c02a6b48de196
[u/mrichter/AliRoot.git] / PWGHF / vertexingHF / macros / AddTaskCFVertexingHF3Prong.C
1 //DEFINITION OF A FEW CONSTANTS
2 const Double_t ymin  = -1.2 ;
3 const Double_t ymax  =  1.2 ;
4 const Double_t cosmin = -0.7;
5 const Double_t cosmax =  1.05;
6 const Double_t cTmin = 0;  // micron
7 const Double_t cTmax = 500;  // micron
8 const Double_t phimin = 0.0;  
9 const Int_t    mintrackrefsTPC = 2 ;
10 const Int_t    mintrackrefsITS = 3 ;
11 const Int_t    charge  = 1 ;
12 const Int_t    minclustersTPC = 50 ;
13 // cuts
14 const Double_t ptmin = 0.1;
15 const Double_t ptmax = 9999.;
16 const Double_t etamin = -0.9;
17 const Double_t etamax = 0.9;
18 const Double_t zvtxmin = -15;
19 const Double_t zvtxmax = 15;
20 const Int_t    minITSClusters = 5;
21
22 const Float_t centmin_0_10 = 0.;
23 const Float_t centmax_0_10 = 10.;
24 const Float_t centmin_10_60 = 10.;
25 const Float_t centmax_10_60 = 60.;
26 const Float_t centmin_60_100 = 60.;
27 const Float_t centmax_60_100 = 100.;
28 const Float_t centmax = 100.;
29 const Float_t fakemin = -0.5;
30 const Float_t fakemax = 2.5.;
31 const Float_t cosminXY = 0.95;
32 const Float_t cosmaxXY = 1.0;
33 const Float_t normDecLXYmin = 0;
34 const Float_t normDecLXYmax = 20;
35 const Float_t multmin_0_20 = 0;
36 const Float_t multmax_0_20 = 20;
37 const Float_t multmin_20_50 = 20;
38 const Float_t multmax_20_50 = 50;
39 const Float_t multmin_50_102 = 50;
40 const Float_t multmax_50_102 = 102;
41
42
43 //----------------------------------------------------
44
45 AliCFTaskVertexingHF *AddTaskCFVertexingHF3Prong(TString suffixName="", const char* cutFile = "./DplustoKpipiCuts.root", Int_t configuration = AliCFTaskVertexingHF::kCheetah, Bool_t isKeepDfromB=kFALSE, Bool_t isKeepDfromBOnly=kFALSE, Int_t pdgCode = 411, Char_t isSign = 2, TString multFile="", Bool_t useNchWeight=kFALSE)
46 //AliCFContainer *AddTaskCFVertexingHF3Prong(const char* cutFile = "./DplustoKpipiCuts.root", Int_t configuration = AliCFTaskVertexingHF::kSnail, Bool_t isKeepDfromB=kFALSE, Bool_t isKeepDfromBOnly=kFALSE, Int_t pdgCode = 411, Char_t isSign = 2)
47 {
48         printf("Addig CF task using cuts from file %s\n",cutFile);
49         if (configuration == AliCFTaskVertexingHF::kSnail){
50                 printf("The configuration is set to be SLOW --> all the variables will be used to fill the CF\n");
51         }
52         else if (configuration == AliCFTaskVertexingHF::kCheetah){
53                 printf("The configuration is set to be FAST --> using only pt, y, ct, phi, zvtx, centrality, fake, multiplicity to fill the CF\n");
54         }
55         else{
56                 printf("The configuration is not defined! returning\n");
57                 return;
58         }
59                
60         gSystem->Sleep(2000);
61
62         // isSign = 0 --> D+ only
63         // isSign = 1 --> D- only
64         // isSign = 2 --> both
65         
66         TString expected;
67         if (isSign == 0 && pdgCode < 0){
68                 AliError(Form("Error setting PDG code (%d) and sign (0 --> particle (%d) only): they are not compatible, returning",pdgCode));
69                 return 0x0;
70         }
71         else if (isSign == 1 && pdgCode > 0){
72                 AliError(Form("Error setting PDG code (%d) and sign (1 --> antiparticle (%d) only): they are not compatible, returning",pdgCode));
73                 return 0x0;
74         }
75         else if (isSign > 2 || isSign < 0){
76                 AliError(Form("Sign not valid (%d, possible values are 0, 1, 2), returning"));
77                 return 0x0;
78         }
79
80         TFile* fileCuts = TFile::Open(cutFile);
81         if(!fileCuts || (fileCuts && !fileCuts->IsOpen())){ 
82           AliFatal(" Cut file not found");
83           return 0x0;
84         }
85         AliRDHFCutsDplustoKpipi *cutsDplustoKpipi = (AliRDHFCutsDplustoKpipi*)fileCuts->Get("AnalysisCuts");
86         TH1F *hMult=0x0;
87         if(multFile.EqualTo("") ) {
88           printf("Will not be corrected with weights \n");
89         }else{
90           TFile *fileMult = TFile::Open(multFile.Data());
91           TDirectoryFile *dir1 = (TDirectoryFile*)fileMult->Get("PWG3_D2H_DMult_DplusLoose");
92           TList* list1=(TList*)dir1->Get("coutputDplusLoose");
93           hMult=(TH1F*)list1->FindObject("hGenPrimaryParticlesInelGt0");
94         }
95         
96         // check that the fKeepD0fromB flag is set to true when the fKeepD0fromBOnly flag is true
97         //  for now the binning is the same than for all D's
98         if(isKeepDfromBOnly) isKeepDfromB = true;
99         
100         /*
101           Double_t ptmin_0_4;
102           Double_t ptmax_0_4;
103           Double_t ptmin_4_8;
104           Double_t ptmax_4_8;
105           Double_t ptmin_8_10;
106           Double_t ptmax_8_10;
107           
108           if(!isKeepDfromB){
109           ptmin_0_4 =  0.0 ;
110           ptmax_0_4 =  4.0 ;
111           ptmin_4_8 =  4.0 ;
112           ptmax_4_8 =  8.0 ;
113           ptmin_8_10 =  8.0 ;
114           ptmax_8_10 =  10.0 ;
115           } else{
116           ptmin_0_4 =  0.0 ;
117           ptmax_0_4 =  3.0 ;
118           ptmin_4_8 =  3.0 ;
119           ptmax_4_8 =  5.0 ;
120           ptmin_8_10 =  5.0 ;
121           ptmax_8_10 =  10.0 ;
122           }
123         */
124
125         //CONTAINER DEFINITION
126         Info("AliCFTaskVertexingHF","SETUP CONTAINER");
127
128         const Double_t phimax = 2*TMath::Pi();
129
130         //Setting up the container grid... 
131         UInt_t nstep = 10; //number of selection steps: MC with limited acceptance, MC, Acceptance, Vertex, Refit, Reco (no cuts), RecoAcceptance, RecoITSClusters (RecoAcceptance included), RecoPPR (RecoAcceptance+RecoITSCluster included), RecoPID 
132 //      const Int_t nbinpt_0_4  = 8 ; //bins in pt from 0 to 4 GeV
133 //      const Int_t nbinpt_4_8  = 4 ; //bins in pt from 4 to 8 GeV
134 //      const Int_t nbinpt_8_10  = 1 ; //bins in pt from 8 to 10 GeV
135
136 /*
137         Int_t nbinpt_0_4;
138         Int_t nbinpt_4_8;
139         Int_t nbinpt_8_10;
140         if (!isKeepDfromB){
141           nbinpt_0_4  = 8 ; //bins in pt from 0 to 4 GeV
142           nbinpt_4_8  = 4 ; //bins in pt from 4 to 8 GeV
143           nbinpt_8_10  = 1 ; //bins in pt from 8 to 10 GeV
144         }else{
145           nbinpt_0_4  = 3 ; //bins in pt from 0 to 3 GeV
146           nbinpt_4_8  = 1 ; //bins in pt from 3 to 5 GeV
147           nbinpt_8_10  = 1 ; //bins in pt from 5 to 10 GeV
148         }
149 */
150         const Int_t nbinpt = cutsDplustoKpipi->GetNPtBins(); // bins in pT
151         printf("pT: nbin (from cuts file) = %d\n",nbinpt);
152         const Int_t nbiny  = 24 ; //bins in y
153         const Int_t nbinphi  = 18 ; //bins in phi
154         const Int_t nbincT  = 25 ; //bins in cT 
155         const Int_t nbinpointing  = 350 ; //bins in cosPointingAngle    
156         const Int_t nbinpTpi_0_4  = 8 ; //bins in ptPi from 0 to 4 GeV
157         const Int_t nbinpTpi_4_8  = 4 ; //bins in ptPi from 4 to 8 GeV
158         const Int_t nbinpTpi_8_10  = 1 ; //bins in ptPi from 8 to 10 GeV
159         const Int_t nbinpTk_0_4  = 8 ; //bins in ptKa from 0 to 4 GeV
160         const Int_t nbinpTk_4_8  = 4 ; //bins in ptKa from 4 to 8 GeV
161         const Int_t nbinpTk_8_10  = 1 ; //bins in ptKa from 8 to 10 GeV
162         const Int_t nbinpTpi2_0_4  = 8 ; //bins in ptpi2 from 0 to 4 GeV
163         const Int_t nbinpTpi2_4_8  = 4 ; //bins in ptpi2 from 4 to 8 GeV
164         const Int_t nbinpTpi2_8_10  = 1 ; //bins in ptpi2 from 8 to 10 GeV
165         const Int_t nbinzvtx  = 30 ; //bins in z vertex
166         const Int_t nbincent = 18; //bins in centrality
167         const Int_t nbincent_0_10 = 4;  //bins in centrality between 0 and 10
168         const Int_t nbincent_10_60 = 10;  //bins in centrality between 10 and 60
169         const Int_t nbincent_60_100 = 4;  //bins in centrality between 60 and 100
170         const Int_t nbinfake = 3;  //bins in fake
171         const Int_t nbinpointingXY = 50;  //bins in cosPointingAngleXY
172         const Int_t nbinnormDecayLXY = 20;  //bins in NormDecayLengthXY
173         const Int_t nbinmult = 48;  //bins in multiplicity (total number)
174         const Int_t nbinmult_0_20 = 20; //bins in multiplicity between 0 and 20
175         const Int_t nbinmult_20_50 = 15; //bins in multiplicity between 20 and 50
176         const Int_t nbinmult_50_102 = 13; //bins in multiplicity between 50 and 102
177         
178         //the sensitive variables, their indices
179         const UInt_t ipT = 0;
180         const UInt_t iy  = 1;
181         const UInt_t iphi  = 2;
182         const UInt_t icT  = 3;
183         const UInt_t ipointing  = 4;
184         const UInt_t ipTpi  = 5;
185         const UInt_t ipTk  = 6;
186         const UInt_t ipTpi2  = 7;
187         const UInt_t izvtx  = 8;
188         const UInt_t icent = 9;
189         const UInt_t ifake = 10;
190         const UInt_t ipointingXY = 11;
191         const UInt_t inormDecayLXY = 12;
192         const UInt_t imult = 13;
193
194         const Int_t nvarTot   = 14 ; //number of variables on the grid:pt, y, cosThetaStar, pTpi, pTk, cT, dca, d0pi, d0K, d0xd0, cosPointingAngle, phi, zvtx, centrality, fake, cosPointingAngleXY, normDecayLengthXY, multiplicity
195
196         //arrays for the number of bins in each dimension
197         Int_t iBin[nvarTot];
198         //iBin[ipT]=nbinpt_0_4+nbinpt_4_8+nbinpt_8_10;
199         iBin[ipT]=nbinpt;
200         iBin[iy]=nbiny;
201         iBin[iphi]=nbinphi;
202         //      iBin[icT]=nbincT_0_4+nbincT_4_8+nbincT_8_10;
203         //iBin[4]=nbinpointing_0_4+nbinpointing_4_8+nbinpointing_8_10;
204         iBin[icT]=nbincT;
205         iBin[ipointing]=nbinpointing;
206         iBin[ipTpi]=nbinpt;
207         iBin[ipTk]=nbinpt;
208         iBin[ipTpi2]=nbinpt;
209         iBin[izvtx]=nbinzvtx;
210         iBin[icent]=nbincent;
211         iBin[ifake]=nbinfake;
212         iBin[ipointingXY]=nbinpointingXY;
213         iBin[inormDecayLXY]=nbinnormDecayLXY;
214         iBin[imult]=nbinmult;
215         
216         //arrays for lower bounds :
217         Double_t *binLimpT=new Double_t[iBin[ipT]+1];
218         Double_t *binLimy=new Double_t[iBin[iy]+1];
219         Double_t *binLimphi=new Double_t[iBin[iphi]+1];
220         Double_t *binLimcT=new Double_t[iBin[icT]+1];
221         Double_t *binLimpointing=new Double_t[iBin[ipointing]+1];
222         Double_t *binLimpTpi=new Double_t[iBin[ipTpi]+1];
223         Double_t *binLimpTk=new Double_t[iBin[ipTk]+1];
224         Double_t *binLimpTpi2=new Double_t[iBin[ipTpi2]+1];
225         Double_t *binLimzvtx=new Double_t[iBin[izvtx]+1];
226         Double_t *binLimcent=new Double_t[iBin[icent]+1];
227         Double_t *binLimfake=new Double_t[iBin[ifake]+1];
228         Double_t *binLimpointingXY=new Double_t[iBin[ipointingXY]+1];
229         Double_t *binLimnormDecayLXY=new Double_t[iBin[inormDecayLXY]+1];
230         Double_t *binLimmult=new Double_t[iBin[imult]+1];
231         
232         // checking limits
233         /*
234           if (ptmax_0_4 != ptmin_4_8) {
235           Error("AliCFHeavyFlavourTaskMultiVarMultiStep","max lim 1st range != min lim 2nd range, please check!");
236           }
237           if (ptmax_4_8 != ptmin_8_10) {
238           Error("AliCFHeavyFlavourTaskMultiVarMultiStep","max lim 2nd range != min lim 3rd range, please check!");
239           }
240         */
241         // values for bin lower bounds
242         // pt
243         Float_t* floatbinLimpT = cutsDplustoKpipi->GetPtBinLimits();
244         for (Int_t ibinpT = 0 ; ibinpT<iBin[ipT]+1; ibinpT++){
245                 binLimpT[ibinpT] = (Double_t)floatbinLimpT[ibinpT];
246                 binLimpTpi[ibinpT] = (Double_t)floatbinLimpT[ibinpT];
247                 binLimpTk[ibinpT] = (Double_t)floatbinLimpT[ibinpT];
248                 binLimpTpi2[ibinpT] = (Double_t)floatbinLimpT[ibinpT];
249         }
250         for(Int_t i=0; i<=nbinpt; i++) printf("binLimpT[%d]=%f\n",i,binLimpT[i]);  
251         
252         /*
253           for(Int_t i=0; i<=nbinpt_0_4; i++) binLimpT[i]=(Double_t)ptmin_0_4 + (ptmax_0_4-ptmin_0_4)/nbinpt_0_4*(Double_t)i ; 
254           if (binLimpT[nbinpt_0_4] != ptmin_4_8)  {
255           Error("AliCFHeavyFlavourTaskMultiVarMultiStep","Calculated bin lim for pt - 1st range - differs from expected!\n");
256           }
257           for(Int_t i=0; i<=nbinpt_4_8; i++) binLimpT[i+nbinpt_0_4]=(Double_t)ptmin_4_8 + (ptmax_4_8-ptmin_4_8)/nbinpt_4_8*(Double_t)i ; 
258           if (binLimpT[nbinpt_0_4+nbinpt_4_8] != ptmin_8_10)  {
259           Error("AliCFHeavyFlavourTaskMultiVarMultiStep","Calculated bin lim for pt - 2nd range - differs from expected!\n");
260           }
261           for(Int_t i=0; i<=nbinpt_8_10; i++) binLimpT[i+nbinpt_0_4+nbinpt_4_8]=(Double_t)ptmin_8_10 + (ptmax_8_10-ptmin_8_10)/nbinpt_8_10*(Double_t)i ; 
262         */
263         
264         // y
265         for(Int_t i=0; i<=nbiny; i++) binLimy[i]=(Double_t)ymin  + (ymax-ymin)  /nbiny*(Double_t)i ;
266         
267         // Phi
268         for(Int_t i=0; i<=nbinphi; i++) binLimphi[i]=(Double_t)phimin  + (phimax-phimin)  /nbinphi*(Double_t)i ;
269         
270         // cT
271         for(Int_t i=0; i<=nbincT; i++) binLimcT[i]=(Double_t)cTmin  + (cTmax-cTmin)  /nbincT*(Double_t)i ;
272         
273         // cosPointingAngle
274         for(Int_t i=0; i<=nbinpointing; i++) binLimpointing[i]=(Double_t)cosmin  + (cosmax-cosmin)  /nbinpointing*(Double_t)i ;
275
276         /*
277         // ptPi
278         for(Int_t i=0; i<=nbincT_0_4; i++) binLimcT[i]=(Double_t)ptmin_0_4 + (ptmax_0_4-ptmin_0_4)/nbincT_0_4*(Double_t)i ; 
279         if (binLimcT[nbincT_0_4] != ptmin_4_8)  {
280         Error("AliCFHeavyFlavourTaskMultiVarMultiStep","Calculated bin lim for ptPi - 1st range - differs from expected!");
281         }
282         for(Int_t i=0; i<=nbincT_4_8; i++) binLimcT[i+nbincT_0_4]=(Double_t)ptmin_4_8 + (ptmax_4_8-ptmin_4_8)/nbincT_4_8*(Double_t)i ; 
283         if (binLimcT[nbincT_0_4+nbincT_4_8] != ptmin_8_10)  {
284         Error("AliCFHeavyFlavourTaskMultiVarMultiStep","Calculated bin lim for ptPi - 2nd range - differs from expected!\n");
285         }
286         for(Int_t i=0; i<=nbincT_8_10; i++) binLimcT[i+nbincT_0_4+nbincT_4_8]=(Double_t)ptmin_8_10 + (ptmax_8_10-ptmin_8_10)/nbincT_8_10*(Double_t)i ; 
287         
288         // ptKa
289         for(Int_t i=0; i<=nbinpointing_0_4; i++) binLimpointing[i]=(Double_t)ptmin_0_4 + (ptmax_0_4-ptmin_0_4)/nbinpointing_0_4*(Double_t)i ; 
290         if (binLimpointing[nbinpointing_0_4] != ptmin_4_8)  {
291         Error("AliCFHeavyFlavourTaskMultiVarMultiStep","Calculated bin lim for ptKa - 1st range - differs from expected!");
292         }
293         for(Int_t i=0; i<=nbinpointing_4_8; i++) binLimpointing[i+nbinpointing_0_4]=(Double_t)ptmin_4_8 + (ptmax_4_8-ptmin_4_8)/nbinpointing_4_8*(Double_t)i ; 
294         if (binLimpointing[nbinpointing_0_4+nbinpointing_4_8] != ptmin_8_10)  {
295         Error("AliCFHeavyFlavourTaskMultiVarMultiStep","Calculated bin lim for ptKa - 2nd range - differs from expected!\n");
296         }
297         for(Int_t i=0; i<=nbinpointing_8_10; i++) binLimpointing[i+nbinpointing_0_4+nbinpointing_4_8]=(Double_t)ptmin_8_10 + (ptmax_8_10-ptmin_8_10)/nbinpointing_8_10*(Double_t)i ; 
298         */
299         
300         // z Primary Vertex
301         for(Int_t i=0; i<=nbinzvtx; i++) {
302                 binLimzvtx[i]=(Double_t)zvtxmin  + (zvtxmax-zvtxmin)  /nbinzvtx*(Double_t)i ;
303         }
304         
305         // centrality
306        
307         for(Int_t i=0; i<=nbincent_0_10; i++) binLimcent[i]=(Double_t)centmin_0_10 + (centmax_0_10-centmin_0_10)/nbincent_0_10*(Double_t)i ; 
308         if (binLimcent[nbincent_0_10] != centmin_10_60)  {
309           Error("AliCFHeavyFlavourTaskMultiVarMultiStep","Calculated bin lim for cent - 1st range - differs from expected!\n");
310         }
311         for(Int_t i=0; i<=nbincent_10_60; i++) binLimcent[i+nbincent_0_10]=(Double_t)centmin_10_60 + (centmax_10_60-centmin_10_60)/nbincent_10_60*(Double_t)i ;
312         if (binLimcent[nbincent_0_10+nbincent_10_60] != centmin_60_100)  {
313           Error("AliCFHeavyFlavourTaskMultiVarMultiStep","Calculated bin lim for cent - 2st range - differs from expected!\n");
314         }
315         for(Int_t i=0; i<=nbincent_60_100; i++) binLimcent[i+nbincent_0_10+nbincent_10_60]=(Double_t)centmin_60_100 + (centmax_60_100-centmin_60_100)/nbincent_60_100*(Double_t)i ;
316         
317         // fake
318         for(Int_t i=0; i<=nbinfake; i++) {
319           binLimfake[i]=(Double_t)fakemin  + (fakemax-fakemin)/nbinfake * (Double_t)i;
320         }
321
322         // cosPointingAngleXY
323         for(Int_t i=0; i<=nbinpointingXY; i++) binLimpointingXY[i]=(Double_t)cosminXY  + (cosmaxXY-cosminXY)  /nbinpointingXY*(Double_t)i ;
324
325         // normDecayLXY
326         for(Int_t i=0; i<=nbinnormDecayLXY; i++) binLimnormDecayLXY[i]=(Double_t)normDecLXYmin  + (normDecLXYmax-normDecLXYmin)  /nbinnormDecayLXY*(Double_t)i ;
327
328         // multiplicity
329         for(Int_t i=0; i<=nbinmult_0_20; i++) binLimmult[i]=(Double_t)multmin_0_20 + (multmax_0_20-multmin_0_20)/nbinmult_0_20*(Double_t)i ; 
330         if (binLimmult[nbinmult_0_20] != multmin_20_50)  {
331                 Error("AliCFHeavyFlavourTaskMultiVarMultiStep","Calculated bin lim for mult - 1st range - differs from expected!\n");
332         }
333         for(Int_t i=0; i<=nbinmult_20_50; i++) binLimmult[i+nbinmult_0_20]=(Double_t)multmin_20_50 + (multmax_20_50-multmin_20_50)/nbinmult_20_50*(Double_t)i ; 
334         if (binLimmult[nbinmult_0_20+nbinmult_20_50] != multmin_50_102)  {
335                 Error("AliCFHeavyFlavourTaskMultiVarMultiStep","Calculated bin lim for mult - 2nd range - differs from expected!\n");
336         }
337         for(Int_t i=0; i<=nbinmult_50_102; i++) binLimmult[i+nbinmult_0_20+nbinmult_20_50]=(Double_t)multmin_50_102 + (multmax_50_102-multmin_50_102)/nbinmult_50_102*(Double_t)i ; 
338         
339         //one "container" for MC
340         TString nameContainer="";
341         if(!isKeepDfromB) {
342                 nameContainer="CFHFcontainer_DplustoKpipi_Prompt";
343                 
344         }
345         else  if(isKeepDfromBOnly){
346                 nameContainer="CFHFcontainer_DplustoKpipi_FromB";
347                 
348         }
349         else  {
350           nameContainer="CFHFcontainer_DplustoKpipi_All";
351         }
352         nameContainer += suffixName.Data();
353
354         
355         AliCFContainer* container;
356         if (configuration == AliCFTaskVertexingHF::kSnail){
357                 container = new AliCFContainer(nameContainer,"container for tracks",nstep,nvarTot,iBin);
358                 //setting the bin limits
359                 printf("pt\n");
360                 container -> SetBinLimits(ipT,binLimpT);
361                 printf("y\n");
362                 container -> SetBinLimits(iy,binLimy);
363                 printf("Phi\n");
364                 container -> SetBinLimits(iphi,binLimphi);
365                 printf("cT\n");
366                 container -> SetBinLimits(icT,binLimcT);
367                 printf("pointing angle\n");
368                 container -> SetBinLimits(ipointing,binLimpointing);
369                 printf("ptpi\n");
370                 container -> SetBinLimits(ipTpi,binLimpTpi);
371                 printf("ptK\n");
372                 container -> SetBinLimits(ipTk,binLimpTk);
373                 printf("ptpi2\n");
374                 container -> SetBinLimits(ipTpi2,binLimpTpi2);
375                 printf("zvtx \n");
376                 container -> SetBinLimits(izvtx,binLimzvtx);
377                 printf("cent\n");
378                 container -> SetBinLimits(icent,binLimcent);
379                 printf("fake\n");
380                 container -> SetBinLimits(ifake,binLimfake);
381                 printf("pointingXY\n");
382                 container -> SetBinLimits(ipointingXY,binLimpointingXY);
383                 printf("normDecayLXY\n");
384                 container -> SetBinLimits(inormDecayLXY,binLimnormDecayLXY);
385                 printf("multiplicity\n");
386                 container -> SetBinLimits(imult,binLimmult);
387                 
388                 container -> SetVarTitle(ipT,"pt");
389                 container -> SetVarTitle(iy,"y");
390                 container -> SetVarTitle(iphi, "phi");
391                 container -> SetVarTitle(icT, "ct");
392                 container -> SetVarTitle(ipointing, "pointing");        
393                 container -> SetVarTitle(ipTpi, "ptpi");
394                 container -> SetVarTitle(ipTk, "ptK");
395                 container -> SetVarTitle(ipTpi2, "ptpi2");
396                 container -> SetVarTitle(izvtx, "zvtx");
397                 container -> SetVarTitle(icent, "centrality");
398                 container -> SetVarTitle(ifake, "fake");
399                 container -> SetVarTitle(ipointingXY, "piointingXY");
400                 container -> SetVarTitle(inormDecayLXY, "normDecayLXY");
401                 container -> SetVarTitle(imult, "multiplicity");
402         }
403         else if (configuration == AliCFTaskVertexingHF::kCheetah){
404                 //arrays for the number of bins in each dimension
405                 const Int_t nvar = 8;
406
407                 const UInt_t ipTFast = 0;
408                 const UInt_t iyFast = 1;
409                 const UInt_t icTFast = 2;
410                 const UInt_t iphiFast = 3;
411                 const UInt_t izvtxFast = 4;
412                 const UInt_t icentFast = 5;
413                 const UInt_t ifakeFast = 6;
414                 const UInt_t imultFast = 7;
415
416                 Int_t iBinFast[nvar];
417                 iBinFast[ipTFast] = iBin[ipT];
418                 iBinFast[iyFast] = iBin[iy];
419                 iBinFast[icTFast] = iBin[icT];
420                 iBinFast[iphiFast] = iBin[iphi];
421                 iBinFast[izvtxFast] = iBin[izvtx];
422                 iBinFast[icentFast] = iBin[icent];
423                 iBinFast[ifakeFast] = iBin[ifake];
424                 iBinFast[imultFast] = iBin[imult];
425
426                 container = new AliCFContainer(nameContainer,"container for tracks",nstep,nvar,iBinFast);
427                 printf("pt\n");
428                 container -> SetBinLimits(ipTFast,binLimpT);
429                 printf("y\n");
430                 container -> SetBinLimits(iyFast,binLimy);
431                 printf("ct\n");
432                 container -> SetBinLimits(icTFast,binLimcT);
433                 printf("phi\n");
434                 container -> SetBinLimits(iphiFast,binLimphi);
435                 printf("zvtx\n");
436                 container -> SetBinLimits(izvtxFast,binLimzvtx);
437                 printf("centrality\n");
438                 container -> SetBinLimits(icentFast,binLimcent);
439                 printf("fake\n");
440                 container -> SetBinLimits(ifakeFast,binLimfake);
441                 printf("multiplicity\n");
442                 container -> SetBinLimits(imultFast,binLimmult);
443
444                 container -> SetVarTitle(ipTFast,"pt");
445                 container -> SetVarTitle(iyFast,"y");
446                 container -> SetVarTitle(icTFast, "ct");
447                 container -> SetVarTitle(iphiFast, "phi");
448                 container -> SetVarTitle(izvtxFast, "zvtx");
449                 container -> SetVarTitle(icentFast, "centrality");
450                 container -> SetVarTitle(ifakeFast, "fake");
451                 container -> SetVarTitle(imultFast, "multiplicity");
452         }
453
454         //return container;
455
456         container -> SetStepTitle(0, "MCLimAcc");
457         container -> SetStepTitle(1, "MC");
458         container -> SetStepTitle(2, "MCAcc");
459         container -> SetStepTitle(3, "RecoVertex");
460         container -> SetStepTitle(4, "RecoRefit");
461         container -> SetStepTitle(5, "Reco");
462         container -> SetStepTitle(6, "RecoAcc");
463         container -> SetStepTitle(7, "RecoITSCluster");
464         container -> SetStepTitle(8, "RecoCuts");
465         container -> SetStepTitle(9, "RecoPID");
466
467
468         //CREATE THE  CUTS -----------------------------------------------
469         
470         // Gen-Level kinematic cuts
471         AliCFTrackKineCuts *mcKineCuts = new AliCFTrackKineCuts("mcKineCuts","MC-level kinematic cuts");
472         
473         //Particle-Level cuts:  
474         AliCFParticleGenCuts* mcGenCuts = new AliCFParticleGenCuts("mcGenCuts","MC particle generation cuts");
475         Bool_t useAbsolute = kTRUE;
476         if (isSign != 2){
477                 useAbsolute = kFALSE;
478         }
479         mcGenCuts->SetRequirePdgCode(pdgCode, useAbsolute);  // kTRUE set in order to include antiparticle
480         mcGenCuts->SetAODMC(1); //special flag for reading MC in AOD tree (important)
481         
482         // Acceptance cuts:
483         AliCFAcceptanceCuts* accCuts = new AliCFAcceptanceCuts("accCuts", "Acceptance cuts");
484         AliCFTrackKineCuts *kineAccCuts = new AliCFTrackKineCuts("kineAccCuts","Kine-Acceptance cuts");
485         kineAccCuts->SetPtRange(ptmin,ptmax);
486         kineAccCuts->SetEtaRange(etamin,etamax);
487
488         // Rec-Level kinematic cuts
489         AliCFTrackKineCuts *recKineCuts = new AliCFTrackKineCuts("recKineCuts","rec-level kine cuts");
490         
491         AliCFTrackQualityCuts *recQualityCuts = new AliCFTrackQualityCuts("recQualityCuts","rec-level quality cuts");
492         
493         AliCFTrackIsPrimaryCuts *recIsPrimaryCuts = new AliCFTrackIsPrimaryCuts("recIsPrimaryCuts","rec-level isPrimary cuts");
494         
495         printf("CREATE MC KINE CUTS\n");
496         TObjArray* mcList = new TObjArray(0) ;
497         mcList->AddLast(mcKineCuts);
498         mcList->AddLast(mcGenCuts);
499         
500         printf("CREATE ACCEPTANCE CUTS\n");
501         TObjArray* accList = new TObjArray(0) ;
502         accList->AddLast(kineAccCuts);
503
504         printf("CREATE RECONSTRUCTION CUTS\n");
505         TObjArray* recList = new TObjArray(0) ;   // not used!! 
506         recList->AddLast(recKineCuts);
507         recList->AddLast(recQualityCuts);
508         recList->AddLast(recIsPrimaryCuts);
509         
510         TObjArray* emptyList = new TObjArray(0);
511
512         //CREATE THE INTERFACE TO CORRECTION FRAMEWORK USED IN THE TASK
513         printf("CREATE INTERFACE AND CUTS\n");
514         AliCFManager* man = new AliCFManager() ;
515         man->SetParticleContainer(container);
516         man->SetParticleCutsList(0 , mcList); // MC, Limited Acceptance
517         man->SetParticleCutsList(1 , mcList); // MC
518         man->SetParticleCutsList(2 , accList); // Acceptance 
519         man->SetParticleCutsList(3 , emptyList); // Vertex 
520         man->SetParticleCutsList(4 , emptyList); // Refit 
521         man->SetParticleCutsList(5 , emptyList); // AOD
522         man->SetParticleCutsList(6 , emptyList); // AOD in Acceptance
523         man->SetParticleCutsList(7 , emptyList); // AOD with required n. of ITS clusters
524         man->SetParticleCutsList(8 , emptyList); // AOD Reco (PPR cuts implemented in Task)
525         man->SetParticleCutsList(9 , emptyList); // AOD Reco PID
526         
527         // Get the pointer to the existing analysis manager via the static access method.
528         //==============================================================================
529         AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
530         if (!mgr) {
531           ::Error("AddTaskCompareHF", "No analysis manager to connect to.");
532           return NULL;
533         }   
534         //CREATE THE TASK
535         printf("CREATE TASK\n");
536
537         // create the task
538         AliCFTaskVertexingHF *task = new AliCFTaskVertexingHF("AliCFTaskVertexingHF",cutsDplustoKpipi);
539         task->SetFillFromGenerated(kFALSE);
540         task->SetDecayChannel(31);
541         task->SetUseWeight(kFALSE);
542         task->SetCFManager(man); //here is set the CF manager
543         task->SetSign(isSign);
544         task->SetCentralitySelection(kFALSE);
545         task->SetFakeSelection(0);
546         task->SetRejectCandidateIfNotFromQuark(kTRUE); // put to false if you want to keep HIJING D0!!
547         task->SetUseMCVertex(kFALSE); // put to true if you want to do studies on pp
548         task->SetUseNchWeight(useNchWeight); //correction with mult weight
549         if(useNchWeight){
550           if(hMult) task->SetMCNchHisto(hMult);
551           else{
552             AliFatal("Histogram for multiplicity weights not found");
553             return 0x0;
554           }
555         }
556         if (isKeepDfromB && !isKeepDfromBOnly) task->SetDselection(2);
557         if (isKeepDfromB && isKeepDfromBOnly) task->SetDselection(1);           
558
559         TF1* funcWeight = 0x0;
560         if (task->GetUseWeight()) {
561                 funcWeight = (TF1*)cutFile->Get("funcWeight");
562                 if (funcWeight == 0x0){
563                         Printf("FONLL Weights will be used");
564                 }
565                 else {
566                         task->SetWeightFunction(funcWeight);
567                         Printf("User-defined Weights will be used. The function being:");
568                         task->GetWeightFunction()->Print();
569                 }
570         }
571
572         Printf("***************** CONTAINER SETTINGS *****************");
573         Printf("decay channel = %d",(Int_t)task->GetDecayChannel());
574         Printf("FillFromGenerated = %d",(Int_t)task->GetFillFromGenerated());
575         Printf("Dselection = %d",(Int_t)task->GetDselection());
576         Printf("Sign = %d",(Int_t)task->GetSign());
577         Printf("Centrality selection = %d",(Int_t)task->GetCentralitySelection());
578         Printf("Fake selection = %d",(Int_t)task->GetFakeSelection());
579         Printf("RejectCandidateIfNotFromQuark selection = %d",(Int_t)task->GetRejectCandidateIfNotFromQuark());
580         Printf("UseMCVertex selection = %d",(Int_t)task->GetUseMCVertex());
581         Printf("***************END CONTAINER SETTINGS *****************\n");
582
583         //-----------------------------------------------------------//
584         //   create correlation matrix for unfolding - only eta-pt   //
585         //-----------------------------------------------------------//
586
587         Bool_t AcceptanceUnf = kTRUE; // unfold at acceptance level, otherwise PPR
588
589         Int_t thnDim[4];
590         
591         //first half  : reconstructed 
592         //second half : MC
593
594         thnDim[0] = iBin[ipT];
595         thnDim[2] = iBin[ipT];
596         thnDim[1] = iBin[iy];
597         thnDim[3] = iBin[iy];
598
599         TString nameCorr="";
600         if(!isKeepDfromB) {
601                 nameCorr="CFHFcorr_DplustoKpipi_Prompt";
602         }
603         else  if(isKeepDfromBOnly){
604                 nameCorr="CFHFcorr_DplustoKpipi_FromB";
605         }
606         else  {
607                 nameCorr="CFHFcorr_DplustoKpipi_All";
608         }
609         nameCorr += suffixName.Data();
610         
611
612         THnSparseD* correlation = new THnSparseD(nameCorr,"THnSparse with correlations",4,thnDim);
613         Double_t** binEdges = new Double_t[2];
614
615         // set bin limits
616
617         binEdges[0]= binLimpT;
618         binEdges[1]= binLimy;
619
620         correlation->SetBinEdges(0,binEdges[0]);
621         correlation->SetBinEdges(2,binEdges[0]);
622
623         correlation->SetBinEdges(1,binEdges[1]);
624         correlation->SetBinEdges(3,binEdges[1]);
625
626         correlation->Sumw2();
627   
628         // correlation matrix ready
629         //------------------------------------------------//
630
631         task->SetCorrelationMatrix(correlation); // correlation matrix for unfolding
632         
633         // Create and connect containers for input/output
634         
635         // ------ input data ------
636         AliAnalysisDataContainer *cinput0  = mgr->GetCommonInputContainer();
637         
638         // ----- output data -----
639         
640         TString outputfile = AliAnalysisManager::GetCommonFileName();
641         TString output1name="", output2name="", output3name="", output4name="";;
642         output2name=nameContainer;
643         output3name=nameCorr;
644         if(!isKeepDfromB) {
645                 outputfile += ":PWG3_D2H_CFtaskDplustoKpipi_Prompt";
646                 output1name="CFHFhist_DplustoKpipi_Prompt";
647                 output4name= "Cuts_DplustoKpipi_Prompt";
648         }
649         else  if(isKeepDfromBOnly){
650                 outputfile += ":PWG3_D2H_CFtaskDplustoKpipi_FromB";
651                 output1name="CFHFhist_DplustoKpipi_FromB";
652                 output4name= "Cuts_DplustoKpipi_FromB";
653         }
654         else{
655                 outputfile += ":PWG3_D2H_CFtaskDplustoKpipi_All";
656                 output1name="CFHFhist_DplustoKpipi_All";
657                 output4name= "Cuts_DplustoKpipi_All";
658         }
659         outputfile += suffixName.Data();
660         output1name += suffixName.Data();
661         output4name += suffixName.Data();
662         
663
664         //now comes user's output objects :
665         // output TH1I for event counting
666         AliAnalysisDataContainer *coutput1 = mgr->CreateContainer(output1name, TH1I::Class(),AliAnalysisManager::kOutputContainer,outputfile.Data());
667         // output Correction Framework Container (for acceptance & efficiency calculations)
668         AliAnalysisDataContainer *coutput2 = mgr->CreateContainer(output2name, AliCFContainer::Class(),AliAnalysisManager::kOutputContainer,outputfile.Data());
669         // Unfolding - correlation matrix
670         AliAnalysisDataContainer *coutput3 = mgr->CreateContainer(output3name, THnSparseD::Class(),AliAnalysisManager::kOutputContainer,outputfile.Data());
671         AliAnalysisDataContainer *coutput4 = mgr->CreateContainer(output4name, AliRDHFCuts::Class(),AliAnalysisManager::kOutputContainer, outputfile.Data());
672
673         mgr->AddTask(task);
674         
675         mgr->ConnectInput(task,0,mgr->GetCommonInputContainer());
676         mgr->ConnectOutput(task,1,coutput1);
677         mgr->ConnectOutput(task,2,coutput2);
678         mgr->ConnectOutput(task,3,coutput3);
679         mgr->ConnectOutput(task,4,coutput4);
680
681         return task;
682         }
683