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