2 //--------------------------------------------------
3 // Example macro to do analysis with the
4 // analysis classes in CaloTrackCorrelations
5 // Can be executed with Root and AliRoot
7 // Pay attention to the options and definitions
8 // set in the lines below
10 // Author : Gustavo Conesa Balbastre (INFN-LNF)
12 //-------------------------------------------------
13 enum anaModes {mLocal=0, mPROOF=1, mPlugin=2, mGRID=3};
14 //mLocal = 0: Analyze locally files in your computer
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
19 //---------------------------------------------------------------------------
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
24 char * kInDir = "/user/data/files/";
25 char * kPattern = ""; // Data are in files kInDir/kPattern+i
28 //---------------------------------------------------------------------------
29 // Dataset for proof analysis, mode=mPROOF
30 // char * kDataset = "/alice/vernet/PbPb_LHC10h_ESD";
32 char * kDatasetPROOF = "/alice/vernet/LHC11b_149646";
33 //char * kDatasetPROOF = "/alice/vernet/LHC11b10a_AOD046";//LHC11d_AOD076
34 Int_t kDatasetNMaxFiles = 20;
35 TString ccin2p3UserName = "arbor" ;
36 TString alienUserName = "narbor" ;
38 //---------------------------------------------------------------------------
39 // Collection file for grid analysis
41 char * kXML = "collection.xml";
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.
48 const Bool_t kGetXSectionFromFileAndScale = kFALSE ;
49 const char * kXSFileName = "pyxsec.root";
51 //---------------------------------------------------------------------------
53 //Set some default values, but used values are set in the code!
55 Bool_t kMC = kFALSE; //With real data kMC = kFALSE
56 TString kInputData = "ESD"; //ESD, AOD, MC, deltaAOD
58 TString kCollision = "pp";
59 Bool_t outAOD = kTRUE; //Some tasks doesnt need it.
65 //________________________
66 void ana(Int_t mode=mGRID)
70 //--------------------------------------------------------------------
71 // Load analysis libraries
72 // Look at the method below,
73 // change whatever you need for your analysis case
74 // ------------------------------------------------------------------
77 //gSystem->ListLibraries();
79 //-------------------------------------------------------------------------------------------------
80 //Create chain from ESD and from cross sections files, look below for options.
81 //-------------------------------------------------------------------------------------------------
83 // Set kInputData and kTreeName looking to the kINDIR
87 // Check global analysis settings
89 CheckEnvironmentVariables();
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");
95 TChain * chain = new TChain(kTreeName) ;
96 TChain * chainxs = new TChain("Xsection") ;
97 CreateChain(mode, chain, chainxs);
99 printf("*********************************************\n");
100 printf("number of entries # %lld, skipped %d\n", chain->GetEntries()) ;
101 printf("*********************************************\n");
105 printf("STOP, no chain available\n");
109 AliLog::SetGlobalLogLevel(AliLog::kError);//Minimum prints on screen
111 //------------------------------------------
112 // Alien handler part
113 //------------------------------------------
114 AliAnalysisGrid *alienHandler=0x0;
117 // Create and configure the alien handler plugin
118 gROOT->LoadMacro("CreateAlienHandler.C");
119 alienHandler = CreateAlienHandler();
120 if (!alienHandler) return;
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);
133 // Connect plugin to the analysis manager
134 mgr->SetGridHandler(alienHandler);
138 if((kMC || kInputData == "MC") && !kInputData.Contains("AOD"))
140 AliMCEventHandler* mcHandler = new AliMCEventHandler();
141 mcHandler->SetReadTR(kFALSE);//Do not search TrackRef file
142 mgr->SetMCtruthEventHandler(mcHandler);
143 if( kInputData == "MC")
145 cout<<"MC INPUT EVENT HANDLER"<<endl;
146 mgr->SetInputEventHandler(NULL);
151 // AOD output handler
152 if(kInputData!="deltaAOD" && outAOD)
154 cout<<"Init output handler"<<endl;
155 AliAODHandler* aodoutHandler = new AliAODHandler();
156 aodoutHandler->SetOutputFileName("aod.root");
157 ////aodoutHandler->SetCreateNonStandardAOD();
158 mgr->SetOutputEventHandler(aodoutHandler);
163 if(kInputData == "ESD")
166 AliESDInputHandler *esdHandler = new AliESDInputHandler();
167 esdHandler->SetReadFriends(kFALSE);
168 mgr->SetInputEventHandler(esdHandler);
169 cout<<"ESD handler "<<mgr->GetInputEventHandler()<<endl;
171 else if(kInputData.Contains("AOD"))
174 AliAODInputHandler *aodHandler = new AliAODInputHandler();
175 mgr->SetInputEventHandler(aodHandler);
176 if(kInputData == "deltaAOD") aodHandler->AddFriend("deltaAODCaloTrackCorr.root");
177 cout<<"AOD handler "<<mgr->GetInputEventHandler()<<endl;
179 //mgr->RegisterExternalFile("deltaAODCaloTrackCorr.root");
180 //mgr->SetDebugLevel(1); // For debugging, do not uncomment if you want no messages.
182 TString outputFile = AliAnalysisManager::GetCommonFileName();
184 //-------------------------------------------------------------------------
185 //Define task, put here any other task that you want to use.
186 //-------------------------------------------------------------------------
189 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
190 AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(kMC);
193 if(kCollision=="PbPb")
195 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
196 AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
199 // Simple event counting tasks
200 AddTaskCounter(""); // All
201 //AddTaskCounter("MB"); // Min Bias
204 AddTaskCounter("INT7"); // Min Bias
205 //AddTaskCounter("EMC1"); // Trig Th > 1.5 GeV approx
206 AddTaskCounter("EMC7"); // Trig Th > 4-5 GeV
207 AddTaskCounter("PHOS"); //
214 if(kInputData=="ESD"){
215 printf("* Configure photon conversion analysis in macro \n");
216 TString arguments = "-run-on-train -use-own-xyz -force-aod -mc-off ";
217 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/ConfigGammaConversion.C");
218 AliAnalysisTaskGammaConversion * taskGammaConversion =
219 ConfigGammaConversion(arguments,mgr->GetCommonInputContainer());
220 taskGammaConversion->SelectCollisionCandidates();
222 // Gamma Conversion AOD to AODPWG4Particle
223 AliAnalysisTaskGCPartToPWG4Part * taskGCToPC = new AliAnalysisTaskGCPartToPWG4Part("GCPartToPWG4Part");
224 taskGCToPC->SetGammaCutId("90035620401003321022000000090");
225 mgr->AddTask(taskGCToPC);
226 mgr->ConnectInput (taskGCToPC, 0, mgr->GetCommonInputContainer() );
227 mgr->ConnectOutput (taskGCToPC, 0, mgr->GetCommonOutputContainer());
231 Bool_t kPrint = kFALSE;
232 Bool_t deltaAOD = kFALSE;
233 gROOT->LoadMacro("AddTaskCaloTrackCorr.C"); // $ALICE_ROOT/PWG4/macros
234 gROOT->LoadMacro("AddTaskEMCALClusterize.C"); // $ALICE_ROOT/PWG4/CaloCalib/macros
241 // Track isolation-correlation analysis and EMCAL QA analysis
242 AliAnalysisTaskCaloTrackCorrelation *anamb = AddTaskCaloTrackCorr(kInputData, "EMCAL", kPrint,kMC, deltaAOD, outputFile.Data(),
243 kYear,kRun,kCollision,"INT7",""); // PHOS trigger
245 AliAnalysisTaskCaloTrackCorrelation *anatr = AddTaskCaloTrackCorr(kInputData, "EMCAL", kPrint,kMC, deltaAOD, outputFile.Data(),
246 kYear,kRun,kCollision,"EMC7","");
253 Bool_t bTrackMatch = kTRUE;
254 Int_t minEcell = 50; // 50 MeV (10 MeV used in reconstruction)
255 Int_t minEseed = 100; // 100 MeV
256 Int_t dTime = 0; // default, 250 ns
257 Int_t wTime = 0; // default 425 < T < 825 ns
258 TString clTrigger = ""; // Do not select, do Min Bias and triggered
260 //Analysis with clusterizer V1
261 AliAnalysisTaskEMCALClusterize * clv1 = AddTaskEMCALClusterize(kMC,"V1",clTrigger,kRun,kPass, bTrackMatch,
262 minEcell,minEseed,dTime,wTime);
264 TString arrayNameV1(Form("V1_Ecell%d_Eseed%d_DT%d_WT%d",minEcell,minEseed, dTime,wTime));
265 printf("Name of clusterizer array: %s\n",arrayNameV1.Data());
270 AliAnalysisTaskCaloTrackCorrelation *anav1tr = AddTaskCaloTrackCorr(kInputData, "EMCAL", kPrint,kMC, deltaAOD, outputFile.Data(),
271 kYear,kRun,kCollision,"EMC7",arrayNameV1);
273 AliAnalysisTaskCaloTrackCorrelation *anav1mb = AddTaskCaloTrackCorr(kInputData, "EMCAL", kPrint,kMC, deltaAOD, outputFile.Data(),
274 kYear,kRun,kCollision,"INT7",arrayNameV1);
277 {// No trigger (should be MB, but for single particle productions it does not work)
279 AliAnalysisTaskCaloTrackCorrelation *anav1 = AddTaskCaloTrackCorr(kInputData, "EMCAL", kPrint,kMC, deltaAOD, outputFile.Data(),
280 kYear,kRun,kCollision,"",arrayNameV1);
285 //Analysis with clusterizer V2
286 AliAnalysisTaskEMCALClusterize * clv2 = AddTaskEMCALClusterize(kMC,"V2",clTrigger,kRun,kPass, bTrackMatch,
287 minEcell,minEseed,dTime,wTime);
289 TString arrayNameV2(Form("V2_Ecell%d_Eseed%d_DT%d_WT%d",minEcell,minEseed, dTime,wTime));
290 printf("Name of clusterizer array: %s\n",arrayNameV2.Data());
295 AliAnalysisTaskCaloTrackCorrelation *anav2tr = AddTaskCaloTrackCorr(kInputData, "EMCAL", kPrint,kMC, deltaAOD, outputFile.Data(),
296 kYear,kRun,kCollision,"EMC7",arrayNameV2);
298 AliAnalysisTaskCaloTrackCorrelation *anav2mb = AddTaskCaloTrackCorr(kInputData, "EMCAL", kPrint,kMC, deltaAOD, outputFile.Data(),
299 kYear,kRun,kCollision,"INT7",arrayNameV2);
302 {// No trigger (should be MB, but for single particle productions it does not work)
303 AliAnalysisTaskCaloTrackCorrelation *anav2 = AddTaskCaloTrackCorr(kInputData, "EMCAL", kPrint,kMC, deltaAOD, outputFile.Data(),
304 kYear,kRun,kCollision,"",arrayNameV2);
312 //Add here PHOS tender or whatever is needed
317 AliAnalysisTaskCaloTrackCorrelation *anav1tr = AddTaskCaloTrackCorr(kInputData, "PHOS", kPrint,kMC, deltaAOD, outputFile.Data(),
318 kYear,kRun,kCollision,"PHOS",""); // PHOS trigger
320 AliAnalysisTaskCaloTrackCorrelation *anav1mb = AddTaskCaloTrackCorr(kInputData, "PHOS", kPrint,kMC, deltaAOD, outputFile.Data(),
321 kYear,kRun,kCollision,"INT7","");
327 AliAnalysisTaskCaloTrackCorrelation *anav1mb = AddTaskCaloTrackCorr(kInputData, "PHOS", kPrint,kMC, deltaAOD, outputFile.Data(),
328 kYear,kRun,kCollision,"","");
333 //-----------------------
335 //-----------------------
339 if (mode == mPlugin) mgr->StartAnalysis("grid");
340 else if (mode == mPROOF ) mgr->StartAnalysis("proof",chain);
341 else mgr->StartAnalysis("local",chain);
343 cout <<" Analysis ended sucessfully "<< endl ;
347 //_____________________________
348 void LoadLibraries(Int_t mode)
351 if (mode == mPROOF) {
352 //TProof::Mgr("ccalpmaster")->SetROOTVersion("ALICE_v5-27-06b");
353 gROOT->LoadMacro("/afs/in2p3.fr/group/alice/laf/EnableAliRootForLAF.C");
354 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");
356 // TProof* proof = TProof::Open("ccaplmaster",Form("workers=%s",nPROOFWorkers.Data()));
358 // //proof->ClearPackages();
359 // proof->UploadPackage("STEERBase");
360 // proof->UploadPackage("ESD");
361 // proof->UploadPackage("AOD");
362 // proof->UploadPackage("ANALYSIS");
363 // proof->UploadPackage("OADB");
364 // proof->UploadPackage("ANALYSISalice");
365 // proof->UploadPackage("CORRFW");
366 // //proof->UploadPackage("JETAN");
367 // proof->UploadPackage("PHOSUtils");
368 // proof->UploadPackage("EMCALUtils");
369 // proof->UploadPackage("PWG4PartCorrBase");
370 // proof->UploadPackage("PWG4PartCorrDep");
371 // proof->UploadPackage("PWG4CaloCalib");
373 // proof->EnablePackage("STEERBase");
374 // proof->EnablePackage("ESD");
375 // proof->EnablePackage("AOD");
376 // proof->EnablePackage("ANALYSIS");
377 // proof->EnablePackage("OADB");
378 // proof->EnablePackage("ANALYSISalice");
379 // proof->EnablePackage("CORRFW");
380 // //proof->EnablePackage("JETAN");
381 // proof->EnablePackage("PHOSUtils");
382 // proof->EnablePackage("EMCALUtils");
383 // proof->EnablePackage("PWG4PartCorrBase");
384 // proof->EnablePackage("PWG4PartCorrDep");
385 // proof->EnablePackage("PWG4CaloCalib");
389 //--------------------------------------
390 // Load the needed libraries most of them already loaded by aliroot
391 //--------------------------------------
392 gSystem->Load("libTree.so");
393 gSystem->Load("libGeom.so");
394 gSystem->Load("libVMC.so");
395 gSystem->Load("libXMLIO.so");
396 gSystem->Load("libMatrix.so");
397 gSystem->Load("libPhysics.so");
398 gSystem->Load("libMinuit.so"); // Root + libraries to if reclusterization is done
400 gSystem->Load("libSTEERBase.so");
401 gSystem->Load("libGui.so"); // Root + libraries to if reclusterization is done
402 gSystem->Load("libCDB.so"); // Root + libraries to if reclusterization is done
403 gSystem->Load("libESD.so"); // Root + libraries to if reclusterization is done
404 gSystem->Load("libAOD.so");
405 gSystem->Load("libRAWDatabase.so"); // Root + libraries to if reclusterization is done
406 gSystem->Load("libProof.so");
407 gSystem->Load("libANALYSIS.so");
408 gSystem->Load("libSTEER.so"); // Root + libraries to if reclusterization is done
410 gSystem->Load("libRAWDatarec.so"); // Root + libraries to if reclusterization is done
411 gSystem->Load("libRAWDatasim.so"); // Root + libraries to if reclusterization is done
412 gSystem->Load("libVZERObase.so"); // Root + libraries to if reclusterization is done
413 gSystem->Load("libVZEROrec.so"); // Root + libraries to if reclusterization is done
415 gSystem->Load("libEMCALUtils");
416 //SetupPar("EMCALUtils");
417 gSystem->Load("libEMCALraw"); // Root + libraries to if reclusterization is done
418 gSystem->Load("libEMCALbase"); // Root + libraries to if reclusterization is done
419 gSystem->Load("libEMCALsim"); // Root + libraries to if reclusterization is done
420 gSystem->Load("libEMCALrec"); // Root + libraries to if reclusterization is done
421 //SetupPar("EMCALraw");
422 //SetupPar("EMCALbase");
423 //SetupPar("EMCALsim");
424 //SetupPar("EMCALrec");
426 gSystem->Load("libANALYSISalice.so");
427 //gSystem->Load("libTENDER.so");
428 //gSystem->Load("libTENDERSupplies.so");
430 gSystem->Load("libPHOSUtils");
431 gSystem->Load("libEMCALUtils");
432 gSystem->Load("libPWG4PartCorrBase");
433 gSystem->Load("libPWG4PartCorrDep");
434 gSystem->Load("libPWG4CaloCalib");
435 //SetupPar("PWG4PartCorrBase");
436 //SetupPar("PWG4PartCorrDep");
437 //SetupPar("PWG4CaloCalib");
439 //gSystem->Load("libJETAN");
440 //gSystem->Load("FASTJETAN");
441 //gSystem->Load("PWG4JetTasks");
443 gSystem->Load("libCORRFW.so");
444 gSystem->Load("libPWG4GammaConv.so");
445 //SetupPar("PWG4GammaConv");
447 // needed for plugin?
448 gSystem->AddIncludePath("-I$ALICE_ROOT");
449 gSystem->AddIncludePath("-I./");
453 //_________________________________
454 void SetupPar(char* pararchivename)
456 //Load par files, create analysis libraries
457 //For testing, if par file already decompressed and modified
458 //classes then do not decompress.
460 TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
461 TString parpar(Form("%s.par", pararchivename)) ;
463 if ( gSystem->AccessPathName(pararchivename) ) {
464 TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
465 gROOT->ProcessLine(processline.Data());
468 TString ocwd = gSystem->WorkingDirectory();
469 gSystem->ChangeDirectory(pararchivename);
471 // check for BUILD.sh and execute
472 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
473 printf("*******************************\n");
474 printf("*** Building PAR archive ***\n");
475 cout<<pararchivename<<endl;
476 printf("*******************************\n");
478 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
479 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
483 // check for SETUP.C and execute
484 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
485 printf("*******************************\n");
486 printf("*** Setup PAR archive ***\n");
487 cout<<pararchivename<<endl;
488 printf("*******************************\n");
489 gROOT->Macro("PROOF-INF/SETUP.C");
492 gSystem->ChangeDirectory(ocwd.Data());
493 printf("Current dir: %s\n", ocwd.Data());
496 //______________________________________
497 void CheckInputData(const anaModes mode)
499 //Sets input data and tree
501 TString ocwd = gSystem->WorkingDirectory();
503 //---------------------------------------
504 //Local files analysis
505 //---------------------------------------
507 //If you want to add several ESD files sitting in a common directory INDIR
508 //Specify as environmental variables the directory (INDIR), the number of files
509 //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
511 if(gSystem->Getenv("INDIR"))
512 kInDir = gSystem->Getenv("INDIR") ;
513 else cout<<"INDIR not set, use default: "<<kInDir<<endl;
515 TString sindir(kInDir);
516 if (sindir.Contains("pass1")) kPass = "pass1";
517 else if(sindir.Contains("pass2")) kPass = "pass2";
518 else if(sindir.Contains("pass3")) kPass = "pass3";
520 if(gSystem->Getenv("PATTERN"))
521 kPattern = gSystem->Getenv("PATTERN") ;
522 else cout<<"PATTERN not set, use default: "<<kPattern<<endl;
524 cout<<"INDIR : "<<kInDir<<endl;
525 cout<<"NFILES : "<<kFile<<endl;
531 for (Int_t event = 0 ; event < kFile ; event++) {
532 sprintf(fileE, "%s/%s%d/AliESDs.root", kInDir,kPattern,event) ;
533 sprintf(fileA, "%s/%s%d/AliAOD.root", kInDir,kPattern,event) ;
534 sprintf(fileG, "%s/%s%d/galice.root", kInDir,kPattern,event) ;
535 sprintf(fileEm, "%s/%s%d/embededAOD.root", kInDir,kPattern,event) ;
537 TFile * fESD = TFile::Open(fileE) ;
538 TFile * fAOD = TFile::Open(fileA) ;
540 //Check if file exists and add it, if not skip it
543 kTreeName = "esdTree";
545 TFile * fG = TFile::Open(fileG);
546 if(fG) { kMC = kTRUE; fG->Close();}
550 TTree* esdTree = (TTree*)fESD->Get("esdTree");
551 AliESDEvent* esd = new AliESDEvent();
552 esd->ReadFromTree(esdTree);
553 esdTree->GetEvent(0);
554 kRun = esd->GetRunNumber();
560 kTreeName = "aodTree";
562 if(((TTree*) fAOD->Get("aodTree"))->GetBranch("mcparticles")) kMC=kTRUE;
566 TTree* aodTree = (TTree*)fAOD->Get("aodTree");
567 AliAODEvent* aod = new AliAODEvent();
568 aod->ReadFromTree(aodTree);
569 aodTree->GetEvent(0);
570 kRun = aod->GetRunNumber();
573 else if(TFile::Open(fileEm))
575 kTreeName = "aodTree";
581 else if(TFile::Open(fileG))
590 if(fESD) fESD->Close();
591 if(fAOD) fAOD->Close();
593 }// local files analysis
595 //------------------------------
597 //-----------------------------
598 else if(mode == mGRID){
599 //Get colection file. It is specified by the environmental
602 if(gSystem->Getenv("XML") )
603 kXML = gSystem->Getenv("XML");
605 sprintf(kXML, "collection.xml") ;
607 if (!TFile::Open(kXML)) {
608 printf("No collection file with name -- %s -- was found\n",kXML);
611 else cout<<"XML file "<<kXML<<endl;
613 //Load necessary libraries and connect to the GRID
614 gSystem->Load("libNetx.so") ;
615 gSystem->Load("libRAliEn.so");
616 TGrid::Connect("alien://") ;
618 //Feed Grid with collection file
619 TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
621 AliError(Form("%s not found", kXML)) ;
624 TGridResult* result = collection->GetGridResult("",0 ,0);
626 for (Int_t index = 0; index < result->GetEntries(); index++) {
627 TString alienURL = result->GetKey(index, "turl") ;
628 cout << "================== " << alienURL << endl ;
630 if (alienURL.Contains("pass1")) kPass = "pass1";
631 else if(alienURL.Contains("pass2")) kPass = "pass2";
632 else if(alienURL.Contains("pass3")) kPass = "pass3";
634 kRun = AliAnalysisManager::GetRunFromAlienPath(alienURL.Data());
635 printf("Run number from alien path = %d\n",kRun);
638 //Check if file exists and add it, if not skip it
639 if (alienURL.Contains("AliESDs.root"))
641 kTreeName = "esdTree";
643 alienURL.ReplaceAll("AliESDs.root","galice.root");
644 if(TFile::Open(alienURL)) kMC=kTRUE;
648 else if(alienURL.Contains("AliAOD.root"))
650 kTreeName = "aodTree";
652 fAOD = TFile::Open(alienURL);
653 if(((TTree*) fAOD->Get("aodTree"))->GetBranch("mcparticles")) kMC=kTRUE;
657 else if(alienURL.Contains("embededAOD.root"))
659 kTreeName = "aodTree";
664 else if(alienURL.Contains("galice.root"))
673 //------------------------------
675 //-----------------------------
676 else if(mode == mPROOF){
678 TFileCollection* coll = gProof->GetDataSet(kDatasetPROOF)->GetStagedSubset();
680 TIter iter(coll->GetList());
682 TFileInfo* fileInfo = 0;
683 while ((fileInfo = dynamic_cast<TFileInfo*> (iter())))
685 if (fileInfo->GetFirstUrl()) {
686 TString ProofURL = fileInfo->GetFirstUrl()->GetUrl();
687 cout << "================== " << ProofURL << endl ;
689 if (ProofURL.Contains("pass1")) kPass = "pass1";
690 else if(ProofURL.Contains("pass2")) kPass = "pass2";
691 else if(ProofURL.Contains("pass3")) kPass = "pass3";
693 kRun = AliAnalysisManager::GetRunFromAlienPath(ProofURL.Data());
694 printf("Run number from alien path = %d\n",kRun);
697 //Check if file exists and add it, if not skip it
698 if (ProofURL.Contains("AliESDs.root"))
700 kTreeName = "esdTree";
702 alienURL.ReplaceAll("AliESDs.root","galice.root");
703 if(TFile::Open(ProofURL)) kMC=kTRUE;
708 else if(ProofURL.Contains("AliAOD.root"))
710 kTreeName = "aodTree";
712 fAOD = TFile::Open(ProofURL);
713 if(((TTree*) fAOD->Get("aodTree"))->GetBranch("mcparticles")) kMC=kTRUE;
717 else if(ProofURL.Contains("embededAOD.root"))
719 kTreeName = "aodTree";
724 else if(ProofURL.Contains("galice.root"))
735 gSystem->ChangeDirectory(ocwd.Data());
739 //_____________________________________________________________________
740 void CreateChain(const anaModes mode, TChain * chain, TChain * chainxs)
742 //Fills chain with data
743 TString ocwd = gSystem->WorkingDirectory();
745 //---------------------------------------
746 // Local files analysis
747 //---------------------------------------
749 //If you want to add several ESD files sitting in a common directory INDIR
750 //Specify as environmental variables the directory (INDIR), the number of files
751 //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
753 if(gSystem->Getenv("INDIR"))
754 kInDir = gSystem->Getenv("INDIR") ;
755 else cout<<"INDIR not set, use default: "<<kInDir<<endl;
757 if(gSystem->Getenv("PATTERN"))
758 kPattern = gSystem->Getenv("PATTERN") ;
759 else cout<<"PATTERN not set, use default: "<<kPattern<<endl;
761 if(gSystem->Getenv("NFILES"))
762 kFile = atoi(gSystem->Getenv("NFILES")) ;
763 else cout<<"NFILES not set, use default: "<<kFile<<endl;
765 //Check if env variables are set and are correct
766 if ( kInDir && kFile) {
767 printf("Get %d files from directory %s\n",kFile,kInDir);
768 if ( ! gSystem->cd(kInDir) ) {//check if ESDs directory exist
769 printf("%s does not exist\n", kInDir) ;
773 //if(gSystem->Getenv("XSFILE"))
774 //kXSFileName = gSystem->Getenv("XSFILE") ;
775 //else cout<<" XS file name not set, use default: "<<kXSFileName<<endl;
776 char * kGener = gSystem->Getenv("GENER");
778 cout<<"GENER "<<kGener<<endl;
779 if (!strcmp(kGener,"PYTHIA")) kXSFileName = "pyxsec.root";
780 else if(!strcmp(kGener,"HERWIG")) kXSFileName = "hexsec.root";
781 else cout<<" UNKNOWN GENER, use default: "<<kXSFileName<<endl;
783 else cout<<" GENER not set, use default xs file name: "<<kXSFileName<<endl;
785 cout<<"INDIR : "<<kInDir <<endl;
786 cout<<"NFILES : "<<kFile <<endl;
787 cout<<"PATTERN : "<<kPattern <<endl;
788 cout<<"XSFILE : "<<kXSFileName<<endl;
791 if (kInputData == "ESD") datafile = "AliESDs.root" ;
792 else if(kInputData.Contains("AOD")) datafile = "AliAOD.root" ;
793 else if(kInputData == "MC") datafile = "galice.root" ;
795 //Loop on ESD/AOD/MC files, add them to chain
801 for (event = 0 ; event < kFile ; event++) {
802 sprintf(file, "%s/%s%d/%s", kInDir,kPattern,event,datafile.Data()) ;
803 sprintf(filexs, "%s/%s%d/%s", kInDir,kPattern,event,kXSFileName) ;
805 //Check if file exists and add it, if not skip it
806 if ( fData = TFile::Open(file)) {
807 if ( fData->Get(kTreeName) ) {
808 printf("++++ Adding %s\n", file) ;
809 chain->AddFile(file);
810 chainxs->Add(filexs) ;
814 printf("---- Skipping %s\n", file) ;
820 TString input = "AliESDs.root" ;
821 cout<<">>>>>> No list added, take a single file <<<<<<<<< "<<input<<endl;
822 chain->AddFile(input);
825 }// local files analysis
827 //------------------------------
829 //------------------------------
830 else if(mode == mGRID){
831 //Get colection file. It is specified by the environmental
834 //Feed Grid with collection file
835 TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
837 AliError(Form("%s not found", kXML)) ;
841 TGridResult* result = collection->GetGridResult("",0 ,0);
843 // Makes the ESD chain
844 printf("*** Getting the Chain ***\n");
845 for (Int_t index = 0; index < result->GetEntries(); index++) {
846 TString alienURL = result->GetKey(index, "turl") ;
847 cout << "================== " << alienURL << endl ;
848 chain->Add(alienURL) ;
849 alienURL.ReplaceAll("AliESDs.root",kXSFileName);
850 chainxs->Add(alienURL) ;
854 //------------------------------
856 //------------------------------
857 else if (mode == mPROOF) {
859 TFileCollection* ds= gProof->GetDataSet(kDatasetPROOF)->GetStagedSubset();
861 gROOT->LoadMacro("/afs/in2p3.fr/group/alice/laf/dataset_management/CreateChainFromDataSet.C");
862 chain = CreateChainFromDataSet(ds, kTreeName , kDatasetNMaxFiles);
863 printf("chain has %d entries\n",chain->GetEntries());
866 gSystem->ChangeDirectory(ocwd.Data());
870 //_________________________________________________________________
871 void GetAverageXsection(TTree * tree, Double_t & xs, Float_t & ntr)
873 // Read the PYTHIA statistics from the file pyxsec.root created by
874 // the function WriteXsection():
875 // integrated cross section (xsection) and
876 // the number of Pyevent() calls (ntrials)
877 // and calculate the weight per one event xsection/ntrials
878 // The spectrum calculated by a user should be
879 // multiplied by this weight, something like this:
880 // TH1F *userSpectrum ... // book and fill the spectrum
881 // userSpectrum->Scale(weight)
883 // Yuri Kharlov 19 June 2007
884 // Gustavo Conesa 15 April 2008
885 Double_t xsection = 0;
890 Int_t nfiles = tree->GetEntries() ;
891 if (tree && nfiles > 0)
893 tree->SetBranchAddress("xsection",&xsection);
894 tree->SetBranchAddress("ntrials",&ntrials);
895 for(Int_t i = 0; i < nfiles; i++){
899 cout << "xsection " <<xsection<<" ntrials "<<ntrials<<endl;
904 cout << "-----------------------------------------------------------------"<<endl;
905 cout << "Average of "<< nfiles<<" files: xsection " <<xs<<" ntrials "<<ntr<<endl;
906 cout << "-----------------------------------------------------------------"<<endl;
908 else cout << " >>>> Empty tree !!!! <<<<< "<<endl;
912 //______________________________
913 void CheckEnvironmentVariables()
916 sprintf(kTrigger,"");
918 Bool_t bRecalibrate = kFALSE;
919 Bool_t bBadChannel = kFALSE;
921 for (int i=0; i< gApplication->Argc();i++){
925 printf("Arg %d: %s\n",i,gApplication->Argv(i));
931 if (!(strcmp(gApplication->Argv(i),"--trigger")))
932 sprintf(trigger,gApplication->Argv(i+1));
934 if (!(strcmp(gApplication->Argv(i),"--recalibrate")))
935 bRecalibrate = atoi(gApplication->Argv(i+1));
937 if (!(strcmp(gApplication->Argv(i),"--badchannel")))
938 bBadChannel = atoi(gApplication->Argv(i+1));
940 if (!(strcmp(gApplication->Argv(i),"--run"))){
941 sRun = gApplication->Argv(i+1);
942 if(sRun.Contains("LHC10")) {
947 kRun = atoi(gApplication->Argv(i+1));
949 else printf("** Run number already set to %d, do not set to %d\n",kRun,atoi(gApplication->Argv(i+1)));
955 if(!sRun.Contains("LHC10")){
956 if ( kRun < 140000) {
958 if( kRun >= 136851 ) kCollision = "PbPb";
965 if(kMC) sprintf(kTrigger,"");
967 printf("*********************************************\n");
968 //printf("*** Settings trigger %s, recalibrate %d, remove bad channels %d, year %d, collision %s, run %d ***\n",
969 // kTrigger,bRecalibrate,bBadChannel, kYear,kCollision.Data(), kRun);
970 printf("*** Settings year %d, collision %s, run %d ***\n",kYear,kCollision.Data(), kRun);
971 printf("*********************************************\n");
975 //_______________________________________________
976 void AddTaskCounter(const TString trigger = "MB")
979 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
981 AliAnalysisTaskCounter * counter = new AliAnalysisTaskCounter(Form("Counter%s",trigger.Data()));
982 if(kRun > 140000 && kRun < 146900) counter ->RejectFastCluster();
983 if (kCollision=="pp" ) counter->SetZVertexCut(50.); //Open cut
984 else if(kCollision=="PbPb") counter->SetZVertexCut(10.); //Centrality defined in this range.
988 printf("counter trigger EMC7\n");
989 counter->SelectCollisionCandidates(AliVEvent::kEMC7);
991 else if (trigger=="INT7")
993 printf("counter trigger INT7\n");
994 counter->SelectCollisionCandidates(AliVEvent::kINT7);
998 printf("counter trigger EMC1\n");
999 counter->SelectCollisionCandidates(AliVEvent::kEMC1);
1001 else if(trigger=="MB")
1003 printf("counter trigger MB\n");
1004 counter->SelectCollisionCandidates(AliVEvent::kMB);
1006 else if(trigger=="PHOS")
1008 printf("counter trigger PHOS\n");
1009 counter->SelectCollisionCandidates(AliVEvent::kPHI7);
1012 TString outputFile = AliAnalysisManager::GetCommonFileName();
1013 AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
1015 AliAnalysisDataContainer *coutput =
1016 mgr->CreateContainer(Form("Counter%s",trigger.Data()), TList::Class(), AliAnalysisManager::kOutputContainer, outputFile.Data());
1017 mgr->AddTask(counter);
1018 mgr->ConnectInput (counter, 0, cinput1);
1019 mgr->ConnectOutput (counter, 1, coutput);