AliPhysics  v5-07-15-01 (b3d7633)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
anaM.C
Go to the documentation of this file.
1 
14 //-------------------------------------------------
16 //mLocal = 0: Analyze locally files in your computer
17 //mGRID = 3: Analyze files on GRID
18 
19 //---------------------------------------------------------------------------
20 //Settings to read locally several files, only for "mLocal" mode
21 //The different values are default, they can be set with environmental
22 //variables: INDIR, PATTERN, NFILES, respectively
23 char * kInDir = "/Users/ymao/group/ana/7TeV/corr";
24 char * kPattern = ""; // Data are in files kInDir/kPattern+i
25 Int_t kFile = 1; // Number of files
26 //---------------------------------------------------------------------------
27 //Collection file for grid analysis
28 char * kXML = "collection.xml";
29 
30 //---------------------------------------------------------------------------
31 
32 const Bool_t kMC = kFALSE; //With real data kMC = kFALSE
33 TString kInputData = "ESD";//ESD, AOD, MC
34 TString kTreeName ;
35 const TString calorimeter = "EMCAL" ;
36 const Bool_t kUsePAR = kFALSE; //set to kFALSE for libraries
37 //const Bool_t kUsePAR = kTRUE; //set to kFALSE for libraries
38 const Bool_t kDoESDFilter = kFALSE; //filter the tracks from the esd
39 
40 Int_t mode = mGRID;
41 
42 //________________________
44 //________________________
45 void anaM()
46 {
47  // Main
48  //--------------------------------------------------------------------
49  // Load analysis libraries
50  // Look at the method below,
51  // change whatever you need for your analysis case
52  // ------------------------------------------------------------------
53  LoadLibraries() ;
54 
55  //-------------------------------------------------------------------------------------------------
56  // Create chain from ESD and from cross sections files, look below for options.
57  //-------------------------------------------------------------------------------------------------
58  if(kInputData == "ESD") kTreeName = "esdTree" ;
59  else if(kInputData == "AOD") kTreeName = "aodTree" ;
60  else if (kInputData == "MC") kTreeName = "TE" ;
61  else {
62  cout<<"Wrong data type "<<kInputData<<endl;
63  break;
64  }
65 
66  TChain * chain = new TChain(kTreeName) ;
67 
68  CreateChain(mode, chain);//, chainxs);
69  cout<<"Chain created"<<endl;
70 
71  if( chain )
72  {
73  AliLog::SetGlobalLogLevel(AliLog::kError);//Minimum prints on screen
74 
75  //--------------------------------------
76  // Make the analysis manager
77  //-------------------------------------
78  AliAnalysisManager *mgr = new AliAnalysisManager("Manager", "Manager");
79  // MC handler
80  if( (kMC && (kInputData == "ESD")) || kInputData == "MC"){
81  AliMCEventHandler* mcHandler = new AliMCEventHandler();
82  mcHandler->SetReadTR(kFALSE);//Do not search TrackRef file
83  mgr->SetMCtruthEventHandler(mcHandler);
84  if( kInputData == "MC") mgr->SetInputEventHandler(NULL);
85  }
86 
87 // // AOD output handler
88 // AliAODHandler* aodoutHandler = new AliAODHandler();
89 // aodoutHandler->SetOutputFileName("AliAOD.root");
90 // mgr->SetOutputEventHandler(aodoutHandler);
91 
92  //input
93  Int_t maxiterations = 1;
94  AliEventPoolLoop* pool = new AliEventPoolLoop(maxiterations);
95  pool->SetChain(chain);
96  Int_t eventsInPool = 10;
97  AliMultiEventInputHandler *inpHandler = NULL ;
98  if(kInputData == "ESD"){
99  // ESD handler
100  printf("ESD MultiInput \n");
101  inpHandler = new AliMultiEventInputHandler(eventsInPool, 0);
102  }
103  if(kInputData == "AOD"){
104  // AOD handler
105  inpHandler = new AliMultiEventInputHandler(eventsInPool, 1);
106  }
107  mgr->SetInputEventHandler(inpHandler);
108  cout<<"Input handler "<<mgr->GetInputEventHandler()<<endl;
109  mgr->SetEventPool(pool);
110  inpHandler->SetEventPool(pool);
111 
112  //mgr->SetDebugLevel(-1); // For debugging, do not uncomment if you want no messages.
113 
114  // select triigger events for physics run
115 
116 // if(!kMC){
117 // gROOT->LoadMacro("AddTaskPhysicsSelection.C");
118 // AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection();
119 // mgr->AddTask(physSelTask);
120 // }
121 
122  //-------------------------------------------------------------------------
123  //Define task, put here any other task that you want to use.
124  //-------------------------------------------------------------------------
125 
126  //correlation analysis
127  gROOT->LoadMacro("AddTaskCaloTrackCorrM.C");
128 
130 
131  mgr->AddTask(taskEMCAL);
132 
134 
135  mgr->AddTask(taskPHOS);
136 
137  //gROOT->LoadMacro("AddTaskChargeCorr.C");
139 // if(!kMC)
140 // taskCharge->SelectCollisionCandidates();
141  mgr->AddTask(taskCharge);
142 
143  //-----------------------
144  // Run the analysis
145  //-----------------------
146  //mgr->ResetAnalysis();
147  mgr->InitAnalysis();
148  mgr->PrintStatus();
149  mgr->StartAnalysis("mix",chain);
150 
151  cout <<" Analysis ended sucessfully "<< endl ;
152  }
153  else cout << "Chain was not produced ! "<<endl;
154 
155 }
156 
157 //_____________________________
159 //_____________________________
161 {
162  //--------------------------------------
163  // Load the needed libraries most of them already loaded by aliroot
164  //--------------------------------------
165  gSystem->Load("libTree");
166  gSystem->Load("libGeom");
167  gSystem->Load("libVMC");
168  gSystem->Load("libXMLIO");
169  if(kUsePAR){
170  //--------------------------------------------------------
171  //If you want to use root and par files from aliroot
172  //--------------------------------------------------------
173  SetupPar("STEERBase");
174  SetupPar("ESD");
175  SetupPar("AOD");
176  SetupPar("ANALYSIS");
177  SetupPar("ANALYSISalice");
178  SetupPar("PHOSUtils");
179  SetupPar("EMCALUtils");
180 
181  SetupPar("PWGCaloTrackCorrBase");
182  SetupPar("PWGGACaloTrackCorrelations");
183  }
184  else{
185  //--------------------------------------------------------
186  // If you want to use already compiled libraries
187  // in the aliroot distribution
188  //--------------------------------------------------------
189  gSystem->Load("libSTEERBase");
190  gSystem->Load("libESD");
191  gSystem->Load("libAOD");
192  gSystem->Load("libANALYSIS");
193  gSystem->Load("libANALYSISalice");
194  gSystem->Load("libPHOSUtils");
195  gSystem->Load("libEMCALUtils");
196  gSystem->Load("libPWGCaloTrackCorrBase");
197  gSystem->Load("libPWGGACaloTrackCorrelations");
198  }
199 }
200 
201 //_________________________________
203 //_________________________________
204 void SetupPar(char* pararchivename)
205 {
206  //Load par files, create analysis libraries
207  //For testing, if par file already decompressed and modified
208  //classes then do not decompress.
209 
210  TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
211  TString parpar(Form("%s.par", pararchivename)) ;
212  if ( gSystem->AccessPathName(pararchivename) ) {
213  TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
214  gROOT->ProcessLine(processline.Data());
215  }
216 
217  TString ocwd = gSystem->WorkingDirectory();
218  gSystem->ChangeDirectory(pararchivename);
219 
220  // check for BUILD.sh and execute
221  if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
222  printf("*******************************\n");
223  printf("*** Building PAR archive ***\n");
224  cout<<pararchivename<<endl;
225  printf("*******************************\n");
226 
227  if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
228  Error("runProcess","Cannot Build the PAR Archive! - Abort!");
229  return -1;
230  }
231  }
232  // check for SETUP.C and execute
233  if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
234  printf("*******************************\n");
235  printf("*** Setup PAR archive ***\n");
236  cout<<pararchivename<<endl;
237  printf("*******************************\n");
238  gROOT->Macro("PROOF-INF/SETUP.C");
239  }
240 
241  gSystem->ChangeDirectory(ocwd.Data());
242  printf("Current dir: %s\n", ocwd.Data());
243 }
244 
245 
246 //_____________________________________________________________________
248 //_____________________________________________________________________
249 void CreateChain(const anaModes mode, TChain * chain){//, TChain * chainxs){
250  //Fills chain with data
251 
252  TString datafileName="";
253  if(kInputData == "ESD") datafileName = "AliESDs.root" ;
254  else if(kInputData == "AOD") datafileName = "AliAOD.root" ;
255  else if(kInputData == "MC") datafileName = "galice.root" ;
256 
257  TString ocwd = gSystem->WorkingDirectory();
258 
259  //---------------------------------------
260  // Local files analysis
261  //---------------------------------------
262  if(mode == mLocal)
263  {
264  //If you want to add several ESD files sitting in a common directory INDIR
265  //Specify as environmental variables the directory (INDIR), the number of files
266  //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
267 
268  cout<<"INDIR : "<<kInDir<<endl;
269  cout<<"NFILES : "<<kFile<<endl;
270  cout<<"PATTERN: " <<kPattern<<endl;
271 
272 
273  //Loop on ESD files, add them to chain
274  TString FileName ;
275  for (Int_t iFile = 0 ; iFile < kFile ; iFile++) {
276  FileName = Form("%s/%s%d/%s", kInDir,kPattern,iFile,datafileName.Data()) ;
277  //cout << "FileName: " << FileName <<endl ;
278  TFile * dataFile = 0 ;
279  //Check if file exists and add it, if not skip it
280  if ( dataFile = TFile::Open(FileName.Data())) {
281  if ( dataFile->Get(kTreeName) ) {
282  Int_t nEventsPerFile = ((TTree*) dataFile->Get(kTreeName)) ->GetEntries();
283  printf(" ++++ Adding %s, with %d events \n", FileName.Data(), nEventsPerFile) ;
284  chain->AddFile(FileName);
285  }
286  }
287  }
288  printf("number of entries # %lld \n", chain->GetEntries()) ;
289  }// local files analysis
290 
291  //------------------------------
292  //GRID xml files
293  //-----------------------------
294  else if(mode == mGRID)
295  {
296  //Load necessary libraries and connect to the GRID
297  gSystem->Load("libNetx") ;
298  gSystem->Load("libRAliEn");
299  TGrid::Connect("alien://") ;
300 
301  //Feed Grid with collection file
302  //TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\", 0)", kXML));
303  TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
304  if (! collection) {
305  AliError(Form("%s not found", kXML)) ;
306  return kFALSE ;
307  }
308  TGridResult* result = collection->GetGridResult("",0 ,0);
309 
310  // Makes the ESD chain
311  printf("*** Getting the Chain ***\n");
312  Int_t nEventsPerFile = 0;
313  for (Int_t index = 0; index < result->GetEntries(); index++) {
314  TString alienURL = result->GetKey(index, "turl") ;
315  cout << "================== " << alienURL << endl ;
316  chain->Add(alienURL) ;
317 
318  }
319  }// xml analysis
320 
321  gSystem->ChangeDirectory(ocwd.Data());
322 }
anaModes
Different analysis modes.
Definition: ana.C:16
void CreateChain(const anaModes mode, TChain *chain)
Fills chain with data files paths.
Definition: anaM.C:249
Int_t kFile
Definition: anaM.C:25
const Bool_t kMC
Definition: anaM.C:32
TSystem * gSystem
char * kXML
Definition: anaM.C:28
TString kInputData
Definition: anaM.C:33
const TString calorimeter
Definition: anaM.C:35
void anaM()
Main execution method.
Definition: anaM.C:45
Main class conecting the CaloTrackCorrelations package and Analysis Mixing Frame. ...
Definition: anaM.C:15
Int_t mode
Definition: anaM.C:40
void LoadLibraries()
Load analysis libraries. Out of date.
Definition: anaM.C:160
AliAnalysisTaskCaloTrackCorrelationM * AddTaskCaloTrackCorrM(TString data, TString calorimeter, Bool_t kPrintSettings=kFALSE)
char * kInDir
Definition: anaM.C:23
Definition: anaM.C:15
char * kPattern
Definition: anaM.C:24
const Bool_t kDoESDFilter
Definition: anaM.C:38
void SetupPar(char *pararchivename)
Par files compilation method.
Definition: anaM.C:204
const Bool_t kUsePAR
Definition: anaM.C:36
TString kTreeName
Definition: anaM.C:34