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