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;
180 //mgr->RegisterExternalFile("deltaAODCaloTrackCorr.root");
181 //mgr->SetDebugLevel(1); // For debugging, do not uncomment if you want no messages.
183 TString outputFile = AliAnalysisManager::GetCommonFileName();
185 //-------------------------------------------------------------------------
186 // Define task, put here any other task that you want to use.
187 //-------------------------------------------------------------------------
190 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
191 AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(kMC);
194 if(kCollision=="PbPb")
196 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
197 AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
200 // Simple event counting tasks
201 AddTaskCounter(""); // All
202 //AddTaskCounter("MB"); // Min Bias
203 AddTaskCounter("Any");
204 AddTaskCounter("AnyINT");// Min Bias
208 AddTaskCounter("EMC1"); // Trig Th > 1.5 GeV approx
209 AddTaskCounter("EMC7"); // Trig Th > 4-5 GeV
210 AddTaskCounter("EMCEGA");
211 AddTaskCounter("EMCEJE");
212 if(kCollision=="PbPb")
214 AddTaskCounter("Central");
215 AddTaskCounter("SemiCentral");
216 AddTaskCounter("PHOSPb");
218 else AddTaskCounter("PHOS");
226 if(kInputData=="ESD"){
227 printf("* Configure photon conversion analysis in macro \n");
228 TString arguments = "-run-on-train -use-own-xyz -force-aod -mc-off ";
229 gROOT->LoadMacro("$ALICE_ROOT/PWGGA/GammaConversion/macros/ConfigGammaConversion.C");
230 AliAnalysisTaskGammaConversion * taskGammaConversion =
231 ConfigGammaConversion(arguments,mgr->GetCommonInputContainer());
232 taskGammaConversion->SelectCollisionCandidates();
234 // Gamma Conversion AOD to AODPWG4Particle
235 AliAnalysisTaskGCPartToPWG4Part * taskGCToPC = new AliAnalysisTaskGCPartToPWG4Part("GCPartToPWG4Part");
236 taskGCToPC->SetGammaCutId("90035620401003321022000000090");
237 mgr->AddTask(taskGCToPC);
238 mgr->ConnectInput (taskGCToPC, 0, mgr->GetCommonInputContainer() );
239 mgr->ConnectOutput (taskGCToPC, 0, mgr->GetCommonOutputContainer());
243 Bool_t kPrint = kFALSE;
244 Bool_t deltaAOD = kFALSE;
245 gROOT->LoadMacro("AddTaskCaloTrackCorr.C"); // $ALICE_ROOT/PWGGA/CaloTrackCorrelations/macros
246 gROOT->LoadMacro("$ALICE_ROOT/PWGGA/EMCALTasks/macros/AddTaskEMCALClusterize.C"); // $ALICE_ROOT/PWGGA/EMCALTasks/macros
248 // gROOT->LoadMacro("$ALICE_ROOT/PWGGA/CaloTrackCorrelations/macros/QA/AddTaskCalorimeterQA.C");
249 // AliAnalysisTaskCaloTrackCorrelation * qatask = AddTaskCalorimeterQA(kInputData,kYear,kPrint,kMC);
251 // Calibration, bad map ...
253 Bool_t calibEE = kTRUE; // It is set automatically, but here we force to use ir or not in any case
254 Bool_t calibTT = kTRUE; // It is set automatically, but here we force to use ir or not in any case
255 if(kRun < 122195 || (kRun > 126437 && kRun < 136851)) calibTT=kFALSE ; // Recalibration parameters not available for LHC10a,b,c,e,f,g
256 Bool_t badMap = kTRUE; // It is set automatically, but here we force to use ir or not in any case
260 printf("==================================== \n");
261 printf("CONFIGURE ANALYSIS FOR PP COLLISIONS \n");
262 printf("==================================== \n");
265 Bool_t reTM = kFALSE; // Recalculate matches if not already done in clusterizer
266 Bool_t anTM = kTRUE; // Remove matched
267 Bool_t exo = kTRUE; // Remove exotic cells
268 Bool_t annonlin = kFALSE; // Apply non linearity (analysis)
269 Int_t minEcell = 50; // 50 MeV (10 MeV used in reconstruction)
270 Int_t minEseed = 100; // 100 MeV
271 Int_t dTime = 0; // default, 250 ns
272 Int_t wTime = 0; // default 425 < T < 825 ns, careful if time calibration is on
273 Int_t unfMinE = 15; // Remove cells with less than 15 MeV from cluster after unfolding
274 Int_t unfFrac = 1; // Remove cells with less than 1% of cluster energy after unfolding
278 TString clTrigger = "EMC7";
279 TString anTrigger = "EMC7";
280 TString anTriggerPH = "PHS";
288 Bool_t selectEvents = kFALSE; // Select events depending on V0, pile-up and vertex quality
289 Bool_t qa = kTRUE; // Do besides calorimeter QA analysis
290 Bool_t hadron = kTRUE; // Do besides charged track correlations analysis
292 //Analysis with clusterizer V1
294 TString arrayNameV1 = "";
295 AliAnalysisTaskEMCALClusterize * clv1 = AddTaskEMCALClusterize(kMC,exo,"V1",arrayNameV1,clTrigger, clTM,
296 minEcell,minEseed,dTime,wTime,unfMinE,unfFrac,
297 calibEE,badMap,calibTT,annonlin);
299 printf("Name of clusterizer1 array: %s\n",arrayNameV1.Data());
301 AliAnalysisTaskCaloTrackCorrelation *anav1 = AddTaskCaloTrackCorr(kInputData, "EMCAL", kMC, selectEvents, exo, annonlin, outputFile.Data(),
302 kYear,kCollision,anTrigger,arrayNameV1,reTM,anTM,
303 -1,-1, qa, hadron,calibEE,badMap,calibTT,deltaAOD,kPrint);
305 //Analysis with clusterizer V2
306 TString arrayNameV2 = "";
307 AliAnalysisTaskEMCALClusterize * clv2 = AddTaskEMCALClusterize(kMC,exo,"V2",arrayNameV2,clTrigger, clTM,
308 minEcell,minEseed,dTime,wTime,unfMinE,unfFrac,
309 calibEE,badMap,calibTT,annonlin);
311 printf("Name of clusterizer2 array: %s\n",arrayNameV2.Data());
314 AliAnalysisTaskCaloTrackCorrelation *anav2 = AddTaskCaloTrackCorr(kInputData, "EMCAL", kMC, selectEvents, exo, annonlin, outputFile.Data(),
315 kYear,kCollision,anTrigger,arrayNameV2,reTM,anTM,
316 -1,-1,qa,hadron,calibEE,badMap,calibTT,deltaAOD,kPrint);
320 //AliAnalysisTaskCaloTrackCorrelation *anaPH = AddTaskCaloTrackCorr(kInputData, "PHOS", kMC, selectEvents, kFALSE, kFALSE, outputFile.Data(),
321 // kYear,kCollision,anTriggerPH,"",kFALSE,kFALSE,
322 // -1,-1, qa, kFALSE,kFALSE,kFALSE,kFALSE,deltaAOD,kPrint);
326 if(kCollision=="PbPb")
328 printf("====================================== \n");
329 printf("CONFIGURE ANALYSIS FOR PbPb COLLISIONS \n");
330 printf("====================================== \n");
333 Bool_t reTM = kFALSE; // Recalculate matches if not already done in clusterizer
334 Bool_t anTM = kTRUE; // Remove matched
335 Bool_t exo = kTRUE; // Remove exotic cells
336 Bool_t annonlin = kFALSE; // Apply non linearity (analysis)
337 Int_t minEcell = 100; // 50 MeV (10 MeV used in reconstruction)
338 Int_t minEseed = 200; // 100 MeV
339 Int_t dTime = 0; // default, 250 ns
340 Int_t wTime = 0; // default 425 < T < 825 ns
341 Int_t unfMinE = 15; // Remove cells with less than 15 MeV from cluster after unfolding
342 Int_t unfFrac = 1; // Remove cells with less than 1% of cluster energy after unfolding
345 TString clTrigger = "EMCGA";
346 TString anTrigger = "EMCGA";
353 Bool_t selectEvents = kFALSE; // Select events depending on V0, pile-up and vertex quality
354 Bool_t qa = kTRUE; // Do besides calorimeter QA analysis
355 Bool_t hadron = kTRUE; // Do besides charged track correlations analysis
357 //Analysis with clusterizer V1
359 TString arrayNameV1 = "";
360 AliAnalysisTaskEMCALClusterize * clv1 = AddTaskEMCALClusterize(kMC,exo,"V1",arrayNameV1,clTrigger, clTM,
361 minEcell,minEseed,dTime,wTime,unfMinE,unfFrac,
362 calibEE,badMap,calibTT,annonlin);
365 printf("Name of clusterizer1 array: %s\n",arrayNameV1.Data());
367 AliAnalysisTaskCaloTrackCorrelation *anav1c = AddTaskCaloTrackCorr(kInputData, "EMCAL", kMC, selectEvents, exo, annonlin, outputFile.Data(),
368 kYear,kCollision,anTrigger,arrayNameV1,reTM,anTM,
369 0,20,qa,hadron,calibEE,badMap,calibTT,deltaAOD,kPrint);
370 AliAnalysisTaskCaloTrackCorrelation *anav1m = AddTaskCaloTrackCorr(kInputData, "EMCAL", kMC, selectEvents, exo, annonlin, outputFile.Data(),
371 kYear,kCollision,anTrigger,arrayNameV1,reTM,anTM,
372 20,40,qa,hadron,calibEE,badMap,calibTT,deltaAOD,kPrint);
373 AliAnalysisTaskCaloTrackCorrelation *anav1p = AddTaskCaloTrackCorr(kInputData, "EMCAL", kMC, selectEvents, exo, annonlin, outputFile.Data(),
374 kYear,kCollision,anTrigger,arrayNameV1,reTM,anTM,
375 60,80,qa,hadron,calibEE,badMap,calibTT,deltaAOD,kPrint);
377 //Analysis with clusterizer V2
379 TString arrayNameV2 = "";
380 AliAnalysisTaskEMCALClusterize * clv2 = AddTaskEMCALClusterize(kMC,exo,"V2",arrayNameV2,clTrigger, clTM,
381 minEcell,minEseed,dTime,wTime,unfMinE,unfFrac,
382 calibEE,badMap,calibTT,annonlin);
384 printf("Name of clusterizer2 array: %s\n",arrayNameV2.Data());
388 AliAnalysisTaskCaloTrackCorrelation *anav2c = AddTaskCaloTrackCorr(kInputData, "EMCAL", kMC, selectEvents, exo, annonlin, outputFile.Data(),
389 kYear,kCollision,anTrigger,arrayNameV2,reTM,anTM,
390 0,20,qa,hadron,calibEE,badMap,calibTT,deltaAOD,kPrint);
391 AliAnalysisTaskCaloTrackCorrelation *anav2m = AddTaskCaloTrackCorr(kInputData, "EMCAL", kMC, selectEvents, exo, annonlin, outputFile.Data(),
392 kYear,kCollision,anTrigger,arrayNameV2,reTM,anTM,
393 20,40,qa,hadron,calibEE,badMap,calibTT,deltaAOD,kPrint);
394 AliAnalysisTaskCaloTrackCorrelation *anav2p = AddTaskCaloTrackCorr(kInputData, "EMCAL", kMC, selectEvents, exo, annonlin, outputFile.Data(),
395 kYear,kCollision,anTrigger,arrayNameV2,reTM,anTM,
396 60,80,qa,hadron,calibEE,badMap,calibTT,deltaAOD,kPrint);
399 //-----------------------
401 //-----------------------
405 if (mode == mPlugin) mgr->StartAnalysis("grid");
406 else if (mode == mPROOF ) mgr->StartAnalysis("proof",chain);
407 else mgr->StartAnalysis("local",chain);
409 cout <<" Analysis ended sucessfully "<< endl ;
413 //_____________________________
414 void LoadLibraries(Int_t mode)
417 if (mode == mPROOF) {
418 //TProof::Mgr("ccalpmaster")->SetROOTVersion("ALICE_v5-27-06b");
419 gROOT->LoadMacro("/afs/in2p3.fr/group/alice/laf/EnableAliRootForLAF.C");
420 TProof* proof = EnableAliRootForLAF("ccaplmaster",nPROOFWorkers.Data(),ccin2p3UserName.Data(),alienUserName.Data(),"",kFALSE,kTRUE,kTRUE,"OADB:ANALYSIS:ANALYSISalice:AOD:ESD:CORRFW:STEERBase:EMCALUtils:PHOSUtils:PWGCaloTrackCorrBase:PWGGACaloTrackCorrelations:PWGGAEMCALTasks");
422 // TProof* proof = TProof::Open("ccaplmaster",Form("workers=%s",nPROOFWorkers.Data()));
424 // //proof->ClearPackages();
425 // proof->UploadPackage("STEERBase");
426 // proof->UploadPackage("ESD");
427 // proof->UploadPackage("AOD");
428 // proof->UploadPackage("ANALYSIS");
429 // proof->UploadPackage("OADB");
430 // proof->UploadPackage("ANALYSISalice");
431 // proof->UploadPackage("CORRFW");
432 // //proof->UploadPackage("JETAN");
433 // proof->UploadPackage("PHOSUtils");
434 // proof->UploadPackage("EMCALUtils");
435 // proof->UploadPackage("PWGCaloTrackCorrBase");
436 // proof->UploadPackage("PWGGACaloTrackCorrelations");
437 // proof->UploadPackage("PWGGAEMCALTasks");
439 // proof->EnablePackage("STEERBase");
440 // proof->EnablePackage("ESD");
441 // proof->EnablePackage("AOD");
442 // proof->EnablePackage("ANALYSIS");
443 // proof->EnablePackage("OADB");
444 // proof->EnablePackage("ANALYSISalice");
445 // proof->EnablePackage("CORRFW");
446 // //proof->EnablePackage("JETAN");
447 // proof->EnablePackage("PHOSUtils");
448 // proof->EnablePackage("EMCALUtils");
449 // proof->EnablePackage("PWGCaloTrackCorrBase");
450 // proof->EnablePackage("PWGGACaloTrackCorrelations");
451 // proof->EnablePackage("PWGGAEMCALTasks");
455 //--------------------------------------
456 // Load the needed libraries most of them already loaded by aliroot
457 //--------------------------------------
458 gSystem->Load("libTree.so");
459 gSystem->Load("libGeom.so");
460 gSystem->Load("libVMC.so");
461 gSystem->Load("libXMLIO.so");
462 gSystem->Load("libMatrix.so");
463 gSystem->Load("libPhysics.so");
464 gSystem->Load("libMinuit.so"); // Root + libraries to if reclusterization is done
466 gSystem->Load("libSTEERBase.so");
467 gSystem->Load("libGui.so"); // Root + libraries to if reclusterization is done
468 gSystem->Load("libCDB.so"); // Root + libraries to if reclusterization is done
469 gSystem->Load("libESD.so"); // Root + libraries to if reclusterization is done
470 gSystem->Load("libAOD.so");
471 gSystem->Load("libRAWDatabase.so"); // Root + libraries to if reclusterization is done
472 gSystem->Load("libProof.so");
473 gSystem->Load("libOADB");
474 gSystem->Load("libANALYSIS.so");
475 gSystem->Load("libSTEER.so"); // Root + libraries to if reclusterization is done
477 gSystem->Load("libRAWDatarec.so"); // Root + libraries to if reclusterization is done
478 gSystem->Load("libRAWDatasim.so"); // Root + libraries to if reclusterization is done
479 gSystem->Load("libVZERObase.so"); // Root + libraries to if reclusterization is done
480 gSystem->Load("libVZEROrec.so"); // Root + libraries to if reclusterization is done
482 gSystem->Load("libEMCALUtils");
483 //SetupPar("EMCALUtils");
484 gSystem->Load("libEMCALraw"); // Root + libraries to if reclusterization is done
485 gSystem->Load("libEMCALbase"); // Root + libraries to if reclusterization is done
486 gSystem->Load("libEMCALsim"); // Root + libraries to if reclusterization is done
487 gSystem->Load("libEMCALrec"); // Root + libraries to if reclusterization is done
488 //SetupPar("EMCALraw");
489 //SetupPar("EMCALbase");
490 //SetupPar("EMCALsim");
491 //SetupPar("EMCALrec");
493 gSystem->Load("libANALYSISalice.so");
494 //gSystem->Load("libTENDER.so");
495 //gSystem->Load("libTENDERSupplies.so");
497 gSystem->Load("libPHOSUtils");
498 gSystem->Load("libEMCALUtils");
499 gSystem->Load("libPWGCaloTrackCorrBase");
500 gSystem->Load("libPWGGACaloTrackCorrelations");
501 gSystem->Load("libPWGGAEMCALTasks");
502 //SetupPar("PWGCaloTrackCorrBase");
503 //SetupPar("PWGGACaloTrackCorrelations");
504 //SetupPar("PWGGAEMCALTasks");
507 //gSystem->Load("libJETAN");
508 //gSystem->Load("FASTJETAN");
509 //gSystem->Load("PWGJE");
511 //gSystem->Load("libCORRFW.so");
512 //gSystem->Load("libPWGGAGammaConv.so");
513 //SetupPar("PWGGAGammaConv");
515 // needed for plugin?
516 gSystem->AddIncludePath("-I$ALICE_ROOT");
517 gSystem->AddIncludePath("-I./");
521 //_________________________________
522 void SetupPar(char* pararchivename)
524 //Load par files, create analysis libraries
525 //For testing, if par file already decompressed and modified
526 //classes then do not decompress.
528 TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
529 TString parpar(Form("%s.par", pararchivename)) ;
531 if ( gSystem->AccessPathName(pararchivename) ) {
532 TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
533 gROOT->ProcessLine(processline.Data());
536 TString ocwd = gSystem->WorkingDirectory();
537 gSystem->ChangeDirectory(pararchivename);
539 // check for BUILD.sh and execute
540 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
541 printf("*******************************\n");
542 printf("*** Building PAR archive ***\n");
543 cout<<pararchivename<<endl;
544 printf("*******************************\n");
546 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
547 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
551 // check for SETUP.C and execute
552 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
553 printf("*******************************\n");
554 printf("*** Setup PAR archive ***\n");
555 cout<<pararchivename<<endl;
556 printf("*******************************\n");
557 gROOT->Macro("PROOF-INF/SETUP.C");
560 gSystem->ChangeDirectory(ocwd.Data());
561 printf("Current dir: %s\n", ocwd.Data());
564 //______________________________________
565 void CheckInputData(const anaModes mode)
567 //Sets input data and tree
569 TString ocwd = gSystem->WorkingDirectory();
571 //---------------------------------------
572 //Local files analysis
573 //---------------------------------------
575 //If you want to add several ESD files sitting in a common directory INDIR
576 //Specify as environmental variables the directory (INDIR), the number of files
577 //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
579 if(gSystem->Getenv("INDIR"))
580 kInDir = gSystem->Getenv("INDIR") ;
581 else cout<<"INDIR not set, use default: "<<kInDir<<endl;
583 TString sindir(kInDir);
584 if (sindir.Contains("pass1")) kPass = "pass1";
585 else if(sindir.Contains("pass2")) kPass = "pass2";
586 else if(sindir.Contains("pass3")) kPass = "pass3";
588 if(gSystem->Getenv("PATTERN"))
589 kPattern = gSystem->Getenv("PATTERN") ;
590 else cout<<"PATTERN not set, use default: "<<kPattern<<endl;
592 cout<<"INDIR : "<<kInDir<<endl;
593 cout<<"NFILES : "<<kFile<<endl;
599 for (Int_t event = 0 ; event < kFile ; event++) {
600 sprintf(fileE, "%s/%s%d/AliESDs.root", kInDir,kPattern,event) ;
601 sprintf(fileA, "%s/%s%d/AliAOD.root", kInDir,kPattern,event) ;
602 sprintf(fileG, "%s/%s%d/galice.root", kInDir,kPattern,event) ;
603 sprintf(fileEm, "%s/%s%d/embededAOD.root", kInDir,kPattern,event) ;
605 TFile * fESD = TFile::Open(fileE) ;
606 TFile * fAOD = TFile::Open(fileA) ;
608 //Check if file exists and add it, if not skip it
611 kTreeName = "esdTree";
613 TFile * fG = TFile::Open(fileG);
614 if(fG) { kMC = kTRUE; fG->Close();}
618 TTree* esdTree = (TTree*)fESD->Get("esdTree");
619 AliESDEvent* esd = new AliESDEvent();
620 esd->ReadFromTree(esdTree);
621 esdTree->GetEvent(0);
622 kRun = esd->GetRunNumber();
628 kTreeName = "aodTree";
630 if(((TTree*) fAOD->Get("aodTree"))->GetBranch("mcparticles")) kMC=kTRUE;
634 TTree* aodTree = (TTree*)fAOD->Get("aodTree");
635 AliAODEvent* aod = new AliAODEvent();
636 aod->ReadFromTree(aodTree);
637 aodTree->GetEvent(0);
638 kRun = aod->GetRunNumber();
641 else if(TFile::Open(fileEm))
643 kTreeName = "aodTree";
649 else if(TFile::Open(fileG))
658 if(fESD) fESD->Close();
659 if(fAOD) fAOD->Close();
661 }// local files analysis
663 //------------------------------
665 //-----------------------------
666 else if(mode == mGRID){
667 //Get colection file. It is specified by the environmental
670 if(gSystem->Getenv("XML") )
671 kXML = gSystem->Getenv("XML");
673 sprintf(kXML, "collection.xml") ;
675 if (!TFile::Open(kXML)) {
676 printf("No collection file with name -- %s -- was found\n",kXML);
679 else cout<<"XML file "<<kXML<<endl;
681 //Load necessary libraries and connect to the GRID
682 gSystem->Load("libNetx.so") ;
683 gSystem->Load("libRAliEn.so");
684 TGrid::Connect("alien://") ;
686 //Feed Grid with collection file
687 TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
689 AliError(Form("%s not found", kXML)) ;
692 TGridResult* result = collection->GetGridResult("",0 ,0);
694 for (Int_t index = 0; index < result->GetEntries(); index++) {
695 TString alienURL = result->GetKey(index, "turl") ;
696 cout << "================== " << alienURL << endl ;
698 if (alienURL.Contains("pass1")) kPass = "pass1";
699 else if(alienURL.Contains("pass2")) kPass = "pass2";
700 else if(alienURL.Contains("pass3")) kPass = "pass3";
702 kRun = AliAnalysisManager::GetRunFromAlienPath(alienURL.Data());
703 printf("Run number from alien path = %d\n",kRun);
706 //Check if file exists and add it, if not skip it
707 if (alienURL.Contains("AliESDs.root"))
709 kTreeName = "esdTree";
711 alienURL.ReplaceAll("AliESDs.root","galice.root");
712 if(TFile::Open(alienURL)) kMC=kTRUE;
716 else if(alienURL.Contains("AliAOD.root"))
718 kTreeName = "aodTree";
720 fAOD = TFile::Open(alienURL);
721 if(((TTree*) fAOD->Get("aodTree"))->GetBranch("mcparticles")) kMC=kTRUE;
725 else if(alienURL.Contains("embededAOD.root"))
727 kTreeName = "aodTree";
732 else if(alienURL.Contains("galice.root"))
741 //------------------------------
743 //-----------------------------
744 else if(mode == mPROOF){
746 TFileCollection* coll = gProof->GetDataSet(kDatasetPROOF)->GetStagedSubset();
748 TIter iter(coll->GetList());
750 TFileInfo* fileInfo = 0;
751 while ((fileInfo = dynamic_cast<TFileInfo*> (iter())))
753 if (fileInfo->GetFirstUrl()) {
754 TString ProofURL = fileInfo->GetFirstUrl()->GetUrl();
755 cout << "================== " << ProofURL << endl ;
757 if (ProofURL.Contains("pass1")) kPass = "pass1";
758 else if(ProofURL.Contains("pass2")) kPass = "pass2";
759 else if(ProofURL.Contains("pass3")) kPass = "pass3";
761 kRun = AliAnalysisManager::GetRunFromAlienPath(ProofURL.Data());
762 printf("Run number from alien path = %d\n",kRun);
765 //Check if file exists and add it, if not skip it
766 if (ProofURL.Contains("AliESDs.root"))
768 kTreeName = "esdTree";
770 alienURL.ReplaceAll("AliESDs.root","galice.root");
771 if(TFile::Open(ProofURL)) kMC=kTRUE;
776 else if(ProofURL.Contains("AliAOD.root"))
778 kTreeName = "aodTree";
780 fAOD = TFile::Open(ProofURL);
781 if(((TTree*) fAOD->Get("aodTree"))->GetBranch("mcparticles")) kMC=kTRUE;
785 else if(ProofURL.Contains("embededAOD.root"))
787 kTreeName = "aodTree";
792 else if(ProofURL.Contains("galice.root"))
803 gSystem->ChangeDirectory(ocwd.Data());
807 //_____________________________________________________________________
808 void CreateChain(const anaModes mode, TChain * chain, TChain * chainxs)
810 //Fills chain with data
811 TString ocwd = gSystem->WorkingDirectory();
813 //---------------------------------------
814 // Local files analysis
815 //---------------------------------------
817 //If you want to add several ESD files sitting in a common directory INDIR
818 //Specify as environmental variables the directory (INDIR), the number of files
819 //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
821 if(gSystem->Getenv("INDIR"))
822 kInDir = gSystem->Getenv("INDIR") ;
823 else cout<<"INDIR not set, use default: "<<kInDir<<endl;
825 if(gSystem->Getenv("PATTERN"))
826 kPattern = gSystem->Getenv("PATTERN") ;
827 else cout<<"PATTERN not set, use default: "<<kPattern<<endl;
829 if(gSystem->Getenv("NFILES"))
830 kFile = atoi(gSystem->Getenv("NFILES")) ;
831 else cout<<"NFILES not set, use default: "<<kFile<<endl;
833 //Check if env variables are set and are correct
834 if ( kInDir && kFile) {
835 printf("Get %d files from directory %s\n",kFile,kInDir);
836 if ( ! gSystem->cd(kInDir) ) {//check if ESDs directory exist
837 printf("%s does not exist\n", kInDir) ;
841 //if(gSystem->Getenv("XSFILE"))
842 //kXSFileName = gSystem->Getenv("XSFILE") ;
843 //else cout<<" XS file name not set, use default: "<<kXSFileName<<endl;
844 char * kGener = gSystem->Getenv("GENER");
846 cout<<"GENER "<<kGener<<endl;
847 if (!strcmp(kGener,"PYTHIA")) kXSFileName = "pyxsec.root";
848 else if(!strcmp(kGener,"HERWIG")) kXSFileName = "hexsec.root";
849 else cout<<" UNKNOWN GENER, use default: "<<kXSFileName<<endl;
851 else cout<<" GENER not set, use default xs file name: "<<kXSFileName<<endl;
853 cout<<"INDIR : "<<kInDir <<endl;
854 cout<<"NFILES : "<<kFile <<endl;
855 cout<<"PATTERN : "<<kPattern <<endl;
856 cout<<"XSFILE : "<<kXSFileName<<endl;
859 if (kInputData == "ESD") datafile = "AliESDs.root" ;
860 else if(kInputData.Contains("AOD")) datafile = "AliAOD.root" ;
861 else if(kInputData == "MC") datafile = "galice.root" ;
863 //Loop on ESD/AOD/MC files, add them to chain
869 for (event = 0 ; event < kFile ; event++) {
870 sprintf(file, "%s/%s%d/%s", kInDir,kPattern,event,datafile.Data()) ;
871 sprintf(filexs, "%s/%s%d/%s", kInDir,kPattern,event,kXSFileName) ;
873 //Check if file exists and add it, if not skip it
874 if ( fData = TFile::Open(file)) {
875 if ( fData->Get(kTreeName) ) {
876 printf("++++ Adding %s\n", file) ;
877 chain->AddFile(file);
878 chainxs->Add(filexs) ;
882 printf("---- Skipping %s\n", file) ;
888 TString input = "AliESDs.root" ;
889 cout<<">>>>>> No list added, take a single file <<<<<<<<< "<<input<<endl;
890 chain->AddFile(input);
893 }// local files analysis
895 //------------------------------
897 //------------------------------
898 else if(mode == mGRID){
899 //Get colection file. It is specified by the environmental
902 //Feed Grid with collection file
903 TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
905 AliError(Form("%s not found", kXML)) ;
909 TGridResult* result = collection->GetGridResult("",0 ,0);
911 // Makes the ESD chain
912 printf("*** Getting the Chain ***\n");
913 for (Int_t index = 0; index < result->GetEntries(); index++) {
914 TString alienURL = result->GetKey(index, "turl") ;
915 cout << "================== " << alienURL << endl ;
916 chain->Add(alienURL) ;
917 alienURL.ReplaceAll("AliESDs.root",kXSFileName);
918 chainxs->Add(alienURL) ;
922 //------------------------------
924 //------------------------------
925 else if (mode == mPROOF) {
927 TFileCollection* ds= gProof->GetDataSet(kDatasetPROOF)->GetStagedSubset();
929 gROOT->LoadMacro("/afs/in2p3.fr/group/alice/laf/dataset_management/CreateChainFromDataSet.C");
930 chain = CreateChainFromDataSet(ds, kTreeName , kDatasetNMaxFiles);
931 printf("chain has %d entries\n",chain->GetEntries());
934 gSystem->ChangeDirectory(ocwd.Data());
938 //_________________________________________________________________
939 void GetAverageXsection(TTree * tree, Double_t & xs, Float_t & ntr)
941 // Read the PYTHIA statistics from the file pyxsec.root created by
942 // the function WriteXsection():
943 // integrated cross section (xsection) and
944 // the number of Pyevent() calls (ntrials)
945 // and calculate the weight per one event xsection/ntrials
946 // The spectrum calculated by a user should be
947 // multiplied by this weight, something like this:
948 // TH1F *userSpectrum ... // book and fill the spectrum
949 // userSpectrum->Scale(weight)
951 // Yuri Kharlov 19 June 2007
952 // Gustavo Conesa 15 April 2008
953 Double_t xsection = 0;
958 Int_t nfiles = tree->GetEntries() ;
959 if (tree && nfiles > 0)
961 tree->SetBranchAddress("xsection",&xsection);
962 tree->SetBranchAddress("ntrials",&ntrials);
963 for(Int_t i = 0; i < nfiles; i++){
967 cout << "xsection " <<xsection<<" ntrials "<<ntrials<<endl;
972 cout << "-----------------------------------------------------------------"<<endl;
973 cout << "Average of "<< nfiles<<" files: xsection " <<xs<<" ntrials "<<ntr<<endl;
974 cout << "-----------------------------------------------------------------"<<endl;
976 else cout << " >>>> Empty tree !!!! <<<<< "<<endl;
980 //______________________________
981 void CheckEnvironmentVariables()
984 sprintf(kTrigger,"");
986 Bool_t bRecalibrate = kFALSE;
987 Bool_t bBadChannel = kFALSE;
989 for (int i=0; i< gApplication->Argc();i++){
993 printf("Arg %d: %s\n",i,gApplication->Argv(i));
999 if (!(strcmp(gApplication->Argv(i),"--trigger")))
1000 sprintf(trigger,gApplication->Argv(i+1));
1002 if (!(strcmp(gApplication->Argv(i),"--recalibrate")))
1003 bRecalibrate = atoi(gApplication->Argv(i+1));
1005 if (!(strcmp(gApplication->Argv(i),"--badchannel")))
1006 bBadChannel = atoi(gApplication->Argv(i+1));
1008 if (!(strcmp(gApplication->Argv(i),"--run"))){
1009 sRun = gApplication->Argv(i+1);
1010 if(sRun.Contains("LHC10")) {
1015 kRun = atoi(gApplication->Argv(i+1));
1017 else printf("** Run number already set to %d, do not set to %d\n",kRun,atoi(gApplication->Argv(i+1)));
1023 if(!sRun.Contains("LHC10")){
1027 if( kRun >= 136851 ) kCollision = "PbPb";
1029 else if( kRun < 170600)
1032 if( kRun >= 166500 ) kCollision = "PbPb";
1041 if(kMC) sprintf(kTrigger,"");
1043 printf("*********************************************\n");
1044 //printf("*** Settings trigger %s, recalibrate %d, remove bad channels %d, year %d, collision %s, run %d ***\n",
1045 // kTrigger,bRecalibrate,bBadChannel, kYear,kCollision.Data(), kRun);
1046 printf("*** Settings year %d, collision %s, run %d ***\n",kYear,kCollision.Data(), kRun);
1047 printf("*********************************************\n");
1051 //_______________________________________________
1052 void AddTaskCounter(const TString trigger = "MB")
1055 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1057 AliAnalysisTaskCounter * counter = new AliAnalysisTaskCounter(Form("Counter%s",trigger.Data()));
1058 if(kRun > 140000 && kRun < 146900) counter ->RejectFastCluster();
1059 if (kCollision=="pp" ) counter->SetZVertexCut(50.); //Open cut
1060 else if(kCollision=="PbPb") counter->SetZVertexCut(10.); //Centrality defined in this range.
1064 printf("counter trigger EMC7\n");
1065 counter->SelectCollisionCandidates(AliVEvent::kEMC7);
1067 else if (trigger=="INT7")
1069 printf("counter trigger INT7\n");
1070 counter->SelectCollisionCandidates(AliVEvent::kINT7);
1074 printf("counter trigger EMC1\n");
1075 counter->SelectCollisionCandidates(AliVEvent::kEMC1);
1077 else if(trigger=="MB")
1079 printf("counter trigger MB\n");
1080 counter->SelectCollisionCandidates(AliVEvent::kMB);
1082 else if(trigger=="PHOS")
1084 printf("counter trigger PHOS\n");
1085 counter->SelectCollisionCandidates(AliVEvent::kPHI7);
1087 else if(trigger=="PHOSPb")
1089 printf("counter trigger PHOSPb\n");
1090 counter->SelectCollisionCandidates(AliVEvent::kPHOSPb);
1092 else if(trigger=="AnyINT")
1094 printf("counter trigger AnyINT\n");
1095 counter->SelectCollisionCandidates(AliVEvent::kAnyINT);
1097 else if(trigger=="INT")
1099 printf("counter trigger AnyINT\n");
1100 counter->SelectCollisionCandidates(AliVEvent::kAny);
1102 else if(trigger=="EMCEGA")
1104 printf("counter trigger EMC Gamma\n");
1105 counter->SelectCollisionCandidates(AliVEvent::kEMCEGA);
1107 else if(trigger=="EMCEJE")
1109 printf("counter trigger EMC Jet\n");
1110 counter->SelectCollisionCandidates(AliVEvent::kEMCEJE);
1112 else if(trigger=="Central")
1114 printf("counter trigger Central\n");
1115 counter->SelectCollisionCandidates(AliVEvent::kCentral);
1117 else if(trigger=="SemiCentral")
1119 printf("counter trigger SemiCentral\n");
1120 counter->SelectCollisionCandidates(AliVEvent::kSemiCentral);
1125 TString outputFile = AliAnalysisManager::GetCommonFileName();
1126 AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
1128 AliAnalysisDataContainer *coutput =
1129 mgr->CreateContainer(Form("Counter%s",trigger.Data()), TList::Class(), AliAnalysisManager::kOutputContainer, outputFile.Data());
1130 mgr->AddTask(counter);
1131 mgr->ConnectInput (counter, 0, cinput1);
1132 mgr->ConnectOutput (counter, 1, coutput);