]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGGA/CaloTrackCorrelations/macros/QA/ana.C
Change the task name from AliAnalysisTaskParticleCorrelation to AliAnalysisTaskCaloTr...
[u/mrichter/AliRoot.git] / PWGGA / CaloTrackCorrelations / macros / QA / ana.C
CommitLineData
a0bb4dc0 1/* $Id: $ */
2//--------------------------------------------------
3// Example macro to do analysis with the
4// analysis classes in PWG4PartCorr
5// Can be executed with Root and AliRoot
6//
7// Pay attention to the options and definitions
8// set in the lines below
9//
10// Author : Gustavo Conesa Balbastre (INFN-LNF)
11//
12//-------------------------------------------------
13enum anaModes {mLocal, mLocalCAF,mPROOF,mGRID};
14//mLocal: Analyze locally files in your computer
15//mLocalCAF: Analyze locally CAF files
16//mPROOF: Analyze CAF files with PROOF
17
18//---------------------------------------------------------------------------
19//Settings to read locally several files, only for "mLocal" mode
20//The different values are default, they can be set with environmental
21//variables: INDIR, PATTERN, NFILES, respectivelly
22char * kInDir = "/user/data/files/";
23char * kPattern = ""; // Data are in files kInDir/kPattern+i
24Int_t kFile = 1; // Number of files
25//---------------------------------------------------------------------------
26//Collection file for grid analysis
27char * kXML = "collection.xml";
a0bb4dc0 28
29const Bool_t kMC = kFALSE; //With real data kMC = kFALSE
30const TString kInputData = "ESD"; //ESD, AOD, MC
31TString kTreeName = "esdTree";
32
33void ana(Int_t mode=mLocal)
34{
35 // Main
36
37 //--------------------------------------------------------------------
38 // Load analysis libraries
39 // Look at the method below,
40 // change whatever you need for your analysis case
41 // ------------------------------------------------------------------
42 LoadLibraries(mode) ;
54769bc0 43 // TGeoManager::Import("geometry.root") ; //need file "geometry.root" in local dir!!!!
44
a0bb4dc0 45 //-------------------------------------------------------------------------------------------------
46 //Create chain from ESD and from cross sections files, look below for options.
47 //-------------------------------------------------------------------------------------------------
48 if(kInputData == "ESD") kTreeName = "esdTree" ;
49 else if(kInputData == "AOD") kTreeName = "aodTree" ;
50 else if (kInputData == "MC") kTreeName = "TE" ;
51 else {
52 cout<<"Wrong data type "<<kInputData<<endl;
53 break;
54 }
55
56 TChain *chain = new TChain(kTreeName) ;
54769bc0 57 CreateChain(mode, chain);
a0bb4dc0 58
59 if(chain){
60 AliLog::SetGlobalLogLevel(AliLog::kError);//Minimum prints on screen
61
62 //--------------------------------------
63 // Make the analysis manager
64 //-------------------------------------
65 AliAnalysisManager *mgr = new AliAnalysisManager("Manager", "Manager");
66 // MC handler
67 if((kMC || kInputData == "MC") && kInputData!="AOD"){
68 AliMCEventHandler* mcHandler = new AliMCEventHandler();
69 mcHandler->SetReadTR(kFALSE);//Do not search TrackRef file
70 mgr->SetMCtruthEventHandler(mcHandler);
3748ffb5 71 if( kInputData == "MC") mgr->SetInputEventHandler(NULL);
a0bb4dc0 72 }
a0bb4dc0 73
74 //input
75 if(kInputData == "ESD")
54769bc0 76 {
77 // ESD handler
78 AliESDInputHandler *esdHandler = new AliESDInputHandler();
79 mgr->SetInputEventHandler(esdHandler);
80 cout<<"ESD handler "<<mgr->GetInputEventHandler()<<endl;
81 }
a0bb4dc0 82 if(kInputData == "AOD"){
83 // AOD handler
84 AliAODInputHandler *aodHandler = new AliAODInputHandler();
85 mgr->SetInputEventHandler(aodHandler);
54769bc0 86 cout<<"AOD handler "<<mgr->GetInputEventHandler()<<endl;
a0bb4dc0 87 }
54769bc0 88
a0bb4dc0 89 //mgr->SetDebugLevel(-1); // For debugging, do not uncomment if you want no messages.
90
3748ffb5 91 // AOD output handler, needed for physics selection
92 cout<<"Init output handler"<<endl;
93 AliAODHandler* aodoutHandler = new AliAODHandler();
94 aodoutHandler->SetOutputFileName("aod.root");
95 ////aodoutHandler->SetCreateNonStandardAOD();
96 mgr->SetOutputEventHandler(aodoutHandler);
97
a0bb4dc0 98 //-------------------------------------------------------------------------
99 //Define task, put here any other task that you want to use.
100 //-------------------------------------------------------------------------
3748ffb5 101
102 TString outputFile = AliAnalysisManager::GetCommonFileName();
a0bb4dc0 103 AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
3748ffb5 104
105 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
106 AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection();
107
a0bb4dc0 108 //gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskESDFilter.C");
109 //AliAnalysisTaskESDfilter *taskesdfilter = AddTaskESDFilter(kTRUE);
3748ffb5 110
111 //Counting events tasks
112 AliAnalysisTaskCounter * counterMB = new AliAnalysisTaskCounter("CounterMB");
113 counterMB->SelectCollisionCandidates(AliVEvent::kMB);
114
115 AliAnalysisDataContainer *coutputMB =
116 mgr->CreateContainer("counterMB", TList::Class(), AliAnalysisManager::kOutputContainer, outputFile.Data());
117 mgr->AddTask(counterMB);
118 mgr->ConnectInput (counterMB, 0, cinput1);
119 mgr->ConnectOutput (counterMB, 1, coutputMB);
120
121 AliAnalysisTaskCounter * counterEMC = new AliAnalysisTaskCounter("CounterEMC");
122 counterEMC->SelectCollisionCandidates(AliVEvent::kEMC7);
123
124 AliAnalysisDataContainer *coutputEMC =
125 mgr->CreateContainer("counterEMC", TList::Class(), AliAnalysisManager::kOutputContainer, outputFile.Data());
126 mgr->AddTask(counterEMC);
127 mgr->ConnectInput (counterEMC, 0, cinput1);
128 mgr->ConnectOutput (counterEMC, 1, coutputEMC);
129
130 AliAnalysisTaskCounter * counterINT = new AliAnalysisTaskCounter("CounterINT");
131 counterINT->SelectCollisionCandidates(AliVEvent::kINT7);
132
133 AliAnalysisDataContainer *coutputINT =
134 mgr->CreateContainer("counterINT7", TList::Class(), AliAnalysisManager::kOutputContainer, outputFile.Data());
135 mgr->AddTask(counterINT);
136 mgr->ConnectInput (counterINT, 0, cinput1);
137 mgr->ConnectOutput (counterINT, 1, coutputINT);
138
139
54769bc0 140 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/QA/AddTaskCalorimeterQA.C");
0e06e5b0 141 AliAnalysisTaskCaloTrackCorrelation *taskQAEMC = AddTaskCalorimeterQA(kInputData,2011,kFALSE,kMC,"","kEMC7");
3748ffb5 142 taskQAEMC->SelectCollisionCandidates(AliVEvent::kEMC7);
0e06e5b0 143 AliAnalysisTaskCaloTrackCorrelation *taskQAINT = AddTaskCalorimeterQA(kInputData,2011,kFALSE,kMC,"","kINT7");
3748ffb5 144 taskQAINT->SelectCollisionCandidates(AliVEvent::kINT7);
a0bb4dc0 145
146 //-----------------------
147 // Run the analysis
148 //-----------------------
149 TString smode = "";
150 if (mode==mLocal || mode == mLocalCAF)
151 smode = "local";
152 else if (mode==mPROOF)
153 smode = "proof";
154 else if (mode==mGRID)
7c30e61e 155 smode = "local";
a0bb4dc0 156
157 mgr->InitAnalysis();
158 mgr->PrintStatus();
159 mgr->StartAnalysis(smode.Data(),chain);
160
161cout <<" Analysis ended sucessfully "<< endl ;
162
163 }
164 else cout << "Chain was not produced ! "<<endl;
165
166}
167
168void LoadLibraries(const anaModes mode) {
169
170 //--------------------------------------
171 // Load the needed libraries most of them already loaded by aliroot
172 //--------------------------------------
173 gSystem->Load("libTree.so");
174 gSystem->Load("libGeom.so");
175 gSystem->Load("libVMC.so");
176 gSystem->Load("libXMLIO.so");
54769bc0 177 gSystem->Load("libMatrix.so");
178 gSystem->Load("libPhysics.so");
a0bb4dc0 179 //----------------------------------------------------------
180 // >>>>>>>>>>> Local mode <<<<<<<<<<<<<<
181 //----------------------------------------------------------
182 if (mode==mLocal || mode == mLocalCAF || mode == mGRID) {
183 //--------------------------------------------------------
184 // If you want to use already compiled libraries
185 // in the aliroot distribution
186 //--------------------------------------------------------
54769bc0 187
a0bb4dc0 188 gSystem->Load("libSTEERBase.so");
189 gSystem->Load("libESD.so");
190 gSystem->Load("libAOD.so");
191 gSystem->Load("libANALYSIS.so");
192 gSystem->Load("libANALYSISalice.so");
193 gSystem->Load("libPHOSUtils");
194 gSystem->Load("libEMCALUtils");
195 gSystem->Load("libPWG4PartCorrBase.so");
196 gSystem->Load("libPWG4PartCorrDep.so");
a0bb4dc0 197
198 //--------------------------------------------------------
199 //If you want to use root and par files from aliroot
200 //--------------------------------------------------------
201// SetupPar("STEERBase");
202// SetupPar("ESD");
203// SetupPar("AOD");
204// SetupPar("ANALYSIS");
205// SetupPar("ANALYSISalice");
206// //If your analysis needs PHOS geometry uncomment following lines
207// SetupPar("PHOSUtils");
208// SetupPar("EMCALUtils");
54769bc0 209// //Create Geometry
a0bb4dc0 210// SetupPar("PWG4PartCorrBase");
211// SetupPar("PWG4PartCorrDep");
54769bc0 212
a0bb4dc0 213 }
214
215 //---------------------------------------------------------
216 // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
217 //---------------------------------------------------------
218 else if (mode==mPROOF) {
219 //
220 // Connect to proof
221 // Put appropriate username here
222 // TProof::Reset("proof://mgheata@lxb6046.cern.ch");
223 TProof::Open("proof://mgheata@lxb6046.cern.ch");
224
225 // gProof->ClearPackages();
226 // gProof->ClearPackage("ESD");
227 // gProof->ClearPackage("AOD");
228 // gProof->ClearPackage("ANALYSIS");
229 // gProof->ClearPackage("PWG4PartCorrBase");
230 // gProof->ClearPackage("PWG4PartCorrDep");
231
232 // Enable the STEERBase Package
233 gProof->UploadPackage("STEERBase.par");
234 gProof->EnablePackage("STEERBase");
235 // Enable the ESD Package
236 gProof->UploadPackage("ESD.par");
237 gProof->EnablePackage("ESD");
238 // Enable the AOD Package
239 gProof->UploadPackage("AOD.par");
240 gProof->EnablePackage("AOD");
241 // Enable the Analysis Package
242 gProof->UploadPackage("ANALYSIS.par");
243 gProof->EnablePackage("ANALYSIS");
244 // Enable the PHOS geometry Package
245 //gProof->UploadPackage("PHOSUtils.par");
246 //gProof->EnablePackage("PHOSUtils");
247 // Enable PartCorr analysis
248 gProof->UploadPackage("PWG4PartCorrBase.par");
249 gProof->EnablePackage("PWG4PartCorrBase");
250 gProof->UploadPackage("PWG4PartCorrDep.par");
251 gProof->EnablePackage("PWG4PartCorrDep");
252 gProof->ShowEnabledPackages();
253 }
254
255}
256
257void SetupPar(char* pararchivename)
258{
259 //Load par files, create analysis libraries
260 //For testing, if par file already decompressed and modified
261 //classes then do not decompress.
262
263 TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
264 TString parpar(Form("%s.par", pararchivename)) ;
265 if ( gSystem->AccessPathName(parpar.Data()) ) {
266 gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
267 TString processline(Form(".! make %s", parpar.Data())) ;
268 gROOT->ProcessLine(processline.Data()) ;
269 gSystem->ChangeDirectory(cdir) ;
270 processline = Form(".! mv $ALICE_ROOT/%s .", parpar.Data()) ;
271 gROOT->ProcessLine(processline.Data()) ;
272 }
273 if ( gSystem->AccessPathName(pararchivename) ) {
274 TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
275 gROOT->ProcessLine(processline.Data());
276 }
277
278 TString ocwd = gSystem->WorkingDirectory();
279 gSystem->ChangeDirectory(pararchivename);
280
281 // check for BUILD.sh and execute
282 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
283 printf("*******************************\n");
284 printf("*** Building PAR archive ***\n");
285 cout<<pararchivename<<endl;
286 printf("*******************************\n");
287
288 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
289 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
290 return -1;
291 }
292 }
293 // check for SETUP.C and execute
294 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
295 printf("*******************************\n");
296 printf("*** Setup PAR archive ***\n");
297 cout<<pararchivename<<endl;
298 printf("*******************************\n");
299 gROOT->Macro("PROOF-INF/SETUP.C");
300 }
301
302 gSystem->ChangeDirectory(ocwd.Data());
303 printf("Current dir: %s\n", ocwd.Data());
304}
305
306
307
54769bc0 308void CreateChain(const anaModes mode, TChain * chain){
a0bb4dc0 309 //Fills chain with data
310 TString ocwd = gSystem->WorkingDirectory();
311
312 //-----------------------------------------------------------
313 //Analysis of CAF data locally and with PROOF
314 //-----------------------------------------------------------
315 if(mode ==mPROOF || mode ==mLocalCAF){
316 // Chain from CAF
317 gROOT->LoadMacro("$ALICE_ROOT/PWG0/CreateESDChain.C");
318 // The second parameter is the number of input files in the chain
319 chain = CreateESDChain("ESD12001.txt", 5);
320 }
321
322 //---------------------------------------
323 //Local files analysis
324 //---------------------------------------
325 else if(mode == mLocal){
326 //If you want to add several ESD files sitting in a common directory INDIR
327 //Specify as environmental variables the directory (INDIR), the number of files
328 //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
329
330 if(gSystem->Getenv("INDIR"))
331 kInDir = gSystem->Getenv("INDIR") ;
332 else cout<<"INDIR not set, use default: "<<kInDir<<endl;
333
334 if(gSystem->Getenv("PATTERN"))
335 kPattern = gSystem->Getenv("PATTERN") ;
336 else cout<<"PATTERN not set, use default: "<<kPattern<<endl;
337
338 if(gSystem->Getenv("NFILES"))
339 kFile = atoi(gSystem->Getenv("NFILES")) ;
340 else cout<<"NFILES not set, use default: "<<kFile<<endl;
341
342 //Check if env variables are set and are correct
343 if ( kInDir && kFile) {
344 printf("Get %d files from directory %s\n",kFile,kInDir);
345 if ( ! gSystem->cd(kInDir) ) {//check if ESDs directory exist
346 printf("%s does not exist\n", kInDir) ;
347 return ;
348 }
349
a0bb4dc0 350 cout<<"INDIR : "<<kInDir<<endl;
351 cout<<"NFILES : "<<kFile<<endl;
352 cout<<"PATTERN : " <<kPattern<<endl;
a0bb4dc0 353
354 TString datafile="";
355 if(kInputData == "ESD") datafile = "AliESDs.root" ;
356 else if(kInputData == "AOD") datafile = "AliAOD.root" ;
a0bb4dc0 357
358 //Loop on ESD files, add them to chain
359 Int_t event =0;
360 Int_t skipped=0 ;
361 char file[120] ;
a0bb4dc0 362
363 for (event = 0 ; event < kFile ; event++) {
364 sprintf(file, "%s/%s%d/%s", kInDir,kPattern,event,datafile.Data()) ;
a0bb4dc0 365 TFile * fESD = 0 ;
366 //Check if file exists and add it, if not skip it
367 if ( fESD = TFile::Open(file)) {
368 if ( fESD->Get(kTreeName) ) {
369 printf("++++ Adding %s\n", file) ;
370 chain->AddFile(file);
a0bb4dc0 371 }
372 }
373 else {
374 printf("---- Skipping %s\n", file) ;
375 skipped++ ;
376 }
377 }
378 printf("number of entries # %lld, skipped %d\n", chain->GetEntries(), skipped*100) ;
379 }
380 else {
381 TString input = "AliESDs.root" ;
382 cout<<">>>>>> No list added, take a single file <<<<<<<<< "<<input<<endl;
383 chain->AddFile(input);
384 }
385
386 }// local files analysis
387
388 //------------------------------
389 //GRID xml files
390 //-----------------------------
391 else if(mode == mGRID){
392 //Get colection file. It is specified by the environmental
393 //variable XML
394
395 if(gSystem->Getenv("XML") )
396 kXML = gSystem->Getenv("XML");
397 else
398 sprintf(kXML, "collection.xml") ;
399
400 if (!TFile::Open(kXML)) {
401 printf("No collection file with name -- %s -- was found\n",kXML);
402 return ;
403 }
404 else cout<<"XML file "<<kXML<<endl;
405
406 //Load necessary libraries and connect to the GRID
407 gSystem->Load("libNetx.so") ;
408 gSystem->Load("libRAliEn.so");
409 TGrid::Connect("alien://") ;
410
411 //Feed Grid with collection file
a0bb4dc0 412 TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
413 if (! collection) {
414 AliError(Form("%s not found", kXML)) ;
415 return kFALSE ;
416 }
417 TGridResult* result = collection->GetGridResult("",0 ,0);
418
419 // Makes the ESD chain
420 printf("*** Getting the Chain ***\n");
421 for (Int_t index = 0; index < result->GetEntries(); index++) {
422 TString alienURL = result->GetKey(index, "turl") ;
423 cout << "================== " << alienURL << endl ;
424 chain->Add(alienURL) ;
a0bb4dc0 425 }
426 }// xml analysis
427
428 gSystem->ChangeDirectory(ocwd.Data());
429}
430