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

#include <BTaggingEfficiencyJsonTool.h>

Inheritance diagram for BTaggingEfficiencyJsonTool:

Classes

class  BoundsHandler
class  MCMCHandler
struct  sysData

Public Member Functions

 BTaggingEfficiencyJsonTool (const std::string &name)
virtual ~BTaggingEfficiencyJsonTool ()
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

enum class  varType {
  unknown , pT , mass , eta ,
  abseta
}
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 varType vType) const
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Static Private Member Functions

static std::string getVariableName (const varType vType)
static varType getVariableType (const std::string &varName)

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"}
json m_json_config
std::map< int, std::string > m_labelMap
std::map< int, std::string > m_labelMapMCMC
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, std::vector< MCMCHandler > > 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

Friends

std::ostream & operator<< (std::ostream &os, const BoundsHandler &handler)
std::ostream & operator<< (std::ostream &os, const MCMCHandler &handler)

Detailed Description

Definition at line 17 of file BTaggingEfficiencyJsonTool.h.

Member Typedef Documentation

◆ StoreGateSvc_t

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

Definition at line 376 of file AthCommonDataStore.h.

Member Enumeration Documentation

◆ varType

enum class BTaggingEfficiencyJsonTool::varType
strongprivate
Enumerator
unknown 
pT 
mass 
eta 
abseta 

Definition at line 52 of file BTaggingEfficiencyJsonTool.h.

52 {
53 unknown,
54 pT,
55 mass,
56 eta,
57 abseta
58 };
Scalar eta() const
pseudorapidity method

Constructor & Destructor Documentation

◆ BTaggingEfficiencyJsonTool()

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

Definition at line 10 of file BTaggingEfficiencyJsonTool.cxx.

10 :
11 asg::AsgTool ( name )
12{
13 m_initialised = false;
14}

◆ ~BTaggingEfficiencyJsonTool()

BTaggingEfficiencyJsonTool::~BTaggingEfficiencyJsonTool ( )
virtual

Definition at line 16 of file BTaggingEfficiencyJsonTool.cxx.

16 {
17}

Member Function Documentation

◆ affectingSystematics()

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

the list of all systematics this tool can be affected by

Implements CP::IReentrantSystematicsTool.

Definition at line 617 of file BTaggingEfficiencyJsonTool.cxx.

618{
619 CP::SystematicSet affectingSystematics;
620 affectingSystematics.insert(CP::SystematicVariation("BTagging_Xbb_SYST", 1));
621 affectingSystematics.insert(CP::SystematicVariation("BTagging_Xbb_SYST", -1));
622
624}
virtual CP::SystematicSet affectingSystematics() const override
the list of all systematics this tool can be affected by

◆ calcSystematicVariation()

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

Definition at line 609 of file BTaggingEfficiencyJsonTool.cxx.

610{
611 CP::SystematicVariation syst = systConfig.getSystematicByBaseName("BTagging_Xbb_SYST");
612 sys.xbb_syst = syst.parameter();
613
614 return StatusCode::SUCCESS;
615}
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 }
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)

◆ 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 BTaggingEfficiencyJsonTool::getJetMassInGeV ( const xAOD::Jet & jet) const
private

Definition at line 357 of file BTaggingEfficiencyJsonTool.cxx.

358{
359 // Convert mass from MeV to GeV
360 if (!m_massAcc) {
361 return jet.m() * BTaggingToolUtil::MeVToGeV;
362 }
363 if (!m_massAcc->isAvailable(jet)) {
364 ATH_MSG_ERROR("Decorated mass '" << SG::AuxTypeRegistry::instance().getName( m_massAcc->auxid() ) << "' not available on jet. Cannot proceed.");
365 throw std::runtime_error("Decorated mass not available on jet.");
366 }
368}
#define ATH_MSG_ERROR(x,...)
std::unique_ptr< SG::ConstAccessor< float > > m_massAcc
static constexpr double MeVToGeV
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 BTaggingEfficiencyJsonTool::getJetPtInGeV ( const xAOD::Jet & jet) const
private

Definition at line 370 of file BTaggingEfficiencyJsonTool.cxx.

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

◆ getJetQuantity()

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

Definition at line 385 of file BTaggingEfficiencyJsonTool.cxx.

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

◆ 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 BTaggingEfficiencyJsonTool::getMCToMCCorr ( const xAOD::Jet & jet,
float & corr ) const
private

Definition at line 293 of file BTaggingEfficiencyJsonTool.cxx.

