]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGCF/EBYE/macros/runTaskFluctuations.C
end-of-line normalization
[u/mrichter/AliRoot.git] / PWGCF / EBYE / macros / runTaskFluctuations.C
CommitLineData
3eacba55 1enum anaModes {mLocal,mLocalPAR,mPROOF,mGrid,mGridPAR};
2//mLocal: Analyze locally files in your computer using aliroot
3//mLocalPAR: Analyze locally files in your computer using root + PAR files
4//mPROOF: Analyze CAF files with PROOF
5//mGrid: Analyze files on Grid via AliEn plug-in and using precompiled FLOW libraries
6//mGridPAR: Analyze files on Grid via AliEn plug-in and using par files for FLOW package
7
8
9const TString analysisType = "ESD"; //"MC", "ESD", "AOD"
10const TString analysisMode = "TPC"; //"TPC", "Global"
11
12//void runTaskFluctuations(Int_t mode = mPROOF, Int_t nRuns = 600000,
13//Bool_t DATA = kTRUE, const Char_t* dataDir="/alice/data/LHC10h_000137161_p1_4plus#esdTree", Int_t offset=0) {
d9649a65 14void runTaskFluctuations(Int_t mode = mLocal, Bool_t DATA = kTRUE) {
3eacba55 15//void runTaskFluctuations(Int_t mode = mGrid, Bool_t DATA = kTRUE) {
16 // Time:
17 TStopwatch timer;
18 timer.Start();
19
20 // Load needed libraries:
21 LoadLibraries(mode);
22
23 // Create and configure the AliEn plug-in:
24 if(mode == mGrid || mode == mGridPAR) {
25 gROOT->LoadMacro("CreateAlienHandler.C");
26 AliAnalysisGrid *alienHandler = CreateAlienHandler();
27 if (!alienHandler) return;
d9649a65 28 gROOT->LoadMacro("AliEbyEFluctuationAnalysisTask.cxx++");
3eacba55 29 }
30 // Chains:
31 if(mode==mLocal || mode == mLocalPAR) {
d9649a65 32 gROOT->LoadMacro("AliEbyEFluctuationAnalysisTask.cxx++");
33 if (analysisType=="ESD") {
3eacba55 34 TChain* chain = new TChain("esdTree");
d9649a65 35 chain->Add("/data/alice2/pchrist/HeavyIons/Data/Pass1_4Plus/Set1/AliESDs.root");
36 chain->Add("/data/alice2/pchrist/HeavyIons/Data/Pass1_4Plus/Set2/AliESDs.root");
37 chain->Add("/data/alice2/pchrist/HeavyIons/Data/Pass1_4Plus/Set3/AliESDs.root");
38 chain->Add("/data/alice2/pchrist/HeavyIons/Data/Pass1_4Plus/Set4/AliESDs.root");
39 chain->Add("/data/alice2/pchrist/HeavyIons/Data/Pass1_4Plus/Set5/AliESDs.root");
40 chain->Add("/data/alice2/pchrist/HeavyIons/Data/Pass1_4Plus/Set6/AliESDs.root");
41 chain->Add("/data/alice2/pchrist/HeavyIons/Data/Pass1_4Plus/Set7/AliESDs.root");
42 chain->Add("/data/alice2/pchrist/HeavyIons/Data/Pass1_4Plus/Set8/AliESDs.root");
43 chain->Add("/data/alice2/pchrist/HeavyIons/Data/Pass1_4Plus/Set9/AliESDs.root");
44 chain->Add("/data/alice2/pchrist/HeavyIons/Data/Pass1_4Plus/Set10/AliESDs.root");
3eacba55 45 }
d9649a65 46 else if(analysisType == "MC") {
47 TChain *chain = new TChain("TE");
48 chain->AddFile("galice.root");
49 }
50 else
3eacba55 51 TChain* chain = CreateAODChain(dataDir, nRuns, offset);
52 }
53 //Proof
54 if(mode == mPROOF) {
55 gROOT->ProcessLine(Form(".include %s/include", gSystem->ExpandPathName("$ALICE_ROOT")));
d9649a65 56 gProof->Load("AliEbyEFluctuationAnalysisTask.cxx++");
3eacba55 57 }
58
59 // Create analysis manager:
60 AliAnalysisManager *mgr = new AliAnalysisManager("FluctuationsAnalysisManager");
61 // Connect plug-in to the analysis manager:
62 if(mode == mGrid || mode == mGridPAR) {
63 mgr->SetGridHandler(alienHandler);
64 }
65 // Event handlers:
66 if(analysisType == "ESD") {
67 AliVEventHandler* esdH = new AliESDInputHandler;
68 mgr->SetInputEventHandler(esdH);
69 } // end of if(analysisType == "ESD")
70 if(analysisType == "AOD") {
71 AliVEventHandler* aodH = new AliAODInputHandler;
72 mgr->SetInputEventHandler(aodH);
73 } // end of if(analysisType == "AOD")
74 if(analysisType == "MC") {
75 AliVEventHandler* esdH = new AliESDInputHandler;
d9649a65 76 mgr->SetInputEventHandler(esdH);
3eacba55 77 AliMCEventHandler *mc = new AliMCEventHandler();
d9649a65 78 mc->SetReadTR(kFALSE);
3eacba55 79 mgr->SetMCtruthEventHandler(mc);
80 } // end of if(analysisType == "MC")
d9649a65 81
82 // Task to check the offline trigger:
83 //if(mode == mLocal || mode == mGrid || mode == mGridPAR)
84 if(analysisType != "MC") {
85 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
86 AliPhysicsSelectionTask* physicsSelTask = AddTaskPhysicsSelection(!DATA);
87 if(!DATA){physicsSelTask->GetPhysicsSelection()->SetAnalyzeMC();}
88 // Enable debug printouts:
89 mgr->SetDebugLevel(2);
90
91 //Add the centrality determination task
92 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
93 AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
94 //taskCentrality->SelectCollisionCandidates(AliVEvent::kMB);
95 }
96
3eacba55 97 // Load the analysis task:
98 gROOT->LoadMacro("AddTaskFluctuations.C");
99 AliEbyEFluctuationAnalysisTask* taskFA = AddTaskFluctuations(analysisType.Data(),
100 analysisMode.Data());
3eacba55 101
102 // Run the analysis:
103 if(!mgr->InitAnalysis()){return;}
104 mgr->PrintStatus();
105 if(mode == mLocal || mode == mLocalPAR)
d9649a65 106 mgr->StartAnalysis("local",chain);
3eacba55 107 else if(mode == mPROOF)
108 mgr->StartAnalysis("proof",dataDir,nRuns,offset);
109 else if(mode == mGrid || mode == mGridPAR)
d9649a65 110 mgr->StartAnalysis("grid");
3eacba55 111
112 // Print real and CPU time used for analysis:
113 timer.Stop();
114 timer.Print();
115
116} // end of void runTaskFluctuations(...)
117
118//=============================================================//
119void LoadLibraries(const anaModes mode) {
120 //--------------------------------------
121 // Load the needed libraries most of them already loaded by aliroot
122 //--------------------------------------
123 gSystem->Load("libTree");
124 gSystem->Load("libGeom");
125 gSystem->Load("libVMC");
126 gSystem->Load("libXMLIO");
127 gSystem->Load("libPhysics");
128
129 //----------------------------------------------------------
130 // >>>>>>>>>>> Local mode <<<<<<<<<<<<<<
131 //----------------------------------------------------------
132 if (mode==mLocal || mode==mGrid || mode == mGridPAR) {
133 //--------------------------------------------------------
134 // If you want to use already compiled libraries
135 // in the aliroot distribution
136 //--------------------------------------------------------
137 gSystem->Load("libSTEERBase");
138 gSystem->Load("libESD");
139 gSystem->Load("libAOD");
140 gSystem->Load("libANALYSIS");
141 gSystem->Load("libANALYSISalice");
d9649a65 142 // Use AliRoot includes to compile our task
143 gROOT->ProcessLine(".include $ALICE_ROOT/include");
1f7eb4d0 144 if(mode==mLocal || mode==mGrid){
145 gSystem->Load("libEventMixing.so");
a022cbd0 146 gSystem->Load("libPWGCFebye");
1f7eb4d0 147 }
148 if(mode==mGridPAR){
149 SetupPar("EventMixing");
a022cbd0 150 SetupPar("PWGCFebye");
1f7eb4d0 151 }
3eacba55 152 }
153
154 else if (mode == mLocalPAR) {
155 //--------------------------------------------------------
156 //If you want to use root and par files from aliroot
157 //--------------------------------------------------------
d9649a65 158 SetupPar("STEERBase");
159 SetupPar("ESD");
160 SetupPar("AOD");
161 SetupPar("ANALYSIS");
162 SetupPar("ANALYSISalice");
a022cbd0 163 SetupPar("PWGCFebye");
3eacba55 164}
165
166 //---------------------------------------------------------
167 // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
168 //---------------------------------------------------------
169 else if (mode==mPROOF) {
170 // Connect to proof
171 printf("*** Connect to PROOF ***\n");
172 gEnv->SetValue("XSec.GSI.DelegProxy","2");
173 // Put appropriate username here
174 TProof::Open("alice-caf.cern.ch");
175 //TProof::Open("skaf.saske.sk");
176 //TProof::Open("prf000-iep-grid.saske.sk");
177
178 gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-12-AN");
d9649a65 179
3eacba55 180 // Clear the Packages
181 //gProof->ClearPackage("STEERBase.par");
182 //gProof->ClearPackage("ESD.par");
183 //gProof->ClearPackage("AOD.par");
184 //gProof->ClearPackage("ANALYSIS.par");
185 //gProof->ClearPackage("ANALYSISalice.par");
a022cbd0 186 //gProof->ClearPackage("PWGCFebye");
3eacba55 187
188 // Upload the Packages
189 //gProof->UploadPackage("STEERBase.par");
190 //gProof->UploadPackage("ESD.par");
191 //gProof->UploadPackage("AOD.par");
192 //gProof->UploadPackage("ANALYSIS.par");
193 //gProof->UploadPackage("ANALYSISalice.par");
194 //gProof->UploadPackage("CORRFW.par");
a022cbd0 195 //gProof->UploadPackage("PWGCFebye");
3eacba55 196
197 // Enable the Packages
198 //gProof->EnablePackage("STEERBase");
199 //gProof->EnablePackage("ESD");
200 //gProof->EnablePackage("AOD");
201 //gProof->EnablePackage("ANALYSIS");
202 //gProof->EnablePackage("ANALYSISalice");
a022cbd0 203 //gProof->EnablePackage("PWGCFebye");
3eacba55 204
205 // Show enables Packages
206 //gProof->ShowEnabledPackages();
207 }
208
209} // end of void LoadLibraries(const anaModes mode)
210
211//===============================================================================================
212
213void SetupPar(char* pararchivename) {
214 //Load par files, create analysis libraries
215 //For testing, if par file already decompressed and modified
216 //classes then do not decompress.
217
218 TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
219 TString parpar(Form("%s.par", pararchivename)) ;
220 if ( gSystem->AccessPathName(parpar.Data()) ) {
221 gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
222 TString processline(Form(".! make %s", parpar.Data())) ;
223 gROOT->ProcessLine(processline.Data()) ;
224 gSystem->ChangeDirectory(cdir) ;
225 processline = Form(".! mv /tmp/%s .", parpar.Data()) ;
226 gROOT->ProcessLine(processline.Data()) ;
227 }
228 if ( gSystem->AccessPathName(pararchivename) ) {
229 TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
230 gROOT->ProcessLine(processline.Data());
231 }
232
233 TString ocwd = gSystem->WorkingDirectory();
234 gSystem->ChangeDirectory(pararchivename);
235
236 // check for BUILD.sh and execute
237 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
238 printf("*******************************\n");
239 printf("*** Building PAR archive ***\n");
240 cout<<pararchivename<<endl;
241 printf("*******************************\n");
242 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
243 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
244 return -1;
245 }
246 }
247 // check for SETUP.C and execute
248 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
249 printf("*******************************\n");
250 printf("*** Setup PAR archive ***\n");
251 cout<<pararchivename<<endl;
252 printf("*******************************\n");
253 gROOT->Macro("PROOF-INF/SETUP.C");
254 }
255
256 gSystem->ChangeDirectory(ocwd.Data());
257 printf("Current dir: %s\n", ocwd.Data());
258
259} // end of void SetupPar(char* pararchivename)
260
261//===============================================================================================
262
263// Helper macros for creating chains
264// from: CreateESDChain.C,v 1.10 jgrosseo Exp
265
266TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
267{
268 // creates chain of files in a given directory or file containing a list.
269 // In case of directory the structure is expected as:
270 // <aDataDir>/<dir0>/AliESDs.root
271 // <aDataDir>/<dir1>/AliESDs.root
272 // ...
273
274 if (!aDataDir)
275 return 0;
276
277 Long_t id, size, flags, modtime;
278 if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
279 {
280 printf("%s not found.\n", aDataDir);
281 return 0;
282 }
283
284 TChain* chain = new TChain("esdTree");
285 TChain* chaingAlice = 0;
286
287 if (flags & 2)
288 {
289 TString execDir(gSystem->pwd());
290 TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
291 TList* dirList = baseDir->GetListOfFiles();
292 Int_t nDirs = dirList->GetEntries();
293 gSystem->cd(execDir);
294
295 Int_t count = 0;
296
297 for (Int_t iDir=0; iDir<nDirs; ++iDir)
298 {
299 TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
300 if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
301 continue;
302
303 if (offset > 0)
304 {
305 --offset;
306 continue;
307 }
308
309 if (count++ == aRuns)
310 break;
311
312 TString presentDirName(aDataDir);
313 presentDirName += "/";
314 presentDirName += presentDir->GetName();
315 chain->Add(presentDirName + "/AliESDs.root/esdTree");
316 // cerr<<presentDirName<<endl;
317 }
318
319 }
320 else
321 {
322 // Open the input stream
323 ifstream in;
324 in.open(aDataDir);
325
326 Int_t count = 0;
327
328 // Read the input list of files and add them to the chain
329 TString esdfile;
330 while(in.good()) {
331 in >> esdfile;
332 if (!esdfile.Contains("root")) continue; // protection
333
334 if (offset > 0)
335 {
336 --offset;
337 continue;
338 }
339
340 if (count++ == aRuns)
341 break;
342
343 // add esd file
344 chain->Add(esdfile);
345 }
346
347 in.close();
348 }
349
350 return chain;
351
352} // end of TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
353
354//===============================================================================================
355
356TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
357{
358 // creates chain of files in a given directory or file containing a list.
359 // In case of directory the structure is expected as:
360 // <aDataDir>/<dir0>/AliAOD.root
361 // <aDataDir>/<dir1>/AliAOD.root
362 // ...
363
364 if (!aDataDir)
365 return 0;
366
367 Long_t id, size, flags, modtime;
368 if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
369 {
370 printf("%s not found.\n", aDataDir);
371 return 0;
372 }
373
374 TChain* chain = new TChain("aodTree");
375 TChain* chaingAlice = 0;
376
377 if (flags & 2)
378 {
379 TString execDir(gSystem->pwd());
380 TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
381 TList* dirList = baseDir->GetListOfFiles();
382 Int_t nDirs = dirList->GetEntries();
383 gSystem->cd(execDir);
384
385 Int_t count = 0;
386
387 for (Int_t iDir=0; iDir<nDirs; ++iDir)
388 {
389 TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
390 if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
391 continue;
392
393 if (offset > 0)
394 {
395 --offset;
396 continue;
397 }
398
399 if (count++ == aRuns)
400 break;
401
402 TString presentDirName(aDataDir);
403 presentDirName += "/";
404 presentDirName += presentDir->GetName();
405 chain->Add(presentDirName + "/AliAOD.root/aodTree");
406 // cerr<<presentDirName<<endl;
407 }
408
409 }
410 else
411 {
412 // Open the input stream
413 ifstream in;
414 in.open(aDataDir);
415
416 Int_t count = 0;
417
418 // Read the input list of files and add them to the chain
419 TString aodfile;
420 while(in.good()) {
421 in >> aodfile;
422 if (!aodfile.Contains("root")) continue; // protection
423
424 if (offset > 0)
425 {
426 --offset;
427 continue;
428 }
429
430 if (count++ == aRuns)
431 break;
432
433 // add aod file
434 chain->Add(aodfile);
435 }
436
437 in.close();
438 }
439
440 return chain;
441
442} // end of TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
443