Used by AsgElectronSelectorTool to calculate the score of a python trained DNN using lwtnn as interface to do electron ID. Also applies a transformation to the input variables based on a QuantileTransformer.
More...
#include <ElectronDNNCalculator.h>
|
std::unique_ptr< lwt::generic::FastGraph< float > > | m_graph = 0 |
| DNN interface via lwtnn. More...
|
|
std::vector< std::vector< double > > | m_quantiles |
| Quantile values for each variable that needs to be transformed with the QuantileTransformer. More...
|
|
std::vector< double > | m_references |
| Reference values for the QuantileTransformer. Basically just equidistant bins between 0 and 1. More...
|
|
bool | m_multiClass |
| Whether the used model is a multiclass model or not. More...
|
|
std::vector< std::string > | m_variables |
| Model variables. More...
|
|
uint | m_var_size |
|
std::function< MsgStream &()> | m_msg |
| the message stream we use More...
|
|
Used by AsgElectronSelectorTool to calculate the score of a python trained DNN using lwtnn as interface to do electron ID. Also applies a transformation to the input variables based on a QuantileTransformer.
- Author
- Lukas Ehrke
Definition at line 23 of file ElectronDNNCalculator.h.
◆ ElectronDNNCalculator()
ElectronDNNCalculator::ElectronDNNCalculator |
( |
AsgElectronSelectorTool * |
owner, |
|
|
const std::string & |
modelFileName, |
|
|
const std::string & |
quantileFileName, |
|
|
const std::vector< std::string > & |
variablesName, |
|
|
const bool |
multiClass |
|
) |
| |
Constructor of the class.
Definition at line 26 of file ElectronDNNCalculator.cxx.
39 if (modelFileName.empty()){
40 throw std::runtime_error(
"No file found at '" + modelFileName +
"'");
47 ATH_MSG_INFO(
"Loading model: " << modelFileName.c_str());
50 lwt::InputOrder
order;
57 size_t nOutputs = parsedGraph.outputs.begin()->second.labels.size();
58 if (nOutputs != 6 && nOutputs != 1){
59 throw std::runtime_error(
"Given model does not have 1 or 6 outputs. Something seems to be wrong with the model file.");
62 throw std::runtime_error(
"Given model has 1 output but config file specifies mutliclass. Something is wrong");
65 throw std::runtime_error(
"Given model has 6 output but config file does not specify mutliclass. Something is wrong");
68 m_graph = std::make_unique<lwt::generic::FastGraph<float>>(parsedGraph,
order);
70 if (quantileFileName.empty()){
71 throw std::runtime_error(
"No file found at '" + quantileFileName +
"'");
75 ATH_MSG_INFO(
"Loading QuantileTransformer " << quantileFileName);
76 std::unique_ptr<TFile> qtfile(TFile::Open(quantileFileName.data()));
78 throw std::runtime_error(
"Could not load all variables for the QuantileTransformer");
◆ ~ElectronDNNCalculator()
ElectronDNNCalculator::~ElectronDNNCalculator |
( |
| ) |
|
|
inline |
◆ calculate()
Eigen::Matrix< float, -1, 1 > ElectronDNNCalculator::calculate |
( |
const std::vector< double > & |
variableValues | ) |
const |
Get the prediction of the DNN model.
Definition at line 85 of file ElectronDNNCalculator.cxx.
89 throw std::runtime_error(
"Passed vector of variables has wrong size");
99 std::vector<Eigen::VectorXf> inp;
100 inp.emplace_back(std::move(inputVector));
◆ msg() [1/2]
MsgStream & asg::AsgMessagingForward::msg |
( |
| ) |
const |
|
inherited |
The standard message stream.
- Returns
- A reference to the default message stream of this object.
Definition at line 24 of file AsgMessagingForward.cxx.
◆ msg() [2/2]
MsgStream & asg::AsgMessagingForward::msg |
( |
const MSG::Level |
lvl | ) |
const |
|
inherited |
The standard message stream.
- Parameters
-
lvl | The message level to set the stream to |
- Returns
- A reference to the default message stream, set to level "lvl"
Definition at line 29 of file AsgMessagingForward.cxx.
◆ msgLvl()
bool asg::AsgMessagingForward::msgLvl |
( |
const MSG::Level |
lvl | ) |
const |
|
inherited |
Test the output level of the object.
- Parameters
-
lvl | The message level to test against |
- Returns
- boolean Indicting if messages at given level will be printed
-
true
If messages at level "lvl" will be printed
Definition at line 11 of file AsgMessagingForward.cxx.
14 if (
msg.level() <= lvl)
◆ readQuantileTransformer()
int ElectronDNNCalculator::readQuantileTransformer |
( |
TTree * |
tree | ) |
|
|
private |
read the bins and values of the QuantileTransformer to transform the input variables.
Definition at line 142 of file ElectronDNNCalculator.cxx.
149 std::map<std::string, double> readVars;
151 sc =
tree->SetBranchAddress(TString(
var), &readVars[
var]) == -5 ? 0 : 1;
154 for (
int ientry = 0; ientry <
tree->GetEntries(); ientry++){
155 tree->GetEntry(ientry);
◆ transformInput()
double ElectronDNNCalculator::transformInput |
( |
const std::vector< double > & |
quantiles, |
|
|
double |
value |
|
) |
| const |
|
private |
transform the input variables according to a given QuantileTransformer.
Definition at line 110 of file ElectronDNNCalculator.cxx.
112 int size = quantiles.size();
119 auto lowBound = std::lower_bound(quantiles.begin(), quantiles.end(),
value);
120 int lowBin =
lowBound - quantiles.begin() - 1;
123 double xLup = quantiles[lowBin], yLup =
m_references[lowBin], xRup = quantiles[lowBin+1], yRup =
m_references[lowBin+1];
126 auto upperBound = std::upper_bound(quantiles.begin(), quantiles.end(),
value);
127 int upperBin = upperBound - quantiles.begin();
130 double xRdown = quantiles[upperBin], yRdown =
m_references[upperBin], xLdown = quantiles[upperBin-1], yLdown =
m_references[upperBin-1];
133 double dydxup = ( yRup - yLup ) / ( xRup - xLup );
134 double dydxdown = ( yRdown - yLdown ) / ( xRdown - xLdown );
137 return 0.5 * ((yLup + dydxup * (
value - xLup)) + (yLdown + dydxdown * (
value - xLdown)));
◆ m_graph
std::unique_ptr<lwt::generic::FastGraph<float> > ElectronDNNCalculator::m_graph = 0 |
|
private |
◆ m_msg
std::function<MsgStream& ()> asg::AsgMessagingForward::m_msg |
|
privateinherited |
the message stream we use
This used to be a simple pointer to the MsgStream
itself, but in AthenaMT the actual object used is local to the thread. So instead of pointing to it directly we are now using a function to look it up, which will get the thread-local object.
Definition at line 77 of file AsgMessagingForward.h.
◆ m_multiClass
bool ElectronDNNCalculator::m_multiClass |
|
private |
◆ m_quantiles
std::vector<std::vector<double> > ElectronDNNCalculator::m_quantiles |
|
private |
Quantile values for each variable that needs to be transformed with the QuantileTransformer.
Definition at line 49 of file ElectronDNNCalculator.h.
◆ m_references
std::vector<double> ElectronDNNCalculator::m_references |
|
private |
Reference values for the QuantileTransformer. Basically just equidistant bins between 0 and 1.
Definition at line 51 of file ElectronDNNCalculator.h.
◆ m_var_size
uint ElectronDNNCalculator::m_var_size |
|
private |
◆ m_variables
std::vector<std::string> ElectronDNNCalculator::m_variables |
|
private |
The documentation for this class was generated from the following files: