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

A tool used by the egammaMVASvc to help calibrate energy for one particle type. More...

#include <egammaMVACalibTool.h>

Inheritance diagram for egammaMVACalibTool:
Collaboration diagram for egammaMVACalibTool:

Public Types

enum  CalibrationType { correctEaccordion , fullCalibration }
 how the output of the BDT is used correctEaccordion: energy = raw energy * BDT fullCalibration: energy = BDT More...
enum  ShiftType { NOSHIFT =0 , MEAN10TOTRUE }
 shift to be applied after the BDT. More...

Public Member Functions

 egammaMVACalibTool (const std::string &type)
virtual ~egammaMVACalibTool () override
virtual StatusCode initialize () override
 Dummy implementation of the initialisation function.
float getEnergy (const xAOD::CaloCluster &clus, const xAOD::Egamma *eg, const egammaMVACalib::GlobalEventInfo &gei=egammaMVACalib::GlobalEventInfo()) const override final
 returns the calibrated energy
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< StoreGateSvcStoreGateSvc_t

Private Member Functions

StatusCode setupBDT (const egammaMVAFunctions::funcMap_t &funcLibrary, const std::string &fileName)
 a function called by initialize to setup the BDT, funcs, and shifts.
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 const TString & getString (TObject *obj)
 a utility to get a TString out of an TObjString pointer

Private Attributes

Gaudi::Property< int > m_particleType
Gaudi::Property< int > m_shiftType
Gaudi::Property< int > m_calibrationType
Gaudi::Property< bool > m_clusterEif0
Gaudi::Property< std::string > m_folder
 string with folder for weight files
Gaudi::Property< bool > m_useLayerCorrected
std::unique_ptr< TH2Poly > m_hPoly
 A TH2Poly used to extract bin numbers. Note there is an offset of 1.
std::vector< MVAUtils::BDTm_BDTs
 Where the BDTs are stored.
std::unique_ptr< egammaMVACalibTool_detail::Funcsm_funcs
 where the pointers to the funcs to calculate the vars per BDT
std::vector< TFormula > m_shifts
 shifts formulas
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

A tool used by the egammaMVASvc to help calibrate energy for one particle type.

The particle type to be calibrated must be specified by the property ParticleType. The property folder must be set with the path to a folder containig three files:

  • MVACalib_electron.weights.root
  • MVACalib_unconvertedPhoton.weights.root
  • MVACalib_convertedPhoton.weights.root

The ROOT files should have in the following content:

  • a TH2Poly object named "hPoly". This is used to decide which BDT to use. The x-axis is cluster eta, the y-axis is the raw-accordion-Et in GeV. The BDT that will be used for each event is the one with index equal to the content of the TH2Poly - 1, e.g. const int bin = m_hPoly->FindBin(etaVar, energyVarGeV) - 1. (the minimum value in the TH2Poly is 1)
  • several TTree named BDTX where X is an integer index (not padded). X here counts from 0. Each TTree has the weights of a BDT and it is the input to MVAUtils::BDT. Alternatively the TTree can be inside a TObjArray named "trees".
  • a TObjArray named "variables" containing many TObjString, each one for each BDT. Each TObjString is a string containing the names of the input variables for each BDT, separated by ";". The names should be understandable by egammaMVAFunctions::initializeElectronFuncs, egammaMVAFunctions::initializeUnconvertedPhotonFuncs, egammaMVAFunctions::initializeConvertedPhotonFuncs.
  • a TObjectArray named "shifts" containing many TObjString, each one for each BDT. Each TObjString is a string which represent the formula to compute the shift (used to construct a TFormula). The variables is the Et in GeV after the calibration. The value of the shift is divided by the energy calibrated by the BDT.

On data the property use_layer_corrected should be set to true. In reconstruction this flag is always false. In PhysicsAnalysis it should be set appropriately. When set to true when using the layer energies as input the data-driver-corrected version are used.

Definition at line 70 of file egammaMVACalibTool.h.

Member Typedef Documentation

◆ StoreGateSvc_t

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

