55ad9b7b9534d70ab7a6bb08a76031c1874565e9
[u/mrichter/AliRoot.git] / PWG3 / vertexingHF / macros / AddTaskCFMultiVarMultiStep.C
1 //DEFINITION OF A FEW CONSTANTS
2 const Double_t ymin  = -2.1 ;
3 const Double_t ymax  =  2.1 ;
4 // const Double_t ptmin_0_4 =  0.0 ;
5 // const Double_t ptmax_0_4 =  4.0 ;
6 // const Double_t ptmin_4_8 =  4.0 ;
7 // const Double_t ptmax_4_8 =  8.0 ;
8 // const Double_t ptmin_8_10 =  8.0 ;
9 // const Double_t ptmax_8_10 =  10.0 ;
10 const Double_t cosmin = -1.05;
11 const Double_t cosmax =  1.05;
12 const Double_t cTmin = 0;  // micron
13 const Double_t cTmax = 500;  // micron
14 const Double_t dcamin = 0;  // micron
15 const Double_t dcamax = 500;  // micron
16 const Double_t d0min = -1000;  // micron
17 const Double_t d0max = 1000;  // micron
18 const Double_t d0xd0min = -100000;  // micron
19 const Double_t d0xd0max = 100000;  // micron
20 const Double_t phimin = 0.0;  
21 //const Double_t phimax = 2Pi;  // defined in the macro!!!!!!!!!!!!!!  
22 const Int_t    mintrackrefsTPC = 2 ;
23 const Int_t    mintrackrefsITS = 3 ;
24 const Int_t    charge  = 1 ;
25 const Int_t    PDG = 421; 
26 const Int_t    minclustersTPC = 50 ;
27 // cuts
28 const Double_t ptmin = 0.1;
29 const Double_t ptmax = 9999.;
30 const Double_t etamin = -0.9;
31 const Double_t etamax = 0.9;
32 const Double_t zmin = -15;
33 const Double_t zmax = 15;
34 const Int_t    minITSClusters = 5;
35
36 //----------------------------------------------------
37
38 AliCFHeavyFlavourTaskMultiVarMultiStep *AddTaskCFMultiVarMultiStep(const char* cutFile = "./D0toKpiCuts.root",Bool_t isKeepD0fromB=kFALSE, Bool_t isKeepD0fromBOnly=kFALSE)
39 {
40         printf("Adding CF task using cuts from file %s\n",cutFile);
41         
42         TFile* fileCuts = new TFile(cutFile);
43         AliRDHFCutsD0toKpi *cutsD0toKpi = (AliRDHFCutsD0toKpi*)fileCuts->Get("D0toKpiCutsStandard");
44         
45         // check that the fKeepD0fromB flag is set to true when the fKeepD0fromBOnly flag is true
46         //  for now the binning is the same than for all D's
47         if(isKeepD0fromBOnly) isKeepD0fromB = true;
48         
49         Double_t ptmin_0_4;
50         Double_t ptmax_0_4;
51         Double_t ptmin_4_8;
52         Double_t ptmax_4_8;
53         Double_t ptmin_8_10;
54         Double_t ptmax_8_10;
55         
56         if(!isKeepD0fromB){
57                 ptmin_0_4 =  0.0 ;
58                 ptmax_0_4 =  4.0 ;
59                 ptmin_4_8 =  4.0 ;
60                 ptmax_4_8 =  8.0 ;
61                 ptmin_8_10 =  8.0 ;
62                 ptmax_8_10 =  10.0 ;
63         } else{
64                 ptmin_0_4 =  0.0 ;
65                 ptmax_0_4 =  3.0 ;
66                 ptmin_4_8 =  3.0 ;
67                 ptmax_4_8 =  5.0 ;
68                 ptmin_8_10 =  5.0 ;
69                 ptmax_8_10 =  10.0 ;
70         }
71   
72
73         //CONTAINER DEFINITION
74         Info("AliCFHeavyFlavourTaskMultiVarMultiStep","SETUP CONTAINER");
75         //the sensitive variables, their indices
76         UInt_t ipt = 0;
77         UInt_t iy  = 1;
78         UInt_t icosThetaStar  = 2;
79         UInt_t ipTpi  = 3;
80         UInt_t ipTk  = 4;
81         UInt_t icT  = 5;
82         UInt_t idca  = 6;
83         UInt_t id0pi  = 7;
84         UInt_t id0K  = 8;
85         UInt_t id0xd0  = 9;
86         UInt_t ipointing  = 10;
87         UInt_t iphi  = 11;
88         UInt_t iz  = 12;
89         
90         const Double_t phimax = 2*TMath::Pi();
91         
92         //Setting up the container grid... 
93         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 
94         const Int_t nvar   = 13 ; //number of variables on the grid:pt, y, cosThetaStar, pTpi, pTk, cT, dca, d0pi, d0K, d0xd0, cosPointingAngle, phi 
95
96         //Setting the bins: pt, ptPi, and ptK are considered seprately because for them you can either define the binning by hand, or using the cuts file
97
98         //arrays for the number of bins in each dimension
99         Int_t iBin[nvar];
100
101         //OPTION 1: defining the pt, ptPi, ptK bins by hand...          
102         Int_t nbin0_0_4;
103         Int_t nbin0_4_8;
104         Int_t nbin0_8_10;
105         if (!isKeepD0fromB){
106                 nbin0_0_4  = 8 ; //bins in pt from 0 to 4 GeV
107                 nbin0_4_8  = 4 ; //bins in pt from 4 to 8 GeV
108                 nbin0_8_10  = 1 ; //bins in pt from 8 to 10 GeV
109         }else{
110                 nbin0_0_4  = 3 ; //bins in pt from 0 to 3 GeV
111                 nbin0_4_8  = 1 ; //bins in pt from 3 to 5 GeV
112                 nbin0_8_10  = 1 ; //bins in pt from 5 to 10 GeV
113         }
114         const Int_t nbin3_0_4  = 8 ; //bins in ptPi from 0 to 4 GeV
115         const Int_t nbin3_4_8  = 4 ; //bins in ptPi from 4 to 8 GeV
116         const Int_t nbin3_8_10  = 1 ; //bins in ptPi from 8 to 10 GeV
117         const Int_t nbin4_0_4  = 8 ; //bins in ptKa from 0 to 4 GeV
118         const Int_t nbin4_4_8  = 4 ; //bins in ptKa from 4 to 8 GeV
119         const Int_t nbin4_8_10  = 1 ; //bins in ptKa from 8 to 10 GeV
120         iBin[0]=nbin0_0_4+nbin0_4_8+nbin0_8_10;
121         iBin[3]=nbin3_0_4+nbin3_4_8+nbin3_8_10;
122         iBin[4]=nbin4_0_4+nbin4_4_8+nbin4_8_10;
123         Double_t *binLim0=new Double_t[iBin[0]+1];
124         Double_t *binLim3=new Double_t[iBin[3]+1];
125         Double_t *binLim4=new Double_t[iBin[4]+1];
126
127         // values for bin lower bounds
128         // pt
129         for(Int_t i=0; i<=nbin0_0_4; i++) binLim0[i]=(Double_t)ptmin_0_4 + (ptmax_0_4-ptmin_0_4)/nbin0_0_4*(Double_t)i ; 
130         if (binLim0[nbin0_0_4] != ptmin_4_8)  {
131                 Error("AliCFHeavyFlavourTaskMultiVarMultiStep","Calculated bin lim for pt - 1st range - differs from expected!\n");
132         }
133         for(Int_t i=0; i<=nbin0_4_8; i++) binLim0[i+nbin0_0_4]=(Double_t)ptmin_4_8 + (ptmax_4_8-ptmin_4_8)/nbin0_4_8*(Double_t)i ; 
134         if (binLim0[nbin0_0_4+nbin0_4_8] != ptmin_8_10)  {
135                 Error("AliCFHeavyFlavourTaskMultiVarMultiStep","Calculated bin lim for pt - 2nd range - differs from expected!\n");
136         }
137         for(Int_t i=0; i<=nbin0_8_10; i++) binLim0[i+nbin0_0_4+nbin0_4_8]=(Double_t)ptmin_8_10 + (ptmax_8_10-ptmin_8_10)/nbin0_8_10*(Double_t)i ; 
138         // ptPi
139         for(Int_t i=0; i<=nbin3_0_4; i++) binLim3[i]=(Double_t)ptmin_0_4 + (ptmax_0_4-ptmin_0_4)/nbin3_0_4*(Double_t)i ; 
140         if (binLim3[nbin3_0_4] != ptmin_4_8)  {
141                 Error("AliCFHeavyFlavourTaskMultiVarMultiStep","Calculated bin lim for ptPi - 1st range - differs from expected!");
142         }
143         for(Int_t i=0; i<=nbin3_4_8; i++) binLim3[i+nbin3_0_4]=(Double_t)ptmin_4_8 + (ptmax_4_8-ptmin_4_8)/nbin3_4_8*(Double_t)i ; 
144         if (binLim3[nbin3_0_4+nbin3_4_8] != ptmin_8_10)  {
145                 Error("AliCFHeavyFlavourTaskMultiVarMultiStep","Calculated bin lim for ptPi - 2nd range - differs from expected!\n");
146         }
147         for(Int_t i=0; i<=nbin3_8_10; i++) binLim3[i+nbin3_0_4+nbin3_4_8]=(Double_t)ptmin_8_10 + (ptmax_8_10-ptmin_8_10)/nbin3_8_10*(Double_t)i ; 
148
149         // ptKa
150         for(Int_t i=0; i<=nbin4_0_4; i++) binLim4[i]=(Double_t)ptmin_0_4 + (ptmax_0_4-ptmin_0_4)/nbin4_0_4*(Double_t)i ; 
151         if (binLim4[nbin4_0_4] != ptmin_4_8)  {
152                 Error("AliCFHeavyFlavourTaskMultiVarMultiStep","Calculated bin lim for ptKa - 1st range - differs from expected!");
153         }
154         for(Int_t i=0; i<=nbin4_4_8; i++) binLim4[i+nbin4_0_4]=(Double_t)ptmin_4_8 + (ptmax_4_8-ptmin_4_8)/nbin4_4_8*(Double_t)i ; 
155         if (binLim4[nbin4_0_4+nbin4_4_8] != ptmin_8_10)  {
156                 Error("AliCFHeavyFlavourTaskMultiVarMultiStep","Calculated bin lim for ptKa - 2nd range - differs from expected!\n");
157         }
158         for(Int_t i=0; i<=nbin4_8_10; i++) binLim4[i+nbin4_0_4+nbin4_4_8]=(Double_t)ptmin_8_10 + (ptmax_8_10-ptmin_8_10)/nbin4_8_10*(Double_t)i ; 
159         
160         
161         //OPTION 2: ...or from the cuts file
162
163         //const Int_t nbin0 = cutsD0toKpi->GetNPtBins(); // bins in pT
164         //iBin[0]=nbin0;
165         //iBin[3]=nbin0;
166         //iBin[4]=nbin0;
167         // values for bin lower bounds
168         //Float_t* floatbinLim0 = cutsD0toKpi->GetPtBinLimits();
169         //for (Int_t ibin0 = 0 ; ibin0<iBin[0]+1; ibin0++){
170         //      binLim0[ibin0] = (Double_t)floatbinLim0[ibin0];
171         //      binLim3[ibin0] = (Double_t)floatbinLim0[ibin0];
172         //      binLim4[ibin0] = (Double_t)floatbinLim0[ibin0];
173         //}
174         //for(Int_t i=0; i<=nbin0; i++) printf("binLim0[%d]=%f\n",i,binLim0[i]);  
175
176         //printf("pT: nbin (from cuts file) = %d\n",nbin0);
177
178         // defining now the binning for the other variables:
179
180         const Int_t nbin1  = 42 ; //bins in y
181         const Int_t nbin2  = 42 ; //bins in cosThetaStar 
182         const Int_t nbin5  = 24 ; //bins in cT
183         const Int_t nbin6  = 24 ; //bins in dca
184         const Int_t nbin7  = 100 ; //bins in d0pi
185         const Int_t nbin8  = 100 ; //bins in d0K
186         const Int_t nbin9  = 80 ; //bins in d0xd0
187         const Int_t nbin10  = 1050 ; //bins in cosPointingAngle
188         const Int_t nbin11  = 20 ; //bins in Phi
189         const Int_t nbin12  = 60 ; //bins in z vertex
190
191         iBin[1]=nbin1;
192         iBin[2]=nbin2;
193         iBin[5]=nbin5;
194         iBin[6]=nbin6;
195         iBin[7]=nbin7;
196         iBin[8]=nbin8;
197         iBin[9]=nbin9;
198         iBin[10]=nbin10;
199         iBin[11]=nbin11;
200         iBin[12]=nbin12;
201         
202         //arrays for lower bounds :
203         Double_t *binLim1=new Double_t[iBin[1]+1];
204         Double_t *binLim2=new Double_t[iBin[2]+1];
205         Double_t *binLim5=new Double_t[iBin[5]+1];
206         Double_t *binLim6=new Double_t[iBin[6]+1];
207         Double_t *binLim7=new Double_t[iBin[7]+1];
208         Double_t *binLim8=new Double_t[iBin[8]+1];
209         Double_t *binLim9=new Double_t[iBin[9]+1];
210         Double_t *binLim10=new Double_t[iBin[10]+1];
211         Double_t *binLim11=new Double_t[iBin[11]+1];
212         Double_t *binLim12=new Double_t[iBin[12]+1];
213
214         // y
215         for(Int_t i=0; i<=nbin1; i++) binLim1[i]=(Double_t)ymin  + (ymax-ymin)  /nbin1*(Double_t)i ;
216
217         // cosThetaStar
218         for(Int_t i=0; i<=nbin2; i++) binLim2[i]=(Double_t)cosmin  + (cosmax-cosmin)  /nbin2*(Double_t)i ;
219         
220         // cT
221         for(Int_t i=0; i<=nbin5; i++) binLim5[i]=(Double_t)cTmin  + (cTmax-cTmin)  /nbin5*(Double_t)i ;
222
223         // dca
224         for(Int_t i=0; i<=nbin6; i++) binLim6[i]=(Double_t)dcamin  + (dcamax-dcamin)  /nbin6*(Double_t)i ;
225
226         // d0pi
227         for(Int_t i=0; i<=nbin7; i++) binLim7[i]=(Double_t)d0min  + (d0max-d0min)  /nbin7*(Double_t)i ;
228
229         // d0K
230         for(Int_t i=0; i<=nbin8; i++) binLim8[i]=(Double_t)d0min  + (d0max-d0min)  /nbin8*(Double_t)i ;
231
232         // d0xd0
233         for(Int_t i=0; i<=nbin9; i++) binLim9[i]=(Double_t)d0xd0min  + (d0xd0max-d0xd0min)  /nbin9*(Double_t)i ;
234
235         // cosPointingAngle
236         for(Int_t i=0; i<=nbin10; i++) binLim10[i]=(Double_t)cosmin  + (cosmax-cosmin)  /nbin10*(Double_t)i ;
237
238         // Phi
239         for(Int_t i=0; i<=nbin11; i++) binLim11[i]=(Double_t)phimin  + (phimax-phimin)  /nbin11*(Double_t)i ;
240
241         // z Primary Vertex
242         for(Int_t i=0; i<=nbin12; i++) {
243                 binLim12[i]=(Double_t)zmin  + (zmax-zmin)  /nbin12*(Double_t)i ;
244                 //              Info("AliCFHeavyFlavourTaskMultiVarMultiStep",Form("i-th bin, lower limit = %f", binLim12[i]));
245         }
246
247         //one "container" for MC
248         TString nameContainer="";
249         if(!isKeepD0fromB) {
250           nameContainer="CFHFccontainer0";
251         }
252         else if(isKeepD0fromBOnly){
253           nameContainer="CFHFccontainer0D0fromB";
254         }
255         else  {
256           nameContainer="CFHFccontainer0allD0";
257
258         }
259
260         AliCFContainer* container = new AliCFContainer(nameContainer,"container for tracks",nstep,nvar,iBin);
261         //setting the bin limits
262         printf("pt\n");
263         container -> SetBinLimits(ipt,binLim0);
264         printf("y\n");
265         container -> SetBinLimits(iy,binLim1);
266         printf("cts\n");
267         container -> SetBinLimits(icosThetaStar,binLim2);
268         printf("ptPi\n");
269         container -> SetBinLimits(ipTpi,binLim3);
270         printf("ptK\n");
271         container -> SetBinLimits(ipTk,binLim4);
272         printf("cT\n");
273         container -> SetBinLimits(icT,binLim5);
274         printf("dca\n");
275         container -> SetBinLimits(idca,binLim6);
276         printf("d0Pi\n");
277         container -> SetBinLimits(id0pi,binLim7);
278         printf("d0K\n");
279         container -> SetBinLimits(id0K,binLim8);
280         printf("d0xd0\n");
281         container -> SetBinLimits(id0xd0,binLim9);
282         printf("pointing\n");
283         container -> SetBinLimits(ipointing,binLim10);
284         printf("phi\n");
285         container -> SetBinLimits(iphi,binLim11);
286         printf("z\n");
287         container -> SetBinLimits(iz,binLim12);
288         
289         container -> SetStepTitle(0, "MCLimAcc");
290         container -> SetStepTitle(1, "MC");
291         container -> SetStepTitle(2, "MCAcc");
292         container -> SetStepTitle(3, "RecoVertex");
293         container -> SetStepTitle(4, "RecoRefit");
294         container -> SetStepTitle(5, "Reco");
295         container -> SetStepTitle(6, "RecoAcc");
296         container -> SetStepTitle(7, "RecoITSCluster");
297         container -> SetStepTitle(8, "RecoCuts");
298         container -> SetStepTitle(9, "RecoPID");
299
300         container -> SetVarTitle(ipt,"pt");
301         container -> SetVarTitle(iy,"y");
302         container -> SetVarTitle(icosThetaStar, "cosThetaStar");
303         container -> SetVarTitle(ipTpi, "ptpi");
304         container -> SetVarTitle(ipTk, "ptK");
305         container -> SetVarTitle(icT, "ct");
306         container -> SetVarTitle(idca, "dca");
307         container -> SetVarTitle(id0pi, "d0pi");
308         container -> SetVarTitle(id0K, "d0K");
309         container -> SetVarTitle(id0xd0, "d0xd0");
310         container -> SetVarTitle(ipointing, "piointing");
311         container -> SetVarTitle(iphi, "phi");
312         container -> SetVarTitle(iz, "z");
313
314
315         //CREATE THE  CUTS -----------------------------------------------
316         
317         // Gen-Level kinematic cuts
318         AliCFTrackKineCuts *mcKineCuts = new AliCFTrackKineCuts("mcKineCuts","MC-level kinematic cuts");
319         
320         //Particle-Level cuts:  
321         AliCFParticleGenCuts* mcGenCuts = new AliCFParticleGenCuts("mcGenCuts","MC particle generation cuts");
322         mcGenCuts->SetRequirePdgCode(PDG, kTRUE);  // kTRUE set in order to include D0_bar
323         mcGenCuts->SetAODMC(1); //special flag for reading MC in AOD tree (important)
324         
325         // Acceptance cuts:
326         AliCFAcceptanceCuts* accCuts = new AliCFAcceptanceCuts("accCuts", "Acceptance cuts");
327         AliCFTrackKineCuts *kineAccCuts = new AliCFTrackKineCuts("kineAccCuts","Kine-Acceptance cuts");
328         kineAccCuts->SetPtRange(ptmin,ptmax);
329         kineAccCuts->SetEtaRange(etamin,etamax);
330
331         // Rec-Level kinematic cuts
332         AliCFTrackKineCuts *recKineCuts = new AliCFTrackKineCuts("recKineCuts","rec-level kine cuts");
333         
334         AliCFTrackQualityCuts *recQualityCuts = new AliCFTrackQualityCuts("recQualityCuts","rec-level quality cuts");
335         
336         AliCFTrackIsPrimaryCuts *recIsPrimaryCuts = new AliCFTrackIsPrimaryCuts("recIsPrimaryCuts","rec-level isPrimary cuts");
337         
338         printf("CREATE MC KINE CUTS\n");
339         TObjArray* mcList = new TObjArray(0) ;
340         mcList->AddLast(mcKineCuts);
341         mcList->AddLast(mcGenCuts);
342         
343         printf("CREATE ACCEPTANCE CUTS\n");
344         TObjArray* accList = new TObjArray(0) ;
345         accList->AddLast(kineAccCuts);
346
347         printf("CREATE RECONSTRUCTION CUTS\n");
348         TObjArray* recList = new TObjArray(0) ;   // not used!! 
349         recList->AddLast(recKineCuts);
350         recList->AddLast(recQualityCuts);
351         recList->AddLast(recIsPrimaryCuts);
352         
353         TObjArray* emptyList = new TObjArray(0);
354
355         //CREATE THE INTERFACE TO CORRECTION FRAMEWORK USED IN THE TASK
356         printf("CREATE INTERFACE AND CUTS\n");
357         AliCFManager* man = new AliCFManager() ;
358         AliLog::SetClassDebugLevel("AliCFManager",AliLog::kError);
359         man->SetParticleContainer     (container);
360         man->SetParticleCutsList(0 , mcList); // MC, Limited Acceptance
361         man->SetParticleCutsList(1 , mcList); // MC
362         man->SetParticleCutsList(2 , accList); // Acceptance 
363         man->SetParticleCutsList(3 , emptyList); // Vertex 
364         man->SetParticleCutsList(4 , emptyList); // Refit 
365         man->SetParticleCutsList(5 , emptyList); // AOD
366         man->SetParticleCutsList(6 , emptyList); // AOD in Acceptance
367         man->SetParticleCutsList(7 , emptyList); // AOD with required n. of ITS clusters
368         man->SetParticleCutsList(8 , emptyList); // AOD Reco (PPR cuts implemented in Task)
369         man->SetParticleCutsList(9 , emptyList); // AOD Reco PID
370         
371         // Get the pointer to the existing analysis manager via the static access method.
372         //==============================================================================
373         AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
374         if (!mgr) {
375           ::Error("AddTaskCompareHF", "No analysis manager to connect to.");
376           return NULL;
377         }   
378         //CREATE THE TASK
379         printf("CREATE TASK\n");
380         // create the task
381         AliCFHeavyFlavourTaskMultiVarMultiStep *task = new AliCFHeavyFlavourTaskMultiVarMultiStep("AliCFHeavyFlavourTaskMultiVarMultiStep",cutsD0toKpi);
382         task->SetFillFromGenerated(kFALSE);
383         task->SetMinITSClusters(minITSClusters);
384         task->SetCFManager(man); //here is set the CF manager
385         task->SetKeepD0fromB(isKeepD0fromB);
386         task->SetKeepD0fromBOnly(isKeepD0fromBOnly);
387         task->SetUseWeight(kFALSE);  // set to true if you want to filled a weight CF   
388
389         //-----------------------------------------------------------//
390         //   create correlation matrix for unfolding - only eta-pt   //
391         //-----------------------------------------------------------//
392
393         Bool_t AcceptanceUnf = kTRUE; // unfold at acceptance level, otherwise PPR
394
395         Int_t thnDim[4];
396         
397         //first half  : reconstructed 
398         //second half : MC
399
400         thnDim[0] = iBin[0];
401         thnDim[2] = iBin[0];
402         thnDim[1] = iBin[1];
403         thnDim[3] = iBin[1];
404
405         TString nameCorr="";
406         if(!isKeepD0fromB) {
407           nameCorr="CFHFcorr0";
408         }
409         else if(isKeepD0fromBOnly){
410           nameCorr= "CFHFcorr0KeepD0fromBOnly";
411         }
412         else  {
413           nameCorr="CFHFcorr0allD0";
414
415         }
416
417         THnSparseD* correlation = new THnSparseD(nameCorr,"THnSparse with correlations",4,thnDim);
418         Double_t** binEdges = new Double_t[2];
419
420         // set bin limits
421
422         binEdges[0]= binLim0;
423         binEdges[1]= binLim1;
424
425         correlation->SetBinEdges(0,binEdges[0]);
426         correlation->SetBinEdges(2,binEdges[0]);
427
428         correlation->SetBinEdges(1,binEdges[1]);
429         correlation->SetBinEdges(3,binEdges[1]);
430
431         correlation->Sumw2();
432   
433         // correlation matrix ready
434         //------------------------------------------------//
435
436         task->SetCorrelationMatrix(correlation); // correlation matrix for unfolding
437         
438         // Create and connect containers for input/output
439         
440         // ------ input data ------
441         AliAnalysisDataContainer *cinput0  = mgr->GetCommonInputContainer();
442         
443         // ----- output data -----
444         
445         TString outputfile = AliAnalysisManager::GetCommonFileName();
446         TString output1name="", output2name="", output3name="", output4name="";
447         output2name=nameContainer;
448         output3name=nameCorr;
449         if(!isKeepD0fromB) {
450           outputfile += ":PWG3_D2H_CFtaskD0toKpi";
451           output1name="CFHFchist0";
452         }
453         else if(isKeepD0fromBOnly){
454           outputfile += ":PWG3_D2H_CFtaskD0toKpiKeepD0fromBOnly";
455           output1name="CFHFchist0D0fromB";
456         }
457         else  {
458           outputfile += ":PWG3_D2H_CFtaskD0toKpiKeepD0fromB";
459           output1name="CFHFchist0allD0";
460
461         }
462         output4name="Cuts";
463
464         //now comes user's output objects :
465         // output TH1I for event counting
466         AliAnalysisDataContainer *coutput1 = mgr->CreateContainer(output1name, TH1I::Class(),AliAnalysisManager::kOutputContainer,outputfile.Data());
467         // output Correction Framework Container (for acceptance & efficiency calculations)
468         AliAnalysisDataContainer *coutput2 = mgr->CreateContainer(output2name, AliCFContainer::Class(),AliAnalysisManager::kOutputContainer,outputfile.Data());
469         // Unfolding - correlation matrix
470         AliAnalysisDataContainer *coutput3 = mgr->CreateContainer(output3name, THnSparseD::Class(),AliAnalysisManager::kOutputContainer,outputfile.Data());
471         AliAnalysisDataContainer *coutput4 = mgr->CreateContainer(output4name, AliRDHFCutsD0toKpi::Class(),AliAnalysisManager::kOutputContainer,outputfile.Data());
472
473         mgr->AddTask(task);
474         
475         mgr->ConnectInput(task,0,mgr->GetCommonInputContainer());
476         mgr->ConnectOutput(task,1,coutput1);
477         mgr->ConnectOutput(task,2,coutput2);
478         mgr->ConnectOutput(task,3,coutput3);
479         mgr->ConnectOutput(task,4,coutput4);
480         return task;
481 }
482