ATLAS Offline Software
Loading...
Searching...
No Matches
egammaLayerRecalibTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6
7#include <TFile.h>
8#include <TObjString.h>
9
11
14
15#include <iostream>
16#include <stdexcept>
17#include <cassert>
18#include <map>
19#include <sstream>
20#include <algorithm>
21#include <cmath>
22#include <limits>
23
24namespace {
25const float VALUE_OVERFLOW = std::numeric_limits<float>::max();
26
27template <typename TargetPtr, typename SourcePtr>
28TargetPtr checked_cast(SourcePtr ptr) {
29 // Do we have ptr types
30 static_assert(std::is_pointer<TargetPtr>::value,
31 "attempt to cast to no ptr object");
32 static_assert(std::is_pointer<SourcePtr>::value,
33 "attempt to cast from no ptr object");
34
35 // nullptr input
36 if (!ptr) {
37 throw std::runtime_error(
38 "Attempt to cast from nullptr in egammaLayerRecalibTool");
39 }
40
41 // dynamic_cast and check
42 TargetPtr obj = dynamic_cast<TargetPtr>(ptr);
43 if (not obj) {
44 throw std::runtime_error("failed dynamic cast for " +
45 std::string(ptr->GetName()) +
46 " in egammaLayerRecalibTool");
47 }
48
49 return obj;
50}
51
52} // end anonymous namespace
53
55 const int bin = m_histo->FindFixBin(input.eta);
56 if (m_histo->IsBinUnderflow(bin) or m_histo->IsBinOverflow(bin)) return VALUE_OVERFLOW;
57 return m_histo->GetBinContent(bin);
58}
59
61 const int bin = m_histo->FindFixBin(input.eta);
62 if (m_histo->IsBinUnderflow(bin) or m_histo->IsBinOverflow(bin)) return VALUE_OVERFLOW;
63 return m_histo->GetBinContent(bin) + m_histo->GetBinError(bin);
64}
65
67 const int bin = m_histo->FindFixBin(input.eta);
68 if (m_histo->IsBinUnderflow(bin) or m_histo->IsBinOverflow(bin)) return VALUE_OVERFLOW;
69 return m_histo->GetBinContent(bin) - m_histo->GetBinError(bin);
70}
71
73 const int bin = m_histo->FindFixBin(input.eta);
74 if (m_histo->IsBinUnderflow(bin) or m_histo->IsBinOverflow(bin)) return VALUE_OVERFLOW;
75 return m_histo->GetBinError(bin);
76}
77
79 const int bin = m_histo->FindFixBin(input.eta);
80 if (m_histo->IsBinUnderflow(bin) or m_histo->IsBinOverflow(bin)) return VALUE_OVERFLOW;
81 return -m_histo->GetBinError(bin);
82}
83
85 const int bin = m_histo.FindFixBin(input.eta, input.phi);
86 if (m_histo.IsBinUnderflow(bin) or m_histo.IsBinOverflow(bin)) return VALUE_OVERFLOW;
87 return m_histo.GetBinContent(bin);
88}
89
91 const int bin = m_histo.FindFixBin(input.etaCalo, input.RunNumber);
92 if (m_histo.IsBinUnderflow(bin) or m_histo.IsBinOverflow(bin)) return VALUE_OVERFLOW;
93 return m_histo.GetBinContent(bin);
94}
95
96float GetAmountFixed::operator()(const StdCalibrationInputs & /*input*/ ) const {
97 return m_amount;
98}
99
101 return m_formula.Eval(input.eta, input.phi, input.RunNumber);
102}
103
105 return m_tool.getCorr(input.RunNumber, input.eta, input.phi);
106}
107
109 return m_toolEMECPS.getCorr(input.RunNumber, input.eta, input.phi);
110}
111
113 return m_tool->getCorr(0, input.RunNumber, input.averageInteractionsPerCrossing, input.eta);
114}
115
117 return m_tool->getCorr(1, input.RunNumber, input.averageInteractionsPerCrossing, input.eta);
118}
119
121 return m_tool->getCorr(2, input.RunNumber, input.averageInteractionsPerCrossing, input.eta);
122}
123
125 return m_tool->getCorr(3, input.RunNumber, input.averageInteractionsPerCrossing, input.eta);
126}
127
128
130{
131 if (amount == VALUE_OVERFLOW) return CP::CorrectionCode::OutOfValidityRange;
132 switch (m_base)
133 {
134 case SHIFT: shift_inputs(inputs, amount); return CP::CorrectionCode::Ok;
135 case SUBTRACT: shift_inputs(inputs, -amount); return CP::CorrectionCode::Ok;
136 case SCALE: scale_inputs(inputs, amount); return CP::CorrectionCode::Ok;
137 case ZEROBASED: scale_inputs(inputs, 1. + amount); return CP::CorrectionCode::Ok;
138 case ONEBASED: scale_inputs(inputs, amount); return CP::CorrectionCode::Ok;
139 case ONEBASED_ALPHA: scale_inputs(inputs, 1. / amount); return CP::CorrectionCode::Ok;
140 case ZEROBASED_ALPHA: scale_inputs(inputs, 1. / (1. + amount)); return CP::CorrectionCode::Ok;
141 default: return CP::CorrectionCode::Error;
142 };
143}
144
145void ScaleE0::scale_inputs(StdCalibrationInputs & inputs, float amount) const { inputs.E0raw *= amount; }
146void ScaleE1::scale_inputs(StdCalibrationInputs & inputs, float amount) const { inputs.E1raw *= amount; }
147void ScaleE2::scale_inputs(StdCalibrationInputs & inputs, float amount) const { inputs.E2raw *= amount; }
148void ScaleE3::scale_inputs(StdCalibrationInputs & inputs, float amount) const { inputs.E3raw *= amount; }
149
150void ScaleE0::shift_inputs(StdCalibrationInputs & inputs, float amount) const { inputs.E0raw += amount; }
151void ScaleE1::shift_inputs(StdCalibrationInputs & inputs, float amount) const { inputs.E1raw += amount; }
152void ScaleE2::shift_inputs(StdCalibrationInputs & inputs, float amount) const { inputs.E2raw += amount; }
153void ScaleE3::shift_inputs(StdCalibrationInputs & inputs, float amount) const { inputs.E3raw += amount; }
154
155
156void ScaleE1overE2::scale_inputs(StdCalibrationInputs & inputs, float amount) const
157{
158 const double Es1 = inputs.E1raw;
159 const double Es2 = inputs.E2raw;
160 if (Es1 == 0 and Es2 == 0) {
161 inputs.E1raw = -999;
162 inputs.E2raw = -999;
163 return;
164 }
165 const double sum = Es1 + Es2;
166 const double alpha = amount;
167 const double den = (alpha * Es1 + Es2);
168 inputs.E1raw = alpha * Es1 * sum / den;
169 inputs.E2raw = Es2 * sum / den;
170}
171
173{
174 // not very useful, never used
175 throw std::runtime_error("not implemented");
176}
177
178void ScaleEaccordion::scale_inputs(StdCalibrationInputs & inputs, float amount) const
179{
180 inputs.E1raw *= amount;
181 inputs.E2raw *= amount;
182 inputs.E3raw *= amount;
183}
184
185void ScaleEaccordion::shift_inputs(StdCalibrationInputs & inputs, float amount) const
186{
187 inputs.E1raw += amount;
188 inputs.E2raw += amount;
189 inputs.E3raw += amount;
190}
191
193{
194 inputs.E0raw *= amount;
195 inputs.E1raw *= amount;
196 inputs.E2raw *= amount;
197 inputs.E3raw *= amount;
198}
199
201{
202 inputs.E0raw += amount;
203 inputs.E1raw += amount;
204 inputs.E2raw += amount;
205 inputs.E3raw += amount;
206}
207
208std::string egammaLayerRecalibTool::resolve_alias(const std::string& tune) {
209
210 if ("layer1_2012" == tune) return "layer1_2012_v5";
211 if ("layer1_alt_2012" == tune) return "layer1_alt_2012_v5";
212 if ("layer1_2011" == tune) return "layer1_2011_v5";
213 if ("layer1_alt_2011" == tune) return "layer1_alt_2011_v5";
214 if ("layer1_2010" == tune) return "layer1_2010_v5";
215 if ("ps_2012" == tune) return "ps_2012_v3";
216 if ("ps_2011" == tune) return "ps_2011_v3";
217 if ("ps_2010" == tune) return "ps_2010_v3";
218 if ("layer1_2012_up" == tune) return "layer1_2012_v5_up";
219 if ("layer1_2012_down" == tune) return "layer1_2012_v5_down";
220 if ("layer1_2012_errup" == tune) return "layer1_2012_v5_errup";
221 if ("layer1_2012_errdown" == tune) return "layer1_2012_v5_errdown";
222 if ("layer1_2011_up" == tune) return "layer1_2011_v5_up";
223 if ("layer1_2011_down" == tune) return "layer1_2011_v5_down";
224 if ("layer1_2011_errup" == tune) return "layer1_2011_v5_errup";
225 if ("layer1_2011_errdown" == tune) return "layer1_2011_v5_errdown";
226 if ("layer1_2010_up" == tune) return "layer1_2010_v5_up";
227 if ("layer1_2010_down" == tune) return "layer1_2010_v5_down";
228 if ("layer1_2010_errup" == tune) return "layer1_2010_v5_errup";
229 if ("layer1_2010_errdown" == tune) return "layer1_2010_v5_errdown";
230 if ("ps_2012_up" == tune) return "ps_2012_v3_up";
231 if ("ps_2012_down" == tune) return "ps_2012_v3_down";
232 if ("ps_2012_errup" == tune) return "ps_2012_v3_errup";
233 if ("ps_2012_errdown" == tune) return "ps_2012_v3_errdown";
234 if ("ps_2011_up" == tune) return "ps_2011_v3_up";
235 if ("ps_2011_down" == tune) return "ps_2011_v3_down";
236 if ("ps_2011_errup" == tune) return "ps_2011_v3_errup";
237 if ("ps_2011_errdown" == tune) return "ps_2011_v3_errdown";
238 if ("ps_2010_up" == tune) return "ps_2010_v3_up";
239 if ("ps_2010_down" == tune) return "ps_2010_v3_down";
240 if ("ps_2010_errup" == tune) return "ps_2010_v3_errup";
241 if ("ps_2010_errdown" == tune) return "ps_2010_v3_errdown";
242
243 return tune;
244}
245
246void egammaLayerRecalibTool::add_scale(const std::string& tuneIn)
247{
248 ATH_MSG_INFO("using scale " << tuneIn);
249 std::string tune = resolve_alias(tuneIn);
250
251 if (tune.empty()) { }
252 else if ("es2025_run3_extrapolate_gnn_v0" == tune) {
253 add_scale("run3_partial_ofc_extrapolate_gnn_v0");
254 }
255 else if ("es2024_run3_extrapolate_v0" == tune) {
256 add_scale("run3_partial_ofc_extrapolate_v0");
257 }
258 // R22 layer tune with fixed E1E2 and repeated acc
259 else if ("es2022_22.0_Precision_v1" == tune) {
260 add_scale("run2_alt_with_layer2_r22_Precision_v1");
261 }
262 else if ("es2022_22.0_Precision" == tune) {
263 add_scale("run2_alt_with_layer2_r22_Precision");
264 }
265 else if ("es2018_21.0_v0" == tune) {
266 add_scale("run2_alt_with_layer2_r21_v1");
267 }
268 else if ("es2017_21.0_v0" == tune) {
269 add_scale("run2_alt_with_layer2_r21_v0");
270 }
271 else if ("es2017_20.7_final" == tune) {
272 add_scale("pileup_20.7");
273 add_scale("run2_alt_with_layer2_modif");
274 }
275 else if ("es2017_20.7_improved" == tune) {
276 add_scale("pileup_20.7"); // new pileup correction Guillaume for 20.7
277 //TEMPORARY HACK REMOVED (two intermediate tags with this ES model use different layer corrections)
278 add_scale("2012_alt_with_layer2_modif"); // temporary old corrections from run1 + EMECPS HV
279 }
280 else if ("pileup_20.7" == tune) {
286 }
287 // Run3 2022+2023
288 else if ("run3_partial_ofc_extrapolate_gnn_v0" == tune) {
289 add_scale("layer2_run3_ofc_extrapolate_v0");
290 add_scale("ps_run3_ofc_extrapolate_v0");
291 if(m_doSaccCorrections) add_scale("acc_zee_run3_gnn_v0");
292 }
293 else if ("run3_partial_ofc_extrapolate_v0" == tune) {
294 add_scale("layer2_run3_ofc_extrapolate_v0");
295 add_scale("ps_run3_ofc_extrapolate_v0");
296 if(m_doSaccCorrections) add_scale("acc_zee_run3_v0");
297 }
298 //Run 2 release 22 with fixed E1E2 and repeated acc
299 else if ("run2_alt_with_layer2_r22_Precision_v1"==tune) {
300 add_scale("layer2_alt_el_mu_comb_r21_v0_fix");
301 add_scale("ps_mu_r21_v0");
302 if(m_doSaccCorrections) add_scale("acc_zee_r22_v1");
303 }
304 //Run 2 release 22
305 else if ("run2_alt_with_layer2_r22_Precision"==tune) {
306 add_scale("layer2_alt_el_mu_comb_r21_v0");
307 add_scale("ps_mu_r21_v0");
308 if(m_doSaccCorrections) add_scale("acc_zee_r22_v0");
309 }
310 else if ("run2_alt_with_layer2_r21_v1"==tune) {
311 add_scale("layer2_alt_run2_r21_v1");
312 add_scale("ps_2016_r21_v0");
313 }
314 else if ("run2_alt_with_layer2_r21_v0"==tune) {
315 add_scale("layer2_alt_run2_r21_v0");
316 add_scale("ps_2016_r21_v0");
317 }
318 else if("run2_alt_with_layer2_modif" == tune) {
319 add_scale("ps_EMECHV1");
320 add_scale("layer2_alt_run2_v1");
321 add_scale("ps_2016");
322 }
323 // 2012
324 else if ("2012" == tune) {
325 add_scale("ps_HV1");
326 add_scale("layer1_2012");
327 add_scale("ps_2012");
328 }
329 else if("2012_with_layer2" == tune) {
330 add_scale("ps_HV1");
331 add_scale("layer2_2012_v5");
332 add_scale("ps_2012");
333 }
334 else if ("2012_alt" == tune) {
335 add_scale("ps_HV1");
336 add_scale("layer1_alt_2012");
337 add_scale("ps_2012");
338 }
339 else if("2012_alt_with_layer2" == tune) {
340 add_scale("ps_HV1");
341 add_scale("layer2_alt_2012_v5");
342 add_scale("ps_2012");
343 }
344 else if("2012_alt_with_layer2_modif" == tune) {
345 add_scale("ps_HV1");
346 add_scale("ps_EMECHV1");
347 add_scale("layer2_alt_2012_v5");
348 add_scale("ps_2012");
349 }
350 else if("2010_with_layer2" == tune) {
351 add_scale("layer2_2010_v5");
352 add_scale("ps_2010");
353 }
354 else if ("2012_layer1_up" == tune) {
355 add_scale("ps_HV1");
356 add_scale("layer1_2012_up");
357 add_scale("ps_2012");
358 }
359 else if ("2012_layer1_down" == tune) {
360 add_scale("ps_HV1");
361 add_scale("layer1_2012_down");
362 add_scale("ps_2012");
363 }
364 else if ("2012_layer1_errup" == tune) {
365 add_scale("layer1_2012_errup");
366 }
367 else if ("2012_layer1_errdown" == tune) {
368 add_scale("layer1_2012_errdown");
369 }
370 else if ("2012_ps_down" == tune) {
371 add_scale("ps_HV1");
372 add_scale("layer1_2012");
373 add_scale("ps_2012_down");
374 }
375 else if ("2012_ps_up" == tune) {
376 add_scale("ps_HV1");
377 add_scale("layer1_2012");
378 add_scale("ps_2012_up");
379 }
380 else if ("2012_ps_errdown" == tune) {
381 add_scale("ps_2012_errdown");
382 }
383 else if ("2012_ps_errup" == tune) {
384 add_scale("ps_2012_errup");
385 }
386 else if ("2012_up" == tune) {
387 add_scale("ps_HV1");
388 add_scale("layer1_2012_up");
389 add_scale("ps_2012_up");
390 }
391 else if ("2012_down" == tune) {
392 add_scale("ps_HV1");
393 add_scale("layer1_2012_down");
394 add_scale("ps_2012_down");
395 }
396 else if ("2012_errup" == tune) {
397 add_scale("layer1_2012_errup");
398 add_scale("ps_2012_errup");
399 }
400 else if ("2012_errdown" == tune) {
401 add_scale("layer1_2012_errdown");
402 add_scale("ps_2012_errdown");
403 }
404 // 2011
405 else if ("2011" == tune) {
406 add_scale("layer1_2011");
407 add_scale("ps_2011");
408 }
409 else if("2011_with_layer2" == tune) {
410 add_scale("layer2_2011_v5");
411 add_scale("ps_2011");
412 }
413 else if ("2011_alt" == tune) {
414 add_scale("layer1_alt_2011");
415 add_scale("ps_2011");
416 }
417 else if("2011_alt_with_layer2" == tune) {
418 add_scale("layer2_alt_2011_v5");
419 add_scale("ps_2011");
420 }
421 else if ("2011_layer1_up" == tune) {
422 add_scale("layer1_2011_up");
423 add_scale("ps_2011");
424 }
425 else if ("2011_layer1_down" == tune) {
426 add_scale("layer1_2011_down");
427 add_scale("ps_2011");
428 }
429 else if ("2011_layer1_errup" == tune) {
430 add_scale("layer1_2011_errup");
431 }
432 else if ("2011_layer1_errdown" == tune) {
433 add_scale("layer1_2011_errdown");
434 }
435 else if ("2011_ps_down" == tune) {
436 add_scale("layer1_2011");
437 add_scale("ps_2011_down");
438 }
439 else if ("2011_ps_up" == tune) {
440 add_scale("layer1_2011");
441 add_scale("ps_2011_up");
442 }
443 else if ("2011_ps_errdown" == tune) {
444 add_scale("ps_2011_errdown");
445 }
446 else if ("2011_ps_errup" == tune) {
447 add_scale("ps_2011_errup");
448 }
449 else if ("2011_up" == tune) {
450 add_scale("layer1_2011_up");
451 add_scale("ps_2011_up");
452 }
453 else if ("2011_down" == tune) {
454 add_scale("layer1_2011_down");
455 add_scale("ps_2011_down");
456 }
457 else if ("2011_errup" == tune) {
458 add_scale("layer1_2011_errup");
459 add_scale("ps_2011_errup");
460 }
461 else if ("2011_errdown" == tune) {
462 add_scale("layer1_2011_errdown");
463 add_scale("ps_2011_errdown");
464 }
465 // 2010
466 else if ("2010" == tune) {
467 add_scale("layer1_2010");
468 add_scale("ps_2010");
469 }
470 else if ("2010_layer1_up" == tune) {
471 add_scale("layer1_2010_up");
472 add_scale("ps_2010");
473 }
474 else if ("2010_layer1_down" == tune) {
475 add_scale("layer1_2010_down");
476 add_scale("ps_2010");
477 }
478 else if ("2010_layer1_errup" == tune) {
479 add_scale("layer1_2010_errup");
480 }
481 else if ("2010_layer1_errdown" == tune) {
482 add_scale("layer1_2010_errdown");
483 }
484 else if ("2010_ps_down" == tune) {
485 add_scale("layer1_2010");
486 add_scale("ps_2010_down");
487 }
488 else if ("2010_ps_up" == tune) {
489 add_scale("layer1_2010");
490 add_scale("ps_2010_up");
491 }
492 else if ("2010_ps_errdown" == tune) {
493 add_scale("ps_2010_errdown");
494 }
495 else if ("2010_ps_errup" == tune) {
496 add_scale("ps_2010_errup");
497 }
498 else if ("2010_up" == tune) {
499 add_scale("layer1_2010_up");
500 add_scale("ps_2010_up");
501 }
502 else if ("2010_down" == tune) {
503 add_scale("layer1_2010_down");
504 add_scale("ps_2010_down");
505 }
506 else if ("2010_errup" == tune) {
507 add_scale("layer1_2010_errup");
508 add_scale("ps_2010_errup");
509 }
510 else if ("2010_errdown" == tune) {
511 add_scale("layer1_2010_errdown");
512 add_scale("ps_2010_errdown");
513 }
514 else if ("ps_HV1" == tune) {
516 }
517 else if ("ps_EMECHV1" == tune) {
519 }
520 else if ("test1" == tune) {
521 TH1F h_presampler("h_presampler", "h_presampler", 10, -2.5, 2.5);
522 // just as an example, correct E0 by 0.1 * sign(eta)
523 // and E1 by 1%
524 for (int ibin = 1; ibin <= 5; ++ibin) {
525 h_presampler.SetBinContent(ibin, -0.1);
526 h_presampler.SetBinContent(ibin + 5, 0.1);
527 }
530 }
531 else if ("acc_zee_run3_gnn_v0" == tune){
532 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v14/egammaLayerRecalibTunes_transformerTune.root");
533 TFile f(file.c_str());
534 TH2F* histo_acc = static_cast<TH2F*>(f.Get("hACC_Zee_rel23_gnn"));
535 assert(histo_acc);
537 new GetAmountHisto2DEtaCaloRunNumber(*histo_acc));
538 }
539 else if ("acc_zee_run3_v0" == tune){
540 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v13/egammaLayerRecalibTunes.root");
541 TFile f(file.c_str());
542 TH2F* histo_acc = static_cast<TH2F*>(f.Get("hACC_Zee_rel23"));
543 assert(histo_acc);
545 new GetAmountHisto2DEtaCaloRunNumber(*histo_acc));
546 }
547 // repeated acc scale based on layer2_alt_el_mu_comb_r21_v0_fix
548 else if ("acc_zee_r22_v1" == tune) {
549 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v12/egammaLayerRecalibTunes.root");
550 TFile f(file.c_str());
551 TH2F* histo_acc = static_cast<TH2F*>(f.Get("hACC_Zee_rel22"));
552 assert(histo_acc);
554 new GetAmountHisto2DEtaCaloRunNumber(*histo_acc));
555 }
556 else if ("acc_zee_r22_v0" == tune) {
557 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v11/egammaLayerRecalibTunes.root");
558 TFile f(file.c_str());
559 TH2F* histo_acc = static_cast<TH2F*>(f.Get("hACC_Zee_rel22"));
560 assert(histo_acc);
562 new GetAmountHisto2DEtaCaloRunNumber(*histo_acc));
563 }
564 else if ("layer1_1" == tune) {
565 TFormula f("formula_layer1_1", "(abs(x)<1.425) ? 0.97 : 1");
567 }
568 else if ("layer1_2" == tune) {
569 TFormula f("formula_layer1_2", "(abs(x)<1.425) ? 0.97 : 1.05");
571 }
572 else if ("layer1_alt_2012_v5" == tune) {
573 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
574 TFile f(file.c_str());
575 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_alt_2012"));
577 new GetAmountHisto1D(*histo));
578 }
579 else if ("layer1_2012_v5" == tune) {
580 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
581 TFile f(file.c_str());
582 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
584 new GetAmountHisto1D(*histo));
585 }
586 else if ("layer1_2012_v5_down" == tune) {
587 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
588 TFile f(file.c_str());
589 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
591 new GetAmountHisto1DUp(*histo));
592 }
593 else if ("layer1_2012_v5_up" == tune) {
594 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
595 TFile f(file.c_str());
596 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
598 new GetAmountHisto1DDown(*histo));
599 }
600 else if ("layer1_2012_v5_errdown" == tune) {
601 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
602 TFile f(file.c_str());
603 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
605 new GetAmountHisto1DErrorUp(*histo));
606 }
607 else if ("layer1_2012_v5_errup" == tune) {
608 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
609 TFile f(file.c_str());
610 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
612 new GetAmountHisto1DErrorDown(*histo));
613 }
614 else if ("layer1_alt_2011_v5" == tune) {
615 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
616 TFile f(file.c_str());
617 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_alt_2011"));
619 new GetAmountHisto1D(*histo));
620 }
621 else if ("layer1_2011_v5" == tune) {
622 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
623 TFile f(file.c_str());
624 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
626 new GetAmountHisto1D(*histo));
627 }
628 else if ("layer1_2011_v5_down" == tune) {
629 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
630 TFile f(file.c_str());
631 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
633 new GetAmountHisto1DUp(*histo));
634 }
635 else if ("layer1_2011_v5_up" == tune) {
636 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
637 TFile f(file.c_str());
638 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
640 new GetAmountHisto1DDown(*histo));
641 }
642 else if ("layer1_2011_v5_errdown" == tune) {
643 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
644 TFile f(file.c_str());
645 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
647 new GetAmountHisto1DErrorUp(*histo));
648 }
649 else if ("layer1_2011_v5_errup" == tune) {
650 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
651 TFile f(file.c_str());
652 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
654 new GetAmountHisto1DErrorDown(*histo));
655 }
656 else if ("layer1_2010_v5" == tune) {
657 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
658 TFile f(file.c_str());
659 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
661 new GetAmountHisto1D(*histo));
662 }
663 else if ("layer1_2010_v5_down" == tune) {
664 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
665 TFile f(file.c_str());
666 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
668 new GetAmountHisto1DUp(*histo));
669 }
670 else if ("layer1_2010_v5_up" == tune) {
671 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
672 TFile f(file.c_str());
673 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
675 new GetAmountHisto1DDown(*histo));
676 }
677 else if ("layer1_2010_v5_errdown" == tune) {
678 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
679 TFile f(file.c_str());
680 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
682 new GetAmountHisto1DErrorUp(*histo));
683 }
684 else if ("layer1_2010_v5_errup" == tune) {
685 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
686 TFile f(file.c_str());
687 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
689 new GetAmountHisto1DErrorDown(*histo));
690 }
691 else if ("layer2_run3_ofc_extrapolate_v0"==tune){
692 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v12/egammaLayerRecalibTunes.root");
693 TFile f(file.c_str());
694 TH1D* histo = static_cast<TH1D*>(f.Get("hE1E2_emu_run2_rel21_v1_run3ofc"));
695 assert(histo);
697 new GetAmountHisto1D(*histo));
698 }
699 // fix E1E2 scale from R21 precision model
700 else if("layer2_alt_el_mu_comb_r21_v0_fix"==tune) {
701 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v12/egammaLayerRecalibTunes.root");
702 TFile f(file.c_str());
703 TH1D* histo = static_cast<TH1D*>(f.Get("hE1E2_emu_run2_rel21_v0_fix"));
704 assert(histo);
706 new GetAmountHisto1D(*histo));
707 }
708 else if("layer2_alt_el_mu_comb_r21_v0"==tune) {
709 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v11/egammaLayerRecalibTunes.root");
710 TFile f(file.c_str());
711 TH1D* histo = static_cast<TH1D*>(f.Get("hE1E2_emu_run2_rel21_v0"));
712 assert(histo);
714 new GetAmountHisto1D(*histo));
715 }
716 else if("layer2_alt_run2_r21_v1"==tune) {
717 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v6/egammaLayerRecalibTunes.root");
718 TFile f(file.c_str());
719 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2_mu_run2_rel21_v1"));
721 new GetAmountHisto1D(*histo));
722 }
723 else if("layer2_alt_run2_r21_v0"==tune) {
724 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v5/egammaLayerRecalibTunes.root");
725 TFile f(file.c_str());
726 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2mu_2016_rel21_v1"));
728 new GetAmountHisto1D(*histo));
729 }
730 else if("layer2_alt_run2_v1" == tune) {
731 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v3/egammaLayerRecalibTunes.root");
732 TFile f(file.c_str());
733 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2mu_2016_v1"));
735 new GetAmountHisto1D(*histo));
736 }
737 else if("layer2_alt_2012_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_2012"));
742 new GetAmountHisto1D(*histo));
743 }
744 else if("layer2_2012_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_2012"));
749 new GetAmountHisto1D(*histo));
750 }
751 else if("layer2_2012_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_2012"));
756 new GetAmountHisto1DDown(*histo));
757 }
758 else if("layer2_2012_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_2012"));
763 new GetAmountHisto1DUp(*histo));
764 }
765 else if ("layer2_2012_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_2012"));
770 new GetAmountHisto1DErrorDown(*histo));
771 }
772 else if ("layer2_2012_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_2012"));
777 new GetAmountHisto1DErrorUp(*histo));
778 }
779 else if("layer2_alt_2011_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_alt_2011"));
784 new GetAmountHisto1D(*histo));
785 }
786 else if("layer2_2011_v5" == 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_2011"));
791 new GetAmountHisto1D(*histo));
792 }
793 else if("layer2_2011_v5_down" == 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_2011"));
798 new GetAmountHisto1DDown(*histo));
799 }
800 else if("layer2_2011_v5_up" == 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_2011"));
805 new GetAmountHisto1DUp(*histo));
806 }
807 else if ("layer2_2011_v5_errdown" == 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_2011"));
812 new GetAmountHisto1DErrorDown(*histo));
813 }
814 else if ("layer2_2011_v5_errup" == tune) {
815 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
816 TFile f(file.c_str());
817 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
819 new GetAmountHisto1DErrorUp(*histo));
820 }
821 else if("layer2_2010_v5" == tune) {
822 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
823 TFile f(file.c_str());
824 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
826 new GetAmountHisto1D(*histo));
827 }
828 else if("layer2_2010_v5_down" == tune) {
829 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
830 TFile f(file.c_str());
831 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
833 new GetAmountHisto1DDown(*histo));
834 }
835 else if("layer2_2010_v5_up" == tune) {
836 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
837 TFile f(file.c_str());
838 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
840 new GetAmountHisto1DUp(*histo));
841 }
842 else if ("layer2_2010_v5_errdown" == tune) {
843 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
844 TFile f(file.c_str());
845 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
847 new GetAmountHisto1DErrorDown(*histo));
848 }
849 else if ("layer2_2010_v5_errup" == tune) {
850 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
851 TFile f(file.c_str());
852 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
854 new GetAmountHisto1DErrorUp(*histo));
855 }
856 else if ("ps_2016_r21_v0" == tune) {
857 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v5/egammaLayerRecalibTunes.root");
858 TFile f(file.c_str());
859 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2016_rel21"));
861 new GetAmountHisto1D(*histo_ps_tot_error));
862 }
863 else if ("ps_run3_ofc_extrapolate_v0" == tune){
864 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v12/egammaLayerRecalibTunes.root");
865 TFile f(file.c_str());
866 TH1* histo_ps_tot_error = static_cast<TH1*>(f.Get("hPS_MuonLowMu_rel21_run3ofc"));
867 assert(histo_ps_tot_error);
869 new GetAmountHisto1D(*histo_ps_tot_error));
870 }
871 else if ("ps_mu_r21_v0" == tune) {
872 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v11/egammaLayerRecalibTunes.root");
873 TFile f(file.c_str());
874 TH1* histo_ps_tot_error = static_cast<TH1*>(f.Get("hPS_MuonLowMu_rel21"));
875 assert(histo_ps_tot_error);
877 new GetAmountHisto1D(*histo_ps_tot_error));
878 }
879 else if ("ps_2016_v1" == tune) {
880 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v4/egammaLayerRecalibTunes.root");
881 TFile f(file.c_str());
882 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2016"));
884 new GetAmountHisto1D(*histo_ps_tot_error));
885 }
886 else if ("ps_2012_v3" == tune) {
887 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
888 TFile f(file.c_str());
889 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2012"));
891 new GetAmountHisto1D(*histo_ps_tot_error));
892 }
893 else if ("ps_2012_v3_down" == tune) {
894 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
895 TFile f(file.c_str());
896 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2012"));
898 new GetAmountHisto1DUp(*histo_ps_tot_error));
899 }
900 else if ("ps_2012_v3_up" == tune){
901 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
902 TFile f(file.c_str());
903 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2012"));
905 new GetAmountHisto1DDown(*histo_ps_tot_error));
906 }
907 else if ("ps_2012_v3_errdown" == 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_2012"));
912 new GetAmountHisto1DErrorUp(*histo_ps_tot_error));
913 }
914 else if ("ps_2012_v3_errup" == 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_2012"));
919 new GetAmountHisto1DErrorDown(*histo_ps_tot_error));
920 }
921 else if ("ps_2011_v3" == 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_2011"));
926 new GetAmountHisto1D(*histo_ps_tot_error));
927 }
928 else if ("ps_2011_v3_down" == 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_2011"));
933 new GetAmountHisto1DUp(*histo_ps_tot_error));
934 }
935 else if ("ps_2011_v3_up" == 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_2011"));
940 new GetAmountHisto1DDown(*histo_ps_tot_error));
941 }
942 else if ("ps_2011_v3_errdown" == tune){
943 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
944 TFile f(file.c_str());
945 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2011"));
947 new GetAmountHisto1DErrorUp(*histo_ps_tot_error));
948 }
949 else if ("ps_2011_v3_errup" == tune){
950 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
951 TFile f(file.c_str());
952 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2011"));
954 new GetAmountHisto1DErrorDown(*histo_ps_tot_error));
955 }
956 // 2010
957 else if ("ps_2010_v3" == tune) {
958 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
959 TFile f(file.c_str());
960 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2010"));
962 new GetAmountHisto1D(*histo_ps_tot_error));
963 }
964 else if ("ps_2010_v3_down" == tune) {
965 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
966 TFile f(file.c_str());
967 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2010"));
969 new GetAmountHisto1DUp(*histo_ps_tot_error));
970 }
971 else if ("ps_2010_v3_up" == tune) {
972 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
973 TFile f(file.c_str());
974 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2010"));
976 new GetAmountHisto1DDown(*histo_ps_tot_error));
977 }
978 else if ("ps_2010_v3_errdown" == tune){
979 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
980 TFile f(file.c_str());
981 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2010"));
983 new GetAmountHisto1DErrorUp(*histo_ps_tot_error));
984 }
985 else if ("ps_2010_v3_errup" == tune){
986 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
987 TFile f(file.c_str());
988 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2010"));
990 new GetAmountHisto1DErrorDown(*histo_ps_tot_error));
991 }
992 else {
993 throw std::runtime_error(tune+" is not a valid tune");
994 }
995}
996
997egammaLayerRecalibTool::egammaLayerRecalibTool(const std::string& name, const std::string& tune, int SaccEnable)
998 : asg::AsgMessaging(name), m_tune(tune), m_doSaccCorrections(SaccEnable)
999{
1000 add_scale(tune);
1001}
1002
1003
1004egammaLayerRecalibTool::egammaLayerRecalibTool(const std::string& tune, int SaccEnable)
1005 : egammaLayerRecalibTool("egammaLayerRecalibTool", tune, SaccEnable) { }
1006
1007
1009{
1010 m_modifiers.emplace_back(modifier, amount);
1011}
1012
1014{
1016 for (const auto& modifier : m_modifiers) {
1017 const float amount = (*modifier.second)(inputs);
1018 const auto s = (*modifier.first)(inputs, amount);
1019 ATH_MSG_DEBUG(" after E0|E1|E2|E3 = " << inputs.E0raw << "|" << inputs.E1raw << "|" << inputs.E2raw << "|" << inputs.E3raw);
1020 if (s != CP::CorrectionCode::Ok) {
1021 if (status != CP::CorrectionCode::Error) { status = s; }
1022 }
1023 }
1024 return status;
1025}
1026
1028 const xAOD::EventInfo& event_info,
1029 StdCalibrationInputs& inputs,
1030 bool& isData,
1031 std::string& fixT,
1032 double& addE2,
1033 double& addE3 ) const
1034{
1035 const xAOD::CaloCluster* cluster = particle.caloCluster();
1036 if (!cluster) {
1037 ATH_MSG_ERROR("egamma particle without CaloCluster");
1039 }
1040
1043 fixT = "_egFixForTopoTimingCut";
1044 unsigned short stat =
1045 xAOD::EgammaHelpers::energyInMissingCells(particle,addE2,addE3);
1046 if (stat) {
1047 ATH_MSG_WARNING("Fix for missing cells required"
1048 " but some layer info is not available,"
1049 " from L2 : " << stat%2 << " from L3 : " << stat/2);
1050 }
1051 }
1052
1053 double eta_calo;
1054 static const SG::AuxElement::Accessor<float> accEtaCalo("etaCalo");
1055 if(particle.author() == xAOD::EgammaParameters::AuthorFwdElectron){
1056 eta_calo = cluster->eta();
1057 }
1058 else if (cluster->retrieveMoment(xAOD::CaloCluster::ETACALOFRAME, eta_calo)){
1059
1060 }
1061 else if (accEtaCalo.isAvailable(*cluster)) {
1062 eta_calo = accEtaCalo(*cluster);
1063 }
1064 else{
1065 ATH_MSG_ERROR("etaCalo not available as auxilliary variable,"
1066 " using cluster eta as eta calo!");
1067 eta_calo=cluster->eta();
1068 }
1069
1070 inputs = StdCalibrationInputs{
1071 event_info.averageInteractionsPerCrossing(),
1072 event_info.runNumber(),
1073 cluster->eta(),
1074 cluster->phi(),
1075 cluster->energyBE(0),
1076 cluster->energyBE(1),
1077 cluster->energyBE(2) + addE2,
1078 cluster->energyBE(3) + addE3,
1079 eta_calo};
1080
1081 isData = !event_info.eventType(xAOD::EventInfo::IS_SIMULATION);
1083 if (isData || m_scaleMC)
1084 status = scale_inputs(inputs);
1085
1086 return status;
1087}
1088
1090{
1091
1092 StdCalibrationInputs inputs{};
1093 bool isData = true;
1094 std::string fixT;
1095 double addE2 = 0.0, addE3 = 0.0;
1096
1097 CP::CorrectionCode status = read_and_scale_inputs(particle, event_info, inputs, isData, fixT, addE2, addE3);
1098
1100 return status;
1101
1102 const xAOD::CaloCluster* cluster = particle.caloCluster();
1103
1104 static const SG::AuxElement::Decorator<double> deco_E0("correctedcl_Es0");
1105 static const SG::AuxElement::Decorator<double> deco_E1("correctedcl_Es1");
1106 static const SG::AuxElement::Decorator<double> deco_E2("correctedcl_Es2");
1107 static const SG::AuxElement::Decorator<double> deco_E3("correctedcl_Es3");
1108 static const SG::AuxElement::Decorator<std::string>
1109 deco_layer_correction("layer_correction");
1110
1111 if (status == CP::CorrectionCode::Ok) {
1112 ATH_MSG_DEBUG("decorating cluster with corrected layer energies");
1113 deco_E0(*cluster) = m_doPSCorrections ?
1114 inputs.E0raw : cluster->energyBE(0);
1115 deco_E1(*cluster) = m_doS12Corrections or m_doSaccCorrections ?
1116 inputs.E1raw : cluster->energyBE(1);
1117 deco_E2(*cluster) = m_doS12Corrections or m_doSaccCorrections ?
1118 inputs.E2raw : cluster->energyBE(2) + addE2;
1119 deco_E3(*cluster) = m_doSaccCorrections ?
1120 inputs.E3raw : cluster->energyBE(3) + addE3;
1121 deco_layer_correction(*cluster) = isData ? m_tune+fixT : fixT;
1122 return status;
1123 }
1124
1125 ATH_MSG_DEBUG("cannot correct layer energies:"
1126 " decorating particle with non-corrected layer energies");
1127 // this is done for safety, since when a particle is decorated
1128 // all the particle in the container are decorated
1129 // it is not possible to distinguish between decorated / non-decorated
1130 // since all are decorated
1131 deco_E0(*cluster) = cluster->energyBE(0);
1132 deco_E1(*cluster) = cluster->energyBE(1);
1133 deco_E2(*cluster) = cluster->energyBE(2) + addE2;
1134 deco_E3(*cluster) = cluster->energyBE(3) + addE3;
1135 deco_layer_correction(*cluster) = isData ? m_tune + "_Err" + fixT : fixT;
1136 return status;
1137
1138}
1139
1140std::array<double,4> egammaLayerRecalibTool::getLayerCorrections(const xAOD::Egamma& particle, const xAOD::EventInfo& event_info) const
1141{
1142 StdCalibrationInputs inputs{};
1143 bool isData = true;
1144 std::string fixT;
1145 double addE2 = 0.0, addE3 = 0.0;
1146
1147 CP::CorrectionCode status = read_and_scale_inputs(particle, event_info, inputs, isData, fixT, addE2, addE3);
1148
1149 if (status != CP::CorrectionCode::Ok) {
1150 if (status == CP::CorrectionCode::Error) {
1151 ATH_MSG_ERROR("Failed to read inputs, returning 1 for all layers, please check if this is expected!");
1152 }
1153 else if (status == CP::CorrectionCode::OutOfValidityRange) {
1154 ATH_MSG_WARNING("Some inputs are out of validity range, returning 1 for all layers; object eta: " << inputs.eta);
1155 }
1156 return {1.,1.,1.,1.};
1157 }
1158
1159 auto safe_divide = [](float a, float b) { return b != 0 ? a/b : 1.f; };
1160 return {
1161 safe_divide(inputs.E0raw, particle.caloCluster()->energyBE(0)),
1162 safe_divide(inputs.E1raw, particle.caloCluster()->energyBE(1)),
1163 safe_divide(inputs.E2raw, particle.caloCluster()->energyBE(2) + addE2),
1164 safe_divide(inputs.E3raw, particle.caloCluster()->energyBE(3) + addE3)
1165 };
1166
1167}
1168
1170{
1171 for (auto modifier : m_modifiers) {
1172 delete modifier.first;
1173 delete modifier.second;
1174 }
1175 m_modifiers.clear();
1176}
1177
1178
1179// helper
1180std::map<std::string, std::string, std::less<>> parse(const std::string& list)
1181{
1182 std::cout << "list: '" << list << "'" << std::endl;
1183 std::map<std::string, std::string, std::less<>> result;
1184 TIter next(TString(list).Tokenize(","));
1185 while (TObjString* sObj = (TObjString*) next())
1186 {
1187 const TString& item(sObj->GetString());
1188 std::cout << "item: '" << item << "'" << std::endl;
1189 TObjArray* item_list = TString(item).Tokenize(":");
1190 std::string key;
1191 std::string value;
1192 if (item_list->GetEntries() == 1) {
1193 key = "amount";
1194 value = static_cast<TObjString*>(item_list->At(0))->GetString().Data();
1195 }
1196 else if (item_list->GetEntries() == 2) {
1197 key = static_cast<TObjString*>(item_list->At(0))->GetString().Data();
1198 value = static_cast<TObjString*>(item_list->At(1))->GetString().Data();
1199 }
1200 else {
1201 std::cerr << "invalid string " << item << std::endl;
1202 }
1203 if (result.find(key) != result.end()) {
1204 std::cerr << "trying to insert two times key " << key << std::endl;
1205 assert(false);
1206 }
1207 result.insert(std::make_pair(key, value));
1208 }
1209 return result;
1210}
1211
1212
1213std::pair<std::string, egammaLayerRecalibTool*>
1214egammaLayerRecalibTool::create(const std::string& type, const std::string& args)
1215{
1216 auto args_map = parse(args);
1217 egammaLayerRecalibTool* tool = new egammaLayerRecalibTool("egammaLayerRecalibTool", "");
1218 std::string name = "";
1219 std::string amount_name = "";
1220 std::string type_name = "";
1221
1222 GetAmountBase* amount_getter = nullptr;
1223 InputModifier* modifier = nullptr;
1224
1225 if (auto pa = args_map.find("amount"); pa != args_map.end()) {
1226 std::string amount_str = pa->second;
1227 bool perc = false;
1228 if (amount_str.back()=='%') {
1229 perc = true;
1230 amount_str.pop_back();
1231 }
1232 const float amount = TString(amount_str).Atof() * (perc ? 0.01 : 1);
1233
1234 amount_getter = new GetAmountFixed(amount);
1235 std::stringstream amount_stream;
1236 amount_stream << amount;
1237 amount_name = amount_stream.str();
1238 std::replace(amount_name.begin(), amount_name.end(), '-', 'n');
1239 std::replace(amount_name.begin(), amount_name.end(), '.', 'p');
1240 }
1241 else if (auto pn = args_map.find("name"); pn != args_map.end()) {
1242 name = pn->second;
1243 }
1244 else if (args_map.find("histo") != args_map.end()) {
1245 int dim = 0;
1246 if (not args_map.contains("file")) {
1247 std::cerr << "with histo you must specify file" << std::endl;
1248 assert(false);
1249 }
1250 if (args_map.contains("formulax") ) dim = 1;
1251
1252 if (dim == 0)
1253 {
1254 std::cerr << "with histo you must specify formulax" << std::endl;
1255 assert(false);
1256 }
1257 if (dim == 1) {
1258 TFile f(args_map["file"].c_str());
1259 std::cout << "opening histo " << args_map["histo"] << " from file " << args_map["file"] << std::endl;
1260 TH1F* histo = dynamic_cast<TH1F*>(f.Get(args_map["histo"].c_str()));
1261
1262 if(histo){
1263 histo->SetDirectory(nullptr);
1264 amount_getter = new GetAmountHisto1D(*histo);
1265 }
1266 else{assert(false); }
1267 }
1268 else { assert(false); }
1269 }
1270 else {
1271 std::cerr << "cannot understand argument " << args << std::endl;
1272 assert(false);
1273 }
1274
1275 if ("bias-E0" == type) { modifier = new ScaleE0(InputModifier::ZEROBASED); type_name = "E0"; }
1276 else if ("bias-E1" == type) { modifier = new ScaleE1(InputModifier::ZEROBASED); type_name = "E1"; }
1277 else if ("bias-E2" == type) { modifier = new ScaleE2(InputModifier::ZEROBASED); type_name = "E2"; }
1278 else if ("bias-E3" == type) { modifier = new ScaleE3(InputModifier::ZEROBASED); type_name = "E3"; }
1279 else if ("bias-E1overE2" == type) { modifier = new ScaleE1overE2(InputModifier::ZEROBASED); type_name = "E1overE2"; }
1280 else if ("bias-Eaccordion" == type) { modifier = new ScaleEaccordion(InputModifier::ZEROBASED); type_name = "Eaccordion"; }
1281 else if ("bias-Ecalorimeter" == type) { modifier = new ScaleEcalorimeter(InputModifier::ZEROBASED); type_name = "Ecalorimeter"; }
1282
1283 if (not type_name.empty() and not amount_name.empty()) {
1284 name = type_name + "_" + amount_name;
1285 }
1286
1287 if (name.empty()) {
1288 std::cerr << "you need to specify a name for the bias with type " << type << std::endl;
1289 }
1290
1291 if (modifier and amount_getter) {
1292 tool->add_scale(modifier, amount_getter);
1293 }
1294 else{
1295 tool->add_scale(type);
1296 //release resources, if modifier false need to release amount_getter and vice versa
1297 //since they are not passed to the tool
1298 if(modifier) delete modifier;
1299 if(amount_getter) delete amount_getter;
1300 }
1301
1302 return {name, tool};
1303}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static Double_t a
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Return value from object correction CP tools.
@ Error
Some error happened during the object correction.
@ OutOfValidityRange
Input object is out of validity range.
@ Ok
The correction was done successfully.
AsgMessaging(const std::string &name)
Constructor with a name.
Correction for pileup induced energy shit as function of mu per layer for 2016 data.
CP::CorrectionCode read_and_scale_inputs(const xAOD::Egamma &particle, const xAOD::EventInfo &event_info, StdCalibrationInputs &inputs, bool &isData, std::string &fixT, double &addE2, double &addE3) const
CP::CorrectionCode applyCorrection(xAOD::Egamma &, const xAOD::EventInfo &event_info) const
std::array< double, 4 > getLayerCorrections(const xAOD::Egamma &particle, const xAOD::EventInfo &event_info) const
void add_scale(InputModifier *modifier, GetAmountBase *amount)
add custom layer scale correction.
static std::string resolve_alias(const std::string &tune)
static const unsigned int m_Run2Run3runNumberTransition
egammaLayerRecalibTool(const std::string &name, const std::string &tune, int SaccEnable=1)
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)
CP::CorrectionCode scale_inputs(StdCalibrationInputs &inputs) const
apply layer calibration to the
void clear_corrections()
remove all the scale corrections
bool retrieveMoment(MomentType type, double &value) const
Retrieve individual moment.
virtual double eta() const
The pseudorapidity ( ) of the particle.
float energyBE(const unsigned layer) const
Get the energy in one layer of the EM Calo.
virtual double phi() const
The azimuthal angle ( ) of the particle.
@ ETACALOFRAME
Eta in the calo frame (for egamma).
bool eventType(EventType type) const
Check for one particular bitmask value.
float averageInteractionsPerCrossing() const
Average interactions per crossing for all BCIDs - for out-of-time pile-up.
@ IS_SIMULATION
true: simulation, false: data
uint32_t runNumber() const
The current event's run number.
std::map< std::string, std::string, std::less<> > parse(const std::string &list)
void * ptr(T *p)
Definition SGImplSvc.cxx:74
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...
const uint16_t AuthorFwdElectron
Electron reconstructed by the Forward cluster-based algorithm.
Definition EgammaDefs.h:30
EventInfo_v1 EventInfo
Definition of the latest event info version.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Egamma_v1 Egamma
Definition of the current "egamma version".
Definition Egamma.h:17
virtual float operator()(const StdCalibrationInputs &input) const
virtual float operator()(const StdCalibrationInputs &input) const
virtual float operator()(const StdCalibrationInputs &input) const
virtual float operator()(const StdCalibrationInputs &input) const
virtual float operator()(const StdCalibrationInputs &input) const
virtual float operator()(const StdCalibrationInputs &input) const
virtual float operator()(const StdCalibrationInputs &input) const
virtual float operator()(const StdCalibrationInputs &input) const
std::unique_ptr< TH1 > m_histo
virtual float operator()(const StdCalibrationInputs &input) const
virtual float operator()(const StdCalibrationInputs &input) const
virtual float operator()(const StdCalibrationInputs &input) const
corr_pileupShift * m_tool
virtual float operator()(const StdCalibrationInputs &inputs) const
corr_pileupShift * m_tool
virtual float operator()(const StdCalibrationInputs &inputs) const
virtual float operator()(const StdCalibrationInputs &inputs) const
corr_pileupShift * m_tool
corr_pileupShift * m_tool
virtual float operator()(const StdCalibrationInputs &inputs) const
virtual void shift_inputs(StdCalibrationInputs &, float amount) const =0
CP::CorrectionCode operator()(StdCalibrationInputs &, float amount) const
virtual void scale_inputs(StdCalibrationInputs &, float amount) const =0
virtual void scale_inputs(StdCalibrationInputs &, float amount) const
virtual void shift_inputs(StdCalibrationInputs &, float amount) const
virtual void scale_inputs(StdCalibrationInputs &, float amount) const
virtual void shift_inputs(StdCalibrationInputs &, float amount) const
virtual void shift_inputs(StdCalibrationInputs &, float amount) const
virtual void scale_inputs(StdCalibrationInputs &, float amount) const
virtual void scale_inputs(StdCalibrationInputs &, float amount) const
virtual void shift_inputs(StdCalibrationInputs &, float amount) const
virtual void scale_inputs(StdCalibrationInputs &, float amount) const
virtual void shift_inputs(StdCalibrationInputs &, float amount) const
virtual void shift_inputs(StdCalibrationInputs &, float amount) const
virtual void scale_inputs(StdCalibrationInputs &, float amount) const
virtual void shift_inputs(StdCalibrationInputs &, float amount) const
virtual void scale_inputs(StdCalibrationInputs &, float amount) const
Name : egammaLayerRecalibTool.h Package : egammaLayerRecalibTool Author : R.
TFile * file