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