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

#include <BTaggingLargeREfficiencyJsonTool.h>

Inheritance diagram for BTaggingLargeREfficiencyJsonTool:

Classes

class  BoundsHandler
class  MCMCHandler
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

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
ToolHandle< IBTaggingLargeRSelectionJsonTool > m_selTool
 Access to a BTaggingLargeRSelectionJsonTool.
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 25 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.

Member Enumeration Documentation

◆ varType

Enumerator
unknown 
pT 
mass 
eta 
abseta 

Definition at line 63 of file BTaggingLargeREfficiencyJsonTool.h.

63 {
64 unknown,
65 pT,
66 mass,
67 eta,
68 abseta
69 };
Scalar eta() const
pseudorapidity method

Constructor & Destructor Documentation

◆ BTaggingLargeREfficiencyJsonTool()

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

Definition at line 10 of file BTaggingLargeREfficiencyJsonTool.cxx.

10 :
11 asg::AsgTool ( name )
12{
13 m_initialised = false;
14
15 declareProperty("btagSelectionJsonTool", m_selTool, "Xbb JSON selection tool");
16}
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 18 of file BTaggingLargeREfficiencyJsonTool.cxx.

18 {
19}

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 624 of file BTaggingLargeREfficiencyJsonTool.cxx.

625{
626 CP::SystematicSet affectingSystematics;
627 affectingSystematics.insert(CP::SystematicVariation("BTagging_Xbb_SYST", 1));
628 affectingSystematics.insert(CP::SystematicVariation("BTagging_Xbb_SYST", -1));
629
631}
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 616 of file BTaggingLargeREfficiencyJsonTool.cxx.

617{
618 CP::SystematicVariation syst = systConfig.getSystematicByBaseName("BTagging_Xbb_SYST");
619 sys.xbb_syst = syst.parameter();
620
621 return StatusCode::SUCCESS;
622}
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 356 of file BTaggingLargeREfficiencyJsonTool.cxx.

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

Definition at line 369 of file BTaggingLargeREfficiencyJsonTool.cxx.

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

◆ getJetQuantity()

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

Definition at line 384 of file BTaggingLargeREfficiencyJsonTool.cxx.

384 {
385 if (vType == varType::pT) {
386 return getJetPtInGeV(jet);
387 } else if (vType == varType::mass) {
388 return getJetMassInGeV(jet);
389 } else if (vType == varType::eta) {
390 return jet.eta();
391 } else if (vType == varType::abseta) {
392 return std::abs(jet.eta());
393 } else {
394 ATH_MSG_ERROR("Unsupported jet variable quantity requested: '" << getVariableName(vType) << "'");
395 throw std::runtime_error("BTaggingLargeREfficiencyJsonTool::getJetQuantity unsupported jet variable: '" + getVariableName(vType) + "'");
396 }
397}
static std::string getVariableName(const varType vType)
float getJetPtInGeV(const xAOD::Jet &jet) const
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 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 // Loop over all MC-MC handlers and find the one where the jet if falling into
326 for (const auto& handler : handlerIt->second) {
327 if (handler.isJetWithinBounds(jet, *this)) {
328 // // Useful for debugging
329 // // Print jet truth label pT mass and eta and the corresponding handler
330 // std::cout << "jet(label=" << label
331 // << ", pT=" << getJetQuantity(jet, "pT")
332 // << ", mass=" << getJetQuantity(jet, "mass")
333 // << ", abseta=" << getJetQuantity(jet, "abseta") << "): "
334 // << handler << std::endl;
335
336 corr = handler.getScaleFactor();
338 }
339 }
340
341 ATH_MSG_WARNING("Jet outside mc-to-mc binning for label " << label << ". Returning correction of 1.");
343}
#define ATH_MSG_WARNING(x,...)
std::map< std::string, std::vector< MCMCHandler > > 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 345 of file BTaggingLargeREfficiencyJsonTool.cxx.

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

◆ getVariableName()

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

Definition at line 527 of file BTaggingLargeREfficiencyJsonTool.cxx.

