AliPhysics  master (3d17d9d)
anaQA.C
Go to the documentation of this file.
1 
14 #if !defined(__CINT__) || defined(__MAKECINT__)
15 
16 #include "Riostream.h"
17 #include "TString.h"
18 #include "TFile.h"
19 #include "TChain.h"
20 #include "TROOT.h"
21 #include "TSystem.h"
22 #include "TApplication.h"
23 
24 #include "TGrid.h"
25 #include "TGridCollection.h"
26 #include "TGridResult.h"
27 #include "AliLog.h"
28 
29 #include "AliAnalysisGrid.h"
30 #include "AliAnalysisManager.h"
31 #include "AliMCEventHandler.h"
32 #include "AliAnalysisTaskSE.h"
33 #include "AliESDEvent.h"
34 #include "AliAODEvent.h"
35 #include "AliESDInputHandler.h"
36 #include "AliAODInputHandler.h"
37 #include "AliAODHandler.h"
38 #include "AliPhysicsSelection.h"
39 #include "AliPhysicsSelectionTask.h"
40 #include "AliMultiInputEventHandler.h"
42 #include "AliAnalysisTaskCounter.h"
43 #include "AliAnalysisDataContainer.h"
44 #include "TSystemDirectory.h"
45 #include "CreateESDChain.C"
46 #include "AddTaskPhysicsSelection.C"
47 #include "AddTaskCalorimeterQA.C"
48 
49 #endif
50 
51 //---------------------------------------------------------------------------
54 {
55  mLocal = 0,
56  mPROOF = 1,
57  mPlugin = 2,
58  mGRID = 3,
60 };
61 
62 //---------------------------------------------------------------------------
63 // Settings to read locally several files, only for "mLocal" mode
64 // The different values are default, they can be set with environmental
65 // variables: INDIR, PATTERN, NFILES, respectivelly
66 
67 char * kInDir = (char*)"/user/data/files/";
68 char * kPattern = (char*)"";
69 Int_t kFile = 2;
70 
71 //---------------------------------------------------------------------------
72 // Collection file for grid analysis
73 
74 char * kXML = (char*)"collection.xml";
75 
76 const Bool_t kMC = kFALSE;
77 const TString kInputData = "ESD";
78 TString kTreeName = "esdTree";
79 
80 
81 //---------------------------------------------------------------------------
82 // Declare methods written after main
83 void LoadLibraries();
84 void SetupPar(char* pararchivename);
85 void CreateChain(const Int_t mode, TChain * chain);
86 
87 //___________________________
97 //___________________________
99 {
100  // Main
101 
102  //--------------------------------------------------------------------
103  // Load analysis libraries
104  // Look at the method below,
105  // change whatever you need for your analysis case
106  // ------------------------------------------------------------------
107  LoadLibraries() ;
108 
109  //-------------------------------------------------------------------------------------------------
110  // Create chain from ESD and from cross sections files, look below for options.
111  //-------------------------------------------------------------------------------------------------
112  if (kInputData == "ESD") kTreeName = "esdTree" ;
113  else if (kInputData == "AOD") kTreeName = "aodTree" ;
114  else if (kInputData == "MC" ) kTreeName = "TE" ;
115  else
116  {
117  cout<<"Wrong data type "<<kInputData<<endl;
118  return;
119  }
120 
121  TChain *chain = new TChain(kTreeName) ;
122  CreateChain(mode, chain);
123 
124  if(chain)
125  {
126  AliLog::SetGlobalLogLevel(AliLog::kError);//Minimum prints on screen
127 
128  //--------------------------------------
129  // Make the analysis manager
130  //-------------------------------------
131  AliAnalysisManager *mgr = new AliAnalysisManager("Manager", "Manager");
132  // MC handler
133  if((kMC || kInputData == "MC") && kInputData!="AOD"){
134  AliMCEventHandler* mcHandler = new AliMCEventHandler();
135  mcHandler->SetReadTR(kFALSE);//Do not search TrackRef file
136  mgr->SetMCtruthEventHandler(mcHandler);
137  if( kInputData == "MC") mgr->SetInputEventHandler(NULL);
138  }
139 
140  //input
141  if(kInputData == "ESD")
142  {
143  // ESD handler
144  AliESDInputHandler *esdHandler = new AliESDInputHandler();
145  mgr->SetInputEventHandler(esdHandler);
146  cout<<"ESD handler "<<mgr->GetInputEventHandler()<<endl;
147  }
148  if(kInputData == "AOD")
149  {
150  // AOD handler
151  AliAODInputHandler *aodHandler = new AliAODInputHandler();
152  mgr->SetInputEventHandler(aodHandler);
153  cout<<"AOD handler "<<mgr->GetInputEventHandler()<<endl;
154  }
155 
156  //mgr->SetDebugLevel(-1); // For debugging, do not uncomment if you want no messages.
157 
158  // AOD output handler, needed for physics selection
159  cout<<"Init output handler"<<endl;
160  AliAODHandler* aodoutHandler = new AliAODHandler();
161  aodoutHandler->SetOutputFileName("aod.root");
163  mgr->SetOutputEventHandler(aodoutHandler);
164 
165  //-------------------------------------------------------------------------
166  // Define task, put here any other task that you want to use.
167  //-------------------------------------------------------------------------
168 
169  TString outputFile = AliAnalysisManager::GetCommonFileName();
170  AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
171 
172  if(kInputData=="ESD" && !kMC)
173  {
174  gROOT->LoadMacro("$ALICE_PHYSICS/OADB/macros/AddTaskPhysicsSelection.C");
175  AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection();
176  }
177 
178  // Counting events tasks
179  if(!kMC)
180  {
181  AliAnalysisTaskCounter * counterMB = new AliAnalysisTaskCounter("CounterMB");
182  counterMB->SelectCollisionCandidates(AliVEvent::kMB);
183 
184  AliAnalysisDataContainer *coutputMB =
185  mgr->CreateContainer("counterMB", TList::Class(), AliAnalysisManager::kOutputContainer, outputFile.Data());
186  mgr->AddTask(counterMB);
187  mgr->ConnectInput (counterMB, 0, cinput1 );
188  mgr->ConnectOutput (counterMB, 1, coutputMB);
189 
190  AliAnalysisTaskCounter * counterEMC = new AliAnalysisTaskCounter("CounterEMC");
191  counterEMC->SelectCollisionCandidates(AliVEvent::kEMC7);
192 
193  AliAnalysisDataContainer *coutputEMC =
194  mgr->CreateContainer("counterEMC", TList::Class(), AliAnalysisManager::kOutputContainer, outputFile.Data());
195  mgr->AddTask(counterEMC);
196  mgr->ConnectInput (counterEMC, 0, cinput1 );
197  mgr->ConnectOutput (counterEMC, 1, coutputEMC);
198 
199  AliAnalysisTaskCounter * counterINT = new AliAnalysisTaskCounter("CounterINT");
200  counterINT->SelectCollisionCandidates(AliVEvent::kINT7);
201 
202  AliAnalysisDataContainer *coutputINT =
203  mgr->CreateContainer("counterINT7", TList::Class(), AliAnalysisManager::kOutputContainer, outputFile.Data());
204  mgr->AddTask(counterINT);
205  mgr->ConnectInput (counterINT, 0, cinput1 );
206  mgr->ConnectOutput (counterINT, 1, coutputINT);
207  }
208  else
209  {
210  AliAnalysisTaskCounter * counter = new AliAnalysisTaskCounter("CounterAny");
211  counter->SelectCollisionCandidates(AliVEvent::kAny);
212 
213  AliAnalysisDataContainer *coutput =
214  mgr->CreateContainer("counter", TList::Class(), AliAnalysisManager::kOutputContainer, outputFile.Data());
215  mgr->AddTask(counter);
216  mgr->ConnectInput (counter, 0, cinput1);
217  mgr->ConnectOutput (counter, 1, coutput);
218  }
219 
220  // QA task
221 
222  gROOT->LoadMacro("$ALICE_PHYSICS/PWGGA/CaloTrackCorrelations/macros/QA/AddTaskCalorimeterQA.C");
223  if(!kMC)
224  {
226  taskQAEMC->SelectCollisionCandidates(AliVEvent::kEMC7);
227  AliAnalysisTaskCaloTrackCorrelation *taskQAINT = AddTaskCalorimeterQA("default",kMC,"",2012);
228  taskQAINT->SelectCollisionCandidates(AliVEvent::kINT7);
229  }
230  else
231  {
232  AliAnalysisTaskCaloTrackCorrelation *taskQA = AddTaskCalorimeterQA("default",kMC,"",2012);
233  }
234 
235  //-----------------------
236  // Run the analysis
237  //-----------------------
238  TString smode = "";
239  if (mode==mLocal || mode == mLocalCAF)
240  smode = "local";
241  else if (mode==mPROOF)
242  smode = "proof";
243  else if (mode==mGRID)
244  smode = "local";
245 
246  mgr->InitAnalysis();
247  mgr->PrintStatus();
248  mgr->StartAnalysis(smode.Data(),chain);
249 
250  cout <<" Analysis ended sucessfully "<< endl ;
251 
252  }
253  else cout << "Chain was not produced ! "<<endl;
254 
255 }
256 
257 //_____________________________
260 //_____________________________
262 {
263 // gSystem->Load("libPWGCaloTrackCorrBase");
264 // gSystem->Load("libPWGGACaloTrackCorrelations");
265 
266 // SetupPar("PWGCaloTrackCorrBase");
267 // SetupPar("PWGGACaloTrackCorrelations");
268 }
269 
270 //_________________________________
274 //_________________________________
275 void SetupPar(char* pararchivename)
276 {
277  TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
278 
279  TString parpar(Form("%s.par", pararchivename)) ;
280 
281  if ( gSystem->AccessPathName(parpar.Data()) )
282  {
283  gSystem->ChangeDirectory(gSystem->Getenv("ALICE_PHYSICS")) ;
284  TString processline(Form(".! make %s", parpar.Data())) ;
285  gROOT->ProcessLine(processline.Data()) ;
286  gSystem->ChangeDirectory(cdir) ;
287  processline = Form(".! mv $ALICE_PHYSICS/%s .", parpar.Data()) ;
288  gROOT->ProcessLine(processline.Data()) ;
289  }
290 
291  if ( gSystem->AccessPathName(pararchivename) )
292  {
293  TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
294  gROOT->ProcessLine(processline.Data());
295  }
296 
297  TString ocwd = gSystem->WorkingDirectory();
298  gSystem->ChangeDirectory(pararchivename);
299 
300  // check for BUILD.sh and execute
301  if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh"))
302  {
303  printf("*******************************\n");
304  printf("*** Building PAR archive ***\n");
305  cout<<pararchivename<<endl;
306  printf("*******************************\n");
307 
308  if (gSystem->Exec("PROOF-INF/BUILD.sh"))
309  {
310  Error("runProcess","Cannot Build the PAR Archive! - Abort!");
311  return ;
312  }
313  }
314  // check for SETUP.C and execute
315  if (!gSystem->AccessPathName("PROOF-INF/SETUP.C"))
316  {
317  printf("*******************************\n");
318  printf("*** Setup PAR archive ***\n");
319  cout<<pararchivename<<endl;
320  printf("*******************************\n");
321  gROOT->Macro("PROOF-INF/SETUP.C");
322  }
323 
324  gSystem->ChangeDirectory(ocwd.Data());
325  printf("Current dir: %s\n", ocwd.Data());
326 }
327 
328 //_____________________________________________________________________
330 //_____________________________________________________________________
331 void CreateChain(const Int_t mode, TChain * chain)
332 {
333  TString ocwd = gSystem->WorkingDirectory();
334 
335  //-----------------------------------------------------------
336  // Analysis of CAF data locally and with PROOF
337  //-----------------------------------------------------------
338  if(mode ==mPROOF || mode ==mLocalCAF)
339  {
340  // Chain from CAF
341  gROOT->LoadMacro("$ALICE_PHYSICS/PWG/EMCAL/CreateESDChain.C");
342  // The second parameter is the number of input files in the chain
343  chain = CreateESDChain("ESD12001.txt", 5);
344  }
345 
346  //---------------------------------------
347  // Local files analysis
348  //---------------------------------------
349  else if(mode == mLocal)
350  {
351  //If you want to add several ESD files sitting in a common directory INDIR
352  //Specify as environmental variables the directory (INDIR), the number of files
353  //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
354 
355  if(gSystem->Getenv("INDIR"))
356  kInDir = (char*)gSystem->Getenv("INDIR") ;
357  else cout<<"INDIR not set, use default: "<<kInDir<<endl;
358 
359  if(gSystem->Getenv("PATTERN"))
360  kPattern = (char*)gSystem->Getenv("PATTERN") ;
361  else cout<<"PATTERN not set, use default: "<<kPattern<<endl;
362 
363  if(gSystem->Getenv("NFILES"))
364  kFile = atoi(gSystem->Getenv("NFILES")) ;
365  else cout<<"NFILES not set, use default: "<<kFile<<endl;
366 
367  //Check if env variables are set and are correct
368  if ( kInDir && kFile) {
369  printf("Get %d files from directory %s\n",kFile,kInDir);
370  if ( ! gSystem->cd(kInDir) ) {//check if ESDs directory exist
371  printf("%s does not exist\n", kInDir) ;
372  return ;
373  }
374 
375  cout<<"INDIR : "<<kInDir<<endl;
376  cout<<"NFILES : "<<kFile<<endl;
377  cout<<"PATTERN : " <<kPattern<<endl;
378 
379  TString datafile="";
380  if(kInputData == "ESD") datafile = "AliESDs.root" ;
381  else if(kInputData == "AOD") datafile = "AliAOD.root" ;
382 
383  //Loop on ESD files, add them to chain
384  Int_t event =0;
385  Int_t skipped=0 ;
386  char file[120] ;
387 
388  for (event = 0 ; event < kFile ; event++) {
389  sprintf(file, "%s/%s%d/%s", kInDir,kPattern,event,datafile.Data()) ;
390  TFile * fESD = TFile::Open(file) ;
391  //Check if file exists and add it, if not skip it
392  if ( fESD ) {
393  if ( fESD->Get(kTreeName) ) {
394  printf("++++ Adding %s\n", file) ;
395  chain->AddFile(file);
396  }
397  }
398  else {
399  printf("---- Skipping %s\n", file) ;
400  skipped++ ;
401  }
402  }
403  printf("number of entries # %lld, skipped %d\n", chain->GetEntries(), skipped*100) ;
404  }
405  else {
406  TString input = "AliESDs.root" ;
407  cout<<">>>>>> No list added, take a single file <<<<<<<<< "<<input<<endl;
408  chain->AddFile(input);
409  }
410 
411  }// local files analysis
412 
413  //------------------------------
414  //GRID xml files
415  //-----------------------------
416  else if(mode == mGRID){
417  //Get colection file. It is specified by the environmental
418  //variable XML
419 
420  if(gSystem->Getenv("XML") )
421  kXML = (char*) gSystem->Getenv("XML");
422  else
423  sprintf(kXML, "collection.xml") ;
424 
425  if (!TFile::Open(kXML)) {
426  printf("No collection file with name -- %s -- was found\n",kXML);
427  return ;
428  }
429  else cout<<"XML file "<<kXML<<endl;
430 
431  //Load necessary libraries and connect to the GRID
432  gSystem->Load("libNetx") ;
433  gSystem->Load("libRAliEn");
434  TGrid::Connect("alien://") ;
435 
436  //Feed Grid with collection file
437  TGridCollection * collection = gGrid->OpenCollection(kXML);
438  if (! collection) {
439  printf("%s not found\n", kXML) ;
440  return ;
441  }
442  TGridResult* result = collection->GetGridResult("",0 ,0);
443 
444  // Makes the ESD chain
445  printf("*** Getting the Chain ***\n");
446  for (Int_t index = 0; index < result->GetEntries(); index++) {
447  TString alienURL = result->GetKey(index, "turl") ;
448  cout << "================== " << alienURL << endl ;
449  chain->Add(alienURL) ;
450  }
451  }// xml analysis
452 
453  gSystem->ChangeDirectory(ocwd.Data());
454 }
455 
anaModes
Different analysis modes.
Definition: ana.C:101
Definition: anaQA.C:55
Count events with different selection criteria.
const TString kInputData
With real data kMC = kFALSE.
Definition: anaQA.C:77
Analyze files on GRID with Plugin.
Definition: anaQA.C:58
const Bool_t kMC
Global name for the xml collection file with data on grid.
Definition: anaQA.C:76
Analyze files on GRID, jobs launched from aliensh.
Definition: anaQA.C:59
TSystem * gSystem
void SetupPar(char *pararchivename)
Definition: anaQA.C:275
void LoadLibraries()
Definition: anaQA.C:261
AliAnalysisTaskCaloTrackCorrelation * AddTaskCalorimeterQA(const char *suffix="default", Bool_t simulation=kFALSE, TString outputFile="", Int_t year=2015, Bool_t printSettings=kFALSE, Bool_t calibrate=kTRUE)
int Int_t
Definition: External.C:63
void CreateChain(const Int_t mode, TChain *chain)
Fills chain with data files paths.
Definition: anaQA.C:331
void anaQA(Int_t mode=mLocal)
Definition: anaQA.C:98
Int_t mode
Definition: anaM.C:41
Analyze files on GRID with Plugin.
Definition: anaQA.C:57
char * kInDir
Definition: anaQA.C:67
Analyze locally files in your computer.
Definition: anaQA.C:56
Main class conecting the CaloTrackCorrelations package and Analysis Frame.
TFile * file
TList with histograms for a given trigger.
Int_t kFile
Data are in files kInDir/kPattern+i.
Definition: anaQA.C:69
bool Bool_t
Definition: External.C:53
char * kXML
Number of files to analyze in local mode.
Definition: anaQA.C:74
TString kTreeName
ESD, AOD, MC.
Definition: anaQA.C:78
Configuration of EMCal QA.
char * kPattern
Global, path to data files.
Definition: anaQA.C:68