40 return StatusCode::FAILURE;
45 TString absoluteJESCalibFile =
m_config->GetValue(
"AbsoluteJES.CalibFile",
"");
47 absoluteJESCalibFile.Remove(0,33);
48 absoluteJESCalibFile.Insert(0,
"JetCalibTools/");
52 m_config->ReadFile(calibFile, kEnvLocal);
53 ATH_MSG_INFO(
"Reading absolute calibration factors from: " << calibFile);
76 for (
int i=0;i<=90; i++)
77 etaBins.push_back(0.1*i-4.5);
79 else if (etaBins.empty()) {
ATH_MSG_FATAL(
"JES.EtaBins incorrectly specified");
return StatusCode::FAILURE; }
81 ATH_MSG_FATAL(
"JES.EtaBins has " << etaBins.size()-1 <<
" bins, can be maximally 90!" );
82 return StatusCode::FAILURE;
90 else {
ATH_MSG_FATAL(
"You can't apply the mass correction unless you specify ApplyMassCorrection: true in the configuration file!");
return StatusCode::FAILURE; }
93 for (
uint ieta=0;ieta<etaBins.size()-1;++ieta) {
96 TString key=Form(
"JES.%s_Bin%d",
m_jetAlgo.Data(),ieta);
113 const double Rcutoff =
getLogPolN(factors,Ecutoff);
115 if(Slope > Rcutoff/Ecutoff)
ATH_MSG_FATAL(
"Slope of calibration curve at minimum ET is too steep for the JES factors of etabin " << ieta <<
", eta = " << etaBins[ieta] );
125 const double Param1 = (2/Ecutoff)*(Rcutoff-
h)-Slope;
126 const double Param2 = (0.5/Ecutoff)*(Slope-Param1);
128 if( Param1 < 0 || Param1 + 2*Param2*Ecutoff < 0)
ATH_MSG_FATAL(
"Polynomial extension to calibration curve below minimum ET is not monotonically increasing for etabin " << ieta <<
", eta = " << etaBins[ieta] );
136 TString key=Form(
"EtaCorr.%s_Bin%d",
m_jetAlgo.Data(),ieta);
140 if (params.size()!=
m_nPar) {
ATH_MSG_FATAL(
"Cannot read jet eta calib constants " << key );
return StatusCode::FAILURE; }
144 key=Form(
"EmaxJES.%s_Bin%d",
m_jetAlgo.Data(),ieta);
146 if (params.size()!=1) {
ATH_MSG_FATAL(
"Cannot read starting energy for the freezing of JES correction " << key );
return StatusCode::FAILURE; }
152 key=Form(
"MassCorr.%s_Bin%d",
m_jetAlgo.Data(),ieta);
154 if (params.size()!=
m_nPar) {
ATH_MSG_FATAL(
"Cannot read JMS calib constants " << key );
return StatusCode::FAILURE;}
160 TString absoluteJESCalibHists =
m_config->GetValue(
"AbsoluteJES.CalibHists",
"");
162 absoluteJESCalibHists.Remove(0,33);
163 absoluteJESCalibHists.Insert(0,
"JetCalibTools/");
173 ATH_MSG_ERROR(
"Only linear extrapolations are supported for p-splines currently. Please change the config file to reflect this");
174 return StatusCode::FAILURE;
178 for (
uint ieta=0;ieta<etaBins.size()-1;++ieta) {
189 if(Slope > Rcutoff/Ecutoff)
ATH_MSG_WARNING(
"Slope of calibration curve at minimum ET is too steep for the JES factors of etabin " << ieta <<
", eta = " << etaBins[ieta] );
199 return StatusCode::SUCCESS;
206 std::unique_ptr<TFile> tmpF(TFile::Open( fileName ));
207 TList *etajes_l =
static_cast<TList*
>( tmpF->Get(etajes_name.c_str()));
211 ATH_MSG_WARNING(
"Do not have the correct number of eta bins for " << fileName <<
"\t" << etajes_name <<
"\t" << etajes_l->GetSize() );
215 auto *pTH1 =
dynamic_cast<TH1*
>(etajes_l->At(i));
216 if (not pTH1)
continue;
228 jetStartP4 =
jet.jetP4();
232 float detectorEta =
jet.getAttribute<
float>(
"DetectorEta");
236 const double etaCorr = calibP4.eta() +
getEtaCorr( calibP4.e(), detectorEta );
239 else{ massCorr = jetStartP4.mass()*
getMassCorr(calibP4.e(), detectorEta); }
240 TLorentzVector TLVjet;
241 TLVjet.SetPtEtaPhiM( calibP4.P()/cosh(etaCorr),etaCorr,calibP4.phi(),massCorr );
242 calibP4.SetPxPyPzE( TLVjet.Px(), TLVjet.Py(), TLVjet.Pz(), TLVjet.E() );
245 float JESFactor = calibP4.e()/jetStartP4.e();
246 jet.setAttribute<
float>(
"JetJESCalibFactor",JESFactor);
251 jet.setJetP4( calibP4 );
253 return StatusCode::SUCCESS;
260 double E = E_uncorr/
m_GeV;
310 double R = slope*(E_uncorr-Ecutoff)+Rcutoff;
318 else ATH_MSG_WARNING(
"Incorrect specification of low Pt JES extrapolation, please check the value of the LowPtJESExtrapolationMethod config flag.");
329 double slope = (rSecond - rFirst) /
binWidth;
346 double E = E_corr/
m_GeV;
360 if (!
m_applyMassCorrection) {
ATH_MSG_FATAL(
"You can't apply the mass correction unless you specify ApplyMassCorrection: true in the configuration file!" );
return 0; }
364 double E = ( E_corr/cosh(eta_det)<5.0*
m_GeV ? 5.0*cosh(eta_det) : E_corr/
m_GeV );
373 y += factors[i]*TMath::Power(log(
x),Int_t(i));
379 const double inv_x = 1. /
x;
381 y += i*factors[i]*TMath::Power(log(
x),Int_t(i-1))*inv_x;
387 if (
bin<=0)
return 0;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Header file for AthHistogramAlgorithm.
double m_JESFactors[s_nEtaBins][s_nParMax]
virtual StatusCode calibrate(xAOD::Jet &jet, JetEventInfo &) const override
unsigned int m_lowPtExtrap
virtual StatusCode initialize() override
double getSplineSlope(const int ieta, const double minE) const
bool m_applyMassCorrection
static const unsigned int s_nEtaBins
double m_JES_MinPt_Slopes[s_nEtaBins]
double m_JES_MinPt_R[s_nEtaBins]
double m_JMSFactors[s_nEtaBins][s_nParMax]
double getLogPolNSlope(const double *factors, double x) const
double getJES(double E_uncorr, double eta_det) const
static const unsigned int s_nParMax
double m_energyFreezeJES[s_nEtaBins]
double getEtaCorr(double E_corr, double eta_det) const
double getLowPtJES(double E_uncorr, double eta_det) const
double m_JES_MinPt_Param1[s_nEtaBins]
void loadSplineHists(const TString &fileName, const std::string &etajes_name="etaJes")
Loads the calib constants from histograms in TFile named fileName.
bool m_useSecondaryminPt_JES
double getSplineCorr(const int etaBin, double E) const
double getMassCorr(double E_corr, double eta_det) const
std::vector< std::unique_ptr< TH1 > > m_etajesFactors
double m_etaCorrFactors[s_nEtaBins][s_nParMax]
virtual ~EtaJESCorrection()
double m_JES_MinPt_Param2[s_nEtaBins]
double m_etaSecondaryminPt_JES
int getEtaBin(double eta_det) const
double m_secondaryminPt_JES
double m_JES_MinPt_E[s_nEtaBins]
double getLogPolN(const double *factors, double x) const
std::string m_jetStartScale
virtual StatusCode setStartP4(xAOD::Jet &jet) const
JetCalibrationStep(const char *name="JetCalibrationStep")
VecD VectorizeD(const TString &str, const TString &sep=" ")
Jet_v1 Jet
Definition of the current "jet version".
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.