Definition at line 388 of file AthCommonDataStore.h.

Member Enumeration Documentation

◆ CalibrationType

how the output of the BDT is used correctEaccordion: energy = raw energy * BDT fullCalibration: energy = BDT

Enumerator
correctEaccordion 
fullCalibration 

Definition at line 82 of file egammaMVACalibTool.h.

◆ ShiftType

shift to be applied after the BDT.

Only MEAN10TOTRUE and MEAN10TOTRUE are supperted

Enumerator
NOSHIFT 
MEAN10TOTRUE 

Definition at line 87 of file egammaMVACalibTool.h.

Constructor & Destructor Documentation

◆ egammaMVACalibTool()

egammaMVACalibTool::egammaMVACalibTool ( const std::string & type)

Definition at line 38 of file egammaMVACalibTool.cxx.

38 :
39 asg::AsgTool(name),
40 m_funcs (std::make_unique<egammaMVACalibTool_detail::Funcs>())
41{
42}
std::unique_ptr< egammaMVACalibTool_detail::Funcs > m_funcs
where the pointers to the funcs to calculate the vars per BDT

◆ ~egammaMVACalibTool()

egammaMVACalibTool::~egammaMVACalibTool ( )
overridevirtual

Definition at line 46 of file egammaMVACalibTool.cxx.

47{
48}

Member Function Documentation

◆ 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

◆ getEnergy()

float egammaMVACalibTool::getEnergy ( const xAOD::CaloCluster & clus,
const xAOD::Egamma * eg,
const egammaMVACalib::GlobalEventInfo & gei = egammaMVACalib::GlobalEventInfo() ) const
finaloverridevirtual

returns the calibrated energy

Implements IegammaMVACalibTool.

Definition at line 242 of file egammaMVACalibTool.cxx.

