ATLAS Offline Software
Loading...
Searching...
No Matches
BTaggingLargeREfficiencyJsonTool Class Reference

#include <BTaggingLargeREfficiencyJsonTool.h>

Inheritance diagram for BTaggingLargeREfficiencyJsonTool:

Classes

class  LargeRMCMCHandler
struct  sysData

Public Member Functions

 BTaggingLargeREfficiencyJsonTool (const std::string &name)
virtual ~BTaggingLargeREfficiencyJsonTool ()
StatusCode initialize () override
 Dummy implementation of the initialisation function.
virtual CP::CorrectionCode getScaleFactor (const xAOD::Jet &jet, float &scalefactor, const CP::SystematicSet &sys) const override
virtual CP::SystematicSet affectingSystematics () const override
 the list of all systematics this tool can be affected by
virtual CP::SystematicSet recommendedSystematics () const override
 the list of all systematics this tool recommends to use
virtual void print () const
 Print the state of the tool.
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysInitialize () override
 Perform system initialization for an algorithm.
virtual StatusCode sysStart () override
 Handle START transition.
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles.
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles.
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T, V, H > &t)
void updateVHKA (Gaudi::Details::PropertyBase &)
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const
Additional helper functions, not directly mimicking Athena
template<class T>
const T * getProperty (const std::string &name) const
 Get one of the tool's properties.
const std::string & msg_level_name () const __attribute__((deprecated))
 A deprecated function for getting the message level's name.
const std::string & getName (const void *ptr) const
 Get the name of an object that is / should be in the event store.
SG::sgkey_t getKey (const void *ptr) const
 Get the (hashed) key of an object that is in the event store.

Protected Member Functions

void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed.

Private Types

typedef ServiceHandle< StoreGateSvc > StoreGateSvc_t

Private Member Functions

StatusCode calcSystematicVariation (const CP::SystematicSet &systConfig, sysData &mySys) const
float getSFSys (const std::string &label, size_t bin_index) const
CP::CorrectionCode getMCToMCCorr (const xAOD::Jet &jet, float &corr) const
float getJetPtInGeV (const xAOD::Jet &jet) const
float getJetMassInGeV (const xAOD::Jet &jet) const
float getJetQuantity (const xAOD::Jet &jet, const BTaggingToolUtil::varType vType) const
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

bool m_initialised = false
Gaudi::Property< std::string > m_outputName {this, "OutputName", "", "Output name of the tagger"}
Gaudi::Property< std::string > m_OP {this, "OperatingPoint", "", "Operating point"}
Gaudi::Property< std::string > m_jetAuthor {this, "JetAuthor", "", "Jet collection"}
Gaudi::Property< std::string > m_json_config_path {this, "JsonConfigFile", "", "Path to JSON config file"}
Gaudi::Property< std::string > m_mcGenerator {this, "MCGenerator", "", "Name of the MC generator of the sample being processed (required for MC-MC scale factor)"}
Gaudi::Property< float > m_minPt {this, "MinPt", -1 , "Minimum jet pT cut (in MeV)"}
Gaudi::Property< float > m_maxEta {this, "MaxEta", 2.5, "Maximum jet eta cut"}
nlohmann::ordered_json m_json_config
std::map< int, std::string > m_labelMap
std::map< int, std::string > m_labelMapMCMC
ToolHandle< IBTaggingLargeRSelectionJsonTool > m_selTool
 Access to a BTaggingLargeRSelectionJsonTool.
std::unique_ptr< BTaggingBoundsHandler::JetQuantityGetter > m_funcGetJetQuantity
std::map< std::string, std::vector< float > > m_sfMap
std::map< std::string, std::vector< float > > m_sfPtMap
std::map< std::string, std::map< std::string, std::vector< float > > > m_sfSysMap
std::map< std::string, std::string > m_mcReference
std::map< std::string, BTaggingGridBoundsHandler< LargeRMCMCHandler > > m_mcmcHandlers
std::unique_ptr< SG::ConstAccessor< int > > m_truthLabelAcc
std::unique_ptr< SG::ConstAccessor< float > > m_massAcc
std::unique_ptr< SG::ConstAccessor< float > > m_ptAcc
CP::SystematicsCache< sysData > m_sysCache {this}
const sysData * m_currentSys {nullptr}
StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default).
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default).
std::vector< SG::VarHandleKeyArray * > m_vhka
bool m_varHandleArraysDeclared

Detailed Description

Definition at line 29 of file BTaggingLargeREfficiencyJsonTool.h.

Member Typedef Documentation

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< AlgTool > >::StoreGateSvc_t
privateinherited

Definition at line 376 of file AthCommonDataStore.h.

Constructor & Destructor Documentation

◆ BTaggingLargeREfficiencyJsonTool()

BTaggingLargeREfficiencyJsonTool::BTaggingLargeREfficiencyJsonTool ( const std::string & name)

Definition at line 11 of file BTaggingLargeREfficiencyJsonTool.cxx.

