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 = kTRUE;
33 void anaCaloFilter(Int_t mode=mLocal)
37 sprintf(cmd, ".! rm -rf AliAOD.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 // ------------------------------------------------------------------
46 //-------------------------------------------------------------------------------------------------
47 //Create chain from ESD and from cross sections files, look below for options.
48 //-------------------------------------------------------------------------------------------------
49 if(kInputData == "ESD") kTreeName = "esdTree" ;
50 else if(kInputData == "AOD") kTreeName = "aodTree" ;
52 cout<<"Wrong data type "<<kInputData<<endl;
56 TChain *chain = new TChain(kTreeName) ;
57 CreateChain(mode, chain);
60 AliLog::SetGlobalLogLevel(AliLog::kError);//Minimum prints on screen
62 //--------------------------------------
63 // Make the analysis manager
64 //-------------------------------------
65 AliAnalysisManager *mgr = new AliAnalysisManager("Manager", "Manager");
68 AliAODHandler* aodoutHandler = new AliAODHandler();
69 aodoutHandler->SetOutputFileName("AliAOD.root");
70 ////aodoutHandler->SetCreateNonStandardAOD();
71 mgr->SetOutputEventHandler(aodoutHandler);
74 if(kInputData == "ESD")
77 AliESDInputHandler *esdHandler = new AliESDInputHandler();
78 mgr->SetInputEventHandler(esdHandler);
79 esdHandler->SetReadFriends(kFALSE);
80 cout<<"ESD handler "<<mgr->GetInputEventHandler()<<endl;
82 if(kInputData == "AOD")
85 AliAODInputHandler *aodHandler = new AliAODInputHandler();
86 mgr->SetInputEventHandler(aodHandler);
87 cout<<"AOD handler "<<mgr->GetInputEventHandler()<<endl;
91 // mgr->SetDebugLevel(1);
93 //-------------------------------------------------------------------------
94 //Define task, put here any other task that you want to use.
95 //-------------------------------------------------------------------------
96 // ESD physics selection task
97 if(kInputData == "ESD" && kUsePhysSel)
99 gROOT->LoadMacro("$ALICE_ROOT/OADB/macros/AddTaskPhysicsSelection.C");
100 AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection();
103 gROOT->LoadMacro("AddTaskCaloFilter.C");
104 AliAnalysisTaskCaloFilter* filter = AddTaskCaloFilter();
106 //AliAnalysisTaskCaloFilter * filter = new AliAnalysisTaskCaloFilter();
107 //filter->SetConfigFileName("ConfigCaloFilter.C");
108 //mgr->AddTask(filter);
110 // Create containers for input/output
111 AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
112 AliAnalysisDataContainer *coutput1 = mgr->GetCommonOutputContainer();
113 AliAnalysisDataContainer *coutntuple = mgr->CreateContainer("EventNtuple", TNtuple::Class(),
114 AliAnalysisManager::kOutputContainer, "eventselection.root");
116 mgr->ConnectInput (filter, 0, cinput1);
117 mgr->ConnectOutput (filter, 0, coutput1 );
118 mgr->ConnectOutput (filter, 1, coutntuple );
120 //-----------------------
122 //-----------------------
124 if (mode==mLocal || mode == mLocalCAF)
126 else if (mode==mPROOF)
128 else if (mode==mGRID)
133 mgr->StartAnalysis(smode.Data(),chain);
135 cout <<" Analysis ended sucessfully "<< endl ;
138 else cout << "Chain was not produced ! "<<endl;
140 //sprintf(cmd, ".! rm -rf CorrectionFiles") ;
144 void LoadLibraries(const anaModes mode) {
146 //--------------------------------------
147 // Load the needed libraries most of them already loaded by aliroot
148 //--------------------------------------
149 gSystem->Load("libTree");
150 gSystem->Load("libGeom");
151 gSystem->Load("libVMC");
152 gSystem->Load("libXMLIO");
153 gSystem->Load("libMatrix");
154 gSystem->Load("libPhysics");
156 //----------------------------------------------------------
157 // >>>>>>>>>>> Local mode <<<<<<<<<<<<<<
158 //----------------------------------------------------------
159 if (mode==mLocal || mode == mLocalCAF || mode == mGRID) {
160 //--------------------------------------------------------
161 // If you want to use already compiled libraries
162 // in the aliroot distribution
163 //--------------------------------------------------------
165 gSystem->Load("libSTEERBase");
166 gSystem->Load("libESD");
167 gSystem->Load("libAOD");
168 gSystem->Load("libANALYSIS");
169 gSystem->Load("libANALYSISalice");
170 gSystem->Load("libANALYSISalice");
171 gSystem->Load("libCORRFW");
172 gSystem->Load("libPHOSUtils");
173 gSystem->Load("libEMCALUtils");
174 gSystem->Load("libPWGGACaloTasks");
176 //--------------------------------------------------------
177 //If you want to use root and par files from aliroot
178 //--------------------------------------------------------
180 SetupPar("STEERBase");
183 SetupPar("ANALYSIS");
184 SetupPar("ANALYSISalice");
185 SetupPar("PHOSUtils");
186 SetupPar("EMCALUtils");
188 TGeoManager::Import("geometry.root") ; //need file "geometry.root" in local dir!!!!
189 SetupPar("PWGGACaloTasks");
193 //---------------------------------------------------------
194 // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
195 //---------------------------------------------------------
196 else if (mode==mPROOF) {
199 // Put appropriate username here
200 // TProof::Reset("proof://mgheata@lxb6046.cern.ch");
201 TProof::Open("proof://mgheata@lxb6046.cern.ch");
203 // gProof->ClearPackages();
204 // gProof->ClearPackage("ESD");
205 // gProof->ClearPackage("AOD");
206 // gProof->ClearPackage("ANALYSIS");
208 // Enable the STEERBase Package
209 gProof->UploadPackage("STEERBase.par");
210 gProof->EnablePackage("STEERBase");
211 // Enable the ESD Package
212 gProof->UploadPackage("ESD.par");
213 gProof->EnablePackage("ESD");
214 // Enable the AOD Package
215 gProof->UploadPackage("AOD.par");
216 gProof->EnablePackage("AOD");
217 // Enable the Analysis Package
218 gProof->UploadPackage("ANALYSIS.par");
219 gProof->EnablePackage("ANALYSIS");
220 // Enable the PHOS geometry Package
221 //gProof->UploadPackage("PHOSUtils.par");
222 //gProof->EnablePackage("PHOSUtils");
223 gProof->ShowEnabledPackages();
228 void SetupPar(char* pararchivename)
230 //Load par files, create analysis libraries
231 //For testing, if par file already decompressed and modified
232 //classes then do not decompress.
234 TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
235 TString parpar(Form("%s.par", pararchivename)) ;
236 if ( gSystem->AccessPathName(parpar.Data()) ) {
237 gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
238 TString processline(Form(".! make %s", parpar.Data())) ;
239 gROOT->ProcessLine(processline.Data()) ;
240 gSystem->ChangeDirectory(cdir) ;
241 processline = Form(".! mv $ALICE_ROOT/%s .", parpar.Data()) ;
242 gROOT->ProcessLine(processline.Data()) ;
244 if ( gSystem->AccessPathName(pararchivename) ) {
245 TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
246 gROOT->ProcessLine(processline.Data());
249 TString ocwd = gSystem->WorkingDirectory();
250 gSystem->ChangeDirectory(pararchivename);
252 // check for BUILD.sh and execute
253 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
254 printf("*******************************\n");
255 printf("*** Building PAR archive ***\n");
256 cout<<pararchivename<<endl;
257 printf("*******************************\n");
259 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
260 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
264 // check for SETUP.C and execute
265 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
266 printf("*******************************\n");
267 printf("*** Setup PAR archive ***\n");
268 cout<<pararchivename<<endl;
269 printf("*******************************\n");
270 gROOT->Macro("PROOF-INF/SETUP.C");
273 gSystem->ChangeDirectory(ocwd.Data());
274 printf("Current dir: %s\n", ocwd.Data());
279 void CreateChain(const anaModes mode, TChain * chain){
280 //Fills chain with data
281 TString ocwd = gSystem->WorkingDirectory();
283 //-----------------------------------------------------------
284 //Analysis of CAF data locally and with PROOF
285 //-----------------------------------------------------------
286 if(mode ==mPROOF || mode ==mLocalCAF){
288 gROOT->LoadMacro("$ALICE_ROOT/PWG0/CreateESDChain.C");
289 // The second parameter is the number of input files in the chain
290 chain = CreateESDChain("ESD12001.txt", 5);
293 //---------------------------------------
294 //Local files analysis
295 //---------------------------------------
296 else if(mode == mLocal){
297 //If you want to add several ESD files sitting in a common directory INDIR
298 //Specify as environmental variables the directory (INDIR), the number of files
299 //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
301 if(gSystem->Getenv("INDIR"))
302 kInDir = gSystem->Getenv("INDIR") ;
303 else cout<<"INDIR not set, use default: "<<kInDir<<endl;
305 if(gSystem->Getenv("PATTERN"))
306 kPattern = gSystem->Getenv("PATTERN") ;
307 else cout<<"PATTERN not set, use default: "<<kPattern<<endl;
309 if(gSystem->Getenv("NFILES"))
310 kFile = atoi(gSystem->Getenv("NFILES")) ;
311 else cout<<"NFILES not set, use default: "<<kFile<<endl;
313 //Check if env variables are set and are correct
314 if ( kInDir && kFile) {
315 printf("Get %d files from directory %s\n",kFile,kInDir);
316 if ( ! gSystem->cd(kInDir) ) {//check if ESDs directory exist
317 printf("%s does not exist\n", kInDir) ;
322 cout<<"INDIR : "<<kInDir<<endl;
323 cout<<"NFILES : "<<kFile<<endl;
324 cout<<"PATTERN : " <<kPattern<<endl;
327 if(kInputData == "ESD") datafile = "AliESDs.root" ;
328 else if(kInputData == "AOD") datafile = "AliAOD.root" ;
329 else if(kInputData == "MC") datafile = "galice.root" ;
331 //Loop on ESD files, add them to chain
336 for (event = 0 ; event < kFile ; event++) {
337 sprintf(file, "%s/%s%d/%s", kInDir,kPattern,event,datafile.Data()) ;
339 //Check if file exists and add it, if not skip it
340 if ( fESD = TFile::Open(file)) {
341 if ( fESD->Get(kTreeName) ) {
342 printf("++++ Adding %s\n", file) ;
343 chain->AddFile(file);
347 printf("---- Skipping %s\n", file) ;
351 printf("number of entries # %lld, skipped %d\n", chain->GetEntries(), skipped*100) ;
354 TString input = "AliESDs.root" ;
355 cout<<">>>>>> No list added, take a single file <<<<<<<<< "<<input<<endl;
356 chain->AddFile(input);
359 }// local files analysis
361 //------------------------------
363 //-----------------------------
364 else if(mode == mGRID){
365 //Get colection file. It is specified by the environmental
368 if(gSystem->Getenv("XML") )
369 kXML = gSystem->Getenv("XML");
371 sprintf(kXML, "collection.xml") ;
373 if (!TFile::Open(kXML)) {
374 printf("No collection file with name -- %s -- was found\n",kXML);
377 else cout<<"XML file "<<kXML<<endl;
379 //Load necessary libraries and connect to the GRID
380 gSystem->Load("libNetx") ;
381 gSystem->Load("libRAliEn");
382 TGrid::Connect("alien://") ;
384 //Feed Grid with collection file
385 //TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\", 0)", kXML));
386 TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
388 AliError(Form("%s not found", kXML)) ;
391 TGridResult* result = collection->GetGridResult("",0 ,0);
393 // Makes the ESD chain
394 printf("*** Getting the Chain ***\n");
395 for (Int_t index = 0; index < result->GetEntries(); index++) {
396 TString alienURL = result->GetKey(index, "turl") ;
397 cout << "================== " << alienURL << endl ;
398 chain->Add(alienURL) ;
402 gSystem->ChangeDirectory(ocwd.Data());