ATLAS Offline Software
Loading...
Searching...
No Matches
AsgElectronSelectorTool.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Dear emacs, this is -*-c++-*-
6
7#ifndef __ASGELECTRONSELECTORTOOL__
8#define __ASGELECTRONSELECTORTOOL__
9#include "TEnv.h"
10// This include is needed at the top before any includes regarding Eigen
11// since it includes Eigen in a specific way which causes compilation errors
12// if not included before Eigen
14
15// Atlas includes
16#include "AsgTools/AsgTool.h"
19#include <Eigen/Dense>
20
21class EventContext;
22
24
26 virtual public IAsgElectronLikelihoodTool
27{
29
30public:
32 AsgElectronSelectorTool( const std::string& myname );
33
34
37public:
38
40
41 std::vector<std::vector<float>> layerOutputs;
42
43 };
44
45 virtual StatusCode initialize() override;
46
47 // Main methods for IAsgSelectorTool interface
52 virtual const asg::AcceptInfo& getAcceptInfo() const override;
53
55 asg::AcceptData accept( const xAOD::IParticle* part ) const override;
56 asg::AcceptData accept( const EventContext& ctx, const xAOD::IParticle* part ) const override;
57
59 asg::AcceptData accept( const EventContext& ctx, const xAOD::Electron* eg ) const override {
60 return accept (ctx, eg, -99); // mu = -99 as input will force accept to grab the pileup variable from the xAOD object
61 }
62
64 asg::AcceptData accept( const EventContext& ctx, const xAOD::Egamma* eg ) const override {
65 return accept (ctx, eg, -99); // mu = -99 as input will force accept to grab the pileup variable from the xAOD object
66 }
67
69 asg::AcceptData accept( const EventContext& ctx, const xAOD::Electron* eg, double mu ) const override;
70
72 asg::AcceptData accept( const EventContext& ctx, const xAOD::Egamma* eg, double mu ) const override;
73
74 // Main methods for IAsgCalculatorTool interface
75public:
77 double calculate( const xAOD::IParticle* part ) const;
78 double calculate( const EventContext &ctx, const xAOD::IParticle* part ) const override;
79
81 double calculate( const EventContext &ctx, const xAOD::Electron* eg ) const override {
82 return calculate (ctx, eg, -99); // mu = -99 as input will force accept to grab the pileup variable from the xAOD object
83 }
84
86 double calculate( const EventContext &ctx, const xAOD::Egamma* eg ) const override {
87 return calculate (ctx, eg, -99); // mu = -99 as input will force accept to grab the pileup variable from the xAOD object
88 }
89
91 double calculate( const EventContext &ctx, const xAOD::Electron* eg, double mu ) const override;
92
94 double calculate( const EventContext &ctx, const xAOD::Egamma* eg, double mu ) const override;
95
97 SelectorOutputs runSelections(const EventContext &ctx,const xAOD::Electron *eg, double mu) const;
98
99 virtual std::vector<float> calculateMultipleOutputs( const EventContext &ctx, const xAOD::Electron *eg, double mu = -99) const override;
100
102 std::vector<double> getDiscriminant(const SelectorOutputs& mvaOutputs, const xAOD::Electron* egu ) const;
103
104 virtual std::string getOperatingPointName() const override;
105
106 // Private methods
107private:
110
112 bool isForwardElectron( const xAOD::Egamma* eg, const float eta ) const;
113
115 double transformMLOutput( float score ) const;
116
118 double combineOutputs(const std::vector<float>& mvaScores, double eta, const std::vector<double>& fractions, bool cfSignal = false ) const;
119 static double combineOutputsCF(const std::vector<float>& mvaScores) ;
120
122 static unsigned int getDiscEtaBin( double eta ) ;
123
125 static unsigned int getDiscEtBin( double et ) ;
126
127 // NOTE that this will only perform the cut interpolation up to ~45 GeV, so
128 // no smoothing is done above this for the high ET MVA binning yet
130 static double interpolateCuts( const std::vector<double>& cuts, double et, double eta ) ;
131
132
133
134 // Private member variables
135private:
136
138 std::string name; // e.g. "FirstSelection" or "SecondSelection"
139 std::string prefix; // e.g. "" for Layer 0, "SecondSelection." for Layer 1
140
142 std::unique_ptr<const ElectronDNNCalculator> m_mvaTool;
143
145 std::vector<std::string> m_variables;
146
148 std::vector<int> m_enum_variables;
149
150 unsigned int m_nOutputs = 0;
151
159 std::vector<double> m_fractions;
161 std::vector<int> m_cutAmbiguity;
163 std::vector<int> m_cutBL;
165 std::vector<int> m_cutPi;
167 std::vector<int> m_cutSCT;
169 std::vector<double> m_cutSelector;
170 std::vector<double> m_cutSelectorCF;
172 std::vector<float> m_defaultOutputs;
173
174 bool initialize(TEnv& env,
175 const std::string& prefixName,
176 const std::string& layerName,
177 const std::string& m_modelFileName,
178 const std::string& m_quantileFileName,
179 asg::AsgTool* parentTool);
180 std::vector<float> evaluate(const std::vector<double>& inputs) const;
181 };
182
183 std::string m_workingPoint;
184
186 std::string m_configFile;
188 std::string m_modelFileName;
189
196 static const unsigned int s_fnDiscEtBins = 10;
197 static const unsigned int s_fnDiscEtaBins = 10;
198
199 std::vector<SelectionLayer> m_layers;
212
213}; // End: class definition
214
215#endif
Scalar eta() const
pseudorapidity method
#define ASG_TOOL_CLASS2(CLASSNAME, INT1, INT2)
virtual std::string getOperatingPointName() const override
Get the name of the current operating point.
static const unsigned int s_fnDiscEtBins
asg::AcceptData accept(const EventContext &ctx, const xAOD::Electron *eg) const override
The main accept method: the actual cuts are applied here.
virtual const asg::AcceptInfo & getAcceptInfo() const override
Method to get the plain AcceptInfo.
std::string m_workingPoint
Working Point.
static unsigned int getDiscEtaBin(double eta)
Gets the Discriminant Eta bin [0,s_fnDiscEtaBins-1] given the eta.
int m_cutPosition_kinematic
The position of the kinematic cut bit in the AcceptInfo return object.
static unsigned int getDiscEtBin(double et)
Gets the Descriminant Et bin the et (MeV) [0,s_fnDiscEtBins-1].
virtual StatusCode initialize() override
Gaudi Service Interface method implementations.
std::string m_modelFileName
The input file name that holds the model.
double calculate(const EventContext &ctx, const xAOD::Egamma *eg) const override
The main result method: the actual mva score is calculated here.
bool m_skipDeltaPoverP
Flag for skip the use of deltaPoverP in dnn calculation (like at HLT).
SelectorOutputs runSelections(const EventContext &ctx, const xAOD::Electron *eg, double mu) const
The result method for multiple outputs: can return multiple outputs of the MVA.
virtual ~AsgElectronSelectorTool()
Standard destructor.
static double interpolateCuts(const std::vector< double > &cuts, double et, double eta)
Interpolates cut values along pt.
static const unsigned int s_fnDiscEtaBins
asg::AcceptInfo m_acceptMVA
Accept info.
double calculate(const EventContext &ctx, const xAOD::Electron *eg) const override
The main result method: the actual mva score is calculated here.
virtual std::vector< float > calculateMultipleOutputs(const EventContext &ctx, const xAOD::Electron *eg, double mu=-99) const override
calculate all outputs of the underlying method (MVA) if it produces multiple outputs
int m_cutPosition_NPixel
The position of the NPixel cut bit in the AcceptInfo return object.
int m_cutPosition_NSilicon
The position of the NSilicon cut bit in the AcceptInfo return object.
asg::AcceptData accept(const EventContext &ctx, const xAOD::Egamma *eg) const override
The main accept method: the actual cuts are applied here.
std::string m_quantileFileName
The input file name that holds the QuantileTransformer.
bool isForwardElectron(const xAOD::Egamma *eg, const float eta) const
check for FwdElectron
AsgElectronSelectorTool(const std::string &myname)
Standard constructor.
int m_cutPosition_NBlayer
The position of the NBlayer cut bit in the AcceptInfo return object.
int m_cutPosition_MVA
The position of the MVA cut bit in the AcceptInfo return object.
double transformMLOutput(float score) const
Applies a logit transformation to the score returned by the underlying MVA tool.
double combineOutputs(const std::vector< float > &mvaScores, double eta, const std::vector< double > &fractions, bool cfSignal=false) const
Combines the six output nodes of a multiclass model into one discriminant.
double calculate(const xAOD::IParticle *part) const
The main result method: the actual mva score is calculated here.
asg::AcceptData accept(const xAOD::IParticle *part) const override
The main accept method: using the generic interface.
std::vector< double > getDiscriminant(const SelectorOutputs &mvaOutputs, const xAOD::Electron *egu) const
Computes discrimiant value from mva output based on whether multiclass is true or false.
static double combineOutputsCF(const std::vector< float > &mvaScores)
int m_cutPosition_ambiguity
The position of the ambiguity cut bit in the AcceptInfo return object.
std::string m_configFile
The input config file.
std::vector< SelectionLayer > m_layers
Used by AsgElectronSelectorTool to calculate the score of a python trained DNN using lwtnn as interfa...
Interface to tool to select electrons.
Base class for the dual-use tool implementation classes.
Definition AsgTool.h:47
Class providing the definition of the 4-vector interface.
Egamma_v1 Egamma
Definition of the current "egamma version".
Definition Egamma.h:17
Electron_v1 Electron
Definition of the current "egamma version".
Definition Electron.h:17
std::vector< int > m_cutSCT
cut min on precision hits
std::vector< int > m_enum_variables
Enum version of used variables.
std::vector< std::string > m_variables
Variables used in the MVA Tool.
std::vector< double > m_cutSelector
cut on mva output
std::vector< int > m_cutPi
cut min on pixel hits
bool m_cfSignal
Use the CF output node in the numerator or the denominator.
std::vector< float > evaluate(const std::vector< double > &inputs) const
std::unique_ptr< const ElectronDNNCalculator > m_mvaTool
Pointer to the class that calculates the MVA score.
std::vector< float > m_defaultOutputs
Default vector to return if calculation fails.
std::vector< double > m_fractions
Fractions to combine the output nodes of a multiclass model into one discriminant.
std::vector< int > m_cutAmbiguity
do cut on ambiguity bit
std::vector< int > m_cutBL
cut min on b-layer hits
std::vector< std::vector< float > > layerOutputs
Extra patterns decribing particle interation process.