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 ("es2024_run3_extrapolate_v0" == tune) {
252 add_scale("run3_partial_ofc_extrapolate_v0");
253 }
254 // R22 layer tune with fixed E1E2 and repeated acc
255 else if ("es2022_22.0_Precision_v1" == tune) {
256 add_scale("run2_alt_with_layer2_r22_Precision_v1");
257 }
258 else if ("es2022_22.0_Precision" == tune) {
259 add_scale("run2_alt_with_layer2_r22_Precision");
260 }
261 else if ("es2018_21.0_v0" == tune) {
262 add_scale("run2_alt_with_layer2_r21_v1");
263 }
264 else if ("es2017_21.0_v0" == tune) {
265 add_scale("run2_alt_with_layer2_r21_v0");
266 }
267 else if ("es2017_20.7_final" == tune) {
268 add_scale("pileup_20.7");
269 add_scale("run2_alt_with_layer2_modif");
270 }
271 else if ("es2017_20.7_improved" == tune) {
272 add_scale("pileup_20.7"); // new pileup correction Guillaume for 20.7
273 //TEMPORARY HACK REMOVED (two intermediate tags with this ES model use different layer corrections)
274 add_scale("2012_alt_with_layer2_modif"); // temporary old corrections from run1 + EMECPS HV
275 }
276 else if ("pileup_20.7" == tune) {
282 }
283 // Run3 2022+2023
284 else if ("run3_partial_ofc_extrapolate_v0" == tune) {
285 add_scale("layer2_run3_ofc_extrapolate_v0");
286 add_scale("ps_run3_ofc_extrapolate_v0");
287 if(m_doSaccCorrections) add_scale("acc_zee_run3_v0");
288 }
289 //Run 2 release 22 with fixed E1E2 and repeated acc
290 else if ("run2_alt_with_layer2_r22_Precision_v1"==tune) {
291 add_scale("layer2_alt_el_mu_comb_r21_v0_fix");
292 add_scale("ps_mu_r21_v0");
293 if(m_doSaccCorrections) add_scale("acc_zee_r22_v1");
294 }
295 //Run 2 release 22
296 else if ("run2_alt_with_layer2_r22_Precision"==tune) {
297 add_scale("layer2_alt_el_mu_comb_r21_v0");
298 add_scale("ps_mu_r21_v0");
299 if(m_doSaccCorrections) add_scale("acc_zee_r22_v0");
300 }
301 else if ("run2_alt_with_layer2_r21_v1"==tune) {
302 add_scale("layer2_alt_run2_r21_v1");
303 add_scale("ps_2016_r21_v0");
304 }
305 else if ("run2_alt_with_layer2_r21_v0"==tune) {
306 add_scale("layer2_alt_run2_r21_v0");
307 add_scale("ps_2016_r21_v0");
308 }
309 else if("run2_alt_with_layer2_modif" == tune) {
310 add_scale("ps_EMECHV1");
311 add_scale("layer2_alt_run2_v1");
312 add_scale("ps_2016");
313 }
314 // 2012
315 else if ("2012" == tune) {
316 add_scale("ps_HV1");
317 add_scale("layer1_2012");
318 add_scale("ps_2012");
319 }
320 else if("2012_with_layer2" == tune) {
321 add_scale("ps_HV1");
322 add_scale("layer2_2012_v5");
323 add_scale("ps_2012");
324 }
325 else if ("2012_alt" == tune) {
326 add_scale("ps_HV1");
327 add_scale("layer1_alt_2012");
328 add_scale("ps_2012");
329 }
330 else if("2012_alt_with_layer2" == tune) {
331 add_scale("ps_HV1");
332 add_scale("layer2_alt_2012_v5");
333 add_scale("ps_2012");
334 }
335 else if("2012_alt_with_layer2_modif" == tune) {
336 add_scale("ps_HV1");
337 add_scale("ps_EMECHV1");
338 add_scale("layer2_alt_2012_v5");
339 add_scale("ps_2012");
340 }
341 else if("2010_with_layer2" == tune) {
342 add_scale("layer2_2010_v5");
343 add_scale("ps_2010");
344 }
345 else if ("2012_layer1_up" == tune) {
346 add_scale("ps_HV1");
347 add_scale("layer1_2012_up");
348 add_scale("ps_2012");
349 }
350 else if ("2012_layer1_down" == tune) {
351 add_scale("ps_HV1");
352 add_scale("layer1_2012_down");
353 add_scale("ps_2012");
354 }
355 else if ("2012_layer1_errup" == tune) {
356 add_scale("layer1_2012_errup");
357 }
358 else if ("2012_layer1_errdown" == tune) {
359 add_scale("layer1_2012_errdown");
360 }
361 else if ("2012_ps_down" == tune) {
362 add_scale("ps_HV1");
363 add_scale("layer1_2012");
364 add_scale("ps_2012_down");
365 }
366 else if ("2012_ps_up" == tune) {
367 add_scale("ps_HV1");
368 add_scale("layer1_2012");
369 add_scale("ps_2012_up");
370 }
371 else if ("2012_ps_errdown" == tune) {
372 add_scale("ps_2012_errdown");
373 }
374 else if ("2012_ps_errup" == tune) {
375 add_scale("ps_2012_errup");
376 }
377 else if ("2012_up" == tune) {
378 add_scale("ps_HV1");
379 add_scale("layer1_2012_up");
380 add_scale("ps_2012_up");
381 }
382 else if ("2012_down" == tune) {
383 add_scale("ps_HV1");
384 add_scale("layer1_2012_down");
385 add_scale("ps_2012_down");
386 }
387 else if ("2012_errup" == tune) {
388 add_scale("layer1_2012_errup");
389 add_scale("ps_2012_errup");
390 }
391 else if ("2012_errdown" == tune) {
392 add_scale("layer1_2012_errdown");
393 add_scale("ps_2012_errdown");
394 }
395 // 2011
396 else if ("2011" == tune) {
397 add_scale("layer1_2011");
398 add_scale("ps_2011");
399 }
400 else if("2011_with_layer2" == tune) {
401 add_scale("layer2_2011_v5");
402 add_scale("ps_2011");
403 }
404 else if ("2011_alt" == tune) {
405 add_scale("layer1_alt_2011");
406 add_scale("ps_2011");
407 }
408 else if("2011_alt_with_layer2" == tune) {
409 add_scale("layer2_alt_2011_v5");
410 add_scale("ps_2011");
411 }
412 else if ("2011_layer1_up" == tune) {
413 add_scale("layer1_2011_up");
414 add_scale("ps_2011");
415 }
416 else if ("2011_layer1_down" == tune) {
417 add_scale("layer1_2011_down");
418 add_scale("ps_2011");
419 }
420 else if ("2011_layer1_errup" == tune) {
421 add_scale("layer1_2011_errup");
422 }
423 else if ("2011_layer1_errdown" == tune) {
424 add_scale("layer1_2011_errdown");
425 }
426 else if ("2011_ps_down" == tune) {
427 add_scale("layer1_2011");
428 add_scale("ps_2011_down");
429 }
430 else if ("2011_ps_up" == tune) {
431 add_scale("layer1_2011");
432 add_scale("ps_2011_up");
433 }
434 else if ("2011_ps_errdown" == tune) {
435 add_scale("ps_2011_errdown");
436 }
437 else if ("2011_ps_errup" == tune) {
438 add_scale("ps_2011_errup");
439 }
440 else if ("2011_up" == tune) {
441 add_scale("layer1_2011_up");
442 add_scale("ps_2011_up");
443 }
444 else if ("2011_down" == tune) {
445 add_scale("layer1_2011_down");
446 add_scale("ps_2011_down");
447 }
448 else if ("2011_errup" == tune) {
449 add_scale("layer1_2011_errup");
450 add_scale("ps_2011_errup");
451 }
452 else if ("2011_errdown" == tune) {
453 add_scale("layer1_2011_errdown");
454 add_scale("ps_2011_errdown");
455 }
456 // 2010
457 else if ("2010" == tune) {
458 add_scale("layer1_2010");
459 add_scale("ps_2010");
460 }
461 else if ("2010_layer1_up" == tune) {
462 add_scale("layer1_2010_up");
463 add_scale("ps_2010");
464 }
465 else if ("2010_layer1_down" == tune) {
466 add_scale("layer1_2010_down");
467 add_scale("ps_2010");
468 }
469 else if ("2010_layer1_errup" == tune) {
470 add_scale("layer1_2010_errup");
471 }
472 else if ("2010_layer1_errdown" == tune) {
473 add_scale("layer1_2010_errdown");
474 }
475 else if ("2010_ps_down" == tune) {
476 add_scale("layer1_2010");
477 add_scale("ps_2010_down");
478 }
479 else if ("2010_ps_up" == tune) {
480 add_scale("layer1_2010");
481 add_scale("ps_2010_up");
482 }
483 else if ("2010_ps_errdown" == tune) {
484 add_scale("ps_2010_errdown");
485 }
486 else if ("2010_ps_errup" == tune) {
487 add_scale("ps_2010_errup");
488 }
489 else if ("2010_up" == tune) {
490 add_scale("layer1_2010_up");
491 add_scale("ps_2010_up");
492 }
493 else if ("2010_down" == tune) {
494 add_scale("layer1_2010_down");
495 add_scale("ps_2010_down");
496 }
497 else if ("2010_errup" == tune) {
498 add_scale("layer1_2010_errup");
499 add_scale("ps_2010_errup");
500 }
501 else if ("2010_errdown" == tune) {
502 add_scale("layer1_2010_errdown");
503 add_scale("ps_2010_errdown");
504 }
505 else if ("ps_HV1" == tune) {
507 }
508 else if ("ps_EMECHV1" == tune) {
510 }
511 else if ("test1" == tune) {
512 TH1F h_presampler("h_presampler", "h_presampler", 10, -2.5, 2.5);
513 // just as an example, correct E0 by 0.1 * sign(eta)
514 // and E1 by 1%
515 for (int ibin = 1; ibin <= 5; ++ibin) {
516 h_presampler.SetBinContent(ibin, -0.1);
517 h_presampler.SetBinContent(ibin + 5, 0.1);
518 }
521 }
522 else if ("acc_zee_run3_v0" == tune){
523 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v13/egammaLayerRecalibTunes.root");
524 TFile f(file.c_str());
525 TH2F* histo_acc = static_cast<TH2F*>(f.Get("hACC_Zee_rel23"));
526 assert(histo_acc);
528 new GetAmountHisto2DEtaCaloRunNumber(*histo_acc));
529 }
530 // repeated acc scale based on layer2_alt_el_mu_comb_r21_v0_fix
531 else if ("acc_zee_r22_v1" == tune) {
532 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v12/egammaLayerRecalibTunes.root");
533 TFile f(file.c_str());
534 TH2F* histo_acc = static_cast<TH2F*>(f.Get("hACC_Zee_rel22"));
535 assert(histo_acc);
537 new GetAmountHisto2DEtaCaloRunNumber(*histo_acc));
538 }
539 else if ("acc_zee_r22_v0" == tune) {
540 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v11/egammaLayerRecalibTunes.root");
541 TFile f(file.c_str());
542 TH2F* histo_acc = static_cast<TH2F*>(f.Get("hACC_Zee_rel22"));
543 assert(histo_acc);
545 new GetAmountHisto2DEtaCaloRunNumber(*histo_acc));
546 }
547 else if ("layer1_1" == tune) {
548 TFormula f("formula_layer1_1", "(abs(x)<1.425) ? 0.97 : 1");
550 }
551 else if ("layer1_2" == tune) {
552 TFormula f("formula_layer1_2", "(abs(x)<1.425) ? 0.97 : 1.05");
554 }
555 else if ("layer1_alt_2012_v5" == tune) {
556 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
557 TFile f(file.c_str());
558 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_alt_2012"));
560 new GetAmountHisto1D(*histo));
561 }
562 else if ("layer1_2012_v5" == tune) {
563 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
564 TFile f(file.c_str());
565 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
567 new GetAmountHisto1D(*histo));
568 }
569 else if ("layer1_2012_v5_down" == tune) {
570 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
571 TFile f(file.c_str());
572 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
574 new GetAmountHisto1DUp(*histo));
575 }
576 else if ("layer1_2012_v5_up" == tune) {
577 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
578 TFile f(file.c_str());
579 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
581 new GetAmountHisto1DDown(*histo));
582 }
583 else if ("layer1_2012_v5_errdown" == tune) {
584 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
585 TFile f(file.c_str());
586 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
588 new GetAmountHisto1DErrorUp(*histo));
589 }
590 else if ("layer1_2012_v5_errup" == tune) {
591 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
592 TFile f(file.c_str());
593 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
595 new GetAmountHisto1DErrorDown(*histo));
596 }
597 else if ("layer1_alt_2011_v5" == tune) {
598 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
599 TFile f(file.c_str());
600 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_alt_2011"));
602 new GetAmountHisto1D(*histo));
603 }
604 else if ("layer1_2011_v5" == tune) {
605 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
606 TFile f(file.c_str());
607 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
609 new GetAmountHisto1D(*histo));
610 }
611 else if ("layer1_2011_v5_down" == tune) {
612 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
613 TFile f(file.c_str());
614 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
616 new GetAmountHisto1DUp(*histo));
617 }
618 else if ("layer1_2011_v5_up" == tune) {
619 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
620 TFile f(file.c_str());
621 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
623 new GetAmountHisto1DDown(*histo));
624 }
625 else if ("layer1_2011_v5_errdown" == tune) {
626 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
627 TFile f(file.c_str());
628 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
630 new GetAmountHisto1DErrorUp(*histo));
631 }
632 else if ("layer1_2011_v5_errup" == tune) {
633 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
634 TFile f(file.c_str());
635 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
637 new GetAmountHisto1DErrorDown(*histo));
638 }
639 else if ("layer1_2010_v5" == tune) {
640 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
641 TFile f(file.c_str());
642 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
644 new GetAmountHisto1D(*histo));
645 }
646 else if ("layer1_2010_v5_down" == tune) {
647 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
648 TFile f(file.c_str());
649 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
651 new GetAmountHisto1DUp(*histo));
652 }
653 else if ("layer1_2010_v5_up" == tune) {
654 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
655 TFile f(file.c_str());
656 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
658 new GetAmountHisto1DDown(*histo));
659 }
660 else if ("layer1_2010_v5_errdown" == tune) {
661 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
662 TFile f(file.c_str());
663 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
665 new GetAmountHisto1DErrorUp(*histo));
666 }
667 else if ("layer1_2010_v5_errup" == tune) {
668 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
669 TFile f(file.c_str());
670 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
672 new GetAmountHisto1DErrorDown(*histo));
673 }
674 else if ("layer2_run3_ofc_extrapolate_v0"==tune){
675 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v12/egammaLayerRecalibTunes.root");
676 TFile f(file.c_str());
677 TH1D* histo = static_cast<TH1D*>(f.Get("hE1E2_emu_run2_rel21_v1_run3ofc"));
678 assert(histo);
680 new GetAmountHisto1D(*histo));
681 }
682 // fix E1E2 scale from R21 precision model
683 else if("layer2_alt_el_mu_comb_r21_v0_fix"==tune) {
684 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v12/egammaLayerRecalibTunes.root");
685 TFile f(file.c_str());
686 TH1D* histo = static_cast<TH1D*>(f.Get("hE1E2_emu_run2_rel21_v0_fix"));
687 assert(histo);
689 new GetAmountHisto1D(*histo));
690 }
691 else if("layer2_alt_el_mu_comb_r21_v0"==tune) {
692 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v11/egammaLayerRecalibTunes.root");
693 TFile f(file.c_str());
694 TH1D* histo = static_cast<TH1D*>(f.Get("hE1E2_emu_run2_rel21_v0"));
695 assert(histo);
697 new GetAmountHisto1D(*histo));
698 }
699 else if("layer2_alt_run2_r21_v1"==tune) {
700 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v6/egammaLayerRecalibTunes.root");
701 TFile f(file.c_str());
702 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2_mu_run2_rel21_v1"));
704 new GetAmountHisto1D(*histo));
705 }
706 else if("layer2_alt_run2_r21_v0"==tune) {
707 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v5/egammaLayerRecalibTunes.root");
708 TFile f(file.c_str());
709 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2mu_2016_rel21_v1"));
711 new GetAmountHisto1D(*histo));
712 }
713 else if("layer2_alt_run2_v1" == tune) {
714 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v3/egammaLayerRecalibTunes.root");
715 TFile f(file.c_str());
716 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2mu_2016_v1"));
718 new GetAmountHisto1D(*histo));
719 }
720 else if("layer2_alt_2012_v5" == tune) {
721 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
722 TFile f(file.c_str());
723 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_alt_2012"));
725 new GetAmountHisto1D(*histo));
726 }
727 else if("layer2_2012_v5" == tune) {
728 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
729 TFile f(file.c_str());
730 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
732 new GetAmountHisto1D(*histo));
733 }
734 else if("layer2_2012_v5_down" == tune) {
735 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
736 TFile f(file.c_str());
737 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
739 new GetAmountHisto1DDown(*histo));
740 }
741 else if("layer2_2012_v5_up" == tune) {
742 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
743 TFile f(file.c_str());
744 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
746 new GetAmountHisto1DUp(*histo));
747 }
748 else if ("layer2_2012_v5_errdown" == tune) {
749 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
750 TFile f(file.c_str());
751 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
753 new GetAmountHisto1DErrorDown(*histo));
754 }
755 else if ("layer2_2012_v5_errup" == tune) {
756 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
757 TFile f(file.c_str());
758 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2012"));
760 new GetAmountHisto1DErrorUp(*histo));
761 }
762 else if("layer2_alt_2011_v5" == tune) {
763 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
764 TFile f(file.c_str());
765 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_alt_2011"));
767 new GetAmountHisto1D(*histo));
768 }
769 else if("layer2_2011_v5" == tune) {
770 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
771 TFile f(file.c_str());
772 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
774 new GetAmountHisto1D(*histo));
775 }
776 else if("layer2_2011_v5_down" == tune) {
777 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
778 TFile f(file.c_str());
779 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
781 new GetAmountHisto1DDown(*histo));
782 }
783 else if("layer2_2011_v5_up" == tune) {
784 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
785 TFile f(file.c_str());
786 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
788 new GetAmountHisto1DUp(*histo));
789 }
790 else if ("layer2_2011_v5_errdown" == tune) {
791 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
792 TFile f(file.c_str());
793 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
795 new GetAmountHisto1DErrorDown(*histo));
796 }
797 else if ("layer2_2011_v5_errup" == tune) {
798 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
799 TFile f(file.c_str());
800 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2011"));
802 new GetAmountHisto1DErrorUp(*histo));
803 }
804 else if("layer2_2010_v5" == tune) {
805 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
806 TFile f(file.c_str());
807 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
809 new GetAmountHisto1D(*histo));
810 }
811 else if("layer2_2010_v5_down" == tune) {
812 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
813 TFile f(file.c_str());
814 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
816 new GetAmountHisto1DDown(*histo));
817 }
818 else if("layer2_2010_v5_up" == tune) {
819 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
820 TFile f(file.c_str());
821 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
823 new GetAmountHisto1DUp(*histo));
824 }
825 else if ("layer2_2010_v5_errdown" == tune) {
826 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
827 TFile f(file.c_str());
828 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
830 new GetAmountHisto1DErrorDown(*histo));
831 }
832 else if ("layer2_2010_v5_errup" == tune) {
833 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
834 TFile f(file.c_str());
835 TH1* histo = checked_cast<TH1*>(f.Get("hE1E2ave_2010"));
837 new GetAmountHisto1DErrorUp(*histo));
838 }
839 else if ("ps_2016_r21_v0" == tune) {
840 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v5/egammaLayerRecalibTunes.root");
841 TFile f(file.c_str());
842 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2016_rel21"));
844 new GetAmountHisto1D(*histo_ps_tot_error));
845 }
846 else if ("ps_run3_ofc_extrapolate_v0" == tune){
847 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v12/egammaLayerRecalibTunes.root");
848 TFile f(file.c_str());
849 TH1F* histo_ps_tot_error = static_cast<TH1F*>(f.Get("hPS_MuonLowMu_rel21_run3ofc"));
850 assert(histo_ps_tot_error);
852 new GetAmountHisto1D(*histo_ps_tot_error));
853 }
854 else if ("ps_mu_r21_v0" == tune) {
855 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v11/egammaLayerRecalibTunes.root");
856 TFile f(file.c_str());
857 TH1F* histo_ps_tot_error = static_cast<TH1F*>(f.Get("hPS_MuonLowMu_rel21"));
858 assert(histo_ps_tot_error);
860 new GetAmountHisto1D(*histo_ps_tot_error));
861 }
862 else if ("ps_2016_v1" == tune) {
863 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v4/egammaLayerRecalibTunes.root");
864 TFile f(file.c_str());
865 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2016"));
867 new GetAmountHisto1D(*histo_ps_tot_error));
868 }
869 else if ("ps_2012_v3" == tune) {
870 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
871 TFile f(file.c_str());
872 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2012"));
874 new GetAmountHisto1D(*histo_ps_tot_error));
875 }
876 else if ("ps_2012_v3_down" == tune) {
877 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
878 TFile f(file.c_str());
879 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2012"));
881 new GetAmountHisto1DUp(*histo_ps_tot_error));
882 }
883 else if ("ps_2012_v3_up" == tune){
884 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
885 TFile f(file.c_str());
886 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2012"));
888 new GetAmountHisto1DDown(*histo_ps_tot_error));
889 }
890 else if ("ps_2012_v3_errdown" == tune){
891 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
892 TFile f(file.c_str());
893 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2012"));
895 new GetAmountHisto1DErrorUp(*histo_ps_tot_error));
896 }
897 else if ("ps_2012_v3_errup" == tune){
898 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
899 TFile f(file.c_str());
900 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2012"));
902 new GetAmountHisto1DErrorDown(*histo_ps_tot_error));
903 }
904 else if ("ps_2011_v3" == tune) {
905 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
906 TFile f(file.c_str());
907 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2011"));
909 new GetAmountHisto1D(*histo_ps_tot_error));
910 }
911 else if ("ps_2011_v3_down" == tune) {
912 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
913 TFile f(file.c_str());
914 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2011"));
916 new GetAmountHisto1DUp(*histo_ps_tot_error));
917 }
918 else if ("ps_2011_v3_up" == tune){
919 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
920 TFile f(file.c_str());
921 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2011"));
923 new GetAmountHisto1DDown(*histo_ps_tot_error));
924 }
925 else if ("ps_2011_v3_errdown" == tune){
926 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
927 TFile f(file.c_str());
928 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2011"));
930 new GetAmountHisto1DErrorUp(*histo_ps_tot_error));
931 }
932 else if ("ps_2011_v3_errup" == tune){
933 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
934 TFile f(file.c_str());
935 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2011"));
937 new GetAmountHisto1DErrorDown(*histo_ps_tot_error));
938 }
939 // 2010
940 else if ("ps_2010_v3" == tune) {
941 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
942 TFile f(file.c_str());
943 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2010"));
945 new GetAmountHisto1D(*histo_ps_tot_error));
946 }
947 else if ("ps_2010_v3_down" == tune) {
948 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
949 TFile f(file.c_str());
950 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2010"));
952 new GetAmountHisto1DUp(*histo_ps_tot_error));
953 }
954 else if ("ps_2010_v3_up" == tune) {
955 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
956 TFile f(file.c_str());
957 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2010"));
959 new GetAmountHisto1DDown(*histo_ps_tot_error));
960 }
961 else if ("ps_2010_v3_errdown" == tune){
962 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
963 TFile f(file.c_str());
964 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2010"));
966 new GetAmountHisto1DErrorUp(*histo_ps_tot_error));
967 }
968 else if ("ps_2010_v3_errup" == tune){
969 const std::string file = PathResolverFindCalibFile("egammaLayerRecalibTool/v1/egammaLayerRecalibTunes.root");
970 TFile f(file.c_str());
971 TH1* histo_ps_tot_error = checked_cast<TH1*>(f.Get("hPS_2010"));
973 new GetAmountHisto1DErrorDown(*histo_ps_tot_error));
974 }
975 else {
976 throw std::runtime_error(tune+" is not a valid tune");
977 }
978}
979
980egammaLayerRecalibTool::egammaLayerRecalibTool(const std::string& name, const std::string& tune, int SaccEnable)
981 : asg::AsgMessaging(name), m_tune(tune), m_doSaccCorrections(SaccEnable)
982{
983 add_scale(tune);
984}
985
986
987egammaLayerRecalibTool::egammaLayerRecalibTool(const std::string& tune, int SaccEnable)
988 : egammaLayerRecalibTool("egammaLayerRecalibTool", tune, SaccEnable) { }
989
990
992{
993 m_modifiers.emplace_back(modifier, amount);
994}
995
997{
999 for (const auto& modifier : m_modifiers) {
1000 const float amount = (*modifier.second)(inputs);
1001 const auto s = (*modifier.first)(inputs, amount);
1002 ATH_MSG_DEBUG(" after E0|E1|E2|E3 = " << inputs.E0raw << "|" << inputs.E1raw << "|" << inputs.E2raw << "|" << inputs.E3raw);
1003 if (s != CP::CorrectionCode::Ok) {
1004 if (status != CP::CorrectionCode::Error) { status = s; }
1005 }
1006 }
1007 return status;
1008}
1009
1011{
1012 const xAOD::CaloCluster* cluster = particle.caloCluster();
1013 if (!cluster) {
1014 ATH_MSG_ERROR("egamma particle without CaloCluster");
1016 }
1017
1018 std::string fixT = "";
1019 double addE2 = 0, addE3 = 0;
1022 fixT = "_egFixForTopoTimingCut";
1023 unsigned short stat =
1024 xAOD::EgammaHelpers::energyInMissingCells(particle,addE2,addE3);
1025 if (stat) {
1026 ATH_MSG_WARNING("Fix for missing cells required"
1027 " but some layer info is not available,"
1028 " from L2 : " << stat%2 << " from L3 : " << stat/2);
1029 }
1030 }
1031
1032 double eta_calo;
1033 static const SG::AuxElement::Accessor<float> accEtaCalo("etaCalo");
1034 if(particle.author() == xAOD::EgammaParameters::AuthorFwdElectron){
1035 eta_calo = cluster->eta();
1036 }
1037 else if (cluster->retrieveMoment(xAOD::CaloCluster::ETACALOFRAME, eta_calo)){
1038
1039 }
1040 else if (accEtaCalo.isAvailable(*cluster)) {
1041 eta_calo = accEtaCalo(*cluster);
1042 }
1043 else{
1044 ATH_MSG_ERROR("etaCalo not available as auxilliary variable,"
1045 " using cluster eta as eta calo!");
1046 eta_calo=cluster->eta();
1047 }
1048
1049 StdCalibrationInputs inputs {
1050 event_info.averageInteractionsPerCrossing(),
1051 event_info.runNumber(),
1052 cluster->eta(),
1053 cluster->phi(),
1054 cluster->energyBE(0),
1055 cluster->energyBE(1),
1056 cluster->energyBE(2) + addE2,
1057 cluster->energyBE(3) + addE3,
1058 eta_calo };
1059
1060 bool isData = !event_info.eventType(xAOD::EventInfo::IS_SIMULATION);
1062 if (isData || m_scaleMC)
1063 status = scale_inputs(inputs);
1064
1065 static const SG::AuxElement::Decorator<double> deco_E0("correctedcl_Es0");
1066 static const SG::AuxElement::Decorator<double> deco_E1("correctedcl_Es1");
1067 static const SG::AuxElement::Decorator<double> deco_E2("correctedcl_Es2");
1068 static const SG::AuxElement::Decorator<double> deco_E3("correctedcl_Es3");
1070 deco_layer_correction("layer_correction");
1071
1072 if (status == CP::CorrectionCode::Ok) {
1073 ATH_MSG_DEBUG("decorating cluster with corrected layer energies");
1074 deco_E0(*cluster) = m_doPSCorrections ?
1075 inputs.E0raw : cluster->energyBE(0);
1076 deco_E1(*cluster) = m_doS12Corrections or m_doSaccCorrections ?
1077 inputs.E1raw : cluster->energyBE(1);
1078 deco_E2(*cluster) = m_doS12Corrections or m_doSaccCorrections ?
1079 inputs.E2raw : cluster->energyBE(2) + addE2;
1080 deco_E3(*cluster) = m_doSaccCorrections ?
1081 inputs.E3raw : cluster->energyBE(3) + addE3;
1082 deco_layer_correction(*cluster) = isData ? m_tune+fixT : fixT;
1083 return status;
1084 }
1085
1086 ATH_MSG_DEBUG("cannot correct layer energies:"
1087 " decorating particle with non-corrected layer energies");
1088 // this is done for safety, since when a particle is decorated
1089 // all the particle in the container are decorated
1090 // it is not possible to distinguish between decorated / non-decorated
1091 // since all are decorated
1092 deco_E0(*cluster) = cluster->energyBE(0);
1093 deco_E1(*cluster) = cluster->energyBE(1);
1094 deco_E2(*cluster) = cluster->energyBE(2) + addE2;
1095 deco_E3(*cluster) = cluster->energyBE(3) + addE3;
1096 deco_layer_correction(*cluster) = isData ? m_tune + "_Err" + fixT : fixT;
1097 return status;
1098
1099}
1100
1101
1103{
1104 for (auto modifier : m_modifiers) {
1105 delete modifier.first;
1106 delete modifier.second;
1107 }
1108 m_modifiers.clear();
1109}
1110
1111
1112// helper
1113std::map<std::string, std::string> parse(const std::string& list)
1114{
1115 std::cout << "list: '" << list << "'" << std::endl;
1116 std::map<std::string, std::string> result;
1117 TIter next(TString(list).Tokenize(","));
1118 while (TObjString* sObj = (TObjString*) next())
1119 {
1120 const TString& item(sObj->GetString());
1121 std::cout << "item: '" << item << "'" << std::endl;
1122 TObjArray* item_list = TString(item).Tokenize(":");
1123 std::string key;
1124 std::string value;
1125 if (item_list->GetEntries() == 1) {
1126 key = "amount";
1127 value = static_cast<TObjString*>(item_list->At(0))->GetString().Data();
1128 }
1129 else if (item_list->GetEntries() == 2) {
1130 key = static_cast<TObjString*>(item_list->At(0))->GetString().Data();
1131 value = static_cast<TObjString*>(item_list->At(1))->GetString().Data();
1132 }
1133 else {
1134 std::cerr << "invalid string " << item << std::endl;
1135 }
1136 if (result.find(key) != result.end()) {
1137 std::cerr << "trying to insert two times key " << key << std::endl;
1138 assert(false);
1139 }
1140 result.insert(std::make_pair(key, value));
1141 }
1142 return result;
1143}
1144
1145
1146std::pair<std::string, egammaLayerRecalibTool*>
1147egammaLayerRecalibTool::create(const std::string& type, const std::string& args)
1148{
1149 std::map<std::string, std::string> args_map = parse(args);
1150 egammaLayerRecalibTool* tool = new egammaLayerRecalibTool("egammaLayerRecalibTool", "");
1151 std::string name = "";
1152 std::string amount_name = "";
1153 std::string type_name = "";
1154
1155 GetAmountBase* amount_getter = nullptr;
1156 InputModifier* modifier = nullptr;
1157
1158 if (args_map.find("amount") != args_map.end()) {
1159 std::string amount_str = args_map["amount"];
1160 bool perc = false;
1161 if (amount_str.back()=='%') {
1162 perc = true;
1163 amount_str.pop_back();
1164 }
1165 const float amount = TString(amount_str).Atof() * (perc ? 0.01 : 1);
1166
1167 amount_getter = new GetAmountFixed(amount);
1168 std::stringstream amount_stream;
1169 amount_stream << amount;
1170 amount_name = amount_stream.str();
1171 std::replace(amount_name.begin(), amount_name.end(), '-', 'n');
1172 std::replace(amount_name.begin(), amount_name.end(), '.', 'p');
1173 }
1174 else if (args_map.find("name") != args_map.end()) {
1175 name = args_map["name"];
1176 }
1177 else if (args_map.find("histo") != args_map.end()) {
1178 int dim = 0;
1179 if (args_map.find("file") == args_map.end()) {
1180 std::cerr << "with histo you must specify file" << std::endl;
1181 assert(false);
1182 }
1183 if (args_map.find("formulax") != args_map.end()) dim = 1;
1184
1185 if (dim == 0)
1186 {
1187 std::cerr << "with histo you must specify formulax" << std::endl;
1188 assert(false);
1189 }
1190 if (dim == 1) {
1191 TFile f(args_map["file"].c_str());
1192 std::cout << "opening histo " << args_map["histo"] << " from file " << args_map["file"] << std::endl;
1193 TH1F* histo = dynamic_cast<TH1F*>(f.Get(args_map["histo"].c_str()));
1194
1195 if(histo){
1196 histo->SetDirectory(nullptr);
1197 amount_getter = new GetAmountHisto1D(*histo);
1198 }
1199 else{assert(false); }
1200 }
1201 else { assert(false); }
1202 }
1203 else {
1204 std::cerr << "cannot understand argument " << args << std::endl;
1205 assert(false);
1206 }
1207
1208 if ("bias-E0" == type) { modifier = new ScaleE0(InputModifier::ZEROBASED); type_name = "E0"; }
1209 else if ("bias-E1" == type) { modifier = new ScaleE1(InputModifier::ZEROBASED); type_name = "E1"; }
1210 else if ("bias-E2" == type) { modifier = new ScaleE2(InputModifier::ZEROBASED); type_name = "E2"; }
1211 else if ("bias-E3" == type) { modifier = new ScaleE3(InputModifier::ZEROBASED); type_name = "E3"; }
1212 else if ("bias-E1overE2" == type) { modifier = new ScaleE1overE2(InputModifier::ZEROBASED); type_name = "E1overE2"; }
1213 else if ("bias-Eaccordion" == type) { modifier = new ScaleEaccordion(InputModifier::ZEROBASED); type_name = "Eaccordion"; }
1214 else if ("bias-Ecalorimeter" == type) { modifier = new ScaleEcalorimeter(InputModifier::ZEROBASED); type_name = "Ecalorimeter"; }
1215
1216 if (not type_name.empty() and not amount_name.empty()) {
1217 name = type_name + "_" + amount_name;
1218 }
1219
1220 if (name.empty()) {
1221 std::cerr << "you need to specify a name for the bias with type " << type << std::endl;
1222 }
1223
1224 if (modifier and amount_getter) {
1225 tool->add_scale(modifier, amount_getter);
1226 }
1227 else{
1228 tool->add_scale(type);
1229 //release resources, if modifier false need to release amount_getter and vice versa
1230 //since they are not passed to the tool
1231 if(modifier) delete modifier;
1232 if(amount_getter) delete amount_getter;
1233 }
1234
1235 return {name, tool};
1236}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
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:575
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
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 applyCorrection(xAOD::Egamma &, 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