11 :
12 asg::AsgTool ( name )
13{
14 m_initialised = false;
15
16 declareProperty("btagSelectionJsonTool", m_selTool, "Xbb JSON selection tool");
17}
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ToolHandle< IBTaggingLargeRSelectionJsonTool > m_selTool
Access to a BTaggingLargeRSelectionJsonTool.

◆ ~BTaggingLargeREfficiencyJsonTool()

BTaggingLargeREfficiencyJsonTool::~BTaggingLargeREfficiencyJsonTool ( )
virtual

Definition at line 19 of file BTaggingLargeREfficiencyJsonTool.cxx.

19 {
20}

Member Function Documentation

◆ affectingSystematics()

CP::SystematicSet BTaggingLargeREfficiencyJsonTool::affectingSystematics ( ) const
overridevirtual

the list of all systematics this tool can be affected by

Implements CP::IReentrantSystematicsTool.

Definition at line 471 of file BTaggingLargeREfficiencyJsonTool.cxx.

472{
473 CP::SystematicSet affectingSystematics;
474 affectingSystematics.insert(CP::SystematicVariation("BTagging_Xbb_SYST", 1));
475 affectingSystematics.insert(CP::SystematicVariation("BTagging_Xbb_SYST", -1));
476
478}
virtual CP::SystematicSet affectingSystematics() const override
the list of all systematics this tool can be affected by

◆ calcSystematicVariation()

StatusCode BTaggingLargeREfficiencyJsonTool::calcSystematicVariation ( const CP::SystematicSet & systConfig,
sysData & mySys ) const
private

Definition at line 463 of file BTaggingLargeREfficiencyJsonTool.cxx.

464{
465 CP::SystematicVariation syst = systConfig.getSystematicByBaseName("BTagging_Xbb_SYST");
466 sys.xbb_syst = syst.parameter();
467
468 return StatusCode::SUCCESS;
469}
SystematicVariation getSystematicByBaseName(const std::string &basename) const
description: get the first systematic matching basename
float parameter() const
description: the numeric parameter contained in the subvariation(), or 0 if the subvariation can't be...

