22#include "lwtnn/parse_json.hh"
65 if (
m_jetAlgo.EqualTo(
"") ) {
ATH_MSG_FATAL(
"No jet algorithm specified. Aborting.");
return StatusCode::FAILURE; }
68 TString MLGSCFile =
m_config->GetValue(
"GNNC.MLFactorsFile",
"empty");
69 if ( MLGSCFile.EqualTo(
"empty") ) {
71 return StatusCode::FAILURE;
74 MLGSCFile.Remove(0,33);
75 MLGSCFile.Insert(0,
"JetCalibTools/");
83 std::ifstream input(fileName);
84 std::unique_ptr<lwt::LightweightGraph> lwnn = std::make_unique<lwt::LightweightGraph> ( lwt::parse_json_graph(input) );
85 m_lwnns.push_back(std::move(lwnn));
92 TString ptCalibHists =
m_config->GetValue(
"GNNC.JPtS_CalibHists",
"");
94 ptCalibHists.Remove(0,33);
95 ptCalibHists.Insert(0,
"JetCalibTools/");
104 ATH_MSG_FATAL(
"Pt cutoff vector has wrong length. There should be one value per eta bin.");
return StatusCode::FAILURE;
105 return StatusCode::FAILURE;
121 return StatusCode::SUCCESS;
128 jetStartP4 =
jet.jetP4();
135 std::map<std::string,std::map<std::string,double>> inputs;
136 inputs[
"node_0"] = NN_inputValues;
138 std::map<std::string, double> outputs =
m_lwnns[nnEtaBin]->compute(inputs);
139 double nnCalibFactor = outputs[
"out_0"];
154 jet.setJetP4( calibP4 );
156 return StatusCode::SUCCESS;
165 std::unique_ptr<TFile> tmpF(TFile::Open( fileName ));
166 TList *ptCorr_l =
dynamic_cast<TList*
>( tmpF->Get(ptCorr_name.c_str()));
168 ATH_MSG_ERROR(
"TList pointer is null in GlobalNNCalibration::loadSplineHists");
173 int nBinsCorr = ptCorr_l->GetSize();
175 if(nBinsCorr != nEtaBins){
176 ATH_MSG_WARNING(
"Do not have the correct number of eta bins for " << fileName <<
"\t" << ptCorr_name <<
"\t" << ptCorr_l->GetSize() );
180 auto *pTH1 =
dynamic_cast<TH1*
>(ptCorr_l->At(i));
181 if (not pTH1)
continue;
198 double R = slope*(pT-ptCutoff)+Rcutoff;
215 double slope = (rSecond - rFirst) /
binWidth;
224 std::vector<float> samplingFrac = jet_reco.
getAttribute<std::vector<float> >(
"EnergyPerSampling");
228 jetStartP4 = jet_reco.
jetP4();
230 float jetE_constitscale = jetconstitP4.e();
233 int PVindex = jetEventInfo.
PVIndex();
238 float EM0 = (samplingFrac[0]+samplingFrac[4])/jetE_constitscale;
239 float EM1 = (samplingFrac[1]+samplingFrac[5])/jetE_constitscale;
240 float EM2 = (samplingFrac[2]+samplingFrac[6])/jetE_constitscale;
241 float EM3 = (samplingFrac[3]+samplingFrac[7])/jetE_constitscale;
242 float Tile0 = (samplingFrac[12]+samplingFrac[18])/jetE_constitscale;
243 float Tile1 = (samplingFrac[13]+samplingFrac[19])/jetE_constitscale;
244 float Tile2 = (samplingFrac[14]+samplingFrac[20])/jetE_constitscale;
245 float HEC0 = (samplingFrac[8])/jetE_constitscale;
246 float HEC1 = (samplingFrac[9])/jetE_constitscale;
247 float HEC2 = (samplingFrac[10])/jetE_constitscale;
248 float HEC3 = (samplingFrac[11])/jetE_constitscale;
250 float FCAL0 = (samplingFrac[21])/jetE_constitscale;
251 float FCAL1 = (samplingFrac[22])/jetE_constitscale;
252 float FCAL2 = (samplingFrac[23])/jetE_constitscale;
257 std::map<std::string,double> inputValues;
263 inputValues[
"jet_pt"] = log10(
getJESPt(jet_reco));
266 inputValues[
"jet_pt"] =
getJESPt(jet_reco);
268 inputValues[
"EM0"] = EM0;
269 inputValues[
"EM1"] = EM1;
270 inputValues[
"EM2"] = EM2;
271 inputValues[
"EM3"] = EM3;
272 inputValues[
"TILE0"] = Tile0;
273 inputValues[
"TILE1"] = Tile1;
274 inputValues[
"TILE2"] = Tile2;
275 inputValues[
"HEC0"] = HEC0;
276 inputValues[
"HEC1"] = HEC1;
277 inputValues[
"HEC2"] = HEC2;
278 inputValues[
"HEC3"] = HEC3;
279 inputValues[
"FCAL0"] = FCAL0;
280 inputValues[
"FCAL1"] = FCAL1;
281 inputValues[
"FCAL2"] = FCAL2;
286 inputValues[
"jet_n90Constituents"] = jet_reco.
getAttribute<
float>(
"N90Constituents");
287 inputValues[
"jet_nMuSeg"] = jet_reco.
getAttribute<
int>(
"GhostMuonSegmentCount");
288 inputValues[
"NPV"] = jetEventInfo.
NPV();
289 inputValues[
"averageInteractionsPerCrossing"] = jetEventInfo.
mu();
292 std::map<std::string,double> NNInputValues;
294 NNInputValues[input.Data()] = inputValues[input.Data()];
297 return NNInputValues;
304 double detEta = jet_reco.
getAttribute<
float>(
"DetectorEta");
305 for(
unsigned int i=1; i<etaBins.size()-1; i++){
306 if(std::abs(detEta) < etaBins[i])
return i-1;
309 return etaBins.size()-2;
315 if( SumPtChargedPFOPt500Acc.
isAvailable(jet_reco) ) {
316 float thisChargedFraction = SumPtChargedPFOPt500Acc(jet_reco).at(PVindex);
318 return double(thisChargedFraction);
326 return DetectorEtaAcc.
withDefault (jet_reco, -999);
332 return NumTrkPt1000Acc(jet_reco).at(PVindex);
339 return double(TrackWidthPt1000Acc(jet_reco).at(PVindex));
345 return jet_reco.
jetP4(
"JetEtaJESScaleMomentum").pt() / 1.e3;
#define ATH_MSG_WARNING(x)
Helper class to provide constant type-safe access to aux data.
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
std::string m_calibAreaTag
std::vector< std::unique_ptr< TH1 > > m_ptCorrFactors
double getJetDetEta(const xAOD::Jet &jet_reco) const
Returns the detector eta of the jet.
std::vector< double > m_closureEtaBins
std::vector< double > m_JPtS_MinPt_Slopes
std::vector< double > m_JPtS_MinPt_Pt
double getJetWtrk1000(const xAOD::Jet &jet_reco, int PVindex) const
Returns the jet width.
std::vector< TString > m_NNInputs
GlobalNNCalibration()
The constructor.
int getJetNtrk1000(const xAOD::Jet &jet_reco, int PVindex) const
Returns the number of tracks with pT > 1 GeV associated to the jet.
virtual StatusCode initialize() override
Returns the charged fraction of a jet.
void loadSplineHists(const TString &fileName, const std::string &etajes_name="etaJes")
Reads the spline histograms from the file given in the config, and stores them in m_ptCorrFactors.
double getJetChargedFraction(const xAOD::Jet &jet_reco, int PVindex) const
Returns the charged fraction of a jet.
double getJESPt(const xAOD::Jet &jet_reco) const
Returns the jet pT after the MCJES calibration.
virtual StatusCode calibrate(xAOD::Jet &jet, JetEventInfo &) const override
double getSplineCorr(const int etaBin, double E) const
Returns the correction from spline histogram, which should be applied after the NN correction.
std::map< std::string, double > getJetFeatures(const xAOD::Jet &jet_reco, JetEventInfo &jetEventInfo) const
Returns a map of possible inputs to the NN, and their corresponding values for this jet.
std::vector< double > m_nnEtaBins
int getEtaBin(const xAOD::Jet &jet_reco, const std::vector< double > &etaBins) const
Returns the eta bin, as determined by a list of bin edges.
double getSplineSlope(const int ieta, const double minPt) const
Gets the slope of the spline histogram for a given eta bin, for extrapolation of the calibration.
std::vector< double > m_JPtS_MinPt_R
std::vector< std::unique_ptr< lwt::LightweightGraph > > m_lwnns
JetCalibrationStep(const char *name="JetCalibrationStep")
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
const_reference_type withDefault(const ELT &e, const T &deflt) const
Fetch the variable for one element, as a const reference, with a default.
bool getAttribute(AttributeID type, T &value) const
Retrieve attribute moment by enum.
JetFourMom_t jetP4() const
The full 4-momentum of the particle : internal jet type.
StrV Vectorize(const TString &str, const TString &sep=" ")
VecD VectorizeD(const TString &str, const TString &sep=" ")
Jet_v1 Jet
Definition of the current "jet version".
@ JetConstitScaleMomentum
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.