]>
Commit | Line | Data |
---|---|---|
8797f8b6 | 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 | ||
21 | using namespace std; | |
22 | ||
23 | enum { kMyRunModeLocal = 0, kMyRunModeCAF, kMyRunModeGRID}; | |
24 | ||
25 | TList * listToLoad = new TList(); // Additional classes to be loaded, see InitAndLoadLibs | |
26 | ||
27 | TChain * GetAnalysisChain(const char * incollection); | |
28 | void InitAndLoadLibs(Int_t runMode=kMyRunModeLocal, Int_t workers=0,Bool_t debug=0) ; | |
29 | ||
30 | void run(const char * data, const char * passOrPath, Long64_t nev = -1, Long64_t offset = 0, Bool_t debug = kFALSE, Int_t runMode = 0, 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 = 6) | |
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 | ||
72 | // Physics selection | |
73 | gROOT->ProcessLine(".L $ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C"); | |
74 | AliPhysicsSelectionTask * physicsSelectionTask = AddTaskPhysicsSelection(isMC); | |
75 | ||
76 | // Centrality | |
77 | gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C"); | |
78 | AliCentralitySelectionTask *taskCentrality = AddTaskCentrality(); | |
79 | taskCentrality->SetPass(2); | |
80 | if(isMC) taskCentrality->SetMCInput(); | |
81 | ||
82 | AliAnalysisCentralitySelector * centrSelector = new AliAnalysisCentralitySelector(); | |
83 | centrSelector->SetIsMC(isMC); | |
84 | centrSelector->SetCentralityEstimator("V0M"); // Todo: add parameter to macro? | |
85 | ||
86 | // Parse option strings | |
87 | TString optionStr(option); | |
88 | ||
89 | // remove SAVE option if set | |
90 | Bool_t doSave = kFALSE; | |
91 | ||
92 | if (optionStr.Contains("SAVE")) | |
93 | { | |
94 | optionStr = optionStr(0,optionStr.Index("SAVE")) + optionStr(optionStr.Index("SAVE")+4, optionStr.Length()); | |
95 | doSave = kTRUE; | |
96 | } | |
97 | TString pathsuffix = ""; | |
98 | // Not used, but may be useful | |
99 | Bool_t useMCKinematics = isMC; | |
100 | if (optionStr.Contains("NOMCKIN")) { | |
101 | cout << ">>>> Ignoring MC kinematics" << endl; | |
102 | useMCKinematics=kFALSE; | |
103 | pathsuffix+="_NOMCKIN"; | |
104 | } | |
105 | ||
106 | gROOT->ProcessLine(".L AddTaskLambdaK0PbPb.C"); | |
107 | Int_t nbin = 0; // will contain the number of centrality bins | |
108 | AliAnalysisTaskPerformanceStrange ** task = AddTaskLambdaK0PbPb("lambdak0.root", centrSelector, nbin, binMin, binMax); // FIXME also pass cuts, centrality bin type selection(5,10% percentiles, ranges...) | |
109 | // configure task | |
110 | // else if (iAODanalysis) task->SetAnalysisType("AOD"); | |
111 | // FIXME: add options to macro | |
112 | // FIXME: put physics selection inside the task | |
113 | cout << nbin << endl; | |
114 | ||
115 | for(Int_t ibin = 0; ibin < nbin; ibin++){ | |
116 | cout << "ibin " << ibin << " "<< endl;//task[ibin] << endl; | |
117 | ||
118 | task[ibin]->SetAnalysisType("ESD"); | |
119 | cout << "1" << endl; | |
120 | task[ibin]->SetAnalysisMC(isMC); // 0 or 1 | |
121 | cout << "2" << endl; | |
122 | task[ibin]->SetCollidingSystems(1); // 0 =pp, 1=AA | |
123 | cout << "3" << endl; | |
124 | task[ibin]->SetAnalysisCut("no"); | |
125 | cout << "4" << endl; | |
126 | if(usePID) | |
127 | task[ibin]->SetUsePID("withPID"); // withPID or withoutPID | |
128 | else | |
129 | task[ibin]->SetUsePID("withoutPID"); // withPID or withoutPID | |
130 | cout << "5" << endl; | |
131 | } | |
132 | ||
133 | // Init and run the analy | |
134 | if (!mgr->InitAnalysis()) return; | |
135 | ||
136 | mgr->PrintStatus(); | |
137 | ||
138 | if (runMode == kMyRunModeLocal ) { | |
139 | // If running in local mode, create chain of ESD files | |
140 | cout << "RUNNING LOCAL, CHAIN" << endl; | |
141 | TChain * chain = GetAnalysisChain(data); | |
142 | // chain->Print(); | |
143 | mgr->StartAnalysis("local",chain,nev); | |
144 | } else if (runMode == kMyRunModeCAF) { | |
145 | mgr->StartAnalysis("proof",TString(passOrPath)+data+"#esdTree",nev); | |
146 | } else if (runMode == kMyRunModeGRID) { | |
147 | mgr->StartAnalysis("grid"); | |
148 | } else { | |
149 | cout << "ERROR: unknown run mode" << endl; | |
150 | } | |
151 | ||
152 | pathsuffix += customSuffix; | |
153 | ||
154 | if (doSave) MoveOutput(data, pathsuffix.Data()); | |
155 | ||
156 | ||
157 | } | |
158 | ||
159 | void MoveOutput(const char * data, const char * suffix = ""){ | |
160 | ||
161 | TString path("output/"); | |
162 | path = path + TString(data).Tokenize("/")->Last()->GetName() + suffix; | |
163 | ||
164 | TString fileName = "lambdak0.root"; | |
165 | gSystem->mkdir(path, kTRUE); | |
166 | gSystem->Rename(fileName, path + "/" + fileName); | |
167 | for(Int_t ibin = 0; ibin < 20; ibin++){ | |
168 | TString fileBin = fileName; | |
169 | fileBin.ReplaceAll(".root",Form("_%2.2d.root",ibin)); | |
170 | gSystem->Rename(fileBin, path + "/" + fileBin); | |
171 | } | |
172 | ||
173 | gSystem->Rename("event_stat.root", path + "/event_stat.root"); | |
174 | gSystem->Rename("EventStat_temp.root", path + "/EventStat_temp.root"); | |
175 | Printf(">>>>> Moved files to %s", path.Data()); | |
176 | } | |
177 | ||
178 | ||
179 | ||
180 | TChain * GetAnalysisChain(const char * incollection){ | |
181 | // Builds a chain of esd files | |
182 | // incollection can be | |
183 | // - a single root file | |
184 | // - an xml collection of files on alien | |
185 | // - a ASCII containing a list of local root files | |
186 | ||
187 | TChain* analysisChain = 0; | |
188 | // chain | |
189 | analysisChain = new TChain("esdTree"); | |
190 | if (TString(incollection).Contains(".root")){ | |
191 | analysisChain->Add(incollection); | |
192 | } | |
193 | else if (TString(incollection).Contains("xml")){ | |
194 | TGrid::Connect("alien://"); | |
195 | TGridCollection * coll = TAlienCollection::Open (incollection); | |
196 | while(coll->Next()){ | |
197 | analysisChain->Add(TString("alien://")+coll->GetLFN()); | |
198 | } | |
199 | } else { | |
200 | ifstream file_collect(incollection); | |
201 | TString line; | |
202 | while (line.ReadLine(file_collect) ) { | |
203 | analysisChain->Add(line.Data()); | |
204 | } | |
205 | } | |
206 | analysisChain->GetListOfFiles()->Print(); | |
207 | ||
208 | return analysisChain; | |
209 | } | |
210 | ||
211 | ||
212 | void InitAndLoadLibs(Int_t runMode, Int_t workers,Bool_t debug) { | |
213 | // Loads libs and par files + custom task and classes (the order is important) | |
214 | // listToLoad->Add(new TObjString("$ALICE_ROOT/STEER/AliCentrality.cxx")); // FIXME: why do I have to load it?!? | |
215 | listToLoad->Add(new TObjString("AliAnalysisCentralitySelector.cxx")); | |
216 | listToLoad->Add(new TObjString("AliAnalysisTaskPerformanceStrange.cxx")); | |
217 | ||
218 | if (runMode == kMyRunModeCAF) | |
219 | { | |
220 | cout << "Init in CAF mode" << endl; | |
221 | ||
222 | gEnv->SetValue("XSec.GSI.DelegProxy", "2"); | |
223 | Char_t* alienuser = gSystem->Getenv("alien_API_USER"); | |
224 | TProof * p = TProof::Open(alienuser!=0 ? Form("%s@alice-caf.cern.ch",alienuser) : "alice-caf.cern.ch", workers>0 ? Form("workers=%d",workers) : ""); | |
225 | //TProof * p = TProof::Open("skaf.saske.sk", workers>0 ? Form("workers=%d",workers) : ""); | |
226 | p->Exec("TObject *o = gEnv->GetTable()->FindObject(\"Proof.UseMergers\"); gEnv->GetTable()->Remove(o);", kTRUE); // avoid submerging | |
227 | //gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-18-AN"); | |
228 | gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-20-AN"); | |
229 | ||
230 | ||
231 | // Enable the needed package | |
232 | // FIXME: what if I don't want to use par files? | |
233 | gSystem->AddIncludePath("-I${ALICE_ROOT}/include/"); | |
234 | gSystem->AddIncludePath("-I${ALICE_ROOT}/STEER/"); | |
235 | // gProof->UploadPackage("$ALICE_ROOT/obj/STEERBase"); | |
236 | // gProof->EnablePackage("$ALICE_ROOT/obj/STEERBase"); | |
237 | // gProof->UploadPackage("$ALICE_ROOT/obj/ESD"); | |
238 | // gProof->EnablePackage("$ALICE_ROOT/obj/ESD"); | |
239 | // gProof->UploadPackage("$ALICE_ROOT/obj/AOD"); | |
240 | // gProof->EnablePackage("$ALICE_ROOT/obj/AOD"); | |
241 | // gProof->UploadPackage("$ALICE_ROOT/obj/ANALYSIS"); | |
242 | // gProof->EnablePackage("$ALICE_ROOT/obj/ANALYSIS"); | |
243 | // gProof->UploadPackage("$ALICE_ROOT/obj/ANALYSISalice"); | |
244 | // gProof->EnablePackage("$ALICE_ROOT/obj/ANALYSISalice"); | |
245 | // gProof->UploadPackage("$ALICE_ROOT/obj/CORRFW"); | |
246 | // gProof->EnablePackage("$ALICE_ROOT/obj/CORRFW"); | |
247 | // gProof->UploadPackage("~/Desktop/OADB");//FIXME | |
248 | // gProof->EnablePackage("~/Desktop/OADB");//FIXME | |
249 | ||
250 | } | |
251 | else | |
252 | { | |
253 | cout << "Init in Local or Grid mode" << endl; | |
254 | gSystem->Load("libCore.so"); | |
255 | gSystem->Load("libTree.so"); | |
256 | gSystem->Load("libGeom.so"); | |
257 | gSystem->Load("libVMC.so"); | |
258 | gSystem->Load("libPhysics.so"); | |
259 | gSystem->Load("libSTEERBase"); | |
260 | gSystem->Load("libESD"); | |
261 | gSystem->Load("libAOD"); | |
262 | gSystem->Load("libANALYSIS"); | |
263 | gSystem->Load("libANALYSISalice"); | |
264 | ||
265 | // gSystem->Load("libVMC"); | |
266 | gROOT->ProcessLine(".include $ALICE_ROOT/include"); | |
267 | gROOT->ProcessLine(".include $ALICE_ROOT/STEER"); | |
268 | } | |
269 | // Load helper classes | |
270 | TIterator * iter = listToLoad->MakeIterator(); | |
271 | TObjString * name = 0; | |
272 | while ((name = (TObjString *)iter->Next())) { | |
273 | gSystem->ExpandPathName(name->String()); | |
274 | cout << name->String().Data() << endl; | |
275 | if (runMode == kMyRunModeCAF) { | |
276 | gProof->Load(name->String()+(debug?"++g":"+")); | |
277 | } else { | |
278 | gROOT->LoadMacro(name->String()+(debug?"++g":"+")); | |
279 | } | |
280 | } | |
281 | ||
282 | } |