AliPhysics  3337bb0 (3337bb0)
 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  // ------------------------------------------------------------------
62  LoadLibraries() ;
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 //_____________________________
212 //_____________________________
214 {
215 // gSystem->Load("libPWGCaloTrackCorrBase");
216 // gSystem->Load("libPWGGACaloTrackCorrelations");
217 
218 // SetupPar("PWGCaloTrackCorrBase");
219 // SetupPar("PWGGACaloTrackCorrelations");
220 }
221 
222 //_________________________________
226 //_________________________________
227 void SetupPar(char* pararchivename)
228 {
229  TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
230 
231  TString parpar(Form("%s.par", pararchivename)) ;
232 
233  if ( gSystem->AccessPathName(parpar.Data()) )
234  {
235  gSystem->ChangeDirectory(gSystem->Getenv("ALICE_PHYSICS")) ;
236  TString processline(Form(".! make %s", parpar.Data())) ;
237  gROOT->ProcessLine(processline.Data()) ;
238  gSystem->ChangeDirectory(cdir) ;
239  processline = Form(".! mv $ALICE_PHYSICS/%s .", parpar.Data()) ;
240  gROOT->ProcessLine(processline.Data()) ;
241  }
242 
243  if ( gSystem->AccessPathName(pararchivename) )
244  {
245  TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
246  gROOT->ProcessLine(processline.Data());
247  }
248 
249  TString ocwd = gSystem->WorkingDirectory();
250  gSystem->ChangeDirectory(pararchivename);
251 
252  // check for BUILD.sh and execute
253  if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh"))
254  {
255  printf("*******************************\n");
256  printf("*** Building PAR archive ***\n");
257  cout<<pararchivename<<endl;
258  printf("*******************************\n");
259 
260  if (gSystem->Exec("PROOF-INF/BUILD.sh"))
261  {
262  Error("runProcess","Cannot Build the PAR Archive! - Abort!");
263  return -1;
264  }
265  }
266  // check for SETUP.C and execute
267  if (!gSystem->AccessPathName("PROOF-INF/SETUP.C"))
268  {
269  printf("*******************************\n");
270  printf("*** Setup PAR archive ***\n");
271  cout<<pararchivename<<endl;
272  printf("*******************************\n");
273  gROOT->Macro("PROOF-INF/SETUP.C");
274  }
275 
276  gSystem->ChangeDirectory(ocwd.Data());
277  printf("Current dir: %s\n", ocwd.Data());
278 }
279 
280 //_____________________________________________________________________
282 //_____________________________________________________________________
283 void CreateChain(const anaModes mode, TChain * chain)
284 {
285  TString ocwd = gSystem->WorkingDirectory();
286 
287  //-----------------------------------------------------------
288  // Analysis of CAF data locally and with PROOF
289  //-----------------------------------------------------------
290  if(mode ==mPROOF || mode ==mLocalCAF)
291  {
292  // Chain from CAF
293  gROOT->LoadMacro("$ALICE_PHYSICS/PWG/EMCAL/CreateESDChain.C");
294  // The second parameter is the number of input files in the chain
295  chain = CreateESDChain("ESD12001.txt", 5);
296  }
297 
298  //---------------------------------------
299  // Local files analysis
300  //---------------------------------------
301  else if(mode == mLocal)
302  {
303  //If you want to add several ESD files sitting in a common directory INDIR
304  //Specify as environmental variables the directory (INDIR), the number of files
305  //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
306 
307  if(gSystem->Getenv("INDIR"))
308  kInDir = gSystem->Getenv("INDIR") ;
309  else cout<<"INDIR not set, use default: "<<kInDir<<endl;
310 
311  if(gSystem->Getenv("PATTERN"))
312  kPattern = gSystem->Getenv("PATTERN") ;
313  else cout<<"PATTERN not set, use default: "<<kPattern<<endl;
314 
315  if(gSystem->Getenv("NFILES"))
316  kFile = atoi(gSystem->Getenv("NFILES")) ;
317  else cout<<"NFILES not set, use default: "<<kFile<<endl;
318 
319  //Check if env variables are set and are correct
320  if ( kInDir && kFile) {
321  printf("Get %d files from directory %s\n",kFile,kInDir);
322  if ( ! gSystem->cd(kInDir) ) {//check if ESDs directory exist
323  printf("%s does not exist\n", kInDir) ;
324  return ;
325  }
326 
327  cout<<"INDIR : "<<kInDir<<endl;
328  cout<<"NFILES : "<<kFile<<endl;
329  cout<<"PATTERN : " <<kPattern<<endl;
330 
331  TString datafile="";
332  if(kInputData == "ESD") datafile = "AliESDs.root" ;
333  else if(kInputData == "AOD") datafile = "AliAOD.root" ;
334 
335  //Loop on ESD files, add them to chain
336  Int_t event =0;
337  Int_t skipped=0 ;
338  char file[120] ;
339 
340  for (event = 0 ; event < kFile ; event++) {
341  sprintf(file, "%s/%s%d/%s", kInDir,kPattern,event,datafile.Data()) ;
342  TFile * fESD = 0 ;
343  //Check if file exists and add it, if not skip it
344  if ( fESD = TFile::Open(file)) {
345  if ( fESD->Get(kTreeName) ) {
346  printf("++++ Adding %s\n", file) ;
347  chain->AddFile(file);
348  }
349  }
350  else {
351  printf("---- Skipping %s\n", file) ;
352  skipped++ ;
353  }
354  }
355  printf("number of entries # %lld, skipped %d\n", chain->GetEntries(), skipped*100) ;
356  }
357  else {
358  TString input = "AliESDs.root" ;
359  cout<<">>>>>> No list added, take a single file <<<<<<<<< "<<input<<endl;
360  chain->AddFile(input);
361  }
362 
363  }// local files analysis
364 
365  //------------------------------
366  //GRID xml files
367  //-----------------------------
368  else if(mode == mGRID){
369  //Get colection file. It is specified by the environmental
370  //variable XML
371 
372  if(gSystem->Getenv("XML") )
373  kXML = gSystem->Getenv("XML");
374  else
375  sprintf(kXML, "collection.xml") ;
376 
377  if (!TFile::Open(kXML)) {
378  printf("No collection file with name -- %s -- was found\n",kXML);
379  return ;
380  }
381  else cout<<"XML file "<<kXML<<endl;
382 
383  //Load necessary libraries and connect to the GRID
384  gSystem->Load("libNetx") ;
385  gSystem->Load("libRAliEn");
386  TGrid::Connect("alien://") ;
387 
388  //Feed Grid with collection file
389  TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
390  if (! collection) {
391  AliError(Form("%s not found", kXML)) ;
392  return kFALSE ;
393  }
394  TGridResult* result = collection->GetGridResult("",0 ,0);
395 
396  // Makes the ESD chain
397  printf("*** Getting the Chain ***\n");
398  for (Int_t index = 0; index < result->GetEntries(); index++) {
399  TString alienURL = result->GetKey(index, "turl") ;
400  cout << "================== " << alienURL << endl ;
401  chain->Add(alienURL) ;
402  }
403  }// xml analysis
404 
405  gSystem->ChangeDirectory(ocwd.Data());
406 }
407 
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:227
void LoadLibraries()
Definition: anaQA.C:213
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:283
Analyze locally files in your computer.
Definition: anaQA.C:19
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:31
bool Bool_t
Definition: External.C:53
char * kXML
Number of files to analyze in local mode.
Definition: anaQA.C:36
TString kTreeName
ESD, AOD, MC.
Definition: anaQA.C:40
char * kPattern
Global, path to data files.
Definition: anaQA.C:30