AliPhysics  abafffd (abafffd)
AliEmcalCorrectionCellEnergyVariation.cxx
Go to the documentation of this file.
1 // AliEmcalCorrectionCellEnergyVariation
2 //
3 
4 #include <TGrid.h>
5 #include <TFile.h>
6 
8 
12 
13 // Actually registers the class with the base class
15 
20  AliEmcalCorrectionComponent("AliEmcalCorrectionCellEnergyVariation"),
21  fMinCellE(0.),
22  fMaxCellE(150.),
23  fEnergyScaleFactorConstant(1.),
24  fEnergyScaleFunction(nullptr)
25 {
26 }
27 
32 {
33 }
34 
39 {
40  // Initialization
42 
43  GetProperty("minCellE", fMinCellE);
44  GetProperty("maxCellE", fMaxCellE);
45  GetProperty("energyScaleFactorConstant", fEnergyScaleFactorConstant);
46 
47  std::string path;
48  std::string name;
49  GetProperty("energyScaleFunctionPath", path);
50  GetProperty("energyScaleFunctionName", name);
51 
52  // Load TF1 from file, if provided
53  if (!path.empty() && !name.empty()) {
54  LoadEnergyScaleFunction(path, name);
55  }
56 
57  return kTRUE;
58 }
59 
64 {
66 }
67 
72 {
73  // If a constant scale factor is supplied, create a TF1 that is constant in E_cell
74  if (TMath::Abs(1 - fEnergyScaleFactorConstant) > 1e-6) {
75 
76  // If a TF1 was already loaded, throw an error
78  AliError(Form("%s: fEnergyScaleFunction was already loaded! Do not apply multiple scale factors.", GetName()));
79  }
80 
81  fEnergyScaleFunction = new TF1("energyScaleFunction", "[0]", fMinCellE, fMaxCellE);
83  }
84 }
85 
90 {
92 
93  Short_t absId =-1;
94  Double_t ecell = 0;
95  Double_t tcell = 0;
96  Double_t efrac = 0;
97  Int_t mclabel = -1;
98 
99  // Loop over all EMCal cells
100  for (Int_t iCell = 0; iCell < fCaloCells->GetNumberOfCells(); iCell++){
101 
102  // Get cell
103  Bool_t getCellResult = fCaloCells->GetCell(iCell, absId, ecell, tcell, mclabel, efrac);
104  if (!getCellResult) {
105  AliWarning(TString::Format("Could not get cell %i from cell collection %s", iCell, fCaloCells->GetName()));
106  }
107 
108  // Get high gain attribute in addition to cell
109  // NOTE: GetCellHighGain() uses the cell position, not cell index, and thus should _NOT_ be used!
110  Bool_t cellHighGain = fCaloCells->GetHighGain(iCell);
111 
112  // Scale cell energy by TF1, if supplied
113  if (fEnergyScaleFunction && ecell > fMinCellE && ecell < fMaxCellE) {
114 
115  ecell *= fEnergyScaleFunction->Eval(ecell);
116 
117  if (ecell > 0.) {
118  fCaloCells->SetCell(iCell, absId, ecell, tcell, mclabel, efrac, cellHighGain);
119  }
120  }
121 
122  }
123 
124  return kTRUE;
125 }
126 
132 void AliEmcalCorrectionCellEnergyVariation::LoadEnergyScaleFunction(const std::string & path, const std::string & name)
133 {
134  TString fname(path);
135  if (fname.BeginsWith("alien://")) {
136  TGrid::Connect("alien://");
137  }
138 
139  TFile* file = TFile::Open(path.data());
140 
141  if (!file || file->IsZombie()) {
142  AliErrorStream() << "Could not open energy scale function file\n";
143  return;
144  }
145 
146  TF1* energyScaleFunction = dynamic_cast<TF1*>(file->Get(name.data()));
147 
148  if (energyScaleFunction) {
149  AliInfoStream() << Form("Cell energy scale function %s loaded from file %s.", name.data(), path.data()) << "\n";
150  }
151  else {
152  AliErrorStream() << Form("Cell energy scale function %s not found in file %s.", name.data(), path.data()) << "\n";
153  return;
154  }
155 
156  fEnergyScaleFunction = static_cast<TF1*>(energyScaleFunction->Clone());
157 
158  file->Close();
159  delete file;
160 }
double Double_t
Definition: External.C:58
static RegisterCorrectionComponent< AliEmcalCorrectionCellEnergyVariation > reg
Double_t fMinCellE
Min cell E to perform scaling on.
AliVCaloCells * fCaloCells
! Pointer to CaloCells
TF1 * fEnergyScaleFunction
Function describing factor to scale cell energy by, as a function of cell E.
int Int_t
Definition: External.C:63
Double_t fEnergyScaleFactorConstant
Constant factor to scale cell energy by.
Base class for correction components in the EMCal correction framework.
short Short_t
Definition: External.C:23
Double_t fMaxCellE
Max cell E to perform scaling on.
Cell energy variation component in the EMCal correction framework.
void LoadEnergyScaleFunction(const std::string &path, const std::string &name)
TFile * file
TList with histograms for a given trigger.
bool Bool_t
Definition: External.C:53
bool GetProperty(std::string propertyName, T &property, bool requiredProperty=true, std::string correctionName="")
Retrieve property.