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);
288 if ( calibration.EqualTo(
"Bcid") ){
289 m_globalConfig->SetValue(
"PileupStartingScale",
"JetBcidScaleMomentum");
290 std::unique_ptr<JetCalibrationStep> bcidCorr = std::make_unique<BcidOffsetCorrection>(this->name()+
"_Bcid",
m_globalConfig, jetAlgo, calibPath,
m_isData);
293 return StatusCode::SUCCESS;
295 else if ( calibration.EqualTo(
"JetArea") || calibration.EqualTo(
"Residual") ) {
296 std::unique_ptr<JetCalibrationStep> puCorr = std::make_unique<JetPileupCorrection>(this->name()+
"_Pileup",
m_globalConfig, jetAlgo, calibPath,
298 puCorr->msg().setLevel( this->
msg().level() );
301 return StatusCode::SUCCESS;
303 else if ( calibration.EqualTo(
"EtaJES") || calibration.EqualTo(
"AbsoluteEtaJES") ) {
304 std::unique_ptr<JetCalibrationStep> etaJESCorr = std::make_unique<EtaJESCorrection>(this->name()+
"_EtaJES",
m_globalConfig, jetAlgo, calibPath,
false,
m_devMode);
305 etaJESCorr->msg().setLevel( this->
msg().level() );
308 return StatusCode::SUCCESS;
310 else if ( calibration.EqualTo(
"EtaMassJES") ) {
311 std::unique_ptr<JetCalibrationStep> etaJESCorr = std::make_unique<EtaJESCorrection>(this->name()+
"_EtaMassJES",
m_globalConfig, jetAlgo, calibPath,
true,
m_devMode);
312 etaJESCorr->msg().setLevel( this->
msg().level() );
315 return StatusCode::SUCCESS;
317 else if ( calibration.EqualTo(
"GSC") ) {
319 gsc->msg().setLevel( this->
msg().level() );
324 TString actualCalibPath;
326 actualCalibPath =
"JetCalibTools/";
328 actualCalibPath =
"JetCalibTool/CalibArea-" +
m_calibAreaTag +
"/";
333 ATH_MSG_WARNING(
"JPS_FastSim.doCalibration is set in JetCalibrationTool config but isData is set to true. Will turn off FastSim calibration.");
338 ATH_MSG_FATAL(
"JPS_FastSim.doCalibration is set in JetCalibrationTool config but file has no FileMetaData. Please fix the sample or configuration.");
339 return StatusCode::FAILURE;
342 JPS_FastSim->msg().setLevel( this->
msg().level() );
349 JPS_PtResidual->msg().setLevel( this->
msg().level() );
353 return StatusCode::SUCCESS;
355 else if ( calibration.EqualTo(
"GNNC") ) {
356 std::unique_ptr<JetCalibrationStep> gnnc = std::make_unique<GlobalNNCalibration>(this->name()+
"_GNNC",
m_globalConfig,jetAlgo,calibPath,
m_devMode);
357 gnnc->msg().setLevel( this->
msg().level() );
360 return StatusCode::SUCCESS;
362 else if ( calibration.EqualTo(
"MC2MC") ) {
364 TString actualCalibPath;
366 actualCalibPath =
"JetCalibTools/";
368 actualCalibPath =
"JetCalibTool/CalibArea-" +
m_calibAreaTag +
"/";
371 ATH_MSG_FATAL(
"MC2MC step of jet calibration is requested but file has no FileMetaData. Please fix the sample or configuration.");
372 return StatusCode::FAILURE;
375 JPS_MC2MC->msg().setLevel( this->
msg().level() );
378 return StatusCode::SUCCESS;
380 else if ( calibration.EqualTo(
"JMS") ) {
381 std::unique_ptr<JetCalibrationStep> jetMassCorr = std::make_unique<JMSCorrection>(this->name()+
"_JMS",
m_globalConfig, jetAlgo, calibPath,
m_devMode);
382 jetMassCorr->msg().setLevel( this->
msg().level() );
385 return StatusCode::SUCCESS;
387 else if ( calibration.EqualTo(
"InsituCombinedMass") ){
389 std::unique_ptr<JetCalibrationStep> jetMassCorr = std::make_unique<JMSCorrection>(this->name()+
"_InsituCombinedMass",
m_globalInsituCombMassConfig.at(i), jetAlgo, calibPath,
m_devMode);
390 jetMassCorr->msg().setLevel( this->
msg().level() );
394 return StatusCode::SUCCESS;
396 else if ( calibration.EqualTo(
"Insitu") ) {
398 std::unique_ptr<JetCalibrationStep> insituDataCorr = std::make_unique<InsituDataCorrection>(this->name()+
"_Insitu",
m_globalConfig, jetAlgo, calibPath,
m_devMode);
399 insituDataCorr->msg().setLevel( this->
msg().level() );
402 return StatusCode::SUCCESS;
405 ATH_MSG_INFO(
"Initializing Time-Dependent Insitu Corrections");
408 unsigned int firstRun =
static_cast<unsigned int>(
m_runBins.at(i)+1.5);
409 unsigned int lastRun =
static_cast<unsigned int>(
m_runBins.at(i+1)+0.5);
410 std::unique_ptr<JetCalibrationStep> insituDataCorr = std::make_unique<InsituDataCorrection>(this->name()+
"_Insitu_"+std::to_string(i),
m_globalTimeDependentConfigs.at(i), jetAlgo,
411 calibPath,
m_devMode, firstRun, lastRun);
412 insituDataCorr->msg().setLevel( this->
msg().level() );
416 return StatusCode::SUCCESS;
419 else if ( calibration.EqualTo(
"Smear") ) {
421 ATH_MSG_FATAL(
"Asked for smearing of data, which is not supported. Aborting.");
422 return StatusCode::FAILURE;
424 std::unique_ptr<JetCalibrationStep> jetSmearCorr = std::make_unique<JetSmearingCorrection>(this->name()+
"_Smear",
m_globalConfig,jetAlgo,calibPath,
m_devMode);
425 jetSmearCorr->msg().setLevel(this->
msg().level());
429 return StatusCode::SUCCESS;
431 else if ( calibration.EqualTo(
"LargeRDNN") ) {
432 std::unique_ptr<JetCalibrationStep> largeR_dnn = std::make_unique<GlobalLargeRDNNCalibration>(this->name()+
"_R10DNN",
m_globalConfig,calibPath,
m_devMode);
433 largeR_dnn->msg().setLevel(this->
msg().level());
436 return StatusCode::SUCCESS;
438 ATH_MSG_FATAL(
"Calibration string not recognized: " << calibration <<
", aborting.");
439 return StatusCode::FAILURE;
458 ATH_MSG_FATAL(
" JetCalibrationTool::initializeEvent : The tool was not initialized.");
459 return StatusCode::FAILURE;
477 eventShape = rhRhoKey.
cptr();
480 ATH_MSG_FATAL(
"Could not retrieve the xAOD::EventShape container " <<
m_rhoKey.key() <<
" from the input file");
481 return StatusCode::FAILURE;
485 return StatusCode::FAILURE;
491 ATH_MSG_FATAL(
"Could not retrieve xAOD::EventShape container " <<
m_rhoKey.key() <<
" from the input file");
492 return StatusCode::FAILURE;
505 return StatusCode::FAILURE;
509 return StatusCode::FAILURE;
514 for (
const auto *
jet : *jets) {
525 static std::atomic<unsigned int> eventInfoWarnings = 0;
528 eventObj = rhEvtInfo.
cptr();
531 if ( eventInfoWarnings < 20 )
532 ATH_MSG_ERROR(
" JetCalibrationTool::initializeEvent : Failed to retrieve event information.");
533 jetEventInfo.
setMu(0);
535 return StatusCode::SUCCESS;
544 return StatusCode::FAILURE;
546 jetEventInfo.
setMu( eventInfoDecor(0) );
557 jetEventInfo.
setPVIndex( PVIndexAccessor(*eventObj) );
563 vertices = rhPV.
cptr();
566 for ( ; vtx_itr != vtx_end; ++vtx_itr ){
588 static const SG::ConstAccessor<int> BCIDGapBeforeTrainMinus12Acc (
"DFCommonJets_BCIDGapBeforeTrainMinus12");
606 vertices = rhPV.
cptr();
608 ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : Failed to retrieve primary vertices.");
610 return StatusCode::SUCCESS;
617 eventNPV = std::count_if(vertices->
begin(), vertices->
end(), [](
const xAOD::Vertex* vtx){ return vtx->vertexType() == xAOD::VxType::PileUp || vtx->vertexType() == xAOD::VxType::PriVtx;});
618 jetEventInfo.
setNPV(eventNPV);
624 static std::atomic<unsigned int> vertexIndexWarnings = 0;
625 if (jetEventInfo.
PVIndex() < 0 ||
static_cast<size_t>(jetEventInfo.
PVIndex()) >= vertices->
size())
627 ++vertexIndexWarnings;
628 if (vertexIndexWarnings < 20)
629 ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : PV index is out of bounds.");
631 return StatusCode::SUCCESS;
637 static std::atomic<unsigned int> eventInfoWarningsMu = 0;
641 jetEventInfo.
setMu(eventInfoDecor(0));
643 ++eventInfoWarningsMu;
644 if ( eventInfoWarningsMu < 20 )
ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : Failed to retrieve event information.");
645 jetEventInfo.
setMu(0);
648 static std::atomic<unsigned int> eventInfoWarningsPV = 0;
652 vertices = rhPV.
cptr();
654 eventNPV = std::count_if(vertices->
begin(), vertices->
end(), [](
const xAOD::Vertex* vtx){ return vtx->vertexType() == xAOD::VxType::PileUp || vtx->vertexType() == xAOD::VxType::PriVtx;});
655 jetEventInfo.
setNPV(eventNPV);
657 ++eventInfoWarningsPV;
658 if ( eventInfoWarningsPV < 20 )
ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : Failed to retrieve primary vertices.");
662 return StatusCode::SUCCESS;