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