77 if ( jetAlgo.EqualTo(
"") || calibSeq.EqualTo(
"") ) {
78 ATH_MSG_FATAL(
"JetCalibrationTool::initialize : At least one of your constructor arguments is not set. Did you use the copy constructor?");
79 return StatusCode::FAILURE;
82 if (
m_config.empty() ) {
ATH_MSG_FATAL(
"No configuration file specified.");
return StatusCode::FAILURE; }
88 dir =
"JetCalibTools/";
90 else{
dir.insert(14,calibPath);}
94 ATH_MSG_FATAL(
"Couldn't find ConfigFile " << configPath );
return StatusCode::FAILURE;
96 ATH_MSG_INFO(
"Reading global JES settings from: " << configPath);
105 if ( calibSeq.Contains(
"JetArea") ) {
109 else {
ATH_MSG_FATAL(
"jetAlgo " << jetAlgo <<
" not recognized.");
return StatusCode::FAILURE; }
117 std::string rhoKey_config =
m_globalConfig->GetValue(
"RhoKey",
"None");
119 bool requireRhoInput =
false;
122 if ( !calibSeq.Contains(
"JetArea") && !calibSeq.Contains(
"Residual") ) {
125 }
else if ( calibSeq.Contains(
"JetArea") ) {
126 if (
m_rhoKey.key().compare(
"auto") == 0 && rhoKey_config.compare(
"None") == 0) {
137 else if(rhoKey_config.compare(
"None") != 0 &&
m_rhoKey.key().compare(
"auto") == 0){
140 requireRhoInput =
true;
141 if ( !calibSeq.Contains(
"Residual") )
m_doResidual =
false;
142 }
else if ( !calibSeq.Contains(
"JetArea") && calibSeq.Contains(
"Residual") ) {
144 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.");
150 "HLT_xAOD__JetContainer_a4tcemsubjesISFS");
152 if ( !calibSeq.Contains(
"Origin") )
m_doOrigin =
false;
153 if ( !calibSeq.Contains(
"GSC") && !calibSeq.Contains(
"GNNC"))
m_doGSC =
false;
154 if ( !calibSeq.Contains(
"Bcid") )
m_doBcid =
false;
155 if ( calibSeq.Contains(
"DNN") )
m_doDNNCal =
true;
158 if ( calibSeq.Contains(
"Insitu") && !
m_isData ) {
159 ATH_MSG_FATAL(
"JetCalibrationTool::initialize : calibSeq string contains Insitu with isData set to false. Can't apply in-situ correction to MC!!");
160 return StatusCode::FAILURE;
178 TEnv *globalConfig_insitu =
new TEnv();
179 int status = globalConfig_insitu->ReadFile(fn_insitu ,EEnvLevel(0));
180 if (
status!=0) {
ATH_MSG_FATAL(
"Cannot read config file " << fn_insitu );
return StatusCode::FAILURE; }
198 TEnv *globalInsituCombMass =
new TEnv();
199 int status = globalInsituCombMass->ReadFile(fn_comb ,EEnvLevel(0));
200 if (
status!=0) {
ATH_MSG_FATAL(
"Cannot read config file " << fn_comb );
return StatusCode::FAILURE; }
208 for (
unsigned int i=0;
i<vecCalibSeq.size(); ++
i) {
209 if ( vecCalibSeq[
i].EqualTo(
"Origin") || vecCalibSeq[
i].EqualTo(
"DEV") )
continue;
210 if ( vecCalibSeq[
i].EqualTo(
"Residual") &&
m_doJetArea )
continue;
223 ATH_MSG_ERROR(
"Residual calibration requested but no primary vertex container specified!");
224 return StatusCode::FAILURE;
227 if(
m_jetAlgo.find(
"PFlow")!=std::string::npos) {
228 ATH_MSG_ERROR(
"GSC calibration for PFlow requested but no primary vertex container specified!");
229 return StatusCode::FAILURE;
232 ATH_MSG_ERROR(
"GSC calibration with tracks requested but no primary vertex container specified!");
233 return StatusCode::FAILURE;
241 if (
m_calibSeq.find(
"Smear") == std::string::npos) {
244 TFile *f_LegJER =
new TFile(fn_JER,
"READ");
248 TString data_hist_name =
"JER_Nominal_data_" +
m_jetAlgo;
251 hist_data = (TH2D*)f_LegJER->Get(data_hist_name);
252 hist_MC = (TH2D*)f_LegJER->Get(mc_hist_name);
258 m_resMC = (TH2D*)hist_MC->Clone();
259 m_resMC->SetDirectory(
nullptr);
265 return StatusCode::SUCCESS;
274 TString generatorsInfo{};
275 TString simFlavour{};
278 if (
inputMetaStore()->contains<xAOD::FileMetaData>(
"FileMetaData") ) {
285 if (dataYear >= 2015 && dataYear <= 2018) {
287 }
else if (dataYear >= 2022 && dataYear <= 2024) {
290 ATH_MSG_WARNING(
"Data year " << dataYear <<
" not recognized from file metadata. The corresponding mcCampaign will not be known.");
294 std::string str_generatorsInfo;
296 generatorsInfo = str_generatorsInfo;
298 std::string str_simFlavour;
300 simFlavour = str_simFlavour;
304 std::string str_mcCampaign;
306 str_mcCampaign.resize(4);
310 ATH_MSG_INFO(
"Have loaded metadata mcDSID:" << mcDSID <<
", generatorsInfo: " << generatorsInfo <<
", mcCampaign: " <<
mcCampaign <<
", simFlavour: " << simFlavour);
318 if ( calibration.EqualTo(
"Bcid") ){
319 m_globalConfig->SetValue(
"PileupStartingScale",
"JetBcidScaleMomentum");
320 std::unique_ptr<JetCalibrationStep> bcidCorr = std::make_unique<BcidOffsetCorrection>(this->
name()+
"_Bcid",
m_globalConfig, jetAlgo, calibPath,
m_isData);
323 return StatusCode::SUCCESS;
325 else if ( calibration.EqualTo(
"JetArea") || calibration.EqualTo(
"Residual") ) {
326 std::unique_ptr<JetCalibrationStep> puCorr = std::make_unique<JetPileupCorrection>(this->
name()+
"_Pileup",
m_globalConfig, jetAlgo, calibPath,
331 return StatusCode::SUCCESS;
333 else if ( calibration.EqualTo(
"EtaJES") || calibration.EqualTo(
"AbsoluteEtaJES") ) {
334 std::unique_ptr<JetCalibrationStep> etaJESCorr = std::make_unique<EtaJESCorrection>(this->
name()+
"_EtaJES",
m_globalConfig, jetAlgo, calibPath,
false,
m_devMode);
338 return StatusCode::SUCCESS;
340 else if ( calibration.EqualTo(
"EtaMassJES") ) {
341 std::unique_ptr<JetCalibrationStep> etaJESCorr = std::make_unique<EtaJESCorrection>(this->
name()+
"_EtaMassJES",
m_globalConfig, jetAlgo, calibPath,
true,
m_devMode);
345 return StatusCode::SUCCESS;
347 else if ( calibration.EqualTo(
"GSC") ) {
354 TString actualCalibPath;
356 actualCalibPath =
"JetCalibTools/";
358 actualCalibPath =
"JetCalibTool/CalibArea-" +
m_calibAreaTag +
"/";
363 ATH_MSG_WARNING(
"JPS_FastSim.doCalibration is set in JetCalibrationTool config but isData is set to true. Will turn off FastSim calibration.");
368 ATH_MSG_FATAL(
"JPS_FastSim.doCalibration is set in JetCalibrationTool config but file has no FileMetaData. Please fix the sample or configuration.");
369 return StatusCode::FAILURE;
372 JPS_FastSim->
msg().setLevel( this->
msg().
level() );
379 JPS_PtResidual->
msg().setLevel( this->
msg().
level() );
383 return StatusCode::SUCCESS;
385 else if ( calibration.EqualTo(
"GNNC") ) {
386 std::unique_ptr<JetCalibrationStep> gnnc = std::make_unique<GlobalNNCalibration>(this->
name()+
"_GNNC",
m_globalConfig,jetAlgo,calibPath,
m_devMode);
390 return StatusCode::SUCCESS;
392 else if ( calibration.EqualTo(
"MC2MC") ) {
394 TString actualCalibPath;
396 actualCalibPath =
"JetCalibTools/";
398 actualCalibPath =
"JetCalibTool/CalibArea-" +
m_calibAreaTag +
"/";
401 ATH_MSG_FATAL(
"MC2MC step of jet calibration is requested but file has no FileMetaData. Please fix the sample or configuration.");
402 return StatusCode::FAILURE;
404 std::unique_ptr<JetCalibrationStep> JPS_MC2MC = std::make_unique<Generic4VecCorrection>(this->
name()+
"_MC2MC",
m_globalConfig, jetAlgo, actualCalibPath,
m_forceCalibFile_MC2MC, Generic4VecCorrection::JET_CORRTYPE::MC2MC,
mcCampaign, simFlavour, (
int) mcDSID, generatorsInfo);
408 return StatusCode::SUCCESS;
410 else if ( calibration.EqualTo(
"JMS") ) {
411 std::unique_ptr<JetCalibrationStep> jetMassCorr = std::make_unique<JMSCorrection>(this->
name()+
"_JMS",
m_globalConfig, jetAlgo, calibPath,
m_devMode);
412 jetMassCorr->
msg().setLevel( this->
msg().
level() );
415 return StatusCode::SUCCESS;
417 else if ( calibration.EqualTo(
"InsituCombinedMass") ){
420 jetMassCorr->
msg().setLevel( this->
msg().
level() );
424 return StatusCode::SUCCESS;
426 else if ( calibration.EqualTo(
"Insitu") ) {
428 std::unique_ptr<JetCalibrationStep> insituDataCorr = std::make_unique<InsituDataCorrection>(this->
name()+
"_Insitu",
m_globalConfig, jetAlgo, calibPath,
m_devMode);
429 insituDataCorr->
msg().setLevel( this->
msg().
level() );
432 return StatusCode::SUCCESS;
435 ATH_MSG_INFO(
"Initializing Time-Dependent Insitu Corrections");
438 unsigned int firstRun =
static_cast<unsigned int>(
m_runBins.at(
i)+1.5);
442 insituDataCorr->
msg().setLevel( this->
msg().
level() );
446 return StatusCode::SUCCESS;
449 else if ( calibration.EqualTo(
"Smear") ) {
451 ATH_MSG_FATAL(
"Asked for smearing of data, which is not supported. Aborting.");
452 return StatusCode::FAILURE;
454 std::unique_ptr<JetCalibrationStep> jetSmearCorr = std::make_unique<JetSmearingCorrection>(this->
name()+
"_Smear",
m_globalConfig,jetAlgo,calibPath,
m_devMode);
459 return StatusCode::SUCCESS;
461 else if ( calibration.EqualTo(
"LargeRDNN") ) {
462 std::unique_ptr<JetCalibrationStep> largeR_dnn = std::make_unique<GlobalLargeRDNNCalibration>(this->
name()+
"_R10DNN",
m_globalConfig,calibPath,
m_devMode);
466 return StatusCode::SUCCESS;
468 ATH_MSG_FATAL(
"Calibration string not recognized: " << calibration <<
", aborting.");
469 return StatusCode::FAILURE;
478 return StatusCode::SUCCESS;
488 ATH_MSG_FATAL(
" JetCalibrationTool::initializeEvent : The tool was not initialized.");
489 return StatusCode::FAILURE;
507 eventShape = rhRhoKey.
cptr();
510 ATH_MSG_FATAL(
"Could not retrieve the xAOD::EventShape container " <<
m_rhoKey.key() <<
" from the input file");
511 return StatusCode::FAILURE;
515 return StatusCode::FAILURE;
521 ATH_MSG_FATAL(
"Could not retrieve xAOD::EventShape container " <<
m_rhoKey.key() <<
" from the input file");
522 return StatusCode::FAILURE;
535 return StatusCode::FAILURE;
539 return StatusCode::FAILURE;
544 for (
const auto *
jet : *
jets) {
555 static std::atomic<unsigned int> eventInfoWarnings = 0;
558 eventObj = rhEvtInfo.
cptr();
561 if ( eventInfoWarnings < 20 )
562 ATH_MSG_ERROR(
" JetCalibrationTool::initializeEvent : Failed to retrieve event information.");
563 jetEventInfo.
setMu(0);
565 return StatusCode::SUCCESS;
574 return StatusCode::FAILURE;
576 jetEventInfo.
setMu( eventInfoDecor(0) );
587 jetEventInfo.
setPVIndex( PVIndexAccessor(*eventObj) );
593 vertices = rhPV.
cptr();
596 for ( ; vtx_itr != vtx_end; ++vtx_itr ){
618 static const SG::ConstAccessor<int> BCIDGapBeforeTrainMinus12Acc (
"DFCommonJets_BCIDGapBeforeTrainMinus12");
636 vertices = rhPV.
cptr();
638 ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : Failed to retrieve primary vertices.");
640 return StatusCode::SUCCESS;
647 eventNPV = std::count_if(vertices->
begin(), vertices->
end(), [](
const xAOD::Vertex* vtx){ return vtx->vertexType() == xAOD::VxType::PileUp || vtx->vertexType() == xAOD::VxType::PriVtx;});
648 jetEventInfo.
setNPV(eventNPV);
654 static std::atomic<unsigned int> vertexIndexWarnings = 0;
655 if (jetEventInfo.
PVIndex() < 0 ||
static_cast<size_t>(jetEventInfo.
PVIndex()) >= vertices->
size())
657 ++vertexIndexWarnings;
658 if (vertexIndexWarnings < 20)
659 ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : PV index is out of bounds.");
661 return StatusCode::SUCCESS;
667 static std::atomic<unsigned int> eventInfoWarningsMu = 0;
671 jetEventInfo.
setMu(eventInfoDecor(0));
673 ++eventInfoWarningsMu;
674 if ( eventInfoWarningsMu < 20 )
ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : Failed to retrieve event information.");
675 jetEventInfo.
setMu(0);
678 static std::atomic<unsigned int> eventInfoWarningsPV = 0;
682 vertices = rhPV.
cptr();
684 eventNPV = std::count_if(vertices->
begin(), vertices->
end(), [](
const xAOD::Vertex* vtx){ return vtx->vertexType() == xAOD::VxType::PileUp || vtx->vertexType() == xAOD::VxType::PriVtx;});
685 jetEventInfo.
setNPV(eventNPV);
687 ++eventInfoWarningsPV;
688 if ( eventInfoWarningsPV < 20 )
ATH_MSG_WARNING(
" JetCalibrationTool::initializeEvent : Failed to retrieve primary vertices.");
692 return StatusCode::SUCCESS;
699 if ( !
jet.getAttribute<
int>(
"OriginCorrected",
tmp) )
700 jet.setAttribute<
int>(
"OriginCorrected",
false);
701 if ( !
jet.getAttribute<
int>(
"PileupCorrected",
tmp) )
702 jet.setAttribute<
int>(
"PileupCorrected",
false);
707 jet.setAttribute<
float>(
"DetectorEta",jetconstitP4.eta());
712 return StatusCode::SUCCESS;
719 ATH_MSG_DEBUG(
"Requesting nominal data resolution without smearing - currently configured to return R21 JER!");
729 ATH_MSG_DEBUG(
"Requesting nominal MC resolution without smearing - currently configured to return R21 JER!");
742 return StatusCode::FAILURE;
747 return StatusCode::FAILURE;
751 if (
histo->GetDimension() != 2)
753 ATH_MSG_ERROR(
"Blocking reading of a " <<
histo->GetDimension() <<
"D histogram as a 2D histogram");
754 return StatusCode::FAILURE;
759 double y = fabs(
jet.eta());
762 const double minX =
histo->GetXaxis()->GetBinLowEdge(1);
763 const double maxX =
histo->GetXaxis()->GetBinLowEdge(
histo->GetNbinsX()+1);
766 else if (
x <= minX )
768 const double minY =
histo->GetYaxis()->GetBinLowEdge(1);
769 const double maxY =
histo->GetYaxis()->GetBinLowEdge(
histo->GetNbinsY()+1);
772 else if (
y <= minY )
778 return StatusCode::SUCCESS;