294{
295 if (! m_initialised) {
296 throw std::runtime_error("BTaggingEfficiencyJsonTool has not been initialised.");
297 }
298
299 corr = 1.0;
300
301 // If MC-MC handlers map is empty it means the JSON file does not contain MC-MC scale factors
302 // Hence exiting directly from the function
303 if (m_mcmcHandlers.empty()) {
305 }
306
307 // Retrieve jet truth labelling
308 // and check if a string label is associated to it
309 // e.g. truthLabel integer is associated to fully-contained top->qqb and the corresponding string label could be "Top" for instance
310 int truthLabel = (*m_truthLabelAcc)(jet);
311 auto labelIt = m_labelMapMCMC.find(truthLabel);
312 if (labelIt == m_labelMapMCMC.end()) {
313 ATH_MSG_WARNING("No mc-to-mc correction on jet with truthLabel: " << truthLabel << ". Returning scale factor of 1.");
314 return CP::CorrectionCode::OutOfValidityRange; // this process has no mc-to-mc correction
315 }
316
317 const std::string& label = labelIt->second;
318 auto handlerIt = m_mcmcHandlers.find(label);
319 if (handlerIt == m_mcmcHandlers.end()) {
320 // If the generator of the sample processed is the same as the generator of the reference sample for the given label
321 // then the map of MC-MC handler is not filled for that label (check happening in the initialize function)
322 // Thus exiting here as the generator of the sample being processed is the same generator as the one used for the calibration
324 }
325
326 // Loop over all MC-MC handlers and find the one where the jet if falling into
327 for (const auto& handler : handlerIt->second) {
328 if (handler.isJetWithinBounds(jet, *this)) {
329 // // Useful for debugging
330 // // Print jet truth label pT mass and eta and the corresponding handler
331 // std::cout << "jet(label=" << label
332 // << ", pT=" << getJetQuantity(jet, "pT")
333 // << ", mass=" << getJetQuantity(jet, "mass")
334 // << ", abseta=" << getJetQuantity(jet, "abseta") << "): "
335 // << handler << std::endl;
336
337 corr = handler.getScaleFactor();
339 }
340 }
341
342 ATH_MSG_WARNING("Jet outside mc-to-mc binning for label " << label << ". Returning correction of 1.");
344}
#define ATH_MSG_WARNING(x,...)
std::map< std::string, std::vector< MCMCHandler > > m_mcmcHandlers
std::map< int, std::string > m_labelMapMCMC
@ 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:99

◆ 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 BTaggingEfficiencyJsonTool::getScaleFactor ( const xAOD::Jet & jet,
float & scalefactor,
const CP::SystematicSet & sys ) const
overridevirtual

Implements IBTaggingEfficiencyJsonTool.

Definition at line 236 of file BTaggingEfficiencyJsonTool.cxx.

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

◆ getSFSys()

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

Definition at line 346 of file BTaggingEfficiencyJsonTool.cxx.

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

◆ getVariableName()

std::string BTaggingEfficiencyJsonTool::getVariableName ( const varType vType)
staticprivate

Definition at line 520 of file BTaggingEfficiencyJsonTool.cxx.

521{
522 if (vType == varType::pT) {
523 return "pT";
524 } else if (vType == varType::mass) {
525 return "mass";
526 } else if (vType == varType::eta) {
527 return "eta";
528 } else if (vType == varType::abseta) {
529 return "abseta";
530 } else {
531 throw std::runtime_error("Variable type " + std::to_string(static_cast<int>(vType)) + " not defined in BTaggingEfficiencyJsonTool.");
532 return "unknown";
533 }
534}

◆ getVariableType()

BTaggingEfficiencyJsonTool::varType BTaggingEfficiencyJsonTool::getVariableType ( const std::string & varName)
staticprivate

Definition at line 504 of file BTaggingEfficiencyJsonTool.cxx.

505{
506 if (varName == "pT") {
507 return varType::pT;
508 } else if (varName == "mass") {
509 return varType::mass;
510 } else if (varName == "eta") {
511 return varType::eta;
512 } else if (varName == "abseta") {
513 return varType::abseta;
514 } else {
515 throw std::runtime_error("Variable '" + varName + "' not defined in BTaggingEfficiencyJsonTool.");
516 return varType::unknown;
517 }
518}

◆ initialize()

StatusCode BTaggingEfficiencyJsonTool::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 19 of file BTaggingEfficiencyJsonTool.cxx.

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

◆ 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()

◆ recommendedSystematics()

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

