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