27 m_nominal(
CP::SystematicSet()) {
32 ATH_MSG_INFO(
" top::BTagScaleFactorCalculator initialize");
35 for (
const std::string&
WP :
m_config->bTagWP_calib()) {
41 std::set<std::string> base_names =
m_systs[
WP].getBaseNames();
46 for (
const std::string&
WP :
m_config->bTagWP_calib_trkJet()) {
53 m_config->setBTaggingSFSysts(
WP, base_names,
true);
57 return StatusCode::SUCCESS;
62 "Failed to apply btagging SFs");
64 "Failed to apply track jet btagging SFs");
66 return StatusCode::SUCCESS;
70 std::string> >& jet_syst_collections,
74 for (
auto currentSystematic : *jet_syst_collections) {
80 for (
auto jetPtr : *
jets) {
81 bool passSelection(
false);
82 if (jetPtr->isAvailable<
char>(
"passPreORSelection")) {
83 if (jetPtr->auxdataConst<
char>(
"passPreORSelection") == 1) {
87 if (jetPtr->isAvailable<
char>(
"passPreORSelectionLoose")) {
88 if (jetPtr->auxdataConst<
char>(
"passPreORSelectionLoose") == 1) {
96 for (
const std::string& tagWP : (use_trackjets ?
m_config->bTagWP_calib_trkJet() :
m_config->bTagWP_calib())) {
97 ToolHandle<IBTaggingEfficiencyTool>& btageff =
99 ToolHandle<IBTaggingSelectionTool>& btagsel =
104 unsigned int MapIndex =
m_config->getMapIndex();
106 btageff->setMapIndex(
"Light", MapIndex);
107 btageff->setMapIndex(
"C", MapIndex);
108 btageff->setMapIndex(
"B", MapIndex);
109 btageff->setMapIndex(
"T", MapIndex);
115 if (bTagSystName !=
"") {
118 top::check(btageff->applySystematicVariation(bTagSyst),
119 "Failed to set new b-tagging SF to a shifted systematic set : " + bTagSystName);
122 "Failed to set new b-tagging SF to nominal");
126 bool isTagged =
false;
127 if (std::fabs(jetPtr->eta()) <= 2.5) {
128 if (tagWP.find(
"Continuous") == std::string::npos) {
129 isTagged =
static_cast<bool>(btagsel->accept(*jetPtr));
130 if (isTagged)
top::check(btageff->getScaleFactor(*jetPtr, btag_SF),
131 "Failed to get nominal b-tagging SF");
132 else top::check(btageff->getInefficiencyScaleFactor(*jetPtr, btag_SF),
133 "Failed to get nominal b-tagging SF");
135 top::check(btageff->getScaleFactor(*jetPtr, btag_SF),
136 "Failed to get nominal Continuous b-tagging SF");
139 jetPtr->auxdecor<
float>(
"btag_SF_" + tagWP +
"_nom") = btag_SF;
142 if (currentSystematic.first ==
m_config->nominalHashValue()) {
143 for (
const auto& variation : sysSet) {
146 syst_set.
insert(variation);
147 top::check(btageff->applySystematicVariation(syst_set),
148 "Failed to set new b-tagging systematic variation " + syst_set.
name());
149 if (std::fabs(jetPtr->eta()) <= 2.5) {
150 if (tagWP.find(
"Continuous") == std::string::npos) {
151 if (isTagged)
top::check(btageff->getScaleFactor(*jetPtr, btag_SF),
152 "Failed to get b-tagging SF for variation " + syst_set.
name());
153 else top::check(btageff->getInefficiencyScaleFactor(*jetPtr, btag_SF),
154 "Failed to get b-tagging SF for variation " + syst_set.
name());
156 top::check(btageff->getScaleFactor(*jetPtr, btag_SF),
157 "Failed to get Continuous b-tagging SF for variation " + syst_set.
name());
160 jetPtr->auxdecor<
float>(
"btag_SF_" + tagWP +
"_" + variation.name()) = btag_SF;
169 return StatusCode::SUCCESS;
173 ATH_MSG_INFO(
"BTagScaleFactorCalculator::debug function");
175 for (
const std::string& tagWP :
m_config->bTagWP()) {
177 ToolHandle<IBTaggingEfficiencyTool>& btageff =
m_btagEffTools[tagWP];
179 top::check(btageff.retrieve(),
"Failed to retrieve tool");
184 ATH_MSG_INFO(
"-----------------------------------------------------------------------");
187 std::vector<std::string> > allowed_variations = btageff->listSystematics();
189 ATH_MSG_INFO(
"Allowed systematics variations for tool " << btageff->name());
190 for (
auto var : allowed_variations) {
191 std::string flvs =
"";
192 for (
auto flv :
var.second) flvs += flv;
198 ATH_MSG_INFO(
"-----------------------------------------------------------------------");
199 ATH_MSG_INFO(
"List of b-tagging scale factor systematics");
200 std::map<std::string,
201 std::vector<std::string> > listOfScaleFactorSystematics = btageff->listScaleFactorSystematics(
false);
202 for (
auto var : listOfScaleFactorSystematics) {
204 std::vector<std::string> systs =
var.second;
205 std::sort(systs.begin(), systs.end());
206 for (
const auto&
sys : systs) {
212 ATH_MSG_INFO(
"List of (named) b-tagging scale factor systematics");
213 listOfScaleFactorSystematics = btageff->listScaleFactorSystematics(
true);
214 for (
auto var : listOfScaleFactorSystematics) {
216 std::vector<std::string> systs =
var.second;
217 std::sort(systs.begin(), systs.end());
218 for (
const auto&
sys : systs) {
223 ATH_MSG_INFO(
"-----------------------------------------------------------------------");
225 return StatusCode::SUCCESS;