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