]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/macros/runAliAnalysisTaskFlow.C
pass weight histograms via Task containors
[u/mrichter/AliRoot.git] / PWG2 / FLOW / macros / runAliAnalysisTaskFlow.C
1 /////////////////////////////////////////////////////////////////////////////////        
2 //       
3 // HOW TO USE THIS MACRO:        
4 //       
5 // With this macro several flow analysis can be run.     
6 // SP    = Scalar Product                (for PbPb or pp)        
7 // LYZ1  = Lee Yang Zeroes first run     (for PbPb)      
8 // LYZ2  = Lee Yang Zeroes second run    (for PbPb)      
9 // LYZEP = Lee Yang Zeroes Event Plane   (for PbPb)      
10 // GFC   = Generating Function Cumulants (for PbPb)  
11 // QC    = Q-cumulants                   (for PbPb)  
12 // FQD   = Fitting q-distribution        (for PbPb) 
13 // MCEP  = Flow calculated from the real MC event plane (for PbPb only!)         
14 //       
15 // The LYZ analysis should be done in the following order;       
16 // LYZ1 -> LYZ2 -> LYZEP,        
17 // because LYZ2 depends on the outputfile of LYZ1 and LYZEP on the outputfile    
18 // of LYZ2.      
19 //       
20 // The MCEP method is a reference method.        
21 // It can only be run when MC information (kinematics.root & galice.root file) is available      
22 // in which the reaction plane is stored.        
23 //       
24 // One can run on ESD, AOD or MC.        
25 // Additional options are ESDMC0, ESDMC1. In these options the ESD and MC        
26 // information is combined. Tracks are selected in the ESD, the PID information          
27 // is taken from the MC (perfect PID). For ESDMC0 the track kinematics is taken          
28 // from the ESD and for ESDMC1 it is taken from the MC information.      
29 //       
30 ///////////////////////////////////////////////////////////////////////////////////      
31          
32
33 //SETTING THE ANALYSIS
34
35 //Flow analysis methods can be: (set to kTRUE or kFALSE)
36 Bool_t SP    = kFALSE;
37 Bool_t LYZ1  = kFALSE;
38 Bool_t LYZ2  = kFALSE;
39 Bool_t LYZEP = kFALSE;
40 Bool_t GFC   = kFALSE;
41 Bool_t QC    = kTRUE;
42 Bool_t FQD   = kFALSE;
43 Bool_t MCEP  = kFALSE;
44
45
46 //Type of analysis can be:
47 // ESD, AOD, MC, ESDMC0, ESDMC1
48 const TString type = "ESD";
49
50 //Bolean to fill/not fill the QA histograms
51 Bool_t QA = kFALSE;    
52
53 //SETTING THE CUTS
54
55 //for integrated flow
56 const Double_t ptmin1 = 0.0;
57 const Double_t ptmax1 = 10.0;
58 const Double_t ymin1  = -1.;
59 const Double_t ymax1  = 1.;
60 const Int_t mintrackrefsTPC1 = 2;
61 const Int_t mintrackrefsITS1 = 3;
62 const Int_t charge1 = 1;
63 Bool_t UsePIDIntegratedFlow = kFALSE;
64 const Int_t PDG1 = 211;
65 const Int_t minclustersTPC1 = 50;
66 const Int_t maxnsigmatovertex1 = 3;
67
68 //for differential flow
69 const Double_t ptmin2 = 0.0;
70 const Double_t ptmax2 = 10.0;
71 const Double_t ymin2  = -1.;
72 const Double_t ymax2  = 1.;
73 const Int_t mintrackrefsTPC2 = 2;
74 const Int_t mintrackrefsITS2 = 3;
75 const Int_t charge2 = 1;
76 Bool_t UsePIDDifferentialFlow = kFALSE;
77 const Int_t PDG2 = 211;
78 const Int_t minclustersTPC2 = 50;
79 const Int_t maxnsigmatovertex2 = 3;
80
81 //WEIGHTS SETTINGS: 
82 //to use or not to use the weights - that is a question!
83 Bool_t usePhiWeights = kTRUE; //Phi
84 Bool_t usePtWeights  = kFALSE; //v'(pt)
85 Bool_t useEtaWeights = kFALSE; //v'(eta)
86 Bool_t useWeights = usePhiWeights||usePtWeights||usePtWeights;
87
88 void runAliAnalysisTaskFlow(Int_t nRuns = 4, const Char_t* dataDir="/data/alice2/kolk/Therminator_midcentral", Int_t offset = 0) 
89 //void runAliAnalysisTaskFlow(Int_t nRuns = -1, const Char_t* dataDir="/Users/snelling/alice_data/Therminator_midcentral", Int_t offset = 0) 
90
91 {
92   TStopwatch timer;
93   timer.Start();
94   
95   if (LYZ1 && LYZ2) {cout<<"WARNING: you cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1."<<endl; exit(); }
96   if (LYZ2 && LYZEP) {cout<<"WARNING: you cannot run LYZ2 and LYZEP at the same time! LYZEP needs the output from LYZ2."<<endl; exit(); }
97   if (LYZ1 && LYZEP) {cout<<"WARNING: you cannot run LYZ1 and LYZEP at the same time! LYZEP needs the output from LYZ2."<<endl; exit(); }
98   
99   // include path (to find the .h files when compiling)
100   gSystem->AddIncludePath("-I$ALICE_ROOT/include") ;
101   gSystem->AddIncludePath("-I$ROOTSYS/include") ;
102   
103   // load needed libraries
104   gSystem->Load("libTree.so");
105   gSystem->Load("libESD.so");
106   cerr<<"libESD loaded..."<<endl;
107   gSystem->Load("libANALYSIS.so");
108   cerr<<"libANALYSIS.so loaded..."<<endl;
109   gSystem->Load("libANALYSISRL.so");
110   cerr<<"libANALYSISRL.so loaded..."<<endl;
111   gSystem->Load("libCORRFW.so");
112   cerr<<"libCORRFW.so loaded..."<<endl;
113   gSystem->Load("libPWG2flow.so");
114   cerr<<"libPWG2flow.so loaded..."<<endl;
115
116   // create the TChain. CreateESDChain() is defined in CreateESDChain.C
117   if (type!="AOD") { TChain* chain = CreateESDChain(dataDir, nRuns, offset);}
118   //  cout<<"chain ("<<chain<<")"<<endl; }
119   else { TChain* chain = CreateAODChain(dataDir, nRuns, offset);}
120   //  cout<<"chain ("<<chain<<")"<<endl; }
121  
122   //____________________________________________//
123   //Create cuts using correction framework
124
125   //Set TList for the QA histograms
126   if (QA) {
127     if (SP){
128       TList* qaIntSP = new TList();
129       TList* qaDiffSP = new TList(); }
130     if (LYZ1) {
131       TList* qaIntLYZ1 = new TList();
132       TList* qaDiffLYZ1 = new TList(); }
133     if (LYZ2) {
134       TList* qaIntLYZ2 = new TList();
135       TList* qaDiffLYZ2 = new TList(); }
136     if (LYZEP) {
137       TList* qaIntLYZEP = new TList();
138       TList* qaDiffLYZEP = new TList(); }
139     if (GFC) {
140       TList* qaIntGFC = new TList();
141       TList* qaDiffGFC = new TList(); }
142     if (QC) {
143       TList* qaIntQC = new TList();
144       TList* qaDiffQC = new TList(); }
145     if (FQD) {
146       TList* qaIntFQD = new TList();
147       TList* qaDiffFQD = new TList(); }
148     if (MCEP) {
149       TList* qaIntMCEP = new TList();
150       TList* qaDiffMCEP = new TList(); }
151   }
152   
153   //############# cuts on MC
154   AliCFTrackKineCuts* mcKineCuts1 = new AliCFTrackKineCuts("mcKineCuts1","MC-level kinematic cuts");
155   mcKineCuts1->SetPtRange(ptmin1,ptmax1);
156   mcKineCuts1->SetRapidityRange(ymin1,ymax1);
157   mcKineCuts1->SetChargeMC(charge1);
158   if (QA) { 
159     if (SP)   { mcKineCuts1->SetQAOn(qaIntSP); }
160     if (LYZ1) { mcKineCuts1->SetQAOn(qaIntLYZ1); }
161     if (LYZ2) { mcKineCuts1->SetQAOn(qaIntLYZ2); }
162     if (LYZEP){ mcKineCuts1->SetQAOn(qaIntLYZEP); }
163     if (GFC)  { mcKineCuts1->SetQAOn(qaIntGFC); }
164     if (QC)   { mcKineCuts1->SetQAOn(qaIntQC); }
165     if (FQD)  { mcKineCuts1->SetQAOn(qaIntFQD); }
166     if (MCEP) { mcKineCuts1->SetQAOn(qaIntMCEP); }
167   }
168   
169   AliCFTrackKineCuts* mcKineCuts2 = new AliCFTrackKineCuts("mcKineCuts2","MC-level kinematic cuts");
170   mcKineCuts2->SetPtRange(ptmin2,ptmax2);
171   mcKineCuts2->SetRapidityRange(ymin2,ymax2);
172   mcKineCuts2->SetChargeMC(charge2);
173   if (QA) { 
174     if (SP)   { mcKineCuts2->SetQAOn(qaDiffSP); }
175     if (LYZ1) { mcKineCuts2->SetQAOn(qaDiffLYZ1); }
176     if (LYZ2) { mcKineCuts2->SetQAOn(qaDiffLYZ2); }
177     if (LYZEP){ mcKineCuts2->SetQAOn(qaDiffLYZEP); }
178     if (GFC)  { mcKineCuts2->SetQAOn(qaDiffGFC); }
179     if (QC)   { mcKineCuts2->SetQAOn(qaDiffQC); } 
180     if (FQD)  { mcKineCuts2->SetQAOn(qaDiffFQD); }    
181     if (MCEP) { mcKineCuts2->SetQAOn(qaDiffMCEP); }
182   }
183
184   AliCFParticleGenCuts* mcGenCuts1 = new AliCFParticleGenCuts("mcGenCuts1","MC particle generation cuts for integrated flow");
185   mcGenCuts1->SetRequireIsPrimary();
186   if (UsePIDIntegratedFlow) {mcGenCuts1->SetRequirePdgCode(PDG1);}
187   if (QA) { 
188     if (SP)   { mcGenCuts1->SetQAOn(qaIntSP); }
189     if (LYZ1) { mcGenCuts1->SetQAOn(qaIntLYZ1); }
190     if (LYZ2) { mcGenCuts1->SetQAOn(qaIntLYZ2); }
191     if (LYZEP){ mcGenCuts1->SetQAOn(qaIntLYZEP); }
192     if (GFC)  { mcGenCuts1->SetQAOn(qaIntGFC); }
193     if (QC)   { mcGenCuts1->SetQAOn(qaIntQC); }
194     if (FQD)  { mcGenCuts1->SetQAOn(qaIntFQD); }
195     if (MCEP) { mcGenCuts1->SetQAOn(qaIntMCEP); }
196   }
197
198   AliCFParticleGenCuts* mcGenCuts2 = new AliCFParticleGenCuts("mcGenCuts2","MC particle generation cuts for differential flow");
199   mcGenCuts2->SetRequireIsPrimary();
200   if (UsePIDDifferentialFlow) {mcGenCuts2->SetRequirePdgCode(PDG2);}
201   if (QA) { 
202     if (SP)   { mcGenCuts2->SetQAOn(qaDiffSP); }
203     if (LYZ1) { mcGenCuts2->SetQAOn(qaDiffLYZ1); }
204     if (LYZ2) { mcGenCuts2->SetQAOn(qaDiffLYZ2); }
205     if (LYZEP){ mcGenCuts2->SetQAOn(qaDiffLYZEP); }
206     if (GFC)  { mcGenCuts2->SetQAOn(qaDiffGFC); }
207     if (QC)   { mcGenCuts2->SetQAOn(qaDiffQC); }
208     if (FQD)  { mcGenCuts2->SetQAOn(qaDiffFQD); }
209     if (MCEP) { mcGenCuts2->SetQAOn(qaDiffMCEP); }
210   }
211   
212   //############# Acceptance Cuts
213   AliCFAcceptanceCuts *mcAccCuts1 = new AliCFAcceptanceCuts("mcAccCuts1","MC acceptance cuts");
214   mcAccCuts1->SetMinNHitITS(mintrackrefsITS1);
215   mcAccCuts1->SetMinNHitTPC(mintrackrefsTPC1);
216   if (QA) { 
217     if (SP)   { mcAccCuts1->SetQAOn(qaIntSP); }
218     if (LYZ1) { mcAccCuts1->SetQAOn(qaIntLYZ1); }
219     if (LYZ2) { mcAccCuts1->SetQAOn(qaIntLYZ2); }
220     if (LYZEP){ mcAccCuts1->SetQAOn(qaIntLYZEP); }
221     if (GFC)  { mcAccCuts1->SetQAOn(qaIntGFC); }
222     if (QC)   { mcAccCuts1->SetQAOn(qaIntQC); }
223     if (FQD)  { mcAccCuts1->SetQAOn(qaIntFQD); }
224     if (MCEP) { mcAccCuts1->SetQAOn(qaIntMCEP); }
225   }
226
227   AliCFAcceptanceCuts *mcAccCuts2 = new AliCFAcceptanceCuts("mcAccCuts2","MC acceptance cuts");
228   mcAccCuts2->SetMinNHitITS(mintrackrefsITS2);
229   mcAccCuts2->SetMinNHitTPC(mintrackrefsTPC2);
230   if (QA) { 
231     if (SP)   { mcAccCuts2->SetQAOn(qaDiffSP); }
232     if (LYZ1) { mcAccCuts2->SetQAOn(qaDiffLYZ1); }
233     if (LYZ2) { mcAccCuts2->SetQAOn(qaDiffLYZ2); }
234     if (LYZEP){ mcAccCuts2->SetQAOn(qaDiffLYZEP); }
235     if (GFC)  { mcAccCuts2->SetQAOn(qaDiffGFC); }
236     if (QC)   { mcAccCuts2->SetQAOn(qaDiffQC); }
237     if (FQD)  { mcAccCuts2->SetQAOn(qaDiffFQD); }    
238     if (MCEP) { mcAccCuts2->SetQAOn(qaDiffMCEP); }
239   }
240   
241   //############# Rec-Level kinematic cuts
242   AliCFTrackKineCuts *recKineCuts1 = new AliCFTrackKineCuts("recKineCuts1","rec-level kine cuts");
243   recKineCuts1->SetPtRange(ptmin1,ptmax1);
244   recKineCuts1->SetRapidityRange(ymin1,ymax1);
245   recKineCuts1->SetChargeRec(charge1);
246   if (QA) { 
247     if (SP)   { recKineCuts1->SetQAOn(qaIntSP); }
248     if (LYZ1) { recKineCuts1->SetQAOn(qaIntLYZ1); }
249     if (LYZ2) { recKineCuts1->SetQAOn(qaIntLYZ2); }
250     if (LYZEP){ recKineCuts1->SetQAOn(qaIntLYZEP); }
251     if (GFC)  { recKineCuts1->SetQAOn(qaIntGFC); }
252     if (QC)   { recKineCuts1->SetQAOn(qaIntQC); }
253     if (FQD)  { recKineCuts1->SetQAOn(qaIntFQD); }
254     if (MCEP) { recKineCuts1->SetQAOn(qaIntMCEP); }
255   }
256
257   AliCFTrackKineCuts *recKineCuts2 = new AliCFTrackKineCuts("recKineCuts2","rec-level kine cuts");
258   recKineCuts2->SetPtRange(ptmin2,ptmax2);
259   recKineCuts2->SetRapidityRange(ymin2,ymax2);
260   recKineCuts2->SetChargeRec(charge2);
261   if (QA) { 
262     if (SP)   { recKineCuts2->SetQAOn(qaDiffSP); }
263     if (LYZ1) { recKineCuts2->SetQAOn(qaDiffLYZ1); }
264     if (LYZ2) { recKineCuts2->SetQAOn(qaDiffLYZ2); }
265     if (LYZEP){ recKineCuts2->SetQAOn(qaDiffLYZEP); }
266     if (GFC)  { recKineCuts2->SetQAOn(qaDiffGFC); }
267     if (QC)   { recKineCuts2->SetQAOn(qaDiffQC); }
268     if (FQD)  { recKineCuts2->SetQAOn(qaDiffFQD); }
269     if (MCEP) { recKineCuts2->SetQAOn(qaDiffMCEP); }
270   }
271   
272   AliCFTrackQualityCuts *recQualityCuts1 = new AliCFTrackQualityCuts("recQualityCuts1","rec-level quality cuts");
273   recQualityCuts1->SetMinNClusterTPC(minclustersTPC1);
274   recQualityCuts1->SetStatus(AliESDtrack::kITSrefit);
275   if (QA) { 
276     if (SP)   { recQualityCuts1->SetQAOn(qaIntSP); }
277     if (LYZ1) { recQualityCuts1->SetQAOn(qaIntLYZ1); }
278     if (LYZ2) { recQualityCuts1->SetQAOn(qaIntLYZ2); }
279     if (LYZEP){ recQualityCuts1->SetQAOn(qaIntLYZEP); }
280     if (GFC)  { recQualityCuts1->SetQAOn(qaIntGFC); }
281     if (QC)   { recQualityCuts1->SetQAOn(qaIntQC); }
282     if (FQD)  { recQualityCuts1->SetQAOn(qaIntFQD); }
283     if (MCEP) { recQualityCuts1->SetQAOn(qaIntMCEP); }
284   }
285
286   AliCFTrackQualityCuts *recQualityCuts2 = new AliCFTrackQualityCuts("recQualityCuts2","rec-level quality cuts");
287   recQualityCuts2->SetMinNClusterTPC(minclustersTPC2);
288   recQualityCuts2->SetStatus(AliESDtrack::kITSrefit);
289   if (QA) { 
290     if (SP)   { recQualityCuts2->SetQAOn(qaDiffSP); }
291     if (LYZ1) { recQualityCuts2->SetQAOn(qaDiffLYZ1); }
292     if (LYZ2) { recQualityCuts2->SetQAOn(qaDiffLYZ2); }
293     if (LYZEP){ recQualityCuts2->SetQAOn(qaDiffLYZEP); }
294     if (GFC)  { recQualityCuts2->SetQAOn(qaDiffGFC); }
295     if (QC)   { recQualityCuts2->SetQAOn(qaDiffQC); }
296     if (FQD)  { recQualityCuts2->SetQAOn(qaDiffFQD); }
297     if (MCEP) { recQualityCuts2->SetQAOn(qaDiffMCEP); }
298   }
299
300   AliCFTrackIsPrimaryCuts *recIsPrimaryCuts1 = new AliCFTrackIsPrimaryCuts("recIsPrimaryCuts1","rec-level isPrimary cuts");
301   recIsPrimaryCuts1->SetMaxNSigmaToVertex(maxnsigmatovertex1);
302   if (QA) { 
303     if (SP)   { recIsPrimaryCuts1->SetQAOn(qaIntSP); }
304     if (LYZ1) { recIsPrimaryCuts1->SetQAOn(qaIntLYZ1); }
305     if (LYZ2) { recIsPrimaryCuts1->SetQAOn(qaIntLYZ2); }
306     if (LYZEP){ recIsPrimaryCuts1->SetQAOn(qaIntLYZEP); }
307     if (GFC)  { recIsPrimaryCuts1->SetQAOn(qaIntGFC); }
308     if (QC)   { recIsPrimaryCuts1->SetQAOn(qaIntQC); }
309     if (FQD)  { recIsPrimaryCuts1->SetQAOn(qaIntFQD); }
310     if (MCEP) { recIsPrimaryCuts1->SetQAOn(qaIntMCEP); }
311   }
312
313   AliCFTrackIsPrimaryCuts *recIsPrimaryCuts2 = new AliCFTrackIsPrimaryCuts("recIsPrimaryCuts2","rec-level isPrimary cuts");
314   recIsPrimaryCuts2->SetMaxNSigmaToVertex(maxnsigmatovertex2);
315   if (QA) { 
316     if (SP)   { recIsPrimaryCuts2->SetQAOn(qaDiffSP); }
317     if (LYZ1) { recIsPrimaryCuts2->SetQAOn(qaDiffLYZ1); }
318     if (LYZ2) { recIsPrimaryCuts2->SetQAOn(qaDiffLYZ2); }
319     if (LYZEP){ recIsPrimaryCuts2->SetQAOn(qaDiffLYZEP); }
320     if (GFC)  { recIsPrimaryCuts2->SetQAOn(qaDiffGFC); }
321     if (QC)   { recIsPrimaryCuts2->SetQAOn(qaDiffQC); }
322     if (FQD)  { recIsPrimaryCuts2->SetQAOn(qaDiffFQD); }
323     if (MCEP) { recIsPrimaryCuts2->SetQAOn(qaDiffMCEP); }
324   }
325   
326
327
328   int n_species = AliPID::kSPECIES ;
329   Double_t* prior = new Double_t[n_species];
330   
331   prior[0] = 0.0244519 ;
332   prior[1] = 0.0143988 ;
333   prior[2] = 0.805747  ;
334   prior[3] = 0.0928785 ;
335   prior[4] = 0.0625243 ;
336
337   AliCFTrackCutPid* cutPID1 = NULL;
338   if(UsePIDIntegratedFlow) {
339     AliCFTrackCutPid* cutPID1 = new AliCFTrackCutPid("cutPID1","ESD_PID for integrated flow") ;
340     cutPID1->SetPriors(prior);
341     cutPID1->SetProbabilityCut(0.0);
342     cutPID1->SetDetectors("TPC TOF");
343     switch(TMath::Abs(PDG1)) {
344     case 11   : cutPID1->SetParticleType(AliPID::kElectron, kTRUE); break;
345     case 13   : cutPID1->SetParticleType(AliPID::kMuon    , kTRUE); break;
346     case 211  : cutPID1->SetParticleType(AliPID::kPion    , kTRUE); break;
347     case 321  : cutPID1->SetParticleType(AliPID::kKaon    , kTRUE); break;
348     case 2212 : cutPID1->SetParticleType(AliPID::kProton  , kTRUE); break;
349     default   : printf("UNDEFINED PID\n"); break;
350     }
351     if (QA) { 
352       if (SP) {cutPID1->SetQAOn(qaIntSP);} 
353       if (LYZ1) {cutPID1->SetQAOn(qaIntLYZ1);} 
354       if (LYZ2) {cutPID1->SetQAOn(qaIntLYZ2);} 
355       if (LYZEP){cutPID1->SetQAOn(qaIntLYZEP);} 
356       if (GFC) {cutPID1->SetQAOn(qaIntGFC);} 
357       if (QC) {cutPID1->SetQAOn(qaIntQC);} 
358       if (FQD) {cutPID1->SetQAOn(qaIntFQD);} 
359       if (MCEP) {cutPID1->SetQAOn(qaIntMCEP);} 
360     }
361   }
362                   
363   AliCFTrackCutPid* cutPID2 = NULL;
364   if (UsePIDDifferentialFlow) {
365     AliCFTrackCutPid* cutPID2 = new AliCFTrackCutPid("cutPID2","ESD_PID for differential flow") ;
366     cutPID2->SetPriors(prior);
367     cutPID2->SetProbabilityCut(0.0);
368     cutPID2->SetDetectors("TPC TOF");
369     switch(TMath::Abs(PDG2)) {
370     case 11   : cutPID2->SetParticleType(AliPID::kElectron, kTRUE); break;
371     case 13   : cutPID2->SetParticleType(AliPID::kMuon    , kTRUE); break;
372     case 211  : cutPID2->SetParticleType(AliPID::kPion    , kTRUE); break;
373     case 321  : cutPID2->SetParticleType(AliPID::kKaon    , kTRUE); break;
374     case 2212 : cutPID2->SetParticleType(AliPID::kProton  , kTRUE); break;
375     default   : printf("UNDEFINED PID\n"); break;
376     }
377     if (QA) { 
378       if (SP) {cutPID2->SetQAOn(qaIntSP);} 
379       if (LYZ1) {cutPID2->SetQAOn(qaIntLYZ1);} 
380       if (LYZ2) {cutPID2->SetQAOn(qaIntLYZ2);} 
381       if (LYZEP){cutPID2->SetQAOn(qaIntLYZEP);} 
382       if (GFC) {cutPID2->SetQAOn(qaIntGFC);} 
383       if (QC) {cutPID2->SetQAOn(qaIntQC);} 
384       if (FQD) {cutPID2->SetQAOn(qaIntFQD);} 
385       if (MCEP) {cutPID2->SetQAOn(qaIntMCEP);} 
386     }
387   }
388
389   printf("CREATE MC KINE CUTS\n");
390   TObjArray* mcList1 = new TObjArray(0);
391   mcList1->AddLast(mcKineCuts1);
392   mcList1->AddLast(mcGenCuts1);
393   
394   TObjArray* mcList2 = new TObjArray(0);
395   mcList2->AddLast(mcKineCuts2);
396   mcList2->AddLast(mcGenCuts2);
397   
398   printf("CREATE ACCEPTANCE CUTS\n");
399   TObjArray* accList1 = new TObjArray(0) ;
400   accList1->AddLast(mcAccCuts1);
401   
402   TObjArray* accList2 = new TObjArray(0) ;
403   accList2->AddLast(mcAccCuts2);
404   
405   printf("CREATE RECONSTRUCTION CUTS\n");
406   TObjArray* recList1 = new TObjArray(0) ;
407   recList1->AddLast(recKineCuts1);
408   recList1->AddLast(recQualityCuts1);
409   recList1->AddLast(recIsPrimaryCuts1);
410   
411   TObjArray* recList2 = new TObjArray(0) ;
412   recList2->AddLast(recKineCuts2);
413   recList2->AddLast(recQualityCuts2);
414   recList2->AddLast(recIsPrimaryCuts2);
415   
416   printf("CREATE PID CUTS\n");
417   TObjArray* fPIDCutList1 = new TObjArray(0) ;
418   if(UsePIDIntegratedFlow) {fPIDCutList1->AddLast(cutPID1);}
419   
420   TObjArray* fPIDCutList2 = new TObjArray(0) ;
421   if (UsePIDDifferentialFlow)  {fPIDCutList2->AddLast(cutPID2);}
422   
423   printf("CREATE INTERFACE AND CUTS FOR INTEGRATED FLOW\n");
424   AliCFManager* cfmgr1 = new AliCFManager();
425   cfmgr1->SetNStepParticle(4); //05nov08
426   cfmgr1->SetParticleCutsList(AliCFManager::kPartGenCuts,mcList1);       //on MC
427   cfmgr1->SetParticleCutsList(AliCFManager::kPartAccCuts,accList1);      //on MC
428   cfmgr1->SetParticleCutsList(AliCFManager::kPartRecCuts,recList1);      //on ESD
429   cfmgr1->SetParticleCutsList(AliCFManager::kPartSelCuts,fPIDCutList1);  //on ESD
430   
431   printf("CREATE INTERFACE AND CUTS FOR DIFFERENTIAL FLOW\n");
432   AliCFManager* cfmgr2 = new AliCFManager();
433   cfmgr2->SetNStepParticle(4); //05nov08
434   cfmgr2->SetParticleCutsList(AliCFManager::kPartGenCuts,mcList2);
435   cfmgr2->SetParticleCutsList(AliCFManager::kPartAccCuts,accList2);
436   cfmgr2->SetParticleCutsList(AliCFManager::kPartRecCuts,recList2);
437   cfmgr2->SetParticleCutsList(AliCFManager::kPartSelCuts,fPIDCutList2);
438   
439   //weights: 
440   TFile *weightsFile = NULL;
441   TList *weightsList = NULL;
442   
443   if(useWeights)
444   {
445    //open the file with the weights:
446    weightsFile = TFile::Open("weights.root","READ");
447    if(weightsFile)
448    {
449     //access the list which holds the histos with weigths:
450     weightsList = (TList*)weightsFile->Get("weights");
451    }else{cout<<" WARNING: the file <weights.root> with weights from the previuos run was not accessed."<<endl;} 
452   }//end of if(useWeights)
453   
454   if (LYZ2){  
455     // read the input file from the first run 
456     TString inputFileNameLYZ2 = "outputLYZ1analysis" ;
457     inputFileNameLYZ2 += type;
458     inputFileNameLYZ2 += ".root";
459     cout<<"The input file is "<<inputFileNameLYZ2.Data()<<endl;
460     TFile* fInputFileLYZ2 = new TFile(inputFileNameLYZ2.Data(),"READ");
461     if(!fInputFileLYZ2 || fInputFileLYZ2->IsZombie()) { 
462       cerr << " ERROR: NO First Run file... " << endl ; }
463     else { 
464       TList* fInputListLYZ2 = (TList*)fInputFileLYZ2->Get("cobjLYZ1");  
465       if (!fInputListLYZ2) {cout<<"list is NULL pointer!"<<endl;}
466     }
467     cout<<"LYZ2 input file/list read..."<<endl;
468   }
469   
470   if (LYZEP) {
471     // read the input file from the second LYZ run
472     TString inputFileNameLYZEP = "outputLYZ2analysis" ;
473     inputFileNameLYZEP += type;
474     inputFileNameLYZEP += ".root";
475     cout<<"The input file is "<<inputFileNameLYZEP.Data()<<endl;
476     TFile* fInputFileLYZEP = new TFile(inputFileNameLYZEP.Data(),"READ");
477     if(!fInputFileLYZEP || fInputFileLYZEP->IsZombie()) { cerr << " ERROR: NO First Run file... " << endl ; }
478     else {
479       TList* fInputListLYZEP = (TList*)fInputFileLYZEP->Get("cobjLYZ2");  
480       if (!fInputListLYZEP) {cout<<"list is NULL pointer!"<<endl;}
481     }
482     cout<<"LYZEP input file/list read..."<<endl;
483   }
484   
485
486   //____________________________________________//
487   // Make the analysis manager
488   AliAnalysisManager *mgr = new AliAnalysisManager("FlowAnalysisManager");
489   
490   if (type == "ESD"){
491     AliVEventHandler* esdH = new AliESDInputHandler;
492     mgr->SetInputEventHandler(esdH); 
493     if (MCEP) {
494       AliMCEventHandler *mc = new AliMCEventHandler();
495       mgr->SetMCtruthEventHandler(mc);}  }
496   
497   if (type == "AOD"){
498     AliVEventHandler* aodH = new AliAODInputHandler;
499     mgr->SetInputEventHandler(aodH);
500     if (MCEP) {
501       AliMCEventHandler *mc = new AliMCEventHandler();
502       mgr->SetMCtruthEventHandler(mc);}  }
503   
504   if (type == "MC" || type == "ESDMC0" || type == "ESDMC1"){
505     AliVEventHandler* esdH = new AliESDInputHandler;
506     mgr->SetInputEventHandler(esdH);
507     
508     AliMCEventHandler *mc = new AliMCEventHandler();
509     mgr->SetMCtruthEventHandler(mc); }
510   
511   //____________________________________________//
512   // Task
513   
514   if (SP){
515     if (QA) { AliAnalysisTaskScalarProduct *taskSP = new AliAnalysisTaskScalarProduct("TaskScalarProduct",kTRUE); }
516     else { AliAnalysisTaskScalarProduct *taskSP = new AliAnalysisTaskScalarProduct("TaskScalarProduct",kFALSE); }
517     taskSP->SetAnalysisType(type);
518     taskSP->SetCFManager1(cfmgr1);
519     taskSP->SetCFManager2(cfmgr2);
520     if (QA) { 
521       taskSP->SetQAList1(qaIntSP);
522       taskSP->SetQAList2(qaDiffSP); }
523     mgr->AddTask(taskSP);
524   }
525   if (LYZ1){
526     if (QA) { AliAnalysisTaskLeeYangZeros *taskLYZ1 = new AliAnalysisTaskLeeYangZeros("TaskLeeYangZeros",kTRUE,kTRUE);}
527     else { AliAnalysisTaskLeeYangZeros *taskLYZ1 = new AliAnalysisTaskLeeYangZeros("TaskLeeYangZeros",kTRUE,kFALSE);}
528     taskLYZ1->SetAnalysisType(type);
529     taskLYZ1->SetFirstRunLYZ(kTRUE);
530     taskLYZ1->SetUseSumLYZ(kTRUE);
531     taskLYZ1->SetCFManager1(cfmgr1);
532     taskLYZ1->SetCFManager2(cfmgr2);
533     if (QA) { 
534       taskLYZ1->SetQAList1(qaIntLYZ1);
535       taskLYZ1->SetQAList2(qaDiffLYZ1);}
536     mgr->AddTask(taskLYZ1);
537   }
538   if (LYZ2){
539     if (QA) { AliAnalysisTaskLeeYangZeros *taskLYZ2 = new AliAnalysisTaskLeeYangZeros("TaskLeeYangZeros",kFALSE,kTRUE);}
540     else { AliAnalysisTaskLeeYangZeros *taskLYZ2 = new AliAnalysisTaskLeeYangZeros("TaskLeeYangZeros",kFALSE,kFALSE); }
541     taskLYZ2->SetAnalysisType(type);
542     taskLYZ2->SetFirstRunLYZ(kFALSE);
543     taskLYZ2->SetUseSumLYZ(kTRUE);
544     taskLYZ2->SetCFManager1(cfmgr1);
545     taskLYZ2->SetCFManager2(cfmgr2);
546     if (QA) { 
547       taskLYZ2->SetQAList1(qaIntLYZ2);
548       taskLYZ2->SetQAList2(qaDiffLYZ2); }
549     mgr->AddTask(taskLYZ2);
550   }
551   if (LYZEP){
552     if (QA) { AliAnalysisTaskLYZEventPlane *taskLYZEP = new AliAnalysisTaskLYZEventPlane("TaskLYZEventPlane",kTRUE); }
553     else { AliAnalysisTaskLYZEventPlane *taskLYZEP = new AliAnalysisTaskLYZEventPlane("TaskLYZEventPlane",kFALSE); }
554     taskLYZEP->SetAnalysisType(type);
555     taskLYZEP->SetCFManager1(cfmgr1);
556     taskLYZEP->SetCFManager2(cfmgr2);
557     if (QA) { 
558       taskLYZEP->SetQAList1(qaIntLYZEP);
559       taskLYZEP->SetQAList2(qaDiffLYZEP); }
560     mgr->AddTask(taskLYZEP);
561   }
562   if (GFC){
563     if (QA) { AliAnalysisTaskCumulants *taskGFC = new AliAnalysisTaskCumulants("TaskCumulants",kTRUE);}
564     else { AliAnalysisTaskCumulants *taskGFC = new AliAnalysisTaskCumulants("TaskCumulants",kFALSE);}
565     taskGFC->SetAnalysisType(type);
566     taskGFC->SetCFManager1(cfmgr1);
567     taskGFC->SetCFManager2(cfmgr2);
568     if (QA) { 
569       taskGFC->SetQAList1(qaIntGFC);
570       taskGFC->SetQAList2(qaDiffGFC); }
571     mgr->AddTask(taskGFC);
572   }
573   if (QC){
574     if (QA) { AliAnalysisTaskQCumulants *taskQC = new AliAnalysisTaskQCumulants("TaskQCumulants",kTRUE,useWeights);}
575     else { AliAnalysisTaskQCumulants *taskQC = new AliAnalysisTaskQCumulants("TaskQCumulants",kFALSE,useWeights);}
576     taskQC->SetAnalysisType(type);
577     taskQC->SetUsePhiWeights(usePhiWeights); 
578     taskQC->SetUsePtWeights(usePtWeights);
579     taskQC->SetUseEtaWeights(useEtaWeights); 
580     taskQC->SetCFManager1(cfmgr1);
581     taskQC->SetCFManager2(cfmgr2);
582     if (QA) { 
583       taskQC->SetQAList1(qaIntQC);
584       taskQC->SetQAList2(qaDiffQC); }
585     mgr->AddTask(taskQC);
586   }
587   if (FQD){
588     if (QA) { AliAnalysisTaskFittingQDistribution *taskFQD = new AliAnalysisTaskFittingQDistribution("TaskFittingQDistribution",kTRUE);}
589     else { AliAnalysisTaskFittingQDistribution *taskFQD = new AliAnalysisTaskFittingQDistribution("TaskFittingQDistribution",kFALSE);}
590     taskFQD->SetAnalysisType(type);
591     taskFQD->SetCFManager1(cfmgr1);
592     taskFQD->SetCFManager2(cfmgr2);
593     if (QA) { 
594       taskFQD->SetQAList1(qaIntFQD);
595       taskFQD->SetQAList2(qaDiffFQD); }
596     mgr->AddTask(taskFQD);
597   }
598   if (MCEP){
599     if (QA) { AliAnalysisTaskMCEventPlane *taskMCEP = new AliAnalysisTaskMCEventPlane("TaskMCEventPlane",kTRUE);}
600     else { AliAnalysisTaskMCEventPlane *taskMCEP = new AliAnalysisTaskMCEventPlane("TaskMCEventPlane",kFALSE);}
601     taskMCEP->SetAnalysisType(type);
602     taskMCEP->SetCFManager1(cfmgr1);
603     taskMCEP->SetCFManager2(cfmgr2);
604     if (QA) { 
605       taskMCEP->SetQAList1(qaIntMCEP);
606       taskMCEP->SetQAList2(qaDiffMCEP); }
607     mgr->AddTask(taskMCEP);
608   }
609   
610   
611   // Create containers for input/output
612   AliAnalysisDataContainer *cinput1 = 
613     mgr->CreateContainer("cchain1",TChain::Class(),AliAnalysisManager::kInputContainer);
614     
615   //AliAnalysisDataContainer *cinputWeights = NULL;  
616   if(useWeights)
617   {    
618    cinputWeights = mgr->CreateContainer("cobjWeights",TList::Class(),AliAnalysisManager::kInputContainer); 
619   }  
620   
621   if (LYZ2){ 
622     AliAnalysisDataContainer *cinputLYZ2 = 
623       mgr->CreateContainer("cobjLYZ2in",TList::Class(),AliAnalysisManager::kInputContainer); } 
624   if (LYZEP){ 
625     AliAnalysisDataContainer *cinputLYZEP = 
626       mgr->CreateContainer("cobjLYZEPin",TList::Class(),AliAnalysisManager::kInputContainer); } 
627   
628   if(SP) {
629     TString outputSP = "outputSPanalysis";
630     outputSP+= type;
631     outputSP+= ".root";
632     AliAnalysisDataContainer *coutputSP = 
633       mgr->CreateContainer("cobjSP", TList::Class(),AliAnalysisManager::kOutputContainer,outputSP);
634   }
635   
636   if(LYZ1) {
637     TString outputLYZ1 = "outputLYZ1analysis";
638     outputLYZ1+= type;
639     outputLYZ1+= ".root";
640     AliAnalysisDataContainer *coutputLYZ1 = 
641       mgr->CreateContainer("cobjLYZ1", TList::Class(),AliAnalysisManager::kOutputContainer,outputLYZ1);
642   }
643   
644   if(LYZ2) {
645     TString outputLYZ2 = "outputLYZ2analysis";
646     outputLYZ2+= type;
647     outputLYZ2+= ".root";
648     AliAnalysisDataContainer *coutputLYZ2 = 
649       mgr->CreateContainer("cobjLYZ2", TList::Class(),AliAnalysisManager::kOutputContainer,outputLYZ2);
650   }
651   
652   if(LYZEP) {
653     TString outputLYZEP = "outputLYZEPanalysis";
654     outputLYZEP+= type;
655     outputLYZEP+= ".root";
656     AliAnalysisDataContainer *coutputLYZEP = 
657       mgr->CreateContainer("cobjLYZEP", TList::Class(),AliAnalysisManager::kOutputContainer,outputLYZEP);
658   }
659   
660   if(GFC) {
661     TString outputGFC = "outputGFCanalysis";
662     outputGFC+= type;
663     outputGFC+= ".root";
664     AliAnalysisDataContainer *coutputGFC = 
665       mgr->CreateContainer("cobjGFC", TList::Class(),AliAnalysisManager::kOutputContainer,outputGFC);
666   }
667   
668   if(QC) {
669     TString outputQC = "outputQCanalysis";
670     outputQC+= type;
671     outputQC+= ".root";
672     AliAnalysisDataContainer *coutputQC = 
673       mgr->CreateContainer("cobjQC", TList::Class(),AliAnalysisManager::kOutputContainer,outputQC);
674   }
675   
676   if(FQD) {
677     TString outputFQD = "outputFQDanalysis";
678     outputFQD+= type;
679     outputFQD+= ".root";
680     AliAnalysisDataContainer *coutputFQD = 
681       mgr->CreateContainer("cobjFQD", TList::Class(),AliAnalysisManager::kOutputContainer,outputFQD);
682   } 
683
684   if(MCEP) {
685     TString outputMCEP = "outputMCEPanalysis";
686     outputMCEP+= type;
687     outputMCEP+= ".root";
688     AliAnalysisDataContainer *coutputMCEP = 
689       mgr->CreateContainer("cobjMCEP", TList::Class(),AliAnalysisManager::kOutputContainer,outputMCEP);
690   }
691   
692   if (QA) { 
693     if(SP) {
694       TString qaNameIntSP = "QAforInt_SP_";
695       qaNameIntSP += type;
696       qaNameIntSP += ".root";
697       AliAnalysisDataContainer *coutputQA1SP = 
698         mgr->CreateContainer("QAintSP", TList::Class(),AliAnalysisManager::kOutputContainer,qaNameIntSP);
699       
700       TString qaNameDiffSP = "QAforDiff_SP_";
701       qaNameDiffSP += type;
702       qaNameDiffSP += ".root";
703       AliAnalysisDataContainer *coutputQA2SP = 
704         mgr->CreateContainer("QAdiffSP", TList::Class(),AliAnalysisManager::kOutputContainer,qaNameDiffSP);
705     }
706     if(LYZ1) {
707       TString qaNameIntLYZ1 = "QAforInt_LYZ1_";
708       qaNameIntLYZ1 += type;
709       qaNameIntLYZ1 += ".root";
710       AliAnalysisDataContainer *coutputQA1LYZ1 = 
711         mgr->CreateContainer("QAintLYZ1", TList::Class(),AliAnalysisManager::kOutputContainer,qaNameIntLYZ1);
712       
713       TString qaNameDiffLYZ1 = "QAforDiff_LYZ1_";
714       qaNameDiffLYZ1 += type;
715       qaNameDiffLYZ1 += ".root";
716       AliAnalysisDataContainer *coutputQA2LYZ1 = 
717         mgr->CreateContainer("QAdiffLYZ1", TList::Class(),AliAnalysisManager::kOutputContainer,qaNameDiffLYZ1);
718     }
719     if(LYZ2) {
720       TString qaNameIntLYZ2 = "QAforInt_LYZ2_";
721       qaNameIntLYZ2 += type;
722       qaNameIntLYZ2 += ".root";
723       AliAnalysisDataContainer *coutputQA1LYZ2 = 
724         mgr->CreateContainer("QAintLYZ2", TList::Class(),AliAnalysisManager::kOutputContainer,qaNameIntLYZ2);
725       
726       TString qaNameDiffLYZ2 = "QAforDiff_LYZ2_";
727       qaNameDiffLYZ2 += type;
728       qaNameDiffLYZ2 += ".root";
729       AliAnalysisDataContainer *coutputQA2LYZ2 = 
730         mgr->CreateContainer("QAdiffLYZ2", TList::Class(),AliAnalysisManager::kOutputContainer,qaNameDiffLYZ2);
731     }
732     if(LYZEP) {
733       TString qaNameIntLYZEP = "QAforInt_LYZEP_";
734       qaNameIntLYZEP += type;
735       qaNameIntLYZEP += ".root";
736       AliAnalysisDataContainer *coutputQA1LYZEP = 
737         mgr->CreateContainer("QAintLYZEP", TList::Class(),AliAnalysisManager::kOutputContainer,qaNameIntLYZEP);
738       
739       TString qaNameDiffLYZEP = "QAforDiff_LYZEP_";
740       qaNameDiffLYZEP += type;
741       qaNameDiffLYZEP += ".root";
742       AliAnalysisDataContainer *coutputQA2LYZEP = 
743         mgr->CreateContainer("QAdiffLYZEP", TList::Class(),AliAnalysisManager::kOutputContainer,qaNameDiffLYZEP);
744     }
745     if(GFC) { 
746       TString qaNameIntGFC = "QAforInt_GFC_";
747       qaNameIntGFC += type;
748       qaNameIntGFC += ".root";
749       AliAnalysisDataContainer *coutputQA1GFC = 
750         mgr->CreateContainer("QAintGFC", TList::Class(),AliAnalysisManager::kOutputContainer,qaNameIntGFC);
751       
752       TString qaNameDiffGFC = "QAforDiff_GFC_";
753       qaNameDiffGFC += type;
754       qaNameDiffGFC += ".root";
755       AliAnalysisDataContainer *coutputQA2GFC = 
756         mgr->CreateContainer("QAdiffGFC", TList::Class(),AliAnalysisManager::kOutputContainer,qaNameDiffGFC);
757     }
758     if(QC) { 
759       TString qaNameIntQC = "QAforInt_QC_";
760       qaNameIntQC += type;
761       qaNameIntQC += ".root";
762       AliAnalysisDataContainer *coutputQA1QC = 
763         mgr->CreateContainer("QAintQC", TList::Class(),AliAnalysisManager::kOutputContainer,qaNameIntQC);
764       
765       TString qaNameDiffQC = "QAforDiff_QC_";
766       qaNameDiffQC += type;
767       qaNameDiffQC += ".root";
768       AliAnalysisDataContainer *coutputQA2QC = 
769         mgr->CreateContainer("QAdiffQC", TList::Class(),AliAnalysisManager::kOutputContainer,qaNameDiffQC);
770     }
771     if(FQD) { 
772       TString qaNameIntFQD = "QAforInt_FQD_";
773       qaNameIntFQD += type;
774       qaNameIntFQD += ".root";
775       AliAnalysisDataContainer *coutputQA1FQD = 
776         mgr->CreateContainer("QAintFQD", TList::Class(),AliAnalysisManager::kOutputContainer,qaNameIntFQD);
777       
778       TString qaNameDiffFQD = "QAforDiff_FQD_";
779       qaNameDiffFQD += type;
780       qaNameDiffFQD += ".root";
781       AliAnalysisDataContainer *coutputQA2FQD = 
782         mgr->CreateContainer("QAdiffFQD", TList::Class(),AliAnalysisManager::kOutputContainer,qaNameDiffFQD);
783     }
784     if(MCEP) {
785       TString qaNameIntMCEP = "QAforInt_MCEP_";
786       qaNameIntMCEP += type;
787       qaNameIntMCEP += ".root";
788       AliAnalysisDataContainer *coutputQA1MCEP = 
789         mgr->CreateContainer("QAintMCEP", TList::Class(),AliAnalysisManager::kOutputContainer,qaNameIntMCEP);
790       
791       TString qaNameDiffMCEP = "QAforDiff_MCEP_";
792       qaNameDiffMCEP += type;
793       qaNameDiffMCEP += ".root";
794       AliAnalysisDataContainer *coutputQA2MCEP = 
795         mgr->CreateContainer("QAdiffMCEP", TList::Class(),AliAnalysisManager::kOutputContainer,qaNameDiffMCEP);
796     }
797   }
798   
799   //____________________________________________//
800   
801   if (SP)   { 
802     mgr->ConnectInput(taskSP,0,cinput1); 
803     mgr->ConnectOutput(taskSP,0,coutputSP);
804     if (QA) { mgr->ConnectOutput(taskSP,1,coutputQA1SP);
805     mgr->ConnectOutput(taskSP,2,coutputQA2SP); }
806   } 
807   if (LYZ1) { 
808     mgr->ConnectInput(taskLYZ1,0,cinput1); 
809     mgr->ConnectOutput(taskLYZ1,0,coutputLYZ1);
810     if (QA) { mgr->ConnectOutput(taskLYZ1,1,coutputQA1LYZ1);
811     mgr->ConnectOutput(taskLYZ1,2,coutputQA2LYZ1); }
812   }  
813   if (LYZ2) { 
814     mgr->ConnectInput(taskLYZ2,0,cinput1); 
815     mgr->ConnectInput(taskLYZ2,1,cinputLYZ2);
816     mgr->ConnectOutput(taskLYZ2,0,coutputLYZ2);
817     if (QA) { mgr->ConnectOutput(taskLYZ2,1,coutputQA1LYZ2);
818     mgr->ConnectOutput(taskLYZ2,2,coutputQA2LYZ2); }
819     cinputLYZ2->SetData(fInputListLYZ2);
820   }  
821   if (LYZEP) { 
822     mgr->ConnectInput(taskLYZEP,0,cinput1); 
823     mgr->ConnectInput(taskLYZEP,1,cinputLYZEP);
824     mgr->ConnectOutput(taskLYZEP,0,coutputLYZEP);
825     if (QA) { mgr->ConnectOutput(taskLYZEP,1,coutputQA1LYZEP);
826     mgr->ConnectOutput(taskLYZEP,2,coutputQA2LYZEP); }
827     cinputLYZEP->SetData(fInputListLYZEP);
828   }
829   if (GFC)   { 
830     mgr->ConnectInput(taskGFC,0,cinput1); 
831     mgr->ConnectOutput(taskGFC,0,coutputGFC);
832     if (QA) { mgr->ConnectOutput(taskGFC,1,coutputQA1GFC);
833     mgr->ConnectOutput(taskGFC,2,coutputQA2GFC); }
834   }  
835   if (QC)   { 
836     mgr->ConnectInput(taskQC,0,cinput1); 
837     mgr->ConnectOutput(taskQC,0,coutputQC);
838     if (QA) { mgr->ConnectOutput(taskQC,1,coutputQA1QC);
839     mgr->ConnectOutput(taskQC,2,coutputQA2QC); }
840     if(useWeights)
841     {
842      mgr->ConnectInput(taskQC,1,cinputWeights);
843      cinputWeights->SetData(weightsList);
844     } 
845   }
846   if (FQD)   { 
847     mgr->ConnectInput(taskFQD,0,cinput1); 
848     mgr->ConnectOutput(taskFQD,0,coutputFQD);
849     if (QA) { mgr->ConnectOutput(taskFQD,1,coutputQA1FQD);
850     mgr->ConnectOutput(taskFQD,2,coutputQA2FQD); }
851   }    
852   if (MCEP)  { 
853     mgr->ConnectInput(taskMCEP,0,cinput1); 
854     mgr->ConnectOutput(taskMCEP,0,coutputMCEP);
855     if (QA) { mgr->ConnectOutput(taskMCEP,1,coutputQA1MCEP);
856     mgr->ConnectOutput(taskMCEP,2,coutputQA2MCEP); }
857   }  
858   
859   if (!mgr->InitAnalysis()) return;
860   mgr->PrintStatus();
861   mgr->StartAnalysis("local",chain);
862   
863   timer.Stop();
864   timer.Print();
865 }
866
867
868 // Helper macros for creating chains
869 // from: CreateESDChain.C,v 1.10 jgrosseo Exp
870
871 TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
872 {
873   // creates chain of files in a given directory or file containing a list.
874   // In case of directory the structure is expected as:
875   // <aDataDir>/<dir0>/AliESDs.root
876   // <aDataDir>/<dir1>/AliESDs.root
877   // ...
878   
879   if (!aDataDir)
880     return 0;
881   
882   Long_t id, size, flags, modtime;
883   if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
884     {
885       printf("%s not found.\n", aDataDir);
886       return 0;
887     }
888   
889   TChain* chain = new TChain("esdTree");
890   TChain* chaingAlice = 0;
891   
892   if (flags & 2)
893     {
894       TString execDir(gSystem->pwd());
895       TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
896       TList* dirList            = baseDir->GetListOfFiles();
897       Int_t nDirs               = dirList->GetEntries();
898       gSystem->cd(execDir);
899       
900       Int_t count = 0;
901       
902       for (Int_t iDir=0; iDir<nDirs; ++iDir)
903         {
904           TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
905           if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
906             continue;
907           
908           if (offset > 0)
909             {
910               --offset;
911               continue;
912             }
913           
914           if (count++ == aRuns)
915             break;
916           
917           TString presentDirName(aDataDir);
918           presentDirName += "/";
919           presentDirName += presentDir->GetName();        
920           chain->Add(presentDirName + "/AliESDs.root/esdTree");
921           //  cerr<<presentDirName<<endl;
922         }
923       
924     }
925   else
926     {
927       // Open the input stream
928       ifstream in;
929       in.open(aDataDir);
930       
931       Int_t count = 0;
932       
933       // Read the input list of files and add them to the chain
934       TString esdfile;
935       while(in.good()) {
936         in >> esdfile;
937         if (!esdfile.Contains("root")) continue; // protection
938         
939         if (offset > 0)
940           {
941             --offset;
942             continue;
943           }
944         
945         if (count++ == aRuns)
946           break;
947         
948         // add esd file
949         chain->Add(esdfile);
950       }
951       
952       in.close();
953     }
954   
955   return chain;
956 }
957
958 // Helper macros for creating chains
959 // from: CreateESDChain.C,v 1.10 jgrosseo Exp
960
961 TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
962 {
963   // creates chain of files in a given directory or file containing a list.
964   // In case of directory the structure is expected as:
965   // <aDataDir>/<dir0>/AliAOD.root
966   // <aDataDir>/<dir1>/AliAOD.root
967   // ...
968   
969   if (!aDataDir)
970     return 0;
971   
972   Long_t id, size, flags, modtime;
973   if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
974     {
975       printf("%s not found.\n", aDataDir);
976       return 0;
977     }
978   
979   TChain* chain = new TChain("aodTree");
980   TChain* chaingAlice = 0;
981   
982   if (flags & 2)
983     {
984       TString execDir(gSystem->pwd());
985       TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
986       TList* dirList            = baseDir->GetListOfFiles();
987       Int_t nDirs               = dirList->GetEntries();
988       gSystem->cd(execDir);
989       
990       Int_t count = 0;
991       
992       for (Int_t iDir=0; iDir<nDirs; ++iDir)
993         {
994           TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
995           if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
996             continue;
997           
998           if (offset > 0)
999             {
1000               --offset;
1001               continue;
1002             }
1003           
1004           if (count++ == aRuns)
1005             break;
1006           
1007           TString presentDirName(aDataDir);
1008           presentDirName += "/";
1009           presentDirName += presentDir->GetName();        
1010           chain->Add(presentDirName + "/AliAOD.root/aodTree");
1011           // cerr<<presentDirName<<endl;
1012         }
1013       
1014     }
1015   else
1016     {
1017       // Open the input stream
1018       ifstream in;
1019       in.open(aDataDir);
1020       
1021       Int_t count = 0;
1022       
1023       // Read the input list of files and add them to the chain
1024       TString aodfile;
1025       while(in.good()) {
1026         in >> aodfile;
1027         if (!aodfile.Contains("root")) continue; // protection
1028         
1029         if (offset > 0)
1030           {
1031             --offset;
1032             continue;
1033           }
1034         
1035         if (count++ == aRuns)
1036           break;
1037         
1038         // add aod file
1039         chain->Add(aodfile);
1040       }
1041       
1042       in.close();
1043     }
1044   
1045   return chain;
1046 }
1047