AliAnaParticleHadronCorrelation: Remove not necessary requests for isolated AODs...
[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
193828fd 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
68
69 CheckInputData(mode);
70
71 // Check global analysis settings
72
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
54769bc0 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
152 // gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
153 // AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
154 // taskCentrality->SetPass(2); // remember to set the pass you are processing!!!
155
156 // Simple event counting tasks
157 AddTaskCounter(""); // All
158 AddTaskCounter("MB"); // Min Bias
159 if(!kMC){
160 AddTaskCounter("INT7"); // Min Bias
161 AddTaskCounter("EMC1"); // Trig Th > 1.5 GeV approx
162 AddTaskCounter("EMC7"); // Trig Th > 4-5 GeV
163 // Add PHOS trigger counter here
164 }
165
2244659d 166
193828fd 167 gROOT->LoadMacro("AddTaskPartCorr.C"); // $ALICE_ROOT/PWG4/macros
168 Bool_t kPrint = kFALSE;
169 Bool_t deltaAOD = kFALSE;
170
171 // Do not reclusterize, do analysis
172 // TString sTrigger(kTrigger)
173 // AliAnalysisTaskParticleCorrelation *ana = AddTaskPartCorr(kInputData, "EMCAL", kPrint,kMC, deltaAOD, outputFile.Data(),
174 // kYear,kRun,kCollision,sTrigger,"");
175
176 // -----
177 // EMCAL
178 // -----
179
180 gROOT->LoadMacro("AddTaskEMCALClusterize.C"); // $ALICE_ROOT/PWG4/CaloCalib/macros
181 Bool_t bTrackMatch = kTRUE;
182 Int_t minEcell = 50; // 50 MeV (10 MeV used in reconstruction)
183 Int_t minEseed = 100; // 100 MeV
184 Int_t dTime = 250; // 250 ns difference in time of cells in cluster, open
185 Int_t wTime = 1000; // 1000 ns time window of cells in cluster, open
186 TString clTrigger = ""; // Do not select, do Min Bias and triggered
187
188 //Analysis with clusterizer V1 (add following lines again with V2, NxN or V1Unfold for other kind of clusterizations in EMCAL)
189 AliAnalysisTaskEMCALClusterize * clv1 = AddTaskEMCALClusterize(kMC,"V1",clTrigger,kRun,kPass, bTrackMatch,
190 minEcell,minEseed,dTime,wTime);
191
192 TString arrayNameV1(Form("V1_Ecell%d_Eseed%d_DT%d_WT%d",minEcell,minEseed, dTime,wTime));
193 printf("Name of clusterizer array: %s\n",arrayNameV1.Data());
194
195 if(!kMC)
196 {
197 AliAnalysisTaskParticleCorrelation *anav1tr = AddTaskPartCorr(kInputData, "EMCAL", kPrint,kMC, deltaAOD, outputFile.Data(),
198 kYear,kRun,kCollision,"EMC7",arrayNameV1);
54769bc0 199
193828fd 200 AliAnalysisTaskParticleCorrelation *anav1mb = AddTaskPartCorr(kInputData, "EMCAL", kPrint,kMC, deltaAOD, outputFile.Data(),
201 kYear,kRun,kCollision,"INT7",arrayNameV1);
202 }
203 else
204 {// No trigger (should be MB, but for single particle productions it does not work)
205 AliAnalysisTaskParticleCorrelation *anav1 = AddTaskPartCorr(kInputData, "EMCAL", kPrint,kMC, deltaAOD, outputFile.Data(),
206 kYear,kRun,kCollision,"",arrayNameV1);
207 }
208
209 // -----
210 // PHOS
211 // -----
212 /*
213 //Add here PHOS tender or whatever is needed
2244659d 214
193828fd 215 if(!kMC)
216 {
217 AliAnalysisTaskParticleCorrelation *anav1tr = AddTaskPartCorr(kInputData, "PHOS", kPrint,kMC, deltaAOD, outputFile.Data(),
218 kYear,kRun,kCollision,"EMC7",""); // Change to PHOS trigger
54769bc0 219
54769bc0 220
193828fd 221 AliAnalysisTaskParticleCorrelation *anav1mb = AddTaskPartCorr(kInputData, "PHOS", kPrint,kMC, deltaAOD, outputFile.Data(),
222 kYear,kRun,kCollision,"INT7","");
223 }
224 else
225 {// No trigger
226 AliAnalysisTaskParticleCorrelation *anav1mb = AddTaskPartCorr(kInputData, "PHOS", kPrint,kMC, deltaAOD, outputFile.Data(),
227 kYear,kRun,kCollision,"","");
d92b41ad 228 }
193828fd 229 */
230
231
232 //-----------------------
233 // Run the analysis
234 //-----------------------
235 mgr->InitAnalysis();
236 mgr->PrintStatus();
237 mgr->StartAnalysis("local",chain);
238
239 cout <<" Analysis ended sucessfully "<< endl ;
240
d92b41ad 241
242}
243
193828fd 244//___________________
245void LoadLibraries()
246{
d92b41ad 247
248 //--------------------------------------
249 // Load the needed libraries most of them already loaded by aliroot
250 //--------------------------------------
251 gSystem->Load("libTree.so");
252 gSystem->Load("libGeom.so");
253 gSystem->Load("libVMC.so");
254 gSystem->Load("libXMLIO.so");
54769bc0 255 gSystem->Load("libMatrix.so");
256 gSystem->Load("libPhysics.so");
193828fd 257 gSystem->Load("libMinuit.so"); // Root + libraries to if reclusterization is done
258
259 gSystem->Load("libSTEERBase.so");
260 gSystem->Load("libGui.so"); // Root + libraries to if reclusterization is done
261 gSystem->Load("libCDB.so"); // Root + libraries to if reclusterization is done
262 gSystem->Load("libESD.so"); // Root + libraries to if reclusterization is done
263 gSystem->Load("libAOD.so");
264 gSystem->Load("libRAWDatabase.so"); // Root + libraries to if reclusterization is done
265 gSystem->Load("libProof.so");
266 gSystem->Load("libANALYSIS.so");
267 gSystem->Load("libSTEER.so"); // Root + libraries to if reclusterization is done
268
269 gSystem->Load("libRAWDatarec.so"); // Root + libraries to if reclusterization is done
270 gSystem->Load("libRAWDatasim.so"); // Root + libraries to if reclusterization is done
271 gSystem->Load("libVZERObase.so"); // Root + libraries to if reclusterization is done
272 gSystem->Load("libVZEROrec.so"); // Root + libraries to if reclusterization is done
273
274 gSystem->Load("libEMCALUtils");
275 //SetupPar("EMCALUtils");
276 gSystem->Load("libEMCALraw"); // Root + libraries to if reclusterization is done
277 gSystem->Load("libEMCALbase"); // Root + libraries to if reclusterization is done
278 gSystem->Load("libEMCALsim"); // Root + libraries to if reclusterization is done
279 gSystem->Load("libEMCALrec"); // Root + libraries to if reclusterization is done
280 //SetupPar("EMCALraw");
281 //SetupPar("EMCALbase");
282 //SetupPar("EMCALsim");
283 //SetupPar("EMCALrec");
284
285 gSystem->Load("libANALYSISalice.so");
286 //gSystem->Load("libTENDER.so");
287 //gSystem->Load("libTENDERSupplies.so");
288
289 gSystem->Load("libPHOSUtils");
290 gSystem->Load("libEMCALUtils");
291 gSystem->Load("libPWG4PartCorrBase");
292 gSystem->Load("libPWG4PartCorrDep");
293 gSystem->Load("libPWG4CaloCalib");
294 //SetupPar("PWG4PartCorrBase");
295 //SetupPar("PWG4PartCorrDep");
296 //SetupPar("PWG4CaloCalib");
d92b41ad 297}
298
299void SetupPar(char* pararchivename)
300{
301 //Load par files, create analysis libraries
302 //For testing, if par file already decompressed and modified
303 //classes then do not decompress.
193828fd 304
d92b41ad 305 TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
306 TString parpar(Form("%s.par", pararchivename)) ;
193828fd 307
d92b41ad 308 if ( gSystem->AccessPathName(pararchivename) ) {
309 TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
310 gROOT->ProcessLine(processline.Data());
311 }
312
313 TString ocwd = gSystem->WorkingDirectory();
314 gSystem->ChangeDirectory(pararchivename);
315
316 // check for BUILD.sh and execute
317 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
318 printf("*******************************\n");
319 printf("*** Building PAR archive ***\n");
320 cout<<pararchivename<<endl;
321 printf("*******************************\n");
322
323 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
324 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
325 return -1;
326 }
327 }
328 // check for SETUP.C and execute
329 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
330 printf("*******************************\n");
331 printf("*** Setup PAR archive ***\n");
332 cout<<pararchivename<<endl;
333 printf("*******************************\n");
334 gROOT->Macro("PROOF-INF/SETUP.C");
335 }
336
337 gSystem->ChangeDirectory(ocwd.Data());
338 printf("Current dir: %s\n", ocwd.Data());
339}
340
193828fd 341void CheckInputData(const anaModes mode){
342 //Sets input data and tree
343
344 TString ocwd = gSystem->WorkingDirectory();
345
346 //---------------------------------------
347 //Local files analysis
348 //---------------------------------------
349 if(mode == mLocal){
350 //If you want to add several ESD files sitting in a common directory INDIR
351 //Specify as environmental variables the directory (INDIR), the number of files
352 //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
d92b41ad 353
193828fd 354 if(gSystem->Getenv("INDIR"))
355 kInDir = gSystem->Getenv("INDIR") ;
356 else cout<<"INDIR not set, use default: "<<kInDir<<endl;
357
358 TString sindir(kInDir);
359 if (sindir.Contains("pass1")) kPass = "pass1";
360 else if(sindir.Contains("pass2")) kPass = "pass2";
361 else if(sindir.Contains("pass3")) kPass = "pass3";
362
363 if(gSystem->Getenv("PATTERN"))
364 kPattern = gSystem->Getenv("PATTERN") ;
365 else cout<<"PATTERN not set, use default: "<<kPattern<<endl;
366
367 cout<<"INDIR : "<<kInDir<<endl;
368 cout<<"NFILES : "<<kFile<<endl;
369
370 char fileE[120] ;
371 char fileA[120] ;
372 char fileG[120] ;
373 char fileEm[120] ;
374 for (Int_t event = 0 ; event < kFile ; event++) {
375 sprintf(fileE, "%s/%s%d/AliESDs.root", kInDir,kPattern,event) ;
376 sprintf(fileA, "%s/%s%d/AliAOD.root", kInDir,kPattern,event) ;
377 sprintf(fileG, "%s/%s%d/galice.root", kInDir,kPattern,event) ;
378 sprintf(fileEm, "%s/%s%d/embededAOD.root", kInDir,kPattern,event) ;
379
380 TFile * fAOD = 0 ;
381 //Check if file exists and add it, if not skip it
382 if ( TFile::Open(fileE)) {
383 kTreeName ="esdTree";
384 kInputData = "ESD";
385 if(TFile::Open(fileG)) kMC=kTRUE;
386 else kMC = kFALSE;
387 return;
388 }
389 else if(fAOD=TFile::Open(fileA)){
390 kTreeName ="aodTree";
391 kInputData = "AOD";
392 if(((TTree*) fAOD->Get("aodTree"))->GetBranch("mcparticles")) kMC=kTRUE;
393 else kMC = kFALSE;
394 return;
395 }
396 else if(fAOD=TFile::Open(fileEm)){
397 kTreeName ="aodTree";
398 kInputData = "AOD";
399 kMC=kTRUE;
400 return;
401 }
402 else if(TFile::Open(fileG)){
403 kTreeName ="TE";
404 kInputData = "MC";
405 kMC=kTRUE;
406 return;
407 }
408 }
409
410 }// local files analysis
411
412 //------------------------------
413 //GRID xml files
414 //-----------------------------
415 else if(mode == mGRID){
416 //Get colection file. It is specified by the environmental
417 //variable XML
418
419 if(gSystem->Getenv("XML") )
420 kXML = gSystem->Getenv("XML");
421 else
422 sprintf(kXML, "collection.xml") ;
423
424 if (!TFile::Open(kXML)) {
425 printf("No collection file with name -- %s -- was found\n",kXML);
426 return ;
427 }
428 else cout<<"XML file "<<kXML<<endl;
429
430 //Load necessary libraries and connect to the GRID
431 gSystem->Load("libNetx.so") ;
432 gSystem->Load("libRAliEn.so");
433 TGrid::Connect("alien://") ;
434
435 //Feed Grid with collection file
436 TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
437 if (! collection) {
438 AliError(Form("%s not found", kXML)) ;
439 return kFALSE ;
440 }
441 TGridResult* result = collection->GetGridResult("",0 ,0);
442
443 for (Int_t index = 0; index < result->GetEntries(); index++) {
444 TString alienURL = result->GetKey(index, "turl") ;
445 cout << "================== " << alienURL << endl ;
446
447 if (alienURL.Contains("pass1")) kPass = "pass1";
448 else if(alienURL.Contains("pass2")) kPass = "pass2";
449 else if(alienURL.Contains("pass3")) kPass = "pass3";
450
451 TFile * fAOD = 0 ;
452 //Check if file exists and add it, if not skip it
453 if (alienURL.Contains("AliESDs.root")) {
454 kTreeName ="esdTree";
455 kInputData = "ESD";
456 alienURL.ReplaceAll("AliESDs.root","galice.root");
457 if(TFile::Open(alienURL)) kMC=kTRUE;
458 else kMC = kFALSE;
459
460 kRun = AliAnalysisManager::GetRunFromAlienPath(alienURL.Data());
461 printf("Run number from alien path = %d\n",kRun);
462
463 return;
464 }
465 else if(alienURL.Contains("AliAOD.root")){
466 kTreeName ="aodTree";
467 kInputData = "AOD";
468 fAOD = TFile::Open(alienURL);
469 if(((TTree*) fAOD->Get("aodTree"))->GetBranch("mcparticles")) kMC=kTRUE;
470 else kMC = kFALSE;
471 return;
472 }
473 else if(alienURL.Contains("embededAOD.root")){
474 kTreeName ="aodTree";
475 kInputData = "AOD";
476 kMC=kTRUE;
477 return;
478 }
479 else if(alienURL.Contains("galice.root")){
480 kTreeName ="TE";
481 kInputData = "MC";
482 kMC=kTRUE;
483 return;
484 }
485 }
486 }// xml analysis
487
488 gSystem->ChangeDirectory(ocwd.Data());
489
490}
d92b41ad 491
193828fd 492//_____________________________________________________________________
493void CreateChain(const anaModes mode, TChain * chain, TChain * chainxs)
494{
d92b41ad 495 //Fills chain with data
496 TString ocwd = gSystem->WorkingDirectory();
497
d92b41ad 498 //---------------------------------------
499 //Local files analysis
500 //---------------------------------------
2244659d 501 if(mode == mLocal){
d92b41ad 502 //If you want to add several ESD files sitting in a common directory INDIR
503 //Specify as environmental variables the directory (INDIR), the number of files
c8fe2783 504 //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
193828fd 505
d92b41ad 506 if(gSystem->Getenv("INDIR"))
507 kInDir = gSystem->Getenv("INDIR") ;
508 else cout<<"INDIR not set, use default: "<<kInDir<<endl;
509
510 if(gSystem->Getenv("PATTERN"))
511 kPattern = gSystem->Getenv("PATTERN") ;
512 else cout<<"PATTERN not set, use default: "<<kPattern<<endl;
513
c8fe2783 514 if(gSystem->Getenv("NFILES"))
515 kFile = atoi(gSystem->Getenv("NFILES")) ;
516 else cout<<"NFILES not set, use default: "<<kFile<<endl;
d92b41ad 517
518 //Check if env variables are set and are correct
c8fe2783 519 if ( kInDir && kFile) {
520 printf("Get %d files from directory %s\n",kFile,kInDir);
d92b41ad 521 if ( ! gSystem->cd(kInDir) ) {//check if ESDs directory exist
193828fd 522 printf("%s does not exist\n", kInDir) ;
523 return ;
d92b41ad 524 }
193828fd 525
c8fe2783 526 //if(gSystem->Getenv("XSFILE"))
527 //kXSFileName = gSystem->Getenv("XSFILE") ;
528 //else cout<<" XS file name not set, use default: "<<kXSFileName<<endl;
529 char * kGener = gSystem->Getenv("GENER");
530 if(kGener) {
193828fd 531 cout<<"GENER "<<kGener<<endl;
532 if(!strcmp(kGener,"PYTHIA")) kXSFileName = "pyxsec.root";
533 else if(!strcmp(kGener,"HERWIG")) kXSFileName = "hexsec.root";
534 else cout<<" UNKNOWN GENER, use default: "<<kXSFileName<<endl;
c8fe2783 535 }
536 else cout<<" GENER not set, use default xs file name: "<<kXSFileName<<endl;
193828fd 537
c8fe2783 538 cout<<"INDIR : "<<kInDir<<endl;
539 cout<<"NFILES : "<<kFile<<endl;
540 cout<<"PATTERN : " <<kPattern<<endl;
541 cout<<"XSFILE : "<<kXSFileName<<endl;
193828fd 542
7175a03a 543 TString datafile="";
544 if(kInputData == "ESD") datafile = "AliESDs.root" ;
193828fd 545 else if(kInputData.Contains("AOD")) datafile = "AliAOD.root" ;//////////
7175a03a 546 else if(kInputData == "MC") datafile = "galice.root" ;
547
d92b41ad 548 //Loop on ESD files, add them to chain
549 Int_t event =0;
550 Int_t skipped=0 ;
551 char file[120] ;
552 char filexs[120] ;
553
c8fe2783 554 for (event = 0 ; event < kFile ; event++) {
193828fd 555 sprintf(file, "%s/%s%d/%s", kInDir,kPattern,event,datafile.Data()) ;
556 sprintf(filexs, "%s/%s%d/%s", kInDir,kPattern,event,kXSFileName) ;
557 TFile * fESD = 0 ;
558 //Check if file exists and add it, if not skip it
559 if ( fESD = TFile::Open(file)) {
560 if ( fESD->Get(kTreeName) ) {
561 printf("++++ Adding %s\n", file) ;
562 chain->AddFile(file);
563 chainxs->Add(filexs) ;
564 }
565 }
566 else {
567 printf("---- Skipping %s\n", file) ;
568 skipped++ ;
569 }
d92b41ad 570 }
d92b41ad 571 }
572 else {
573 TString input = "AliESDs.root" ;
574 cout<<">>>>>> No list added, take a single file <<<<<<<<< "<<input<<endl;
575 chain->AddFile(input);
576 }
577
578 }// local files analysis
579
580 //------------------------------
581 //GRID xml files
582 //-----------------------------
583 else if(mode == mGRID){
584 //Get colection file. It is specified by the environmental
585 //variable XML
d92b41ad 586
d92b41ad 587 //Feed Grid with collection file
d92b41ad 588 TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
589 if (! collection) {
590 AliError(Form("%s not found", kXML)) ;
591 return kFALSE ;
592 }
593 TGridResult* result = collection->GetGridResult("",0 ,0);
193828fd 594
d92b41ad 595 // Makes the ESD chain
596 printf("*** Getting the Chain ***\n");
597 for (Int_t index = 0; index < result->GetEntries(); index++) {
598 TString alienURL = result->GetKey(index, "turl") ;
599 cout << "================== " << alienURL << endl ;
600 chain->Add(alienURL) ;
601 alienURL.ReplaceAll("AliESDs.root",kXSFileName);
602 chainxs->Add(alienURL) ;
603 }
604 }// xml analysis
605
606 gSystem->ChangeDirectory(ocwd.Data());
193828fd 607
d92b41ad 608}
609
193828fd 610//_________________________________________________________________
d92b41ad 611void GetAverageXsection(TTree * tree, Double_t & xs, Float_t & ntr)
612{
613 // Read the PYTHIA statistics from the file pyxsec.root created by
614 // the function WriteXsection():
615 // integrated cross section (xsection) and
616 // the number of Pyevent() calls (ntrials)
617 // and calculate the weight per one event xsection/ntrials
618 // The spectrum calculated by a user should be
619 // multiplied by this weight, something like this:
620 // TH1F *userSpectrum ... // book and fill the spectrum
621 // userSpectrum->Scale(weight)
622 //
623 // Yuri Kharlov 19 June 2007
624 // Gustavo Conesa 15 April 2008
625 Double_t xsection = 0;
626 UInt_t ntrials = 0;
627 xs = 0;
628 ntr = 0;
629
630 Int_t nfiles = tree->GetEntries() ;
631 if (tree && nfiles > 0) {
632 tree->SetBranchAddress("xsection",&xsection);
633 tree->SetBranchAddress("ntrials",&ntrials);
634 for(Int_t i = 0; i < nfiles; i++){
635 tree->GetEntry(i);
636 xs += xsection ;
637 ntr += ntrials ;
638 cout << "xsection " <<xsection<<" ntrials "<<ntrials<<endl;
639 }
640
641 xs = xs / nfiles;
642 ntr = ntr / nfiles;
643 cout << "-----------------------------------------------------------------"<<endl;
644 cout << "Average of "<< nfiles<<" files: xsection " <<xs<<" ntrials "<<ntr<<endl;
645 cout << "-----------------------------------------------------------------"<<endl;
646 }
647 else cout << " >>>> Empty tree !!!! <<<<< "<<endl;
648
649}
650
651
193828fd 652//______________________________
653void CheckEnvironmentVariables()
654{
655
656sprintf(kTrigger,"");
657
658Bool_t bRecalibrate = kFALSE;
659Bool_t bBadChannel = kFALSE;
660
661for (int i=0; i< gApplication->Argc();i++){
662
663#ifdef VERBOSEARGS
664
665 printf("Arg %d: %s\n",i,gApplication->Argv(i));
666
667#endif
668
669 if (!(strcmp(gApplication->Argv(i),"--trigger")))
670 sprintf(trigger,gApplication->Argv(i+1));
671
672 if (!(strcmp(gApplication->Argv(i),"--recalibrate")))
673 bRecalibrate = atoi(gApplication->Argv(i+1));
674
675 if (!(strcmp(gApplication->Argv(i),"--badchannel")))
676 bBadChannel = atoi(gApplication->Argv(i+1));
677
678 if (!(strcmp(gApplication->Argv(i),"--run"))){
679 TString sRun(gApplication->Argv(i+1));
680 if(sRun.Contains("LHC10")) {
681 kYear = 2010;
682 }
683 else {
684 if(kRun <=0){
685 kRun = atoi(gApplication->Argv(i+1));
686 }
687 else printf("** Run number already set to %d, do not set to %d\n",kRun,atoi(gApplication->Argv(i+1)));
688 }//numeric run
689 }//--run available
690
691}// args loop
692
693 if(!sRun.Contains("LHC10")){
694 if ( kRun < 140000) {
695 kYear = 2010;
696 if( kRun >= 136851 ) kCollision = "PbPb";
697 }
698 else{
699 kYear = 2011;
700 }
701 }
702
703if(kMC) sprintf(kTrigger,"");
704
705printf("*********************************************\n");
706//printf("*** Settings trigger %s, recalibrate %d, remove bad channels %d, year %d, collision %s, run %d ***\n",
707// kTrigger,bRecalibrate,bBadChannel, kYear,kCollision.Data(), kRun);
708printf("*** Settings year %d, collision %s, run %d ***\n",kYear,kCollision.Data(), kRun);
709printf("*********************************************\n");
710
711}
712
713//_____________________________________________________________
714void AddTaskCounter(const TString trigger = "MB")
715{
716
717 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
718
719 AliAnalysisTaskCounter * counter = new AliAnalysisTaskCounter(Form("Counter%s",trigger.Data()));
720 if(kRun > 140000 && kRun < 146900) counter ->RejectFastCluster();
721 if (kCollision=="pp" ) counter->SetZVertexCut(50.); //Open cut
722 else if(kCollision=="PbPb") counter->SetZVertexCut(10.); //Centrality defined in this range.
723
724 if(trigger=="EMC7"){
725 printf("counter trigger EMC7\n");
726 counter->SelectCollisionCandidates(AliVEvent::kEMC7);
727 }
728 else if (trigger=="INT7"){
729 printf("counter trigger INT7\n");
730 counter->SelectCollisionCandidates(AliVEvent::kINT7);
731 }
732 if(trigger=="EMC1"){
733 printf("counter trigger EMC1\n");
734 counter->SelectCollisionCandidates(AliVEvent::kEMC1);
735 }
736 else if(trigger=="MB"){
737 printf("counter trigger MB\n");
738 counter->SelectCollisionCandidates(AliVEvent::kMB);
739 }
740
741 TString outputFile = AliAnalysisManager::GetCommonFileName();
742 AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
743
744 AliAnalysisDataContainer *coutput =
745 mgr->CreateContainer(Form("Counter%s",trigger.Data()), TList::Class(), AliAnalysisManager::kOutputContainer, outputFile.Data());
746 mgr->AddTask(counter);
747 mgr->ConnectInput (counter, 0, cinput1);
748 mgr->ConnectOutput (counter, 1, coutput);
749
750}
751
752
753
754
d92b41ad 755