5#ifndef EGAMMA_CALIB_TOOL_H_
6#define EGAMMA_CALIB_TOOL_H_
52 bool do_throw =
false) {
56 phi_calo = cluster.
phi();
60 phi_calo = phiCaloAcc(cluster);
63 msg.msg(MSG::ERROR) <<
"phiCalo not available as auxilliary variable"
66 throw std::runtime_error(
"phiCalo not available as auxilliary variable");
68 msg.msg(MSG::WARNING) <<
"using phi as phiCalo" <<
endmsg;
69 phi_calo = cluster.
phi();
75 bool do_throw =
false) {
79 eta_calo = cluster.
eta();
83 eta_calo = etaCaloAcc(cluster);
86 msg.msg(MSG::ERROR) <<
"etaCalo not available as auxilliary variable"
89 throw std::runtime_error(
"etaCalo not available as auxilliary variable");
91 msg.msg(MSG::WARNING) <<
"using eta as etaCalo" <<
endmsg;
103 template<ContainerIdConcept CI = ClusterDef,ColumnarModeConcept CM=ColumnarMode>
113 :
m_phiCaloAcc (columnarTool,
"phiCalo", {.isOptional =
true}),
132 msg.msg(MSG::ERROR) <<
"phiCalo not available as auxilliary variable" <<
endmsg;
133 if (do_throw) {
throw std::runtime_error(
"phiCalo not available as auxilliary variable"); }
134 msg.msg(MSG::WARNING) <<
"using phi as phiCalo" <<
endmsg;
141 template<ContainerIdConcept CI = ClusterDef,ColumnarModeConcept CM=ColumnarMode>
151 :
m_etaCaloAcc (columnarTool,
"etaCalo", {.isOptional =
true}),
170 msg.msg(MSG::ERROR) <<
"etaCalo not available as auxilliary variable" <<
endmsg;
171 if (do_throw) {
throw std::runtime_error(
"etaCalo not available as auxilliary variable"); }
172 msg.msg(MSG::WARNING) <<
"using eta as etaCalo" <<
endmsg;
181namespace ADD_CMODE(CP) {
183class EgammaCalibrationAndSmearingTool
184 :
virtual public CP::IEgammaCalibrationAndSmearingTool,
185 public asg::AsgMetadataTool,
public columnar::ColumnarTool<> {
188 IEgammaCalibrationAndSmearingTool, CP::ISystematicsTool,
189 CP::IReentrantSystematicsTool)
192 enum class ScaleDecorrelation {
198 enum class ResolutionDecorrelation {
FULL, ONENP };
199 static const int AUTO = 2;
201 typedef unsigned int RandomNumber;
202 typedef std::function<
int(
const EgammaCalibrationAndSmearingTool&,
207 EgammaCalibrationAndSmearingTool(
const std::string& name);
208 ~EgammaCalibrationAndSmearingTool();
213 virtual CP::CorrectionCode applyCorrection(
xAOD::Egamma&)
const override;
222 virtual CP::CorrectionCode correctedCopy(
const xAOD::Photon&,
229 virtual CP::SystematicSet affectingSystematics()
const override;
231 virtual bool isAffectedBySystematic(
232 const CP::SystematicVariation& systematic)
const override;
234 virtual CP::SystematicSet recommendedSystematics()
const override;
237 const CP::SystematicSet& systConfig)
override;
238 virtual void setRandomSeedFunction(
const IdFunction&& function) {
239 m_set_seed_function = std::move(function);
241 const IdFunction getRandomSeedFunction()
const {
return m_set_seed_function; }
244 double energy,
double cl_eta,
double cl_etaCalo,
246 bool withCT =
false)
const override;
249 static const unsigned int m_Run2Run3runNumberTransition = 400000;
251 std::string m_ESModel;
252 std::string m_decorrelation_model_name;
253 std::string m_decorrelation_model_scale_name;
254 std::string m_decorrelation_model_resolution_name;
255 ScaleDecorrelation m_decorrelation_model_scale = ScaleDecorrelation::FULL;
256 ResolutionDecorrelation m_decorrelation_model_resolution =
257 ResolutionDecorrelation::FULL;
259 int m_doScaleCorrection;
262 std::string m_ResolutionType;
269 int m_useIntermoduleCorrection;
270 int m_usePhiUniformCorrection;
271 int m_useCaloDistPhiUnifCorrection;
272 int m_useGainCorrection;
273 int m_doADCLinearityCorrection;
274 int m_doLeakageCorrection;
275 bool m_use_ep_combination;
276 int m_use_mva_calibration;
277 bool m_use_full_statistical_error;
278 int m_use_temp_correction201215;
279 int m_use_uA2MeV_2015_first2weeks_correction;
280 bool m_use_mapping_correction;
281 int m_user_random_run_number;
282 int m_useGainInterpolation;
283 int m_useLayerCorrection;
284 int m_usePSCorrection;
285 int m_useS12Correction;
286 int m_useSaccCorrection;
291 std::unique_ptr<TH2> m_caloDistPhiUnifCorr;
293 Gaudi::Property<bool> m_fixForMissingCells{
294 this,
"FixForMissingCells",
true,
295 "AOD fix for cell recovery in core egamma cluster"};
297 Gaudi::Property<bool> m_doFwdCalib{
298 this,
"DoFwdElectronCalibration",
false,
299 "MVA calibration of the forward electron"};
301 Gaudi::Property<bool> m_doElectronMVA{
302 this,
"DoElectronMVACalibration",
true,
303 "Load the electron MVA calibration (disable if no electrons are calibrated)"};
305 Gaudi::Property<bool> m_doPhotonMVA{
306 this,
"DoPhotonMVACalibration",
true,
307 "Load the photon MVA calibrations (disable if no photons are calibrated)"};
309 Gaudi::Property<std::string> m_pVtxKey{
310 this,
"PrimaryVerticesKey",
"PrimaryVertices",
311 "Name of the primary vertex container"};
313 void setupSystematics();
316 struct EtaCaloPredicate
318 EtaCaloPredicate(
double eta_min,
double eta_max) : m_eta_min(eta_min), m_eta_max(eta_max) {}
320 const Accessors&
acc = *
tool.m_accessors;
321 const double eta =
acc.etaCaloAcc(
acc.caloClusterAcc(p)[0].value(),
acc.authorAcc (p));
322 return (
eta >= m_eta_min and
eta < m_eta_max);
325 float m_eta_min, m_eta_max;
328 const EgammaPredicate EtaCaloPredicateFactory(
double eta_min,
double eta_max)
const
330 return EtaCaloPredicate(eta_min, eta_max);
335 struct AbsEtaCaloPredicate {
336 AbsEtaCaloPredicate(
double eta_min,
double eta_max)
337 : m_eta_min(eta_min), m_eta_max(eta_max) {}
339 const Accessors&
acc = *
tool.m_accessors;
341 std::abs(
acc.etaCaloAcc(
acc.caloClusterAcc(p)[0].value(),
acc.authorAcc (p)));
342 return (aeta >= m_eta_min and aeta < m_eta_max);
346 float m_eta_min, m_eta_max;
349 const EgammaPredicate AbsEtaCaloPredicateFactory(
double eta_min,
350 double eta_max)
const {
354 return AbsEtaCaloPredicate(eta_min, eta_max);
357 const EgammaPredicate AbsEtaCaloPredicateFactory(
358 std::pair<double, double> edges)
const {
359 return AbsEtaCaloPredicateFactory(edges.first, edges.second);
362 const std::vector<EgammaPredicate> AbsEtaCaloPredicatesFactory(
363 const std::vector<std::pair<double, double>>& edges)
const {
364 std::vector<EgammaPredicate>
result;
365 result.reserve(edges.size());
366 for (
const auto& it : edges) {
367 result.push_back(AbsEtaCaloPredicateFactory(
it.first,
it.second));
372 const std::vector<EgammaPredicate> AbsEtaCaloPredicatesFactory(
373 const std::vector<double>& edges)
const {
374 std::vector<EgammaPredicate>
result;
375 result.reserve(edges.size() - 1);
376 auto it2 = edges.begin();
378 for (; it2 != edges.end(); ++
it, ++it2) {
379 result.push_back(AbsEtaCaloPredicateFactory(*it, *it2));
384 struct DoubleOrAbsEtaCaloPredicate {
385 DoubleOrAbsEtaCaloPredicate(
double eta1_min,
double eta1_max,
386 double eta2_min,
double eta2_max)
387 : m_eta1_min(eta1_min),
388 m_eta1_max(eta1_max),
389 m_eta2_min(eta2_min),
390 m_eta2_max(eta2_max) {}
393 const Accessors&
acc = *
tool.m_accessors;
395 std::abs(
acc.etaCaloAcc(
acc.caloClusterAcc(p)[0].value(),
acc.authorAcc (p)));
396 return ((aeta >= m_eta1_min and aeta < m_eta1_max) or
397 (aeta >= m_eta2_min and aeta < m_eta2_max));
401 float m_eta1_min, m_eta1_max, m_eta2_min, m_eta2_max;
404 const EgammaPredicate DoubleOrAbsEtaCaloPredicateFactory(
405 double eta1_min,
double eta1_max,
double eta2_min,
406 double eta2_max)
const {
407 return DoubleOrAbsEtaCaloPredicate(eta1_min, eta1_max, eta2_min, eta2_max);
417 bool withCT =
true)
const override;
418 double intermodule_correction(
double Ecl,
double phi,
double eta)
const;
419 double correction_phi_unif(
double eta,
double phi)
const;
422 ServiceHandle<IegammaMVASvc> m_MVACalibSvc{
this,
"MVACalibSvc",
"",
423 "calibration service"};
424 std::unique_ptr<egGain::GainUncertainty> m_gain_tool_run2;
425 std::shared_ptr<LinearityADC> m_ADCLinearity_tool;
426 egGain::GainTool* m_gain_tool =
nullptr;
427 egammaLayerRecalibTool* m_layer_recalibration_tool =
nullptr;
428 std::string m_layer_recalibration_tune;
431 std::unique_ptr<AtlasRoot::egammaEnergyCorrectionTool> m_rootTool;
432 std::string m_MVAfolder;
435 EgammaPredicate predicate;
439 std::map<CP::SystematicVariation, SysInfo> m_syst_description;
440 std::map<CP::SystematicVariation, egEnergyCorr::Resolution::Variation>
441 m_syst_description_resolution;
449 EgammaPredicate m_currentScalePredicate;
451 IdFunction m_set_seed_function;
460 Gaudi::Property<bool> m_onlyElectrons {
this,
"onlyElectrons",
false,
"the tool will only be applied to electrons"};
461 Gaudi::Property<bool> m_onlyPhotons {
this,
"onlyPhotons",
false,
"the tool will only be applied to photons"};
462 struct Accessors :
public columnar::ColumnarTool<>
464 Accessors(columnar::ColumnarTool<>& tool) : columnar::ColumnarTool<>(&
tool) {}
467 columnar::MomentumAccessors<columnar::EgammaDef> momAcc;
486 columnar::ClusterHelpers::EnergyBEAccessor<> energyBEAcc {*
this};
487 columnar::ClusterHelpers::EtaBEAccessor<> clusterEtaBEAcc {*
this};
488 columnar::ClusterHelpers::EtaCaloAccessor<> etaCaloAcc {*
this};
489 columnar::ClusterHelpers::PhiCaloAccessor<> phiCaloAcc {*
this};
491 columnar::EventInfoHelpers::EventTypeAccessor<> eventTypeAcc {*
this};
497 std::unique_ptr<Accessors> m_accessors;