68 std::string dir =
m_dir;
71 if ( jetAlgo.EqualTo(
"") || calibSeq.EqualTo(
"") ) {
72 ATH_MSG_FATAL(
"JetCalibrationTool::initialize : At least one of your constructor arguments is not set. Did you use the copy constructor?");
73 return StatusCode::FAILURE;
76 if (
m_config.empty() ) {
ATH_MSG_FATAL(
"No configuration file specified.");
return StatusCode::FAILURE; }
82 dir =
"JetCalibTools/";
84 else{dir.insert(14,calibPath);}
88 ATH_MSG_FATAL(
"Couldn't find ConfigFile " << configPath );
return StatusCode::FAILURE;
90 ATH_MSG_INFO(
"Reading global JES settings from: " << configPath);
96 if (status!=0) {
ATH_MSG_FATAL(
"Cannot read config file " << fn );
return StatusCode::FAILURE; }
99 if ( calibSeq.Contains(
"JetArea") ) {
103 else {
ATH_MSG_FATAL(
"jetAlgo " << jetAlgo <<
" not recognized.");
return StatusCode::FAILURE; }
111 std::string rhoKey_config =
m_globalConfig->GetValue(
"RhoKey",
"None");
113 bool requireRhoInput =
false;
116 if ( !calibSeq.Contains(
"JetArea") && !calibSeq.Contains(
"Residual") ) {
119 }
else if ( calibSeq.Contains(
"JetArea") ) {
120 if (
m_rhoKey.key().compare(
"auto") == 0 && rhoKey_config.compare(
"None") == 0) {
131 else if(rhoKey_config.compare(
"None") != 0 &&
m_rhoKey.key().compare(
"auto") == 0){
134 requireRhoInput =
true;
135 if ( !calibSeq.Contains(
"Residual") )
m_doResidual =
false;
136 }
else if ( !calibSeq.Contains(
"JetArea") && calibSeq.Contains(
"Residual") ) {
138 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.");
144 "HLT_xAOD__JetContainer_a4tcemsubjesISFS");
146 if ( !calibSeq.Contains(
"Origin") )
m_doOrigin =
false;
147 if ( !calibSeq.Contains(
"GSC") && !calibSeq.Contains(
"GNNC"))
m_doGSC =
false;
148 if ( !calibSeq.Contains(
"Bcid") )
m_doBcid =
false;
149 if ( calibSeq.Contains(
"DNN") )
m_doDNNCal =
true;
152 if ( calibSeq.Contains(
"Insitu") && !
m_isData ) {
153 ATH_MSG_FATAL(
"JetCalibrationTool::initialize : calibSeq string contains Insitu with isData set to false. Can't apply in-situ correction to MC!!");
154 return StatusCode::FAILURE;
172 TEnv *globalConfig_insitu =
new TEnv();
173 int status = globalConfig_insitu->ReadFile(fn_insitu ,EEnvLevel(0));
174 if (status!=0) {
ATH_MSG_FATAL(
"Cannot read config file " << fn_insitu );
return StatusCode::FAILURE; }
192 TEnv *globalInsituCombMass =
new TEnv();
193 int status = globalInsituCombMass->ReadFile(fn_comb ,EEnvLevel(0));
194 if (status!=0) {
ATH_MSG_FATAL(
"Cannot read config file " << fn_comb );
return StatusCode::FAILURE; }
202 for (
unsigned int i=0; i<vecCalibSeq.size(); ++i) {
203 if ( vecCalibSeq[i].EqualTo(
"Origin") || vecCalibSeq[i].EqualTo(
"DEV") )
continue;
204 if ( vecCalibSeq[i].EqualTo(
"Residual") &&
m_doJetArea )
continue;
217 ATH_MSG_ERROR(
"Residual calibration requested but no primary vertex container specified!");
218 return StatusCode::FAILURE;
221 if(
m_jetAlgo.find(
"PFlow")!=std::string::npos) {
222 ATH_MSG_ERROR(
"GSC calibration for PFlow requested but no primary vertex container specified!");
223 return StatusCode::FAILURE;
226 ATH_MSG_ERROR(
"GSC calibration with tracks requested but no primary vertex container specified!");
227 return StatusCode::FAILURE;
234 return StatusCode::SUCCESS;
243 TString generatorsInfo{};
244 TString simFlavour{};
246 TString mcCampaign{};
254 if (dataYear >= 2015 && dataYear <= 2018) {
256 }
else if (dataYear >= 2022 && dataYear <= 2024) {
259 ATH_MSG_WARNING(
"Data year " << dataYear <<
" not recognized from file metadata. The corresponding mcCampaign will not be known.");
263 std::string str_generatorsInfo;
265 generatorsInfo = str_generatorsInfo;
267 std::string str_simFlavour;
269 simFlavour = str_simFlavour;
273 std::string str_mcCampaign;
275 str_mcCampaign.resize(4);
276 mcCampaign = str_mcCampaign;
277 mcCampaign.ToUpper();
279 ATH_MSG_INFO(
"Have loaded metadata mcDSID:" << mcDSID <<
", generatorsInfo: " << generatorsInfo <<
", mcCampaign: " << mcCampaign <<
", simFlavour: " << simFlavour);
287 if ( calibration.EqualTo(
"Bcid") ){
288 m_globalConfig->SetValue(
"PileupStartingScale",
"JetBcidScaleMomentum");
289 std::unique_ptr<JetCalibrationStep> bcidCorr = std::make_unique<BcidOffsetCorrection>(this->name()+
"_Bcid",
m_globalConfig, jetAlgo, calibPath,
m_isData);
292 return StatusCode::SUCCESS;
294 else if ( calibration.EqualTo(
"JetArea") || calibration.EqualTo(
"Residual") ) {
295 std::unique_ptr<JetCalibrationStep> puCorr = std::make_unique<JetPileupCorrection>(this->name()+
"_Pileup",
m_globalConfig, jetAlgo, calibPath,
297 puCorr->msg().setLevel( this->
msg().level() );
300 return StatusCode::SUCCESS;
302 else if ( calibration.EqualTo(
"EtaJES") || calibration.EqualTo(
"AbsoluteEtaJES") ) {
303 std::unique_ptr<JetCalibrationStep> etaJESCorr = std::make_unique<EtaJESCorrection>(this->name()+
"_EtaJES",
m_globalConfig, jetAlgo, calibPath,
false,
m_devMode);
304 etaJESCorr->msg().setLevel( this->
msg().level() );
307 return StatusCode::SUCCESS;
309 else if ( calibration.EqualTo(
"EtaMassJES") ) {
310 std::unique_ptr<JetCalibrationStep> etaJESCorr = std::make_unique<EtaJESCorrection>(this->name()+
"_EtaMassJES",
m_globalConfig, jetAlgo, calibPath,
true,
m_devMode);
311 etaJESCorr->msg().setLevel( this->
msg().level() );
314 return StatusCode::SUCCESS;
316 else if ( calibration.EqualTo(
"GSC") ) {
318 gsc->msg().setLevel( this->
msg().level() );
323 TString actualCalibPath;
325 actualCalibPath =
"JetCalibTools/";
327 actualCalibPath =
"JetCalibTool/CalibArea-" +
m_calibAreaTag +
"/";
332 ATH_MSG_WARNING(
"JPS_FastSim.doCalibration is set in JetCalibrationTool config but isData is set to true. Will turn off FastSim calibration.");
337 ATH_MSG_FATAL(
"JPS_FastSim.doCalibration is set in JetCalibrationTool config but file has no FileMetaData. Please fix the sample or configuration.");
338 return StatusCode::FAILURE;
341 JPS_FastSim->msg().setLevel( this->
msg().level() );
348 JPS_PtResidual->msg().setLevel( this->
msg().level() );
352 return StatusCode::SUCCESS;
354 else if ( calibration.EqualTo(
"GNNC") ) {
355 std::unique_ptr<JetCalibrationStep> gnnc = std::make_unique<GlobalNNCalibration>(this->name()+
"_GNNC",
m_globalConfig,jetAlgo,calibPath,
m_devMode);
356 gnnc->msg().setLevel( this->
msg().level() );
359 return StatusCode::SUCCESS;
361 else if ( calibration.EqualTo(
"MC2MC") ) {
363 TString actualCalibPath;
365 actualCalibPath =
"JetCalibTools/";
367 actualCalibPath =
"JetCalibTool/CalibArea-" +
m_calibAreaTag +
"/";
370 ATH_MSG_FATAL(
"MC2MC step of jet calibration is requested but file has no FileMetaData. Please fix the sample or configuration.");
371 return StatusCode::FAILURE;
374 JPS_MC2MC->msg().setLevel( this->
msg().level() );
377 return StatusCode::SUCCESS;
379 else if ( calibration.EqualTo(
"JMS") ) {
380 std::unique_ptr<JetCalibrationStep> jetMassCorr = std::make_unique<JMSCorrection>(this->name()+
"_JMS",
m_globalConfig, jetAlgo, calibPath,
m_devMode);
381 jetMassCorr->msg().setLevel( this->
msg().level() );
384 return StatusCode::SUCCESS;
386 else if ( calibration.EqualTo(
"InsituCombinedMass") ){
388 std::unique_ptr<JetCalibrationStep> jetMassCorr = std::make_unique<JMSCorrection>(this->name()+
"_InsituCombinedMass",
m_globalInsituCombMassConfig.at(i), jetAlgo, calibPath,
m_devMode);
389 jetMassCorr->msg().setLevel( this->
msg().level() );
393 return StatusCode::SUCCESS;
395 else if ( calibration.EqualTo(
"Insitu") ) {
397 std::unique_ptr<JetCalibrationStep> insituDataCorr = std::make_unique<InsituDataCorrection>(this->name()+
"_Insitu",
m_globalConfig, jetAlgo, calibPath,
m_devMode);
398 insituDataCorr->msg().setLevel( this->
msg().level() );
401 return StatusCode::SUCCESS;
404 ATH_MSG_INFO(
"Initializing Time-Dependent Insitu Corrections");
407 unsigned int firstRun =
static_cast<unsigned int>(
m_runBins.at(i)+1.5);
408 unsigned int lastRun =
static_cast<unsigned int>(
m_runBins.at(i+1)+0.5);
409 std::unique_ptr<JetCalibrationStep> insituDataCorr = std::make_unique<InsituDataCorrection>(this->name()+
"_Insitu_"+std::to_string(i),
m_globalTimeDependentConfigs.at(i), jetAlgo,
410 calibPath,
m_devMode, firstRun, lastRun);
411 insituDataCorr->msg().setLevel( this->
msg().level() );
415 return StatusCode::SUCCESS;
418 else if ( calibration.EqualTo(
"Smear") ) {
420 ATH_MSG_FATAL(
"Asked for smearing of data, which is not supported. Aborting.");
421 return StatusCode::FAILURE;
423 std::unique_ptr<JetCalibrationStep> jetSmearCorr = std::make_unique<JetSmearingCorrection>(this->name()+
"_Smear",
m_globalConfig,jetAlgo,calibPath,
m_devMode);
424 jetSmearCorr->msg().setLevel(this->
msg().level());
428 return StatusCode::SUCCESS;
430 else if ( calibration.EqualTo(
"LargeRDNN") ) {
431 std::unique_ptr<JetCalibrationStep> largeR_dnn = std::make_unique<GlobalLargeRDNNCalibration>(this->name()+
"_R10DNN",
m_globalConfig,calibPath,
m_devMode);
432 largeR_dnn->msg().setLevel(this->
msg().level());
435 return StatusCode::SUCCESS;
437 ATH_MSG_FATAL(
"Calibration string not recognized: " << calibration <<
", aborting.");
438 return StatusCode::FAILURE;
457 ATH_MSG_FATAL(
" JetCalibrationTool::initializeEvent : The tool was not initialized.");
458 return StatusCode::FAILURE;
476 eventShape = rhRhoKey.
cptr();
479 ATH_MSG_FATAL(
"Could not retrieve the xAOD::EventShape container " <<
m_rhoKey.key() <<
" from the input file");
480 return StatusCode::FAILURE;
484 return StatusCode::FAILURE;
490 ATH_MSG_FATAL(
"Could not retrieve xAOD::EventShape container " <<
m_rhoKey.key() <<
" from the input file");
491 return StatusCode::FAILURE;
504 return StatusCode::FAILURE;
508 return StatusCode::FAILURE;
513 for (
const auto *
jet : *jets) {
524 static std::atomic<unsigned int> eventInfoWarnings = 0;
527 eventObj = rhEvtInfo.
cptr();
530 if ( eventInfoWarnings < 20 )
531 ATH_MSG_ERROR(
" JetCalibrationTool::initializeEvent : Failed to retrieve event information.");
532 jetEventInfo.
setMu(0);
534 return StatusCode::SUCCESS;
543 return StatusCode::FAILURE;
545 jetEventInfo.
setMu( eventInfoDecor(0) );
556 jetEventInfo.
setPVIndex( PVIndexAccessor(*eventObj) );
562 vertices = rhPV.
cptr();
565 for ( ; vtx_itr != vtx_end; ++vtx_itr ){
587 static const SG::ConstAccessor<int> BCIDGapBeforeTrainMinus12Acc (
"DFCommonJets_BCIDGapBeforeTrainMinus12");
605 vertices = rhPV.
cptr();
607 ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : Failed to retrieve primary vertices.");
609 return StatusCode::SUCCESS;
616 eventNPV = std::count_if(vertices->
begin(), vertices->
end(), [](
const xAOD::Vertex* vtx){ return vtx->vertexType() == xAOD::VxType::PileUp || vtx->vertexType() == xAOD::VxType::PriVtx;});
617 jetEventInfo.
setNPV(eventNPV);
623 static std::atomic<unsigned int> vertexIndexWarnings = 0;
624 if (jetEventInfo.
PVIndex() < 0 ||
static_cast<size_t>(jetEventInfo.
PVIndex()) >= vertices->
size())
626 ++vertexIndexWarnings;
627 if (vertexIndexWarnings < 20)
628 ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : PV index is out of bounds.");
630 return StatusCode::SUCCESS;
636 static std::atomic<unsigned int> eventInfoWarningsMu = 0;
640 jetEventInfo.
setMu(eventInfoDecor(0));
642 ++eventInfoWarningsMu;
643 if ( eventInfoWarningsMu < 20 )
ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : Failed to retrieve event information.");
644 jetEventInfo.
setMu(0);
647 static std::atomic<unsigned int> eventInfoWarningsPV = 0;
651 vertices = rhPV.
cptr();
653 eventNPV = std::count_if(vertices->
begin(), vertices->
end(), [](
const xAOD::Vertex* vtx){ return vtx->vertexType() == xAOD::VxType::PileUp || vtx->vertexType() == xAOD::VxType::PriVtx;});
654 jetEventInfo.
setNPV(eventNPV);
656 ++eventInfoWarningsPV;
657 if ( eventInfoWarningsPV < 20 )
ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : Failed to retrieve primary vertices.");
661 return StatusCode::SUCCESS;