49 #include "TDirectory.h"
55 #include <unordered_set>
69 , m_energyScale(1.
e-3)
74 , m_calibArea(
"CalibArea-08")
77 , m_analysisHistPattern(
"")
78 , m_NJetAccessorName(
"Njet")
83 , m_refNPVHist(nullptr)
84 , m_refMuHist(nullptr)
86 , m_recognizedSystematics()
87 , m_recommendedSystematics()
89 , m_currentUncSet(nullptr)
92 , m_fileValidHist(nullptr)
93 , m_caloMassWeight(nullptr)
94 , m_TAMassWeight(nullptr)
95 , m_combMassWeightCaloMassDef(CompMassDef::UNKNOWN)
96 , m_combMassWeightTAMassDef(CompMassDef::UNKNOWN)
97 , m_combMassParam(CompParametrization::UNKNOWN)
101 , m_resHelper(nullptr)
102 , m_namePrefix(
"JET_")
103 , m_accTagScaleFactor(
"temp_SF")
104 , m_accEffSF(
"temp_effSF")
105 , m_accSigeffSF(
"temp_sigeffSF")
106 , m_accEfficiency(
"temp_efficiency")
107 , m_accTagResult(
"temp_accept")
108 , m_absEtaGluonFraction(true)
109 , m_pseudoDataJERsmearingMode(false)
129 ATH_MSG_ERROR(Form(
"Failed to pre-set applySystematicVariation to no variation"));
134 , m_isInit(toCopy.m_isInit)
136 , m_energyScale(1.
e-3)
137 , m_release(toCopy.m_release)
138 , m_jetDef(toCopy.m_jetDef)
139 , m_mcType(toCopy.m_mcType)
140 , m_configFile(toCopy.m_configFile)
141 , m_calibArea(toCopy.m_calibArea)
143 , m_analysisFile(toCopy.m_analysisFile)
144 , m_analysisHistPattern(toCopy.m_analysisHistPattern)
145 , m_NJetAccessorName(toCopy.m_NJetAccessorName)
146 , m_systFilters(toCopy.m_systFilters)
147 , m_defAnaFile(toCopy.m_defAnaFile)
148 , m_refNPV(toCopy.m_refNPV)
149 , m_refMu(toCopy.m_refMu)
153 , m_recognizedSystematics(toCopy.m_recognizedSystematics)
154 , m_recommendedSystematics(toCopy.m_recommendedSystematics)
155 , m_currentSystSet(toCopy.m_currentSystSet)
156 , m_currentUncSet(nullptr)
159 , m_fileValidHist(toCopy.m_fileValidHist)
160 , m_caloMassWeight(nullptr)
161 , m_TAMassWeight(nullptr)
162 , m_combMassWeightCaloMassDef(CompMassDef::
UNKNOWN)
163 , m_combMassWeightTAMassDef(CompMassDef::
UNKNOWN)
164 , m_combMassParam(CompParametrization::
UNKNOWN)
165 , m_userSeed(toCopy.m_userSeed)
166 , m_rand(toCopy.m_rand)
167 , m_isData(toCopy.m_isData)
169 , m_namePrefix(toCopy.m_namePrefix)
170 , m_accTagScaleFactor(toCopy.m_accTagScaleFactor)
171 , m_accEffSF(toCopy.m_accEffSF)
172 , m_accSigeffSF(toCopy.m_accSigeffSF)
173 , m_accEfficiency(toCopy.m_accEfficiency)
174 , m_accTagResult(toCopy.m_accTagResult)
175 , m_absEtaGluonFraction(toCopy.m_absEtaGluonFraction)
176 , m_pseudoDataJERsmearingMode(toCopy.m_pseudoDataJERsmearingMode)
180 for (
size_t iGroup = 0; iGroup < toCopy.
m_groups.size(); ++iGroup)
184 ATH_MSG_ERROR(Form(
"Failed to re-set applySystematicVariation in new tool copy"));
191 for (
size_t iGroup = 0; iGroup <
m_groups.size(); ++iGroup)
219 return StatusCode::FAILURE;
223 return StatusCode::SUCCESS;
232 return StatusCode::FAILURE;
236 return StatusCode::SUCCESS;
245 return StatusCode::FAILURE;
248 ATH_MSG_INFO(Form(
"Preparing to initialize the JetUncertaintiesTool named %s",
m_name.c_str()));
256 if (configFilePath ==
"")
259 return StatusCode::FAILURE;
263 if (settings.ReadFile(configFilePath.Data(),kEnvGlobal))
265 ATH_MSG_ERROR(
"Cannot read config file: " << configFilePath.Data());
266 return StatusCode::FAILURE;
270 ATH_MSG_INFO(Form(
"================================================"));
276 ATH_MSG_INFO(Form(
" Location: %s",configFilePath.Data()));
280 m_release = settings.GetValue(
"UncertaintyRelease",
"UNKNOWN");
284 TString allowedJetDefStr = settings.GetValue(
"SupportedJetDefs",
"");
285 if (allowedJetDefStr ==
"")
287 ATH_MSG_ERROR(
"Cannot find supported jet definitions in config");
288 return StatusCode::FAILURE;
290 std::vector<TString> allowedJetDefs = jet::utils::vectorize<TString>(allowedJetDefStr,
" ,");
291 bool foundJetDef =
false;
292 for (
size_t iDef = 0; iDef < allowedJetDefs.size(); ++iDef)
293 if (!allowedJetDefs.at(iDef).CompareTo(
m_jetDef.c_str(),TString::kIgnoreCase))
302 return StatusCode::FAILURE;
307 TString allowedMCtypeStr = settings.GetValue(
"SupportedMCTypes",
"");
308 if (allowedMCtypeStr ==
"")
311 return StatusCode::FAILURE;
313 std::vector<TString> allowedMCtypes = jet::utils::vectorize<TString>(allowedMCtypeStr,
" ,");
314 bool foundMCtype =
false;
315 for (
size_t iType = 0; iType < allowedMCtypes.size(); ++iType)
316 if (!allowedMCtypes.at(iType).CompareTo(
m_mcType.c_str(),TString::kIgnoreCase))
319 m_mcType = allowedMCtypes.at(iType);
325 return StatusCode::FAILURE;
331 TString histFileName = settings.GetValue(
"UncertaintyRootFile",
"");
332 if (histFileName ==
"")
335 return StatusCode::FAILURE;
337 ATH_MSG_INFO(Form(
" UncertaintyFile: \"%s\"",histFileName.Data()));
341 if (histFilePath ==
"")
343 ATH_MSG_ERROR(
"Cannot find the path of the uncertainty histogram file");
344 return StatusCode::FAILURE;
346 ATH_MSG_INFO(Form(
" Location: %s",histFilePath.Data()));
349 TFile* histFile =
new TFile(histFilePath,
"READ");
350 if (!histFile || histFile->IsZombie())
352 ATH_MSG_ERROR(
"Cannot open uncertainty histogram file: " << histFileName.Data());
353 return StatusCode::FAILURE;
359 m_defAnaFile = settings.GetValue(
"AnalysisRootFile",
"");
367 if (analysisFilePath ==
"")
369 ATH_MSG_ERROR(
"Cannot find the path of the analysis histogram file");
370 return StatusCode::FAILURE;
372 ATH_MSG_INFO(Form(
" Location: %s",analysisFilePath.Data()));
379 if (analysisFilePath ==
"")
381 ATH_MSG_ERROR(
"Cannot find the path of the default analysis histogram file");
382 return StatusCode::FAILURE;
384 ATH_MSG_INFO(Form(
" Location: %s",analysisFilePath.Data()));
393 TString validHistForFile = settings.GetValue(
"FileValidHistogram",
"");
394 if (validHistForFile !=
"")
397 TString validHistForFileParam = settings.GetValue(
"FileValidHistParam",
"");
398 if (validHistForFileParam ==
"")
400 ATH_MSG_ERROR(
"Specified a FileValidHistogram without an accompanying FileValidHistParam: " << validHistForFile.Data());
401 return StatusCode::FAILURE;
413 return StatusCode::FAILURE;
419 const TString caloMassWeight = TString(settings.GetValue(
"CombMassWeightCaloHist",
""));
420 const TString TAMassWeight = TString(settings.GetValue(
"CombMassWeightTAHist",
""));
421 if (caloMassWeight !=
"" && TAMassWeight !=
"")
427 return StatusCode::FAILURE;
429 return StatusCode::FAILURE;
432 const TString combMassParam = TString(settings.GetValue(
"CombMassWeightParam",
"PtMass"));
436 ATH_MSG_ERROR(
"Unexpected combined mass parametrization: " << combMassParam.Data());
437 return StatusCode::FAILURE;
440 ATH_MSG_INFO(
" Found and loaded combined mass weight factors");
446 const TString caloWeightMassDef = settings.GetValue(
"CombMassWeightCaloMassDef",
"Calo");
447 const TString TAWeightMassDef = settings.GetValue(
"CombMassWeightTAMassDef",
"TA");
448 if (caloWeightMassDef !=
"")
453 if (TAWeightMassDef !=
"")
459 else if (caloMassWeight !=
"" && TAMassWeight ==
"")
461 ATH_MSG_ERROR(
" Found combined mass weight factors for the calo term, but not the TA term");
462 return StatusCode::FAILURE;
464 else if (caloMassWeight ==
"" && TAMassWeight !=
"")
466 ATH_MSG_ERROR(
" Found combined mass weight factors for the TA term, but not the calo term");
467 return StatusCode::FAILURE;
472 m_name_EffSF = TString(settings.GetValue(
"TagSFEffName",
"temp_effSF"));
473 m_name_Efficiency = TString(settings.GetValue(
"TagEfficiencyName",
"temp_efficiency"));
474 m_name_TagResult = TString(settings.GetValue(
"TagResultName",
"temp_accept")).ReplaceAll(
"accept",
"Tagged");
487 TString refNPV = settings.GetValue(
"Pileup.NPVRef",
"");
488 TString refMu = settings.GetValue(
"Pileup.MuRef",
"");
489 if ( (refNPV !=
"" && refMu ==
"") || (refNPV ==
"" && refMu !=
"") )
492 return StatusCode::FAILURE;
494 else if ( refNPV !=
"" && refMu !=
"")
498 if (utils::isTypeObjFromString<float>(refNPV))
499 m_refNPV = utils::getTypeObjFromString<float>(refNPV);
504 return StatusCode::FAILURE;
507 if (utils::isTypeObjFromString<float>(refMu))
508 m_refMu = utils::getTypeObjFromString<float>(refMu);
513 return StatusCode::FAILURE;
521 std::string varString =
"";
522 for (
size_t iFilter = 0; iFilter <
m_systFilters.size(); ++iFilter)
526 ATH_MSG_ERROR(
"Unable to parse VariablesToShift due to unknown variable, please check for typos: " <<
m_systFilters.at(iFilter));
527 return StatusCode::FAILURE;
529 if (!varString.empty())
533 ATH_MSG_INFO(Form(
" VariablesToShift: %s",varString.c_str()));
540 return StatusCode::FAILURE;
550 ATH_MSG_INFO(Form(
"%6s %-40s : %s",
"",
"JES uncert. comp.",
"Description"));
551 ATH_MSG_INFO(Form(
"%6s %-40s -%s",
"",
"-----------------",
"-----------"));
552 for (
size_t iGroup = 0; iGroup < 999; ++iGroup)
555 const TString
prefix = Form(
"JESGroup.%zu.",iGroup);
559 if (
helper.initialize(settings).isFailure())
560 return StatusCode::FAILURE;
563 if (!
helper.isGroup())
continue;
572 return StatusCode::FAILURE;
574 for (
size_t iComp = 0; iComp < 999; ++iComp)
577 const TString
prefix = Form(
"JESComponent.%zu.",iComp);
581 if (
helper.initialize(settings).isFailure())
582 return StatusCode::FAILURE;
599 return StatusCode::FAILURE;
604 size_t numCompsBeforeMerger = 0;
605 for (
size_t iGroup = 0; iGroup <
m_groups.size(); ++iGroup) {
606 numCompsBeforeMerger +=
m_groups.at(iGroup)->getNumComponents();
618 for (
size_t iGroup = 0; iGroup <
m_groups.size(); ++iGroup)
620 const int groupNum =
m_groups.at(iGroup)->getGroupNum();
621 const int subgroupNum =
m_groups.at(iGroup)->getSubgroupNum();
625 if (!groupNum || !subgroupNum)
continue;
628 if (groupNum == subgroupNum)
630 ATH_MSG_ERROR(Form(
"Specified group %d (%s) as the parent of itself, blocking for safety",groupNum,
m_groups.at(iGroup)->getName().Data()));
631 return StatusCode::FAILURE;
635 for (
size_t iParentGroup = 0; iParentGroup <
m_groups.size(); ++iParentGroup)
637 if (iParentGroup == iGroup)
continue;
639 const int parentGroupNum =
m_groups.at(iParentGroup)->getGroupNum();
640 if (parentGroupNum == subgroupNum)
643 if (
m_groups.at(iParentGroup)->addSubgroup(
m_groups.at(iGroup)).isFailure())
645 ATH_MSG_ERROR(Form(
"Failed to add group %d (%s) as a subgroup of group %d (%s)",groupNum,
m_groups.at(iGroup)->getName().Data(),parentGroupNum,
m_groups.at(iParentGroup)->getName().Data()));
646 return StatusCode::FAILURE;
654 std::vector<UncertaintyGroup*> localGroupVec;
655 for (
size_t iGroup = 0; iGroup <
m_groups.size(); ++iGroup)
656 localGroupVec.push_back(
m_groups.at(iGroup));
659 for (
size_t iGroup = 0; iGroup < localGroupVec.size(); ++iGroup)
662 if (!localGroupVec.at(iGroup)->getSubgroupNum())
663 m_groups.push_back(localGroupVec.at(iGroup));
668 size_t numCompsAfterMerger = 0;
669 for (
size_t iGroup = 0; iGroup <
m_groups.size(); ++iGroup) {
670 numCompsAfterMerger +=
m_groups.at(iGroup)->getNumComponents();
681 if (numCompsBeforeMerger != numCompsAfterMerger)
683 ATH_MSG_ERROR(Form(
"Something went wrong merging groups: %zu before merger and %zu after merger",numCompsBeforeMerger,numCompsAfterMerger));
684 for (
size_t iGroup = 0; iGroup <
m_groups.size(); ++iGroup)
688 return StatusCode::FAILURE;
695 for (
size_t iGroup = 0; iGroup <
m_groups.size(); ++iGroup)
697 if (
m_groups.at(iGroup)->getNumComponents() == 0)
700 return StatusCode::FAILURE;
702 if (
m_groups.at(iGroup)->initialize(histFile).isFailure())
703 return StatusCode::FAILURE;
716 return StatusCode::FAILURE;
718 if (systVar.
basename().find(
"JER") != std::string::npos) {
721 return StatusCode::FAILURE;
729 for (
size_t iGroup = 0; iGroup <
m_groups.size(); ++iGroup)
731 std::set<CompScaleVar::TypeEnum> scaleVars =
m_groups.at(iGroup)->getScaleVars();
739 return StatusCode::FAILURE;
747 for (
size_t iFilter = 0; iFilter <
m_systFilters.size(); ++iFilter)
749 bool filterIsSane =
false;
750 for (
size_t iGroup = 0; iGroup <
m_groups.size(); ++iGroup)
760 ATH_MSG_ERROR(
" One of the specified VariablesToShift is not associated with any components, please check for typos: " <<
m_systFilters.at(iFilter));
761 return StatusCode::FAILURE;
767 size_t numCompInGroups = 0;
768 for (
size_t iGroup = 0; iGroup <
m_groups.size(); ++iGroup)
769 numCompInGroups +=
m_groups.at(iGroup)->getNumComponents();
779 ATH_MSG_INFO(Form(
"================================================"));
802 if (
group.groupNum == 0)
805 return StatusCode::FAILURE;
807 for (
size_t iGroup = 0; iGroup <
m_groups.size(); ++iGroup)
810 ATH_MSG_ERROR(
"Group number matches previous group (" <<
m_groups.at(iGroup)->getName().Data() <<
"): " <<
group.name.Data());
811 return StatusCode::FAILURE;
819 return StatusCode::FAILURE;
823 if (!
m_groups.back()->getSubgroupNum())
825 size_t numGroups = 0;
826 for (
size_t iGroup = 0; iGroup <
m_groups.size(); ++iGroup)
827 if (!
m_groups.at(iGroup)->getSubgroupNum())
831 ,
m_groups.back()->getDesc().Data() ));
833 return StatusCode::SUCCESS;
838 const bool isSimpleGroup =
helper.isCompGroup();
842 ATH_MSG_DEBUG(Form(
"Starting to process %s named %s",isSimpleGroup?
"simple component group":
"standard component",component.
name.Data()));
851 ATH_MSG_ERROR(
"Failed to build simple group for component: " << component.
name.Data());
852 return StatusCode::FAILURE;
854 const size_t groupIndex =
m_groups.size();
856 ATH_MSG_DEBUG(Form(
"Created new group \"%s\" for a simple component at index %zu",simpleGroup->
getName().Data(),groupIndex));
858 if (!
m_groups.back()->getSubgroupNum())
860 size_t numGroups = 0;
861 for (
size_t iGroup = 0; iGroup <
m_groups.size(); ++iGroup)
862 if (!
m_groups.at(iGroup)->getSubgroupNum())
866 ,
m_groups.back()->getDesc().Data() ));
876 return StatusCode::FAILURE;
878 if (
m_groups.at(groupIndex)->addComponent(compObject).isFailure())
879 return StatusCode::FAILURE;
880 ATH_MSG_DEBUG(Form(
"Added single component \"%s\" to simple group \"%s\" (index %zu)",compObject->
getName().Data(),
m_groups.at(groupIndex)->getName().Data(),groupIndex));
884 for (
size_t iSubComp = 0; iSubComp < component.
subComps.size(); ++iSubComp)
895 return StatusCode::FAILURE;
897 if (
m_groups.at(groupIndex)->addComponent(subCompObject).isFailure())
898 return StatusCode::FAILURE;
899 ATH_MSG_DEBUG(Form(
"Added component \"%s\" (%zu of %zu) to simple group \"%s\" (index %zu)",subCompObject->
getName().Data(),iSubComp+1,component.
subComps.size(),
m_groups.at(groupIndex)->getName().Data(),groupIndex));
905 size_t groupIndex = 0;
908 ATH_MSG_ERROR(
"No groups exist to add the component to: " << component.
name.Data());
909 return StatusCode::FAILURE;
911 for (
size_t iGroup = 0; iGroup <
m_groups.size(); ++iGroup)
920 return StatusCode::FAILURE;
927 return StatusCode::FAILURE;
929 if (
m_groups.at(groupIndex)->addComponent(compObject).isFailure())
930 return StatusCode::FAILURE;
931 ATH_MSG_DEBUG(Form(
"Added component \"%s\" to group \"%s\" (index %zu)",compObject->
getName().Data(),
m_groups.at(groupIndex)->getName().Data(),groupIndex));
934 return StatusCode::SUCCESS;
940 if (component.
name ==
"")
942 ATH_MSG_ERROR(
"Attempting to create a component with no name");
947 ATH_MSG_ERROR(
"Attempting to create a component with no parametrization: " << component.
name.Data());
952 ATH_MSG_ERROR(
"Attempting to create a component with no variable to scale: " << component.
name.Data());
965 ATH_MSG_ERROR(
"Attempted to create pileup component without NPV reference value: " << component.
name.Data());
970 ATH_MSG_ERROR(
"Attempted to create pileup component without mu reference value: " << component.
name.Data());
996 ATH_MSG_ERROR(
"Attempting to create a flavour uncertainty component without having specified an AnalysisRootFile");
1019 else if (component.
name.Contains(
"PunchThrough",TString::kIgnoreCase))
1030 else if (component.
name.Contains(
"Closeby",TString::kIgnoreCase))
1046 ATH_MSG_ERROR(
"Asking to create a combined mass term without specifying weights: " << component.
name.Data());
1074 ATH_MSG_ERROR(
"Failed to build calo-group for combined mass component: " << component.
name.Data());
1079 std::vector<TString> caloComps = jet::utils::vectorize<TString>(component.
caloMassTerm,
", ");
1080 std::vector<TString> caloMassDefs = jet::utils::vectorize<TString>(component.
caloMassDef,
", ");
1081 if (caloComps.size() != caloMassDefs.size())
1083 ATH_MSG_ERROR(
"Unbalanced number of calo mass terms and calo mass definitions, " << caloComps.size() <<
" vs " << caloMassDefs.size() <<
" for combined mass component: " << component.
name.Data());
1088 for (
size_t iComp = 0; iComp < caloComps.size(); ++iComp)
1094 caloCompH.
name = caloComps.at(iComp);
1099 ATH_MSG_ERROR(
"Failed to parse calo mass definition " << iComp <<
" (" << caloMassDefs.at(iComp).Data() <<
") for combined mass component: " << component.
name.Data());
1129 ATH_MSG_ERROR(
"Failed to build TA-group for combined mass component: " << component.
name.Data());
1134 std::vector<TString> TAComps = jet::utils::vectorize<TString>(component.
TAMassTerm,
", ");
1135 std::vector<TString> TAMassDefs = jet::utils::vectorize<TString>(component.
TAMassDef,
", ");
1136 if (TAComps.size() != TAMassDefs.size())
1138 ATH_MSG_ERROR(
"Unbalanced number of TA mass terms and TA mass definitions, " << TAComps.size() <<
" vs " << TAMassDefs.size() <<
" for combined mass component: " << component.
name.Data());
1143 for (
size_t iComp = 0; iComp < TAComps.size(); ++iComp)
1149 TACompH.
name = TAComps.at(iComp);
1154 ATH_MSG_ERROR(
"Failed to parse TA mass definition " << iComp <<
" (" << TAMassDefs.at(iComp).Data() <<
") for combined mass component: " << component.
name.Data());
1170 if (cmuc->
setTATerm(TAGroup).isFailure())
1178 else if (component.
name.Contains(
"Large",TString::kIgnoreCase) && component.
name.Contains(
"Topology",TString::kIgnoreCase))
1188 ATH_MSG_ERROR(Form(
"No LargeRJetTruthLabels specified for Large-R jet topology component %s",component.
name.Data()));
1238 ATH_MSG_ERROR(
"Failed to find the type of component to build: " << component.
name.Data());
1254 return baseNames.find(systematic.
basename()) != baseNames.end();
1281 const std::set<CompScaleVar::TypeEnum> scaleVars = systematic.
getScaleVars();
1283 for (
size_t iFilter = 0; iFilter <
m_systFilters.size(); ++iFilter)
1287 passesFilter =
true;
1308 ATH_MSG_ERROR(
"Failed to add systematic to list of recommended systematics: " << systematic.
name());
1309 return StatusCode::FAILURE;
1312 return StatusCode::SUCCESS;
1324 std::string remappedName = systConfig.
name();
1325 size_t found = remappedName.find(
"_PseudoData");
1326 if (
found != std::string::npos) {
1327 remappedName.erase(
found, std::string(
"_PseudoData").
length());
1333 return StatusCode::FAILURE;
1338 return StatusCode::FAILURE;
1344 return StatusCode::FAILURE;
1349 return StatusCode::SUCCESS;
1357 filteredSet =
iter->second;
1362 return StatusCode::FAILURE;
1366 return StatusCode::SUCCESS;
1377 uncSet =
iter->second;
1385 ATH_MSG_ERROR(
"Failed to create UncertaintySet for filtered CP::SystematicSet: " << filteredSet.
name());
1387 return StatusCode::FAILURE;
1389 m_systSetMap.insert(std::make_pair(filteredSet,uncSet));
1392 return StatusCode::SUCCESS;
1406 if (
release.BeginsWith(
"2011_"))
1408 else if (
release.BeginsWith(
"2012_"))
1410 else if (
release.BeginsWith(
"2015_") ||
release.BeginsWith(
"2016"))
1420 ATH_MSG_FATAL(
"Tool must be initialized before calling getRefMu");
1425 ATH_MSG_FATAL(
"Tool contains a histogram for refMu, cannot return float");
1435 ATH_MSG_FATAL(
"Tool must be initialized before calling getRefNPV");
1440 ATH_MSG_FATAL(
"Tool contains a histogram for refNPV, cannot return float");
1450 ATH_MSG_FATAL(
"Tool must be initialized before calling getRefMu");
1460 ATH_MSG_FATAL(
"Tool must be initialized before calling getRefNPV");
1471 ATH_MSG_FATAL(
"Tool must be initialized before calling getNumComponents");
1487 ATH_MSG_FATAL(
"Tool must be initialized before calling getComponentIndex");
1491 for (
size_t iComp = 0; iComp <
m_groups.size(); ++iComp)
1492 if (
m_groups.at(iComp)->getName().CompareTo(
name,TString::kIgnoreCase) == 0)
1503 ATH_MSG_FATAL(
"Tool must be initialized before calling getComponentName");
1518 ATH_MSG_FATAL(
"Tool must be initialized before calling getComponentDesc");
1533 ATH_MSG_FATAL(
"Tool must be initialized before calling getComponentCategory");
1548 ATH_MSG_FATAL(
"Tool must be initialized before calling getComponentIsReducible");
1563 ATH_MSG_FATAL(
"Tool must be initialized before asking for information pertaining to a given component index");
1564 return StatusCode::FAILURE;
1570 return StatusCode::FAILURE;
1574 return StatusCode::SUCCESS;
1579 return varSet.size() == 1 && *(varSet.begin()) ==
var;
1675 if (!eInfo)
return false;
1682 ATH_MSG_FATAL(
"Tool must be initialized before calling getValidity");
1704 ATH_MSG_ERROR(
"Asked for the validity of a set which scales multiple variables without specifying the variable of interest:" <<
m_groups.at(
index)->getName().Data());
1732 ATH_MSG_FATAL(
"Tool must be initialized before calling getUncertainty");
1758 ATH_MSG_ERROR(
"Asked for the uncertainty of a set which scales multiple variables without specifying the variable of interest:" <<
m_groups.at(
index)->getName().Data());
1779 if (!eInfo)
return false;
1786 ATH_MSG_FATAL(
"Tool must be initialized before calling getValidUncertainty");
1809 ATH_MSG_ERROR(
"Asked for the valid uncertainty of a set which scales multiple variables without specifying the variable of interest:" <<
m_groups.at(
index)->getName().Data());
1832 ATH_MSG_FATAL(
"Tool must be initialized before calling getNominalResolution");
1837 ATH_MSG_ERROR(
"The ResolutionHelper class was not created");
1850 ATH_MSG_ERROR(
"Parametrization involves mass but mass def is unknown");
1919 ATH_MSG_ERROR(
"Failed to read histogram due to unknown parametrization type in " <<
getName());
1936 if (caloRes == 0 || TARes == 0)
return 0;
1938 const double caloFactor = (caloRes == 0) ? 0 : 1./(caloRes*caloRes);
1939 const double TAFactor = ( TARes == 0) ? 0 : 1./(TARes*TARes);
1941 if (caloFactor + TAFactor == 0)
return 0;
1943 return caloFactor/(caloFactor+TAFactor);
1957 if (caloRes == 0 || TARes == 0)
return 0;
1959 const double caloFactor = 1./(caloRes*caloRes);
1960 const double TAFactor = 1./(TARes*TARes);
1962 if (caloFactor + TAFactor == 0)
return 0;
1964 return TAFactor/(caloFactor+TAFactor);
1977 ATH_MSG_FATAL(
"Tool must be initialized before calling getComponentCategories");
1985 for (
size_t iComp = 0; iComp <
m_groups.size(); ++iComp)
2000 ATH_MSG_FATAL(
"Tool must be initialized before calling getComponentsInCategory");
2013 std::vector<size_t> components;
2014 for (
size_t iComp = 0; iComp <
m_groups.size(); ++iComp)
2015 if (
m_groups.at(iComp)->getCategory() == categoryEnum)
2016 components.push_back(iComp);
2025 ATH_MSG_FATAL(
"Tool must be initialized before calling getComponentNamesInCategory");
2030 std::vector<std::string>
names;
2031 for (
size_t iComp = 0; iComp < components.size(); ++iComp)
2053 ATH_MSG_FATAL(
"Tool must be initialized before calling getCorrelationMatrix");
2057 std::cout <<
"Creating with max values " << valEta1 <<
" " << valEta2 << std::endl;
2073 ATH_MSG_FATAL(
"Tool must be initialized before calling getCorrelationMatrix");
2101 ATH_MSG_FATAL(
"Tool must be initialized before calling applyCorrection");
2113 std::vector< std::pair<CompScaleVar::TypeEnum,double> > uncSet;
2117 bool allValid =
true;
2118 for (
size_t iVar = 0; iVar < validitySet.size(); ++iVar)
2120 const bool validity = validitySet.at(iVar).second;
2136 bool hasMassRes =
false;
2137 bool hasPtRes =
false;
2138 bool hasFvRes =
false;
2145 ATH_MSG_ERROR(
"Varying both absolute and relative mass resolution components simultaneously is not supported");
2155 ATH_MSG_ERROR(
"Varying both absolute and relative pT resolution components simultaneously is not supported");
2165 ATH_MSG_ERROR(
"Varying both absolute and relative four-vector resolution components simultaneously is not supported");
2174 for (
size_t iVar = 0; iVar < uncSet.size(); ++iVar)
2178 const double shift = 1 + uncSet.at(iVar).second;
2179 const double smear = uncSet.at(iVar).second;
2183 double smearingFactor = 1;
2245 ATH_MSG_ERROR(
"Smearing the mass without specifying the topology is not supported");
2251 ATH_MSG_ERROR(
"Smearing the mass using multiple topology definitions is not supported");
2309 for (
size_t iJet = 0; iJet <
inputs.size(); ++iJet)
2328 static unsigned long long eventNum = 0;
2335 ATH_MSG_ERROR(
"Failed to retrieve default EventInfo object");
2340 if (eInfoObj && eventNum == eInfoConst->
eventNumber())
2350 eInfoObj = eInfoPair.first;
2351 eInfoAux = eInfoPair.second;
2361 ATH_MSG_ERROR(
"Failed to retrieve default NPV value from PrimaryVertices");
2369 for (itr = vertices->
begin(); itr != vertices->
end(); ++itr)
2370 if ( (*itr)->nTrackParticles() > 1)
2374 accNPV(*eInfoObj) = NPV;
2502 else if (variation < 0 && !m_resHelper->smearOnlyMC())
2508 const double sigmaNom =
std::max(sigmaMC,sigmaData);
2516 const double sigmaSmear = sqrt(
pow(sigmaNom + fabs(variation)*relativeFactor,2) -
pow(sigmaNom,2));
2520 ATH_MSG_ERROR(
"A seed of 1e5 times the jet phi is used in JetCalibTools so using it here leads to correlated smearing");
2530 if(seed == 0) seed =
m_isData ? 34545654 : 45583453;
2536 double smearingFactor = -1;
2537 while (smearingFactor < 0)
2538 smearingFactor =
m_rand.Gaus(1.,sigmaSmear);
2539 return smearingFactor;
2556 const float value = accD12(constJet);
2558 return StatusCode::SUCCESS;
2561 ATH_MSG_ERROR(
"Split12 moment (D12) is not available on the jet, please make sure to set Split12 before calling the tool");
2562 return StatusCode::FAILURE;
2572 const float value = accD23(constJet);
2574 return StatusCode::SUCCESS;
2577 ATH_MSG_ERROR(
"Split23 moment (D23) is not available on the jet, please make sure to set Split23 before calling the tool");
2578 return StatusCode::FAILURE;
2590 if (Tau21wasAvailable)
2594 ATH_MSG_ERROR(
"The Tau21 moment was previously available but is not available on this jet. This functionality is not supported.");
2595 return StatusCode::FAILURE;
2597 const float value = accTau21(constJet);
2599 return StatusCode::SUCCESS;
2601 if (TauNNwasAvailable)
2605 ATH_MSG_ERROR(
"The Tau2 and Tau1 moments were previously available but are not available on this jet. This functionality is not supported.");
2606 return StatusCode::FAILURE;
2608 const float tau2 = accTau2(constJet);
2609 const float tau1 = accTau1(constJet);
2610 accTau21(
jet) = fabs(tau1) > 1.e-6 ? shift*(tau2/tau1) : -999;
2611 return StatusCode::SUCCESS;
2626 ATH_MSG_ERROR(
"Neither Tau21 nor Tau1+Tau2 moments are available on the jet, please make sure one of these options is available before calling the tool.");
2627 return StatusCode::FAILURE;
2639 if (Tau32wasAvailable)
2643 ATH_MSG_ERROR(
"The Tau32 moment was previously available but is not available on this jet. This functionality is not supported.");
2644 return StatusCode::FAILURE;
2646 const float value = accTau32(constJet);
2648 return StatusCode::SUCCESS;
2650 if (TauNNwasAvailable)
2654 ATH_MSG_ERROR(
"The Tau3 and Tau2 moments were previously available but are not available on this jet. This functionality is not supported.");
2655 return StatusCode::FAILURE;
2657 const float tau3 = accTau3(constJet);
2658 const float tau2 = accTau2(constJet);
2659 accTau32(
jet) = fabs(tau2) > 1.e-6 ? shift*(tau3/tau2) : -999;
2660 return StatusCode::SUCCESS;
2675 ATH_MSG_ERROR(
"Neither Tau32 nor Tau2+Tau3 moments are available on the jet, please make sure one of these options is available before calling the tool");
2676 return StatusCode::FAILURE;
2687 static const bool Tau21wtawasAvailable = accTau21wta.
isAvailable(
jet);
2688 static const bool Tau21WTAwasAvailable = accTau21WTA.
isAvailable(
jet);
2693 if (Tau21wtawasAvailable)
2697 ATH_MSG_ERROR(
"The Tau21_wta moment was previously available but is not available on this jet. This functionality is not supported.");
2698 return StatusCode::FAILURE;
2700 const float value = accTau21wta(constJet);
2702 return StatusCode::SUCCESS;
2704 if (Tau21WTAwasAvailable)
2708 ATH_MSG_ERROR(
"The Tau21_WTA moment was previously available but is not available on this jet. This functionality is not supported.");
2709 return StatusCode::FAILURE;
2711 const float value = accTau21WTA(constJet);
2713 return StatusCode::SUCCESS;
2715 if (TauNNwtawasAvailable)
2719 ATH_MSG_ERROR(
"The Tau2_wta and Tau1_wta moments were previously available but are not available on this jet. This functionality is not supported.");
2720 return StatusCode::FAILURE;
2722 const float tau2 = accTau2wta(constJet);
2723 const float tau1 = accTau1wta(constJet);
2724 accTau21wta(
jet) = fabs(tau1) > 1.e-6 ? shift*(tau2/tau1) : -999;
2725 return StatusCode::SUCCESS;
2727 if (TauNNWTAwasAvailable)
2731 ATH_MSG_ERROR(
"The Tau2_WTA and Tau1_WTA moments were previously available but are not available on this jet. This functionality is not supported.");
2732 return StatusCode::FAILURE;
2734 const float tau2 = accTau2WTA(constJet);
2735 const float tau1 = accTau1WTA(constJet);
2736 accTau21WTA(
jet) = fabs(tau1) > 1.e-6 ? shift*(tau2/tau1) : -999;
2737 return StatusCode::SUCCESS;
2740 ATH_MSG_ERROR(
"Neither Tau21_wta nor Tau1_wta+Tau2_wta moments are available on the jet, please make sure one of these options is available before calling the tool");
2741 return StatusCode::FAILURE;
2751 static const bool Tau32wtawasAvailable = accTau32wta.
isAvailable(
jet);
2752 static const bool Tau32WTAwasAvailable = accTau32WTA.
isAvailable(
jet);
2757 if (Tau32wtawasAvailable)
2761 ATH_MSG_ERROR(
"The Tau32_wta moment was previously available but is not available on this jet. This functionality is not supported.");
2762 return StatusCode::FAILURE;
2764 const float value = accTau32wta(constJet);
2766 return StatusCode::SUCCESS;
2768 if (Tau32WTAwasAvailable)
2772 ATH_MSG_ERROR(
"The Tau32_WTA moment was previously available but is not available on this jet. This functionality is not supported.");
2773 return StatusCode::FAILURE;
2775 const float value = accTau32WTA(constJet);
2777 return StatusCode::SUCCESS;
2779 if (TauNNwtawasAvailable)
2783 ATH_MSG_ERROR(
"The Tau3_wta and Tau2_wta moments were previously available but are not available on this jet. This functionality is not supported.");
2784 return StatusCode::FAILURE;
2786 const float tau3 = accTau3wta(constJet);
2787 const float tau2 = accTau2wta(constJet);
2788 accTau32wta(
jet) = fabs(tau2) > 1.e-6 ? shift*(tau3/tau2) : -999;
2789 return StatusCode::SUCCESS;
2791 if (TauNNWTAwasAvailable)
2795 ATH_MSG_ERROR(
"The Tau3_WTA and Tau2_WTA moments were previously available but are not available on this jet. This functionality is not supported.");
2796 return StatusCode::FAILURE;
2798 const float tau3 = accTau3WTA(constJet);
2799 const float tau2 = accTau2WTA(constJet);
2800 accTau32WTA(
jet) = fabs(tau2) > 1.e-6 ? shift*(tau3/tau2) : -999;
2801 return StatusCode::SUCCESS;
2828 ATH_MSG_ERROR(
"Neither Tau32_wta nor Tau2_wta+Tau3_wta moments are available on the jet, please make sure one of these options is available before calling the tool");
2829 return StatusCode::FAILURE;
2846 ATH_MSG_ERROR(
"The D2 moment was previously available but is not available on this jet. This functionality is not supported.");
2847 return StatusCode::FAILURE;
2849 const float value = accD2(constJet);
2851 return StatusCode::SUCCESS;
2853 if (ECFwasAvailable)
2857 ATH_MSG_ERROR(
"The ECF1, ECF2, and ECF3 moments were previously available but are not available on this jet. This functionality is not supported.");
2858 return StatusCode::FAILURE;
2860 const float ecf1 = accECF1(constJet);
2861 const float ecf2 = accECF2(constJet);
2862 const float ecf3 = accECF3(constJet);
2863 accD2(
jet) = fabs(ecf2) > 1.e-6 ? shift * (
pow(ecf1/ecf2,3)*ecf3) : -999;
2864 return StatusCode::SUCCESS;
2882 ATH_MSG_ERROR(
"Neither D2 nor ECF1+ECF2+ECF3 moments are available on the jet, please make sure one of these options is available before calling the tool");
2883 return StatusCode::FAILURE;
2900 ATH_MSG_ERROR(
"The C2 moment was previously available but is not available on this jet. This functionality is not supported.");
2901 return StatusCode::FAILURE;
2903 const float value = accC2(constJet);
2905 return StatusCode::SUCCESS;
2907 if (ECFwasAvailable)
2911 ATH_MSG_ERROR(
"The ECF1, ECF2, and ECF3 moments were previously available but are not available on this jet. This functionality is not supported.");
2912 return StatusCode::FAILURE;
2914 const float ecf1 = accECF1(constJet);
2915 const float ecf2 = accECF2(constJet);
2916 const float ecf3 = accECF3(constJet);
2917 accC2(
jet) = fabs(ecf2) > 1.e-6 ? shift * (ecf3*ecf1/
pow(ecf2,2)) : -999;
2918 return StatusCode::SUCCESS;
2921 ATH_MSG_ERROR(
"Neither C2 nor ECF1+ECF2+ECF3 moments are available on the jet, please make sure one of these options is available before calling the tool");
2922 return StatusCode::FAILURE;
2932 const float value = accQw(constJet);
2934 return StatusCode::SUCCESS;
2937 ATH_MSG_ERROR(
"Qw moment is not available on the jet, please make sure to set Qw before calling the tool");
2938 return StatusCode::FAILURE;
2945 if (TagScaleFactorwasAvailable)
2949 ATH_MSG_ERROR(
"TagScaleFactor was previously available but is not available on this jet. This functionality is not supported.");
2950 return StatusCode::FAILURE;
2955 return StatusCode::SUCCESS;
2967 if ( shift*
value < 0.0 ){
2972 return StatusCode::SUCCESS;
2977 if ( shift*
value < 0.0 ){
2983 return StatusCode::SUCCESS;
2988 if ( shift*
value < 0.0 ){
2993 return StatusCode::SUCCESS;
2997 ATH_MSG_ERROR(
"TagScaleFactor is not available on the jet, please make sure you called BoostedJetTaggers tag() function before calling this function.");
2998 return StatusCode::FAILURE;
3005 if (TagScaleFactorwasAvailable)
3009 ATH_MSG_ERROR(
"TagScaleFactor was previously available but is not available on this jet. This functionality is not supported.");
3010 return StatusCode::FAILURE;
3015 return StatusCode::SUCCESS;
3022 float sigeffSF = 1.0;
3023 float updated_efficiency =
efficiency + shift;
3025 if ( updated_efficiency < 1
e-5 ) updated_efficiency=1
e-5;
3026 if ( updated_efficiency > 1.0-1
e-5 ) updated_efficiency=1.0-1
e-5;
3033 return StatusCode::SUCCESS;
3037 if ( std::abs(effSF - 1.0) < 1
e-5 && std::abs(shift)>0 ) {
3042 float variatedIneffSFsig = (1. - sigeffSF*updated_efficiency)/(1. - updated_efficiency);
3047 return StatusCode::SUCCESS;
3052 return StatusCode::SUCCESS;
3056 ATH_MSG_ERROR(
"TagScaleFactor is not available on the jet, please make sure you called BoostedJetTaggers tag() function before calling this function.");
3057 return StatusCode::FAILURE;