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 = "/user/data/files/";
22 char * kPattern = ""; // Data are in files kInDir/kPattern+i
23 Int_t kFile = 1; // Number of files
24 //---------------------------------------------------------------------------
25 //Collection file for grid analysis
26 char * kXML = "collection.xml";
27 //---------------------------------------------------------------------------
29 const TString kInputData = "ESD"; //ESD, AOD, MC
30 TString kTreeName = "esdTree";
31 Bool_t kUsePhysSel = kFALSE;
33 void emcalReclusterize(Int_t mode=mLocal)
37 sprintf(cmd, ".! rm -rf aod.root") ;
38 gROOT->ProcessLine(cmd) ;
39 //--------------------------------------------------------------------
40 // Load analysis libraries
41 // Look at the method below,
42 // change whatever you need for your analysis case
43 // ------------------------------------------------------------------
45 //gSystem->Unload("libPWG4CaloCalib.so");
46 //Try to set the new library
47 //gSystem->Load("./PWG4CaloCalib/libPWG4CaloCalib.so");
48 //gSystem->ListLibraries();
50 //-------------------------------------------------------------------------------------------------
51 //Create chain from ESD and from cross sections files, look below for options.
52 //-------------------------------------------------------------------------------------------------
53 if(kInputData == "ESD") kTreeName = "esdTree" ;
54 else if(kInputData == "AOD") kTreeName = "aodTree" ;
56 cout<<"Wrong data type "<<kInputData<<endl;
60 TChain *chain = new TChain(kTreeName) ;
61 CreateChain(mode, chain);
64 AliLog::SetGlobalLogLevel(AliLog::kError);//Minimum prints on screen
66 //--------------------------------------
67 // Make the analysis manager
68 //-------------------------------------
69 AliAnalysisManager *mgr = new AliAnalysisManager("Manager", "Manager");
72 AliAODHandler* aodoutHandler = new AliAODHandler();
73 aodoutHandler->SetOutputFileName("aod.root");
74 ////aodoutHandler->SetCreateNonStandardAOD();
75 mgr->SetOutputEventHandler(aodoutHandler);
78 if(kInputData == "ESD")
81 AliESDInputHandler *esdHandler = new AliESDInputHandler();
82 mgr->SetInputEventHandler(esdHandler);
83 esdHandler->SetReadFriends(kFALSE);
84 cout<<"ESD handler "<<mgr->GetInputEventHandler()<<endl;
86 if(kInputData == "AOD")
89 AliAODInputHandler *aodHandler = new AliAODInputHandler();
90 mgr->SetInputEventHandler(aodHandler);
91 cout<<"AOD handler "<<mgr->GetInputEventHandler()<<endl;
95 mgr->SetDebugLevel(1);
97 // Create containers for input/output
98 AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
99 AliAnalysisDataContainer *coutput1 = mgr->GetCommonOutputContainer();
101 //-------------------------------------------------------------------------
102 //Define task, put here any other task that you want to use.
103 //-------------------------------------------------------------------------
105 // ESD physics selection task
106 if(kInputData == "ESD" && kUsePhysSel){
107 gROOT->LoadMacro("AddTaskPhysicsSelection.C");
108 AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection();
111 AliAnalysisTaskEMCALClusterize * clusterize = new AliAnalysisTaskEMCALClusterize("EMCALClusterize");
112 if(kUsePhysSel)clusterize->SelectCollisionCandidates();
113 //clusterize->SetOCDBPath("local://$ALICE_ROOT/OCDB"); // by default it is raw://
114 clusterize->FillAODFile(kFALSE); // fill aod.root with clusters?, not really needed for analysis.
115 clusterize->JustUnfold(kTRUE); // if TRUE, do just unfolding, do not recluster cells
116 AliEMCALRecParam * params = clusterize->GetRecParam();
117 params->SetClusterizerFlag(AliEMCALRecParam::kClusterizerNxN);
118 params->SetClusteringThreshold(0.1); // 100 MeV
119 params->SetMinECut(0.01); //10 MeV
120 params->SetUnfold(kFALSE);
122 params->SetTimeCut(1e6);///Open this cut for AODs
123 params->SetTimeMin(-1);//Open this cut for AODs
124 params->SetTimeMax(1e6);//Open this cut for AODs
126 // TGeoHMatrix *matrix[4];
128 // double rotationMatrix[4][9] = {-0.014585, -0.999892, -0.002031, 0.999892, -0.014589, 0.001950, -0.001979, -0.002003, 0.999996,
129 // -0.014585, 0.999892, 0.002031, 0.999892, 0.014589, -0.001950, -0.001979, 0.002003, -0.999996,
130 // -0.345861, -0.938280, -0.003412, 0.938281, -0.345869, 0.001950, -0.003010, -0.002527, 0.999992,
131 // -0.345861, 0.938280, 0.003412, 0.938281, 0.345869, -0.001950, -0.003010, 0.002527, -0.999992};
133 // double translationMatrix[4][3] = {0.367264, 446.508738, 175.97185+0.3,
134 // 1.078181, 445.826258, -174.026758+0.3,
135 // -153.843916, 418.304256, 175.956905+0.8,
136 // -152.649580, 417.621779, -174.040392+0.8};
139 // double rotationMatrix[4][9] = {-0.014587, -0.999892, -0.002031, 0.999892, -0.014591, 0.001979, -0.002009, -0.002002, 0.999996,
140 // -0.014587, 0.999892, 0.002031, 0.999892, 0.014591, -0.001979, -0.002009, 0.002002, -0.999996,
141 // -0.345864, -0.938278, -0.003412, 0.938276, -0.345874, 0.003010, -0.004004, -0.002161, 0.999990,
142 // -0.345864, 0.938278, 0.003412, 0.938276, 0.345874, -0.003010, -0.004004, 0.002161, -0.999990};
144 // double translationMatrix[4][3] = {0.351659, 447.576446, 176.269742,
145 // 1.062577, 446.893974, -173.728870,
146 // -154.213287, 419.306156, 176.753692,
147 // -153.018950, 418.623681, -173.243605};
149 // for(int j=0; j<4; j++)
151 // matrix[j] = new TGeoHMatrix();
152 // matrix[j]->SetRotation(rotationMatrix[j]);
153 // matrix[j]->SetTranslation(translationMatrix[j]);
154 // matrix[j]->Print();
155 // clusterize->SetGeometryMatrixInSM(matrix[j],j);
159 // clusterize->SwitchOnLoadOwnEMCALGeometryMatrices();
162 mgr->AddTask(clusterize);
163 mgr->ConnectInput (clusterize, 0, cinput1);
164 mgr->ConnectOutput (clusterize, 0, coutput1 );
167 //-----------------------
169 //-----------------------
171 if (mode==mLocal || mode == mLocalCAF)
173 else if (mode==mPROOF)
175 else if (mode==mGRID)
180 mgr->StartAnalysis(smode.Data(),chain);
182 cout <<" Analysis ended sucessfully "<< endl ;
185 else cout << "Chain was not produced ! "<<endl;
189 void LoadLibraries(const anaModes mode) {
191 //--------------------------------------
192 // Load the needed libraries most of them already loaded by aliroot
193 //--------------------------------------
194 gSystem->Load("libTree.so");
195 gSystem->Load("libGeom.so");
196 gSystem->Load("libVMC.so");
197 gSystem->Load("libXMLIO.so");
198 gSystem->Load("libMatrix.so");
199 gSystem->Load("libPhysics.so");
201 //----------------------------------------------------------
202 // >>>>>>>>>>> Local mode <<<<<<<<<<<<<<
203 //----------------------------------------------------------
204 if (mode==mLocal || mode == mLocalCAF || mode == mGRID) {
205 //--------------------------------------------------------
206 // If you want to use already compiled libraries
207 // in the aliroot distribution
208 //--------------------------------------------------------
210 gSystem->Load("libSTEERBase.so");
211 gSystem->Load("libESD.so");
212 gSystem->Load("libAOD.so");
213 gSystem->Load("libANALYSIS.so");
214 gSystem->Load("libANALYSISalice.so");
215 gSystem->Load("libANALYSISalice.so");
216 gSystem->Load("libEMCALUtils.so");
218 //SetupPar("EMCALUtils");
219 //SetupPar("PWG4CaloCalib");
221 TGeoManager::Import("geometry.root") ; //need file "geometry.root" in local dir!!!!
222 gSystem->Load("libPWG4CaloCalib.so");
225 // gSystem->Load("libPWG4omega3pi.so");
226 // gSystem->Load("libCORRFW.so");
227 // gSystem->Load("libPWG3base.so");
228 // gSystem->Load("libPWG3muon.so");
230 //--------------------------------------------------------
231 //If you want to use root and par files from aliroot
232 //--------------------------------------------------------
234 SetupPar("STEERBase");
237 SetupPar("ANALYSIS");
238 SetupPar("ANALYSISalice");
239 SetupPar("PHOSUtils");
240 SetupPar("EMCALUtils");
242 TGeoManager::Import("geometry.root") ; //need file "geometry.root" in local dir!!!!
243 SetupPar("PWG4CaloCalib");
247 //---------------------------------------------------------
248 // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
249 //---------------------------------------------------------
250 else if (mode==mPROOF) {
253 // Put appropriate username here
254 // TProof::Reset("proof://mgheata@lxb6046.cern.ch");
255 TProof::Open("proof://mgheata@lxb6046.cern.ch");
257 // gProof->ClearPackages();
258 // gProof->ClearPackage("ESD");
259 // gProof->ClearPackage("AOD");
260 // gProof->ClearPackage("ANALYSIS");
261 // gProof->ClearPackage("PWG4PartCorrBase");
262 // gProof->ClearPackage("PWG4PartCorrDep");
264 // Enable the STEERBase Package
265 gProof->UploadPackage("STEERBase.par");
266 gProof->EnablePackage("STEERBase");
267 // Enable the ESD Package
268 gProof->UploadPackage("ESD.par");
269 gProof->EnablePackage("ESD");
270 // Enable the AOD Package
271 gProof->UploadPackage("AOD.par");
272 gProof->EnablePackage("AOD");
273 // Enable the Analysis Package
274 gProof->UploadPackage("ANALYSIS.par");
275 gProof->EnablePackage("ANALYSIS");
276 // Enable the PHOS geometry Package
277 //gProof->UploadPackage("PHOSUtils.par");
278 //gProof->EnablePackage("PHOSUtils");
279 // Enable PartCorr analysis
280 gProof->UploadPackage("PWG4PartCorrBase.par");
281 gProof->EnablePackage("PWG4PartCorrBase");
282 gProof->UploadPackage("PWG4PartCorrDep.par");
283 gProof->EnablePackage("PWG4PartCorrDep");
284 gProof->ShowEnabledPackages();
289 void SetupPar(char* pararchivename)
291 //Load par files, create analysis libraries
292 //For testing, if par file already decompressed and modified
293 //classes then do not decompress.
295 TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
296 TString parpar(Form("%s.par", pararchivename)) ;
297 if ( gSystem->AccessPathName(parpar.Data()) ) {
298 gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
299 TString processline(Form(".! make %s", parpar.Data())) ;
300 gROOT->ProcessLine(processline.Data()) ;
301 gSystem->ChangeDirectory(cdir) ;
302 processline = Form(".! mv $ALICE_ROOT/%s .", parpar.Data()) ;
303 gROOT->ProcessLine(processline.Data()) ;
305 if ( gSystem->AccessPathName(pararchivename) ) {
306 TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
307 gROOT->ProcessLine(processline.Data());
310 TString ocwd = gSystem->WorkingDirectory();
311 gSystem->ChangeDirectory(pararchivename);
313 // check for BUILD.sh and execute
314 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
315 printf("*******************************\n");
316 printf("*** Building PAR archive ***\n");
317 cout<<pararchivename<<endl;
318 printf("*******************************\n");
320 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
321 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
325 // check for SETUP.C and execute
326 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
327 printf("*******************************\n");
328 printf("*** Setup PAR archive ***\n");
329 cout<<pararchivename<<endl;
330 printf("*******************************\n");
331 gROOT->Macro("PROOF-INF/SETUP.C");
334 gSystem->ChangeDirectory(ocwd.Data());
335 printf("Current dir: %s\n", ocwd.Data());
340 void CreateChain(const anaModes mode, TChain * chain){
341 //Fills chain with data
342 TString ocwd = gSystem->WorkingDirectory();
344 //-----------------------------------------------------------
345 //Analysis of CAF data locally and with PROOF
346 //-----------------------------------------------------------
347 if(mode ==mPROOF || mode ==mLocalCAF){
349 gROOT->LoadMacro("$ALICE_ROOT/PWG0/CreateESDChain.C");
350 // The second parameter is the number of input files in the chain
351 chain = CreateESDChain("ESD12001.txt", 5);
354 //---------------------------------------
355 //Local files analysis
356 //---------------------------------------
357 else if(mode == mLocal){
358 //If you want to add several ESD files sitting in a common directory INDIR
359 //Specify as environmental variables the directory (INDIR), the number of files
360 //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
362 if(gSystem->Getenv("INDIR"))
363 kInDir = gSystem->Getenv("INDIR") ;
364 else cout<<"INDIR not set, use default: "<<kInDir<<endl;
366 if(gSystem->Getenv("PATTERN"))
367 kPattern = gSystem->Getenv("PATTERN") ;
368 else cout<<"PATTERN not set, use default: "<<kPattern<<endl;
370 if(gSystem->Getenv("NFILES"))
371 kFile = atoi(gSystem->Getenv("NFILES")) ;
372 else cout<<"NFILES not set, use default: "<<kFile<<endl;
374 //Check if env variables are set and are correct
375 if ( kInDir && kFile) {
376 printf("Get %d files from directory %s\n",kFile,kInDir);
377 if ( ! gSystem->cd(kInDir) ) {//check if ESDs directory exist
378 printf("%s does not exist\n", kInDir) ;
383 cout<<"INDIR : "<<kInDir<<endl;
384 cout<<"NFILES : "<<kFile<<endl;
385 cout<<"PATTERN : " <<kPattern<<endl;
388 if(kInputData == "ESD") datafile = "AliESDs.root" ;
389 else if(kInputData == "AOD") datafile = "AliAODs.root" ;
390 else if(kInputData == "MC") datafile = "galice.root" ;
392 //Loop on ESD files, add them to chain
397 for (event = 0 ; event < kFile ; event++) {
398 sprintf(file, "%s/%s%d/%s", kInDir,kPattern,event,datafile.Data()) ;
400 //Check if file exists and add it, if not skip it
401 if ( fESD = TFile::Open(file)) {
402 if ( fESD->Get(kTreeName) ) {
403 printf("++++ Adding %s\n", file) ;
404 chain->AddFile(file);
408 printf("---- Skipping %s\n", file) ;
412 printf("number of entries # %lld, skipped %d\n", chain->GetEntries(), skipped*100) ;
415 TString input = "AliESDs.root" ;
416 cout<<">>>>>> No list added, take a single file <<<<<<<<< "<<input<<endl;
417 chain->AddFile(input);
420 }// local files analysis
422 //------------------------------
424 //-----------------------------
425 else if(mode == mGRID){
426 //Get colection file. It is specified by the environmental
429 if(gSystem->Getenv("XML") )
430 kXML = gSystem->Getenv("XML");
432 sprintf(kXML, "collection.xml") ;
434 if (!TFile::Open(kXML)) {
435 printf("No collection file with name -- %s -- was found\n",kXML);
438 else cout<<"XML file "<<kXML<<endl;
440 //Load necessary libraries and connect to the GRID
441 gSystem->Load("libNetx.so") ;
442 gSystem->Load("libRAliEn.so");
443 TGrid::Connect("alien://") ;
445 //Feed Grid with collection file
446 //TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\", 0)", kXML));
447 TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
449 AliError(Form("%s not found", kXML)) ;
452 TGridResult* result = collection->GetGridResult("",0 ,0);
454 // Makes the ESD chain
455 printf("*** Getting the Chain ***\n");
456 for (Int_t index = 0; index < result->GetEntries(); index++) {
457 TString alienURL = result->GetKey(index, "turl") ;
458 cout << "================== " << alienURL << endl ;
459 chain->Add(alienURL) ;
463 gSystem->ChangeDirectory(ocwd.Data());