245{
246
247 ATH_MSG_DEBUG("calling getEnergy with cluster index " << clus.index());
248
249 // find the bin of BDT and the shift
250 const auto initEnergy =
252 float(clus.e()) : (m_useLayerCorrected ?
253 egammaMVAFunctions::compute_correctedcl_Eacc(clus) :
254 egammaMVAFunctions::compute_rawcl_Eacc(clus));
255
256 const auto etVarGeV = (initEnergy / std::cosh(clus.eta())) / GeV;
257 const auto etaVar = std::abs(clus.eta());
258
259 ATH_MSG_DEBUG("Looking at object with initEnergy = " << initEnergy
260 << ", etVarGeV = " << etVarGeV
261 << ", etaVar = " << etaVar
262 << ", clus->e() = " << clus.e());
263
264 // Normally, we'd just use FindFixBin here. But TH2Poly overrides FindBin
265 // to handle its special bin definitions, but it doesn't also override
266 // FindFixBin. But TH2Poly::FindBin (unlike TH1::FindBin) doesn't actually
267 // do anything non-const, so just suppress the warning here.
268 TH2Poly* hPoly ATLAS_THREAD_SAFE = m_hPoly.get();
269 const int bin = hPoly->FindBin(etaVar, etVarGeV) - 1; // poly bins are shifted by one
270
271 ATH_MSG_DEBUG("Using bin: " << bin);
272
273 if (bin < 0) {
274 ATH_MSG_DEBUG("The bin is under/overflow; just return the energy");
275 return clus.e();
276 }
277
278 if (bin >= static_cast<int>(m_BDTs.size())) {
279 ATH_MSG_WARNING("The bin is outside the range, so just return the energy");
280 return clus.e();
281 }
282
283
284 // select the bdt and functions. (shifts are done later if needed)
285 // if there is only one BDT just use that
286 const int bin_BDT = m_BDTs.size() != 1 ? bin : 0;
287 const auto& bdt = m_BDTs[bin_BDT];
288 const auto& funcs = m_funcs->funcs[bin_BDT];
289
290 const size_t sz = funcs.size();
291
292 // could consider adding std::array support to the BDTs
293 std::vector<float> vars(sz);
294
295 for (size_t i = 0; i < sz; ++i) {
296 vars[i] = funcs[i](eg, &clus);
297 ATH_MSG_DEBUG("Variable " << i << " = " << std::format("{:10.4f}", vars[i]));
298 }
299
300 // Retrieve nPV and mu in case of forward electron;
301 // they are the last two variables in the input vars
303 vars.insert(vars.end(),{float(gei.nPV), gei.acmu});
304 }
305
306 // evaluate the BDT response
307 const float mvaOutput = bdt.GetResponse(vars);
308 ATH_MSG_DEBUG("BDT response = " << std::format("{:10.6f}", mvaOutput));
309
310 // what to do if the MVA response is 0;
311 if (mvaOutput == 0.) {
312 if (m_clusterEif0) {
313 return clus.e();
314 }
315 return 0.;
316 }
317
318 // calculate the unshifted energy
319 const auto energy = (m_calibrationType == fullCalibration) ?
320 mvaOutput : (initEnergy * mvaOutput);
321
322 ATH_MSG_DEBUG("energy after MVA = " << std::format("{:.3f}", energy));
323
324 if (m_shiftType == NOSHIFT) {
325 // if no shift, just return the unshifted energy
326 return energy;
327 }
328
329 // have to do a shift if here. It's based on the corrected Et in GeV
330 const auto etGeV = (energy / std::cosh(clus.eta())) / GeV;
331
332 // evaluate the TFormula associated with the bin
333 const auto shift = m_shifts[bin].Eval(etGeV);
334 ATH_MSG_DEBUG("shift = " << shift);
335 if (shift > 0.5) {
336 ATH_MSG_DEBUG("energy after MVA and shift = " << std::format("{:.3f}", energy/shift));
337 return energy / shift;
338 }
339 ATH_MSG_WARNING("Shift value too small: " << shift << "; not applying shift");
340 return energy;
341
342}
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static Double_t sz
#define ATLAS_THREAD_SAFE
size_t index() const
Return the index of this element within its container.
Gaudi::Property< bool > m_clusterEif0
std::vector< TFormula > m_shifts
shifts formulas
Gaudi::Property< bool > m_useLayerCorrected
Gaudi::Property< int > m_calibrationType
Gaudi::Property< int > m_shiftType
std::unique_ptr< TH2Poly > m_hPoly
A TH2Poly used to extract bin numbers. Note there is an offset of 1.
Gaudi::Property< int > m_particleType
std::vector< MVAUtils::BDT > m_BDTs
Where the BDTs are stored.
virtual double eta() const
The pseudorapidity ( ) of the particle.
virtual double e() const
The total energy of the particle.
float compute_correctedcl_Eacc(const xAOD::CaloCluster &cl)
float compute_rawcl_Eacc(const xAOD::CaloCluster &cl)

◆ 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::TEvent 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::TEvent, 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()

◆ 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::TEvent 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::TEvent, 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.

◆ getString()

const TString & egammaMVACalibTool::getString ( TObject * obj)
staticprivate

a utility to get a TString out of an TObjString pointer

Definition at line 233 of file egammaMVACalibTool.cxx.

234{
235 TObjString *objS = dynamic_cast<TObjString*>(obj);
236 if (!objS) {
237 throw std::runtime_error("egammaMVACalibTool::getString was passed something that was not a string object");
238 }
239 return objS->GetString();
240}

◆ initialize()

StatusCode egammaMVACalibTool::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 51 of file egammaMVACalibTool.cxx.

