AliPhysics  4e47bdd (4e47bdd)
 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  fEvent(0),
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  fEvent(0),
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 {
151  GetPass();
152 
153  return kTRUE;
154 }
155 
161 {
162  return kTRUE;
163 }
164 
173 void AliEmcalCorrectionComponent::GetEtaPhiDiff(const AliVTrack *t, const AliVCluster *v, Double_t &phidiff, Double_t &etadiff)
174 {
175  phidiff = 999;
176  etadiff = 999;
177 
178  if (!t||!v) return;
179 
180  Double_t veta = t->GetTrackEtaOnEMCal();
181  Double_t vphi = t->GetTrackPhiOnEMCal();
182 
183  Float_t pos[3] = {0};
184  v->GetPosition(pos);
185  TVector3 cpos(pos);
186  Double_t ceta = cpos.Eta();
187  Double_t cphi = cpos.Phi();
188  etadiff=veta-ceta;
189  phidiff=TVector2::Phi_mpi_pi(vphi-cphi);
190 }
191 
197 {
198 
199  if (!fEvent) return ;
200 
201  Int_t bunchCrossNo = fEvent->GetBunchCrossNumber();
202 
203  if (fRecoUtils)
204  fRecoUtils->RecalibrateCells(fCaloCells, bunchCrossNo);
205 
206  fCaloCells->Sort();
207 }
208 
213 {
214  // Get run number.
215  Bool_t runChanged = fRun != fEvent->GetRunNumber();
216 
217  if (runChanged) {
218  fRun = fEvent->GetRunNumber();
219  AliWarning(Form("Run changed, initializing parameters for %d", fRun));
220 
221  // init geometry if not already done
222  fGeom = AliEMCALGeometry::GetInstanceFromRunNumber(fRun);
223  if (!fGeom)
224  {
225  AliFatal("Can not create geometry");
226  return kFALSE;
227  }
228  }
229  return runChanged;
230 }
231 
242 {
243  std::size_t sharedParameterLocation = value.find("sharedParameters:");
244  if (sharedParameterLocation != std::string::npos)
245  {
246  // "sharedParameters:" is 17 characters long
247  value.erase(sharedParameterLocation, sharedParameterLocation + 17);
248  return true;
249  }
250  // Return false otherwise
251  return false;
252 }
253 
258 {
259  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
260  TTree *inputTree = mgr->GetTree();
261 
262  if (!inputTree)
263  {
264  AliError("Pointer to tree = 0, returning");
265  return;
266  }
267 
268  TFile *inputFile = inputTree->GetCurrentFile();
269  if (!inputFile) {
270  AliError("Null pointer input file, returning");
271  return;
272  }
273 
274  TString fname(inputFile->GetName());
275  if (fname.Contains("pass1_pidfix")) fFilepass = TString("pass1_pidfix");
276  else if (fname.Contains("pass3_lowIR_pidfix")) fFilepass = TString("pass3_lowIR_pidfix");
277  else if (fname.Contains("pass4_lowIR_pidfix_cookdedx")) fFilepass = TString("pass4_lowIR_pidfix_cookdedx");
278  else if (fname.Contains("pass1")) fFilepass = TString("pass1");
279  else if (fname.Contains("pass2")) fFilepass = TString("pass2");
280  else if (fname.Contains("pass3")) fFilepass = TString("pass3");
281  else if (fname.Contains("pass4")) fFilepass = TString("pass4");
282  else if (fname.Contains("pass5")) fFilepass = TString("pass5");
283  else if (fname.Contains("LHC11c") && fname.Contains("spc_calo")) fFilepass = TString("spc_calo");
284  else if (fname.Contains("calo") || fname.Contains("high_lumi"))
285  {
286  Printf("%s: Path contains <calo> or <high-lumi>, set as <pass1>", GetName());
287  fFilepass = TString("pass1");
288  }
289  else if (fname.Contains("LHC14a1a"))
290  {
291  AliInfo("Energy calibration activated for this MC production!");
292  fFilepass = TString("LHC14a1a");
293  }
294  else
295  {
296  AliFatal(Form("Pass number string not found: %s. Please set the pass number in the configuration!", fname.Data()));
297  return;
298  }
299 }
300 
305  TString name = h->GetName();
306 
307  Short_t absId =-1;
308  Double_t ecell = 0;
309  Double_t tcell = 0;
310  Double_t efrac = 0;
311  Int_t mclabel = -1;
312 
313  for (Int_t iCell = 0; iCell < fCaloCells->GetNumberOfCells(); iCell++){
314 
315  fCaloCells->GetCell(iCell, absId, ecell, tcell, mclabel, efrac);
316  if(name.Contains("Energy")){
317  h->Fill(ecell);
318  }
319  else if(name.Contains("Time")){
320  h->Fill(tcell);
321  }
322 
323  }
324 
325 }
326 
331 {
332  if (!fEvent)
333  return 0;
334 
335  AliInfo("Initialising Bad channel map");
336 
337  // init default maps first
338  if (!fRecoUtils->GetEMCALBadChannelStatusMapArray())
339  fRecoUtils->InitEMCALBadChannelStatusMap() ;
340 
341  Int_t runBC = fEvent->GetRunNumber();
342 
343  AliOADBContainer *contBC = new AliOADBContainer("");
344  if (fBasePath!="")
345  { //if fBasePath specified in the ->SetBasePath()
346  AliInfo(Form("Loading Bad Channels OADB from given path %s",fBasePath.Data()));
347 
348  TFile *fbad=new TFile(Form("%s/EMCALBadChannels.root",fBasePath.Data()),"read");
349  if (!fbad || fbad->IsZombie())
350  {
351  AliFatal(Form("EMCALBadChannels.root was not found in the path provided: %s",fBasePath.Data()));
352  return 0;
353  }
354 
355  if (fbad) delete fbad;
356 
357  contBC->InitFromFile(Form("%s/EMCALBadChannels.root",fBasePath.Data()),"AliEMCALBadChannels");
358  }
359  else
360  { // Else choose the one in the $ALICE_PHYSICS directory
361  AliInfo("Loading Bad Channels OADB from $ALICE_PHYSICS/OADB/EMCAL");
362 
363  TFile *fbad=new TFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALBadChannels.root","read");
364  if (!fbad || fbad->IsZombie())
365  {
366  AliFatal("$ALICE_PHYSICS/OADB/EMCAL/EMCALBadChannels.root was not found");
367  return 0;
368  }
369 
370  if (fbad) delete fbad;
371 
372  contBC->InitFromFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALBadChannels.root","AliEMCALBadChannels");
373  }
374 
375  TObjArray *arrayBC=(TObjArray*)contBC->GetObject(runBC);
376  if (!arrayBC)
377  {
378  AliError(Form("No external hot channel set for run number: %d", runBC));
379  delete contBC;
380  return 2;
381  }
382 
383  Int_t sms = fGeom->GetEMCGeometry()->GetNumberOfSuperModules();
384  for (Int_t i=0; i<sms; ++i)
385  {
386  TH2I *h = fRecoUtils->GetEMCALChannelStatusMap(i);
387  if (h)
388  delete h;
389  h=(TH2I*)arrayBC->FindObject(Form("EMCALBadChannelMap_Mod%d",i));
390 
391  if (!h)
392  {
393  AliError(Form("Can not get EMCALBadChannelMap_Mod%d",i));
394  continue;
395  }
396  h->SetDirectory(0);
397  fRecoUtils->SetEMCALChannelStatusMap(i,h);
398  }
399 
400  delete contBC;
401 
402  return 1;
403 }
404 
AliEMCALGeometry * fGeom
! Geometry object
double Double_t
Definition: External.C:58
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.
AliVEvent * fEvent
! Pointer to event
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.
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
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.