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