52{
54 ATH_MSG_FATAL("Particle type not set: you have to set property ParticleType to a valid value");
55 return StatusCode::FAILURE;
56 }
57 ATH_MSG_DEBUG("Initializing with particle " << m_particleType);
58
60 ATH_MSG_DEBUG("Using Mean10 shift");
61 } else if (m_shiftType == NOSHIFT) {
62 ATH_MSG_DEBUG("Not using a shift");
63 } else {
64 ATH_MSG_FATAL("Unsupported shift: " << m_shiftType);
65 return StatusCode::FAILURE;
66 }
67
68 // get the BDTs and initialize functions
69 ATH_MSG_DEBUG("get BDTs in folder: " << m_folder);
70 switch (m_particleType) {
72 {
73 std::unique_ptr<egammaMVAFunctions::funcMap_t> funcLibraryPtr =
75 ATH_CHECK(setupBDT(*funcLibraryPtr,
76 PathResolverFindCalibFile(m_folder + "/MVACalib_electron.weights.root")));
77 }
78 break;
80 {
81 std::unique_ptr<egammaMVAFunctions::funcMap_t> funcLibraryPtr =
83 ATH_CHECK(setupBDT(*funcLibraryPtr,
84 PathResolverFindCalibFile(m_folder + "/MVACalib_unconvertedPhoton.weights.root")));
85 }
86 break;
88 {
89 std::unique_ptr<egammaMVAFunctions::funcMap_t> funcLibraryPtr =
91 ATH_CHECK(setupBDT(*funcLibraryPtr,
92 PathResolverFindCalibFile(m_folder + "/MVACalib_convertedPhoton.weights.root")));
93 }
94 break;
96 {
97 std::unique_ptr<egammaMVAFunctions::funcMap_t> funcLibraryPtr =
99 ATH_CHECK(setupBDT(*funcLibraryPtr,
100 PathResolverFindCalibFile("egammaMVACalib/MVACalib_fwdelectron.weights.root")));
101 }
102 break;
103
104 default:
105 ATH_MSG_FATAL("Particle type not set properly: " << m_particleType);
106 return StatusCode::FAILURE;
107 }
108
109 // Load these dictionaries now, so we don't need to try to do so
110 // while multiple threads are running.
111 TClass::GetClass ("TH2Poly");
112 TClass::GetClass ("TMultiGraph");
113
114 return StatusCode::SUCCESS;
115}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Gaudi::Property< std::string > m_folder
string with folder for weight files
StatusCode setupBDT(const egammaMVAFunctions::funcMap_t &funcLibrary, const std::string &fileName)
a function called by initialize to setup the BDT, funcs, and shifts.
std::unique_ptr< funcMap_t > initializeUnconvertedPhotonFuncs(bool useLayerCorrected)
A function to build the map for uncoverted photons.
std::unique_ptr< funcMap_t > initializeElectronFuncs(bool useLayerCorrected)
A function to build the map for electrons.
std::unique_ptr< funcMap_t > initializeForwardElectronFuncs(bool useLayerCorrected)
NEW: A function to build the map for forward electrons.
std::unique_ptr< funcMap_t > initializeConvertedPhotonFuncs(bool useLayerCorrected)
A function to build the map for converted photons.

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

◆ 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 380 of file AthCommonDataStore.h.

381 {
382 h.renounce();
384 }
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 364 of file AthCommonDataStore.h.

364 {
366 }

◆ setupBDT()

StatusCode egammaMVACalibTool::setupBDT ( const egammaMVAFunctions::funcMap_t & funcLibrary,
const std::string & fileName )
private

a function called by initialize to setup the BDT, funcs, and shifts.

Definition at line 117 of file egammaMVACalibTool.cxx.

