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