528{
529 if (vType == varType::pT) {
530 return "pT";
531 } else if (vType == varType::mass) {
532 return "mass";
533 } else if (vType == varType::eta) {
534 return "eta";
535 } else if (vType == varType::abseta) {
536 return "abseta";
537 } else {
538 throw std::runtime_error("Variable type " + std::to_string(static_cast<int>(vType)) + " not defined in BTaggingLargeREfficiencyJsonTool.");
539 return "unknown";
540 }
541}

◆ getVariableType()

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

Definition at line 511 of file BTaggingLargeREfficiencyJsonTool.cxx.

512{
513 if (varName == "pT") {
514 return varType::pT;
515 } else if (varName == "mass") {
516 return varType::mass;
517 } else if (varName == "eta") {
518 return varType::eta;
519 } else if (varName == "abseta") {
520 return varType::abseta;
521 } else {
522 throw std::runtime_error("Variable '" + varName + "' not defined in BTaggingLargeREfficiencyJsonTool.");
523 return varType::unknown;
524 }
525}

◆ 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 21 of file BTaggingLargeREfficiencyJsonTool.cxx.

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

◆ 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 BTaggingLargeREfficiencyJsonTool::recommendedSystematics ( ) const
overridevirtual

the list of all systematics this tool recommends to use

Implements CP::IReentrantSystematicsTool.

Definition at line 633 of file BTaggingLargeREfficiencyJsonTool.cxx.

634{
635 return affectingSystematics();
636}

◆ 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 543 of file BTaggingLargeREfficiencyJsonTool.cxx.

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

◆ operator<< [2/2]

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

Definition at line 556 of file BTaggingLargeREfficiencyJsonTool.cxx.

556 {
557 // Return
558 // MCMCHandler(var1: [minVar1, maxVar1], var2: [minVar2, maxVar2], ... , SF: sfValue)
559 // e.g. MCMCHandler(pT: [250, 500], abseta[0., 2.0], SF: 0.9)
560 os << "MCMCHandler(";
561 // Add the list of variables with lower and upper bounds
562 os << dynamic_cast<const BTaggingLargeREfficiencyJsonTool::BoundsHandler&>(handler);
563 // Finally add the MC-MC SF value
564 os << ", SF: " << handler.m_MCMCSF << ")";
565 return os;
566}

Member Data Documentation

◆ m_currentSys

const sysData* BTaggingLargeREfficiencyJsonTool::m_currentSys {nullptr}
private

Definition at line 224 of file BTaggingLargeREfficiencyJsonTool.h.

224{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 BTaggingLargeREfficiencyJsonTool::m_initialised = false
private

Definition at line 43 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_jetAuthor

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

Definition at line 47 of file BTaggingLargeREfficiencyJsonTool.h.

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

◆ m_json_config

json BTaggingLargeREfficiencyJsonTool::m_json_config
private

Definition at line 55 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 48 of file BTaggingLargeREfficiencyJsonTool.h.

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

◆ m_labelMap

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

Definition at line 56 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_labelMapMCMC

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

Definition at line 57 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_massAcc

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

Definition at line 217 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_maxEta

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

Definition at line 53 of file BTaggingLargeREfficiencyJsonTool.h.

53{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 49 of file BTaggingLargeREfficiencyJsonTool.h.

49{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> > BTaggingLargeREfficiencyJsonTool::m_mcmcHandlers
private

Definition at line 214 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_mcReference

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

Definition at line 213 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 52 of file BTaggingLargeREfficiencyJsonTool.h.

52{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 46 of file BTaggingLargeREfficiencyJsonTool.h.

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

◆ m_outputName

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

Definition at line 45 of file BTaggingLargeREfficiencyJsonTool.h.

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

◆ m_ptAcc

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

Definition at line 218 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_selTool

ToolHandle<IBTaggingLargeRSelectionJsonTool> BTaggingLargeREfficiencyJsonTool::m_selTool
private

Access to a BTaggingLargeRSelectionJsonTool.

Definition at line 60 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_sfMap

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

Definition at line 208 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_sfPtMap

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

Definition at line 209 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_sfSysMap

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

Definition at line 210 of file BTaggingLargeREfficiencyJsonTool.h.

◆ m_sysCache

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

Definition at line 223 of file BTaggingLargeREfficiencyJsonTool.h.

223{this};

◆ m_truthLabelAcc

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

Definition at line 216 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: