Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
egammaLayerRecalibTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <iostream>
6 #include <exception>
7 #include <cassert>
8 #include <string>
9 #include <map>
10 #include <sstream>
11 #include <algorithm>
12 #include <cmath>
13 #include <limits>
14 
15 #include <TFile.h>
16 #include <TObjString.h>
17 
19 
22 
23 namespace {
24 const float VALUE_OVERFLOW = std::numeric_limits<float>::max();
25 
26 template <typename TargetPtr, typename SourcePtr>
27 TargetPtr checked_cast(SourcePtr ptr) {
28  // Do we have ptr types
30  "attempt to cast to no ptr object");
32  "attempt to cast from no ptr object");
33 
34  // nullptr input
35  if (!ptr) {
36  throw std::runtime_error(
37  "Attempt to cast from nullptr in egammaLayerRecalibTool");
38  }
39 
40  // dynamic_cast and check
41  TargetPtr obj = dynamic_cast<TargetPtr>(ptr);
42  if (not obj) {
43  throw std::runtime_error("failed dynamic cast for " +
44  std::string(ptr->GetName()) +
45  " in egammaLayerRecalibTool");
46  }
47 
48  return obj;
49 }
50 
51 } // end anonymous namespace
52 
54  const int bin = m_histo->FindFixBin(input.eta);
55  if (m_histo->IsBinUnderflow(bin) or m_histo->IsBinOverflow(bin)) return VALUE_OVERFLOW;
56  return m_histo->GetBinContent(bin);
57 }
58 
60  const int bin = m_histo->FindFixBin(input.eta);
61  if (m_histo->IsBinUnderflow(bin) or m_histo->IsBinOverflow(bin)) return VALUE_OVERFLOW;
62  return m_histo->GetBinContent(bin) + m_histo->GetBinError(bin);
63 }
64 
66  const int bin = m_histo->FindFixBin(input.eta);
67  if (m_histo->IsBinUnderflow(bin) or m_histo->IsBinOverflow(bin)) return VALUE_OVERFLOW;
68  return m_histo->GetBinContent(bin) - m_histo->GetBinError(bin);
69 }
70 
72  const int bin = m_histo->FindFixBin(input.eta);
73  if (m_histo->IsBinUnderflow(bin) or m_histo->IsBinOverflow(bin)) return VALUE_OVERFLOW;
74  return m_histo->GetBinError(bin);
75 }
76 
78  const int bin = m_histo->FindFixBin(input.eta);
79  if (m_histo->IsBinUnderflow(bin) or m_histo->IsBinOverflow(bin)) return VALUE_OVERFLOW;
80  return -m_histo->GetBinError(bin);
81 }
82 
84  const int bin = m_histo.FindFixBin(input.eta, input.phi);
85  if (m_histo.IsBinUnderflow(bin) or m_histo.IsBinOverflow(bin)) return VALUE_OVERFLOW;
86  return m_histo.GetBinContent(bin);
87 }
88 
90  const int bin = m_histo.FindFixBin(input.etaCalo, input.RunNumber);
91  if (m_histo.IsBinUnderflow(bin) or m_histo.IsBinOverflow(bin)) return VALUE_OVERFLOW;
92  return m_histo.GetBinContent(bin);
93 }
94 
95 float GetAmountFixed::operator()(const StdCalibrationInputs & /*input*/ ) const {
96  return m_amount;
97 }
98 
100  return m_formula.Eval(input.eta, input.phi, input.RunNumber);
101 }
102 
104  return m_tool.getCorr(input.RunNumber, input.eta, input.phi);
105 }
106 
108  return m_toolEMECPS.getCorr(input.RunNumber, input.eta, input.phi);
109 }
110 
112  return m_tool->getCorr(0, input.RunNumber, input.averageInteractionsPerCrossing, input.eta);
113 }
114 
116  return m_tool->getCorr(1, input.RunNumber, input.averageInteractionsPerCrossing, input.eta);
117 }
118 
120  return m_tool->getCorr(2, input.RunNumber, input.averageInteractionsPerCrossing, input.eta);
121 }
122 
124  return m_tool->getCorr(3, input.RunNumber, input.averageInteractionsPerCrossing, input.eta);
125 }
126 
127 
129 {
130  if (amount == VALUE_OVERFLOW) return CP::CorrectionCode::OutOfValidityRange;
131  switch (m_base)
132  {
133  case SHIFT: shift_inputs(inputs, amount); return CP::CorrectionCode::Ok;
134  case SUBTRACT: shift_inputs(inputs, -amount); return CP::CorrectionCode::Ok;
135  case SCALE: scale_inputs(inputs, amount); return CP::CorrectionCode::Ok;
136  case ZEROBASED: scale_inputs(inputs, 1. + amount); return CP::CorrectionCode::Ok;
137  case ONEBASED: scale_inputs(inputs, amount); return CP::CorrectionCode::Ok;
138  case ONEBASED_ALPHA: scale_inputs(inputs, 1. / amount); return CP::CorrectionCode::Ok;
139  case ZEROBASED_ALPHA: scale_inputs(inputs, 1. / (1. + amount)); return CP::CorrectionCode::Ok;
140  default: return CP::CorrectionCode::Error;
141  };
142 }
143 
144 void ScaleE0::scale_inputs(StdCalibrationInputs & inputs, float amount) const { inputs.E0raw *= amount; }
145 void ScaleE1::scale_inputs(StdCalibrationInputs & inputs, float amount) const { inputs.E1raw *= amount; }
146 void ScaleE2::scale_inputs(StdCalibrationInputs & inputs, float amount) const { inputs.E2raw *= amount; }
147 void ScaleE3::scale_inputs(StdCalibrationInputs & inputs, float amount) const { inputs.E3raw *= amount; }
148 
149 void ScaleE0::shift_inputs(StdCalibrationInputs & inputs, float amount) const { inputs.E0raw += amount; }
150 void ScaleE1::shift_inputs(StdCalibrationInputs & inputs, float amount) const { inputs.E1raw += amount; }
151 void ScaleE2::shift_inputs(StdCalibrationInputs & inputs, float amount) const { inputs.E2raw += amount; }
152 void ScaleE3::shift_inputs(StdCalibrationInputs & inputs, float amount) const { inputs.E3raw += amount; }
153 
154 
156 {
157  const double Es1 = inputs.E1raw;
158  const double Es2 = inputs.E2raw;
159  if (Es1 == 0 and Es2 == 0) {
160  inputs.E1raw = -999;
161  inputs.E2raw = -999;
162  return;
163  }
164  const double sum = Es1 + Es2;
165  const double alpha = amount;
166  const double den = (alpha * Es1 + Es2);
167  inputs.E1raw = alpha * Es1 * sum / den;
168  inputs.E2raw = Es2 * sum / den;
169 }
170 
172 {
173  // not very useful, never used
174  throw std::runtime_error("not implemented");
175 }
176 
178 {
179  inputs.E1raw *= amount;
180  inputs.E2raw *= amount;
181  inputs.E3raw *= amount;
182 }
183 
185 {
186  inputs.E1raw += amount;
187  inputs.E2raw += amount;
188  inputs.E3raw += amount;
189 }
190 
192 {
193  inputs.E0raw *= amount;
194  inputs.E1raw *= amount;
195  inputs.E2raw *= amount;
196  inputs.E3raw *= amount;
197 }
198 
200 {
201  inputs.E0raw += amount;
202  inputs.E1raw += amount;
203  inputs.E2raw += amount;
204  inputs.E3raw += amount;
205 }
206 
207 std::string egammaLayerRecalibTool::resolve_alias(const std::string& tune) {
208 
209  if ("layer1_2012" == tune) return "layer1_2012_v5";
210  if ("layer1_alt_2012" == tune) return "layer1_alt_2012_v5";
211  if ("layer1_2011" == tune) return "layer1_2011_v5";
212  if ("layer1_alt_2011" == tune) return "layer1_alt_2011_v5";
213  if ("layer1_2010" == tune) return "layer1_2010_v5";
214  if ("ps_2012" == tune) return "ps_2012_v3";
215  if ("ps_2011" == tune) return "ps_2011_v3";
216  if ("ps_2010" == tune) return "ps_2010_v3";
217  if ("layer1_2012_up" == tune) return "layer1_2012_v5_up";
218  if ("layer1_2012_down" == tune) return "layer1_2012_v5_down";
219  if ("layer1_2012_errup" == tune) return "layer1_2012_v5_errup";
220  if ("layer1_2012_errdown" == tune) return "layer1_2012_v5_errdown";
221  if ("layer1_2011_up" == tune) return "layer1_2011_v5_up";
222  if ("layer1_2011_down" == tune) return "layer1_2011_v5_down";
223  if ("layer1_2011_errup" == tune) return "layer1_2011_v5_errup";
224  if ("layer1_2011_errdown" == tune) return "layer1_2011_v5_errdown";
225  if ("layer1_2010_up" == tune) return "layer1_2010_v5_up";
226  if ("layer1_2010_down" == tune) return "layer1_2010_v5_down";
227  if ("layer1_2010_errup" == tune) return "layer1_2010_v5_errup";
228  if ("layer1_2010_errdown" == tune) return "layer1_2010_v5_errdown";
229  if ("ps_2012_up" == tune) return "ps_2012_v3_up";
230  if ("ps_2012_down" == tune) return "ps_2012_v3_down";
231  if ("ps_2012_errup" == tune) return "ps_2012_v3_errup";
232  if ("ps_2012_errdown" == tune) return "ps_2012_v3_errdown";
233  if ("ps_2011_up" == tune) return "ps_2011_v3_up";
234  if ("ps_2011_down" == tune) return "ps_2011_v3_down";
235  if ("ps_2011_errup" == tune) return "ps_2011_v3_errup";
236  if ("ps_2011_errdown" == tune) return "ps_2011_v3_errdown";
237  if ("ps_2010_up" == tune) return "ps_2010_v3_up";
238  if ("ps_2010_down" == tune) return "ps_2010_v3_down";
239  if ("ps_2010_errup" == tune) return "ps_2010_v3_errup";
240  if ("ps_2010_errdown" == tune) return "ps_2010_v3_errdown";
241 
242  return tune;
243 }
244 
245 void egammaLayerRecalibTool::add_scale(const std::string& tuneIn)
246 {
247  ATH_MSG_INFO("using scale " << tuneIn);
248  std::string tune = resolve_alias(tuneIn);
249 
250  if (tune.empty()) { }
251  // R22 layer tune with fixed E1E2 and repeated acc
252  else if ("es2022_22.0_Precision_v1" == tune) {
253  add_scale("run2_alt_with_layer2_r22_Precision_v1");
254  }
255  else if ("es2022_22.0_Precision" == tune) {
256  add_scale("run2_alt_with_layer2_r22_Precision");
257  }
258  else if ("es2018_21.0_v0" == tune) {
259  add_scale("run2_alt_with_layer2_r21_v1");
260  }
261  else if ("es2017_21.0_v0" == tune) {
262  add_scale("run2_alt_with_layer2_r21_v0");
263  }
264  else if ("es2017_20.7_final" == tune) {
265  add_scale("pileup_20.7");
266  add_scale("run2_alt_with_layer2_modif");
267  }
268  else if ("es2017_20.7_improved" == tune) {
269  add_scale("pileup_20.7"); // new pileup correction Guillaume for 20.7
270  //TEMPORARY HACK REMOVED (two intermediate tags with this ES model use different layer corrections)
271  add_scale("2012_alt_with_layer2_modif"); // temporary old corrections from run1 + EMECPS HV
272  }
273  else if ("pileup_20.7" == tune) {
279  }
280  //Run 2 release 22 with fixed E1E2 and repeated acc
281  else if ("run2_alt_with_layer2_r22_Precision_v1"==tune) {
282  add_scale("layer2_alt_el_mu_comb_r21_v0_fix");
283  add_scale("ps_mu_r21_v0");
284  if(m_doSaccCorrections) add_scale("acc_zee_r22_v1");
285  }
286  //Run 2 release 22
287  else if ("run2_alt_with_layer2_r22_Precision"==tune) {
288  add_scale("layer2_alt_el_mu_comb_r21_v0");
289  add_scale("ps_mu_r21_v0");
290  if(m_doSaccCorrections) add_scale("acc_zee_r22_v0");
291  }
292  else if ("run2_alt_with_layer2_r21_v1"==tune) {
293  add_scale("layer2_alt_run2_r21_v1");
294  add_scale("ps_2016_r21_v0");
295  }
296  else if ("run2_alt_with_layer2_r21_v0"==tune) {
297  add_scale("layer2_alt_run2_r21_v0");
298  add_scale("ps_2016_r21_v0");
299  }
300  else if("run2_alt_with_layer2_modif" == tune) {
301  add_scale("ps_EMECHV1");
302  add_scale("layer2_alt_run2_v1");
303  add_scale("ps_2016");
304  }
305  // 2012
306  else if ("2012" == tune) {
307  add_scale("ps_HV1");
308  add_scale("layer1_2012");
309  add_scale("ps_2012");
310  }
311  else if("2012_with_layer2" == tune) {
312  add_scale("ps_HV1");
313  add_scale("layer2_2012_v5");
314  add_scale("ps_2012");
315  }
316  else if ("2012_alt" == tune) {
317  add_scale("ps_HV1");
318  add_scale("layer1_alt_2012");
319  add_scale("ps_2012");
320  }
321  else if("2012_alt_with_layer2" == tune) {
322  add_scale("ps_HV1");
323  add_scale("layer2_alt_2012_v5");
324  add_scale("ps_2012");
325  }
326  else if("2012_alt_with_layer2_modif" == tune) {
327  add_scale("ps_HV1");
328  add_scale("ps_EMECHV1");
329  add_scale("layer2_alt_2012_v5");
330  add_scale("ps_2012");
331  }
332  else if("2010_with_layer2" == tune) {
333  add_scale("layer2_2010_v5");
334  add_scale("ps_2010");
335  }
336  else if ("2012_layer1_up" == tune) {
337  add_scale("ps_HV1");
338  add_scale("layer1_2012_up");
339  add_scale("ps_2012");
340  }
341  else if ("2012_layer1_down" == tune) {
342  add_scale("ps_HV1");
343  add_scale("layer1_2012_down");
344  add_scale("ps_2012");
345  }
346  else if ("2012_layer1_errup" == tune) {
347  add_scale("layer1_2012_errup");
348  }
349  else if ("2012_layer1_errdown" == tune) {
350  add_scale("layer1_2012_errdown");
351  }
352  else if ("2012_ps_down" == tune) {
353  add_scale("ps_HV1");
354  add_scale("layer1_2012");
355  add_scale("ps_2012_down");
356  }
357  else if ("2012_ps_up" == tune) {
358  add_scale("ps_HV1");
359  add_scale("layer1_2012");
360  add_scale("ps_2012_up");
361  }
362  else if ("2012_ps_errdown" == tune) {
363  add_scale("ps_2012_errdown");
364  }
365  else if ("2012_ps_errup" == tune) {
366  add_scale("ps_2012_errup");
367  }
368  else if ("2012_up" == tune) {
369  add_scale("ps_HV1");
370  add_scale("layer1_2012_up");
371  add_scale("ps_2012_up");
372  }
373  else if ("2012_down" == tune) {
374  add_scale("ps_HV1");
375  add_scale("layer1_2012_down");
376  add_scale("ps_2012_down");
377  }
378  else if ("2012_errup" == tune) {
379  add_scale("layer1_2012_errup");
380  add_scale("ps_2012_errup");
381  }
382  else if ("2012_errdown" == tune) {
383  add_scale("layer1_2012_errdown");
384  add_scale("ps_2012_errdown");
385  }
386  // 2011
387  else if ("2011" == tune) {
388  add_scale("layer1_2011");
389  add_scale("ps_2011");
390  }
391  else if("2011_with_layer2" == tune) {
392  add_scale("layer2_2011_v5");
393  add_scale("ps_2011");
394  }
395  else if ("2011_alt" == tune) {
396  add_scale("layer1_alt_2011");
397  add_scale("ps_2011");
398  }
399  else if("2011_alt_with_layer2" == tune) {
400  add_scale("layer2_alt_2011_v5");
401  add_scale("ps_2011");
402  }
403  else if ("2011_layer1_up" == tune) {
404  add_scale("layer1_2011_up");
405  add_scale("ps_2011");
406  }
407  else if ("2011_layer1_down" == tune) {
408  add_scale("layer1_2011_down");
409  add_scale("ps_2011");
410  }
411  else if ("2011_layer1_errup" == tune) {
412  add_scale("layer1_2011_errup");
413  }
414  else if ("2011_layer1_errdown" == tune) {
415  add_scale("layer1_2011_errdown");
416  }
417  else if ("2011_ps_down" == tune) {
418  add_scale("layer1_2011");
419  add_scale("ps_2011_down");
420  }
421  else if ("2011_ps_up" == tune) {
422  add_scale("layer1_2011");
423  add_scale("ps_2011_up");
424  }
425  else if ("2011_ps_errdown" == tune) {
426  add_scale("ps_2011_errdown");
427  }
428  else if ("2011_ps_errup" == tune) {
429  add_scale("ps_2011_errup");
430  }
431  else if ("2011_up" == tune) {
432  add_scale("layer1_2011_up");
433  add_scale("ps_2011_up");
434  }
435  else if ("2011_down" == tune) {
436  add_scale("layer1_2011_down");
437  add_scale("ps_2011_down");
438  }
439  else if ("2011_errup" == tune) {
440  add_scale("layer1_2011_errup");
441  add_scale("ps_2011_errup");
442  }
443  else if ("2011_errdown" == tune) {
444  add_scale("layer1_2011_errdown");
445  add_scale("ps_2011_errdown");
446  }
447  // 2010
448  else if ("2010" == tune) {
449  add_scale("layer1_2010");
450  add_scale("ps_2010");
451  }
452  else if ("2010_layer1_up" == tune) {
453  add_scale("layer1_2010_up");
454  add_scale("ps_2010");
455  }
456  else if ("2010_layer1_down" == tune) {
457  add_scale("layer1_2010_down");
458  add_scale("ps_2010");
459  }
460  else if ("2010_layer1_errup" == tune) {
461  add_scale("layer1_2010_errup");
462  }
463  else if ("2010_layer1_errdown" == tune) {
464  add_scale("layer1_2010_errdown");
465  }
466  else if ("2010_ps_down" == tune) {
467  add_scale("layer1_2010");
468  add_scale("ps_2010_down");
469  }
470  else if ("2010_ps_up" == tune) {
471  add_scale("layer1_2010");
472  add_scale("ps_2010_up");
473  }
474  else if ("2010_ps_errdown" == tune) {
475  add_scale("ps_2010_errdown");
476  }
477  else if ("2010_ps_errup" == tune) {
478  add_scale("ps_2010_errup");
479  }
480  else if ("2010_up" == tune) {
481  add_scale("layer1_2010_up");
482  add_scale("ps_2010_up");
483  }
484  else if ("2010_down" == tune) {
485  add_scale("layer1_2010_down");
486  add_scale("ps_2010_down");
487  }
488  else if ("2010_errup" == tune) {
489  add_scale("layer1_2010_errup");
490  add_scale("ps_2010_errup");
491  }
492  else if ("2010_errdown" == tune) {
493  add_scale("layer1_2010_errdown");
494  add_scale("ps_2010_errdown");
495  }
496  else if ("ps_HV1" == tune) {
498  }
499  else if ("ps_EMECHV1" == tune) {
501  }
502  else if ("test1" == tune) {
503  TH1F h_presampler("h_presampler", "h_presampler", 10, -2.5, 2.5);
504  // just as an example, correct E0 by 0.1 * sign(eta)
505  // and E1 by 1%
506  for (int ibin = 1; ibin <= 5; ++ibin) {
507  h_presampler.SetBinContent(ibin, -0.1);
508  h_presampler.SetBinContent(ibin + 5, 0.1);
509  }
512  }
513  // repeated acc scale based on layer2_alt_el_mu_comb_r21_v0_fix
514  else if ("acc_zee_r22_v1" == tune) {
515  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v12/egammaLayerRecalibTunes.root");
516  TFile f(file.c_str());
517  TH2F* histo_acc = static_cast<TH2F*>(f.Get("hACC_Zee_rel22"));
518  assert(histo_acc);
520  new GetAmountHisto2DEtaCaloRunNumber(*histo_acc));
521  }
522  else if ("acc_zee_r22_v0" == tune) {
523  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v11/egammaLayerRecalibTunes.root");
524  TFile f(file.c_str());
525  TH2F* histo_acc = static_cast<TH2F*>(f.Get("hACC_Zee_rel22"));
526  assert(histo_acc);
528  new GetAmountHisto2DEtaCaloRunNumber(*histo_acc));
529  }
530  else if ("layer1_1" == tune) {
531  TFormula f("formula_layer1_1", "(abs(x)<1.425) ? 0.97 : 1");
533  }
534  else if ("layer1_2" == tune) {
535  TFormula f("formula_layer1_2", "(abs(x)<1.425) ? 0.97 : 1.05");
537  }
538  else if ("layer1_alt_2012_v5" == tune) {
539  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
540  TFile f(file.c_str());
541  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_alt_2012"));
543  new GetAmountHisto1D(*histo));
544  }
545  else if ("layer1_2012_v5" == tune) {
546  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
547  TFile f(file.c_str());
548  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
550  new GetAmountHisto1D(*histo));
551  }
552  else if ("layer1_2012_v5_down" == tune) {
553  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
554  TFile f(file.c_str());
555  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
557  new GetAmountHisto1DUp(*histo));
558  }
559  else if ("layer1_2012_v5_up" == tune) {
560  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
561  TFile f(file.c_str());
562  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
565  }
566  else if ("layer1_2012_v5_errdown" == tune) {
567  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
568  TFile f(file.c_str());
569  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
572  }
573  else if ("layer1_2012_v5_errup" == tune) {
574  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
575  TFile f(file.c_str());
576  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
579  }
580  else if ("layer1_alt_2011_v5" == tune) {
581  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
582  TFile f(file.c_str());
583  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_alt_2011"));
585  new GetAmountHisto1D(*histo));
586  }
587  else if ("layer1_2011_v5" == tune) {
588  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
589  TFile f(file.c_str());
590  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
592  new GetAmountHisto1D(*histo));
593  }
594  else if ("layer1_2011_v5_down" == tune) {
595  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
596  TFile f(file.c_str());
597  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
599  new GetAmountHisto1DUp(*histo));
600  }
601  else if ("layer1_2011_v5_up" == tune) {
602  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
603  TFile f(file.c_str());
604  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
607  }
608  else if ("layer1_2011_v5_errdown" == tune) {
609  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
610  TFile f(file.c_str());
611  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
614  }
615  else if ("layer1_2011_v5_errup" == tune) {
616  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
617  TFile f(file.c_str());
618  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
621  }
622  else if ("layer1_2010_v5" == tune) {
623  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
624  TFile f(file.c_str());
625  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
627  new GetAmountHisto1D(*histo));
628  }
629  else if ("layer1_2010_v5_down" == tune) {
630  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
631  TFile f(file.c_str());
632  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
634  new GetAmountHisto1DUp(*histo));
635  }
636  else if ("layer1_2010_v5_up" == tune) {
637  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
638  TFile f(file.c_str());
639  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
642  }
643  else if ("layer1_2010_v5_errdown" == tune) {
644  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
645  TFile f(file.c_str());
646  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
649  }
650  else if ("layer1_2010_v5_errup" == tune) {
651  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
652  TFile f(file.c_str());
653  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
656  }
657  // fix E1E2 scale from R21 precision model
658  else if("layer2_alt_el_mu_comb_r21_v0_fix"==tune) {
659  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v12/egammaLayerRecalibTunes.root");
660  TFile f(file.c_str());
661  TH1D* histo = static_cast<TH1D*>(f.Get("hE1E2_emu_run2_rel21_v0_fix"));
662  assert(histo);
664  new GetAmountHisto1D(*histo));
665  }
666  else if("layer2_alt_el_mu_comb_r21_v0"==tune) {
667  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v11/egammaLayerRecalibTunes.root");
668  TFile f(file.c_str());
669  TH1D* histo = static_cast<TH1D*>(f.Get("hE1E2_emu_run2_rel21_v0"));
670  assert(histo);
672  new GetAmountHisto1D(*histo));
673  }
674  else if("layer2_alt_run2_r21_v1"==tune) {
675  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v6/egammaLayerRecalibTunes.root");
676  TFile f(file.c_str());
677  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2_mu_run2_rel21_v1"));
679  new GetAmountHisto1D(*histo));
680  }
681  else if("layer2_alt_run2_r21_v0"==tune) {
682  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v5/egammaLayerRecalibTunes.root");
683  TFile f(file.c_str());
684  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2mu_2016_rel21_v1"));
686  new GetAmountHisto1D(*histo));
687  }
688  else if("layer2_alt_run2_v1" == tune) {
689  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v3/egammaLayerRecalibTunes.root");
690  TFile f(file.c_str());
691  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2mu_2016_v1"));
693  new GetAmountHisto1D(*histo));
694  }
695  else if("layer2_alt_2012_v5" == tune) {
696  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
697  TFile f(file.c_str());
698  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_alt_2012"));
700  new GetAmountHisto1D(*histo));
701  }
702  else if("layer2_2012_v5" == tune) {
703  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
704  TFile f(file.c_str());
705  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
707  new GetAmountHisto1D(*histo));
708  }
709  else if("layer2_2012_v5_down" == tune) {
710  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
711  TFile f(file.c_str());
712  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
715  }
716  else if("layer2_2012_v5_up" == tune) {
717  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
718  TFile f(file.c_str());
719  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
721  new GetAmountHisto1DUp(*histo));
722  }
723  else if ("layer2_2012_v5_errdown" == tune) {
724  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
725  TFile f(file.c_str());
726  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
729  }
730  else if ("layer2_2012_v5_errup" == tune) {
731  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
732  TFile f(file.c_str());
733  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
736  }
737  else if("layer2_alt_2011_v5" == tune) {
738  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
739  TFile f(file.c_str());
740  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_alt_2011"));
742  new GetAmountHisto1D(*histo));
743  }
744  else if("layer2_2011_v5" == tune) {
745  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
746  TFile f(file.c_str());
747  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
749  new GetAmountHisto1D(*histo));
750  }
751  else if("layer2_2011_v5_down" == tune) {
752  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
753  TFile f(file.c_str());
754  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
757  }
758  else if("layer2_2011_v5_up" == tune) {
759  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
760  TFile f(file.c_str());
761  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
763  new GetAmountHisto1DUp(*histo));
764  }
765  else if ("layer2_2011_v5_errdown" == tune) {
766  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
767  TFile f(file.c_str());
768  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
771  }
772  else if ("layer2_2011_v5_errup" == tune) {
773  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
774  TFile f(file.c_str());
775  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
778  }
779  else if("layer2_2010_v5" == tune) {
780  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
781  TFile f(file.c_str());
782  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
784  new GetAmountHisto1D(*histo));
785  }
786  else if("layer2_2010_v5_down" == tune) {
787  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
788  TFile f(file.c_str());
789  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
792  }
793  else if("layer2_2010_v5_up" == tune) {
794  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
795  TFile f(file.c_str());
796  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
798  new GetAmountHisto1DUp(*histo));
799  }
800  else if ("layer2_2010_v5_errdown" == tune) {
801  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
802  TFile f(file.c_str());
803  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
806  }
807  else if ("layer2_2010_v5_errup" == tune) {
808  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
809  TFile f(file.c_str());
810  TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
813  }
814  else if ("ps_2016_r21_v0" == tune) {
815  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v5/egammaLayerRecalibTunes.root");
816  TFile f(file.c_str());
817  TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2016_rel21"));
819  new GetAmountHisto1D(*histo_ps_tot_error));
820  }
821  else if ("ps_mu_r21_v0" == tune) {
822  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v11/egammaLayerRecalibTunes.root");
823  TFile f(file.c_str());
824  TH1F* histo_ps_tot_error = static_cast<TH1F*>(f.Get("hPS_MuonLowMu_rel21"));
825  assert(histo_ps_tot_error);
827  new GetAmountHisto1D(*histo_ps_tot_error));
828  }
829  else if ("ps_2016_v1" == tune) {
830  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v4/egammaLayerRecalibTunes.root");
831  TFile f(file.c_str());
832  TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2016"));
834  new GetAmountHisto1D(*histo_ps_tot_error));
835  }
836  else if ("ps_2012_v3" == tune) {
837  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
838  TFile f(file.c_str());
839  TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2012"));
841  new GetAmountHisto1D(*histo_ps_tot_error));
842  }
843  else if ("ps_2012_v3_down" == tune) {
844  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
845  TFile f(file.c_str());
846  TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2012"));
848  new GetAmountHisto1DUp(*histo_ps_tot_error));
849  }
850  else if ("ps_2012_v3_up" == tune){
851  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
852  TFile f(file.c_str());
853  TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2012"));
855  new GetAmountHisto1DDown(*histo_ps_tot_error));
856  }
857  else if ("ps_2012_v3_errdown" == tune){
858  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
859  TFile f(file.c_str());
860  TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2012"));
862  new GetAmountHisto1DErrorUp(*histo_ps_tot_error));
863  }
864  else if ("ps_2012_v3_errup" == tune){
865  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
866  TFile f(file.c_str());
867  TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2012"));
869  new GetAmountHisto1DErrorDown(*histo_ps_tot_error));
870  }
871  else if ("ps_2011_v3" == tune) {
872  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
873  TFile f(file.c_str());
874  TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2011"));
876  new GetAmountHisto1D(*histo_ps_tot_error));
877  }
878  else if ("ps_2011_v3_down" == tune) {
879  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
880  TFile f(file.c_str());
881  TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2011"));
883  new GetAmountHisto1DUp(*histo_ps_tot_error));
884  }
885  else if ("ps_2011_v3_up" == tune){
886  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
887  TFile f(file.c_str());
888  TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2011"));
890  new GetAmountHisto1DDown(*histo_ps_tot_error));
891  }
892  else if ("ps_2011_v3_errdown" == tune){
893  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
894  TFile f(file.c_str());
895  TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2011"));
897  new GetAmountHisto1DErrorUp(*histo_ps_tot_error));
898  }
899  else if ("ps_2011_v3_errup" == tune){
900  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
901  TFile f(file.c_str());
902  TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2011"));
904  new GetAmountHisto1DErrorDown(*histo_ps_tot_error));
905  }
906  // 2010
907  else if ("ps_2010_v3" == tune) {
908  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
909  TFile f(file.c_str());
910  TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2010"));
912  new GetAmountHisto1D(*histo_ps_tot_error));
913  }
914  else if ("ps_2010_v3_down" == tune) {
915  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
916  TFile f(file.c_str());
917  TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2010"));
919  new GetAmountHisto1DUp(*histo_ps_tot_error));
920  }
921  else if ("ps_2010_v3_up" == tune) {
922  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
923  TFile f(file.c_str());
924  TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2010"));
926  new GetAmountHisto1DDown(*histo_ps_tot_error));
927  }
928  else if ("ps_2010_v3_errdown" == tune){
929  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
930  TFile f(file.c_str());
931  TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2010"));
933  new GetAmountHisto1DErrorUp(*histo_ps_tot_error));
934  }
935  else if ("ps_2010_v3_errup" == tune){
936  const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
937  TFile f(file.c_str());
938  TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2010"));
940  new GetAmountHisto1DErrorDown(*histo_ps_tot_error));
941  }
942  else {
943  throw std::runtime_error(tune+" is not a valid tune");
944  }
945 }
946 
947 egammaLayerRecalibTool::egammaLayerRecalibTool(const std::string& name, const std::string& tune, int SaccEnable)
948  : asg::AsgMessaging(name), m_tune(tune), m_doSaccCorrections(SaccEnable)
949 {
950  add_scale(tune);
951 }
952 
953 
954 egammaLayerRecalibTool::egammaLayerRecalibTool(const std::string& tune, int SaccEnable)
955  : egammaLayerRecalibTool("egammaLayerRecalibTool", tune, SaccEnable) { }
956 
957 
959 {
960  m_modifiers.emplace_back(modifier, amount);
961 }
962 
964 {
966  for (const auto& modifier : m_modifiers) {
967  const float amount = (*modifier.second)(inputs);
968  const auto s = (*modifier.first)(inputs, amount);
969  ATH_MSG_DEBUG(" after E0|E1|E2|E3 = " << inputs.E0raw << "|" << inputs.E1raw << "|" << inputs.E2raw << "|" << inputs.E3raw);
970  if (s != CP::CorrectionCode::Ok) {
972  }
973  }
974  return status;
975 }
976 
978 {
979  const xAOD::CaloCluster* cluster = particle.caloCluster();
980  if (!cluster) {
981  ATH_MSG_ERROR("egamma particle without CaloCluster");
983  }
984 
985  std::string fixT = "";
986  double addE2 = 0, addE3 = 0;
987  if (m_aodFixMissingCells &&
988  event_info.runNumber() > m_Run2Run3runNumberTransition) {
989  fixT = "_egFixForTopoTimingCut";
990  unsigned short stat =
992  if (stat) {
993  ATH_MSG_WARNING("Fix for missing cells required"
994  " but some layer info is not available,"
995  " from L2 : " << stat%2 << " from L3 : " << stat/2);
996  }
997  }
998 
999  double eta_calo;
1000  static const SG::AuxElement::Accessor<float> accEtaCalo("etaCalo");
1002  eta_calo = cluster->eta();
1003  }
1004  else if (cluster->retrieveMoment(xAOD::CaloCluster::ETACALOFRAME, eta_calo)){
1005 
1006  }
1007  else if (accEtaCalo.isAvailable(*cluster)) {
1008  eta_calo = accEtaCalo(*cluster);
1009  }
1010  else{
1011  ATH_MSG_ERROR("etaCalo not available as auxilliary variable,"
1012  " using cluster eta as eta calo!");
1013  eta_calo=cluster->eta();
1014  }
1015 
1017  event_info.averageInteractionsPerCrossing(),
1018  event_info.runNumber(),
1019  cluster->eta(),
1020  cluster->phi(),
1021  cluster->energyBE(0),
1022  cluster->energyBE(1),
1023  cluster->energyBE(2) + addE2,
1024  cluster->energyBE(3) + addE3,
1025  eta_calo };
1026 
1027  bool isData = !event_info.eventType(xAOD::EventInfo::IS_SIMULATION);
1029  if (isData || m_scaleMC)
1031 
1032  static const SG::AuxElement::Decorator<double> deco_E0("correctedcl_Es0");
1033  static const SG::AuxElement::Decorator<double> deco_E1("correctedcl_Es1");
1034  static const SG::AuxElement::Decorator<double> deco_E2("correctedcl_Es2");
1035  static const SG::AuxElement::Decorator<double> deco_E3("correctedcl_Es3");
1037  deco_layer_correction("layer_correction");
1038 
1039  if (status == CP::CorrectionCode::Ok) {
1040  ATH_MSG_DEBUG("decorating cluster with corrected layer energies");
1041  deco_E0(*cluster) = m_doPSCorrections ?
1042  inputs.E0raw : cluster->energyBE(0);
1043  deco_E1(*cluster) = m_doS12Corrections or m_doSaccCorrections ?
1044  inputs.E1raw : cluster->energyBE(1);
1045  deco_E2(*cluster) = m_doS12Corrections or m_doSaccCorrections ?
1046  inputs.E2raw : cluster->energyBE(2) + addE2;
1047  deco_E3(*cluster) = m_doSaccCorrections ?
1048  inputs.E3raw : cluster->energyBE(3) + addE3;
1049  deco_layer_correction(*cluster) = isData ? m_tune+fixT : fixT;
1050  return status;
1051  }
1052 
1053  ATH_MSG_DEBUG("cannot correct layer energies:"
1054  " decorating particle with non-corrected layer energies");
1055  // this is done for safety, since when a particle is decorated
1056  // all the particle in the container are decorated
1057  // it is not possible to distinguish between decorated / non-decorated
1058  // since all are decorated
1059  deco_E0(*cluster) = cluster->energyBE(0);
1060  deco_E1(*cluster) = cluster->energyBE(1);
1061  deco_E2(*cluster) = cluster->energyBE(2) + addE2;
1062  deco_E3(*cluster) = cluster->energyBE(3) + addE3;
1063  deco_layer_correction(*cluster) = isData ? m_tune + "_Err" + fixT : fixT;
1064  return status;
1065 
1066 }
1067 
1068 
1070 {
1071  for (auto modifier : m_modifiers) {
1072  delete modifier.first;
1073  delete modifier.second;
1074  }
1075  m_modifiers.clear();
1076 }
1077 
1078 
1079 // helper
1080 std::map<std::string, std::string> parse(const std::string& list)
1081 {
1082  std::cout << "list: '" << list << "'" << std::endl;
1083  std::map<std::string, std::string> result;
1084  TIter next(TString(list).Tokenize(","));
1085  while (TObjString* sObj = (TObjString*) next())
1086  {
1087  const TString& item(sObj->GetString());
1088  std::cout << "item: '" << item << "'" << std::endl;
1089  TObjArray* item_list = TString(item).Tokenize(":");
1090  std::string key;
1091  std::string value;
1092  if (item_list->GetEntries() == 1) {
1093  key = "amount";
1094  value = static_cast<TObjString*>(item_list->At(0))->GetString().Data();
1095  }
1096  else if (item_list->GetEntries() == 2) {
1097  key = static_cast<TObjString*>(item_list->At(0))->GetString().Data();
1098  value = static_cast<TObjString*>(item_list->At(1))->GetString().Data();
1099  }
1100  else {
1101  std::cerr << "invalid string " << item << std::endl;
1102  }
1103  if (result.find(key) != result.end()) {
1104  std::cerr << "trying to insert two times key " << key << std::endl;
1105  assert(false);
1106  }
1107  result.insert(std::make_pair(key, value));
1108  }
1109  return result;
1110 }
1111 
1112 
1113 std::pair<std::string, egammaLayerRecalibTool*>
1114 egammaLayerRecalibTool::create(const std::string& type, const std::string& args)
1115 {
1116  std::map<std::string, std::string> args_map = parse(args);
1117  egammaLayerRecalibTool* tool = new egammaLayerRecalibTool("egammaLayerRecalibTool", "");
1118  std::string name = "";
1119  std::string amount_name = "";
1120  std::string type_name = "";
1121 
1122  GetAmountBase* amount_getter = nullptr;
1123  InputModifier* modifier = nullptr;
1124 
1125  if (args_map.find("amount") != args_map.end()) {
1126  std::string amount_str = args_map["amount"];
1127  bool perc = false;
1128  if (amount_str.back()=='%') {
1129  perc = true;
1130  amount_str.pop_back();
1131  }
1132  const float amount = TString(amount_str).Atof() * (perc ? 0.01 : 1);
1133 
1134  amount_getter = new GetAmountFixed(amount);
1135  std::stringstream amount_stream;
1136  amount_stream << amount;
1137  amount_name = amount_stream.str();
1138  std::replace(amount_name.begin(), amount_name.end(), '-', 'n');
1139  std::replace(amount_name.begin(), amount_name.end(), '.', 'p');
1140  }
1141  else if (args_map.find("name") != args_map.end()) {
1142  name = args_map["name"];
1143  }
1144  else if (args_map.find("histo") != args_map.end()) {
1145  int dim = 0;
1146  if (args_map.find("file") == args_map.end()) {
1147  std::cerr << "with histo you must specify file" << std::endl;
1148  assert(false);
1149  }
1150  if (args_map.find("formulax") != args_map.end()) dim = 1;
1151 
1152  if (dim == 0)
1153  {
1154  std::cerr << "with histo you must specify formulax" << std::endl;
1155  assert(false);
1156  }
1157  if (dim == 1) {
1158  TFile f(args_map["file"].c_str());
1159  std::cout << "opening histo " << args_map["histo"] << " from file " << args_map["file"] << std::endl;
1160  TH1F* histo = dynamic_cast<TH1F*>(f.Get(args_map["histo"].c_str()));
1161 
1162  if(histo){
1163  histo->SetDirectory(nullptr);
1164  amount_getter = new GetAmountHisto1D(*histo);
1165  }
1166  else{assert(false); }
1167  }
1168  else { assert(false); }
1169  }
1170  else {
1171  std::cerr << "cannot understand argument " << args << std::endl;
1172  assert(false);
1173  }
1174 
1175  if ("bias-E0" == type) { modifier = new ScaleE0(InputModifier::ZEROBASED); type_name = "E0"; }
1176  else if ("bias-E1" == type) { modifier = new ScaleE1(InputModifier::ZEROBASED); type_name = "E1"; }
1177  else if ("bias-E2" == type) { modifier = new ScaleE2(InputModifier::ZEROBASED); type_name = "E2"; }
1178  else if ("bias-E3" == type) { modifier = new ScaleE3(InputModifier::ZEROBASED); type_name = "E3"; }
1179  else if ("bias-E1overE2" == type) { modifier = new ScaleE1overE2(InputModifier::ZEROBASED); type_name = "E1overE2"; }
1180  else if ("bias-Eaccordion" == type) { modifier = new ScaleEaccordion(InputModifier::ZEROBASED); type_name = "Eaccordion"; }
1181  else if ("bias-Ecalorimeter" == type) { modifier = new ScaleEcalorimeter(InputModifier::ZEROBASED); type_name = "Ecalorimeter"; }
1182 
1183  if (not type_name.empty() and not amount_name.empty()) {
1184  name = type_name + "_" + amount_name;
1185  }
1186 
1187  if (name.empty()) {
1188  std::cerr << "you need to specify a name for the bias with type " << type << std::endl;
1189  }
1190 
1191  if (modifier and amount_getter) {
1192  tool->add_scale(modifier, amount_getter);
1193  }
1194  else{
1195  tool->add_scale(type);
1196  //release resources, if modifier false need to release amount_getter and vice versa
1197  //since they are not passed to the tool
1198  if(modifier) delete modifier;
1199  if(amount_getter) delete amount_getter;
1200  }
1201 
1202  return {name, tool};
1203 }
InputModifier::SCALE
@ SCALE
Definition: egammaLayerRecalibTool.h:205
corr_HV_EMBPS::getCorr
float getCorr(int run, float eta, float phi) const
get correction factor to apply to raw EMBPS energy : corrected raw EMBPS energy = correction factor *...
Definition: corr_HV_EMBPS.cxx:45
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
GetAmountHVPSGuillaume
Definition: egammaLayerRecalibTool.h:68
xAOD::EgammaHelpers::energyInMissingCells
unsigned short energyInMissingCells(const xAOD::Egamma &eg, double &e2, double &e3)
Get the energies in sampling 2 and 3 that are in cells rejected by the topo-cluster timing cut but th...
Definition: EgammaxAODHelpers.cxx:176
GetAmountPileupE3
Definition: egammaLayerRecalibTool.h:106
GetAmountHVPSGuillaume::m_tool
corr_HV_EMBPS m_tool
Definition: egammaLayerRecalibTool.h:71
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
yodamerge_tmp.dim
dim
Definition: yodamerge_tmp.py:239
add-xsec-uncert-quadrature-N.alpha
alpha
Definition: add-xsec-uncert-quadrature-N.py:110
get_generator_info.result
result
Definition: get_generator_info.py:21
GetAmountHisto1D::operator()
virtual float operator()(const StdCalibrationInputs &input) const
Definition: egammaLayerRecalibTool.cxx:53
ScaleE3::shift_inputs
virtual void shift_inputs(StdCalibrationInputs &, float amount) const
Definition: egammaLayerRecalibTool.cxx:152
egammaLayerRecalibTool::m_aodFixMissingCells
bool m_aodFixMissingCells
Definition: egammaLayerRecalibTool.h:342
egammaLayerRecalibTool::m_pileup_tool
corr_pileupShift * m_pileup_tool
Definition: egammaLayerRecalibTool.h:340
InputModifier::ZEROBASED
@ ZEROBASED
Definition: egammaLayerRecalibTool.h:205
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
python.CaloAddPedShiftConfig.args
args
Definition: CaloAddPedShiftConfig.py:45
InputModifier::SHIFT
@ SHIFT
Definition: egammaLayerRecalibTool.h:205
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
GetAmountPileupE2::operator()
virtual float operator()(const StdCalibrationInputs &inputs) const
Definition: egammaLayerRecalibTool.cxx:119
GetAmountBase
Definition: egammaLayerRecalibTool.h:60
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
NNPDF30NNLO.tune
tune
Definition: GeneratorFilters/share/common/NNPDF30NNLO.py:1
GetAmountPileupE0::m_tool
corr_pileupShift * m_tool
Definition: egammaLayerRecalibTool.h:86
GetAmountFixed::operator()
virtual float operator()(const StdCalibrationInputs &input) const
Definition: egammaLayerRecalibTool.cxx:95
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1080
asg
Definition: DataHandleTestTool.h:28
GetAmountPileupE2::m_tool
corr_pileupShift * m_tool
Definition: egammaLayerRecalibTool.h:102
bin
Definition: BinsDiffFromStripMedian.h:43
egammaLayerRecalibTool::scale_inputs
CP::CorrectionCode scale_inputs(StdCalibrationInputs &inputs) const
apply layer calibration to the
Definition: egammaLayerRecalibTool.cxx:963
athena.value
value
Definition: athena.py:124
ScaleE0::shift_inputs
virtual void shift_inputs(StdCalibrationInputs &, float amount) const
Definition: egammaLayerRecalibTool.cxx:149
GetAmountHVEMECPS207::operator()
virtual float operator()(const StdCalibrationInputs &input) const
Definition: egammaLayerRecalibTool.cxx:107
GetAmountPileupE2
Definition: egammaLayerRecalibTool.h:98
xAOD::Egamma_v1
Definition: Egamma_v1.h:56
egammaLayerRecalibTool::applyCorrection
CP::CorrectionCode applyCorrection(xAOD::Egamma &, const xAOD::EventInfo &event_info) const
Definition: egammaLayerRecalibTool.cxx:977
GetAmountPileupE1::operator()
virtual float operator()(const StdCalibrationInputs &inputs) const
Definition: egammaLayerRecalibTool.cxx:115
xAOD::EgammaParameters::AuthorFwdElectron
const uint16_t AuthorFwdElectron
Electron reconstructed by the Forward cluster-based algorithm.
Definition: EgammaDefs.h:30
GetAmountHisto1DUp::operator()
virtual float operator()(const StdCalibrationInputs &input) const
Definition: egammaLayerRecalibTool.cxx:59
GetAmountFormula::operator()
virtual float operator()(const StdCalibrationInputs &input) const
Definition: egammaLayerRecalibTool.cxx:99
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
corr_pileupShift
Correction for pileup induced energy shit as function of mu per layer for 2016 data.
Definition: corr_pileupShift.h:13
InputModifier::shift_inputs
virtual void shift_inputs(StdCalibrationInputs &, float amount) const =0
xAOD::EventInfo_v1::IS_SIMULATION
@ IS_SIMULATION
true: simulation, false: data
Definition: EventInfo_v1.h:151
ScaleE3
Definition: egammaLayerRecalibTool.h:247
python.TrigEgammaMonitorHelper.TH2F
def TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:45
GetAmountHisto2DEtaCaloRunNumber
Definition: egammaLayerRecalibTool.h:173
ScaleE1overE2::scale_inputs
virtual void scale_inputs(StdCalibrationInputs &, float amount) const
Definition: egammaLayerRecalibTool.cxx:155
GetAmountHisto2D::m_histo
TH2F m_histo
Definition: egammaLayerRecalibTool.h:168
InputModifier::SUBTRACT
@ SUBTRACT
Definition: egammaLayerRecalibTool.h:205
postInclude.inputs
inputs
Definition: postInclude.SortInput.py:15
GetAmountFixed::m_amount
float m_amount
Definition: egammaLayerRecalibTool.h:187
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
GetAmountPileupE1::m_tool
corr_pileupShift * m_tool
Definition: egammaLayerRecalibTool.h:94
xAOD::EventInfo_v1::runNumber
uint32_t runNumber() const
The current event's run number.
GetAmountHisto2DEtaCaloRunNumber::m_histo
TH2F m_histo
Definition: egammaLayerRecalibTool.h:177
ScaleE1::shift_inputs
virtual void shift_inputs(StdCalibrationInputs &, float amount) const
Definition: egammaLayerRecalibTool.cxx:150
InputModifier::ONEBASED_ALPHA
@ ONEBASED_ALPHA
Definition: egammaLayerRecalibTool.h:205
GetAmountHisto1DErrorDown
Definition: egammaLayerRecalibTool.h:158
ScaleE0
Definition: egammaLayerRecalibTool.h:220
PyPoolBrowser.item
item
Definition: PyPoolBrowser.py:129
GetAmountHisto2DEtaCaloRunNumber::operator()
virtual float operator()(const StdCalibrationInputs &input) const
Definition: egammaLayerRecalibTool.cxx:89
CP::CorrectionCode::OutOfValidityRange
@ OutOfValidityRange
Input object is out of validity range.
Definition: CorrectionCode.h:37
CP::CorrectionCode::Error
@ Error
Some error happened during the object correction.
Definition: CorrectionCode.h:36
ScaleEcalorimeter
Definition: egammaLayerRecalibTool.h:274
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:62
EgammaxAODHelpers.h
GetAmountHisto1DDown::operator()
virtual float operator()(const StdCalibrationInputs &input) const
Definition: egammaLayerRecalibTool.cxx:65
egammaLayerRecalibTool::m_modifiers
ModifiersList m_modifiers
Definition: egammaLayerRecalibTool.h:338
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
InputModifier::ONEBASED
@ ONEBASED
Definition: egammaLayerRecalibTool.h:205
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
corr_pileupShift::getCorr
float getCorr(int layer, int run, float mu, float eta) const
get shift to subtract to raw layer energy : corrected layer energy = raw energy - shift
Definition: corr_pileupShift.cxx:37
GetAmountPileupE0::operator()
virtual float operator()(const StdCalibrationInputs &inputs) const
Definition: egammaLayerRecalibTool.cxx:111
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:59
fillPileUpNoiseLumi.next
next
Definition: fillPileUpNoiseLumi.py:52
GetAmountPileupE1
Definition: egammaLayerRecalibTool.h:90
GetAmountPileupE3::m_tool
corr_pileupShift * m_tool
Definition: egammaLayerRecalibTool.h:110
egammaLayerRecalibTool::egammaLayerRecalibTool
egammaLayerRecalibTool(const std::string &name, const std::string &tune, int SaccEnable=1)
Definition: egammaLayerRecalibTool.cxx:947
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
GetAmountPileupE3::operator()
virtual float operator()(const StdCalibrationInputs &inputs) const
Definition: egammaLayerRecalibTool.cxx:123
GetAmountFormula
Definition: egammaLayerRecalibTool.h:116
GetAmountFixed
Definition: egammaLayerRecalibTool.h:182
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
egammaLayerRecalibTool::clear_corrections
void clear_corrections()
remove all the scale corrections
Definition: egammaLayerRecalibTool.cxx:1069
ScaleE2::scale_inputs
virtual void scale_inputs(StdCalibrationInputs &, float amount) const
Definition: egammaLayerRecalibTool.cxx:146
file
TFile * file
Definition: tile_monitor.h:29
egammaLayerRecalibTool.h
hist_file_dump.f
f
Definition: hist_file_dump.py:141
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
egammaLayerRecalibTool::m_scaleMC
bool m_scaleMC
Definition: egammaLayerRecalibTool.h:343
InputModifier::ZEROBASED_ALPHA
@ ZEROBASED_ALPHA
Definition: egammaLayerRecalibTool.h:205
GetAmountHVEMECPS207
Definition: egammaLayerRecalibTool.h:75
beamspotman.stat
stat
Definition: beamspotman.py:266
ScaleE1
Definition: egammaLayerRecalibTool.h:229
egammaLayerRecalibTool::m_doPSCorrections
bool m_doPSCorrections
Definition: egammaLayerRecalibTool.h:333
egammaLayerRecalibTool::m_doSaccCorrections
bool m_doSaccCorrections
Definition: egammaLayerRecalibTool.h:335
egammaLayerRecalibTool::m_Run2Run3runNumberTransition
static const unsigned int m_Run2Run3runNumberTransition
Definition: egammaLayerRecalibTool.h:330
xAOD::EventInfo_v1::averageInteractionsPerCrossing
float averageInteractionsPerCrossing() const
Average interactions per crossing for all BCIDs - for out-of-time pile-up.
Definition: EventInfo_v1.cxx:397
PathResolver.h
InputModifier
Definition: egammaLayerRecalibTool.h:204
ScaleEaccordion::shift_inputs
virtual void shift_inputs(StdCalibrationInputs &, float amount) const
Definition: egammaLayerRecalibTool.cxx:184
egammaLayerRecalibTool::add_scale
void add_scale(InputModifier *modifier, GetAmountBase *amount)
add custom layer scale correction.
Definition: egammaLayerRecalibTool.cxx:958
ScaleE1::scale_inputs
virtual void scale_inputs(StdCalibrationInputs &, float amount) const
Definition: egammaLayerRecalibTool.cxx:145
GetAmountHisto1DErrorUp
Definition: egammaLayerRecalibTool.h:151
ScaleE3::scale_inputs
virtual void scale_inputs(StdCalibrationInputs &, float amount) const
Definition: egammaLayerRecalibTool.cxx:147
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
GetAmountPileupE0
Definition: egammaLayerRecalibTool.h:82
ScaleE2::shift_inputs
virtual void shift_inputs(StdCalibrationInputs &, float amount) const
Definition: egammaLayerRecalibTool.cxx:151
pool::Tokenize
void Tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
GetAmountHisto1D
Definition: egammaLayerRecalibTool.h:125
InputModifier::scale_inputs
virtual void scale_inputs(StdCalibrationInputs &, float amount) const =0
item
Definition: ItemListSvc.h:43
make_hlt_rep.modifier
string modifier
Definition: make_hlt_rep.py:14
GetAmountHVPSGuillaume::operator()
virtual float operator()(const StdCalibrationInputs &input) const
Definition: egammaLayerRecalibTool.cxx:103
GetAmountHisto1DErrorDown::operator()
virtual float operator()(const StdCalibrationInputs &input) const
Definition: egammaLayerRecalibTool.cxx:77
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
egammaLayerRecalibTool
Definition: egammaLayerRecalibTool.h:283
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
GetAmountHisto1DErrorUp::operator()
virtual float operator()(const StdCalibrationInputs &input) const
Definition: egammaLayerRecalibTool.cxx:71
ScaleEaccordion
Definition: egammaLayerRecalibTool.h:265
ScaleEcalorimeter::scale_inputs
virtual void scale_inputs(StdCalibrationInputs &, float amount) const
Definition: egammaLayerRecalibTool.cxx:191
StdCalibrationInputs
Name : egammaLayerRecalibTool.h Package : egammaLayerRecalibTool Author : R.
Definition: egammaLayerRecalibTool.h:45
ScaleE1overE2
Definition: egammaLayerRecalibTool.h:256
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
egammaLayerRecalibTool::resolve_alias
static std::string resolve_alias(const std::string &tune)
Definition: egammaLayerRecalibTool.cxx:207
egammaLayerRecalibTool::create
static std::pair< std::string, egammaLayerRecalibTool * > create(const std::string &type, const std::string &args)
helper to create a tool from a string (useful for command line arguments)
Definition: egammaLayerRecalibTool.cxx:1114
ScaleE2
Definition: egammaLayerRecalibTool.h:238
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
ScaleE0::scale_inputs
virtual void scale_inputs(StdCalibrationInputs &, float amount) const
Definition: egammaLayerRecalibTool.cxx:144
InputModifier::m_base
NullPoint m_base
Definition: egammaLayerRecalibTool.h:215
egammaLayerRecalibTool::m_doS12Corrections
bool m_doS12Corrections
Definition: egammaLayerRecalibTool.h:334
ScaleEcalorimeter::shift_inputs
virtual void shift_inputs(StdCalibrationInputs &, float amount) const
Definition: egammaLayerRecalibTool.cxx:199
SG::ConstAccessor< T, AuxAllocator_t< T > >::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
merge.status
status
Definition: merge.py:17
corr_HV_EMECPS::getCorr
float getCorr(int run, float eta, float phi) const
get correction factor to apply to raw EMECPS energy : corrected raw EMECPS energy = correction factor...
Definition: corr_HV_EMECPS.cxx:41
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
ScaleEaccordion::scale_inputs
virtual void scale_inputs(StdCalibrationInputs &, float amount) const
Definition: egammaLayerRecalibTool.cxx:177
GetAmountHisto1DDown
Definition: egammaLayerRecalibTool.h:144
InputModifier::operator()
CP::CorrectionCode operator()(StdCalibrationInputs &, float amount) const
Definition: egammaLayerRecalibTool.cxx:128
GetAmountHisto1DUp
Definition: egammaLayerRecalibTool.h:137
egammaLayerRecalibTool::m_tune
std::string m_tune
Definition: egammaLayerRecalibTool.h:332
GetAmountHisto2D::operator()
virtual float operator()(const StdCalibrationInputs &input) const
Definition: egammaLayerRecalibTool.cxx:83
xAOD::CaloCluster_v1::ETACALOFRAME
@ ETACALOFRAME
Eta in the calo frame (for egamma)
Definition: CaloCluster_v1.h:190
plotBeamSpotCompare.histo
histo
Definition: plotBeamSpotCompare.py:415
python.PyAthena.obj
obj
Definition: PyAthena.py:132
GetAmountHVEMECPS207::m_toolEMECPS
corr_HV_EMECPS m_toolEMECPS
Definition: egammaLayerRecalibTool.h:78
ScaleE1overE2::shift_inputs
virtual void shift_inputs(StdCalibrationInputs &, float amount) const
Definition: egammaLayerRecalibTool.cxx:171
GetAmountFormula::m_formula
TFormula m_formula
Definition: egammaLayerRecalibTool.h:120
GetAmountHisto1D::m_histo
std::unique_ptr< TH1 > m_histo
Definition: egammaLayerRecalibTool.h:132
keylayer_zslicemap.perc
perc
Definition: keylayer_zslicemap.py:62
xAOD::EventInfo_v1::eventType
bool eventType(EventType type) const
Check for one particular bitmask value.
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37