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