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/schutz/group/benjamin/pi0";
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
39 TString kTreeName = "aodTree";
41 void ana(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 if(kInputData == "ESD")
92 AliESDInputHandler *esdHandler = new AliESDInputHandler();
93 mgr->SetInputEventHandler(esdHandler);
94 cout<<"ESD handler "<<mgr->GetInputEventHandler()<<endl;
96 if(kInputData == "AOD"){
98 AliAODInputHandler *aodHandler = new AliAODInputHandler();
99 mgr->SetInputEventHandler(aodHandler);
100 cout<<"AOD handler "<<mgr->GetInputEventHandler()<<endl;
104 // mgr->SetDebugLevel(-1); // For debugging, do not uncomment if you want no messages.
106 //-------------------------------------------------------------------------
107 //Define task, put here any other task that you want to use.
108 //-------------------------------------------------------------------------
109 AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
110 AliAnalysisDataContainer *coutput1 = mgr->GetCommonOutputContainer();
112 // gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskESDFilter.C");
113 // AliAnalysisTaskESDfilter *taskesdfilter = AddTaskESDFilter(kFALSE);
115 gROOT->LoadMacro("AddTaskPartCorr.C");
118 AliAnalysisTaskParticleCorrelation *taskEMCAL = AddTaskPartCorr(kInputData,"EMCAL", kTRUE, kFALSE);
119 mgr->AddTask(taskEMCAL);
120 AliAnalysisTaskParticleCorrelation *taskPHOS = AddTaskPartCorr(kInputData,"PHOS", kTRUE, kFALSE);
121 mgr->AddTask(taskPHOS);
123 //gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskCalorimeterQA.C");
124 //gROOT->LoadMacro("AddTaskCalorimeterQA.C");
125 //AliAnalysisTaskParticleCorrelation *taskQA = AddTaskCalorimeterQA(kInputData,kFALSE,kTRUE);
127 //gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskomega3pi.C");
128 //AliAnalysisTaskOmegaPi0PiPi * taskomega = AddTaskomega3pi();
129 //mgr->AddTask(taskomega);
133 //-----------------------
135 //-----------------------
137 if (mode==mLocal || mode == mLocalCAF)
139 else if (mode==mPROOF)
141 else if (mode==mGRID)
146 mgr->StartAnalysis(smode.Data(),chain);
148 cout <<" Analysis ended sucessfully "<< endl ;
151 else cout << "Chain was not produced ! "<<endl;
155 void LoadLibraries(const anaModes mode) {
157 //--------------------------------------
158 // Load the needed libraries most of them already loaded by aliroot
159 //--------------------------------------
160 gSystem->Load("libTree.so");
161 gSystem->Load("libGeom.so");
162 gSystem->Load("libVMC.so");
163 gSystem->Load("libXMLIO.so");
165 //----------------------------------------------------------
166 // >>>>>>>>>>> Local mode <<<<<<<<<<<<<<
167 //----------------------------------------------------------
168 if (mode==mLocal || mode == mLocalCAF || mode == mGRID) {
169 //--------------------------------------------------------
170 // If you want to use already compiled libraries
171 // in the aliroot distribution
172 //--------------------------------------------------------
173 //gSystem->Load("/Users/Gustavo/Work/analysis/STEERBase/libSTEERBase.so");
174 //gSystem->Load("/Users/Gustavo/Work/analysis/ESD/libESD.so");
175 //gSystem->Load("/Users/Gustavo/Work/analysis/AOD/libAOD.so");
176 //gSystem->Load("/Users/Gustavo/Work/analysis/ANALYSIS/libANALYSIS.so");
177 //gSystem->Load("/Users/Gustavo/Work/analysis/ANALYSISalice/libANALYSISalice.so");
178 //gSystem->Load("libPHOSUtils");
179 //gSystem->Load("/Users/Gustavo/Work/analysis/PWG4PartCorrBase/libPWG4PartCorrBase.so");
180 //gSystem->Load("/Users/Gustavo/Work/analysis/PWG4PartCorrDep/libPWG4PartCorrDep.so");
182 gSystem->Load("libSTEERBase.so");
183 gSystem->Load("libESD.so");
184 gSystem->Load("libAOD.so");
185 gSystem->Load("libANALYSIS.so");
186 gSystem->Load("libANALYSISalice.so");
187 gSystem->Load("libPHOSUtils");
188 gSystem->Load("libEMCALUtils");
189 gSystem->Load("libPWG4PartCorrBase.so");
190 gSystem->Load("libPWG4PartCorrDep.so");
191 gSystem->Load("libPWG4omega3pi.so");
192 gSystem->Load("libCORRFW.so");
193 gSystem->Load("libPWG3base.so");
194 gSystem->Load("libPWG3muon.so");
196 //--------------------------------------------------------
197 //If you want to use root and par files from aliroot
198 //--------------------------------------------------------
199 // SetupPar("STEERBase");
202 // SetupPar("ANALYSIS");
203 // SetupPar("ANALYSISalice");
204 // //If your analysis needs PHOS geometry uncomment following lines
205 // SetupPar("PHOSUtils");
206 // SetupPar("EMCALUtils");
207 // // //Create Geometry
208 // // TGeoManager::Import("geometry.root") ; //need file "geometry.root" in local dir!!!!
209 // SetupPar("PWG4PartCorrBase");
210 // SetupPar("PWG4PartCorrDep");
211 // //SetupPar("PWG4omega3pi");
214 //---------------------------------------------------------
215 // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
216 //---------------------------------------------------------
217 else if (mode==mPROOF) {
220 // Put appropriate username here
221 // TProof::Reset("proof://mgheata@lxb6046.cern.ch");
222 TProof::Open("proof://mgheata@lxb6046.cern.ch");
224 // gProof->ClearPackages();
225 // gProof->ClearPackage("ESD");
226 // gProof->ClearPackage("AOD");
227 // gProof->ClearPackage("ANALYSIS");
228 // gProof->ClearPackage("PWG4PartCorrBase");
229 // gProof->ClearPackage("PWG4PartCorrDep");
231 // Enable the STEERBase Package
232 gProof->UploadPackage("STEERBase.par");
233 gProof->EnablePackage("STEERBase");
234 // Enable the ESD Package
235 gProof->UploadPackage("ESD.par");
236 gProof->EnablePackage("ESD");
237 // Enable the AOD Package
238 gProof->UploadPackage("AOD.par");
239 gProof->EnablePackage("AOD");
240 // Enable the Analysis Package
241 gProof->UploadPackage("ANALYSIS.par");
242 gProof->EnablePackage("ANALYSIS");
243 // Enable the PHOS geometry Package
244 //gProof->UploadPackage("PHOSUtils.par");
245 //gProof->EnablePackage("PHOSUtils");
246 // Enable PartCorr analysis
247 gProof->UploadPackage("PWG4PartCorrBase.par");
248 gProof->EnablePackage("PWG4PartCorrBase");
249 gProof->UploadPackage("PWG4PartCorrDep.par");
250 gProof->EnablePackage("PWG4PartCorrDep");
251 gProof->ShowEnabledPackages();
256 void SetupPar(char* pararchivename)
258 //Load par files, create analysis libraries
259 //For testing, if par file already decompressed and modified
260 //classes then do not decompress.
262 TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
263 TString parpar(Form("%s.par", pararchivename)) ;
264 if ( gSystem->AccessPathName(parpar.Data()) ) {
265 gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
266 TString processline(Form(".! make %s", parpar.Data())) ;
267 gROOT->ProcessLine(processline.Data()) ;
268 gSystem->ChangeDirectory(cdir) ;
269 processline = Form(".! mv $ALICE_ROOT/%s .", parpar.Data()) ;
270 gROOT->ProcessLine(processline.Data()) ;
272 if ( gSystem->AccessPathName(pararchivename) ) {
273 TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
274 gROOT->ProcessLine(processline.Data());
277 TString ocwd = gSystem->WorkingDirectory();
278 gSystem->ChangeDirectory(pararchivename);
280 // check for BUILD.sh and execute
281 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
282 printf("*******************************\n");
283 printf("*** Building PAR archive ***\n");
284 cout<<pararchivename<<endl;
285 printf("*******************************\n");
287 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
288 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
292 // check for SETUP.C and execute
293 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
294 printf("*******************************\n");
295 printf("*** Setup PAR archive ***\n");
296 cout<<pararchivename<<endl;
297 printf("*******************************\n");
298 gROOT->Macro("PROOF-INF/SETUP.C");
301 gSystem->ChangeDirectory(ocwd.Data());
302 printf("Current dir: %s\n", ocwd.Data());
307 void CreateChain(const anaModes mode, TChain * chain, TChain * chainxs){
308 //Fills chain with data
309 TString ocwd = gSystem->WorkingDirectory();
311 //-----------------------------------------------------------
312 //Analysis of CAF data locally and with PROOF
313 //-----------------------------------------------------------
314 if(mode ==mPROOF || mode ==mLocalCAF){
316 gROOT->LoadMacro("$ALICE_ROOT/PWG0/CreateESDChain.C");
317 // The second parameter is the number of input files in the chain
318 chain = CreateESDChain("ESD12001.txt", 5);
321 //---------------------------------------
322 //Local files analysis
323 //---------------------------------------
324 else if(mode == mLocal){
325 //If you want to add several ESD files sitting in a common directory INDIR
326 //Specify as environmental variables the directory (INDIR), the number of files
327 //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
329 if(gSystem->Getenv("INDIR"))
330 kInDir = gSystem->Getenv("INDIR") ;
331 else cout<<"INDIR not set, use default: "<<kInDir<<endl;
333 if(gSystem->Getenv("PATTERN"))
334 kPattern = gSystem->Getenv("PATTERN") ;
335 else cout<<"PATTERN not set, use default: "<<kPattern<<endl;
337 if(gSystem->Getenv("NFILES"))
338 kFile = atoi(gSystem->Getenv("NFILES")) ;
339 else cout<<"NFILES not set, use default: "<<kFile<<endl;
341 //Check if env variables are set and are correct
342 if ( kInDir && kFile) {
343 printf("Get %d files from directory %s\n",kFile,kInDir);
344 if ( ! gSystem->cd(kInDir) ) {//check if ESDs directory exist
345 printf("%s does not exist\n", kInDir) ;
349 //if(gSystem->Getenv("XSFILE"))
350 //kXSFileName = gSystem->Getenv("XSFILE") ;
351 //else cout<<" XS file name not set, use default: "<<kXSFileName<<endl;
352 char * kGener = gSystem->Getenv("GENER");
354 cout<<"GENER "<<kGener<<endl;
355 if(!strcmp(kGener,"PYTHIA")) kXSFileName = "pyxsec.root";
356 else if(!strcmp(kGener,"HERWIG")) kXSFileName = "hexsec.root";
357 else cout<<" UNKNOWN GENER, use default: "<<kXSFileName<<endl;
359 else cout<<" GENER not set, use default xs file name: "<<kXSFileName<<endl;
361 cout<<"INDIR : "<<kInDir<<endl;
362 cout<<"NFILES : "<<kFile<<endl;
363 cout<<"PATTERN : " <<kPattern<<endl;
364 cout<<"XSFILE : "<<kXSFileName<<endl;
367 if(kInputData == "ESD") datafile = "AliESDs.root" ;
368 else if(kInputData == "AOD") datafile = "AliAOD.root" ;
369 else if(kInputData == "MC") datafile = "galice.root" ;
371 //Loop on ESD files, add them to chain
377 for (event = 0 ; event < kFile ; event++) {
378 sprintf(file, "%s/%s%d/%s", kInDir,kPattern,event,datafile.Data()) ;
379 sprintf(filexs, "%s/%s%d/%s", kInDir,kPattern,event,kXSFileName) ;
381 //Check if file exists and add it, if not skip it
382 if ( fESD = TFile::Open(file)) {
383 if ( fESD->Get(kTreeName) ) {
384 printf("++++ Adding %s\n", file) ;
385 chain->AddFile(file);
386 chainxs->Add(filexs) ;
390 printf("---- Skipping %s\n", file) ;
394 printf("number of entries # %lld, skipped %d\n", chain->GetEntries(), skipped*100) ;
397 TString input = "AliESDs.root" ;
398 cout<<">>>>>> No list added, take a single file <<<<<<<<< "<<input<<endl;
399 chain->AddFile(input);
402 }// local files analysis
404 //------------------------------
406 //-----------------------------
407 else if(mode == mGRID){
408 //Get colection file. It is specified by the environmental
411 if(gSystem->Getenv("XML") )
412 kXML = gSystem->Getenv("XML");
414 sprintf(kXML, "collection.xml") ;
416 if (!TFile::Open(kXML)) {
417 printf("No collection file with name -- %s -- was found\n",kXML);
420 else cout<<"XML file "<<kXML<<endl;
422 //Load necessary libraries and connect to the GRID
423 gSystem->Load("libNetx.so") ;
424 gSystem->Load("libRAliEn.so");
425 TGrid::Connect("alien://") ;
427 //Feed Grid with collection file
428 //TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\", 0)", kXML));
429 TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
431 AliError(Form("%s not found", kXML)) ;
434 TGridResult* result = collection->GetGridResult("",0 ,0);
436 // Makes the ESD chain
437 printf("*** Getting the Chain ***\n");
438 for (Int_t index = 0; index < result->GetEntries(); index++) {
439 TString alienURL = result->GetKey(index, "turl") ;
440 cout << "================== " << alienURL << endl ;
441 chain->Add(alienURL) ;
442 alienURL.ReplaceAll("AliESDs.root",kXSFileName);
443 chainxs->Add(alienURL) ;
447 gSystem->ChangeDirectory(ocwd.Data());
450 //________________________________________________
451 void GetAverageXsection(TTree * tree, Double_t & xs, Float_t & ntr)
453 // Read the PYTHIA statistics from the file pyxsec.root created by
454 // the function WriteXsection():
455 // integrated cross section (xsection) and
456 // the number of Pyevent() calls (ntrials)
457 // and calculate the weight per one event xsection/ntrials
458 // The spectrum calculated by a user should be
459 // multiplied by this weight, something like this:
460 // TH1F *userSpectrum ... // book and fill the spectrum
461 // userSpectrum->Scale(weight)
463 // Yuri Kharlov 19 June 2007
464 // Gustavo Conesa 15 April 2008
465 Double_t xsection = 0;
470 Int_t nfiles = tree->GetEntries() ;
471 if (tree && nfiles > 0) {
472 tree->SetBranchAddress("xsection",&xsection);
473 tree->SetBranchAddress("ntrials",&ntrials);
474 for(Int_t i = 0; i < nfiles; i++){
478 cout << "xsection " <<xsection<<" ntrials "<<ntrials<<endl;
483 cout << "-----------------------------------------------------------------"<<endl;
484 cout << "Average of "<< nfiles<<" files: xsection " <<xs<<" ntrials "<<ntr<<endl;
485 cout << "-----------------------------------------------------------------"<<endl;
487 else cout << " >>>> Empty tree !!!! <<<<< "<<endl;