patch for V0
[u/mrichter/AliRoot.git] / PWG4 / macros / ana.C
CommitLineData
d92b41ad 1/* $Id: $ */
d92b41ad 2//--------------------------------------------------
3// Example macro to do analysis with the
4// analysis classes in PWG4PartCorr
5// Can be executed with Root and AliRoot
6//
7// Pay attention to the options and definitions
8// set in the lines below
9//
10// Author : Gustavo Conesa Balbastre (INFN-LNF)
11//
12//-------------------------------------------------
2244659d 13enum anaModes {mLocal=0, mGRID=3};
14//mLocal = 0: Analyze locally files in your computer
15//mGRID = 3: Analyze files on GRID
d92b41ad 16
17//---------------------------------------------------------------------------
18//Settings to read locally several files, only for "mLocal" mode
19//The different values are default, they can be set with environmental
c8fe2783 20//variables: INDIR, PATTERN, NFILES, respectivelly
54769bc0 21
22char * kInDir = "/user/data/files/";
3e0577a2 23char * kPattern = ""; // Data are in files kInDir/kPattern+i
193828fd 24Int_t kFile = 1; // Number of files for local analysis
d92b41ad 25//---------------------------------------------------------------------------
26//Collection file for grid analysis
27char * kXML = "collection.xml";
28//---------------------------------------------------------------------------
29//Scale histograms from file. Change to kTRUE when xsection file exists
30//Put name of file containing xsection
31//Put number of events per ESD file
32//This is an specific case for normalization of Pythia files.
33const Bool_t kGetXSectionFromFileAndScale = kFALSE ;
34const char * kXSFileName = "pyxsec.root";
54769bc0 35
d92b41ad 36//---------------------------------------------------------------------------
37
193828fd 38//Set some default values, but used values are set in the code!
39
40Bool_t kMC = kFALSE; //With real data kMC = kFALSE
41TString kInputData = "ESD"; //ESD, AOD, MC, deltaAOD
42Int_t kYear = 2011;
43TString kCollision = "pp";
44Bool_t outAOD = kTRUE; //Some tasks doesnt need it.
2244659d 45TString kTreeName;
193828fd 46TString kPass = "";
47char kTrigger[1024];
48Int_t kRun = 0;
7175a03a 49
193828fd 50void ana(Int_t mode=mGRID)
d92b41ad 51{
52 // Main
cd54ca47 53
d92b41ad 54 //--------------------------------------------------------------------
55 // Load analysis libraries
56 // Look at the method below,
57 // change whatever you need for your analysis case
58 // ------------------------------------------------------------------
193828fd 59
2244659d 60 LoadLibraries() ;
193828fd 61 //gSystem->ListLibraries();
2244659d 62
d92b41ad 63 //-------------------------------------------------------------------------------------------------
64 //Create chain from ESD and from cross sections files, look below for options.
c8fe2783 65 //-------------------------------------------------------------------------------------------------
54769bc0 66
193828fd 67 // Set kInputData and kTreeName looking to the kINDIR
cd54ca47 68
193828fd 69 CheckInputData(mode);
cd54ca47 70
193828fd 71 // Check global analysis settings
cd54ca47 72
193828fd 73 CheckEnvironmentVariables();
74
75 printf("*********************************************\n");
76 printf("*** Input data < %s >, pass %s, tree < %s >, MC? < %d > ***\n",kInputData.Data(),kPass.Data(),kTreeName.Data(),kMC);
77 printf("*********************************************\n");
2244659d 78
193828fd 79 TChain * chain = new TChain(kTreeName) ;
d92b41ad 80 TChain * chainxs = new TChain("Xsection") ;
193828fd 81 CreateChain(mode, chain, chainxs);
54769bc0 82
193828fd 83 printf("*********************************************\n");
84 printf("number of entries # %lld, skipped %d\n", chain->GetEntries()) ;
85 printf("*********************************************\n");
86
87 if(!chain){
88 printf("STOP, no chain available\n");
89 return;
90 }
91
92 AliLog::SetGlobalLogLevel(AliLog::kError);//Minimum prints on screen
cd54ca47 93
193828fd 94 //--------------------------------------
95 // Make the analysis manager
96 //-------------------------------------
97 AliAnalysisManager *mgr = new AliAnalysisManager("Manager", "Manager");
98 //AliAnalysisManager::SetUseProgressBar(kTRUE);
99 //mgr->SetSkipTerminate(kTRUE);
100 //mgr->SetNSysInfo(1);
101
102 // MC handler
103 if((kMC || kInputData == "MC") && !kInputData.Contains("AOD")){
104 AliMCEventHandler* mcHandler = new AliMCEventHandler();
105 mcHandler->SetReadTR(kFALSE);//Do not search TrackRef file
106 mgr->SetMCtruthEventHandler(mcHandler);
107 if( kInputData == "MC") {
108 cout<<"MC INPUT EVENT HANDLER"<<endl;
109 mgr->SetInputEventHandler(NULL);
d92b41ad 110 }
193828fd 111 }
112
113 // AOD output handler
114 if(kInputData!="deltaAOD" && outAOD){
115 cout<<"Init output handler"<<endl;
116 AliAODHandler* aodoutHandler = new AliAODHandler();
117 aodoutHandler->SetOutputFileName("aod.root");
118 ////aodoutHandler->SetCreateNonStandardAOD();
119 mgr->SetOutputEventHandler(aodoutHandler);
120 }
121
122 //input
123
124 if(kInputData == "ESD"){
125 // ESD handler
126 AliESDInputHandler *esdHandler = new AliESDInputHandler();
127 esdHandler->SetReadFriends(kFALSE);
128 mgr->SetInputEventHandler(esdHandler);
129 cout<<"ESD handler "<<mgr->GetInputEventHandler()<<endl;
130 }
131 else if(kInputData.Contains("AOD")){
132 // AOD handler
133 AliAODInputHandler *aodHandler = new AliAODInputHandler();
134 mgr->SetInputEventHandler(aodHandler);
135 if(kInputData == "deltaAOD") aodHandler->AddFriend("deltaAODPartCorr.root");
136 cout<<"AOD handler "<<mgr->GetInputEventHandler()<<endl;
137 }
138 //mgr->RegisterExternalFile("deltaAODPartCorr.root");
139 //mgr->SetDebugLevel(1); // For debugging, do not uncomment if you want no messages.
140
141 TString outputFile = AliAnalysisManager::GetCommonFileName();
142
143 //-------------------------------------------------------------------------
144 //Define task, put here any other task that you want to use.
145 //-------------------------------------------------------------------------
146
147 // Physics selection
148 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
149 AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(kMC);
150
151 // Centrality
2c18833a 152 if(kCollision=="PbPb"){
153 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
154 AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
155 taskCentrality->SetPass(2); // remember to set the pass you are processing!!!
156 }
193828fd 157
158 // Simple event counting tasks
159 AddTaskCounter(""); // All
160 AddTaskCounter("MB"); // Min Bias
161 if(!kMC){
162 AddTaskCounter("INT7"); // Min Bias
163 AddTaskCounter("EMC1"); // Trig Th > 1.5 GeV approx
164 AddTaskCounter("EMC7"); // Trig Th > 4-5 GeV
cd54ca47 165 AddTaskCounter("PHOS"); //
193828fd 166 }
167
193828fd 168 gROOT->LoadMacro("AddTaskPartCorr.C"); // $ALICE_ROOT/PWG4/macros
cd54ca47 169
193828fd 170 Bool_t kPrint = kFALSE;
171 Bool_t deltaAOD = kFALSE;
cd54ca47 172
173 // ------
174 // Tracks
175 // ------
193828fd 176
cd54ca47 177 // QA analysis to compare after clusterization and track isolation-correlation analysis
178 AliAnalysisTaskParticleCorrelation *ana = AddTaskPartCorr(kInputData, "EMCAL", kPrint,kMC, deltaAOD, outputFile.Data(),
179 kYear,kRun,kCollision,"EMC7","");
193828fd 180
181 // -----
182 // EMCAL
cd54ca47 183 // -----
193828fd 184
185 gROOT->LoadMacro("AddTaskEMCALClusterize.C"); // $ALICE_ROOT/PWG4/CaloCalib/macros
186 Bool_t bTrackMatch = kTRUE;
cd54ca47 187 Int_t minEcell = 50; // 50 MeV (10 MeV used in reconstruction)
188 Int_t minEseed = 100; // 100 MeV
2c18833a 189 Int_t dTime = 40; // 40 ns difference in time of cells in cluster
190 Int_t wTime = 10000; // open time window of cells in cluster, open
cd54ca47 191 TString clTrigger = ""; // Do not select, do Min Bias and triggered
193828fd 192
cd54ca47 193 //Analysis with clusterizer V1
193828fd 194 AliAnalysisTaskEMCALClusterize * clv1 = AddTaskEMCALClusterize(kMC,"V1",clTrigger,kRun,kPass, bTrackMatch,
195 minEcell,minEseed,dTime,wTime);
196
197 TString arrayNameV1(Form("V1_Ecell%d_Eseed%d_DT%d_WT%d",minEcell,minEseed, dTime,wTime));
198 printf("Name of clusterizer array: %s\n",arrayNameV1.Data());
199
200 if(!kMC)
201 {
cd54ca47 202
203 AliAnalysisTaskParticleCorrelation *anav1tr = AddTaskPartCorr(kInputData, "EMCAL", kPrint,kMC, deltaAOD, outputFile.Data(),
193828fd 204 kYear,kRun,kCollision,"EMC7",arrayNameV1);
54769bc0 205
cd54ca47 206 AliAnalysisTaskParticleCorrelation *anav1mb = AddTaskPartCorr(kInputData, "EMCAL", kPrint,kMC, deltaAOD, outputFile.Data(),
193828fd 207 kYear,kRun,kCollision,"INT7",arrayNameV1);
208 }
209 else
210 {// No trigger (should be MB, but for single particle productions it does not work)
cd54ca47 211
193828fd 212 AliAnalysisTaskParticleCorrelation *anav1 = AddTaskPartCorr(kInputData, "EMCAL", kPrint,kMC, deltaAOD, outputFile.Data(),
213 kYear,kRun,kCollision,"",arrayNameV1);
214 }
215
cd54ca47 216
217 //Analysis with clusterizer V2
218 AliAnalysisTaskEMCALClusterize * clv2 = AddTaskEMCALClusterize(kMC,"V2",clTrigger,kRun,kPass, bTrackMatch,
219 minEcell,minEseed,dTime,wTime);
220
221 TString arrayNameV2(Form("V2_Ecell%d_Eseed%d_DT%d_WT%d",minEcell,minEseed, dTime,wTime));
222 printf("Name of clusterizer array: %s\n",arrayNameV2.Data());
223
193828fd 224 if(!kMC)
225 {
cd54ca47 226
227 AliAnalysisTaskParticleCorrelation *anav2tr = AddTaskPartCorr(kInputData, "EMCAL", kPrint,kMC, deltaAOD, outputFile.Data(),
228 kYear,kRun,kCollision,"EMC7",arrayNameV2);
54769bc0 229
cd54ca47 230 AliAnalysisTaskParticleCorrelation *anav2mb = AddTaskPartCorr(kInputData, "EMCAL", kPrint,kMC, deltaAOD, outputFile.Data(),
231 kYear,kRun,kCollision,"INT7",arrayNameV2);
193828fd 232 }
233 else
cd54ca47 234 {// No trigger (should be MB, but for single particle productions it does not work)
235 AliAnalysisTaskParticleCorrelation *anav2 = AddTaskPartCorr(kInputData, "EMCAL", kPrint,kMC, deltaAOD, outputFile.Data(),
236 kYear,kRun,kCollision,"",arrayNameV2);
d92b41ad 237 }
cd54ca47 238
239 // -----
240 // PHOS
241 // -----
242 /*
243 //Add here PHOS tender or whatever is needed
244
245 if(!kMC)
246 {
247
248 AliAnalysisTaskParticleCorrelation *anav1tr = AddTaskPartCorr(kInputData, "PHOS", kPrint,kMC, deltaAOD, outputFile.Data(),
249 kYear,kRun,kCollision,"PHOS",""); // Change to PHOS trigger
250
251
252 AliAnalysisTaskParticleCorrelation *anav1mb = AddTaskPartCorr(kInputData, "PHOS", kPrint,kMC, deltaAOD, outputFile.Data(),
253 kYear,kRun,kCollision,"INT7","");
254
255 }
256 else
257 {// No trigger
258
259 AliAnalysisTaskParticleCorrelation *anav1mb = AddTaskPartCorr(kInputData, "PHOS", kPrint,kMC, deltaAOD, outputFile.Data(),
260 kYear,kRun,kCollision,"","");
261
262 }
263 */
193828fd 264
265
266 //-----------------------
267 // Run the analysis
268 //-----------------------
269 mgr->InitAnalysis();
270 mgr->PrintStatus();
271 mgr->StartAnalysis("local",chain);
272
273 cout <<" Analysis ended sucessfully "<< endl ;
274
d92b41ad 275
276}
277
193828fd 278//___________________
279void LoadLibraries()
280{
d92b41ad 281
282 //--------------------------------------
283 // Load the needed libraries most of them already loaded by aliroot
284 //--------------------------------------
285 gSystem->Load("libTree.so");
286 gSystem->Load("libGeom.so");
287 gSystem->Load("libVMC.so");
288 gSystem->Load("libXMLIO.so");
54769bc0 289 gSystem->Load("libMatrix.so");
290 gSystem->Load("libPhysics.so");
193828fd 291 gSystem->Load("libMinuit.so"); // Root + libraries to if reclusterization is done
292
293 gSystem->Load("libSTEERBase.so");
294 gSystem->Load("libGui.so"); // Root + libraries to if reclusterization is done
295 gSystem->Load("libCDB.so"); // Root + libraries to if reclusterization is done
296 gSystem->Load("libESD.so"); // Root + libraries to if reclusterization is done
297 gSystem->Load("libAOD.so");
298 gSystem->Load("libRAWDatabase.so"); // Root + libraries to if reclusterization is done
299 gSystem->Load("libProof.so");
300 gSystem->Load("libANALYSIS.so");
301 gSystem->Load("libSTEER.so"); // Root + libraries to if reclusterization is done
302
303 gSystem->Load("libRAWDatarec.so"); // Root + libraries to if reclusterization is done
304 gSystem->Load("libRAWDatasim.so"); // Root + libraries to if reclusterization is done
305 gSystem->Load("libVZERObase.so"); // Root + libraries to if reclusterization is done
306 gSystem->Load("libVZEROrec.so"); // Root + libraries to if reclusterization is done
307
308 gSystem->Load("libEMCALUtils");
309 //SetupPar("EMCALUtils");
310 gSystem->Load("libEMCALraw"); // Root + libraries to if reclusterization is done
311 gSystem->Load("libEMCALbase"); // Root + libraries to if reclusterization is done
312 gSystem->Load("libEMCALsim"); // Root + libraries to if reclusterization is done
313 gSystem->Load("libEMCALrec"); // Root + libraries to if reclusterization is done
314 //SetupPar("EMCALraw");
315 //SetupPar("EMCALbase");
316 //SetupPar("EMCALsim");
317 //SetupPar("EMCALrec");
318
319 gSystem->Load("libANALYSISalice.so");
320 //gSystem->Load("libTENDER.so");
321 //gSystem->Load("libTENDERSupplies.so");
322
323 gSystem->Load("libPHOSUtils");
324 gSystem->Load("libEMCALUtils");
325 gSystem->Load("libPWG4PartCorrBase");
326 gSystem->Load("libPWG4PartCorrDep");
327 gSystem->Load("libPWG4CaloCalib");
328 //SetupPar("PWG4PartCorrBase");
329 //SetupPar("PWG4PartCorrDep");
330 //SetupPar("PWG4CaloCalib");
d92b41ad 331}
332
333void SetupPar(char* pararchivename)
334{
335 //Load par files, create analysis libraries
336 //For testing, if par file already decompressed and modified
337 //classes then do not decompress.
193828fd 338
d92b41ad 339 TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
340 TString parpar(Form("%s.par", pararchivename)) ;
193828fd 341
d92b41ad 342 if ( gSystem->AccessPathName(pararchivename) ) {
343 TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
344 gROOT->ProcessLine(processline.Data());
345 }
346
347 TString ocwd = gSystem->WorkingDirectory();
348 gSystem->ChangeDirectory(pararchivename);
349
350 // check for BUILD.sh and execute
351 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
352 printf("*******************************\n");
353 printf("*** Building PAR archive ***\n");
354 cout<<pararchivename<<endl;
355 printf("*******************************\n");
356
357 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
358 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
359 return -1;
360 }
361 }
362 // check for SETUP.C and execute
363 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
364 printf("*******************************\n");
365 printf("*** Setup PAR archive ***\n");
366 cout<<pararchivename<<endl;
367 printf("*******************************\n");
368 gROOT->Macro("PROOF-INF/SETUP.C");
369 }
370
371 gSystem->ChangeDirectory(ocwd.Data());
372 printf("Current dir: %s\n", ocwd.Data());
373}
374
193828fd 375void CheckInputData(const anaModes mode){
376 //Sets input data and tree
377
378 TString ocwd = gSystem->WorkingDirectory();
379
380 //---------------------------------------
381 //Local files analysis
382 //---------------------------------------
383 if(mode == mLocal){
384 //If you want to add several ESD files sitting in a common directory INDIR
385 //Specify as environmental variables the directory (INDIR), the number of files
386 //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
cd54ca47 387
193828fd 388 if(gSystem->Getenv("INDIR"))
389 kInDir = gSystem->Getenv("INDIR") ;
390 else cout<<"INDIR not set, use default: "<<kInDir<<endl;
391
392 TString sindir(kInDir);
393 if (sindir.Contains("pass1")) kPass = "pass1";
394 else if(sindir.Contains("pass2")) kPass = "pass2";
395 else if(sindir.Contains("pass3")) kPass = "pass3";
396
397 if(gSystem->Getenv("PATTERN"))
398 kPattern = gSystem->Getenv("PATTERN") ;
399 else cout<<"PATTERN not set, use default: "<<kPattern<<endl;
400
401 cout<<"INDIR : "<<kInDir<<endl;
402 cout<<"NFILES : "<<kFile<<endl;
403
404 char fileE[120] ;
405 char fileA[120] ;
406 char fileG[120] ;
407 char fileEm[120] ;
408 for (Int_t event = 0 ; event < kFile ; event++) {
409 sprintf(fileE, "%s/%s%d/AliESDs.root", kInDir,kPattern,event) ;
410 sprintf(fileA, "%s/%s%d/AliAOD.root", kInDir,kPattern,event) ;
411 sprintf(fileG, "%s/%s%d/galice.root", kInDir,kPattern,event) ;
412 sprintf(fileEm, "%s/%s%d/embededAOD.root", kInDir,kPattern,event) ;
413
414 TFile * fAOD = 0 ;
415 //Check if file exists and add it, if not skip it
416 if ( TFile::Open(fileE)) {
417 kTreeName ="esdTree";
418 kInputData = "ESD";
419 if(TFile::Open(fileG)) kMC=kTRUE;
420 else kMC = kFALSE;
421 return;
422 }
423 else if(fAOD=TFile::Open(fileA)){
424 kTreeName ="aodTree";
425 kInputData = "AOD";
426 if(((TTree*) fAOD->Get("aodTree"))->GetBranch("mcparticles")) kMC=kTRUE;
427 else kMC = kFALSE;
428 return;
429 }
430 else if(fAOD=TFile::Open(fileEm)){
431 kTreeName ="aodTree";
432 kInputData = "AOD";
433 kMC=kTRUE;
434 return;
435 }
436 else if(TFile::Open(fileG)){
437 kTreeName ="TE";
438 kInputData = "MC";
439 kMC=kTRUE;
440 return;
441 }
442 }
443
444 }// local files analysis
445
446 //------------------------------
447 //GRID xml files
448 //-----------------------------
449 else if(mode == mGRID){
450 //Get colection file. It is specified by the environmental
451 //variable XML
452
453 if(gSystem->Getenv("XML") )
454 kXML = gSystem->Getenv("XML");
455 else
456 sprintf(kXML, "collection.xml") ;
457
458 if (!TFile::Open(kXML)) {
459 printf("No collection file with name -- %s -- was found\n",kXML);
460 return ;
461 }
462 else cout<<"XML file "<<kXML<<endl;
463
464 //Load necessary libraries and connect to the GRID
465 gSystem->Load("libNetx.so") ;
466 gSystem->Load("libRAliEn.so");
467 TGrid::Connect("alien://") ;
468
469 //Feed Grid with collection file
470 TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
471 if (! collection) {
472 AliError(Form("%s not found", kXML)) ;
473 return kFALSE ;
474 }
475 TGridResult* result = collection->GetGridResult("",0 ,0);
476
477 for (Int_t index = 0; index < result->GetEntries(); index++) {
478 TString alienURL = result->GetKey(index, "turl") ;
479 cout << "================== " << alienURL << endl ;
480
481 if (alienURL.Contains("pass1")) kPass = "pass1";
482 else if(alienURL.Contains("pass2")) kPass = "pass2";
483 else if(alienURL.Contains("pass3")) kPass = "pass3";
484
485 TFile * fAOD = 0 ;
486 //Check if file exists and add it, if not skip it
487 if (alienURL.Contains("AliESDs.root")) {
488 kTreeName ="esdTree";
489 kInputData = "ESD";
490 alienURL.ReplaceAll("AliESDs.root","galice.root");
491 if(TFile::Open(alienURL)) kMC=kTRUE;
492 else kMC = kFALSE;
493
494 kRun = AliAnalysisManager::GetRunFromAlienPath(alienURL.Data());
495 printf("Run number from alien path = %d\n",kRun);
496
497 return;
498 }
499 else if(alienURL.Contains("AliAOD.root")){
500 kTreeName ="aodTree";
501 kInputData = "AOD";
502 fAOD = TFile::Open(alienURL);
503 if(((TTree*) fAOD->Get("aodTree"))->GetBranch("mcparticles")) kMC=kTRUE;
504 else kMC = kFALSE;
505 return;
506 }
507 else if(alienURL.Contains("embededAOD.root")){
508 kTreeName ="aodTree";
509 kInputData = "AOD";
510 kMC=kTRUE;
511 return;
512 }
513 else if(alienURL.Contains("galice.root")){
514 kTreeName ="TE";
515 kInputData = "MC";
516 kMC=kTRUE;
517 return;
518 }
519 }
520 }// xml analysis
521
522 gSystem->ChangeDirectory(ocwd.Data());
523
524}
d92b41ad 525
193828fd 526//_____________________________________________________________________
527void CreateChain(const anaModes mode, TChain * chain, TChain * chainxs)
528{
d92b41ad 529 //Fills chain with data
530 TString ocwd = gSystem->WorkingDirectory();
531
d92b41ad 532 //---------------------------------------
533 //Local files analysis
534 //---------------------------------------
2244659d 535 if(mode == mLocal){
d92b41ad 536 //If you want to add several ESD files sitting in a common directory INDIR
537 //Specify as environmental variables the directory (INDIR), the number of files
c8fe2783 538 //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
193828fd 539
d92b41ad 540 if(gSystem->Getenv("INDIR"))
541 kInDir = gSystem->Getenv("INDIR") ;
542 else cout<<"INDIR not set, use default: "<<kInDir<<endl;
543
544 if(gSystem->Getenv("PATTERN"))
545 kPattern = gSystem->Getenv("PATTERN") ;
546 else cout<<"PATTERN not set, use default: "<<kPattern<<endl;
547
c8fe2783 548 if(gSystem->Getenv("NFILES"))
549 kFile = atoi(gSystem->Getenv("NFILES")) ;
550 else cout<<"NFILES not set, use default: "<<kFile<<endl;
d92b41ad 551
552 //Check if env variables are set and are correct
c8fe2783 553 if ( kInDir && kFile) {
554 printf("Get %d files from directory %s\n",kFile,kInDir);
d92b41ad 555 if ( ! gSystem->cd(kInDir) ) {//check if ESDs directory exist
193828fd 556 printf("%s does not exist\n", kInDir) ;
557 return ;
d92b41ad 558 }
193828fd 559
c8fe2783 560 //if(gSystem->Getenv("XSFILE"))
561 //kXSFileName = gSystem->Getenv("XSFILE") ;
562 //else cout<<" XS file name not set, use default: "<<kXSFileName<<endl;
563 char * kGener = gSystem->Getenv("GENER");
564 if(kGener) {
193828fd 565 cout<<"GENER "<<kGener<<endl;
566 if(!strcmp(kGener,"PYTHIA")) kXSFileName = "pyxsec.root";
567 else if(!strcmp(kGener,"HERWIG")) kXSFileName = "hexsec.root";
568 else cout<<" UNKNOWN GENER, use default: "<<kXSFileName<<endl;
c8fe2783 569 }
570 else cout<<" GENER not set, use default xs file name: "<<kXSFileName<<endl;
193828fd 571
c8fe2783 572 cout<<"INDIR : "<<kInDir<<endl;
573 cout<<"NFILES : "<<kFile<<endl;
574 cout<<"PATTERN : " <<kPattern<<endl;
575 cout<<"XSFILE : "<<kXSFileName<<endl;
193828fd 576
7175a03a 577 TString datafile="";
578 if(kInputData == "ESD") datafile = "AliESDs.root" ;
193828fd 579 else if(kInputData.Contains("AOD")) datafile = "AliAOD.root" ;//////////
7175a03a 580 else if(kInputData == "MC") datafile = "galice.root" ;
581
d92b41ad 582 //Loop on ESD files, add them to chain
583 Int_t event =0;
584 Int_t skipped=0 ;
585 char file[120] ;
586 char filexs[120] ;
587
c8fe2783 588 for (event = 0 ; event < kFile ; event++) {
193828fd 589 sprintf(file, "%s/%s%d/%s", kInDir,kPattern,event,datafile.Data()) ;
590 sprintf(filexs, "%s/%s%d/%s", kInDir,kPattern,event,kXSFileName) ;
591 TFile * fESD = 0 ;
592 //Check if file exists and add it, if not skip it
593 if ( fESD = TFile::Open(file)) {
594 if ( fESD->Get(kTreeName) ) {
595 printf("++++ Adding %s\n", file) ;
596 chain->AddFile(file);
597 chainxs->Add(filexs) ;
598 }
599 }
600 else {
601 printf("---- Skipping %s\n", file) ;
602 skipped++ ;
603 }
d92b41ad 604 }
d92b41ad 605 }
606 else {
607 TString input = "AliESDs.root" ;
608 cout<<">>>>>> No list added, take a single file <<<<<<<<< "<<input<<endl;
609 chain->AddFile(input);
610 }
611
612 }// local files analysis
613
614 //------------------------------
615 //GRID xml files
616 //-----------------------------
617 else if(mode == mGRID){
618 //Get colection file. It is specified by the environmental
619 //variable XML
d92b41ad 620
d92b41ad 621 //Feed Grid with collection file
d92b41ad 622 TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
623 if (! collection) {
624 AliError(Form("%s not found", kXML)) ;
625 return kFALSE ;
626 }
627 TGridResult* result = collection->GetGridResult("",0 ,0);
193828fd 628
d92b41ad 629 // Makes the ESD chain
630 printf("*** Getting the Chain ***\n");
631 for (Int_t index = 0; index < result->GetEntries(); index++) {
632 TString alienURL = result->GetKey(index, "turl") ;
633 cout << "================== " << alienURL << endl ;
634 chain->Add(alienURL) ;
635 alienURL.ReplaceAll("AliESDs.root",kXSFileName);
636 chainxs->Add(alienURL) ;
637 }
638 }// xml analysis
639
640 gSystem->ChangeDirectory(ocwd.Data());
193828fd 641
d92b41ad 642}
643
193828fd 644//_________________________________________________________________
d92b41ad 645void GetAverageXsection(TTree * tree, Double_t & xs, Float_t & ntr)
646{
647 // Read the PYTHIA statistics from the file pyxsec.root created by
648 // the function WriteXsection():
649 // integrated cross section (xsection) and
650 // the number of Pyevent() calls (ntrials)
651 // and calculate the weight per one event xsection/ntrials
652 // The spectrum calculated by a user should be
653 // multiplied by this weight, something like this:
654 // TH1F *userSpectrum ... // book and fill the spectrum
655 // userSpectrum->Scale(weight)
656 //
657 // Yuri Kharlov 19 June 2007
658 // Gustavo Conesa 15 April 2008
659 Double_t xsection = 0;
660 UInt_t ntrials = 0;
661 xs = 0;
662 ntr = 0;
663
664 Int_t nfiles = tree->GetEntries() ;
665 if (tree && nfiles > 0) {
666 tree->SetBranchAddress("xsection",&xsection);
667 tree->SetBranchAddress("ntrials",&ntrials);
668 for(Int_t i = 0; i < nfiles; i++){
669 tree->GetEntry(i);
670 xs += xsection ;
671 ntr += ntrials ;
672 cout << "xsection " <<xsection<<" ntrials "<<ntrials<<endl;
673 }
674
675 xs = xs / nfiles;
676 ntr = ntr / nfiles;
677 cout << "-----------------------------------------------------------------"<<endl;
678 cout << "Average of "<< nfiles<<" files: xsection " <<xs<<" ntrials "<<ntr<<endl;
679 cout << "-----------------------------------------------------------------"<<endl;
680 }
681 else cout << " >>>> Empty tree !!!! <<<<< "<<endl;
682
683}
684
685
193828fd 686//______________________________
687void CheckEnvironmentVariables()
688{
689
cd54ca47 690 sprintf(kTrigger,"");
193828fd 691
cd54ca47 692 Bool_t bRecalibrate = kFALSE;
693 Bool_t bBadChannel = kFALSE;
193828fd 694
cd54ca47 695 for (int i=0; i< gApplication->Argc();i++){
696
697#ifdef VERBOSEARGS
698
699 printf("Arg %d: %s\n",i,gApplication->Argv(i));
700
193828fd 701#endif
cd54ca47 702
2c18833a 703 TString sRun = "";
704
cd54ca47 705 if (!(strcmp(gApplication->Argv(i),"--trigger")))
706 sprintf(trigger,gApplication->Argv(i+1));
193828fd 707
708 if (!(strcmp(gApplication->Argv(i),"--recalibrate")))
709 bRecalibrate = atoi(gApplication->Argv(i+1));
cd54ca47 710
711 if (!(strcmp(gApplication->Argv(i),"--badchannel")))
712 bBadChannel = atoi(gApplication->Argv(i+1));
713
714 if (!(strcmp(gApplication->Argv(i),"--run"))){
2c18833a 715 sRun = gApplication->Argv(i+1);
cd54ca47 716 if(sRun.Contains("LHC10")) {
717 kYear = 2010;
718 }
719 else {
720 if(kRun <=0){
721 kRun = atoi(gApplication->Argv(i+1));
722 }
723 else printf("** Run number already set to %d, do not set to %d\n",kRun,atoi(gApplication->Argv(i+1)));
724 }//numeric run
725 }//--run available
726
727 }// args loop
728
193828fd 729 if(!sRun.Contains("LHC10")){
730 if ( kRun < 140000) {
731 kYear = 2010;
732 if( kRun >= 136851 ) kCollision = "PbPb";
733 }
734 else{
735 kYear = 2011;
736 }
737 }
738
cd54ca47 739 if(kMC) sprintf(kTrigger,"");
740
741 printf("*********************************************\n");
742 //printf("*** Settings trigger %s, recalibrate %d, remove bad channels %d, year %d, collision %s, run %d ***\n",
743 // kTrigger,bRecalibrate,bBadChannel, kYear,kCollision.Data(), kRun);
744 printf("*** Settings year %d, collision %s, run %d ***\n",kYear,kCollision.Data(), kRun);
745 printf("*********************************************\n");
746
193828fd 747}
748
749//_____________________________________________________________
750void AddTaskCounter(const TString trigger = "MB")
751{
752
753 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
754
755 AliAnalysisTaskCounter * counter = new AliAnalysisTaskCounter(Form("Counter%s",trigger.Data()));
756 if(kRun > 140000 && kRun < 146900) counter ->RejectFastCluster();
757 if (kCollision=="pp" ) counter->SetZVertexCut(50.); //Open cut
758 else if(kCollision=="PbPb") counter->SetZVertexCut(10.); //Centrality defined in this range.
759
760 if(trigger=="EMC7"){
761 printf("counter trigger EMC7\n");
762 counter->SelectCollisionCandidates(AliVEvent::kEMC7);
763 }
764 else if (trigger=="INT7"){
765 printf("counter trigger INT7\n");
766 counter->SelectCollisionCandidates(AliVEvent::kINT7);
767 }
768 if(trigger=="EMC1"){
769 printf("counter trigger EMC1\n");
770 counter->SelectCollisionCandidates(AliVEvent::kEMC1);
771 }
772 else if(trigger=="MB"){
773 printf("counter trigger MB\n");
774 counter->SelectCollisionCandidates(AliVEvent::kMB);
775 }
cd54ca47 776 else if(trigger=="PHOS"){
777 printf("counter trigger PHOS\n");
778 counter->SelectCollisionCandidates(AliVEvent::kPHI7);
779 }
193828fd 780
781 TString outputFile = AliAnalysisManager::GetCommonFileName();
782 AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
783
784 AliAnalysisDataContainer *coutput =
785 mgr->CreateContainer(Form("Counter%s",trigger.Data()), TList::Class(), AliAnalysisManager::kOutputContainer, outputFile.Data());
786 mgr->AddTask(counter);
787 mgr->ConnectInput (counter, 0, cinput1);
788 mgr->ConnectOutput (counter, 1, coutput);
cd54ca47 789
193828fd 790}
791
792
793
794
d92b41ad 795