]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGLF/STRANGENESS/LambdaK0PbPb/MainStreamAnalysis/run.C
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGLF / STRANGENESS / LambdaK0PbPb / MainStreamAnalysis / run.C
CommitLineData
9d9613cc 1// #include <iostream>
2// #include "AliAnalysisManager.h"
3// #include "AliESDInputHandler.h"
4// #include "AliMCEventHandler.h"
5// #include "AliAnalysisGrid.h"
6// #include "AliCentralitySelectionTask.h"
7// #include "AliAnalysisCentralitySelector.h"
8// #include "AliAnalysisTaskPerformanceStrange.h"
9// #include "TString.h"
10// #include "TChain.h"
11// #include "TAlienCollection.h"
12// #include <fstream>
13// #include "TObjString.h"
14// #include "TIterator.h"
15// #include "TGrid.h"
16// #include "TROOT.h"
17
18// #include "CreateAlienHandler.C"
19// #include
20
21using namespace std;
22
23enum { kMyRunModeLocal = 0, kMyRunModeCAF, kMyRunModeGRID};
24
25TList * listToLoad = new TList(); // Additional classes to be loaded, see InitAndLoadLibs
26
27TChain * GetAnalysisChain(const char * incollection);
28void InitAndLoadLibs(Int_t runMode=kMyRunModeLocal, Int_t workers=0,Bool_t debug=0) ;
29
30void run(const char * data, const char * passOrPath, Long64_t nev = -1, Long64_t offset = 0, Bool_t debug = kFALSE, Int_t runMode = 2, Bool_t isMC = 0, Bool_t usePID = kTRUE, const char* option = "",TString customSuffix = "", Int_t workers = -1, const char * gridMode="full", Int_t binMin=0, Int_t binMax = 10)
31{
32 // runMode:
33 //
34 // 0 local
35 // 1 proof
36 // 2 grid
37
38 if (nev < 0)
39 nev = 1234567890;
40 InitAndLoadLibs(runMode,workers,debug);
41
42 // Create the analysis manager
43 AliAnalysisManager * mgr = new AliAnalysisManager;
44
45 // Add ESD handler
46 AliESDInputHandler* esdH = new AliESDInputHandler;
47 // Do I need any of this?
48 // esdH->SetInactiveBranches("AliESDACORDE FMD ALIESDTZERO ALIESDZDC AliRawDataErrorLogs CaloClusters Cascades EMCALCells EMCALTrigger ESDfriend Kinks AliESDTZERO ALIESDACORDE MuonTracks TrdTracks");
49 mgr->SetInputEventHandler(esdH);
50
51 if(isMC) {
52 AliMCEventHandler* handler = new AliMCEventHandler;
53 handler->SetPreReadMode(AliMCEventHandler::kLmPreRead);
54 mgr->SetMCtruthEventHandler(handler);
55 }
56
57
58 // If we are running on grid, we need the alien handler
59 if (runMode == kMyRunModeGRID) {
60 // Create and configure the alien handler plugin
61 TGrid::Connect("alien://");// Why do I need this? Without a get a bus error...
62 gROOT->LoadMacro("CreateAlienHandler.C");
63 AliAnalysisGrid *alienHandler = CreateAlienHandler(data, listToLoad, gridMode, isMC);
64 if (!alienHandler) {
65 cout << "Cannot create alien handler" << endl;
66 exit(1);
67 }
68 mgr->SetGridHandler(alienHandler);
69 }
70
71 // PID task
72 gROOT->ProcessLine(".L $ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C");
73 AddTaskPIDResponse(isMC,kTRUE);
74 //AddTaskPIDResponse();
75
76
77 // Physics selection
63b6cbd0 78 gROOT->ProcessLine(".L $ALICE_ROOT/OADB/macros/AddTaskPhysicsSelection.C");
9d9613cc 79 AliPhysicsSelectionTask * physicsSelectionTask = AddTaskPhysicsSelection(isMC,kTRUE,0);
80
81 // Centrality
1c06a186 82 gROOT->LoadMacro("$ALICE_ROOT/OADB/macros/AddTaskCentrality.C");
9d9613cc 83 AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
84 //taskCentrality->SetPass(2);
85 if(isMC) taskCentrality->SetMCInput();
86
87 AliAnalysisCentralitySelector * centrSelector = new AliAnalysisCentralitySelector();
88 centrSelector->SetIsMC(isMC);
89 centrSelector->SetCentralityEstimator("V0M"); // Todo: add parameter to macro?
90
91 // Parse option strings
92 TString optionStr(option);
93
94 // remove SAVE option if set
95 Bool_t doSave = kFALSE;
96
97 if (optionStr.Contains("SAVE"))
98 {
99 optionStr = optionStr(0,optionStr.Index("SAVE")) + optionStr(optionStr.Index("SAVE")+4, optionStr.Length());
100 doSave = kTRUE;
101 }
102 TString pathsuffix = "";
103 // Not used, but may be useful
104 Bool_t useMCKinematics = isMC;
105 if (optionStr.Contains("NOMCKIN")) {
106 cout << ">>>> Ignoring MC kinematics" << endl;
107 useMCKinematics=kFALSE;
108 pathsuffix+="_NOMCKIN";
109 }
110
111 gROOT->ProcessLine(".L AddTaskLambdaK0PbPb.C");
112 Int_t nbin = 0; // will contain the number of centrality bins
113 AliAnalysisTaskPerformanceStrange ** task = AddTaskLambdaK0PbPb("lambdak0.root", centrSelector, nbin, binMin, binMax,isMC); // FIXME also pass cuts, centrality bin type selection(5,10% percentiles, ranges...)
114 // configure task
115 // else if (iAODanalysis) task->SetAnalysisType("AOD");
116 // FIXME: add options to macro
117 // FIXME: put physics selection inside the task
118 cout << nbin << endl;
119
120 for(Int_t ibin = 0; ibin < nbin; ibin++){
121 cout << "ibin " << ibin << " "<< endl;//task[ibin] << endl;
122
123 task[ibin]->SetAnalysisType("ESD");
124 cout << "1" << endl;
125 task[ibin]->SetAnalysisMC(isMC); // 0 or 1
126 cout << "2" << endl;
127 task[ibin]->SetCollidingSystems(1); // 0 =pp, 1=AA
128 cout << "3" << endl;
129 task[ibin]->SetAnalysisCut("no");
130 cout << "4" << endl;
131 task[ibin]->SetQASelector(kFALSE);
132 cout<< "5" << endl;
133 if(usePID)
134 task[ibin]->SetUsePID("withPID"); // withPID or withoutPID
135 else
136 task[ibin]->SetUsePID("withoutPID"); // withPID or withoutPID
11d8f775 137 task[ibin]->SetArmenterosCut(0.2);
138 cout << "6" << endl;
9d9613cc 139 }
140
141 // Init and run the analy
142 if (!mgr->InitAnalysis()) return;
143
144 mgr->PrintStatus();
145
146 if (runMode == kMyRunModeLocal ) {
147 // If running in local mode, create chain of ESD files
148 cout << "RUNNING LOCAL, CHAIN" << endl;
149 TChain * chain = GetAnalysisChain(data);
150 // chain->Print();
151 mgr->StartAnalysis("local",chain,nev);
152 } else if (runMode == kMyRunModeCAF) {
153 mgr->StartAnalysis("proof",TString(passOrPath)+data+"#esdTree",nev);
154 } else if (runMode == kMyRunModeGRID) {
155 mgr->StartAnalysis("grid");
156 } else {
157 cout << "ERROR: unknown run mode" << endl;
158 }
159
160 pathsuffix += customSuffix;
161
162 if (doSave) MoveOutput(data, pathsuffix.Data());
163
164
165}
166
167void MoveOutput(const char * data, const char * suffix = ""){
168
169 // TString path("output10bins/");
170 TString path("output10binsNew/");
171 path = path + TString(data).Tokenize("/")->Last()->GetName() + suffix;
172
173 TString fileName = "lambdak0.root";
174 gSystem->mkdir(path, kTRUE);
175 gSystem->Rename(fileName, path + "/" + fileName);
176 for(Int_t ibin = 0; ibin < 20; ibin++){
177 TString fileBin = fileName;
178 fileBin.ReplaceAll(".root",Form("_%2.2d.root",ibin));
179 gSystem->Rename(fileBin, path + "/" + fileBin);
180 }
181
182 gSystem->Rename("event_stat.root", path + "/event_stat.root");
183 gSystem->Rename("EventStat_temp.root", path + "/EventStat_temp.root");
184 Printf(">>>>> Moved files to %s", path.Data());
185}
186
187
188
189TChain * GetAnalysisChain(const char * incollection){
190 // Builds a chain of esd files
191 // incollection can be
192 // - a single root file
193 // - an xml collection of files on alien
194 // - a ASCII containing a list of local root files
195
196 TChain* analysisChain = 0;
197 // chain
198 analysisChain = new TChain("esdTree");
199 if (TString(incollection).Contains(".root")){
200 analysisChain->Add(incollection);
201 }
202 else if (TString(incollection).Contains("xml")){
203 TGrid::Connect("alien://");
204 TGridCollection * coll = TAlienCollection::Open (incollection);
205 while(coll->Next()){
206 analysisChain->Add(TString("alien://")+coll->GetLFN());
207 }
208 } else {
209 ifstream file_collect(incollection);
210 TString line;
211 while (line.ReadLine(file_collect) ) {
212 analysisChain->Add(line.Data());
213 }
214 }
215 analysisChain->GetListOfFiles()->Print();
216
217 return analysisChain;
218}
219
220
221void InitAndLoadLibs(Int_t runMode, Int_t workers,Bool_t debug) {
222 // Loads libs and par files + custom task and classes (the order is important)
223 // listToLoad->Add(new TObjString("$ALICE_ROOT/STEER/AliCentrality.cxx")); // FIXME: why do I have to load it?!?
224 listToLoad->Add(new TObjString("AliAnalysisCentralitySelector.cxx"));
225 listToLoad->Add(new TObjString("AliAnalysisTaskPerformanceStrange.cxx"));
226
227 if (runMode == kMyRunModeCAF)
228 {
229 cout << "Init in CAF mode" << endl;
230
231 gEnv->SetValue("XSec.GSI.DelegProxy", "2");
232 Char_t* alienuser = gSystem->Getenv("alien_API_USER");
233 TProof * p = TProof::Open(alienuser!=0 ? Form("%s@alice-caf.cern.ch",alienuser) : "alice-caf.cern.ch", workers>0 ? Form("workers=%d",workers) : "");
234 //TProof * p = TProof::Open("skaf.saske.sk", workers>0 ? Form("workers=%d",workers) : "");
235 p->Exec("TObject *o = gEnv->GetTable()->FindObject(\"Proof.UseMergers\"); gEnv->GetTable()->Remove(o);", kTRUE); // avoid submerging
236 //gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-18-AN");
237 //gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-20-AN");
238 //gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-21-AN");
239 //gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-28-AN");
240 //gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-31-AN");
241 // gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-33-AN");
242 // gProof->EnablePackage("VO_ALICE@AliRoot::v5-02-04-AN");
243 //gProof->EnablePackage("VO_ALICE@AliRoot::v5-02-08pA-AN");
244 gProof->EnablePackage("VO_ALICE@AliRoot::v5-03-01-AN");
245
246 // Enable the needed package
247 // FIXME: what if I don't want to use par files?
248 gSystem->AddIncludePath("-I${ALICE_ROOT}/include/");
249 gSystem->AddIncludePath("-I${ALICE_ROOT}/STEER/");
250 // gProof->UploadPackage("$ALICE_ROOT/obj/STEERBase");
251 // gProof->EnablePackage("$ALICE_ROOT/obj/STEERBase");
252 // gProof->UploadPackage("$ALICE_ROOT/obj/ESD");
253 // gProof->EnablePackage("$ALICE_ROOT/obj/ESD");
254 // gProof->UploadPackage("$ALICE_ROOT/obj/AOD");
255 // gProof->EnablePackage("$ALICE_ROOT/obj/AOD");
256 // gProof->UploadPackage("$ALICE_ROOT/obj/ANALYSIS");
257 // gProof->EnablePackage("$ALICE_ROOT/obj/ANALYSIS");
258 // gProof->UploadPackage("$ALICE_ROOT/obj/ANALYSISalice");
259 // gProof->EnablePackage("$ALICE_ROOT/obj/ANALYSISalice");
260 // gProof->UploadPackage("$ALICE_ROOT/obj/CORRFW");
261 // gProof->EnablePackage("$ALICE_ROOT/obj/CORRFW");
262 // gProof->UploadPackage("~/Desktop/OADB");//FIXME
263 // gProof->EnablePackage("~/Desktop/OADB");//FIXME
264
265 }
266 else
267 {
268 cout << "Init in Local or Grid mode" << endl;
4070f709 269 gSystem->Load("libCore");
270 gSystem->Load("libTree");
271 gSystem->Load("libGeom");
272 gSystem->Load("libVMC");
273 gSystem->Load("libPhysics");
9d9613cc 274 gSystem->Load("libSTEERBase");
275 gSystem->Load("libESD");
276 gSystem->Load("libAOD");
277 gSystem->Load("libANALYSIS");
278 gSystem->Load("libANALYSISalice");
279
280 // gSystem->Load("libVMC");
281 gROOT->ProcessLine(".include $ALICE_ROOT/include");
282 gROOT->ProcessLine(".include $ALICE_ROOT/STEER");
283 }
284 // Load helper classes
285 TIterator * iter = listToLoad->MakeIterator();
286 TObjString * name = 0;
287 while ((name = (TObjString *)iter->Next())) {
288 gSystem->ExpandPathName(name->String());
289 cout << name->String().Data() << endl;
290 if (runMode == kMyRunModeCAF) {
291 gProof->Load(name->String()+(debug?"++g":"+"));
292 } else {
293 gROOT->LoadMacro(name->String()+(debug?"++g":"+"));
294 }
295 }
296
297}