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