119{
120 ATH_MSG_DEBUG("Trying to open " << fileName);
121
122 std::unique_ptr<TFile> f(TFile::Open(fileName.c_str()));
123 if (!f || f->IsZombie()) {
124 ATH_MSG_FATAL("Could not open file: " << fileName);
125 return StatusCode::FAILURE;
126 }
127
128 // Load hPoly
129 TH2Poly *hPoly = nullptr;
130 f->GetObject("hPoly", hPoly);
131 if (!hPoly) {
132 ATH_MSG_FATAL("Could not find hPoly");
133 return StatusCode::FAILURE;
134 }
135 //pass ownership to class variable
136 m_hPoly.reset(static_cast<TH2Poly*>(hPoly));
137 m_hPoly->SetDirectory(nullptr);
138
139 // Load variables
140 TObjArray *variablesTmp = nullptr;
141 f->GetObject("variables", variablesTmp);
142 if (!variablesTmp) {
143 ATH_MSG_FATAL("Could not find variables");
144 return StatusCode::FAILURE;
145 }
146 auto variables = std::unique_ptr<TObjArray>(variablesTmp);
147 variables->SetOwner(); // to delete the objects when d-tor is called
148
149 // Load shifts
150 TObjArray *shiftsTmp = nullptr;
151 f->GetObject("shifts", shiftsTmp);
152 if (!shiftsTmp) {
153 ATH_MSG_FATAL("Could not find shifts");
154 return StatusCode::FAILURE;
155 }
156 auto shifts = std::unique_ptr<TObjArray>(shiftsTmp);
157 shifts->SetOwner(); // to delete the objects when d-tor is called
158
159 // Load trees
160 TObjArray *treesTmp = nullptr;
161 std::unique_ptr<TObjArray> trees;
162 f->GetObject("trees", treesTmp);
163 if (treesTmp) {
164 trees = std::unique_ptr<TObjArray>(treesTmp);
165 trees->SetOwner(); // to delete the objects when d-tor is called
166 ATH_MSG_DEBUG("setupBDT " << "BDTs read from TObjArray");
167 } else {
168 ATH_MSG_DEBUG("setupBDT " << "Reading trees individually");
169 trees = std::make_unique<TObjArray>();
170 trees->SetOwner(); // to delete the objects when d-tor is called
171 for (int i = 0; i < variables->GetEntries(); ++i)
172 {
173 TTree *tree = nullptr;
174 f->GetObject(Form("BDT%d", i), tree);
175 if (tree) tree->SetCacheSize(0);
176 trees->AddAtAndExpand(tree, i);
177 }
178 }
179
180 // Ensure the objects have (the same number of) entries
181 if (!trees->GetEntries() || !(trees->GetEntries() == variables->GetEntries())) {
182 ATH_MSG_FATAL("Tree has size " << trees->GetEntries()
183 << " while variables has size " << variables->GetEntries());
184 return StatusCode::FAILURE;
185 }
186
187 // Loop simultaneously over trees, variables and shifts
188 // Define the BDTs, the list of variables and the shift for each BDT
189 TObjString *str2;
190 TObjString *shift;
191 TTree *tree;
192 TIter nextTree(trees.get());
193 TIter nextVariables(variables.get());
194 TIter nextShift(shifts.get());
195 for (int i=0; (tree = (TTree*) nextTree()) && ((TObjString*) nextVariables()); ++i)
196 {
197 m_BDTs.emplace_back(tree);
198
199 std::vector<std::function<float(const xAOD::Egamma*, const xAOD::CaloCluster*)> > funcs;
200 // Loop over variables, which are separated by comma
201 char separator_var = ';';
202 if (getString(variables->At(i)).Index(";") < 1) separator_var = ','; // old versions
203 std::unique_ptr<TObjArray> tokens(getString(variables->At(i)).Tokenize(separator_var));
204 TIter nextVar(tokens.get());
205 while ((str2 = (TObjString*) nextVar()))
206 {
207 const TString& varName = getString(str2);
208 if (varName.Contains("npv") || varName.Contains("actualIntPerXing"))
209 continue;
210 if (!varName.Length()) {
211 ATH_MSG_FATAL("There was an empty variable name!");
212 return StatusCode::FAILURE;
213 }
214 try {
215 funcs.push_back(funcLibrary.at(varName.Data()));
216 } catch(const std::out_of_range& e) {
217 ATH_MSG_FATAL("Could not find formula for variable " << varName << ", error: " << e.what());
218 return StatusCode::FAILURE;
219 }
220 }
221 m_funcs->funcs.push_back(std::move(funcs));
222
223 if (m_shiftType == MEAN10TOTRUE) {
224 shift = (TObjString*) nextShift();
225 const TString& shiftFormula = getString(shift);
226 m_shifts.emplace_back("", shiftFormula);
227 }
228 }
229 return StatusCode::SUCCESS;
230
231}
static const TString & getString(TObject *obj)
a utility to get a TString out of an TObjString pointer
str varName
end cluster ToT and charge
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Egamma_v1 Egamma
Definition of the current "egamma version".
Definition Egamma.h:17
TChain * tree

