19 m_config(nullptr), m_jetAlgo(
""), m_calibAreaTag(
""), m_dev(false), m_doResidual(false),
20 m_doJetArea(false), m_doOrigin(false), m_isData(false),
21 m_useFull4vectorArea(false), m_residualOffsetCorr(nullptr), m_originScale(
"JetOriginConstitScaleMomentum")
25 bool doResidual,
bool doJetArea,
bool doOrigin,
const std::string& originScale,
26 bool isData,
bool dev)
28 m_config(
config), m_jetAlgo(std::move(jetAlgo)), m_calibAreaTag(std::move(calibAreaTag)), m_dev(dev),
29 m_doResidual(doResidual), m_doJetArea(doJetArea), m_doOrigin(doOrigin), m_isData(isData),
30 m_useFull4vectorArea(false), m_residualOffsetCorr(nullptr), m_originScale(originScale)
47 ATH_MSG_ERROR(
"Jet pileup correction tool received a null config pointer.");
48 return StatusCode::FAILURE;
53 ATH_MSG_FATAL(
"If you're trying to apply only the Residual pile up correction, it needs to be specify in the Calibration Sequence. ApplyOnlyResidual should be true in the configuration file and the PileupStartScale should be specified.");
54 return StatusCode::FAILURE;
61 bool useNjet =
m_config->GetValue(
"OffsetCorrection.UseNjet",
false);
66 else ATH_MSG_DEBUG(
"The pileup residual calibrations will be applied simultaneously (default).");
70 else if (useNjet)
ATH_MSG_DEBUG(
"NJet will be used instead of NPV in the pileup corrections.");
74 ATH_MSG_FATAL(
"Sequential residual calibration can not be applied in doMuOnly or doNPVOnly or doNJetOnly cases.");
75 return StatusCode::FAILURE;
78 ATH_MSG_FATAL(
"Conflicting configuation, UseNjet true but doMuOnly or doNPVOnly also true.");
79 return StatusCode::FAILURE;
82 ATH_MSG_FATAL(
"It was requested to apply only the mu-based AND the NPV-based calibrations.");
83 return StatusCode::FAILURE;
86 ATH_MSG_FATAL(
"It was requested to apply only the mu-based AND the NJet-based calibrations.");
87 return StatusCode::FAILURE;
90 ATH_MSG_FATAL(
"It was requested to apply only the NJet-based calibration but not to use Njet instead of NPV.");
91 return StatusCode::FAILURE;
94 ATH_MSG_FATAL(
"It was requested to apply NJet-based and NPV calibrations.");
95 return StatusCode::FAILURE;
99 ATH_MSG_FATAL(
"3D correction incompatible with any other PU correction. Please turn off any PU residual options.");
100 return StatusCode::FAILURE;
107 ATH_MSG_WARNING(
"Configuration file does not specify the jet starting scale!");
116 m_residual3DCorr = std::make_unique<PUCorrection::PU3DCorrectionHelper>( ) ;
118 TString PUCalibFile3D =
m_config->GetValue(
"PU3DCorrection.constants",
"pu3DResidualsConstants.root");
123 PUCalibFile3D.Remove(0,33);
124 PUCalibFile3D.Insert(0,
"JetCalibTools/");
136 ATH_MSG_INFO(
"Pile-up 3D correction. Configured with :");
137 ATH_MSG_INFO(
" calib constants file="<<
m_config->GetValue(
"PU3DCorrection.constants",
"pu3DResidualsConstants.root") );
142 std::string
suffix =
"_Residual";
149 ATH_MSG_WARNING(
"JetPileupCorrection::initializeTool : WARNING!! You have requested the 4 vector jet area correction and the residual offset correction. This configuration is not currently supported, the residual offset correction will be deactivated.");
150 return StatusCode::SUCCESS;
152 ATH_MSG_VERBOSE(
"JetPileupCorrection::initializeTool : You have requested the transverse jet area correction without the residual offset correction. This configuration is not recommended.");
153 return StatusCode::SUCCESS;
155 return StatusCode::SUCCESS;
157 return StatusCode::FAILURE;
166 jetStartP4 =
jet.jetP4();
168 const double E_det = jetStartP4.e();
169 const double pT_det = jetStartP4.pt();
170 const double eta_det = jetStartP4.eta();
171 const double mass_det = jetStartP4.mass();
173 if ( E_det < mass_det ) {
174 ATH_MSG_WARNING(
"JetPileupCorrection::calibrateImpl : Current jet has mass=" << mass_det/
m_GeV <<
" GeV, which is greater than it's energy=" << E_det/
m_GeV <<
" GeV?? Aborting." );
175 return StatusCode::FAILURE;
180 const double rho = jetEventInfo.
rho();
184 int NPV = jetEventInfo.
NPV();
185 float mu = jetEventInfo.
mu();
188 double scaleF = pt_calib < 0 ? 0.01*
m_GeV/pT_det : pt_calib/pT_det;
190 jet.setAttribute<
int>(
"PileupCorrected",
true);
192 jet.setJetP4( calibP4 );
195 ATH_MSG_VERBOSE(
" Applying area-subtraction calibration to jet " <<
jet.index() <<
" with pT = " << 0.001*
jet.pt() <<
" GeV");
199 jet.setAttribute<
int>(
"PileupCorrected",
true);
202 jet.setJetP4( calibP4 );
205 ATH_MSG_VERBOSE(
" Applying residual pileup calibration to jet " <<
jet.index() <<
" with pT = " << 0.001*
jet.pt() <<
" GeV");
207 const double NPV = jetEventInfo.
NPV();
208 const double mu = jetEventInfo.
mu();
209 const int nJet = jetEventInfo.
nJet();
213 double pT_offset = pT_det;
214 double pileup_SF = 1;
221 pT_offset =
m_doJetArea ? pT_det -
rho*jetareaP4.pt() - offsetET : pT_det - offsetET;
224 pileup_SF = pT_offset >= 0 ? pT_offset / pT_det : 0.01*
m_GeV/pT_det;
228 static std::atomic<unsigned int> originWarnings = 0;
230 calibP4 = jetOriginP4*pileup_SF;
232 if ( originWarnings < 20 ) {
236 calibP4 = jetStartP4*pileup_SF;
239 calibP4 = jetStartP4*pileup_SF;
245 pT_offset =
m_doJetArea ? pT_det -
rho*jetareaP4.pt() - offsetET : pT_det - offsetET;
246 double muSF = pT_offset >= 0 ? pT_offset / pT_det : 0.01*
m_GeV/pT_det;
251 static std::atomic<unsigned int> originWarnings = 0;
253 calibP4 = jetOriginP4*muSF;
255 if ( originWarnings < 20 ) {
259 calibP4 = jetStartP4*muSF;
262 calibP4 = jetStartP4*muSF;
267 double pT_afterMuCalib = calibP4.pt();
268 pT_offset = pT_afterMuCalib - offsetET;
269 double SF = pT_offset >= 0 ? pT_offset / pT_afterMuCalib : 0.01*
m_GeV/pT_afterMuCalib;
270 calibP4 = calibP4*
SF;
277 jet.setAttribute<
int>(
"PileupCorrected",
true);
281 jet.setJetP4( calibP4 );
284 ATH_MSG_VERBOSE(
" Applying postive-only area-subtraction calibration to jet " <<
jet.index() <<
" with pT = " << 0.001*
jet.pt() <<
" GeV");
286 const double area_SF = (pT_det-
rho*jetareaP4.pt()<=0 || E_det-
rho*jetareaP4.e()<=0) ? 10/pT_det : (pT_det-
rho*jetareaP4.pt())/pT_det;
290 static std::atomic<unsigned int> originWarnings = 0;
292 calibP4 = jetOriginP4*area_SF;
294 if ( originWarnings < 20 ) {
298 calibP4 = jetStartP4*area_SF;
300 }
else calibP4 = jetStartP4*area_SF;
305 jet.setAttribute<
int>(
"PileupCorrected",
true);
309 jet.setJetP4( calibP4 );
313 return StatusCode::SUCCESS;