]>
Commit | Line | Data |
---|---|---|
b83cc5a7 | 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 | //------------------------------------------------- | |
13 | enum 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, NEVENT, respectivelly | |
22 | char * kInDir = "/home/blau/data"; | |
23 | char * kPattern = ""; // Data are in diles /data/Run0, | |
24 | Int_t kEvent = 3; // Number of files | |
25 | //--------------------------------------------------------------------------- | |
26 | //Collection file for grid analysis | |
27 | char * kXML = "collection.xml"; | |
28 | //--------------------------------------------------------------------------- | |
29 | //Scale histograms from file. Change to kTRUE when xsection file exists | |
30 | //Put name of file containing xsection | |
31 | //Put number of events per ESD file | |
32 | //This is an specific case for normalization of Pythia files. | |
33 | const Bool_t kGetXSectionFromFileAndScale = kFALSE ; | |
34 | const char * kXSFileName = "pyxsec.root"; | |
35 | //const Int_t kNumberOfEventsPerFile = 100; | |
36 | //--------------------------------------------------------------------------- | |
37 | ||
38 | const Bool_t kMC = kTRUE; //With real data kMC = kFALSE | |
39 | const TString kInputData = "ESD";//ESD, AOD, MC | |
40 | TString kTreeName = "esdTree"; | |
41 | ||
42 | void anaPhotonTagging(Int_t mode=mGRID, TString configName = "ConfigAnalysisPhoton") | |
43 | { | |
44 | // Main | |
45 | ||
46 | //-------------------------------------------------------------------- | |
47 | // Load analysis libraries | |
48 | // Look at the method below, | |
49 | // change whatever you need for your analysis case | |
50 | // ------------------------------------------------------------------ | |
51 | LoadLibraries(mode) ; | |
52 | ||
53 | //------------------------------------------------------------------------------------------------- | |
54 | //Create chain from ESD and from cross sections files, look below for options. | |
55 | //------------------------------------------------------------------------------------------------- | |
56 | if(kInputData == "ESD") kTreeName = "esdTree" ; | |
57 | else if(kInputData == "AOD") kTreeName = "aodTree" ; | |
58 | else if (kInputData == "MC") kTreeName = "TE" ; | |
59 | else { | |
60 | cout<<"Wrong data type "<<kInputData<<endl; | |
61 | break; | |
62 | } | |
63 | ||
64 | TChain *chain = new TChain(kTreeName) ; | |
65 | TChain * chainxs = new TChain("Xsection") ; | |
66 | CreateChain(mode, chain, chainxs); | |
67 | ||
68 | if(chain){ | |
69 | AliLog::SetGlobalLogLevel(AliLog::kError);//Minimum prints on screen | |
70 | ||
71 | //-------------------------------------- | |
72 | // Make the analysis manager | |
73 | //------------------------------------- | |
74 | AliAnalysisManager *mgr = new AliAnalysisManager("Manager", "Manager"); | |
75 | // MC handler | |
76 | if(kMC || kInputData == "MC"){ | |
77 | AliMCEventHandler* mcHandler = new AliMCEventHandler(); | |
78 | mcHandler->SetReadTR(kFALSE);//Do not search TrackRef file | |
79 | mgr->SetMCtruthEventHandler(mcHandler); | |
80 | } | |
81 | ||
82 | // AOD output handler | |
83 | AliAODHandler* aodoutHandler = new AliAODHandler(); | |
84 | aodoutHandler->SetOutputFileName("aod.root"); | |
85 | //aodoutHandler->SetCreateNonStandardAOD(); | |
86 | mgr->SetOutputEventHandler(aodoutHandler); | |
87 | ||
88 | //input | |
89 | if(kInputData == "ESD"){ | |
90 | // ESD handler | |
91 | AliESDInputHandler *esdHandler = new AliESDInputHandler(); | |
92 | mgr->SetInputEventHandler(esdHandler); | |
93 | } | |
94 | if(kInputData == "AOD"){ | |
95 | // AOD handler | |
96 | AliAODInputHandler *aodHandler = new AliAODInputHandler(); | |
97 | mgr->SetInputEventHandler(aodHandler); | |
98 | } | |
99 | ||
100 | //mgr->SetDebugLevel(-1); // For debugging, do not uncomment if you want no messages. | |
101 | ||
102 | //------------------------------------------------------------------------- | |
103 | //Define task, put here any other task that you want to use. | |
104 | //------------------------------------------------------------------------- | |
105 | // AliAnaPi0Conv * task = new AliAnaPi0Conv("Pi0") ; | |
106 | ||
107 | AliAnalysisTaskTaggedPhotons * taskPHOS = new AliAnalysisTaskTaggedPhotons("TaggedPHOS"); | |
108 | taskPHOS->SetPHOS(kTRUE); | |
109 | mgr->AddTask(taskPHOS); | |
110 | ||
111 | AliAnalysisTaskTaggedPhotons * taskEMCAL = new AliAnalysisTaskTaggedPhotons("TaggedEMCAL"); | |
112 | taskEMCAL->SetPHOS(kFALSE); | |
113 | mgr->AddTask(taskEMCAL); | |
114 | ||
115 | ||
116 | // Create containers for input/output | |
117 | AliAnalysisDataContainer *cinput1 = mgr->CreateContainer("cchain",TChain::Class(), | |
118 | AliAnalysisManager::kInputContainer); | |
119 | AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("tree", TTree::Class(), | |
120 | AliAnalysisManager::kOutputContainer, "default"); | |
121 | AliAnalysisDataContainer *coutput2 = mgr->CreateContainer("histosP", TList::Class(), | |
122 | AliAnalysisManager::kOutputContainer, "histosPHOS.root"); | |
123 | AliAnalysisDataContainer *coutput3 = mgr->CreateContainer("histosE", TList::Class(), | |
124 | AliAnalysisManager::kOutputContainer, "histosEMCAL.root"); | |
125 | ||
126 | mgr->ConnectInput (taskPHOS, 0, cinput1); | |
127 | mgr->ConnectOutput (taskPHOS, 0, coutput1 ); | |
128 | mgr->ConnectOutput (taskPHOS, 1, coutput2 ); | |
129 | mgr->ConnectInput (taskEMCAL, 0, cinput1); | |
130 | mgr->ConnectOutput (taskEMCAL, 0, coutput1 ); | |
131 | mgr->ConnectOutput (taskEMCAL, 1, coutput3 ); | |
132 | ||
133 | ||
134 | ||
135 | //----------------------- | |
136 | // Run the analysis | |
137 | //----------------------- | |
138 | TString smode = ""; | |
139 | if (mode==mLocal || mode == mLocalCAF) | |
140 | smode = "local"; | |
141 | else if (mode==mPROOF) | |
142 | smode = "proof"; | |
143 | else if (mode==mGRID) | |
144 | smode = "grid"; | |
145 | ||
146 | mgr->InitAnalysis(); | |
147 | mgr->PrintStatus(); | |
148 | mgr->StartAnalysis("local",chain); | |
149 | // mgr->StartAnalysis(smode.Data(),chain); | |
150 | ||
151 | cout <<" Analysis ended sucessfully "<< endl ; | |
152 | ||
153 | } | |
154 | else cout << "Chain was not produced ! "<<endl; | |
155 | ||
156 | } | |
157 | ||
158 | void LoadLibraries(const anaModes mode) { | |
159 | ||
160 | //-------------------------------------- | |
161 | // Load the needed libraries most of them already loaded by aliroot | |
162 | //-------------------------------------- | |
163 | gSystem->Load("libTree.so"); | |
164 | gSystem->Load("libGeom.so"); | |
165 | gSystem->Load("libVMC.so"); | |
166 | gSystem->Load("libXMLIO.so"); | |
167 | ||
168 | //---------------------------------------------------------- | |
169 | // >>>>>>>>>>> Local mode <<<<<<<<<<<<<< | |
170 | //---------------------------------------------------------- | |
171 | if (mode==mLocal || mode == mLocalCAF || mode == mGRID) { | |
172 | //-------------------------------------------------------- | |
173 | // If you want to use already compiled libraries | |
174 | // in the aliroot distribution | |
175 | //-------------------------------------------------------- | |
176 | //gSystem->Load("libSTEERBase"); | |
177 | //gSystem->Load("libESD"); | |
178 | //gSystem->Load("libAOD"); | |
179 | //gSystem->Load("libANALYSIS"); | |
180 | //gSystem->Load("libANALYSISalice"); | |
181 | //gSystem->Load("libPHOSUtils"); | |
182 | //gSystem->Load("libPWG4PartCorrBase"); | |
183 | //gSystem->Load("libPWG4PartCorrDep"); | |
184 | ||
185 | //-------------------------------------------------------- | |
186 | //If you want to use root and par files from aliroot | |
187 | //-------------------------------------------------------- | |
188 | SetupPar("STEERBase"); | |
189 | SetupPar("ESD"); | |
190 | SetupPar("AOD"); | |
191 | SetupPar("ANALYSIS"); | |
192 | SetupPar("ANALYSISalice"); | |
193 | //If your analysis needs PHOS geometry uncomment following lines | |
194 | SetupPar("PHOSUtils"); | |
195 | // //Create Geometry | |
196 | TGeoManager::Import("geometry.root") ; //need file "geometry.root" in local dir!!!! | |
197 | SetupPar("PWG4PartCorrBase"); | |
198 | SetupPar("PWG4PartCorrDep"); | |
199 | } | |
200 | ||
201 | //--------------------------------------------------------- | |
202 | // <<<<<<<<<< PROOF mode >>>>>>>>>>>> | |
203 | //--------------------------------------------------------- | |
204 | else if (mode==mPROOF) { | |
205 | // | |
206 | // Connect to proof | |
207 | // Put appropriate username here | |
208 | // TProof::Reset("proof://mgheata@lxb6046.cern.ch"); | |
209 | TProof::Open("proof://mgheata@lxb6046.cern.ch"); | |
210 | ||
211 | // gProof->ClearPackages(); | |
212 | // gProof->ClearPackage("ESD"); | |
213 | // gProof->ClearPackage("AOD"); | |
214 | // gProof->ClearPackage("ANALYSIS"); | |
215 | // gProof->ClearPackage("PWG4PartCorrBase"); | |
216 | // gProof->ClearPackage("PWG4PartCorrDep"); | |
217 | ||
218 | // Enable the STEERBase Package | |
219 | gProof->UploadPackage("STEERBase.par"); | |
220 | gProof->EnablePackage("STEERBase"); | |
221 | // Enable the ESD Package | |
222 | gProof->UploadPackage("ESD.par"); | |
223 | gProof->EnablePackage("ESD"); | |
224 | // Enable the AOD Package | |
225 | gProof->UploadPackage("AOD.par"); | |
226 | gProof->EnablePackage("AOD"); | |
227 | // Enable the Analysis Package | |
228 | gProof->UploadPackage("ANALYSIS.par"); | |
229 | gProof->EnablePackage("ANALYSIS"); | |
230 | // Enable the PHOS geometry Package | |
231 | //gProof->UploadPackage("PHOSUtils.par"); | |
232 | //gProof->EnablePackage("PHOSUtils"); | |
233 | // Enable PartCorr analysis | |
234 | gProof->UploadPackage("PWG4PartCorrBase.par"); | |
235 | gProof->EnablePackage("PWG4PartCorrBase"); | |
236 | gProof->UploadPackage("PWG4PartCorrDep.par"); | |
237 | gProof->EnablePackage("PWG4PartCorrDep"); | |
238 | gProof->ShowEnabledPackages(); | |
239 | } | |
240 | ||
241 | } | |
242 | ||
243 | void SetupPar(char* pararchivename) | |
244 | { | |
245 | //Load par files, create analysis libraries | |
246 | //For testing, if par file already decompressed and modified | |
247 | //classes then do not decompress. | |
248 | ||
249 | TString cdir(Form("%s", gSystem->WorkingDirectory() )) ; | |
250 | TString parpar(Form("%s.par", pararchivename)) ; | |
251 | if ( gSystem->AccessPathName(parpar.Data()) ) { | |
252 | gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ; | |
253 | TString processline(Form(".! make %s", parpar.Data())) ; | |
254 | gROOT->ProcessLine(processline.Data()) ; | |
255 | gSystem->ChangeDirectory(cdir) ; | |
256 | processline = Form(".! mv $ALICE_ROOT/%s .", parpar.Data()) ; | |
257 | gROOT->ProcessLine(processline.Data()) ; | |
258 | } | |
259 | if ( gSystem->AccessPathName(pararchivename) ) { | |
260 | TString processline = Form(".! tar xvzf %s",parpar.Data()) ; | |
261 | gROOT->ProcessLine(processline.Data()); | |
262 | } | |
263 | ||
264 | TString ocwd = gSystem->WorkingDirectory(); | |
265 | gSystem->ChangeDirectory(pararchivename); | |
266 | ||
267 | // check for BUILD.sh and execute | |
268 | if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) { | |
269 | printf("*******************************\n"); | |
270 | printf("*** Building PAR archive ***\n"); | |
271 | cout<<pararchivename<<endl; | |
272 | printf("*******************************\n"); | |
273 | ||
274 | if (gSystem->Exec("PROOF-INF/BUILD.sh")) { | |
275 | Error("runProcess","Cannot Build the PAR Archive! - Abort!"); | |
276 | return -1; | |
277 | } | |
278 | } | |
279 | // check for SETUP.C and execute | |
280 | if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) { | |
281 | printf("*******************************\n"); | |
282 | printf("*** Setup PAR archive ***\n"); | |
283 | cout<<pararchivename<<endl; | |
284 | printf("*******************************\n"); | |
285 | gROOT->Macro("PROOF-INF/SETUP.C"); | |
286 | } | |
287 | ||
288 | gSystem->ChangeDirectory(ocwd.Data()); | |
289 | printf("Current dir: %s\n", ocwd.Data()); | |
290 | } | |
291 | ||
292 | ||
293 | ||
294 | void CreateChain(const anaModes mode, TChain * chain, TChain * chainxs){ | |
295 | //Fills chain with data | |
296 | TString ocwd = gSystem->WorkingDirectory(); | |
297 | ||
298 | //----------------------------------------------------------- | |
299 | //Analysis of CAF data locally and with PROOF | |
300 | //----------------------------------------------------------- | |
301 | if(mode ==mPROOF || mode ==mLocalCAF){ | |
302 | // Chain from CAF | |
303 | gROOT->LoadMacro("$ALICE_ROOT/PWG0/CreateESDChain.C"); | |
304 | // The second parameter is the number of input files in the chain | |
305 | chain = CreateESDChain("ESD12001.txt", 5); | |
306 | } | |
307 | ||
308 | //--------------------------------------- | |
309 | //Local files analysis | |
310 | //--------------------------------------- | |
311 | else if(mode == mLocal){ | |
312 | //If you want to add several ESD files sitting in a common directory INDIR | |
313 | //Specify as environmental variables the directory (INDIR), the number of files | |
314 | //to analyze (NEVENT) and the pattern name of the directories with files (PATTERN) | |
315 | ||
316 | if(gSystem->Getenv("INDIR")) | |
317 | kInDir = gSystem->Getenv("INDIR") ; | |
318 | else cout<<"INDIR not set, use default: "<<kInDir<<endl; | |
319 | ||
320 | if(gSystem->Getenv("PATTERN")) | |
321 | kPattern = gSystem->Getenv("PATTERN") ; | |
322 | else cout<<"PATTERN not set, use default: "<<kPattern<<endl; | |
323 | ||
324 | if(gSystem->Getenv("NEVENT")) | |
325 | kEvent = atoi(gSystem->Getenv("NEVENT")) ; | |
326 | else cout<<"NEVENT not set, use default: "<<kEvent<<endl; | |
327 | ||
328 | //Check if env variables are set and are correct | |
329 | if ( kInDir && kEvent) { | |
330 | printf("Get %d files from directory %s\n",kEvent,kInDir); | |
331 | if ( ! gSystem->cd(kInDir) ) {//check if ESDs directory exist | |
332 | printf("%s does not exist\n", kInDir) ; | |
333 | return ; | |
334 | } | |
335 | cout<<"INDIR : "<<kInDir<<endl; | |
336 | cout<<"NEVENT : "<<kEvent<<endl; | |
337 | cout<<"PATTERN: " <<kPattern<<endl; | |
338 | ||
339 | TString datafile=""; | |
340 | if(kInputData == "ESD") datafile = "AliESDs.root" ; | |
341 | else if(kInputData == "AOD") datafile = "aod.root" ; | |
342 | else if(kInputData == "MC") datafile = "galice.root" ; | |
343 | ||
344 | //Loop on ESD files, add them to chain | |
345 | Int_t event =0; | |
346 | Int_t skipped=0 ; | |
347 | char file[120] ; | |
348 | char filexs[120] ; | |
349 | ||
350 | for (event = 0 ; event < kEvent ; event++) { | |
351 | sprintf(file, "%s/%s%d/%s", kInDir,kPattern,event,datafile.Data()) ; | |
352 | sprintf(filexs, "%s/%s%d/%s", kInDir,kPattern,event,kXSFileName) ; | |
353 | TFile * fESD = 0 ; | |
354 | //Check if file exists and add it, if not skip it | |
355 | if ( fESD = TFile::Open(file)) { | |
356 | if ( fESD->Get(kTreeName) ) { | |
357 | printf("++++ Adding %s\n", file) ; | |
358 | chain->AddFile(file); | |
359 | chainxs->Add(filexs) ; | |
360 | } | |
361 | } | |
362 | else { | |
363 | printf("---- Skipping %s\n", file) ; | |
364 | skipped++ ; | |
365 | } | |
366 | } | |
367 | printf("number of entries # %lld, skipped %d\n", chain->GetEntries(), skipped*100) ; | |
368 | } | |
369 | else { | |
370 | TString input = "AliESDs.root" ; | |
371 | cout<<">>>>>> No list added, take a single file <<<<<<<<< "<<input<<endl; | |
372 | chain->AddFile(input); | |
373 | } | |
374 | ||
375 | }// local files analysis | |
376 | ||
377 | //------------------------------ | |
378 | //GRID xml files | |
379 | //----------------------------- | |
380 | else if(mode == mGRID){ | |
381 | //Get colection file. It is specified by the environmental | |
382 | //variable XML | |
383 | ||
384 | if(gSystem->Getenv("XML") ) | |
385 | kXML = gSystem->Getenv("XML"); | |
386 | else | |
387 | sprintf(kXML, "collection.xml") ; | |
388 | ||
389 | if (!TFile::Open(kXML)) { | |
390 | printf("No collection file with name -- %s -- was found\n",kXML); | |
391 | return ; | |
392 | } | |
393 | else cout<<"XML file "<<kXML<<endl; | |
394 | ||
395 | //Load necessary libraries and connect to the GRID | |
396 | gSystem->Load("libNetx.so") ; | |
397 | gSystem->Load("libRAliEn.so"); | |
398 | TGrid::Connect("alien://") ; | |
399 | ||
400 | //Feed Grid with collection file | |
401 | //TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\", 0)", kXML)); | |
402 | TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML); | |
403 | if (! collection) { | |
404 | AliError(Form("%s not found", kXML)) ; | |
405 | return kFALSE ; | |
406 | } | |
407 | TGridResult* result = collection->GetGridResult("",0 ,0); | |
408 | ||
409 | // Makes the ESD chain | |
410 | printf("*** Getting the Chain ***\n"); | |
411 | for (Int_t index = 0; index < result->GetEntries(); index++) { | |
412 | TString alienURL = result->GetKey(index, "turl") ; | |
413 | cout << "================== " << alienURL << endl ; | |
414 | chain->Add(alienURL) ; | |
415 | alienURL.ReplaceAll("AliESDs.root",kXSFileName); | |
416 | chainxs->Add(alienURL) ; | |
417 | } | |
418 | }// xml analysis | |
419 | ||
420 | gSystem->ChangeDirectory(ocwd.Data()); | |
421 | } | |
422 | ||
423 | //________________________________________________ | |
424 | void GetAverageXsection(TTree * tree, Double_t & xs, Float_t & ntr) | |
425 | { | |
426 | // Read the PYTHIA statistics from the file pyxsec.root created by | |
427 | // the function WriteXsection(): | |
428 | // integrated cross section (xsection) and | |
429 | // the number of Pyevent() calls (ntrials) | |
430 | // and calculate the weight per one event xsection/ntrials | |
431 | // The spectrum calculated by a user should be | |
432 | // multiplied by this weight, something like this: | |
433 | // TH1F *userSpectrum ... // book and fill the spectrum | |
434 | // userSpectrum->Scale(weight) | |
435 | // | |
436 | // Yuri Kharlov 19 June 2007 | |
437 | // Gustavo Conesa 15 April 2008 | |
438 | Double_t xsection = 0; | |
439 | UInt_t ntrials = 0; | |
440 | xs = 0; | |
441 | ntr = 0; | |
442 | ||
443 | Int_t nfiles = tree->GetEntries() ; | |
444 | if (tree && nfiles > 0) { | |
445 | tree->SetBranchAddress("xsection",&xsection); | |
446 | tree->SetBranchAddress("ntrials",&ntrials); | |
447 | for(Int_t i = 0; i < nfiles; i++){ | |
448 | tree->GetEntry(i); | |
449 | xs += xsection ; | |
450 | ntr += ntrials ; | |
451 | cout << "xsection " <<xsection<<" ntrials "<<ntrials<<endl; | |
452 | } | |
453 | ||
454 | xs = xs / nfiles; | |
455 | ntr = ntr / nfiles; | |
456 | cout << "-----------------------------------------------------------------"<<endl; | |
457 | cout << "Average of "<< nfiles<<" files: xsection " <<xs<<" ntrials "<<ntr<<endl; | |
458 | cout << "-----------------------------------------------------------------"<<endl; | |
459 | } | |
460 | else cout << " >>>> Empty tree !!!! <<<<< "<<endl; | |
461 | ||
462 | } | |
463 | ||
464 | ||
465 |