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, NEVENT, respectivelly
22 char * kInDir = "/home/blau/data";
23 char * kPattern = ""; // Data are in diles /data/Run0,
24 Int_t kEvent = 3; // 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 //const Int_t kNumberOfEventsPerFile = 100;
36 //---------------------------------------------------------------------------
38 const Bool_t kMC = kTRUE; //With real data kMC = kFALSE
39 const TString kInputData = "ESD";//ESD, AOD, MC
40 TString kTreeName = "esdTree";
42 void anaPhotonTagging(Int_t mode=mGRID, TString configName = "ConfigAnalysisPhoton")
46 //--------------------------------------------------------------------
47 // Load analysis libraries
48 // Look at the method below,
49 // change whatever you need for your analysis case
50 // ------------------------------------------------------------------
53 //-------------------------------------------------------------------------------------------------
54 //Create chain from ESD and from cross sections files, look below for options.
55 //-------------------------------------------------------------------------------------------------
56 if(kInputData == "ESD") kTreeName = "esdTree" ;
57 else if(kInputData == "AOD") kTreeName = "aodTree" ;
58 else if (kInputData == "MC") kTreeName = "TE" ;
60 cout<<"Wrong data type "<<kInputData<<endl;
64 TChain *chain = new TChain(kTreeName) ;
65 TChain * chainxs = new TChain("Xsection") ;
66 CreateChain(mode, chain, chainxs);
69 AliLog::SetGlobalLogLevel(AliLog::kError);//Minimum prints on screen
71 //--------------------------------------
72 // Make the analysis manager
73 //-------------------------------------
74 AliAnalysisManager *mgr = new AliAnalysisManager("Manager", "Manager");
76 if(kMC || kInputData == "MC"){
77 AliMCEventHandler* mcHandler = new AliMCEventHandler();
78 mcHandler->SetReadTR(kFALSE);//Do not search TrackRef file
79 mgr->SetMCtruthEventHandler(mcHandler);
83 AliAODHandler* aodoutHandler = new AliAODHandler();
84 aodoutHandler->SetOutputFileName("aod.root");
85 //aodoutHandler->SetCreateNonStandardAOD();
86 mgr->SetOutputEventHandler(aodoutHandler);
89 if(kInputData == "ESD"){
91 AliESDInputHandler *esdHandler = new AliESDInputHandler();
92 mgr->SetInputEventHandler(esdHandler);
94 if(kInputData == "AOD"){
96 AliAODInputHandler *aodHandler = new AliAODInputHandler();
97 mgr->SetInputEventHandler(aodHandler);
100 //mgr->SetDebugLevel(-1); // For debugging, do not uncomment if you want no messages.
102 //-------------------------------------------------------------------------
103 //Define task, put here any other task that you want to use.
104 //-------------------------------------------------------------------------
105 // AliAnaPi0Conv * task = new AliAnaPi0Conv("Pi0") ;
107 AliAnalysisTaskTaggedPhotons * taskPHOS = new AliAnalysisTaskTaggedPhotons("TaggedPHOS");
108 taskPHOS->SetPHOS(kTRUE);
109 mgr->AddTask(taskPHOS);
111 AliAnalysisTaskTaggedPhotons * taskEMCAL = new AliAnalysisTaskTaggedPhotons("TaggedEMCAL");
112 taskEMCAL->SetPHOS(kFALSE);
113 mgr->AddTask(taskEMCAL);
116 // Create containers for input/output
117 AliAnalysisDataContainer *cinput1 = mgr->CreateContainer("cchain",TChain::Class(),
118 AliAnalysisManager::kInputContainer);
119 AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("tree", TTree::Class(),
120 AliAnalysisManager::kOutputContainer, "default");
121 AliAnalysisDataContainer *coutput2 = mgr->CreateContainer("histosP", TList::Class(),
122 AliAnalysisManager::kOutputContainer, "histosPHOS.root");
123 AliAnalysisDataContainer *coutput3 = mgr->CreateContainer("histosE", TList::Class(),
124 AliAnalysisManager::kOutputContainer, "histosEMCAL.root");
126 mgr->ConnectInput (taskPHOS, 0, cinput1);
127 mgr->ConnectOutput (taskPHOS, 0, coutput1 );
128 mgr->ConnectOutput (taskPHOS, 1, coutput2 );
129 mgr->ConnectInput (taskEMCAL, 0, cinput1);
130 mgr->ConnectOutput (taskEMCAL, 0, coutput1 );
131 mgr->ConnectOutput (taskEMCAL, 1, coutput3 );
135 //-----------------------
137 //-----------------------
139 if (mode==mLocal || mode == mLocalCAF)
141 else if (mode==mPROOF)
143 else if (mode==mGRID)
148 mgr->StartAnalysis("local",chain);
149 // mgr->StartAnalysis(smode.Data(),chain);
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("libSTEERBase");
177 //gSystem->Load("libESD");
178 //gSystem->Load("libAOD");
179 //gSystem->Load("libANALYSIS");
180 //gSystem->Load("libANALYSISalice");
181 //gSystem->Load("libPHOSUtils");
182 //gSystem->Load("libPWG4PartCorrBase");
183 //gSystem->Load("libPWG4PartCorrDep");
185 //--------------------------------------------------------
186 //If you want to use root and par files from aliroot
187 //--------------------------------------------------------
188 SetupPar("STEERBase");
191 SetupPar("ANALYSIS");
192 SetupPar("ANALYSISalice");
193 //If your analysis needs PHOS geometry uncomment following lines
194 SetupPar("PHOSUtils");
196 TGeoManager::Import("geometry.root") ; //need file "geometry.root" in local dir!!!!
197 SetupPar("PWG4PartCorrBase");
198 SetupPar("PWG4PartCorrDep");
201 //---------------------------------------------------------
202 // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
203 //---------------------------------------------------------
204 else if (mode==mPROOF) {
207 // Put appropriate username here
208 // TProof::Reset("proof://mgheata@lxb6046.cern.ch");
209 TProof::Open("proof://mgheata@lxb6046.cern.ch");
211 // gProof->ClearPackages();
212 // gProof->ClearPackage("ESD");
213 // gProof->ClearPackage("AOD");
214 // gProof->ClearPackage("ANALYSIS");
215 // gProof->ClearPackage("PWG4PartCorrBase");
216 // gProof->ClearPackage("PWG4PartCorrDep");
218 // Enable the STEERBase Package
219 gProof->UploadPackage("STEERBase.par");
220 gProof->EnablePackage("STEERBase");
221 // Enable the ESD Package
222 gProof->UploadPackage("ESD.par");
223 gProof->EnablePackage("ESD");
224 // Enable the AOD Package
225 gProof->UploadPackage("AOD.par");
226 gProof->EnablePackage("AOD");
227 // Enable the Analysis Package
228 gProof->UploadPackage("ANALYSIS.par");
229 gProof->EnablePackage("ANALYSIS");
230 // Enable the PHOS geometry Package
231 //gProof->UploadPackage("PHOSUtils.par");
232 //gProof->EnablePackage("PHOSUtils");
233 // Enable PartCorr analysis
234 gProof->UploadPackage("PWG4PartCorrBase.par");
235 gProof->EnablePackage("PWG4PartCorrBase");
236 gProof->UploadPackage("PWG4PartCorrDep.par");
237 gProof->EnablePackage("PWG4PartCorrDep");
238 gProof->ShowEnabledPackages();
243 void SetupPar(char* pararchivename)
245 //Load par files, create analysis libraries
246 //For testing, if par file already decompressed and modified
247 //classes then do not decompress.
249 TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
250 TString parpar(Form("%s.par", pararchivename)) ;
251 if ( gSystem->AccessPathName(parpar.Data()) ) {
252 gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
253 TString processline(Form(".! make %s", parpar.Data())) ;
254 gROOT->ProcessLine(processline.Data()) ;
255 gSystem->ChangeDirectory(cdir) ;
256 processline = Form(".! mv $ALICE_ROOT/%s .", parpar.Data()) ;
257 gROOT->ProcessLine(processline.Data()) ;
259 if ( gSystem->AccessPathName(pararchivename) ) {
260 TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
261 gROOT->ProcessLine(processline.Data());
264 TString ocwd = gSystem->WorkingDirectory();
265 gSystem->ChangeDirectory(pararchivename);
267 // check for BUILD.sh and execute
268 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
269 printf("*******************************\n");
270 printf("*** Building PAR archive ***\n");
271 cout<<pararchivename<<endl;
272 printf("*******************************\n");
274 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
275 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
279 // check for SETUP.C and execute
280 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
281 printf("*******************************\n");
282 printf("*** Setup PAR archive ***\n");
283 cout<<pararchivename<<endl;
284 printf("*******************************\n");
285 gROOT->Macro("PROOF-INF/SETUP.C");
288 gSystem->ChangeDirectory(ocwd.Data());
289 printf("Current dir: %s\n", ocwd.Data());
294 void CreateChain(const anaModes mode, TChain * chain, TChain * chainxs){
295 //Fills chain with data
296 TString ocwd = gSystem->WorkingDirectory();
298 //-----------------------------------------------------------
299 //Analysis of CAF data locally and with PROOF
300 //-----------------------------------------------------------
301 if(mode ==mPROOF || mode ==mLocalCAF){
303 gROOT->LoadMacro("$ALICE_ROOT/PWG0/CreateESDChain.C");
304 // The second parameter is the number of input files in the chain
305 chain = CreateESDChain("ESD12001.txt", 5);
308 //---------------------------------------
309 //Local files analysis
310 //---------------------------------------
311 else if(mode == mLocal){
312 //If you want to add several ESD files sitting in a common directory INDIR
313 //Specify as environmental variables the directory (INDIR), the number of files
314 //to analyze (NEVENT) and the pattern name of the directories with files (PATTERN)
316 if(gSystem->Getenv("INDIR"))
317 kInDir = gSystem->Getenv("INDIR") ;
318 else cout<<"INDIR not set, use default: "<<kInDir<<endl;
320 if(gSystem->Getenv("PATTERN"))
321 kPattern = gSystem->Getenv("PATTERN") ;
322 else cout<<"PATTERN not set, use default: "<<kPattern<<endl;
324 if(gSystem->Getenv("NEVENT"))
325 kEvent = atoi(gSystem->Getenv("NEVENT")) ;
326 else cout<<"NEVENT not set, use default: "<<kEvent<<endl;
328 //Check if env variables are set and are correct
329 if ( kInDir && kEvent) {
330 printf("Get %d files from directory %s\n",kEvent,kInDir);
331 if ( ! gSystem->cd(kInDir) ) {//check if ESDs directory exist
332 printf("%s does not exist\n", kInDir) ;
335 cout<<"INDIR : "<<kInDir<<endl;
336 cout<<"NEVENT : "<<kEvent<<endl;
337 cout<<"PATTERN: " <<kPattern<<endl;
340 if(kInputData == "ESD") datafile = "AliESDs.root" ;
341 else if(kInputData == "AOD") datafile = "aod.root" ;
342 else if(kInputData == "MC") datafile = "galice.root" ;
344 //Loop on ESD files, add them to chain
350 for (event = 0 ; event < kEvent ; event++) {
351 sprintf(file, "%s/%s%d/%s", kInDir,kPattern,event,datafile.Data()) ;
352 sprintf(filexs, "%s/%s%d/%s", kInDir,kPattern,event,kXSFileName) ;
354 //Check if file exists and add it, if not skip it
355 if ( fESD = TFile::Open(file)) {
356 if ( fESD->Get(kTreeName) ) {
357 printf("++++ Adding %s\n", file) ;
358 chain->AddFile(file);
359 chainxs->Add(filexs) ;
363 printf("---- Skipping %s\n", file) ;
367 printf("number of entries # %lld, skipped %d\n", chain->GetEntries(), skipped*100) ;
370 TString input = "AliESDs.root" ;
371 cout<<">>>>>> No list added, take a single file <<<<<<<<< "<<input<<endl;
372 chain->AddFile(input);
375 }// local files analysis
377 //------------------------------
379 //-----------------------------
380 else if(mode == mGRID){
381 //Get colection file. It is specified by the environmental
384 if(gSystem->Getenv("XML") )
385 kXML = gSystem->Getenv("XML");
387 sprintf(kXML, "collection.xml") ;
389 if (!TFile::Open(kXML)) {
390 printf("No collection file with name -- %s -- was found\n",kXML);
393 else cout<<"XML file "<<kXML<<endl;
395 //Load necessary libraries and connect to the GRID
396 gSystem->Load("libNetx.so") ;
397 gSystem->Load("libRAliEn.so");
398 TGrid::Connect("alien://") ;
400 //Feed Grid with collection file
401 //TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\", 0)", kXML));
402 TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
404 AliError(Form("%s not found", kXML)) ;
407 TGridResult* result = collection->GetGridResult("",0 ,0);
409 // Makes the ESD chain
410 printf("*** Getting the Chain ***\n");
411 for (Int_t index = 0; index < result->GetEntries(); index++) {
412 TString alienURL = result->GetKey(index, "turl") ;
413 cout << "================== " << alienURL << endl ;
414 chain->Add(alienURL) ;
415 alienURL.ReplaceAll("AliESDs.root",kXSFileName);
416 chainxs->Add(alienURL) ;
420 gSystem->ChangeDirectory(ocwd.Data());
423 //________________________________________________
424 void GetAverageXsection(TTree * tree, Double_t & xs, Float_t & ntr)
426 // Read the PYTHIA statistics from the file pyxsec.root created by
427 // the function WriteXsection():
428 // integrated cross section (xsection) and
429 // the number of Pyevent() calls (ntrials)
430 // and calculate the weight per one event xsection/ntrials
431 // The spectrum calculated by a user should be
432 // multiplied by this weight, something like this:
433 // TH1F *userSpectrum ... // book and fill the spectrum
434 // userSpectrum->Scale(weight)
436 // Yuri Kharlov 19 June 2007
437 // Gustavo Conesa 15 April 2008
438 Double_t xsection = 0;
443 Int_t nfiles = tree->GetEntries() ;
444 if (tree && nfiles > 0) {
445 tree->SetBranchAddress("xsection",&xsection);
446 tree->SetBranchAddress("ntrials",&ntrials);
447 for(Int_t i = 0; i < nfiles; i++){
451 cout << "xsection " <<xsection<<" ntrials "<<ntrials<<endl;
456 cout << "-----------------------------------------------------------------"<<endl;
457 cout << "Average of "<< nfiles<<" files: xsection " <<xs<<" ntrials "<<ntr<<endl;
458 cout << "-----------------------------------------------------------------"<<endl;
460 else cout << " >>>> Empty tree !!!! <<<<< "<<endl;