◆ declareGaudiProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareGaudiProperty ( Gaudi::Property< T, V, H > & hndl,
const SG::VarHandleKeyType &  )
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158 {
160 hndl.value(),
161 hndl.documentation());
162
163 }

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty ( Gaudi::Property< T, V, H > & t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145 {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>

◆ detStore()

const ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

◆ evtStore()

ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase & ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ getJetMassInGeV()

float BTaggingLargeREfficiencyJsonTool::getJetMassInGeV ( const xAOD::Jet & jet) const
private

Definition at line 353 of file BTaggingLargeREfficiencyJsonTool.cxx.

354{
355 // Convert mass from MeV to GeV
356 if (!m_massAcc) {
357 return BTaggingToolUtil::MeVToGeV( jet.m() );
358 }
359 if (!m_massAcc->isAvailable(jet)) {
360 ATH_MSG_ERROR("Decorated mass '" << SG::AuxTypeRegistry::instance().getName( m_massAcc->auxid() ) << "' not available on jet. Cannot proceed.");
361 throw std::runtime_error("Decorated mass not available on jet.");
362 }
363 return BTaggingToolUtil::MeVToGeV( (*m_massAcc)(jet) );
364}
#define ATH_MSG_ERROR(x,...)
std::unique_ptr< SG::ConstAccessor< float > > m_massAcc
static double MeVToGeV(const double x)
static AuxTypeRegistry & instance()
Return the singleton registry instance.
const std::string & getName(const void *ptr) const
Get the name of an object that is / should be in the event store.
Definition AsgTool.cxx:106

◆ getJetPtInGeV()

float BTaggingLargeREfficiencyJsonTool::getJetPtInGeV ( const xAOD::Jet & jet) const
private

Definition at line 366 of file BTaggingLargeREfficiencyJsonTool.cxx.

367{
368 // Convert pT from MeV to GeV
369 if (!m_ptAcc) {
370 return BTaggingToolUtil::MeVToGeV( jet.pt() );
371 }
372
373 if (!m_ptAcc->isAvailable(jet)) {
374 ATH_MSG_ERROR("Decorated pT '" << SG::AuxTypeRegistry::instance().getName( m_ptAcc->auxid() ) << "' not available on jet. Cannot proceed.");
375 throw std::runtime_error("Decorated pT not available on jet.");
376 }
377
378 return BTaggingToolUtil::MeVToGeV( (*m_ptAcc)(jet) );
379}
std::unique_ptr< SG::ConstAccessor< float > > m_ptAcc

◆ getJetQuantity()

float BTaggingLargeREfficiencyJsonTool::getJetQuantity ( const xAOD::Jet & jet,
const BTaggingToolUtil::varType vType ) const
private

Definition at line 381 of file BTaggingLargeREfficiencyJsonTool.cxx.

381 {
382 if (vType == BTaggingToolUtil::varType::pT) {
383 return getJetPtInGeV(jet);
384 } else if (vType == BTaggingToolUtil::varType::mass) {
385 return getJetMassInGeV(jet);
386 } else if (vType == BTaggingToolUtil::varType::eta) {
387 return jet.eta();
388 } else if (vType == BTaggingToolUtil::varType::abseta) {
389 return std::abs(jet.eta());
390 } else {
391 ATH_MSG_ERROR("Unsupported jet variable quantity requested: '" << BTaggingToolUtil::getVariableName(vType) << "'");
392 throw std::runtime_error("BTaggingLargeREfficiencyJsonTool::getJetQuantity unsupported jet variable: '" + BTaggingToolUtil::getVariableName(vType) + "'");
393 }
394}
float getJetPtInGeV(const xAOD::Jet &jet) const
float getJetMassInGeV(const xAOD::Jet &jet) const
static std::string getVariableName(const varType vType)

◆ getKey()

SG::sgkey_t asg::AsgTool::getKey ( const void * ptr) const
inherited

Get the (hashed) key of an object that is in the event store.

This is a bit of a special one. StoreGateSvc and xAOD::Event both provide ways for getting the SG::sgkey_t key for an object that is in the store, based on a bare pointer. But they provide different interfaces for doing so.

In order to allow tools to efficiently perform this operation, they can use this helper function.

See also
asg::AsgTool::getName
Parameters
ptrThe bare pointer to the object that the event store should know about
Returns
The hashed key of the object in the store. If not found, an invalid (zero) key.

Definition at line 119 of file AsgTool.cxx.

119 {
120
121#ifdef XAOD_STANDALONE
122 // In case we use @c xAOD::Event, we have a direct function call
123 // for this.
124 return evtStore()->event()->getKey( ptr );
125#else
126 const SG::DataProxy* proxy = evtStore()->proxy( ptr );
127 return ( proxy == nullptr ? 0 : proxy->sgkey() );
128#endif // XAOD_STANDALONE
129 }
ServiceHandle< StoreGateSvc > & evtStore()

◆ getMCToMCCorr()

CP::CorrectionCode BTaggingLargeREfficiencyJsonTool::getMCToMCCorr ( const xAOD::Jet & jet,
float & corr ) const
private

Definition at line 292 of file BTaggingLargeREfficiencyJsonTool.cxx.

293{
294 if (! m_initialised) {
295 throw std::runtime_error("BTaggingLargeREfficiencyJsonTool has not been initialised.");
296 }
297
298 corr = 1.0;
299
300 // If MC-MC handlers map is empty it means the JSON file does not contain MC-MC scale factors
301 // Hence exiting directly from the function
302 if (m_mcmcHandlers.empty()) {
304 }
305
306 // Retrieve jet truth labelling
307 // and check if a string label is associated to it
308 // e.g. truthLabel integer is associated to fully-contained top->qqb and the corresponding string label could be "Top" for instance
309 int truthLabel = (*m_truthLabelAcc)(jet);
310 auto labelIt = m_labelMapMCMC.find(truthLabel);
311 if (labelIt == m_labelMapMCMC.end()) {
312 ATH_MSG_WARNING("No mc-to-mc correction on jet with truthLabel: " << truthLabel << ". Returning scale factor of 1.");
313 return CP::CorrectionCode::OutOfValidityRange; // this process has no mc-to-mc correction
314 }
315
316 const std::string& label = labelIt->second;
317 auto handlerIt = m_mcmcHandlers.find(label);
318 if (handlerIt == m_mcmcHandlers.end()) {
319 // If the generator of the sample processed is the same as the generator of the reference sample for the given label
320 // then the map of MC-MC handler is not filled for that label (check happening in the initialize function)
321 // Thus exiting here as the generator of the sample being processed is the same generator as the one used for the calibration
323 }
324
325 // Retrieve the pointer to the hander in which the jet is falling
326 // if the jet is outside of the range then handler will be a null pointer
327 const LargeRMCMCHandler * handler = handlerIt->second.getHandlerPtr(jet);
328 if (!handler){
329 ATH_MSG_WARNING("Jet outside mc-to-mc binning for label " << label << ". Returning correction of 1.");
331 }
332
333 // To print the handler content
334 // std::cout << "handler=" << handler->to_string() << std::endl;
335
336 // Retrieve the corresponding MC-MC scale factor
337 const bool isTagged = (m_selTool->accept(jet) == 1);
338 corr = handler->getScaleFactor(isTagged);
340}
#define ATH_MSG_WARNING(x,...)
std::map< std::string, BTaggingGridBoundsHandler< LargeRMCMCHandler > > m_mcmcHandlers
@ OutOfValidityRange
Input object is out of validity range.
@ Ok
The correction was done successfully.
std::string label(const std::string &format, int i)
Definition label.h:19
void handler(int sig)
signal handler
Definition rmain.cxx:100

◆ getName()

const std::string & asg::AsgTool::getName ( const void * ptr) const
inherited

Get the name of an object that is / should be in the event store.

This is a bit of a special one. StoreGateSvc and xAOD::Event both provide ways for getting the std::string name for an object that is in the store, based on a bare pointer. But they provide different interfaces for doing so.

In order to allow tools to efficiently perform this operation, they can use this helper function.

See also
asg::AsgTool::getKey
Parameters
ptrThe bare pointer to the object that the event store should know about
Returns
The string name of the object in the store. If not found, an empty string.

Definition at line 106 of file AsgTool.cxx.

106 {
107
108#ifdef XAOD_STANDALONE
109 // In case we use @c xAOD::Event, we have a direct function call
110 // for this.
111 return evtStore()->event()->getName( ptr );
112#else
113 const SG::DataProxy* proxy = evtStore()->proxy( ptr );
114 static const std::string dummy = "";
115 return ( proxy == nullptr ? dummy : proxy->name() );
116#endif // XAOD_STANDALONE
117 }

◆ getProperty()

template<class T>
const T * asg::AsgTool::getProperty ( const std::string & name) const
inherited

Get one of the tool's properties.

◆ getScaleFactor()

CP::CorrectionCode BTaggingLargeREfficiencyJsonTool::getScaleFactor ( const xAOD::Jet & jet,
float & scalefactor,
const CP::SystematicSet & sys ) const
overridevirtual

Implements IBTaggingLargeREfficiencyJsonTool.

Definition at line 235 of file BTaggingLargeREfficiencyJsonTool.cxx.

236{
237 if (! m_initialised) {
238 throw std::runtime_error("BTaggingLargeREfficiencyJsonTool has not been initialised.");
239 }
240
241 sf = 1.0;
242
243 int truthLabel = (*m_truthLabelAcc)(jet);
244 std::string labelString;
245 auto it = m_labelMap.find(truthLabel);
246 if (it != m_labelMap.end()) {
247 labelString = it->second;
248 } else {
249 ATH_MSG_WARNING("No calibration on jet with truthLabel: " << truthLabel << ". Returning scale factor of 1.");
251 }
252
253 if (!m_sfPtMap.contains(labelString)) {
254 ATH_MSG_WARNING("No calibration on jet with truthLabel: " << truthLabel << ". Returning scale factor of 1.");
256 }
257 const auto& pts = m_sfPtMap.at(labelString);
258 size_t bin_index = pts.size();
259 if (getJetPtInGeV(jet) < pts[0]) {
260 ATH_MSG_WARNING("No calibration for jet with pt: " << getJetPtInGeV(jet) << ". Returning scale factor of 1.");
262 }
263 for (size_t i = 1; i < pts.size(); i++) {
264 if (getJetPtInGeV(jet) < pts[i]) {
265 bin_index = i-1;
266 break;
267 }
268 }
269
270 const auto& SFs = m_sfMap.at(labelString);
271 if (bin_index >= SFs.size()) {
272 ATH_MSG_WARNING("No calibration for jet with pt: " << getJetPtInGeV(jet) << ". Returning scale factor of 1.");
274 }
275
276 sf = SFs[bin_index];
277
278 float corr = 1.;
279 CP::CorrectionCode worstCorrectionCode = CP::CorrectionCode::Ok;
280 CP::CorrectionCode ccMCMC = getMCToMCCorr(jet, corr);
281 worstCorrectionCode = std::min(worstCorrectionCode, ccMCMC);
282 sf *= corr;
283
284 sysData tempSys;
285 if (calcSystematicVariation(sys, tempSys) == StatusCode::SUCCESS && tempSys.xbb_syst != 0) {
286 sf += tempSys.xbb_syst * getSFSys(labelString, bin_index);
287 }
288
289 return worstCorrectionCode;
290}
float getSFSys(const std::string &label, size_t bin_index) const
std::map< std::string, std::vector< float > > m_sfMap
std::map< std::string, std::vector< float > > m_sfPtMap
StatusCode calcSystematicVariation(const CP::SystematicSet &systConfig, sysData &mySys) const
CP::CorrectionCode getMCToMCCorr(const xAOD::Jet &jet, float &corr) const

◆ getSFSys()

float BTaggingLargeREfficiencyJsonTool::getSFSys ( const std::string & label,
size_t bin_index ) const
private

Definition at line 342 of file BTaggingLargeREfficiencyJsonTool.cxx.

343{
344 float result = 0.0;
345 const auto& systematics = m_sfSysMap.at(labelString);
346 for (auto& [systematicName, values] : systematics){
347 float sys_value = values.at(bin_index);
348 result += sys_value*sys_value;
349 }
350 return std::sqrt(result);
351}
static const std::vector< std::string > systematics
std::map< std::string, std::map< std::string, std::vector< float > > > m_sfSysMap

◆ initialize()

StatusCode BTaggingLargeREfficiencyJsonTool::initialize ( void )
overridevirtual

Dummy implementation of the initialisation function.

It's here to allow the dual-use tools to skip defining an initialisation function. Since many are doing so...

Reimplemented from asg::AsgTool.

Definition at line 22 of file BTaggingLargeREfficiencyJsonTool.cxx.

23{
24 if (m_minPt > 0.){
25 // Convert MeV cut to GeV as in the JSON files numbers are in GeV
27 }
28
29 // Getter of the jet quantities used by the handlers to check if the jet falls into their bounds
30 m_funcGetJetQuantity = std::make_unique<BTaggingBoundsHandler::JetQuantityGetter>(
32
33 // Retrieve selection tool
34 ATH_MSG_INFO("Initialize BTagging Efficiency Json Tool: retrieving corresponding selection tool");
35 ANA_CHECK (m_selTool.retrieve());
36
37 ATH_MSG_INFO("Initialize BTagging Efficiency Json Tool from: " + m_json_config_path);
38 std::string pathToJsonConfigFile = PathResolverFindCalibFile(m_json_config_path);
39 std::ifstream jsonFile(pathToJsonConfigFile);
40
41 if (!jsonFile.is_open()) {
42 ATH_MSG_ERROR( "JSON file " + m_json_config_path + " does not exist. Please put the correct path of the file." );
43 return StatusCode::FAILURE;
44 }
45 m_json_config = json::parse(jsonFile);
46 jsonFile.close();
47
48 if (m_outputName.empty() || !m_json_config.contains(m_outputName)){
49 ATH_MSG_ERROR( "The output name " + m_outputName + " not found in JSON file: " + m_json_config_path );
50 return StatusCode::FAILURE;
51 }
52
53 if (m_jetAuthor.empty() || !m_json_config[m_outputName].contains(m_jetAuthor)){
54 ATH_MSG_ERROR( "Tagger: " +m_outputName+ " and Jet Collection: " +m_jetAuthor+ " not found in JSON file: " +m_json_config_path );
55 return StatusCode::FAILURE;
56 }
57
58 if (m_OP.empty() || !m_json_config[m_outputName][m_jetAuthor].contains(m_OP)){
59 ATH_MSG_ERROR( "OP " +m_OP+ " not available for " +m_outputName+ " tagger.");
60 return StatusCode::FAILURE;
61 }
62
63 const auto& meta = m_json_config[m_outputName][m_jetAuthor]["meta"];
64 const std::string truthLabel = meta["TruthLabel"];
65 m_truthLabelAcc = std::make_unique<SG::ConstAccessor<int>>(truthLabel);
66
67 // map truth labels to categories for scale factors
68 // NB: MC-MC scale factors have a dedicated truth label to categories mapping
69 if (meta.contains("labelMapping")) {
70 for (auto& el : meta["labelMapping"].items()) {
71 std::string label = el.key();
72 for (const auto& num : el.value()) {
73 int key = num;
75 }
76 }
77 } else {
78 ATH_MSG_WARNING("No 'labelMapping' defined in JSON.");
79 }
80
81 // map truth labels to categories for MC-MC scale factors
82 if (meta.contains("labelMappingMCMC")) {
83 for (auto& el : meta["labelMappingMCMC"].items()) {
84 std::string label = el.key();
85 for (const auto& num : el.value()) {
86 int key = num;
88 }
89 }
90 } else {
91 ATH_MSG_WARNING("No 'labelMappingMCMC' defined in JSON.");
92 }
93
94 // Get mass decorator if specified
95 if (meta.contains("Mass")) {
96 std::string massDecoratorName = meta["Mass"].get<std::string>();
97 if (massDecoratorName != "default") {
98 m_massAcc = std::make_unique<SG::ConstAccessor<float>>(massDecoratorName);
99 ATH_MSG_INFO("Using decorated mass '" << massDecoratorName << "' for Efficiency SF.");
100 }
101 }
102
103 if (meta.contains("PT")) {
104 std::string ptDecoratorName = meta["PT"].get<std::string>();
105 if (ptDecoratorName != "default") {
106 m_ptAcc = std::make_unique<SG::ConstAccessor<float>>(ptDecoratorName);
107 ATH_MSG_INFO("Using decorated pT '" << ptDecoratorName << "' for Efficiency SF.");
108 }
109 }
110 // preload pt bins, systematics and SFs for each category
111 const auto& json_config_OP = m_json_config[m_outputName][m_jetAuthor][m_OP];
112 if (json_config_OP.contains("data_mc")) {
113 if (!meta.contains("labelMapping")) {
114 ATH_MSG_ERROR("JSON contains data-mc scale factors but no 'labelMapping'.");
115 return StatusCode::FAILURE;
116 }
117 for (const auto& label : meta["labelMapping"].items()) {
118 std::string labelString = label.key();
119 if (json_config_OP["data_mc"].contains(labelString)) {
120 for (const auto& pt : json_config_OP["data_mc"][labelString]["pt"]) {
121 m_sfPtMap[labelString].push_back(BTaggingToolUtil::getExtendedFloat(pt));
122 }
123
124 m_sfMap[labelString] = json_config_OP["data_mc"][labelString]["nominal"].get<std::vector<float>>();
125 for (auto& [systematicName, values] : json_config_OP["data_mc"][labelString]["systematics"].items()){
126 m_sfSysMap[labelString][systematicName] = values.get<std::vector<float>>();
127 }
128 }
129 }
130 } else {
131 ATH_MSG_WARNING("No calibration data-mc scale factors present in json.");
132 }
133
134 if (meta.contains("labelMappingMCMC") && !json_config_OP.contains("mc_mc")) {
135 ATH_MSG_ERROR("JSON contains labelMappingMCMC but no mc-mc entry found for the WP used.");
136 return StatusCode::FAILURE;
137 }
138
139 if (json_config_OP.contains("mc_mc")) {
140 // Get the MC-MC json configuration related config
141 const auto &json_config_OPMCMC = json_config_OP["mc_mc"];
142
143 if (!meta.contains("labelMappingMCMC")) {
144 ATH_MSG_ERROR("JSON contains mc-to-mc corrections but no 'labelMappingMCMC'.");
145 return StatusCode::FAILURE;
146 }
147 if (!json_config_OPMCMC.contains("corrections")){
148 ATH_MSG_ERROR("No mc-to-mc corrections in JSON.");
149 return StatusCode::FAILURE;
150 }
151
152 if (!m_mcGenerator.value().empty()) {
153 // JSON file contains mc-to-mc corrections and user provided the mc generator
154 // Hence retrieving relevant MC-MC information from the JSON file
155 for (const auto& label : meta["labelMappingMCMC"].items()) {
156 std::string labelStringMCMC = label.key();
157
158 if (!json_config_OPMCMC["corrections"].contains(labelStringMCMC)) {
159 ATH_MSG_ERROR("JSON file contains labelStringMCMC=" << labelStringMCMC << " but no corresponding MC-MC SF found in the file");
160 return StatusCode::FAILURE;
161 }
162 // Retrieve the corrections associted to the label string
163 const auto& mcmcAtLabel = json_config_OPMCMC["corrections"][labelStringMCMC];
164 if (mcmcAtLabel.contains("reference")) {
165 // Retrieve the reference generator used for the calibration
166 m_mcReference[labelStringMCMC] = mcmcAtLabel["reference"];
167
168 // If the MC generator of the sample being processed is the same as the reference MC generator
169 // Then there is no MC-MC scale factor to be applied as processing the same MC generator as used for the calibration
170 // Hence skipping the rest
171 if (m_mcGenerator.value() == m_mcReference.at(labelStringMCMC)) continue;
172
173 // Make sure the generator associated to the sample being processed is provided
174 if (!mcmcAtLabel.contains(m_mcGenerator.value())) {
175 ATH_MSG_ERROR("No mc-to-mc corrections for generator '" << m_mcGenerator.value() << "' and label " << labelStringMCMC);
176 return StatusCode::FAILURE;
177 }
178
179 // Vector of MC-MC handler that will be filled in the loop below
180 std::vector<LargeRMCMCHandler> tmpVecLargeRMCMCHandler;
181 for (const auto& entry : mcmcAtLabel[m_mcGenerator.value()]) {
182 try {
183 tmpVecLargeRMCMCHandler.push_back(LargeRMCMCHandler(entry, m_funcGetJetQuantity.get()));
184 // // Useful for debugging
185 // // Get the latest handler that was just added
186 // const LargeRMCMCHandler &handler = tmpVecLargeRMCMCHandler[tmpVecLargeRMCMCHandler.size() -1];
187 // // Then print its content
188 // std::cout << "labelStringMCMC=" << labelStringMCMC << ": " << handler << std::endl;
189 } catch (const std::exception& e) {
190 ATH_MSG_ERROR("Malformed mc-to-mc correction for label " << labelStringMCMC
191 << " and generator '" << m_mcGenerator.value() << "': " << e.what());
192 return StatusCode::FAILURE;
193 }
194 }
195
196 const std::string context = "MC-MC GridBoundsHandler initialization for label='" + labelStringMCMC + "' and generator='" + m_mcGenerator.value() + "'";
197 // Finally add the grid of handlers to the map of MC-MC handlers
198 // If any exception is thrown return failure
199 try {
200 m_mcmcHandlers.emplace(labelStringMCMC, BTaggingGridBoundsHandler<LargeRMCMCHandler>(context, std::move(tmpVecLargeRMCMCHandler)));
201 } catch (const std::exception& e) {
202 ATH_MSG_ERROR(e.what());
203 return StatusCode::FAILURE;
204 }
205
206 } else {
207 ATH_MSG_ERROR("mc-to-mc corrections incomplete for jet with truthLabel: " << labelStringMCMC << ".");
208 return StatusCode::FAILURE;
209 }
210 }
211 } else {
212 // The JSON file contains MC-MC scale factors but the user did not provide the MC Generator of the sample processed
213 ATH_MSG_ERROR("No mc generator passed to the tool. Please provide the mc generator for the mc-to-mc corrections.");
214 return StatusCode::FAILURE;
215 }
216 } else {
217 // No mc-to-mc corrections present in the given json file.
218 ATH_MSG_WARNING("No mc-to-mc corrections present in json.");
219 }
220
221
222 m_currentSys = nullptr;
223 m_sysCache.initialize(affectingSystematics(),
224 [this](const CP::SystematicSet& systConfig, sysData& sys)
225 {return calcSystematicVariation(systConfig, sys);});
226 if (m_sysCache.get(CP::SystematicSet(), m_currentSys) != StatusCode::SUCCESS) {
227 ATH_MSG_ERROR("Failed to initialize systematic cache");
228 return StatusCode::FAILURE;
229 }
230
231 m_initialised = true;
232 return StatusCode::SUCCESS;
233}
#define ATH_MSG_INFO(x,...)
#define ANA_CHECK(EXP)
check whether the given expression was successful
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
float getJetQuantity(const xAOD::Jet &jet, const BTaggingToolUtil::varType vType) const
Gaudi::Property< std::string > m_json_config_path
std::unique_ptr< BTaggingBoundsHandler::JetQuantityGetter > m_funcGetJetQuantity
std::unique_ptr< SG::ConstAccessor< int > > m_truthLabelAcc
std::map< std::string, std::string > m_mcReference
static float getExtendedFloat(const nlohmann::json &config)
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:116

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ msg()

MsgStream & AthCommonMsg< AlgTool >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msg_level_name()

const std::string & asg::AsgTool::msg_level_name ( ) const
inherited

A deprecated function for getting the message level's name.

Instead of using this, weirdly named function, user code should get the string name of the current minimum message level (in case they really need it...), with:

MSG::name( msg().level() )

This function's name doesn't follow the ATLAS coding rules, and as such will be removed in the not too distant future.

Returns
The string name of the current minimum message level that's printed

Definition at line 101 of file AsgTool.cxx.

101 {
102
103 return MSG::name( msg().level() );
104 }
MsgStream & msg() const
const std::string & name(Level lvl)
Convenience function for translating message levels to strings.
Definition MsgLevel.cxx:19

◆ msgLvl()

bool AthCommonMsg< AlgTool >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ outputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ print()

void asg::AsgTool::print ( ) const
virtualinherited

Print the state of the tool.

Implements asg::IAsgTool.

Reimplemented in AsgHelloTool, HI::HIPileupTool, JetFromPseudojet, JetPileupLabelingTool, JetPseudojetRetriever, JetSubStructureMomentToolsBase, JetTruthLabelingTool, and KtDeltaRTool.

Definition at line 131 of file AsgTool.cxx.

131 {
132
133 ATH_MSG_INFO( "AsgTool " << name() << " @ " << this );
134 return;
135 }

◆ recommendedSystematics()

CP::SystematicSet BTaggingLargeREfficiencyJsonTool::recommendedSystematics ( ) const
overridevirtual

the list of all systematics this tool recommends to use

Implements CP::IReentrantSystematicsTool.

Definition at line 480 of file BTaggingLargeREfficiencyJsonTool.cxx.

481{
482 return affectingSystematics();
483}

◆ renounce()

std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > AthCommonDataStore< AthCommonMsg< AlgTool > >::renounce ( T & h)
inlineprotectedinherited

Definition at line 368 of file AthCommonDataStore.h.

369 {
370 h.renounce();
372 }
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 352 of file AthCommonDataStore.h.

352 {
354 }

◆ sysInitialize()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysInitialize ( )
overridevirtualinherited

Perform system initialization for an algorithm.

We override this to declare all the elements of handle key arrays at the end of initialization. See comments on updateVHKA.

Reimplemented in asg::AsgMetadataTool, AthCheckedComponent< AthAlgTool >, and AthCheckedComponent<::AthAlgTool >.

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::updateVHKA ( Gaudi::Details::PropertyBase & )
inlineinherited

Definition at line 298 of file AthCommonDataStore.h.

298 {
299 for (auto &a : m_vhka) {
301 for (auto k : keys) {
302 k->setOwner(this);
303 }
304 }
305 }
std::vector< SG::VarHandleKeyArray * > m_vhka

Member Data Documentation

◆ m_currentSys

const sysData* BTaggingLargeREfficiencyJsonTool::m_currentSys {nullptr}
private

Definition at line 108 of file BTaggingLargeREfficiencyJsonTool.h.

108{nullptr};

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default).

Definition at line 381 of file AthCommonDataStore.h.

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default).

Definition at line 378 of file AthCommonDataStore.h.

◆ m_funcGetJetQuantity

std::unique_ptr<BTaggingBoundsHandler::JetQuantityGetter> BTaggingLargeREfficiencyJsonTool::m_funcGetJetQuantity
private

Definition at line 89 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_initialised

bool BTaggingLargeREfficiencyJsonTool::m_initialised = false
private

Definition at line 47 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_jetAuthor

Gaudi::Property<std::string> BTaggingLargeREfficiencyJsonTool::m_jetAuthor {this, "JetAuthor", "", "Jet collection"}
private

Definition at line 51 of file BTaggingLargeREfficiencyJsonTool.h.

51{this, "JetAuthor", "", "Jet collection"};

◆ m_json_config

nlohmann::ordered_json BTaggingLargeREfficiencyJsonTool::m_json_config
private

Definition at line 59 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_json_config_path

Gaudi::Property<std::string> BTaggingLargeREfficiencyJsonTool::m_json_config_path {this, "JsonConfigFile", "", "Path to JSON config file"}
private

Definition at line 52 of file BTaggingLargeREfficiencyJsonTool.h.

52{this, "JsonConfigFile", "", "Path to JSON config file"};

◆ m_labelMap

std::map<int, std::string> BTaggingLargeREfficiencyJsonTool::m_labelMap
private

Definition at line 60 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_labelMapMCMC

std::map<int, std::string> BTaggingLargeREfficiencyJsonTool::m_labelMapMCMC
private

Definition at line 61 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_massAcc

std::unique_ptr<SG::ConstAccessor<float> > BTaggingLargeREfficiencyJsonTool::m_massAcc
private

Definition at line 101 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_maxEta

Gaudi::Property<float> BTaggingLargeREfficiencyJsonTool::m_maxEta {this, "MaxEta", 2.5, "Maximum jet eta cut"}
private

Definition at line 57 of file BTaggingLargeREfficiencyJsonTool.h.

57{this, "MaxEta", 2.5, "Maximum jet eta cut"};

◆ m_mcGenerator

Gaudi::Property<std::string> BTaggingLargeREfficiencyJsonTool::m_mcGenerator {this, "MCGenerator", "", "Name of the MC generator of the sample being processed (required for MC-MC scale factor)"}
private

Definition at line 53 of file BTaggingLargeREfficiencyJsonTool.h.

53{this, "MCGenerator", "", "Name of the MC generator of the sample being processed (required for MC-MC scale factor)"};

◆ m_mcmcHandlers

std::map<std::string, BTaggingGridBoundsHandler<LargeRMCMCHandler> > BTaggingLargeREfficiencyJsonTool::m_mcmcHandlers
private

Definition at line 98 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_mcReference

std::map<std::string, std::string> BTaggingLargeREfficiencyJsonTool::m_mcReference
private

Definition at line 97 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_minPt

Gaudi::Property<float> BTaggingLargeREfficiencyJsonTool::m_minPt {this, "MinPt", -1 , "Minimum jet pT cut (in MeV)"}
private

Definition at line 56 of file BTaggingLargeREfficiencyJsonTool.h.

56{this, "MinPt", -1 /*MeV*/, "Minimum jet pT cut (in MeV)"};

◆ m_OP

Gaudi::Property<std::string> BTaggingLargeREfficiencyJsonTool::m_OP {this, "OperatingPoint", "", "Operating point"}
private

Definition at line 50 of file BTaggingLargeREfficiencyJsonTool.h.

50{this, "OperatingPoint", "", "Operating point"};

◆ m_outputName

Gaudi::Property<std::string> BTaggingLargeREfficiencyJsonTool::m_outputName {this, "OutputName", "", "Output name of the tagger"}
private

Definition at line 49 of file BTaggingLargeREfficiencyJsonTool.h.

49{this, "OutputName", "", "Output name of the tagger"};

◆ m_ptAcc

std::unique_ptr<SG::ConstAccessor<float> > BTaggingLargeREfficiencyJsonTool::m_ptAcc
private

Definition at line 102 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_selTool

ToolHandle<IBTaggingLargeRSelectionJsonTool> BTaggingLargeREfficiencyJsonTool::m_selTool
private

Access to a BTaggingLargeRSelectionJsonTool.

Definition at line 64 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_sfMap

std::map<std::string, std::vector<float> > BTaggingLargeREfficiencyJsonTool::m_sfMap
private

Definition at line 92 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_sfPtMap

std::map<std::string, std::vector<float> > BTaggingLargeREfficiencyJsonTool::m_sfPtMap
private

Definition at line 93 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_sfSysMap

std::map<std::string, std::map<std::string, std::vector<float> > > BTaggingLargeREfficiencyJsonTool::m_sfSysMap
private

Definition at line 94 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_sysCache

CP::SystematicsCache<sysData> BTaggingLargeREfficiencyJsonTool::m_sysCache {this}
private

Definition at line 107 of file BTaggingLargeREfficiencyJsonTool.h.

107{this};

◆ m_truthLabelAcc

std::unique_ptr<SG::ConstAccessor<int> > BTaggingLargeREfficiencyJsonTool::m_truthLabelAcc
private

Definition at line 100 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< AlgTool > >::m_varHandleArraysDeclared
privateinherited

Definition at line 387 of file AthCommonDataStore.h.

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< AlgTool > >::m_vhka
privateinherited

Definition at line 386 of file AthCommonDataStore.h.


The documentation for this class was generated from the following files: