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