AliPhysics  d497547 (d497547)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliEmcalCorrectionComponent.cxx
Go to the documentation of this file.
1 // AliEmcalCorrectionComponent
2 //
3 
5 
6 #include <TFile.h>
7 #include <TH1.h>
8 
9 #include "AliEmcalList.h"
10 #include "AliEMCALRecoUtils.h"
11 #include "AliAnalysisManager.h"
12 #include "AliVEvent.h"
13 #include "AliClusterContainer.h"
14 #include "AliTrackContainer.h"
15 #include "AliParticleContainer.h"
16 #include "AliMCParticleContainer.h"
17 #include "AliOADBContainer.h"
18 
22 
23 // Must create an instance of the map, since it is static
25 
30  TNamed("AliEmcalCorrectionComponent", "AliEmcalCorrectionComponent"),
31  fUserConfiguration(),
32  fDefaultConfiguration(),
33  fCreateHisto(kTRUE),
34  fRun(-1),
35  fFilepass(""),
36  fGetPassFromFileName(kTRUE),
37  fEventManager(),
38  fEsdMode(0),
39  fMCEvent(0),
40  fCent(0),
41  fNcentBins(4),
42  fCentBin(0),
43  fNbins(250),
44  fMinBinPt(0),
45  fMaxBinPt(250),
46  fGeom(0),
47  fIsEmbedded(kFALSE),
48  fMinMCLabel(0),
49  fClusterCollArray(),
50  fParticleCollArray(),
51  fCaloCells(0),
52  fRecoUtils(0),
53  fOutput(0),
54  fBasePath("")
55 
56 {
57  fVertex[0] = 0;
58  fVertex[1] = 0;
59  fVertex[2] = 0;
60 }
61 
66  TNamed(name, name),
67  fUserConfiguration(),
68  fDefaultConfiguration(),
69  fCreateHisto(kTRUE),
70  fRun(-1),
71  fFilepass(""),
72  fGetPassFromFileName(kTRUE),
73  fEventManager(),
74  fEsdMode(0),
75  fMCEvent(0),
76  fCent(0),
77  fNcentBins(4),
78  fCentBin(0),
79  fNbins(250),
80  fMinBinPt(0),
81  fMaxBinPt(250),
82  fGeom(0),
83  fIsEmbedded(kFALSE),
84  fMinMCLabel(0),
85  fClusterCollArray(),
86  fParticleCollArray(),
87  fCaloCells(0),
88  fRecoUtils(0),
89  fOutput(0),
90  fBasePath("")
91 {
92  fVertex[0] = 0;
93  fVertex[1] = 0;
94  fVertex[2] = 0;
95 }
96 
101 {
102 }
103 
108 {
109  // Read in pass. If it is empty, set flag to automatically find the pass from the filename.
110  std::string tempString = "";
111  GetProperty("pass", tempString);
112  fFilepass = tempString.c_str();
113  if (fFilepass != "") {
114  fGetPassFromFileName = kFALSE;
115  // Handle the "default" value used in MC
116  if (fFilepass == "default") {
117  AliError("Received \"default\" as pass value. Defaulting to \"pass1\"! In the case of MC, the user should set the proper pass value in their configuration file! For data, empty quotes should be set so that the pass is automatically set.");
118  fFilepass = "pass1";
119  }
120  }
121 
122  return kTRUE;
123 }
124 
130 {
131  // Setup Output
132  fOutput = new AliEmcalList();
133  fOutput->SetOwner();
134 }
135 
141 {
142 }
143 
149 {
150  AliDebugStream(3) << ": fEventManager.UseEmbeddingEvent(): " << fEventManager.UseEmbeddingEvent() << ", "
151  << "fEventManager.InputEvent(): " << fEventManager.InputEvent() << ", "
152  << "fEventManager address: " << &fEventManager << "\n";
154  GetPass();
155 
156  return kTRUE;
157 }
158 
164 {
165  return kTRUE;
166 }
167 
176 void AliEmcalCorrectionComponent::GetEtaPhiDiff(const AliVTrack *t, const AliVCluster *v, Double_t &phidiff, Double_t &etadiff)
177 {
178  phidiff = 999;
179  etadiff = 999;
180 
181  if (!t||!v) return;
182 
183  Double_t veta = t->GetTrackEtaOnEMCal();
184  Double_t vphi = t->GetTrackPhiOnEMCal();
185 
186  Float_t pos[3] = {0};
187  v->GetPosition(pos);
188  TVector3 cpos(pos);
189  Double_t ceta = cpos.Eta();
190  Double_t cphi = cpos.Phi();
191  etadiff=veta-ceta;
192  phidiff=TVector2::Phi_mpi_pi(vphi-cphi);
193 }
194 
200 {
201 
202  if (!fEventManager.InputEvent()) return ;
203 
204  Int_t bunchCrossNo = fEventManager.InputEvent()->GetBunchCrossNumber();
205 
206  if (fRecoUtils)
207  fRecoUtils->RecalibrateCells(fCaloCells, bunchCrossNo);
208 
209  fCaloCells->Sort();
210 }
211 
216 {
217  // Get run number.
218  Bool_t runChanged = fRun != fEventManager.InputEvent()->GetRunNumber();
219 
220  if (runChanged) {
221  fRun = fEventManager.InputEvent()->GetRunNumber();
222  AliWarning(Form("Run changed, initializing parameters for %d", fRun));
223 
224  // init geometry if not already done
225  fGeom = AliEMCALGeometry::GetInstanceFromRunNumber(fRun);
226  if (!fGeom)
227  {
228  AliFatal("Can not create geometry");
229  return kFALSE;
230  }
231  }
232  return runChanged;
233 }
234 
245 {
246  std::size_t sharedParameterLocation = value.find("sharedParameters:");
247  if (sharedParameterLocation != std::string::npos)
248  {
249  // "sharedParameters:" is 17 characters long
250  value.erase(sharedParameterLocation, sharedParameterLocation + 17);
251  return true;
252  }
253  // Return false otherwise
254  return false;
255 }
256 
261 {
262  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
263  TTree *inputTree = mgr->GetTree();
264 
265  if (!inputTree)
266  {
267  AliError("Pointer to tree = 0, returning");
268  return;
269  }
270 
271  TFile *inputFile = inputTree->GetCurrentFile();
272  if (!inputFile) {
273  AliError("Null pointer input file, returning");
274  return;
275  }
276 
277  TString fname(inputFile->GetName());
278  if (fname.Contains("pass1_pidfix")) fFilepass = TString("pass1_pidfix");
279  else if (fname.Contains("pass3_lowIR_pidfix")) fFilepass = TString("pass3_lowIR_pidfix");
280  else if (fname.Contains("pass4_lowIR_pidfix_cookdedx")) fFilepass = TString("pass4_lowIR_pidfix_cookdedx");
281  else if (fname.Contains("pass1")) fFilepass = TString("pass1");
282  else if (fname.Contains("pass2")) fFilepass = TString("pass2");
283  else if (fname.Contains("pass3")) fFilepass = TString("pass3");
284  else if (fname.Contains("pass4")) fFilepass = TString("pass4");
285  else if (fname.Contains("pass5")) fFilepass = TString("pass5");
286  else if (fname.Contains("LHC11c") && fname.Contains("spc_calo")) fFilepass = TString("spc_calo");
287  else if (fname.Contains("calo") || fname.Contains("high_lumi"))
288  {
289  Printf("%s: Path contains <calo> or <high-lumi>, set as <pass1>", GetName());
290  fFilepass = TString("pass1");
291  }
292  else if (fname.Contains("LHC14a1a"))
293  {
294  AliInfo("Energy calibration activated for this MC production!");
295  fFilepass = TString("LHC14a1a");
296  }
297  else
298  {
299  AliFatal(Form("Pass number string not found: %s. Please set the pass number in the configuration!", fname.Data()));
300  return;
301  }
302 }
303 
308  TString name = h->GetName();
309 
310  Short_t absId =-1;
311  Double_t ecell = 0;
312  Double_t tcell = 0;
313  Double_t efrac = 0;
314  Int_t mclabel = -1;
315 
316  for (Int_t iCell = 0; iCell < fCaloCells->GetNumberOfCells(); iCell++){
317 
318  fCaloCells->GetCell(iCell, absId, ecell, tcell, mclabel, efrac);
319  if(name.Contains("Energy")){
320  h->Fill(ecell);
321  }
322  else if(name.Contains("Time")){
323  h->Fill(tcell);
324  }
325 
326  }
327 
328 }
329 
334 {
335  if (!fEventManager.InputEvent())
336  return 0;
337 
338  AliInfo("Initialising Bad channel map");
339 
340  // init default maps first
341  if (!fRecoUtils->GetEMCALBadChannelStatusMapArray())
342  fRecoUtils->InitEMCALBadChannelStatusMap() ;
343 
344  Int_t runBC = fEventManager.InputEvent()->GetRunNumber();
345 
346  AliOADBContainer *contBC = new AliOADBContainer("");
347  if (fBasePath!="")
348  { //if fBasePath specified in the ->SetBasePath()
349  AliInfo(Form("Loading Bad Channels OADB from given path %s",fBasePath.Data()));
350 
351  TFile *fbad=new TFile(Form("%s/EMCALBadChannels.root",fBasePath.Data()),"read");
352  if (!fbad || fbad->IsZombie())
353  {
354  AliFatal(Form("EMCALBadChannels.root was not found in the path provided: %s",fBasePath.Data()));
355  return 0;
356  }
357 
358  if (fbad) delete fbad;
359 
360  contBC->InitFromFile(Form("%s/EMCALBadChannels.root",fBasePath.Data()),"AliEMCALBadChannels");
361  }
362  else
363  { // Else choose the one in the $ALICE_PHYSICS directory
364  AliInfo("Loading Bad Channels OADB from $ALICE_PHYSICS/OADB/EMCAL");
365 
366  TFile *fbad=new TFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALBadChannels.root","read");
367  if (!fbad || fbad->IsZombie())
368  {
369  AliFatal("$ALICE_PHYSICS/OADB/EMCAL/EMCALBadChannels.root was not found");
370  return 0;
371  }
372 
373  if (fbad) delete fbad;
374 
375  contBC->InitFromFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALBadChannels.root","AliEMCALBadChannels");
376  }
377 
378  TObjArray *arrayBC=(TObjArray*)contBC->GetObject(runBC);
379  if (!arrayBC)
380  {
381  AliError(Form("No external hot channel set for run number: %d", runBC));
382  delete contBC;
383  return 2;
384  }
385 
386  Int_t sms = fGeom->GetEMCGeometry()->GetNumberOfSuperModules();
387  for (Int_t i=0; i<sms; ++i)
388  {
389  TH2I *h = fRecoUtils->GetEMCALChannelStatusMap(i);
390  if (h)
391  delete h;
392  h=(TH2I*)arrayBC->FindObject(Form("EMCALBadChannelMap_Mod%d",i));
393 
394  if (!h)
395  {
396  AliError(Form("Can not get EMCALBadChannelMap_Mod%d",i));
397  continue;
398  }
399  h->SetDirectory(0);
400  fRecoUtils->SetEMCALChannelStatusMap(i,h);
401  }
402 
403  delete contBC;
404 
405  return 1;
406 }
407 
AliEMCALGeometry * fGeom
! Geometry object
double Double_t
Definition: External.C:58
bool UseEmbeddingEvent() const
True if the embedding event should be used.
AliVCaloCells * fCaloCells
! Pointer to CaloCells
AliEMCALRecoUtils * fRecoUtils
Pointer to RecoUtils.
int Int_t
Definition: External.C:63
float Float_t
Definition: External.C:68
Base class for correction components in the EMCal correction framework.
static map_type * componentMap
Contains the map to all of the components.
std::map< std::string, AliEmcalCorrectionComponent *(*)()> map_type
Double_t fVertex[3]
! Event vertex
TString fBasePath
Base folder path to get root files.
TList * fOutput
! List of output histograms
short Short_t
Definition: External.C:23
Enhanced TList-derived class that implements correct merging for pt_hard binned production.
Definition: AliEmcalList.h:25
static bool IsSharedValue(std::string &value)
Bool_t fGetPassFromFileName
Get fFilepass from file name.
AliEmcalCorrectionEventManager fEventManager
Minimal task which inherits from AliAnalysisTaskSE and manages access to the event.
void GetEtaPhiDiff(const AliVTrack *t, const AliVCluster *v, Double_t &phidiff, Double_t &etadiff)
bool Bool_t
Definition: External.C:53
TString fFilepass
Input data pass number.
bool GetProperty(std::string propertyName, T &property, bool requiredProperty=true, std::string correctionName="")
Retrieve property.