31#include "CaloGeoHelpers/CaloSampling.h"
33#include "lwtnn/parse_json.hh"
45AsgForwardElectronCalibrationTool::AsgForwardElectronCalibrationTool(
46 const std::string& myname)
63 ATH_MSG_ERROR(
"Exactly 3 model files expected (one per eta bin): "
64 "[2.5,2.7], [2.7,3.2], [3.2,4.0]). Only got "
66 return StatusCode::FAILURE;
89 "x14_SECOND_ENG_DENS",
93 "x17_delta_phi_rescaled2",
99 "x22_calo_frac_HAD_0",
100 "x23_calo_frac_HAD_1",
101 "x24_calo_frac_HAD_2",
102 "x25_calo_frac_HAD_3"
112 return StatusCode::FAILURE;
114 std::ifstream dnn_json(path);
115 auto parsed = lwt::parse_json_graph(dnn_json);
117 std::make_unique<lwt::LightweightGraph>(parsed));
119 <<
m_graphs.size() - 1 <<
": " << path);
122 ATH_MSG_INFO(
"AsgForwardElectronCalibrationTool initialised");
123 return StatusCode::SUCCESS;
150 const double absEta = std::abs(cluster->
eta());
154 <<
" is outside allowed range.");
160 std::vector<float> inputs;
161 if (!
getInputs(eg, inputs))
return -999.;
165 std::map<std::string, std::map<std::string, double>> inputMap;
167 inputMap[
"node_0"][
m_variables[i]] =
static_cast<float>(inputs[i]);
169 const auto outputs =
m_graphs[etaBin]->compute(inputMap);
170 const double rawOut = outputs.begin()->second;
174 double calibratedPt_rounded = std::round(calibratedPt);
176 return calibratedPt_rounded;
185 if (absEta > 2.5 && absEta <= 2.7)
return 0;
186 if (absEta > 2.7 && absEta <= 3.2)
return 1;
187 if (absEta > 3.2 && absEta <= 4.0)
return 2;
195 std::vector<float>& inputs)
const
203 if (!cluster) {
ATH_MSG_ERROR(
"No CaloCluster.");
return false; }
204 if (!track) {
ATH_MSG_ERROR(
"No TrackParticle.");
return false; }
207 inputs.push_back(
static_cast<float>(cluster->
eta()));
208 inputs.push_back(
static_cast<float>(cluster->
phi()));
211 inputs.push_back(
static_cast<float>(track->eta()));
212 inputs.push_back(
static_cast<float>(track->phi()));
215 if (track->hasValidTime()) inputs.push_back(
static_cast<float>(track->time()));
218 ATH_MSG_DEBUG(
"No valid time for the track while doing track->time()" );
219 inputs.push_back(-99);
228 const char* name) ->
float {
245 const char* name) ->
float {
257 "delta_phi_rescaled2"));
263 const double caloE = cluster->
e();
264 const double inv_E = (caloE != 0.) ? 1. / caloE : 0.;
270 inputs.push_back(
static_cast<float>(cluster->
energyBE(1) * inv_E));
271 inputs.push_back(
static_cast<float>(cluster->
energyBE(2) * inv_E));
272 inputs.push_back(
static_cast<float>(cluster->
energyBE(3) * inv_E));
277 inputs.push_back(
static_cast<float>(
278 cluster->
eSample(
static_cast<CS
>(CaloSampling::HEC0)) * inv_E));
279 inputs.push_back(
static_cast<float>(
280 (cluster->
eSample(
static_cast<CS
>(CaloSampling::HEC1)) +
281 cluster->
eSample(
static_cast<CS
>(CaloSampling::FCAL0))) * inv_E));
282 inputs.push_back(
static_cast<float>(
283 (cluster->
eSample(
static_cast<CS
>(CaloSampling::HEC2)) +
284 cluster->
eSample(
static_cast<CS
>(CaloSampling::FCAL1))) * inv_E));
285 inputs.push_back(
static_cast<float>(
286 (cluster->
eSample(
static_cast<CS
>(CaloSampling::HEC3)) +
287 cluster->
eSample(
static_cast<CS
>(CaloSampling::FCAL2))) * inv_E));
299 return (
x > 20.) ?
x : std::log1p(std::exp(
x));
#define ATH_MSG_WARNING(x)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
bool retrieveMoment(MomentType type, double &value) const
Retrieve individual moment.
virtual double eta() const
The pseudorapidity ( ) of the particle.
virtual double e() const
The total energy of the particle.
float eSample(const CaloSample sampling) const
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.
MomentType
Enums to identify different moments.
@ SECOND_ENG_DENS
Second Moment in E/V.
@ SECOND_LAMBDA
Second Moment in .
@ LATERAL
Normalized lateral moment.
@ LONGITUDINAL
Normalized longitudinal moment.
@ ENG_FRAC_MAX
Energy fraction of hottest cell.
@ SECOND_R
Second Moment in .
@ CENTER_LAMBDA
Shower depth at Cluster Centroid.
const xAOD::CaloCluster * caloCluster(size_t index=0) const
Pointer to the xAOD::CaloCluster/s that define the electron candidate.
bool trackCaloMatchValue(float &value, const EgammaParameters::TrackCaloMatchType information) const
Accessor for Track to Calo Match Values.
const xAOD::TrackParticle * trackParticle(size_t index=0) const
Pointer to the xAOD::TrackParticle/s that match the electron candidate.
uint8_t trackParticleSummaryIntValue(const SummaryType information, int index=0) const
Accessor to the matching track(s) int information (index = 0 is the best match) Will lead to an excep...
@ deltaPhiFromLastMeasurement
difference between the cluster phi (sampling 2) and the eta of the track extrapolated from the last m...
@ deltaEta2
difference between the cluster eta (second sampling) and the eta of the track extrapolated to the sec...
@ deltaPhiRescaled2
difference between the cluster phi (second sampling) and the phi of the track extrapolated to the sec...
@ deltaPhi2
difference between the cluster phi (second sampling) and the phi of the track extrapolated to the sec...
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
@ numberOfSCTHits
number of hits in SCT [unit8_t].
@ numberOfPixelHits
these are the pixel hits, including the b-layer [unit8_t].
Electron_v1 Electron
Definition of the current "egamma version".