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