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);
97 if (status!=0) {
ATH_MSG_FATAL(
"Cannot read config file " << fn );
return StatusCode::FAILURE; }
100 if ( calibSeq.Contains(
"JetArea") ) {
104 else {
ATH_MSG_FATAL(
"jetAlgo " << jetAlgo <<
" not recognized.");
return StatusCode::FAILURE; }
112 std::string rhoKey_config =
m_globalConfig->GetValue(
"RhoKey",
"None");
114 bool requireRhoInput =
false;
117 if ( !calibSeq.Contains(
"JetArea") && !calibSeq.Contains(
"Residual") ) {
120 }
else if ( calibSeq.Contains(
"JetArea") ) {
121 if (
m_rhoKey.key().compare(
"auto") == 0 && rhoKey_config.compare(
"None") == 0) {
132 else if(rhoKey_config.compare(
"None") != 0 &&
m_rhoKey.key().compare(
"auto") == 0){
135 requireRhoInput =
true;
136 if ( !calibSeq.Contains(
"Residual") )
m_doResidual =
false;
137 }
else if ( !calibSeq.Contains(
"JetArea") && calibSeq.Contains(
"Residual") ) {
139 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.");
145 "HLT_xAOD__JetContainer_a4tcemsubjesISFS");
147 if ( !calibSeq.Contains(
"Origin") )
m_doOrigin =
false;
148 if ( !calibSeq.Contains(
"GSC") && !calibSeq.Contains(
"GNNC"))
m_doGSC =
false;
149 if ( !calibSeq.Contains(
"Bcid") )
m_doBcid =
false;
150 if ( calibSeq.Contains(
"DNN") )
m_doDNNCal =
true;
153 if ( calibSeq.Contains(
"Insitu") && !
m_isData ) {
154 ATH_MSG_FATAL(
"JetCalibrationTool::initialize : calibSeq string contains Insitu with isData set to false. Can't apply in-situ correction to MC!!");
155 return StatusCode::FAILURE;
173 TEnv *globalConfig_insitu =
new TEnv();
174 int status = globalConfig_insitu->ReadFile(fn_insitu ,EEnvLevel(0));
175 if (status!=0) {
ATH_MSG_FATAL(
"Cannot read config file " << fn_insitu );
return StatusCode::FAILURE; }
193 TEnv *globalInsituCombMass =
new TEnv();
194 int status = globalInsituCombMass->ReadFile(fn_comb ,EEnvLevel(0));
195 if (status!=0) {
ATH_MSG_FATAL(
"Cannot read config file " << fn_comb );
return StatusCode::FAILURE; }
203 for (
unsigned int i=0; i<vecCalibSeq.size(); ++i) {
204 if ( vecCalibSeq[i].EqualTo(
"Origin") || vecCalibSeq[i].EqualTo(
"DEV") )
continue;
205 if ( vecCalibSeq[i].EqualTo(
"Residual") &&
m_doJetArea )
continue;
218 ATH_MSG_ERROR(
"Residual calibration requested but no primary vertex container specified!");
219 return StatusCode::FAILURE;
222 if(
m_jetAlgo.find(
"PFlow")!=std::string::npos) {
223 ATH_MSG_ERROR(
"GSC calibration for PFlow requested but no primary vertex container specified!");
224 return StatusCode::FAILURE;
227 ATH_MSG_ERROR(
"GSC calibration with tracks requested but no primary vertex container specified!");
228 return StatusCode::FAILURE;
235 return StatusCode::SUCCESS;
244 TString generatorsInfo{};
245 TString simFlavour{};
247 TString mcCampaign{};
255 if (dataYear >= 2015 && dataYear <= 2018) {
257 }
else if (dataYear >= 2022 && dataYear <= 2024) {
260 ATH_MSG_VERBOSE(
"Data year " << dataYear <<
" not recognized from file metadata. The corresponding mcCampaign will not be known.");
264 std::string str_generatorsInfo;
266 generatorsInfo = str_generatorsInfo;
268 std::string str_simFlavour;
270 simFlavour = str_simFlavour;
274 std::string str_mcCampaign;
276 str_mcCampaign.resize(4);
277 mcCampaign = str_mcCampaign;
278 mcCampaign.ToUpper();
280 ATH_MSG_INFO(
"Have loaded metadata mcDSID:" << mcDSID <<
", generatorsInfo: " << generatorsInfo <<
", mcCampaign: " << mcCampaign <<
", simFlavour: " << simFlavour);
285 ATH_MSG_DEBUG(
"Some values in FileMetaData returned false for 'value()'.");
292 if ( calibration.EqualTo(
"Bcid") ){
293 m_globalConfig->SetValue(
"PileupStartingScale",
"JetBcidScaleMomentum");
294 std::unique_ptr<JetCalibrationStep> bcidCorr = std::make_unique<BcidOffsetCorrection>(this->name()+
"_Bcid",
m_globalConfig, jetAlgo, calibPath,
m_isData);
297 return StatusCode::SUCCESS;
299 else if ( calibration.EqualTo(
"JetArea") || calibration.EqualTo(
"Residual") ) {
300 std::unique_ptr<JetCalibrationStep> puCorr = std::make_unique<JetPileupCorrection>(this->name()+
"_Pileup",
m_globalConfig, jetAlgo, calibPath,
302 puCorr->msg().setLevel( this->
msg().level() );
305 return StatusCode::SUCCESS;
307 else if ( calibration.EqualTo(
"EtaJES") || calibration.EqualTo(
"AbsoluteEtaJES") ) {
308 std::unique_ptr<JetCalibrationStep> etaJESCorr = std::make_unique<EtaJESCorrection>(this->name()+
"_EtaJES",
m_globalConfig, jetAlgo, calibPath,
false,
m_devMode);
309 etaJESCorr->msg().setLevel( this->
msg().level() );
312 return StatusCode::SUCCESS;
314 else if ( calibration.EqualTo(
"EtaMassJES") ) {
315 std::unique_ptr<JetCalibrationStep> etaJESCorr = std::make_unique<EtaJESCorrection>(this->name()+
"_EtaMassJES",
m_globalConfig, jetAlgo, calibPath,
true,
m_devMode);
316 etaJESCorr->msg().setLevel( this->
msg().level() );
319 return StatusCode::SUCCESS;
321 else if ( calibration.EqualTo(
"GSC") ) {
323 gsc->msg().setLevel( this->
msg().level() );
328 TString actualCalibPath;
330 actualCalibPath =
"JetCalibTools/";
332 actualCalibPath =
"JetCalibTool/CalibArea-" +
m_calibAreaTag +
"/";
337 ATH_MSG_WARNING(
"JPS_FastSim.doCalibration is set in JetCalibrationTool config but isData is set to true. Will turn off FastSim calibration.");
342 ATH_MSG_FATAL(
"JPS_FastSim.doCalibration is set in JetCalibrationTool config but file has no FileMetaData. Please fix the sample or configuration.");
343 return StatusCode::FAILURE;
346 JPS_FastSim->msg().setLevel( this->
msg().level() );
353 JPS_PtResidual->msg().setLevel( this->
msg().level() );
357 return StatusCode::SUCCESS;
359 else if ( calibration.EqualTo(
"GNNC") ) {
360 std::unique_ptr<JetCalibrationStep> gnnc = std::make_unique<GlobalNNCalibration>(this->name()+
"_GNNC",
m_globalConfig,jetAlgo,calibPath,
m_devMode);
361 gnnc->msg().setLevel( this->
msg().level() );
364 return StatusCode::SUCCESS;
366 else if ( calibration.EqualTo(
"MC2MC") ) {
368 TString actualCalibPath;
370 actualCalibPath =
"JetCalibTools/";
372 actualCalibPath =
"JetCalibTool/CalibArea-" +
m_calibAreaTag +
"/";
375 ATH_MSG_FATAL(
"MC2MC step of jet calibration is requested but file has no FileMetaData. Please fix the sample or configuration.");
376 return StatusCode::FAILURE;
379 JPS_MC2MC->msg().setLevel( this->
msg().level() );
382 return StatusCode::SUCCESS;
384 else if ( calibration.EqualTo(
"JMS") ) {
385 std::unique_ptr<JetCalibrationStep> jetMassCorr = std::make_unique<JMSCorrection>(this->name()+
"_JMS",
m_globalConfig, jetAlgo, calibPath,
m_devMode);
386 jetMassCorr->msg().setLevel( this->
msg().level() );
389 return StatusCode::SUCCESS;
391 else if ( calibration.EqualTo(
"InsituCombinedMass") ){
393 std::unique_ptr<JetCalibrationStep> jetMassCorr = std::make_unique<JMSCorrection>(this->name()+
"_InsituCombinedMass",
m_globalInsituCombMassConfig.at(i), jetAlgo, calibPath,
m_devMode);
394 jetMassCorr->msg().setLevel( this->
msg().level() );
398 return StatusCode::SUCCESS;
400 else if ( calibration.EqualTo(
"Insitu") ) {
402 std::unique_ptr<JetCalibrationStep> insituDataCorr = std::make_unique<InsituDataCorrection>(this->name()+
"_Insitu",
m_globalConfig, jetAlgo, calibPath,
m_devMode);
403 insituDataCorr->msg().setLevel( this->
msg().level() );
406 return StatusCode::SUCCESS;
409 ATH_MSG_INFO(
"Initializing Time-Dependent Insitu Corrections");
412 unsigned int firstRun =
static_cast<unsigned int>(
m_runBins.at(i)+1.5);
413 unsigned int lastRun =
static_cast<unsigned int>(
m_runBins.at(i+1)+0.5);
414 std::unique_ptr<JetCalibrationStep> insituDataCorr = std::make_unique<InsituDataCorrection>(this->name()+
"_Insitu_"+std::to_string(i),
m_globalTimeDependentConfigs.at(i), jetAlgo,
415 calibPath,
m_devMode, firstRun, lastRun);
416 insituDataCorr->msg().setLevel( this->
msg().level() );
420 return StatusCode::SUCCESS;
423 else if ( calibration.EqualTo(
"Smear") ) {
425 ATH_MSG_FATAL(
"Asked for smearing of data, which is not supported. Aborting.");
426 return StatusCode::FAILURE;
428 std::unique_ptr<JetCalibrationStep> jetSmearCorr = std::make_unique<JetSmearingCorrection>(this->name()+
"_Smear",
m_globalConfig,jetAlgo,calibPath,
m_devMode);
429 jetSmearCorr->msg().setLevel(this->
msg().level());
433 return StatusCode::SUCCESS;
435 else if ( calibration.EqualTo(
"LargeRDNN") ) {
436 std::unique_ptr<JetCalibrationStep> largeR_dnn = std::make_unique<GlobalLargeRDNNCalibration>(this->name()+
"_R10DNN",
m_globalConfig,calibPath,
m_devMode);
437 largeR_dnn->msg().setLevel(this->
msg().level());
440 return StatusCode::SUCCESS;
442 ATH_MSG_FATAL(
"Calibration string not recognized: " << calibration <<
", aborting.");
443 return StatusCode::FAILURE;
462 ATH_MSG_FATAL(
" JetCalibrationTool::initializeEvent : The tool was not initialized.");
463 return StatusCode::FAILURE;
481 eventShape = rhRhoKey.
cptr();
484 ATH_MSG_FATAL(
"Could not retrieve the xAOD::EventShape container " <<
m_rhoKey.key() <<
" from the input file");
485 return StatusCode::FAILURE;
489 return StatusCode::FAILURE;
495 ATH_MSG_FATAL(
"Could not retrieve xAOD::EventShape container " <<
m_rhoKey.key() <<
" from the input file");
496 return StatusCode::FAILURE;
509 return StatusCode::FAILURE;
513 return StatusCode::FAILURE;
518 for (
const auto *
jet : *jets) {
529 static std::atomic<unsigned int> eventInfoWarnings = 0;
532 eventObj = rhEvtInfo.
cptr();
535 if ( eventInfoWarnings < 20 )
536 ATH_MSG_ERROR(
" JetCalibrationTool::initializeEvent : Failed to retrieve event information.");
537 jetEventInfo.
setMu(0);
539 return StatusCode::SUCCESS;
548 return StatusCode::FAILURE;
550 jetEventInfo.
setMu( eventInfoDecor(0) );
561 jetEventInfo.
setPVIndex( PVIndexAccessor(*eventObj) );
567 vertices = rhPV.
cptr();
570 for ( ; vtx_itr != vtx_end; ++vtx_itr ){
592 static const SG::ConstAccessor<int> BCIDGapBeforeTrainMinus12Acc (
"DFCommonJets_BCIDGapBeforeTrainMinus12");
610 vertices = rhPV.
cptr();
612 ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : Failed to retrieve primary vertices.");
614 return StatusCode::SUCCESS;
621 eventNPV = std::count_if(vertices->
begin(), vertices->
end(), [](
const xAOD::Vertex* vtx){ return vtx->vertexType() == xAOD::VxType::PileUp || vtx->vertexType() == xAOD::VxType::PriVtx;});
622 jetEventInfo.
setNPV(eventNPV);
628 static std::atomic<unsigned int> vertexIndexWarnings = 0;
629 if (jetEventInfo.
PVIndex() < 0 ||
static_cast<size_t>(jetEventInfo.
PVIndex()) >= vertices->
size())
631 ++vertexIndexWarnings;
632 if (vertexIndexWarnings < 20)
633 ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : PV index is out of bounds.");
635 return StatusCode::SUCCESS;
641 static std::atomic<unsigned int> eventInfoWarningsMu = 0;
645 jetEventInfo.
setMu(eventInfoDecor(0));
647 ++eventInfoWarningsMu;
648 if ( eventInfoWarningsMu < 20 )
ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : Failed to retrieve event information.");
649 jetEventInfo.
setMu(0);
652 static std::atomic<unsigned int> eventInfoWarningsPV = 0;
656 vertices = rhPV.
cptr();
658 eventNPV = std::count_if(vertices->
begin(), vertices->
end(), [](
const xAOD::Vertex* vtx){ return vtx->vertexType() == xAOD::VxType::PileUp || vtx->vertexType() == xAOD::VxType::PriVtx;});
659 jetEventInfo.
setNPV(eventNPV);
661 ++eventInfoWarningsPV;
662 if ( eventInfoWarningsPV < 20 )
ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : Failed to retrieve primary vertices.");
666 return StatusCode::SUCCESS;