AliPhysics  a5cd6b6 (a5cd6b6)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
emcalReclusterize.C
Go to the documentation of this file.
1 //--------------------------------------------------
2 // Example macro to do Calorimeters filtering
3 // copy ESDs into AODs
4 //
5 // Pay attention to the options and definitions
6 // set in the lines below
7 //
8 // Author : Gustavo Conesa Balbastre (INFN-LNF)
9 //
10 //-------------------------------------------------
11 //--------------------------------------------------
23 //
24 //-------------------------------------------------
25 
27 //mLocal: Analyze locally files in your computer
28 //mLocalCAF: Analyze locally CAF files
29 //mPROOF: Analyze CAF files with PROOF
30 
31 //---------------------------------------------------------------------------
32 //Settings to read locally several files, only for "mLocal" mode
33 //The different values are default, they can be set with environmental
34 //variables: INDIR, PATTERN, NFILES, respectivelly
35 char * kInDir = "/Users/Gustavo/Work/data/134908/pass1";
36 //char * kInDir = "/Users/Gustavo/Work/data/137366/";
37 char * kPattern = ""; // Data are in files kInDir/kPattern+i
38 Int_t kFile = 1; // Number of files
39 //---------------------------------------------------------------------------
40 //Collection file for grid analysis
41 char * kXML = "collection.xml";
42 //---------------------------------------------------------------------------
43 
44 TString kInputData = "AOD"; //ESD, AOD, MC
45 TString kTreeName = "esdTree";
47 Bool_t kEmbed = kTRUE;
48 
50 {
51  // Main
52  //char cmd[200] ;
53  //sprintf(cmd, ".! rm -rf outputAOD.root") ;
54  //gROOT->ProcessLine(cmd) ;
55  //--------------------------------------------------------------------
56  // Load analysis libraries
57  // Look at the method below,
58  // change whatever you need for your analysis case
59  // ------------------------------------------------------------------
61 
62  //-------------------------------------------------------------------------------------------------
63  //Create chain from ESD and from cross sections files, look below for options.
64  //-------------------------------------------------------------------------------------------------
65  if(kInputData == "ESD") kTreeName = "esdTree" ;
66  else if(kInputData == "AOD") kTreeName = "aodTree" ;
67  else {
68  cout<<"Wrong data type "<<kInputData<<endl;
69  break;
70  }
71 
72  TChain *chain = new TChain(kTreeName) ;
73  CreateChain(mode, chain);
74 
75  if(chain){
76  AliLog::SetGlobalLogLevel(AliLog::kError);//Minimum prints on screen
77 
78  //--------------------------------------
79  // Make the analysis manager
80  //-------------------------------------
81  AliAnalysisManager *mgr = new AliAnalysisManager("Manager", "Manager");
82 
83  // AOD output handler
84  AliAODHandler* aodoutHandler = new AliAODHandler();
85  aodoutHandler->SetOutputFileName("outputAOD.root");
86  if(kEmbed){
87  aodoutHandler->SetCreateNonStandardAOD();
88  kInputData = "AOD";
89  }
90  mgr->SetOutputEventHandler(aodoutHandler);
91 
92 
93  //input
94  if(kInputData == "ESD")
95  {
96  // ESD handler
97  AliESDInputHandler *esdHandler = new AliESDInputHandler();
98  mgr->SetInputEventHandler(esdHandler);
99  esdHandler->SetReadFriends(kFALSE);
100  cout<<"ESD handler "<<mgr->GetInputEventHandler()<<endl;
101  }
102  if(kInputData == "AOD")
103  {
104  // AOD handler
105  AliAODInputHandler *aodHandler = new AliAODInputHandler();
106  mgr->SetInputEventHandler(aodHandler);
107  if(kEmbed){
108  aodHandler->SetMergeEvents(kTRUE);
109  aodHandler->AddFriend("AliAOD.root");
110  }
111 
112  cout<<"AOD handler "<<mgr->GetInputEventHandler()<<endl;
113 
114  }
115 
116  //mgr->SetDebugLevel(1);
117 
118  //-------------------------------------------------------------------------
119  //Define task, put here any other task that you want to use.
120  //-------------------------------------------------------------------------
121  AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
122  AliAnalysisDataContainer *coutput1 = mgr->GetCommonOutputContainer();
123 
124  // ESD physics selection task
125  if(kInputData == "ESD" && kUsePhysSel){
126  gROOT->LoadMacro("AddTaskPhysicsSelection.C");
127  AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection();
128  }
129 
130  gROOT->LoadMacro("$ALICE_PHYSICS/PWGPP/EMCAL/macros/AddTaskEMCALClusterize.C");
131 
132  Bool_t kMC = kFALSE; // extra checks in case of MC analysis
133  Bool_t outAOD = kFALSE ; // Generate output AOD with new clusters
134  Bool_t calibEE = kTRUE; // It is set automatically, but here we force to use it or not in any case
135  Bool_t calibTT = kTRUE; // It is set automatically, but here we force to use it or not in any case
136  if(kRun < 122195 || (kRun > 126437 && kRun < 136851) || kMC) calibTT=kFALSE ; // Recalibration parameters not available for LHC10a,b,c,e,f,g
137  Bool_t badMap = kTRUE; // It is set automatically, but here we force to use it or not in any case
138  Bool_t clTM = kTRUE;
139  Bool_t exo = kTRUE; // Remove exotic cells
140  Bool_t clnonlin = kTRUE; // Apply non linearity (clusterization)
141  Int_t minEcell = 50; // 50 MeV (10 MeV used in reconstruction)
142  Int_t minEseed = 100; // 100 MeV
143  Int_t dTime = 0; // default, 250 ns
144  Int_t wTime = 0; // default 425 < T < 825 ns, careful if time calibration is on
145  Int_t unfMinE = 15; // Remove cells with less than 15 MeV from cluster after unfolding
146  Int_t unfFrac = 1; // Remove cells with less than 1% of cluster energy after unfolding
147 
148  TString arrayName = "";
149  TString clusterzerName = "V1"; // "V2", "NxN","V1Unfold"
150 
151  AliAnalysisTaskEMCALClusterize * clv1 = AddTaskEMCALClusterize(arrayNameV1,outAOD,kMC,exo,clusterizerName,clTrigger, clTM,
152  minEcell,minEseed,dTime,wTime,unfMinE,unfFrac,
153  calibEnergy,badMap,calibTime,nonlinear);
154 
155  // AliAnalysisTaskEMCALClusterize * clusterize = new AliAnalysisTaskEMCALClusterize();
156 // clusterize->SetConfigFileName("ConfigEMCALClusterize.C");
157 // clusterize->SetOCDBPath("local://$ALICE_ROOT/OCDB");
158 // mgr->AddTask(clusterize);
159 //
160 // // Create containers for input/output
161 // AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer() ;
162 // AliAnalysisDataContainer *coutput1 = mgr->GetCommonOutputContainer() ;
163 //
164 // mgr->ConnectInput (clusterize, 0, cinput1 );
165 // mgr->ConnectOutput (clusterize, 0, coutput1 );
166 
167  //-----------------------
168  // Run the analysis
169  //-----------------------
170  TString smode = "";
171  if (mode==mLocal || mode == mLocalCAF)
172  smode = "local";
173  else if (mode==mPROOF)
174  smode = "proof";
175  else if (mode==mGRID)
176  smode = "local";
177 
178  mgr->InitAnalysis();
179  mgr->PrintStatus();
180  mgr->StartAnalysis(smode.Data(),chain);
181 
182  cout <<" Analysis ended sucessfully "<< endl ;
183 
184  }
185  else cout << "Chain was not produced ! "<<endl;
186 
187 }
188 
190 
191  //--------------------------------------
192  // Load the needed libraries most of them already loaded by aliroot
193  //--------------------------------------
194  gSystem->Load("libTree");
195  gSystem->Load("libGeom");
196  gSystem->Load("libVMC");
197  gSystem->Load("libXMLIO");
198  gSystem->Load("libMatrix");
199  gSystem->Load("libPhysics");
200 
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  //--------------------------------------------------------
209 
210  gSystem->Load("libSTEERBase");
211  gSystem->Load("libESD");
212  gSystem->Load("libAOD");
213  gSystem->Load("libANALYSIS");
214  gSystem->Load("libANALYSISalice");
215  gSystem->Load("libANALYSISalice");
216 
217  //SetupPar("EMCALUtils");
218  //SetupPar("PWGPPEMCAL");
219 
220  gSystem->Load("libEMCALUtils");
221  gSystem->Load("libPWGPPEMCAL");
222 
223  }
224 
225  //---------------------------------------------------------
226  // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
227  //---------------------------------------------------------
228  else if (mode==mPROOF) {
229  //
230  // Connect to proof
231  // Put appropriate username here
232  // TProof::Reset("proof://mgheata@lxb6046.cern.ch");
233  TProof::Open("proof://mgheata@lxb6046.cern.ch");
234 
235  // gProof->ClearPackages();
236  // gProof->ClearPackage("ESD");
237  // gProof->ClearPackage("AOD");
238  // gProof->ClearPackage("ANALYSIS");
239 
240  // Enable the STEERBase Package
241  gProof->UploadPackage("STEERBase.par");
242  gProof->EnablePackage("STEERBase");
243  // Enable the ESD Package
244  gProof->UploadPackage("ESD.par");
245  gProof->EnablePackage("ESD");
246  // Enable the AOD Package
247  gProof->UploadPackage("AOD.par");
248  gProof->EnablePackage("AOD");
249  // Enable the Analysis Package
250  gProof->UploadPackage("ANALYSIS.par");
251  gProof->EnablePackage("ANALYSIS");
252  // Enable the PHOS geometry Package
253  //gProof->UploadPackage("PHOSUtils.par");
254  //gProof->EnablePackage("PHOSUtils");
255  gProof->ShowEnabledPackages();
256  }
257 
258 }
259 
260 void SetupPar(char* pararchivename)
261 {
262  //Load par files, create analysis libraries
263  //For testing, if par file already decompressed and modified
264  //classes then do not decompress.
265 
266  TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
267  TString parpar(Form("%s.par", pararchivename)) ;
268  if ( gSystem->AccessPathName(parpar.Data()) ) {
269  gSystem->ChangeDirectory(gSystem->Getenv("ALICE_PHYSICS")) ;
270  TString processline(Form(".! make %s", parpar.Data())) ;
271  gROOT->ProcessLine(processline.Data()) ;
272  gSystem->ChangeDirectory(cdir) ;
273  processline = Form(".! mv $ALICE_PHYSICS/%s .", parpar.Data()) ;
274  gROOT->ProcessLine(processline.Data()) ;
275  }
276  if ( gSystem->AccessPathName(pararchivename) ) {
277  TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
278  gROOT->ProcessLine(processline.Data());
279  }
280 
281  TString ocwd = gSystem->WorkingDirectory();
282  gSystem->ChangeDirectory(pararchivename);
283 
284  // check for BUILD.sh and execute
285  if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
286  printf("*******************************\n");
287  printf("*** Building PAR archive ***\n");
288  cout<<pararchivename<<endl;
289  printf("*******************************\n");
290 
291  if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
292  Error("runProcess","Cannot Build the PAR Archive! - Abort!");
293  return -1;
294  }
295  }
296  // check for SETUP.C and execute
297  if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
298  printf("*******************************\n");
299  printf("*** Setup PAR archive ***\n");
300  cout<<pararchivename<<endl;
301  printf("*******************************\n");
302  gROOT->Macro("PROOF-INF/SETUP.C");
303  }
304 
305  gSystem->ChangeDirectory(ocwd.Data());
306  printf("Current dir: %s\n", ocwd.Data());
307 }
308 
309 
310 
311 void CreateChain(const anaModes mode, TChain * chain){
312  //Fills chain with data
313  TString ocwd = gSystem->WorkingDirectory();
314 
315  //-----------------------------------------------------------
316  //Analysis of CAF data locally and with PROOF
317  //-----------------------------------------------------------
318  if(mode ==mPROOF || mode ==mLocalCAF){
319  // Chain from CAF
320  gROOT->LoadMacro("$ALICE_PHYSICS/PWG/EMCAL/macros/CreateESDChain.C");
321  // The second parameter is the number of input files in the chain
322  chain = CreateESDChain("ESD12001.txt", 5);
323  }
324 
325  //---------------------------------------
326  //Local files analysis
327  //---------------------------------------
328  else if(mode == mLocal){
329  //If you want to add several ESD files sitting in a common directory INDIR
330  //Specify as environmental variables the directory (INDIR), the number of files
331  //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
332 
333  if(gSystem->Getenv("INDIR"))
334  kInDir = gSystem->Getenv("INDIR") ;
335  else cout<<"INDIR not set, use default: "<<kInDir<<endl;
336 
337  if(gSystem->Getenv("PATTERN"))
338  kPattern = gSystem->Getenv("PATTERN") ;
339  else cout<<"PATTERN not set, use default: "<<kPattern<<endl;
340 
341  if(gSystem->Getenv("NFILES"))
342  kFile = atoi(gSystem->Getenv("NFILES")) ;
343  else cout<<"NFILES not set, use default: "<<kFile<<endl;
344 
345  //Check if env variables are set and are correct
346  if ( kInDir && kFile) {
347  printf("Get %d files from directory %s\n",kFile,kInDir);
348  if ( ! gSystem->cd(kInDir) ) {//check if ESDs directory exist
349  printf("%s does not exist\n", kInDir) ;
350  return ;
351  }
352 
353 
354  cout<<"INDIR : "<<kInDir<<endl;
355  cout<<"NFILES : "<<kFile<<endl;
356  cout<<"PATTERN : " <<kPattern<<endl;
357 
358  TString datafile="";
359  if(kInputData == "ESD") datafile = "AliESDs.root" ;
360  else if(kInputData == "AOD") datafile = "AliAODs.root" ;
361  else if(kInputData == "MC") datafile = "galice.root" ;
362 
363  //Loop on ESD files, add them to chain
364  Int_t event =0;
365  Int_t skipped=0 ;
366  char file[120] ;
367 
368  for (event = 0 ; event < kFile ; event++) {
369  sprintf(file, "%s/%s%d/%s", kInDir,kPattern,event,datafile.Data()) ;
370  TFile * fESD = 0 ;
371  //Check if file exists and add it, if not skip it
372  if ( fESD = TFile::Open(file)) {
373  if ( fESD->Get(kTreeName) ) {
374  printf("++++ Adding %s\n", file) ;
375  chain->AddFile(file);
376  }
377  }
378  else {
379  printf("---- Skipping %s\n", file) ;
380  skipped++ ;
381  }
382  }
383  printf("number of entries # %lld, skipped %d\n", chain->GetEntries(), skipped*100) ;
384  }
385  else {
386  TString input = "AliESDs.root" ;
387  cout<<">>>>>> No list added, take a single file <<<<<<<<< "<<input<<endl;
388  chain->AddFile(input);
389  }
390 
391  }// local files analysis
392 
393  //------------------------------
394  //GRID xml files
395  //-----------------------------
396  else if(mode == mGRID){
397  //Get colection file. It is specified by the environmental
398  //variable XML
399 
400  if(gSystem->Getenv("XML") )
401  kXML = gSystem->Getenv("XML");
402  else
403  sprintf(kXML, "collection.xml") ;
404 
405  if (!TFile::Open(kXML)) {
406  printf("No collection file with name -- %s -- was found\n",kXML);
407  return ;
408  }
409  else cout<<"XML file "<<kXML<<endl;
410 
411  //Load necessary libraries and connect to the GRID
412  gSystem->Load("libNetx") ;
413  gSystem->Load("libRAliEn");
414  TGrid::Connect("alien://") ;
415 
416  //Feed Grid with collection file
417  //TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\", 0)", kXML));
418  TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
419  if (! collection) {
420  AliError(Form("%s not found", kXML)) ;
421  return kFALSE ;
422  }
423  TGridResult* result = collection->GetGridResult("",0 ,0);
424 
425  // Makes the ESD chain
426  printf("*** Getting the Chain ***\n");
427  for (Int_t index = 0; index < result->GetEntries(); index++) {
428  TString alienURL = result->GetKey(index, "turl") ;
429  cout << "================== " << alienURL << endl ;
430  chain->Add(alienURL) ;
431  }
432  }// xml analysis
433 
434  gSystem->ChangeDirectory(ocwd.Data());
435 }
436 
char * kPattern
Bool_t kEmbed
Bool_t kUsePhysSel
anaModes
Different analysis modes.
Definition: ana.C:16
char * kXML
void CreateChain(const anaModes mode, TChain *chain)
TSystem * gSystem
TString kTreeName
void LoadLibraries(const anaModes mode)
Bool_t kMC
Definition: ana.C:62
int Int_t
Definition: External.C:63
Int_t kFile
Int_t kRun
Definition: ana.C:70
Bool_t outAOD
Definition: ana.C:66
AliAnalysisTaskEMCALClusterize * AddTaskEMCALClusterize(TString &arrayName, const Bool_t bFillAOD=kFALSE, const Int_t bMC=kFALSE, const Bool_t exotic=kTRUE, const TString name="V1Unfold", const TString trigger="", const Bool_t tm=kTRUE, const Int_t minEcell=50, const Int_t minEseed=100, const Int_t maxDeltaT=250, const Int_t timeWindow=1000, const Int_t minEUnf=15, const Int_t minFrac=1, const Bool_t bRecalE=kTRUE, const Bool_t bBad=kTRUE, const Bool_t bRecalT=kTRUE, const Bool_t bNonLine=kFALSE, const Int_t minCen=-1, const Int_t maxCen=-1, const Float_t clusterEnergyCutEvent=-1, const Int_t nRowDiff=1, const Int_t nColDiff=1, const Bool_t skipOrReject=kFALSE)
Int_t mode
Definition: anaM.C:40
void emcalReclusterize(Int_t mode=mLocal)
TString kInputData
TFile * file
char * kInDir
bool Bool_t
Definition: External.C:53
void SetupPar(char *pararchivename)
Reclusterize EMCal clusters, put them in a new branch for other following analysis.