-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.C
375 lines (313 loc) · 10.5 KB
/
run.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
/**
* File : run.C
* Author : Anton Riedel <[email protected]>
* Date : 07.05.2021
* Last Modified Date: 06.09.2021
* Last Modified By : Anton Riedel <[email protected]>
*/
// Include macros (see
// https://alice-doc.github.io/alice-analysis-tutorial/analysis/ROOT5-to-6.html):
// For this to have an effect, it is assumted that some local AliROOT env is
// initialized, so that env variables ALICE_ROOT and ALICE_PHYSICS are set
#ifdef __CLING__
// Tell ROOT where to find AliRoot and AliPhysics headers:
R__ADD_INCLUDE_PATH($ALICE_ROOT)
R__ADD_INCLUDE_PATH($ALICE_PHYSICS)
#include "OADB/COMMON/MULTIPLICITY/macros/AddTaskMultSelection.C"
#include "OADB/macros/AddTaskPhysicsSelection.C"
#endif
// local macros
#include "AddTask.C"
#include "CreateAlienHandler.C"
// local function declarations
void LoadLibraries();
TChain *CreateAODChain(const char *aDataDir, Int_t aRuns, Int_t offset);
TChain *CreateESDChain(const char *aDataDir, Int_t aRuns, Int_t offset);
// 2/ The main macro:
void run(Int_t RunNumber = 137161, Int_t nEvents = 100, Int_t offset = 0) {
// Body:
// a) Time;
// b) Load needed libraries;
// c) Make analysis manager;
// d) Chains;
// e) Connect plug-in to the analysis manager;
// f) Event handlers;
// g) Task to check the offline trigger: for AODs this is not needed, indeed;
// h) Add the centrality determination task;
// i) Setup analysis per centrality bin;
// j) Enable debug printouts;
// k) Run the analysis;
// l) Print real and CPU time used for analysis.
// get configuration from the environemnt
const char *analysisMode = std::getenv("ANALYSIS_MODE");
const char *dataDir = std::getenv("DataDir");
Bool_t bRunOverData = kTRUE;
if (std::stoi(std::getenv("RUN_OVER_DATA")) == 1) {
bRunOverData = kTRUE;
} else {
bRunOverData = kFALSE;
}
Bool_t bRunOverAOD = kTRUE;
if (std::stoi(std::getenv("RUN_OVER_AOD")) == 1) {
bRunOverAOD = kTRUE;
} else {
bRunOverAOD = kFALSE;
}
// centrality bins
// Int_t binfirst = 0; // where do we start numbering bins
// Int_t binlast = 0; // where do we stop numbering bins
// const Int_t numberOfCentralityBins = 1;
// Float_t centralityArray[numberOfCentralityBins + 1] = {
// 0.0, 100.0}; // in centrality percentile
std::vector<Int_t> CentralityBins;
std::stringstream StreamCenBins(std::getenv("CENTRALITY_BIN_EDGES"));
std::string edge;
while (StreamCenBins >> edge) {
CentralityBins.push_back(std::stoi(edge));
}
// a) Time:
TStopwatch timer;
timer.Start();
// b) Load needed libraries:
LoadLibraries();
// c) Make analysis manager:
AliAnalysisManager *mgr = new AliAnalysisManager("FlowAnalysisManager");
// d) Chains:
TChain *chain = NULL;
if (TString(analysisMode).EqualTo("local")) {
if (bRunOverAOD) {
chain = CreateAODChain(dataDir, nEvents, offset);
} else {
chain = CreateESDChain(dataDir, nEvents, offset);
}
}
// e) Connect plug-in to the analysis manager:
if (TString(analysisMode).EqualTo("grid")) {
AliAnalysisGrid *alienHandler = CreateAlienHandler(RunNumber);
if (!alienHandler) {
return;
}
mgr->SetGridHandler(alienHandler);
}
// f) Event handlers:
if (bRunOverAOD) {
AliVEventHandler *aodH = new AliAODInputHandler();
mgr->SetInputEventHandler(aodH);
} else {
AliVEventHandler *esdH = new AliESDInputHandler();
mgr->SetInputEventHandler(esdH);
}
if (!bRunOverData) {
AliMCEventHandler *mc = new AliMCEventHandler();
mgr->SetMCtruthEventHandler(mc);
}
// g) Task to check the offline trigger: for AODs this is not needed, indeed
if (!bRunOverAOD) {
AddTaskPhysicsSelection(!bRunOverData);
}
// h) Add the centrality determination task:
AliMultSelectionTask *task = AddTaskMultSelection(kFALSE); // user mode
task->SetSelectedTriggerClass(
AliVEvent::kINT7); // set the trigger (kINT7 is minimum bias)
// i) Setup analysis per centrality bin:
for (std::size_t i = 0; i < CentralityBins.size() - 1; i++) {
Float_t lowCentralityBinEdge = CentralityBins.at(i);
Float_t highCentralityBinEdge = CentralityBins.at(i + 1);
Printf("\nWagon for centrality bin %i: %.1f-%.1f", int(i),
lowCentralityBinEdge, highCentralityBinEdge);
AddTask(lowCentralityBinEdge, highCentralityBinEdge, bRunOverAOD);
}
// j) Enable debug printouts:
mgr->SetDebugLevel(2);
// k) Run the analysis:
if (!mgr->InitAnalysis()) {
return;
}
mgr->PrintStatus();
if (TString(analysisMode).EqualTo("local")) {
mgr->StartAnalysis("local", chain);
} else if (TString(analysisMode).EqualTo("grid")) {
mgr->StartAnalysis("grid");
}
// l) Print real and CPU time used for analysis:
timer.Stop();
timer.Print();
return;
} // end of void run(...)
//===============================================================================================
void LoadLibraries() {
// Load the needed libraries (most of them already loaded by aliroot).
gSystem->Load("libCore");
gSystem->Load("libTree");
gSystem->Load("libGeom");
gSystem->Load("libVMC");
gSystem->Load("libXMLIO");
gSystem->Load("libPhysics");
gSystem->Load("libXMLParser");
gSystem->Load("libProof");
gSystem->Load("libMinuit");
gSystem->Load("libSTEERBase");
gSystem->Load("libCDB");
gSystem->Load("libRAWDatabase");
gSystem->Load("libRAWDatarec");
gSystem->Load("libESD");
gSystem->Load("libAOD");
// gSystem->Load("libSTEER");
gSystem->Load("libANALYSIS");
gSystem->Load("libANALYSISalice");
gSystem->Load("libTPCbase");
/* not really neeeded:
gSystem->Load("libTOFbase");
gSystem->Load("libTOFrec");
gSystem->Load("libTRDbase");
gSystem->Load("libVZERObase");
gSystem->Load("libVZEROrec");
gSystem->Load("libT0base");
gSystem->Load("libT0rec");
gSystem->Load("libTENDER");
gSystem->Load("libTENDERSupplies");
*/
// Flow libraries:
gSystem->Load("libPWGflowBase");
gSystem->Load("libPWGflowTasks");
} // end of void LoadLibraries()
//===============================================================================================
TChain *CreateESDChain(const char *aDataDir, Int_t aRuns, Int_t offset) {
// Helper macros for creating chains
// adapted from original: CreateESDChain.C,v 1.10 jgrosseo Exp
// creates chain of files in a given directory or file containing a list.
// In case of directory the structure is expected as:
// <aDataDir>/<dir0>/AliESDs.root
// <aDataDir>/<dir1>/AliESDs.root
// ...
if (!aDataDir) {
return 0;
}
Long_t id, size, flags, modtime;
if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime)) {
printf("WARNING: Sorry, but 'dataDir' set to %s I really coudn't found.\n",
aDataDir);
return 0;
}
TChain *chain = new TChain("esdTree");
TChain *chaingAlice = 0;
if (flags & 2) {
TString execDir(gSystem->pwd());
TSystemDirectory *baseDir = new TSystemDirectory(".", aDataDir);
TList *dirList = baseDir->GetListOfFiles();
Int_t nDirs = dirList->GetEntries();
gSystem->cd(execDir);
Int_t count = 0;
for (Int_t iDir = 0; iDir < nDirs; ++iDir) {
TSystemFile *presentDir = (TSystemFile *)dirList->At(iDir);
if (!presentDir || !presentDir->IsDirectory() ||
strcmp(presentDir->GetName(), ".") == 0 ||
strcmp(presentDir->GetName(), "..") == 0) {
continue;
}
if (offset > 0) {
--offset;
continue;
}
if (count++ == aRuns) {
break;
}
TString presentDirName(aDataDir);
presentDirName += "/";
presentDirName += presentDir->GetName();
chain->Add(presentDirName + "/AliESDs.root/esdTree");
cout << "Adding to TChain the ESDs from " << presentDirName << endl;
} // end of for (Int_t iDir=0; iDir<nDirs; ++iDir)
} // end of if(flags & 2)
else {
// Open the input stream:
ifstream in;
in.open(aDataDir);
Int_t count = 0;
// Read the input list of files and add them to the chain:
TString esdfile;
while (in.good()) {
in >> esdfile;
if (!esdfile.Contains("root"))
continue; // protection
if (offset > 0) {
--offset;
continue;
}
if (count++ == aRuns) {
break;
}
// add esd file
chain->Add(esdfile);
} // end of while(in.good())
in.close();
}
return chain;
} // end of TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t
// offset)
//===============================================================================================
TChain *CreateAODChain(const char *aDataDir, Int_t aRuns, Int_t offset) {
// creates chain of files in a given directory or file containing a list.
// In case of directory the structure is expected as:
// <aDataDir>/<dir0>/AliAOD.root
// <aDataDir>/<dir1>/AliAOD.root
// ...
if (!aDataDir)
return 0;
Long_t id, size, flags, modtime;
if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime)) {
printf("%s not found.\n", aDataDir);
return 0;
}
TChain *chain = new TChain("aodTree");
TChain *chaingAlice = 0;
if (flags & 2) {
TString execDir(gSystem->pwd());
TSystemDirectory *baseDir = new TSystemDirectory(".", aDataDir);
TList *dirList = baseDir->GetListOfFiles();
Int_t nDirs = dirList->GetEntries();
gSystem->cd(execDir);
Int_t count = 0;
for (Int_t iDir = 0; iDir < nDirs; ++iDir) {
TSystemFile *presentDir = (TSystemFile *)dirList->At(iDir);
if (!presentDir || !presentDir->IsDirectory() ||
strcmp(presentDir->GetName(), ".") == 0 ||
strcmp(presentDir->GetName(), "..") == 0)
continue;
if (offset > 0) {
--offset;
continue;
}
if (count++ == aRuns)
break;
TString presentDirName(aDataDir);
presentDirName += "/";
presentDirName += presentDir->GetName();
chain->Add(presentDirName + "/AliAOD.root/aodTree");
// cerr<<presentDirName<<endl;
}
} else {
// Open the input stream
ifstream in;
in.open(aDataDir);
Int_t count = 0;
// Read the input list of files and add them to the chain
TString aodfile;
while (in.good()) {
in >> aodfile;
if (!aodfile.Contains("root"))
continue; // protection
if (offset > 0) {
--offset;
continue;
}
if (count++ == aRuns)
break;
// add aod file
chain->Add(aodfile);
}
in.close();
}
return chain;
} // end of TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t
// offset)