◆ 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 >, AthCheckedComponent<::AthAlgTool >, and DerivationFramework::CfAthAlgTool.

◆ 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 308 of file AthCommonDataStore.h.

308 {
309 // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310 // << " size: " << m_vhka.size() << endmsg;
311 for (auto &a : m_vhka) {
313 for (auto k : keys) {
314 k->setOwner(this);
315 }
316 }
317 }
std::vector< SG::VarHandleKeyArray * > m_vhka

Member Data Documentation

◆ m_BDTs

std::vector<MVAUtils::BDT> egammaMVACalibTool::m_BDTs
private

Where the BDTs are stored.

Definition at line 125 of file egammaMVACalibTool.h.

◆ m_calibrationType

Gaudi::Property<int> egammaMVACalibTool::m_calibrationType
private
Initial value:
{this,
"CalibrationType", correctEaccordion,
"What type of calibration to apply"}

Definition at line 104 of file egammaMVACalibTool.h.

104 {this,
105 "CalibrationType", correctEaccordion,
106 "What type of calibration to apply"};

◆ m_clusterEif0

Gaudi::Property<bool> egammaMVACalibTool::m_clusterEif0
private
Initial value:
{this,
"useClusterIf0", true,
"Use cluster energy if MVA response is 0"}

Definition at line 108 of file egammaMVACalibTool.h.

108 {this,
109 "useClusterIf0", true,
110 "Use cluster energy if MVA response is 0"};

◆ m_detStore

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

Pointer to StoreGate (detector store by default)

Definition at line 393 of file AthCommonDataStore.h.

◆ m_evtStore

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

Pointer to StoreGate (event store by default)

Definition at line 390 of file AthCommonDataStore.h.

◆ m_folder

Gaudi::Property<std::string> egammaMVACalibTool::m_folder
private
Initial value:
{this,
"folder", "",
"string with folder for weight files"}

string with folder for weight files

Definition at line 113 of file egammaMVACalibTool.h.

113 {this,
114 "folder", "",
115 "string with folder for weight files"};

◆ m_funcs

std::unique_ptr<egammaMVACalibTool_detail::Funcs> egammaMVACalibTool::m_funcs
private

where the pointers to the funcs to calculate the vars per BDT

Definition at line 130 of file egammaMVACalibTool.h.

◆ m_hPoly

std::unique_ptr<TH2Poly> egammaMVACalibTool::m_hPoly
private

A TH2Poly used to extract bin numbers. Note there is an offset of 1.

Definition at line 122 of file egammaMVACalibTool.h.

◆ m_particleType

Gaudi::Property<int> egammaMVACalibTool::m_particleType
private
Initial value:
{this,
"What type of particle do we use"}

Definition at line 96 of file egammaMVACalibTool.h.

96 {this,
98 "What type of particle do we use"};

◆ m_shifts

std::vector<TFormula> egammaMVACalibTool::m_shifts
private

shifts formulas

Definition at line 133 of file egammaMVACalibTool.h.

◆ m_shiftType

Gaudi::Property<int> egammaMVACalibTool::m_shiftType
private
Initial value:
{this,
"ShiftType", MEAN10TOTRUE,
"Shift corrections to apply to value"}

Definition at line 100 of file egammaMVACalibTool.h.

100 {this,
101 "ShiftType", MEAN10TOTRUE,
102 "Shift corrections to apply to value"};

◆ m_useLayerCorrected

Gaudi::Property<bool> egammaMVACalibTool::m_useLayerCorrected
private
Initial value:
{this,
"use_layer_corrected", false,
"whether to use layer corrections"}

Definition at line 117 of file egammaMVACalibTool.h.

117 {this,
118 "use_layer_corrected", false,
119 "whether to use layer corrections"};

◆ m_varHandleArraysDeclared

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

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

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

Definition at line 398 of file AthCommonDataStore.h.


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