the list of all systematics this tool recommends to use

Implements CP::IReentrantSystematicsTool.

Definition at line 626 of file BTaggingEfficiencyJsonTool.cxx.

627{
628 return affectingSystematics();
629}

◆ 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

◆ operator<< [1/2]

std::ostream & operator<< ( std::ostream & os,
const BoundsHandler & handler )
friend

Definition at line 536 of file BTaggingEfficiencyJsonTool.cxx.

536 {
537 // Add the list of variables with lower and upper bounds
538 // e.g. "pT: [250, 500], mass: [50, 100]"
539 // The separator ", " is only added between entries, not after the last one
540 bool first = true;
541 for (const auto& [vType, bounds] : handler.m_varBinBounds) {
542 if (!first) os << ", ";
543 first = false;
544 os << BTaggingEfficiencyJsonTool::getVariableName(vType) << ": [" << bounds.lowerBound << ", " << bounds.upperBound << "]";
545 }
546 return os;
547}
bool first
Definition DeMoScan.py:534

◆ operator<< [2/2]

std::ostream & operator<< ( std::ostream & os,
const MCMCHandler & handler )
friend

Definition at line 549 of file BTaggingEfficiencyJsonTool.cxx.

549 {
550 // Return
551 // MCMCHandler(var1: [minVar1, maxVar1], var2: [minVar2, maxVar2], ... , SF: sfValue)
552 // e.g. MCMCHandler(pT: [250, 500], abseta[0., 2.0], SF: 0.9)
553 os << "MCMCHandler(";
554 // Add the list of variables with lower and upper bounds
555 os << dynamic_cast<const BTaggingEfficiencyJsonTool::BoundsHandler&>(handler);
556 // Finally add the MC-MC SF value
557 os << ", SF: " << handler.m_MCMCSF << ")";
558 return os;
559}

Member Data Documentation

◆ m_currentSys

const sysData* BTaggingEfficiencyJsonTool::m_currentSys {nullptr}
private

Definition at line 188 of file BTaggingEfficiencyJsonTool.h.

188{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_initialised

bool BTaggingEfficiencyJsonTool::m_initialised = false
private

Definition at line 35 of file BTaggingEfficiencyJsonTool.h.

◆ m_jetAuthor

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

Definition at line 39 of file BTaggingEfficiencyJsonTool.h.

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

◆ m_json_config

json BTaggingEfficiencyJsonTool::m_json_config
private

Definition at line 47 of file BTaggingEfficiencyJsonTool.h.

◆ m_json_config_path

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

Definition at line 40 of file BTaggingEfficiencyJsonTool.h.

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

◆ m_labelMap

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

Definition at line 48 of file BTaggingEfficiencyJsonTool.h.

◆ m_labelMapMCMC

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

Definition at line 49 of file BTaggingEfficiencyJsonTool.h.

◆ m_massAcc

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

Definition at line 181 of file BTaggingEfficiencyJsonTool.h.

◆ m_maxEta

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

Definition at line 45 of file BTaggingEfficiencyJsonTool.h.

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

◆ m_mcGenerator

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

Definition at line 41 of file BTaggingEfficiencyJsonTool.h.

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

◆ m_mcmcHandlers

std::map<std::string, std::vector<MCMCHandler> > BTaggingEfficiencyJsonTool::m_mcmcHandlers
private

Definition at line 178 of file BTaggingEfficiencyJsonTool.h.

◆ m_mcReference

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

Definition at line 177 of file BTaggingEfficiencyJsonTool.h.

◆ m_minPt

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

Definition at line 44 of file BTaggingEfficiencyJsonTool.h.

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

◆ m_OP

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

Definition at line 38 of file BTaggingEfficiencyJsonTool.h.

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

◆ m_outputName

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

Definition at line 37 of file BTaggingEfficiencyJsonTool.h.

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

◆ m_ptAcc

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

Definition at line 182 of file BTaggingEfficiencyJsonTool.h.

◆ m_sfMap

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

Definition at line 172 of file BTaggingEfficiencyJsonTool.h.

◆ m_sfPtMap

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

Definition at line 173 of file BTaggingEfficiencyJsonTool.h.

◆ m_sfSysMap

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

Definition at line 174 of file BTaggingEfficiencyJsonTool.h.

◆ m_sysCache

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

Definition at line 187 of file BTaggingEfficiencyJsonTool.h.

187{this};

◆ m_truthLabelAcc

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

Definition at line 180 of file BTaggingEfficiencyJsonTool.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: