29 m_jetAlgo(
""), m_config(
""), m_calibSeq(
""), m_calibAreaTag(
""), m_originScale(
""), m_devMode(false),
30 m_isData(true), m_timeDependentCalib(false),
m_dir(
""), m_eInfoName(
""), m_globalConfig(nullptr),
31 m_doBcid(true), m_doJetArea(true), m_doResidual(true), m_doOrigin(true), m_doGSC(true), m_doDNNCal(false), m_gscDepth(
"auto"), m_smearIndex(-1), m_useOriginVertex(false)
65 if ( jetAlgo.EqualTo(
"") || calibSeq.EqualTo(
"") ) {
66 ATH_MSG_FATAL(
"JetCalibrationTool::initialize : At least one of your constructor arguments is not set. Did you use the copy constructor?");
67 return StatusCode::FAILURE;
70 if (
m_config.empty() ) {
ATH_MSG_FATAL(
"No configuration file specified.");
return StatusCode::FAILURE; }
76 dir =
"JetCalibTools/";
78 else{
dir.insert(14,calibPath);}
90 if ( calibSeq.Contains(
"JetArea") ) {
94 else {
ATH_MSG_FATAL(
"jetAlgo " << jetAlgo <<
" not recognized.");
return StatusCode::FAILURE; }
102 std::string rhoKey_config =
m_globalConfig->GetValue(
"RhoKey",
"None");
104 bool requireRhoInput =
false;
107 if ( !calibSeq.Contains(
"JetArea") && !calibSeq.Contains(
"Residual") ) {
110 }
else if ( calibSeq.Contains(
"JetArea") ) {
111 if (
m_rhoKey.key().compare(
"auto") == 0 && rhoKey_config.compare(
"None") == 0) {
122 else if(rhoKey_config.compare(
"None") != 0 &&
m_rhoKey.key().compare(
"auto") == 0){
125 requireRhoInput =
true;
126 if ( !calibSeq.Contains(
"Residual") )
m_doResidual =
false;
127 }
else if ( !calibSeq.Contains(
"JetArea") && calibSeq.Contains(
"Residual") ) {
129 ATH_MSG_INFO(
"ApplyOnlyResidual should be true if only Residual pile up correction wants to be applied. Need to specify pile up starting scale in the configuration file.");
135 "HLT_xAOD__JetContainer_a4tcemsubjesISFS");
137 if ( !calibSeq.Contains(
"Origin") )
m_doOrigin =
false;
138 if ( !calibSeq.Contains(
"GSC") && !calibSeq.Contains(
"GNNC"))
m_doGSC =
false;
139 if ( !calibSeq.Contains(
"Bcid") )
m_doBcid =
false;
140 if ( calibSeq.Contains(
"DNN") )
m_doDNNCal =
true;
143 if ( calibSeq.Contains(
"Insitu") && !
m_isData ) {
144 ATH_MSG_FATAL(
"JetCalibrationTool::initialize : calibSeq string contains Insitu with isData set to false. Can't apply in-situ correction to MC!!");
145 return StatusCode::FAILURE;
163 TEnv *globalConfig_insitu =
new TEnv();
164 int status = globalConfig_insitu->ReadFile(fn_insitu ,EEnvLevel(0));
165 if (
status!=0) {
ATH_MSG_FATAL(
"Cannot read config file " << fn_insitu );
return StatusCode::FAILURE; }
183 TEnv *globalInsituCombMass =
new TEnv();
184 int status = globalInsituCombMass->ReadFile(fn_comb ,EEnvLevel(0));
185 if (
status!=0) {
ATH_MSG_FATAL(
"Cannot read config file " << fn_comb );
return StatusCode::FAILURE; }
193 for (
unsigned int i=0;
i<vecCalibSeq.size(); ++
i) {
194 if ( vecCalibSeq[
i].EqualTo(
"Origin") || vecCalibSeq[
i].EqualTo(
"DEV") )
continue;
195 if ( vecCalibSeq[
i].EqualTo(
"Residual") &&
m_doJetArea )
continue;
208 ATH_MSG_ERROR(
"Residual calibration requested but no primary vertex container specified!");
209 return StatusCode::FAILURE;
212 if(
m_jetAlgo.find(
"PFlow")!=std::string::npos) {
213 ATH_MSG_ERROR(
"GSC calibration for PFlow requested but no primary vertex container specified!");
214 return StatusCode::FAILURE;
217 ATH_MSG_ERROR(
"GSC calibration with tracks requested but no primary vertex container specified!");
218 return StatusCode::FAILURE;
226 return StatusCode::SUCCESS;
233 if ( calibration.EqualTo(
"Bcid") ){
234 m_globalConfig->SetValue(
"PileupStartingScale",
"JetBcidScaleMomentum");
235 std::unique_ptr<JetCalibrationStep> bcidCorr = std::make_unique<BcidOffsetCorrection>(this->
name()+
"_Bcid",
m_globalConfig, jetAlgo, calibPath,
m_isData);
238 return StatusCode::SUCCESS;
240 else if ( calibration.EqualTo(
"JetArea") || calibration.EqualTo(
"Residual") ) {
241 std::unique_ptr<JetCalibrationStep> puCorr = std::make_unique<JetPileupCorrection>(this->
name()+
"_Pileup",
m_globalConfig, jetAlgo, calibPath,
246 return StatusCode::SUCCESS;
248 else if ( calibration.EqualTo(
"EtaJES") || calibration.EqualTo(
"AbsoluteEtaJES") ) {
249 std::unique_ptr<JetCalibrationStep> etaJESCorr = std::make_unique<EtaJESCorrection>(this->
name()+
"_EtaJES",
m_globalConfig, jetAlgo, calibPath,
false,
m_devMode);
253 return StatusCode::SUCCESS;
255 else if ( calibration.EqualTo(
"EtaMassJES") ) {
256 std::unique_ptr<JetCalibrationStep> etaJESCorr = std::make_unique<EtaJESCorrection>(this->
name()+
"_EtaMassJES",
m_globalConfig, jetAlgo, calibPath,
true,
m_devMode);
260 return StatusCode::SUCCESS;
262 else if ( calibration.EqualTo(
"GSC") ) {
267 return StatusCode::SUCCESS;
269 else if ( calibration.EqualTo(
"GNNC") ) {
270 std::unique_ptr<JetCalibrationStep> gnnc = std::make_unique<GlobalNNCalibration>(this->
name()+
"_GNNC",
m_globalConfig,jetAlgo,calibPath,
m_devMode);
274 return StatusCode::SUCCESS;
276 else if ( calibration.EqualTo(
"JMS") ) {
277 std::unique_ptr<JetCalibrationStep> jetMassCorr = std::make_unique<JMSCorrection>(this->
name()+
"_JMS",
m_globalConfig, jetAlgo, calibPath,
m_devMode);
278 jetMassCorr->
msg().setLevel( this->
msg().
level() );
281 return StatusCode::SUCCESS;
283 else if ( calibration.EqualTo(
"InsituCombinedMass") ){
286 jetMassCorr->
msg().setLevel( this->
msg().
level() );
290 return StatusCode::SUCCESS;
292 else if ( calibration.EqualTo(
"Insitu") ) {
294 std::unique_ptr<JetCalibrationStep> insituDataCorr = std::make_unique<InsituDataCorrection>(this->
name()+
"_Insitu",
m_globalConfig, jetAlgo, calibPath,
m_devMode);
295 insituDataCorr->
msg().setLevel( this->
msg().
level() );
298 return StatusCode::SUCCESS;
301 ATH_MSG_INFO(
"Initializing Time-Dependent Insitu Corrections");
304 unsigned int firstRun =
static_cast<unsigned int>(
m_runBins.at(
i)+1.5);
308 insituDataCorr->
msg().setLevel( this->
msg().
level() );
312 return StatusCode::SUCCESS;
315 else if ( calibration.EqualTo(
"Smear") ) {
317 ATH_MSG_FATAL(
"Asked for smearing of data, which is not supported. Aborting.");
318 return StatusCode::FAILURE;
320 std::unique_ptr<JetCalibrationStep> jetSmearCorr = std::make_unique<JetSmearingCorrection>(this->
name()+
"_Smear",
m_globalConfig,jetAlgo,calibPath,
m_devMode);
325 return StatusCode::SUCCESS;
327 else if ( calibration.EqualTo(
"LargeRDNN") ) {
328 std::unique_ptr<JetCalibrationStep> largeR_dnn = std::make_unique<GlobalLargeRDNNCalibration>(this->
name()+
"_R10DNN",
m_globalConfig,calibPath,
m_devMode);
332 return StatusCode::SUCCESS;
334 ATH_MSG_FATAL(
"Calibration string not recognized: " << calibration <<
", aborting.");
335 return StatusCode::FAILURE;
344 return StatusCode::SUCCESS;
354 ATH_MSG_FATAL(
" JetCalibrationTool::initializeEvent : The tool was not initialized.");
355 return StatusCode::FAILURE;
373 eventShape = rhRhoKey.
cptr();
376 ATH_MSG_FATAL(
"Could not retrieve the xAOD::EventShape container " <<
m_rhoKey.key() <<
" from the input file");
377 return StatusCode::FAILURE;
381 return StatusCode::FAILURE;
387 ATH_MSG_FATAL(
"Could not retrieve xAOD::EventShape container " <<
m_rhoKey.key() <<
" from the input file");
388 return StatusCode::FAILURE;
401 return StatusCode::FAILURE;
405 return StatusCode::FAILURE;
410 for (
const auto *
jet : *
jets) {
421 static std::atomic<unsigned int> eventInfoWarnings = 0;
424 eventObj = rhEvtInfo.
cptr();
427 if ( eventInfoWarnings < 20 )
428 ATH_MSG_ERROR(
" JetCalibrationTool::initializeEvent : Failed to retrieve event information.");
429 jetEventInfo.
setMu(0);
431 return StatusCode::SUCCESS;
440 return StatusCode::FAILURE;
442 jetEventInfo.
setMu( eventInfoDecor(0) );
453 jetEventInfo.
setPVIndex( PVIndexAccessor(*eventObj) );
459 vertices = rhPV.
cptr();
462 for ( ; vtx_itr != vtx_end; ++vtx_itr ){
484 static const SG::ConstAccessor<int> BCIDGapBeforeTrainMinus12Acc (
"DFCommonJets_BCIDGapBeforeTrainMinus12");
502 vertices = rhPV.
cptr();
504 ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : Failed to retrieve primary vertices.");
506 return StatusCode::SUCCESS;
513 eventNPV = std::count_if(vertices->
begin(), vertices->
end(), [](
const xAOD::Vertex* vtx){ return vtx->vertexType() == xAOD::VxType::PileUp || vtx->vertexType() == xAOD::VxType::PriVtx;});
514 jetEventInfo.
setNPV(eventNPV);
520 static std::atomic<unsigned int> vertexIndexWarnings = 0;
521 if (jetEventInfo.
PVIndex() < 0 ||
static_cast<size_t>(jetEventInfo.
PVIndex()) >= vertices->
size())
523 ++vertexIndexWarnings;
524 if (vertexIndexWarnings < 20)
525 ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : PV index is out of bounds.");
527 return StatusCode::SUCCESS;
533 static std::atomic<unsigned int> eventInfoWarningsMu = 0;
537 jetEventInfo.
setMu(eventInfoDecor(0));
539 ++eventInfoWarningsMu;
540 if ( eventInfoWarningsMu < 20 )
ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : Failed to retrieve event information.");
541 jetEventInfo.
setMu(0);
544 static std::atomic<unsigned int> eventInfoWarningsPV = 0;
548 vertices = rhPV.
cptr();
550 eventNPV = std::count_if(vertices->
begin(), vertices->
end(), [](
const xAOD::Vertex* vtx){ return vtx->vertexType() == xAOD::VxType::PileUp || vtx->vertexType() == xAOD::VxType::PriVtx;});
551 jetEventInfo.
setNPV(eventNPV);
553 ++eventInfoWarningsPV;
554 if ( eventInfoWarningsPV < 20 )
ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : Failed to retrieve primary vertices.");
558 return StatusCode::SUCCESS;
565 if ( !
jet.getAttribute<
int>(
"OriginCorrected",
tmp) )
566 jet.setAttribute<
int>(
"OriginCorrected",
false);
567 if ( !
jet.getAttribute<
int>(
"PileupCorrected",
tmp) )
568 jet.setAttribute<
int>(
"PileupCorrected",
false);
573 jet.setAttribute<
float>(
"DetectorEta",jetconstitP4.eta());
578 return StatusCode::SUCCESS;
585 ATH_MSG_ERROR(
"Cannot retrieve the nominal data resolution - smearing was not configured during initialization");
586 return StatusCode::FAILURE;
594 ATH_MSG_ERROR(
"Cannot retrieve the nominal MC resolution - smearing was not configured during initialization");
595 return StatusCode::FAILURE;