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 = "/user/data/files/";
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";
29 const Bool_t kMC = kFALSE; //With real data kMC = kFALSE
30 const TString kInputData = "ESD"; //ESD, AOD, MC
31 TString kTreeName = "esdTree";
33 void ana(Int_t mode=mLocal)
37 //--------------------------------------------------------------------
38 // Load analysis libraries
39 // Look at the method below,
40 // change whatever you need for your analysis case
41 // ------------------------------------------------------------------
43 // TGeoManager::Import("geometry.root") ; //need file "geometry.root" in local dir!!!!
45 //-------------------------------------------------------------------------------------------------
46 //Create chain from ESD and from cross sections files, look below for options.
47 //-------------------------------------------------------------------------------------------------
48 if(kInputData == "ESD") kTreeName = "esdTree" ;
49 else if(kInputData == "AOD") kTreeName = "aodTree" ;
50 else if (kInputData == "MC") kTreeName = "TE" ;
52 cout<<"Wrong data type "<<kInputData<<endl;
56 TChain *chain = new TChain(kTreeName) ;
57 CreateChain(mode, chain);
60 AliLog::SetGlobalLogLevel(AliLog::kError);//Minimum prints on screen
62 //--------------------------------------
63 // Make the analysis manager
64 //-------------------------------------
65 AliAnalysisManager *mgr = new AliAnalysisManager("Manager", "Manager");
67 if((kMC || kInputData == "MC") && kInputData!="AOD"){
68 AliMCEventHandler* mcHandler = new AliMCEventHandler();
69 mcHandler->SetReadTR(kFALSE);//Do not search TrackRef file
70 mgr->SetMCtruthEventHandler(mcHandler);
71 if( kInputData == "MC") mgr->SetInputEventHandler(NULL);
75 if(kInputData == "ESD")
78 AliESDInputHandler *esdHandler = new AliESDInputHandler();
79 mgr->SetInputEventHandler(esdHandler);
80 cout<<"ESD handler "<<mgr->GetInputEventHandler()<<endl;
82 if(kInputData == "AOD"){
84 AliAODInputHandler *aodHandler = new AliAODInputHandler();
85 mgr->SetInputEventHandler(aodHandler);
86 cout<<"AOD handler "<<mgr->GetInputEventHandler()<<endl;
89 //mgr->SetDebugLevel(-1); // For debugging, do not uncomment if you want no messages.
91 // AOD output handler, needed for physics selection
92 cout<<"Init output handler"<<endl;
93 AliAODHandler* aodoutHandler = new AliAODHandler();
94 aodoutHandler->SetOutputFileName("aod.root");
95 ////aodoutHandler->SetCreateNonStandardAOD();
96 mgr->SetOutputEventHandler(aodoutHandler);
98 //-------------------------------------------------------------------------
99 //Define task, put here any other task that you want to use.
100 //-------------------------------------------------------------------------
102 TString outputFile = AliAnalysisManager::GetCommonFileName();
103 AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
105 if(kInputData=="ESD" && !kMC)
107 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
108 AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection();
111 //Counting events tasks
114 AliAnalysisTaskCounter * counterMB = new AliAnalysisTaskCounter("CounterMB");
115 counterMB->SelectCollisionCandidates(AliVEvent::kMB);
117 AliAnalysisDataContainer *coutputMB =
118 mgr->CreateContainer("counterMB", TList::Class(), AliAnalysisManager::kOutputContainer, outputFile.Data());
119 mgr->AddTask(counterMB);
120 mgr->ConnectInput (counterMB, 0, cinput1 );
121 mgr->ConnectOutput (counterMB, 1, coutputMB);
123 AliAnalysisTaskCounter * counterEMC = new AliAnalysisTaskCounter("CounterEMC");
124 counterEMC->SelectCollisionCandidates(AliVEvent::kEMC7);
126 AliAnalysisDataContainer *coutputEMC =
127 mgr->CreateContainer("counterEMC", TList::Class(), AliAnalysisManager::kOutputContainer, outputFile.Data());
128 mgr->AddTask(counterEMC);
129 mgr->ConnectInput (counterEMC, 0, cinput1 );
130 mgr->ConnectOutput (counterEMC, 1, coutputEMC);
132 AliAnalysisTaskCounter * counterINT = new AliAnalysisTaskCounter("CounterINT");
133 counterINT->SelectCollisionCandidates(AliVEvent::kINT7);
135 AliAnalysisDataContainer *coutputINT =
136 mgr->CreateContainer("counterINT7", TList::Class(), AliAnalysisManager::kOutputContainer, outputFile.Data());
137 mgr->AddTask(counterINT);
138 mgr->ConnectInput (counterINT, 0, cinput1 );
139 mgr->ConnectOutput (counterINT, 1, coutputINT);
143 AliAnalysisDataContainer *coutput =
144 mgr->CreateContainer("counter", TList::Class(), AliAnalysisManager::kOutputContainer, outputFile.Data());
145 mgr->AddTask(counter);
146 mgr->ConnectInput (counter, 0, cinput1);
147 mgr->ConnectOutput (counter, 1, coutput);
152 gROOT->LoadMacro("$ALICE_ROOT/PWGGA/CaloTrackCorrelations/macros/QA/AddTaskCalorimeterQA.C");
155 AliAnalysisTaskCaloTrackCorrelation *taskQAEMC = AddTaskCalorimeterQA("EMC",kMC,"",2012);
156 taskQAEMC->SelectCollisionCandidates(AliVEvent::kEMC7);
157 AliAnalysisTaskCaloTrackCorrelation *taskQAINT = AddTaskCalorimeterQA("default",kMC,"",2012);
158 taskQAINT->SelectCollisionCandidates(AliVEvent::kINT7);
162 AliAnalysisTaskCaloTrackCorrelation *taskQA = AddTaskCalorimeterQA("default",kMC,"",2012);
165 //-----------------------
167 //-----------------------
169 if (mode==mLocal || mode == mLocalCAF)
171 else if (mode==mPROOF)
173 else if (mode==mGRID)
178 mgr->StartAnalysis(smode.Data(),chain);
180 cout <<" Analysis ended sucessfully "<< endl ;
183 else cout << "Chain was not produced ! "<<endl;
187 void LoadLibraries(const anaModes mode) {
189 //--------------------------------------
190 // Load the needed libraries most of them already loaded by aliroot
191 //--------------------------------------
192 gSystem->Load("libTree");
193 gSystem->Load("libGeom");
194 gSystem->Load("libVMC");
195 gSystem->Load("libXMLIO");
196 gSystem->Load("libMatrix");
197 gSystem->Load("libPhysics");
198 //----------------------------------------------------------
199 // >>>>>>>>>>> Local mode <<<<<<<<<<<<<<
200 //----------------------------------------------------------
201 if (mode==mLocal || mode == mLocalCAF || mode == mGRID) {
202 //--------------------------------------------------------
203 // If you want to use already compiled libraries
204 // in the aliroot distribution
205 //--------------------------------------------------------
207 gSystem->Load("libSTEERBase");
208 gSystem->Load("libProof");
209 gSystem->Load("libOADB");
210 gSystem->Load("libESD");
211 gSystem->Load("libAOD");
212 gSystem->Load("libANALYSIS");
213 gSystem->Load("libANALYSISalice");
214 gSystem->Load("libESDfilter");
216 gSystem->Load("libPHOSUtils");
217 gSystem->Load("libEMCALUtils");
219 gSystem->Load("libTender");
220 gSystem->Load("libTenderSupplies");
222 gSystem->Load("libCORRFW");
223 gSystem->Load("libPWGTools");
225 gSystem->Load("libPWGCaloTrackCorrBase");
226 gSystem->Load("libPWGGACaloTrackCorrelations");
229 //--------------------------------------------------------
230 //If you want to use root and par files from aliroot
231 //--------------------------------------------------------
232 // SetupPar("STEERBase");
235 // SetupPar("ANALYSIS");
236 // SetupPar("ANALYSISalice");
237 // //If your analysis needs PHOS geometry uncomment following lines
238 // SetupPar("PHOSUtils");
239 // SetupPar("EMCALUtils");
241 // SetupPar("PWGCaloTrackCorrBase");
242 // SetupPar("PWGGACaloTrackCorrelations");
247 //---------------------------------------------------------
248 // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
249 //---------------------------------------------------------
250 else if (mode==mPROOF) {
253 // Put appropriate username here
254 // TProof::Reset("proof://mgheata@lxb6046.cern.ch");
255 TProof::Open("proof://mgheata@lxb6046.cern.ch");
257 // gProof->ClearPackages();
258 // gProof->ClearPackage("ESD");
259 // gProof->ClearPackage("AOD");
260 // gProof->ClearPackage("ANALYSIS");
261 // gProof->ClearPackage("PWG4PartCorrBase");
262 // gProof->ClearPackage("PWG4PartCorrDep");
264 // Enable the STEERBase Package
265 gProof->UploadPackage("STEERBase.par");
266 gProof->EnablePackage("STEERBase");
267 // Enable the ESD Package
268 gProof->UploadPackage("ESD.par");
269 gProof->EnablePackage("ESD");
270 // Enable the AOD Package
271 gProof->UploadPackage("AOD.par");
272 gProof->EnablePackage("AOD");
273 // Enable the Analysis Package
274 gProof->UploadPackage("ANALYSIS.par");
275 gProof->EnablePackage("ANALYSIS");
276 // Enable the PHOS geometry Package
277 //gProof->UploadPackage("PHOSUtils.par");
278 //gProof->EnablePackage("PHOSUtils");
279 // Enable PartCorr analysis
280 gProof->UploadPackage("PWG4PartCorrBase.par");
281 gProof->EnablePackage("PWG4PartCorrBase");
282 gProof->UploadPackage("PWG4PartCorrDep.par");
283 gProof->EnablePackage("PWG4PartCorrDep");
284 gProof->ShowEnabledPackages();
289 void SetupPar(char* pararchivename)
291 //Load par files, create analysis libraries
292 //For testing, if par file already decompressed and modified
293 //classes then do not decompress.
295 TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
296 TString parpar(Form("%s.par", pararchivename)) ;
297 if ( gSystem->AccessPathName(parpar.Data()) ) {
298 gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
299 TString processline(Form(".! make %s", parpar.Data())) ;
300 gROOT->ProcessLine(processline.Data()) ;
301 gSystem->ChangeDirectory(cdir) ;
302 processline = Form(".! mv $ALICE_ROOT/%s .", parpar.Data()) ;
303 gROOT->ProcessLine(processline.Data()) ;
305 if ( gSystem->AccessPathName(pararchivename) ) {
306 TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
307 gROOT->ProcessLine(processline.Data());
310 TString ocwd = gSystem->WorkingDirectory();
311 gSystem->ChangeDirectory(pararchivename);
313 // check for BUILD.sh and execute
314 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
315 printf("*******************************\n");
316 printf("*** Building PAR archive ***\n");
317 cout<<pararchivename<<endl;
318 printf("*******************************\n");
320 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
321 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
325 // check for SETUP.C and execute
326 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
327 printf("*******************************\n");
328 printf("*** Setup PAR archive ***\n");
329 cout<<pararchivename<<endl;
330 printf("*******************************\n");
331 gROOT->Macro("PROOF-INF/SETUP.C");
334 gSystem->ChangeDirectory(ocwd.Data());
335 printf("Current dir: %s\n", ocwd.Data());
340 void CreateChain(const anaModes mode, TChain * chain){
341 //Fills chain with data
342 TString ocwd = gSystem->WorkingDirectory();
344 //-----------------------------------------------------------
345 //Analysis of CAF data locally and with PROOF
346 //-----------------------------------------------------------
347 if(mode ==mPROOF || mode ==mLocalCAF){
349 gROOT->LoadMacro("$ALICE_ROOT/PWG0/CreateESDChain.C");
350 // The second parameter is the number of input files in the chain
351 chain = CreateESDChain("ESD12001.txt", 5);
354 //---------------------------------------
355 //Local files analysis
356 //---------------------------------------
357 else if(mode == mLocal){
358 //If you want to add several ESD files sitting in a common directory INDIR
359 //Specify as environmental variables the directory (INDIR), the number of files
360 //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
362 if(gSystem->Getenv("INDIR"))
363 kInDir = gSystem->Getenv("INDIR") ;
364 else cout<<"INDIR not set, use default: "<<kInDir<<endl;
366 if(gSystem->Getenv("PATTERN"))
367 kPattern = gSystem->Getenv("PATTERN") ;
368 else cout<<"PATTERN not set, use default: "<<kPattern<<endl;
370 if(gSystem->Getenv("NFILES"))
371 kFile = atoi(gSystem->Getenv("NFILES")) ;
372 else cout<<"NFILES not set, use default: "<<kFile<<endl;
374 //Check if env variables are set and are correct
375 if ( kInDir && kFile) {
376 printf("Get %d files from directory %s\n",kFile,kInDir);
377 if ( ! gSystem->cd(kInDir) ) {//check if ESDs directory exist
378 printf("%s does not exist\n", kInDir) ;
382 cout<<"INDIR : "<<kInDir<<endl;
383 cout<<"NFILES : "<<kFile<<endl;
384 cout<<"PATTERN : " <<kPattern<<endl;
387 if(kInputData == "ESD") datafile = "AliESDs.root" ;
388 else if(kInputData == "AOD") datafile = "AliAOD.root" ;
390 //Loop on ESD files, add them to chain
395 for (event = 0 ; event < kFile ; event++) {
396 sprintf(file, "%s/%s%d/%s", kInDir,kPattern,event,datafile.Data()) ;
398 //Check if file exists and add it, if not skip it
399 if ( fESD = TFile::Open(file)) {
400 if ( fESD->Get(kTreeName) ) {
401 printf("++++ Adding %s\n", file) ;
402 chain->AddFile(file);
406 printf("---- Skipping %s\n", file) ;
410 printf("number of entries # %lld, skipped %d\n", chain->GetEntries(), skipped*100) ;
413 TString input = "AliESDs.root" ;
414 cout<<">>>>>> No list added, take a single file <<<<<<<<< "<<input<<endl;
415 chain->AddFile(input);
418 }// local files analysis
420 //------------------------------
422 //-----------------------------
423 else if(mode == mGRID){
424 //Get colection file. It is specified by the environmental
427 if(gSystem->Getenv("XML") )
428 kXML = gSystem->Getenv("XML");
430 sprintf(kXML, "collection.xml") ;
432 if (!TFile::Open(kXML)) {
433 printf("No collection file with name -- %s -- was found\n",kXML);
436 else cout<<"XML file "<<kXML<<endl;
438 //Load necessary libraries and connect to the GRID
439 gSystem->Load("libNetx") ;
440 gSystem->Load("libRAliEn");
441 TGrid::Connect("alien://") ;
443 //Feed Grid with collection file
444 TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
446 AliError(Form("%s not found", kXML)) ;
449 TGridResult* result = collection->GetGridResult("",0 ,0);
451 // Makes the ESD chain
452 printf("*** Getting the Chain ***\n");
453 for (Int_t index = 0; index < result->GetEntries(); index++) {
454 TString alienURL = result->GetKey(index, "turl") ;
455 cout << "================== " << alienURL << endl ;
456 chain->Add(alienURL) ;
460 gSystem->ChangeDirectory(ocwd.Data());