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