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();
279 ATH_MSG_INFO(
"Have loaded metadata mcDSID:" << mcDSID <<
", generatorsInfo: " << generatorsInfo <<
", mcCampaign: " << mcCampaign <<
", simFlavour: " << simFlavour);
283 ATH_MSG_DEBUG(
"Some values in FileMetaData returned false for 'value()'.");
290 if ( calibration.EqualTo(
"Bcid") ){
291 m_globalConfig->SetValue(
"PileupStartingScale",
"JetBcidScaleMomentum");
292 std::unique_ptr<JetCalibrationStep> bcidCorr = std::make_unique<BcidOffsetCorrection>(this->name()+
"_Bcid",
m_globalConfig, jetAlgo, calibPath,
m_isData);
295 return StatusCode::SUCCESS;
297 else if ( calibration.EqualTo(
"JetArea") || calibration.EqualTo(
"Residual") ) {
298 std::unique_ptr<JetCalibrationStep> puCorr = std::make_unique<JetPileupCorrection>(this->name()+
"_Pileup",
m_globalConfig, jetAlgo, calibPath,
300 puCorr->msg().setLevel( this->
msg().level() );
303 return StatusCode::SUCCESS;
305 else if ( calibration.EqualTo(
"EtaJES") || calibration.EqualTo(
"AbsoluteEtaJES") ) {
306 std::unique_ptr<JetCalibrationStep> etaJESCorr = std::make_unique<EtaJESCorrection>(this->name()+
"_EtaJES",
m_globalConfig, jetAlgo, calibPath,
false,
m_devMode);
307 etaJESCorr->msg().setLevel( this->
msg().level() );
310 return StatusCode::SUCCESS;
312 else if ( calibration.EqualTo(
"EtaMassJES") ) {
313 std::unique_ptr<JetCalibrationStep> etaJESCorr = std::make_unique<EtaJESCorrection>(this->name()+
"_EtaMassJES",
m_globalConfig, jetAlgo, calibPath,
true,
m_devMode);
314 etaJESCorr->msg().setLevel( this->
msg().level() );
317 return StatusCode::SUCCESS;
319 else if ( calibration.EqualTo(
"GSC") ) {
321 gsc->msg().setLevel( this->
msg().level() );
326 TString actualCalibPath;
328 actualCalibPath =
"JetCalibTools/";
330 actualCalibPath =
"JetCalibTool/CalibArea-" +
m_calibAreaTag +
"/";
335 ATH_MSG_WARNING(
"JPS_FastSim.doCalibration is set in JetCalibrationTool config but isData is set to true. Will turn off FastSim calibration.");
340 ATH_MSG_FATAL(
"JPS_FastSim.doCalibration is set in JetCalibrationTool config but file has no FileMetaData. Please fix the sample or configuration.");
341 return StatusCode::FAILURE;
344 JPS_FastSim->msg().setLevel( this->
msg().level() );
351 JPS_PtResidual->msg().setLevel( this->
msg().level() );
355 return StatusCode::SUCCESS;
357 else if ( calibration.EqualTo(
"GNNC") ) {
358 std::unique_ptr<JetCalibrationStep> gnnc = std::make_unique<GlobalNNCalibration>(this->name()+
"_GNNC",
m_globalConfig,jetAlgo,calibPath,
m_devMode);
359 gnnc->msg().setLevel( this->
msg().level() );
362 return StatusCode::SUCCESS;
364 else if ( calibration.EqualTo(
"MC2MC") ) {
366 TString actualCalibPath;
368 actualCalibPath =
"JetCalibTools/";
370 actualCalibPath =
"JetCalibTool/CalibArea-" +
m_calibAreaTag +
"/";
373 ATH_MSG_FATAL(
"MC2MC step of jet calibration is requested but file has no FileMetaData. Please fix the sample or configuration.");
374 return StatusCode::FAILURE;
377 JPS_MC2MC->msg().setLevel( this->
msg().level() );
380 return StatusCode::SUCCESS;
382 else if ( calibration.EqualTo(
"JMS") ) {
383 std::unique_ptr<JetCalibrationStep> jetMassCorr = std::make_unique<JMSCorrection>(this->name()+
"_JMS",
m_globalConfig, jetAlgo, calibPath,
m_devMode);
384 jetMassCorr->msg().setLevel( this->
msg().level() );
387 return StatusCode::SUCCESS;
389 else if ( calibration.EqualTo(
"InsituCombinedMass") ){
391 std::unique_ptr<JetCalibrationStep> jetMassCorr = std::make_unique<JMSCorrection>(this->name()+
"_InsituCombinedMass",
m_globalInsituCombMassConfig.at(i), jetAlgo, calibPath,
m_devMode);
392 jetMassCorr->msg().setLevel( this->
msg().level() );
396 return StatusCode::SUCCESS;
398 else if ( calibration.EqualTo(
"Insitu") ) {
400 std::unique_ptr<JetCalibrationStep> insituDataCorr = std::make_unique<InsituDataCorrection>(this->name()+
"_Insitu",
m_globalConfig, jetAlgo, calibPath,
m_devMode);
401 insituDataCorr->msg().setLevel( this->
msg().level() );
404 return StatusCode::SUCCESS;
407 ATH_MSG_INFO(
"Initializing Time-Dependent Insitu Corrections");
410 unsigned int firstRun =
static_cast<unsigned int>(
m_runBins.at(i)+1.5);
411 unsigned int lastRun =
static_cast<unsigned int>(
m_runBins.at(i+1)+0.5);
412 std::unique_ptr<JetCalibrationStep> insituDataCorr = std::make_unique<InsituDataCorrection>(this->name()+
"_Insitu_"+std::to_string(i),
m_globalTimeDependentConfigs.at(i), jetAlgo,
413 calibPath,
m_devMode, firstRun, lastRun);
414 insituDataCorr->msg().setLevel( this->
msg().level() );
418 return StatusCode::SUCCESS;
421 else if ( calibration.EqualTo(
"Smear") ) {
423 ATH_MSG_FATAL(
"Asked for smearing of data, which is not supported. Aborting.");
424 return StatusCode::FAILURE;
426 std::unique_ptr<JetCalibrationStep> jetSmearCorr = std::make_unique<JetSmearingCorrection>(this->name()+
"_Smear",
m_globalConfig,jetAlgo,calibPath,
m_devMode);
427 jetSmearCorr->msg().setLevel(this->
msg().level());
431 return StatusCode::SUCCESS;
433 else if ( calibration.EqualTo(
"LargeRDNN") ) {
434 std::unique_ptr<JetCalibrationStep> largeR_dnn = std::make_unique<GlobalLargeRDNNCalibration>(this->name()+
"_R10DNN",
m_globalConfig,calibPath,
m_devMode);
435 largeR_dnn->msg().setLevel(this->
msg().level());
438 return StatusCode::SUCCESS;
440 ATH_MSG_FATAL(
"Calibration string not recognized: " << calibration <<
", aborting.");
441 return StatusCode::FAILURE;
460 ATH_MSG_FATAL(
" JetCalibrationTool::initializeEvent : The tool was not initialized.");
461 return StatusCode::FAILURE;
465 static const SG::AuxElement::ConstAccessor<int> PVIndexAccessor(
"PVIndex");
479 eventShape = rhRhoKey.
cptr();
482 ATH_MSG_FATAL(
"Could not retrieve the xAOD::EventShape container " <<
m_rhoKey.key() <<
" from the input file");
483 return StatusCode::FAILURE;
487 return StatusCode::FAILURE;
493 ATH_MSG_FATAL(
"Could not retrieve xAOD::EventShape container " <<
m_rhoKey.key() <<
" from the input file");
494 return StatusCode::FAILURE;
507 return StatusCode::FAILURE;
511 return StatusCode::FAILURE;
516 for (
const auto *
jet : *jets) {
527 static std::atomic<unsigned int> eventInfoWarnings = 0;
530 eventObj = rhEvtInfo.
cptr();
533 if ( eventInfoWarnings < 20 )
534 ATH_MSG_ERROR(
" JetCalibrationTool::initializeEvent : Failed to retrieve event information.");
535 jetEventInfo.
setMu(0);
537 return StatusCode::SUCCESS;
546 return StatusCode::FAILURE;
548 jetEventInfo.
setMu( eventInfoDecor(0) );
558 if (
m_doGSC && PVIndexAccessor.isAvailable(*eventObj) )
559 jetEventInfo.
setPVIndex( PVIndexAccessor(*eventObj) );
565 vertices = rhPV.
cptr();
568 for ( ; vtx_itr != vtx_end; ++vtx_itr ){
590 static const SG::ConstAccessor<int> BCIDGapBeforeTrainMinus12Acc (
"DFCommonJets_BCIDGapBeforeTrainMinus12");
608 vertices = rhPV.
cptr();
610 ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : Failed to retrieve primary vertices.");
612 return StatusCode::SUCCESS;
619 eventNPV = std::count_if(vertices->
begin(), vertices->
end(), [](
const xAOD::Vertex* vtx){ return vtx->vertexType() == xAOD::VxType::PileUp || vtx->vertexType() == xAOD::VxType::PriVtx;});
620 jetEventInfo.
setNPV(eventNPV);
626 static std::atomic<unsigned int> vertexIndexWarnings = 0;
627 if (jetEventInfo.
PVIndex() < 0 ||
static_cast<size_t>(jetEventInfo.
PVIndex()) >= vertices->
size())
629 ++vertexIndexWarnings;
630 if (vertexIndexWarnings < 20)
631 ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : PV index is out of bounds.");
633 return StatusCode::SUCCESS;
639 static std::atomic<unsigned int> eventInfoWarningsMu = 0;
643 jetEventInfo.
setMu(eventInfoDecor(0));
645 ++eventInfoWarningsMu;
646 if ( eventInfoWarningsMu < 20 )
ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : Failed to retrieve event information.");
647 jetEventInfo.
setMu(0);
650 static std::atomic<unsigned int> eventInfoWarningsPV = 0;
654 vertices = rhPV.
cptr();
656 eventNPV = std::count_if(vertices->
begin(), vertices->
end(), [](
const xAOD::Vertex* vtx){ return vtx->vertexType() == xAOD::VxType::PileUp || vtx->vertexType() == xAOD::VxType::PriVtx;});
657 jetEventInfo.
setNPV(eventNPV);
659 ++eventInfoWarningsPV;
660 if ( eventInfoWarningsPV < 20 )
ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : Failed to retrieve primary vertices.");
664 return StatusCode::SUCCESS;