]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGLF/STRANGENESS/LambdaK0PbPb/runAOD.C
.so cleanup: removed from gSystem->Load()
[u/mrichter/AliRoot.git] / PWGLF / STRANGENESS / LambdaK0PbPb / runAOD.C
CommitLineData
7e7db1a0 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 runAOD(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 //Add AOD handler
52 AliAODInputHandler* aodH = new AliAODInputHandler;
53 mgr->SetInputEventHandler(aodH);
54 /*
55 if(isMC) {
56 AliMCEventHandler* handler = new AliMCEventHandler;
57 handler->SetPreReadMode(AliMCEventHandler::kLmPreRead);
58 mgr->SetMCtruthEventHandler(handler);
59 }
60 */
61
62 // If we are running on grid, we need the alien handler
63 if (runMode == kMyRunModeGRID) {
64 // Create and configure the alien handler plugin
65 TGrid::Connect("alien://");// Why do I need this? Without a get a bus error...
66 gROOT->LoadMacro("CreateAlienHandler.C");
67 AliAnalysisGrid *alienHandler = CreateAlienHandler(data, listToLoad, gridMode, isMC);
68 if (!alienHandler) {
69 cout << "Cannot create alien handler" << endl;
70 exit(1);
71 }
72 mgr->SetGridHandler(alienHandler);
73 }
74
75 // Physics selection
76 gROOT->ProcessLine(".L $ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
77 // AliPhysicsSelectionTask * physicsSelectionTask = AddTaskPhysicsSelection(isMC,kTRUE,0);
78 AliPhysicsSelectionTask * physicsSelectionTask = AddTaskPhysicsSelection(isMC,kTRUE,0);
79 // AliPhysicsSelectionTask * physicsSelectionTask = AddTaskPhysicsSelection(isMC,kFALSE,0);
80 if(!physicsSelectionTask ) { Printf("no physSelTask"); return; }
81
82 /* gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
83 AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
84 //taskCentrality->SetPass(2); i
85 if(isMC) taskCentrality->SetMCInput();
86 */
87 // PID task
88 gROOT->ProcessLine(".L $ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C");
89 AliAnalysisTask *PIDTask = AddTaskPIDResponse(isMC,kTRUE);
90 if(!PIDTask ) { Printf("no physSelTask"); return; }
91
92 /* // Centrality
93 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
94 AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
95 //taskCentrality->SetPass(2);
96 if(isMC) taskCentrality->SetMCInput();
97 */
98 // Parse option strings
99 TString optionStr(option);
100
101 // remove SAVE option if set
102 Bool_t doSave = kFALSE;
103
104 if (optionStr.Contains("SAVE"))
105 {
106 optionStr = optionStr(0,optionStr.Index("SAVE")) + optionStr(optionStr.Index("SAVE")+4, optionStr.Length());
107 doSave = kTRUE;
108 }
109 TString pathsuffix = "";
110 // Not used, but may be useful
111 Bool_t useMCKinematics = isMC;
112 if (optionStr.Contains("NOMCKIN")) {
113 cout << ">>>> Ignoring MC kinematics" << endl;
114 useMCKinematics=kFALSE;
115 pathsuffix+="_NOMCKIN";
116 }
117
118 gROOT->ProcessLine(".L AddTaskLambdaK0PbPbAOD.C");
119 Int_t nbin = 0; // will contain the number of centrality bins
120 AliAnalysisTaskPerformanceStrangeAOD ** task = AddTaskLambdaK0PbPbAOD("lambdak0.root", nbin, binMin, binMax,isMC); // FIXME also pass cuts, centrality bin type selection(5,10% percentiles, ranges...)
121 // configure task
122 // else if (iAODanalysis) task->SetAnalysisType("AOD");
123 // FIXME: add options to macro
124 // FIXME: put physics selection inside the task
125 cout << nbin << endl;
126
127 for(Int_t ibin = 0; ibin < nbin; ibin++){
128 cout << "ibin " << ibin << " "<< endl;//task[ibin] << endl;
129
130 task[ibin]->SetAnalysisType("AOD");
131 cout << "1" << endl;
132 task[ibin]->SetAnalysisMC(isMC); // 0 or 1
133 cout << "2" << endl;
134 task[ibin]->SetCollidingSystems(1); // 0 =pp, 1=AA
135 cout << "3" << endl;
136 task[ibin]->SetAnalysisCut("no");
137 cout << "4" << endl;
138 task[ibin]->SetQASelector(kFALSE);
139 cout<< "5" << endl;
140 if(usePID)
141 task[ibin]->SetUsePID("withPID"); // withPID or withoutPID
142 else
143 task[ibin]->SetUsePID("withoutPID"); // withPID or withoutPID
144 cout << "5" << endl;
145 }
146
147 // Init and run the analy
148 if (!mgr->InitAnalysis()) return;
149
150 mgr->PrintStatus();
151
152 if (runMode == kMyRunModeLocal ) {
153 // If running in local mode, create chain of ESD files
154 cout << "RUNNING LOCAL, CHAIN" << endl;
155 TChain * chain = GetAnalysisChain(data);
156 // chain->Print();
157 mgr->StartAnalysis("local",chain,nev);
158 } else if (runMode == kMyRunModeCAF) {
159 mgr->StartAnalysis("proof",TString(passOrPath)+data+"#aodTree",nev);
160 } else if (runMode == kMyRunModeGRID) {
161 mgr->StartAnalysis("grid");
162 } else {
163 cout << "ERROR: unknown run mode" << endl;
164 }
165
166 pathsuffix += customSuffix;
167
168 if (doSave) MoveOutput(data, pathsuffix.Data());
169
170
171}
172
173void MoveOutput(const char * data, const char * suffix = ""){
174
175 // TString path("output10bins/");
176 TString path("output10binsNew/");
177 path = path + TString(data).Tokenize("/")->Last()->GetName() + suffix;
178
179 TString fileName = "lambdak0.root";
180 gSystem->mkdir(path, kTRUE);
181 gSystem->Rename(fileName, path + "/" + fileName);
182 for(Int_t ibin = 0; ibin < 20; ibin++){
183 TString fileBin = fileName;
184 fileBin.ReplaceAll(".root",Form("_%2.2d.root",ibin));
185 gSystem->Rename(fileBin, path + "/" + fileBin);
186 }
187
188 gSystem->Rename("event_stat.root", path + "/event_stat.root");
189 gSystem->Rename("EventStat_temp.root", path + "/EventStat_temp.root");
190 Printf(">>>>> Moved files to %s", path.Data());
191}
192
193
194
195TChain * GetAnalysisChain(const char * incollection){
196 // Builds a chain of esd files
197 // incollection can be
198 // - a single root file
199 // - an xml collection of files on alien
200 // - a ASCII containing a list of local root files
201
202 TChain* analysisChain = 0;
203 // chain
204 analysisChain = new TChain("aodTree");
205 if (TString(incollection).Contains(".root")){
206 analysisChain->Add(incollection);
207 }
208 else if (TString(incollection).Contains("xml")){
209 TGrid::Connect("alien://");
210 TGridCollection * coll = TAlienCollection::Open (incollection);
211 while(coll->Next()){
212 analysisChain->Add(TString("alien://")+coll->GetLFN());
213 }
214 } else {
215 ifstream file_collect(incollection);
216 TString line;
217 while (line.ReadLine(file_collect) ) {
218 analysisChain->Add(line.Data());
219 }
220 }
221 analysisChain->GetListOfFiles()->Print();
222
223 return analysisChain;
224}
225
226
227void InitAndLoadLibs(Int_t runMode, Int_t workers,Bool_t debug) {
228 // Loads libs and par files + custom task and classes (the order is important)
229 listToLoad->Add(new TObjString("AliAnalysisTaskPerformanceStrangeAOD.cxx"));
230
231 if (runMode == kMyRunModeCAF)
232 {
233 cout << "Init in CAF mode" << endl;
234
235 gEnv->SetValue("XSec.GSI.DelegProxy", "2");
236 Char_t* alienuser = gSystem->Getenv("alien_API_USER");
237 TProof * p = TProof::Open(alienuser!=0 ? Form("%s@alice-caf.cern.ch",alienuser) : "alice-caf.cern.ch", workers>0 ? Form("workers=%d",workers) : "");
238 //TProof * p = TProof::Open("skaf.saske.sk", workers>0 ? Form("workers=%d",workers) : "");
239 p->Exec("TObject *o = gEnv->GetTable()->FindObject(\"Proof.UseMergers\"); gEnv->GetTable()->Remove(o);", kTRUE); // avoid submerging
240 gProof->EnablePackage("VO_ALICE@AliRoot::v5-02-19-AN");
241 //gProof->GetManager()->SetROOTVersion("VO_ALICE@ROOT::v5-30-02");
242 //gProof->EnablePackage("VO_ALICE@AliRoot::v5-02-04-AN");
243
244
245 // Enable the needed package
246 // FIXME: what if I don't want to use par files?
247 gSystem->AddIncludePath("-I${ALICE_ROOT}/include/");
248 gSystem->AddIncludePath("-I${ALICE_ROOT}/STEER/");
249
250 }
251 else
252 {
253 cout << "Init in Local or Grid mode" << endl;
4070f709 254 gSystem->Load("libCore");
255 gSystem->Load("libTree");
256 gSystem->Load("libGeom");
257 gSystem->Load("libVMC");
258 gSystem->Load("libPhysics");
7e7db1a0 259 gSystem->Load("libSTEERBase");
260 gSystem->Load("libESD");
261 gSystem->Load("libAOD");
262 gSystem->Load("libANALYSIS");
4070f709 263 gSystem->Load("libOADB");
7e7db1a0 264 gSystem->Load("libANALYSISalice");
265
266 // gSystem->Load("libVMC");
267 gROOT->ProcessLine(".include $ALICE_ROOT/include");
268 gROOT->ProcessLine(".include $ALICE_ROOT/STEER");
269 }
270 // Load helper classes
271 TIterator * iter = listToLoad->MakeIterator();
272 TObjString * name = 0;
273 while ((name = (TObjString *)iter->Next())) {
274 gSystem->ExpandPathName(name->String());
275 cout << name->String().Data() << endl;
276 if (runMode == kMyRunModeCAF) {
277 gProof->Load(name->String()+(debug?"++g":"+"));
278 } else {
279 gROOT->LoadMacro(name->String()+(debug?"++g":"+"));
280 }
281 }
282
283}