2 //--------------------------------------------------
3 // Example macro to do Calorimeters filtering
6 // Pay attention to the options and definitions
7 // set in the lines below
9 // Author : Gustavo Conesa Balbastre (INFN-LNF)
11 //-------------------------------------------------
12 enum anaModes {mLocal, mLocalCAF,mPROOF,mGRID};
13 //mLocal: Analyze locally files in your computer
14 //mLocalCAF: Analyze locally CAF files
15 //mPROOF: Analyze CAF files with PROOF
17 //---------------------------------------------------------------------------
18 //Settings to read locally several files, only for "mLocal" mode
19 //The different values are default, they can be set with environmental
20 //variables: INDIR, PATTERN, NFILES, respectivelly
21 char * kInDir = "/Users/Gustavo/Work/data/134908/pass1";
22 //char * kInDir = "/Users/Gustavo/Work/data/137366/";
23 char * kPattern = ""; // Data are in files kInDir/kPattern+i
24 Int_t kFile = 1; // Number of files
25 //---------------------------------------------------------------------------
26 //Collection file for grid analysis
27 char * kXML = "collection.xml";
28 //---------------------------------------------------------------------------
30 TString kInputData = "AOD"; //ESD, AOD, MC
31 TString kTreeName = "esdTree";
32 Bool_t kUsePhysSel = kFALSE;
33 Bool_t kEmbed = kTRUE;
35 void emcalReclusterize(Int_t mode=mLocal)
39 //sprintf(cmd, ".! rm -rf outputAOD.root") ;
40 //gROOT->ProcessLine(cmd) ;
41 //--------------------------------------------------------------------
42 // Load analysis libraries
43 // Look at the method below,
44 // change whatever you need for your analysis case
45 // ------------------------------------------------------------------
48 //-------------------------------------------------------------------------------------------------
49 //Create chain from ESD and from cross sections files, look below for options.
50 //-------------------------------------------------------------------------------------------------
51 if(kInputData == "ESD") kTreeName = "esdTree" ;
52 else if(kInputData == "AOD") kTreeName = "aodTree" ;
54 cout<<"Wrong data type "<<kInputData<<endl;
58 TChain *chain = new TChain(kTreeName) ;
59 CreateChain(mode, chain);
62 AliLog::SetGlobalLogLevel(AliLog::kError);//Minimum prints on screen
64 //--------------------------------------
65 // Make the analysis manager
66 //-------------------------------------
67 AliAnalysisManager *mgr = new AliAnalysisManager("Manager", "Manager");
70 AliAODHandler* aodoutHandler = new AliAODHandler();
71 aodoutHandler->SetOutputFileName("outputAOD.root");
73 aodoutHandler->SetCreateNonStandardAOD();
76 mgr->SetOutputEventHandler(aodoutHandler);
80 if(kInputData == "ESD")
83 AliESDInputHandler *esdHandler = new AliESDInputHandler();
84 mgr->SetInputEventHandler(esdHandler);
85 esdHandler->SetReadFriends(kFALSE);
86 cout<<"ESD handler "<<mgr->GetInputEventHandler()<<endl;
88 if(kInputData == "AOD")
91 AliAODInputHandler *aodHandler = new AliAODInputHandler();
92 mgr->SetInputEventHandler(aodHandler);
94 aodHandler->SetMergeEvents(kTRUE);
95 aodHandler->AddFriend("AliAOD.root");
98 cout<<"AOD handler "<<mgr->GetInputEventHandler()<<endl;
102 //mgr->SetDebugLevel(1);
104 //-------------------------------------------------------------------------
105 //Define task, put here any other task that you want to use.
106 //-------------------------------------------------------------------------
107 AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
108 AliAnalysisDataContainer *coutput1 = mgr->GetCommonOutputContainer();
110 // ESD physics selection task
111 if(kInputData == "ESD" && kUsePhysSel){
112 gROOT->LoadMacro("AddTaskPhysicsSelection.C");
113 AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection();
116 gROOT->LoadMacro("AddTaskEMCALClusterize.C");
117 AliAnalysisTaskEMCALClusterize * clusterize = AddTaskEMCALClusterize();
119 // AliAnalysisTaskEMCALClusterize * clusterize = new AliAnalysisTaskEMCALClusterize();
120 // clusterize->SetConfigFileName("ConfigEMCALClusterize.C");
121 // clusterize->SetOCDBPath("local://$ALICE_ROOT/OCDB");
122 // mgr->AddTask(clusterize);
124 // // Create containers for input/output
125 // AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer() ;
126 // AliAnalysisDataContainer *coutput1 = mgr->GetCommonOutputContainer() ;
128 // mgr->ConnectInput (clusterize, 0, cinput1 );
129 // mgr->ConnectOutput (clusterize, 0, coutput1 );
131 //-----------------------
133 //-----------------------
135 if (mode==mLocal || mode == mLocalCAF)
137 else if (mode==mPROOF)
139 else if (mode==mGRID)
144 mgr->StartAnalysis(smode.Data(),chain);
146 cout <<" Analysis ended sucessfully "<< endl ;
149 else cout << "Chain was not produced ! "<<endl;
153 void LoadLibraries(const anaModes mode) {
155 //--------------------------------------
156 // Load the needed libraries most of them already loaded by aliroot
157 //--------------------------------------
158 gSystem->Load("libTree.so");
159 gSystem->Load("libGeom.so");
160 gSystem->Load("libVMC.so");
161 gSystem->Load("libXMLIO.so");
162 gSystem->Load("libMatrix.so");
163 gSystem->Load("libPhysics.so");
165 //----------------------------------------------------------
166 // >>>>>>>>>>> Local mode <<<<<<<<<<<<<<
167 //----------------------------------------------------------
168 if (mode==mLocal || mode == mLocalCAF || mode == mGRID) {
169 //--------------------------------------------------------
170 // If you want to use already compiled libraries
171 // in the aliroot distribution
172 //--------------------------------------------------------
174 gSystem->Load("libSTEERBase.so");
175 gSystem->Load("libESD.so");
176 gSystem->Load("libAOD.so");
177 gSystem->Load("libANALYSIS.so");
178 gSystem->Load("libANALYSISalice.so");
179 gSystem->Load("libANALYSISalice.so");
180 gSystem->Load("libEMCALUtils.so");
182 //SetupPar("EMCALUtils");
183 //SetupPar("PWG4CaloCalib");
185 //TGeoManager::Import("geometry.root") ; //need file "geometry.root" in local dir!!!!
186 gSystem->Load("libPWG4CaloCalib.so");
189 // gSystem->Load("libPWG4omega3pi.so");
190 // gSystem->Load("libCORRFW.so");
191 // gSystem->Load("libPWGHFbase.so");
192 // gSystem->Load("libPWGmuon.so");
194 //--------------------------------------------------------
195 //If you want to use root and par files from aliroot
196 //--------------------------------------------------------
198 SetupPar("STEERBase");
201 SetupPar("ANALYSIS");
202 SetupPar("ANALYSISalice");
203 SetupPar("PHOSUtils");
204 SetupPar("EMCALUtils");
206 TGeoManager::Import("geometry.root") ; //need file "geometry.root" in local dir!!!!
207 SetupPar("PWG4CaloCalib");
211 //---------------------------------------------------------
212 // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
213 //---------------------------------------------------------
214 else if (mode==mPROOF) {
217 // Put appropriate username here
218 // TProof::Reset("proof://mgheata@lxb6046.cern.ch");
219 TProof::Open("proof://mgheata@lxb6046.cern.ch");
221 // gProof->ClearPackages();
222 // gProof->ClearPackage("ESD");
223 // gProof->ClearPackage("AOD");
224 // gProof->ClearPackage("ANALYSIS");
225 // gProof->ClearPackage("PWG4PartCorrBase");
226 // gProof->ClearPackage("PWG4PartCorrDep");
228 // Enable the STEERBase Package
229 gProof->UploadPackage("STEERBase.par");
230 gProof->EnablePackage("STEERBase");
231 // Enable the ESD Package
232 gProof->UploadPackage("ESD.par");
233 gProof->EnablePackage("ESD");
234 // Enable the AOD Package
235 gProof->UploadPackage("AOD.par");
236 gProof->EnablePackage("AOD");
237 // Enable the Analysis Package
238 gProof->UploadPackage("ANALYSIS.par");
239 gProof->EnablePackage("ANALYSIS");
240 // Enable the PHOS geometry Package
241 //gProof->UploadPackage("PHOSUtils.par");
242 //gProof->EnablePackage("PHOSUtils");
243 // Enable PartCorr analysis
244 gProof->UploadPackage("PWG4PartCorrBase.par");
245 gProof->EnablePackage("PWG4PartCorrBase");
246 gProof->UploadPackage("PWG4PartCorrDep.par");
247 gProof->EnablePackage("PWG4PartCorrDep");
248 gProof->ShowEnabledPackages();
253 void SetupPar(char* pararchivename)
255 //Load par files, create analysis libraries
256 //For testing, if par file already decompressed and modified
257 //classes then do not decompress.
259 TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
260 TString parpar(Form("%s.par", pararchivename)) ;
261 if ( gSystem->AccessPathName(parpar.Data()) ) {
262 gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
263 TString processline(Form(".! make %s", parpar.Data())) ;
264 gROOT->ProcessLine(processline.Data()) ;
265 gSystem->ChangeDirectory(cdir) ;
266 processline = Form(".! mv $ALICE_ROOT/%s .", parpar.Data()) ;
267 gROOT->ProcessLine(processline.Data()) ;
269 if ( gSystem->AccessPathName(pararchivename) ) {
270 TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
271 gROOT->ProcessLine(processline.Data());
274 TString ocwd = gSystem->WorkingDirectory();
275 gSystem->ChangeDirectory(pararchivename);
277 // check for BUILD.sh and execute
278 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
279 printf("*******************************\n");
280 printf("*** Building PAR archive ***\n");
281 cout<<pararchivename<<endl;
282 printf("*******************************\n");
284 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
285 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
289 // check for SETUP.C and execute
290 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
291 printf("*******************************\n");
292 printf("*** Setup PAR archive ***\n");
293 cout<<pararchivename<<endl;
294 printf("*******************************\n");
295 gROOT->Macro("PROOF-INF/SETUP.C");
298 gSystem->ChangeDirectory(ocwd.Data());
299 printf("Current dir: %s\n", ocwd.Data());
304 void CreateChain(const anaModes mode, TChain * chain){
305 //Fills chain with data
306 TString ocwd = gSystem->WorkingDirectory();
308 //-----------------------------------------------------------
309 //Analysis of CAF data locally and with PROOF
310 //-----------------------------------------------------------
311 if(mode ==mPROOF || mode ==mLocalCAF){
313 gROOT->LoadMacro("$ALICE_ROOT/PWG0/CreateESDChain.C");
314 // The second parameter is the number of input files in the chain
315 chain = CreateESDChain("ESD12001.txt", 5);
318 //---------------------------------------
319 //Local files analysis
320 //---------------------------------------
321 else if(mode == mLocal){
322 //If you want to add several ESD files sitting in a common directory INDIR
323 //Specify as environmental variables the directory (INDIR), the number of files
324 //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
326 if(gSystem->Getenv("INDIR"))
327 kInDir = gSystem->Getenv("INDIR") ;
328 else cout<<"INDIR not set, use default: "<<kInDir<<endl;
330 if(gSystem->Getenv("PATTERN"))
331 kPattern = gSystem->Getenv("PATTERN") ;
332 else cout<<"PATTERN not set, use default: "<<kPattern<<endl;
334 if(gSystem->Getenv("NFILES"))
335 kFile = atoi(gSystem->Getenv("NFILES")) ;
336 else cout<<"NFILES not set, use default: "<<kFile<<endl;
338 //Check if env variables are set and are correct
339 if ( kInDir && kFile) {
340 printf("Get %d files from directory %s\n",kFile,kInDir);
341 if ( ! gSystem->cd(kInDir) ) {//check if ESDs directory exist
342 printf("%s does not exist\n", kInDir) ;
347 cout<<"INDIR : "<<kInDir<<endl;
348 cout<<"NFILES : "<<kFile<<endl;
349 cout<<"PATTERN : " <<kPattern<<endl;
352 if(kInputData == "ESD") datafile = "AliESDs.root" ;
353 else if(kInputData == "AOD") datafile = "AliAODs.root" ;
354 else if(kInputData == "MC") datafile = "galice.root" ;
356 //Loop on ESD files, add them to chain
361 for (event = 0 ; event < kFile ; event++) {
362 sprintf(file, "%s/%s%d/%s", kInDir,kPattern,event,datafile.Data()) ;
364 //Check if file exists and add it, if not skip it
365 if ( fESD = TFile::Open(file)) {
366 if ( fESD->Get(kTreeName) ) {
367 printf("++++ Adding %s\n", file) ;
368 chain->AddFile(file);
372 printf("---- Skipping %s\n", file) ;
376 printf("number of entries # %lld, skipped %d\n", chain->GetEntries(), skipped*100) ;
379 TString input = "AliESDs.root" ;
380 cout<<">>>>>> No list added, take a single file <<<<<<<<< "<<input<<endl;
381 chain->AddFile(input);
384 }// local files analysis
386 //------------------------------
388 //-----------------------------
389 else if(mode == mGRID){
390 //Get colection file. It is specified by the environmental
393 if(gSystem->Getenv("XML") )
394 kXML = gSystem->Getenv("XML");
396 sprintf(kXML, "collection.xml") ;
398 if (!TFile::Open(kXML)) {
399 printf("No collection file with name -- %s -- was found\n",kXML);
402 else cout<<"XML file "<<kXML<<endl;
404 //Load necessary libraries and connect to the GRID
405 gSystem->Load("libNetx.so") ;
406 gSystem->Load("libRAliEn.so");
407 TGrid::Connect("alien://") ;
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);
413 AliError(Form("%s not found", kXML)) ;
416 TGridResult* result = collection->GetGridResult("",0 ,0);
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) ;
427 gSystem->ChangeDirectory(ocwd.Data());