2 //--------------------------------------------------
3 // Example macro to do analysis with the
4 // analysis classes in PWG4PartCorr
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, mLocalCAF,mPROOF,mGRID};
14 //mLocal: Analyze locally files in your computer
15 //mLocalCAF: Analyze locally CAF files
16 //mPROOF: Analyze CAF files with PROOF
18 //---------------------------------------------------------------------------
19 //Settings to read locally several files, only for "mLocal" mode
20 //The different values are default, they can be set with environmental
21 //variables: INDIR, PATTERN, NFILES, respectivelly
22 //char * kInDir = "/Users/Gustavo/Work/mixed/data";
23 char * kPattern = ""; // Data are in files kInDir/kPattern+i
24 Int_t kFile = 1; // Number of files
25 //---------------------------------------------------------------------------
26 //Collection file for grid analysis
27 char * kXML = "collection.xml";
28 //---------------------------------------------------------------------------
29 //Scale histograms from file. Change to kTRUE when xsection file exists
30 //Put name of file containing xsection
31 //Put number of events per ESD file
32 //This is an specific case for normalization of Pythia files.
33 const Bool_t kGetXSectionFromFileAndScale = kFALSE ;
34 const char * kXSFileName = "pyxsec.root";
35 //---------------------------------------------------------------------------
37 const Bool_t kMC = kFALSE; //With real data kMC = kFALSE
38 const TString kInputData = "AOD"; //ESD, AOD, MC
41 void anaM(Int_t mode=mLocal)
45 //--------------------------------------------------------------------
46 // Load analysis libraries
47 // Look at the method below,
48 // change whatever you need for your analysis case
49 // ------------------------------------------------------------------
52 //-------------------------------------------------------------------------------------------------
53 //Create chain from ESD and from cross sections files, look below for options.
54 //-------------------------------------------------------------------------------------------------
55 if(kInputData == "ESD") kTreeName = "esdTree" ;
56 else if(kInputData == "AOD") kTreeName = "aodTree" ;
57 else if (kInputData == "MC") kTreeName = "TE" ;
59 cout<<"Wrong data type "<<kInputData<<endl;
63 TChain *chain = new TChain(kTreeName) ;
64 TChain * chainxs = new TChain("Xsection") ;
65 CreateChain(mode, chain, chainxs);
68 AliLog::SetGlobalLogLevel(AliLog::kError);//Minimum prints on screen
70 //--------------------------------------
71 // Make the analysis manager
72 //-------------------------------------
73 AliAnalysisManager *mgr = new AliAnalysisManager("Manager", "Manager");
75 if((kMC || kInputData == "MC") && kInputData!="AOD"){
76 AliMCEventHandler* mcHandler = new AliMCEventHandler();
77 mcHandler->SetReadTR(kFALSE);//Do not search TrackRef file
78 mgr->SetMCtruthEventHandler(mcHandler);
79 if( kInputData == "MC") mgr->SetInputEventHandler(NULL);
83 // AliAODHandler* aodoutHandler = new AliAODHandler();
84 // aodoutHandler->SetOutputFileName("aod.root");
85 // ////aodoutHandler->SetCreateNonStandardAOD();
86 // mgr->SetOutputEventHandler(aodoutHandler);
89 Int_t maxiterations = 1;
90 AliEventPoolLoop* pool = new AliEventPoolLoop(maxiterations);
91 pool->SetChain(chain);
92 Int_t eventsInPool = 2;
93 AliMultiEventInputHandler *inpHandler = NULL ;
94 if(kInputData == "ESD"){
96 printf("ESD MultiInput \n");
97 inpHandler = new AliMultiEventInputHandler(eventsInPool, 0);
99 if(kInputData == "AOD"){
101 inpHandler = new AliMultiEventInputHandler(eventsInPool, 1);
103 mgr->SetInputEventHandler(inpHandler);
104 cout<<"Input handler "<<mgr->GetInputEventHandler()<<endl;
105 mgr->SetEventPool(pool);
106 inpHandler->SetEventPool(pool);
108 //mgr->SetDebugLevel(10); // For debugging, do not uncomment if you want no messages.
110 //-------------------------------------------------------------------------
111 //Define task, put here any other task that you want to use.
112 //-------------------------------------------------------------------------
113 // AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
114 // AliAnalysisDataContainer *coutput1 = mgr->GetCommonOutputContainer();
116 //gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskESDFilter.C");
117 //AliAnalysisTaskESDfilter *taskesdfilter = AddTaskESDFilter(kTRUE);
119 gROOT->LoadMacro("AddTaskPartCorrM.C");
121 AliAnalysisTaskParticleCorrelationM *taskEMCAL = AddTaskPartCorrM(kInputData,"EMCAL", kFALSE,kFALSE,kFALSE,kTRUE);
122 mgr->AddTask(taskEMCAL);
123 AliAnalysisTaskParticleCorrelationM *taskPHOS = AddTaskPartCorrM(kInputData,"PHOS", kFALSE, kFALSE);
124 mgr->AddTask(taskPHOS);
126 //gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskCalorimeterQA.C");
127 //gROOT->LoadMacro("AddTaskCalorimeterQA.C");
128 //AliAnalysisTaskParticleCorrelation *taskQA = AddTaskCalorimeterQA(kInputData,kFALSE,kTRUE);
130 //gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskomega3pi.C");
131 //AliAnalysisTaskOmegaPi0PiPi * taskomega = AddTaskomega3pi();
132 //mgr->AddTask(taskomega);
136 //-----------------------
138 //-----------------------
140 if (mode==mLocal || mode == mLocalCAF)
142 else if (mode==mPROOF)
144 else if (mode==mGRID)
149 mgr->StartAnalysis(smode.Data(),chain,1000);
151 cout <<" Analysis ended sucessfully "<< endl ;
154 else cout << "Chain was not produced ! "<<endl;
158 void LoadLibraries(const anaModes mode) {
160 //--------------------------------------
161 // Load the needed libraries most of them already loaded by aliroot
162 //--------------------------------------
163 gSystem->Load("libTree.so");
164 gSystem->Load("libGeom.so");
165 gSystem->Load("libVMC.so");
166 gSystem->Load("libXMLIO.so");
168 //----------------------------------------------------------
169 // >>>>>>>>>>> Local mode <<<<<<<<<<<<<<
170 //----------------------------------------------------------
171 if (mode==mLocal || mode == mLocalCAF || mode == mGRID) {
172 //--------------------------------------------------------
173 // If you want to use already compiled libraries
174 // in the aliroot distribution
175 //--------------------------------------------------------
176 //gSystem->Load("/Users/Gustavo/Work/analysis/STEERBase/libSTEERBase.so");
177 //gSystem->Load("/Users/Gustavo/Work/analysis/ESD/libESD.so");
178 //gSystem->Load("/Users/Gustavo/Work/analysis/AOD/libAOD.so");
179 //gSystem->Load("/Users/Gustavo/Work/analysis/ANALYSIS/libANALYSIS.so");
180 //gSystem->Load("/Users/Gustavo/Work/analysis/ANALYSISalice/libANALYSISalice.so");
181 //gSystem->Load("libPHOSUtils");
182 //gSystem->Load("/Users/Gustavo/Work/analysis/PWG4PartCorrBase/libPWG4PartCorrBase.so");
183 //gSystem->Load("/Users/Gustavo/Work/analysis/PWG4PartCorrDep/libPWG4PartCorrDep.so");
185 gSystem->Load("libSTEERBase.so");
186 gSystem->Load("libESD.so");
187 gSystem->Load("libAOD.so");
188 gSystem->Load("libANALYSIS.so");
189 gSystem->Load("libANALYSISalice.so");
190 gSystem->Load("libPHOSUtils");
191 gSystem->Load("libEMCALUtils");
192 gSystem->Load("libPWG4PartCorrBase.so");
193 gSystem->Load("libPWG4PartCorrDep.so");
194 // gSystem->Load("libPWG4omega3pi.so");
195 // gSystem->Load("libCORRFW.so");
196 // gSystem->Load("libPWG3base.so");
197 // gSystem->Load("libPWG3muon.so");
199 //--------------------------------------------------------
200 //If you want to use root and par files from aliroot
201 //--------------------------------------------------------
202 // SetupPar("STEERBase");
205 // SetupPar("ANALYSIS");
206 // SetupPar("ANALYSISalice");
207 // //If your analysis needs PHOS geometry uncomment following lines
208 // SetupPar("PHOSUtils");
209 // SetupPar("EMCALUtils");
210 // // //Create Geometry
211 // // TGeoManager::Import("geometry.root") ; //need file "geometry.root" in local dir!!!!
212 // SetupPar("PWG4PartCorrBase");
213 // SetupPar("PWG4PartCorrDep");
214 // //SetupPar("PWG4omega3pi");
217 //---------------------------------------------------------
218 // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
219 //---------------------------------------------------------
220 else if (mode==mPROOF) {
223 // Put appropriate username here
224 // TProof::Reset("proof://mgheata@lxb6046.cern.ch");
225 TProof::Open("proof://mgheata@lxb6046.cern.ch");
227 // gProof->ClearPackages();
228 // gProof->ClearPackage("ESD");
229 // gProof->ClearPackage("AOD");
230 // gProof->ClearPackage("ANALYSIS");
231 // gProof->ClearPackage("PWG4PartCorrBase");
232 // gProof->ClearPackage("PWG4PartCorrDep");
234 // Enable the STEERBase Package
235 gProof->UploadPackage("STEERBase.par");
236 gProof->EnablePackage("STEERBase");
237 // Enable the ESD Package
238 gProof->UploadPackage("ESD.par");
239 gProof->EnablePackage("ESD");
240 // Enable the AOD Package
241 gProof->UploadPackage("AOD.par");
242 gProof->EnablePackage("AOD");
243 // Enable the Analysis Package
244 gProof->UploadPackage("ANALYSIS.par");
245 gProof->EnablePackage("ANALYSIS");
246 // Enable the PHOS geometry Package
247 //gProof->UploadPackage("PHOSUtils.par");
248 //gProof->EnablePackage("PHOSUtils");
249 // Enable PartCorr analysis
250 gProof->UploadPackage("PWG4PartCorrBase.par");
251 gProof->EnablePackage("PWG4PartCorrBase");
252 gProof->UploadPackage("PWG4PartCorrDep.par");
253 gProof->EnablePackage("PWG4PartCorrDep");
254 gProof->ShowEnabledPackages();
259 void SetupPar(char* pararchivename)
261 //Load par files, create analysis libraries
262 //For testing, if par file already decompressed and modified
263 //classes then do not decompress.
265 TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
266 TString parpar(Form("%s.par", pararchivename)) ;
267 if ( gSystem->AccessPathName(parpar.Data()) ) {
268 gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
269 TString processline(Form(".! make %s", parpar.Data())) ;
270 gROOT->ProcessLine(processline.Data()) ;
271 gSystem->ChangeDirectory(cdir) ;
272 processline = Form(".! mv $ALICE_ROOT/%s .", parpar.Data()) ;
273 gROOT->ProcessLine(processline.Data()) ;
275 if ( gSystem->AccessPathName(pararchivename) ) {
276 TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
277 gROOT->ProcessLine(processline.Data());
280 TString ocwd = gSystem->WorkingDirectory();
281 gSystem->ChangeDirectory(pararchivename);
283 // check for BUILD.sh and execute
284 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
285 printf("*******************************\n");
286 printf("*** Building PAR archive ***\n");
287 cout<<pararchivename<<endl;
288 printf("*******************************\n");
290 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
291 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
295 // check for SETUP.C and execute
296 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
297 printf("*******************************\n");
298 printf("*** Setup PAR archive ***\n");
299 cout<<pararchivename<<endl;
300 printf("*******************************\n");
301 gROOT->Macro("PROOF-INF/SETUP.C");
304 gSystem->ChangeDirectory(ocwd.Data());
305 printf("Current dir: %s\n", ocwd.Data());
310 void CreateChain(const anaModes mode, TChain * chain, TChain * chainxs){
311 //Fills chain with data
312 TString ocwd = gSystem->WorkingDirectory();
314 //-----------------------------------------------------------
315 //Analysis of CAF data locally and with PROOF
316 //-----------------------------------------------------------
317 if(mode ==mPROOF || mode ==mLocalCAF){
319 gROOT->LoadMacro("$ALICE_ROOT/PWG0/CreateESDChain.C");
320 // The second parameter is the number of input files in the chain
321 chain = CreateESDChain("ESD12001.txt", 5);
324 //---------------------------------------
325 //Local files analysis
326 //---------------------------------------
327 else if(mode == mLocal){
328 //If you want to add several ESD files sitting in a common directory INDIR
329 //Specify as environmental variables the directory (INDIR), the number of files
330 //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
332 if(gSystem->Getenv("INDIR"))
333 kInDir = gSystem->Getenv("INDIR") ;
334 else cout<<"INDIR not set, use default: "<<kInDir<<endl;
336 if(gSystem->Getenv("PATTERN"))
337 kPattern = gSystem->Getenv("PATTERN") ;
338 else cout<<"PATTERN not set, use default: "<<kPattern<<endl;
340 if(gSystem->Getenv("NFILES"))
341 kFile = atoi(gSystem->Getenv("NFILES")) ;
342 else cout<<"NFILES not set, use default: "<<kFile<<endl;
344 //Check if env variables are set and are correct
345 if ( kInDir && kFile) {
346 printf("Get %d files from directory %s\n",kFile,kInDir);
347 if ( ! gSystem->cd(kInDir) ) {//check if ESDs directory exist
348 printf("%s does not exist\n", kInDir) ;
352 //if(gSystem->Getenv("XSFILE"))
353 //kXSFileName = gSystem->Getenv("XSFILE") ;
354 //else cout<<" XS file name not set, use default: "<<kXSFileName<<endl;
355 char * kGener = gSystem->Getenv("GENER");
357 cout<<"GENER "<<kGener<<endl;
358 if(!strcmp(kGener,"PYTHIA")) kXSFileName = "pyxsec.root";
359 else if(!strcmp(kGener,"HERWIG")) kXSFileName = "hexsec.root";
360 else cout<<" UNKNOWN GENER, use default: "<<kXSFileName<<endl;
362 else cout<<" GENER not set, use default xs file name: "<<kXSFileName<<endl;
364 cout<<"INDIR : "<<kInDir<<endl;
365 cout<<"NFILES : "<<kFile<<endl;
366 cout<<"PATTERN : " <<kPattern<<endl;
367 cout<<"XSFILE : "<<kXSFileName<<endl;
370 if(kInputData == "ESD") datafile = "AliESDs.root" ;
371 else if(kInputData == "AOD") datafile = "AliAOD.root" ;
372 else if(kInputData == "MC") datafile = "galice.root" ;
374 //Loop on ESD files, add them to chain
380 for (event = 0 ; event < kFile ; event++) {
381 sprintf(file, "%s/%s%d/%s", kInDir,kPattern,event,datafile.Data()) ;
382 sprintf(filexs, "%s/%s%d/%s", kInDir,kPattern,event,kXSFileName) ;
384 //Check if file exists and add it, if not skip it
385 if ( fESD = TFile::Open(file)) {
386 if ( fESD->Get(kTreeName) ) {
387 printf("++++ Adding %s\n", file) ;
388 chain->AddFile(file);
389 chainxs->Add(filexs) ;
393 printf("---- Skipping %s\n", file) ;
397 printf("number of entries # %lld, skipped %d\n", chain->GetEntries(), skipped*100) ;
400 TString input = "AliESDs.root" ;
401 cout<<">>>>>> No list added, take a single file <<<<<<<<< "<<input<<endl;
402 chain->AddFile(input);
405 }// local files analysis
407 //------------------------------
409 //-----------------------------
410 else if(mode == mGRID){
411 //Get colection file. It is specified by the environmental
414 if(gSystem->Getenv("XML") )
415 kXML = gSystem->Getenv("XML");
417 sprintf(kXML, "collection.xml") ;
419 if (!TFile::Open(kXML)) {
420 printf("No collection file with name -- %s -- was found\n",kXML);
423 else cout<<"XML file "<<kXML<<endl;
425 //Load necessary libraries and connect to the GRID
426 gSystem->Load("libNetx.so") ;
427 gSystem->Load("libRAliEn.so");
428 TGrid::Connect("alien://") ;
430 //Feed Grid with collection file
431 //TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\", 0)", kXML));
432 TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
434 AliError(Form("%s not found", kXML)) ;
437 TGridResult* result = collection->GetGridResult("",0 ,0);
439 // Makes the ESD chain
440 printf("*** Getting the Chain ***\n");
441 for (Int_t index = 0; index < result->GetEntries(); index++) {
442 TString alienURL = result->GetKey(index, "turl") ;
443 cout << "================== " << alienURL << endl ;
444 chain->Add(alienURL) ;
445 alienURL.ReplaceAll("AliESDs.root",kXSFileName);
446 chainxs->Add(alienURL) ;
450 gSystem->ChangeDirectory(ocwd.Data());
453 //________________________________________________
454 void GetAverageXsection(TTree * tree, Double_t & xs, Float_t & ntr)
456 // Read the PYTHIA statistics from the file pyxsec.root created by
457 // the function WriteXsection():
458 // integrated cross section (xsection) and
459 // the number of Pyevent() calls (ntrials)
460 // and calculate the weight per one event xsection/ntrials
461 // The spectrum calculated by a user should be
462 // multiplied by this weight, something like this:
463 // TH1F *userSpectrum ... // book and fill the spectrum
464 // userSpectrum->Scale(weight)
466 // Yuri Kharlov 19 June 2007
467 // Gustavo Conesa 15 April 2008
468 Double_t xsection = 0;
473 Int_t nfiles = tree->GetEntries() ;
474 if (tree && nfiles > 0) {
475 tree->SetBranchAddress("xsection",&xsection);
476 tree->SetBranchAddress("ntrials",&ntrials);
477 for(Int_t i = 0; i < nfiles; i++){
481 cout << "xsection " <<xsection<<" ntrials "<<ntrials<<endl;
486 cout << "-----------------------------------------------------------------"<<endl;
487 cout << "Average of "<< nfiles<<" files: xsection " <<xs<<" ntrials "<<ntr<<endl;
488 cout << "-----------------------------------------------------------------"<<endl;
490 else cout << " >>>> Empty tree !!!! <<<<< "<<endl;