ATLAS Offline Software
AsgElectronSelectorTool.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Dear emacs, this is -*-c++-*-
6 
7 #ifndef __ASGELECTRONSELECTORTOOL__
8 #define __ASGELECTRONSELECTORTOOL__
9 
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"
18 #include "xAODEgamma/ElectronFwd.h"
19 #include <Eigen/Dense>
20 
21 class EventContext;
22 
24 
26  virtual public IAsgElectronLikelihoodTool
27 {
29 
30 public:
32  AsgElectronSelectorTool( const std::string& myname );
33 
34 
37 public:
39  virtual StatusCode initialize() override;
40 
41  // Main methods for IAsgSelectorTool interface
46  virtual const asg::AcceptInfo& getAcceptInfo() const override;
47 
49  asg::AcceptData accept( const xAOD::IParticle* part ) const override;
50  asg::AcceptData accept( const EventContext& ctx, const xAOD::IParticle* part ) const override;
51 
53  asg::AcceptData accept( const EventContext& ctx, const xAOD::Electron* eg ) const override {
54  return accept (ctx, eg, -99); // mu = -99 as input will force accept to grab the pileup variable from the xAOD object
55  }
56 
58  asg::AcceptData accept( const EventContext& ctx, const xAOD::Egamma* eg ) const override {
59  return accept (ctx, eg, -99); // mu = -99 as input will force accept to grab the pileup variable from the xAOD object
60  }
61 
63  asg::AcceptData accept( const EventContext& ctx, const xAOD::Electron* eg, double mu ) const override;
64 
66  asg::AcceptData accept( const EventContext& ctx, const xAOD::Egamma* eg, double mu ) const override;
67 
68  // Main methods for IAsgCalculatorTool interface
69 public:
71  double calculate( const xAOD::IParticle* part ) const;
72  double calculate( const EventContext &ctx, const xAOD::IParticle* part ) const override;
73 
75  double calculate( const EventContext &ctx, const xAOD::Electron* eg ) const override {
76  return calculate (ctx, eg, -99); // mu = -99 as input will force accept to grab the pileup variable from the xAOD object
77  }
78 
80  double calculate( const EventContext &ctx, const xAOD::Egamma* eg ) const override {
81  return calculate (ctx, eg, -99); // mu = -99 as input will force accept to grab the pileup variable from the xAOD object
82  }
83 
85  double calculate( const EventContext &ctx, const xAOD::Electron* eg, double mu ) const override;
86 
88  double calculate( const EventContext &ctx, const xAOD::Egamma* eg, double mu ) const override;
89 
91  double getDiscriminant(std::vector<float>& mvaOutputs, const xAOD::Electron* egu ) const;
92 
94  std::vector<float> calculateMultipleOutputs( const EventContext &ctx, const xAOD::Electron *eg, double mu = -99) const override;
95 
96  virtual std::string getOperatingPointName() const override;
97 
98  // Private methods
99 private:
102 
104  bool isForwardElectron( const xAOD::Egamma* eg, const float eta ) const;
105 
107  double transformMLOutput( float score ) const;
108 
110  double combineOutputs(const std::vector<float>& mvaScores, double eta) const;
111  static double combineOutputsCF(const std::vector<float>& mvaScores) ;
112 
114  static unsigned int getDiscEtaBin( double eta ) ;
115 
117  static unsigned int getDiscEtBin( double et ) ;
118 
119  // NOTE that this will only perform the cut interpolation up to ~45 GeV, so
120  // no smoothing is done above this for the high ET MVA binning yet
122  static double interpolateCuts( const std::vector<double>& cuts, double et, double eta ) ;
123 
124 
125 
126  // Private member variables
127 private:
128 
130  std::string m_workingPoint;
131 
133  std::string m_configFile;
134 
136  std::unique_ptr<const ElectronDNNCalculator> m_mvaTool;
137 
139  std::string m_modelFileName;
140 
142  std::string m_quantileFileName;
143 
145  std::vector<std::string> m_variables;
146 
148  std::vector<int> m_enum_variables;
149 
152 
154 
156  bool m_multiClass{};
158  bool m_CFReject{};
160  bool m_cfSignal{};
162  std::vector<double> m_fractions;
163 
165  std::vector<int> m_cutAmbiguity;
167  std::vector<int> m_cutBL;
169  std::vector<int> m_cutPi;
171  std::vector<int> m_cutSCT;
175  std::vector<double> m_cutSelector;
176  std::vector<double> m_cutSelectorCF;
177 
178 
191 
193  std::vector<float> m_defaultVector;
194 
196  static const unsigned int s_fnDiscEtBins = 10;
198  static const unsigned int s_fnDiscEtaBins = 10;
199 
200 
201 }; // End: class definition
202 
203 #endif
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
AsgElectronSelectorTool
Electron selector tool to select signal electrons using the ElectronDNNCalculator retrieve a score ba...
Definition: AsgElectronSelectorTool.h:27
AsgElectronSelectorTool::getDiscriminant
double getDiscriminant(std::vector< float > &mvaOutputs, const xAOD::Electron *egu) const
Computes discrimiant value from mva output based on whether multiclass is true or false.
Definition: AsgElectronSelectorTool.cxx:564
AsgElectronSelectorTool::m_cutPosition_kinematic
int m_cutPosition_kinematic
The position of the kinematic cut bit in the AcceptInfo return object.
Definition: AsgElectronSelectorTool.h:180
et
Extra patterns decribing particle interation process.
asg::AsgTool
Base class for the dual-use tool implementation classes.
Definition: AsgTool.h:47
AsgElectronSelectorTool::m_cutPi
std::vector< int > m_cutPi
cut min on pixel hits
Definition: AsgElectronSelectorTool.h:169
AsgElectronSelectorTool::calculate
double calculate(const EventContext &ctx, const xAOD::Electron *eg) const override
The main result method: the actual mva score is calculated here.
Definition: AsgElectronSelectorTool.h:75
AsgElectronSelectorTool::m_configFile
std::string m_configFile
The input config file.
Definition: AsgElectronSelectorTool.h:133
ParticleTest.eg
eg
Definition: ParticleTest.py:29
AsgElectronSelectorTool::m_variables
std::vector< std::string > m_variables
Variables used in the MVA Tool.
Definition: AsgElectronSelectorTool.h:145
AsgElectronSelectorTool::m_mvaTool
std::unique_ptr< const ElectronDNNCalculator > m_mvaTool
Pointer to the class that calculates the MVA score.
Definition: AsgElectronSelectorTool.h:136
AsgElectronSelectorTool::combineOutputsCF
static double combineOutputsCF(const std::vector< float > &mvaScores)
Definition: AsgElectronSelectorTool.cxx:1007
ASG_TOOL_CLASS2
#define ASG_TOOL_CLASS2(CLASSNAME, INT1, INT2)
Definition: AsgToolMacros.h:77
AsgElectronSelectorTool::m_enum_variables
std::vector< int > m_enum_variables
Enum version of used variables.
Definition: AsgElectronSelectorTool.h:148
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
AsgElectronSelectorTool::getOperatingPointName
virtual std::string getOperatingPointName() const override
Get the name of the current operating point.
Definition: AsgElectronSelectorTool.cxx:869
AsgElectronSelectorTool::AsgElectronSelectorTool
AsgElectronSelectorTool(const std::string &myname)
Standard constructor.
Definition: AsgElectronSelectorTool.cxx:91
AsgElectronSelectorTool::accept
asg::AcceptData accept(const EventContext &ctx, const xAOD::Egamma *eg) const override
The main accept method: the actual cuts are applied here.
Definition: AsgElectronSelectorTool.h:58
AsgElectronSelectorTool::getDiscEtBin
static unsigned int getDiscEtBin(double et)
Gets the Descriminant Et bin the et (MeV) [0,s_fnDiscEtBins-1].
Definition: AsgElectronSelectorTool.cxx:1028
AsgElectronSelectorTool::m_defaultVector
std::vector< float > m_defaultVector
Default vector to return if calculation fails.
Definition: AsgElectronSelectorTool.h:193
AsgElectronSelectorTool::m_modelFileName
std::string m_modelFileName
The input file name that holds the model.
Definition: AsgElectronSelectorTool.h:139
xAOD::Egamma_v1
Definition: Egamma_v1.h:56
AsgElectronSelectorTool::m_CFReject
bool m_CFReject
Run CF rejection or not.
Definition: AsgElectronSelectorTool.h:158
IAsgSelectionTool
Definition: IAsgSelectionTool.h:28
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
AsgElectronSelectorTool::m_cutAmbiguity
std::vector< int > m_cutAmbiguity
do cut on ambiguity bit
Definition: AsgElectronSelectorTool.h:165
AsgElectronSelectorTool::m_cutSelector
std::vector< double > m_cutSelector
cut on mva output
Definition: AsgElectronSelectorTool.h:175
AsgElectronSelectorTool::accept
asg::AcceptData accept(const xAOD::IParticle *part) const override
The main accept method: using the generic interface.
Definition: AsgElectronSelectorTool.cxx:875
AsgElectronSelectorTool::calculate
double calculate(const EventContext &ctx, const xAOD::Egamma *eg) const override
The main result method: the actual mva score is calculated here.
Definition: AsgElectronSelectorTool.h:80
IAsgElectronLikelihoodTool.h
AsgElectronSelectorTool::m_cfSignal
bool m_cfSignal
Use the CF output node in the numerator or the denominator.
Definition: AsgElectronSelectorTool.h:160
AsgElectronSelectorTool::m_multiClass
bool m_multiClass
Multiclass model or not.
Definition: AsgElectronSelectorTool.h:156
asg::AcceptInfo
Definition: AcceptInfo.h:28
AsgElectronSelectorTool::m_cutPosition_NBlayer
int m_cutPosition_NBlayer
The position of the NBlayer cut bit in the AcceptInfo return object.
Definition: AsgElectronSelectorTool.h:186
AsgElectronSelectorTool::accept
asg::AcceptData accept(const EventContext &ctx, const xAOD::Electron *eg) const override
The main accept method: the actual cuts are applied here.
Definition: AsgElectronSelectorTool.h:53
AsgElectronSelectorTool::m_quantileFileName
std::string m_quantileFileName
The input file name that holds the QuantileTransformer.
Definition: AsgElectronSelectorTool.h:142
AsgElectronSelectorTool::initialize
virtual StatusCode initialize() override
Gaudi Service Interface method implementations.
Definition: AsgElectronSelectorTool.cxx:122
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AsgElectronSelectorTool::getDiscEtaBin
static unsigned int getDiscEtaBin(double eta)
Gets the Discriminant Eta bin [0,s_fnDiscEtaBins-1] given the eta.
Definition: AsgElectronSelectorTool.cxx:1017
AsgElectronSelectorTool::calculate
double calculate(const xAOD::IParticle *part) const
The main result method: the actual mva score is calculated here.
Definition: AsgElectronSelectorTool.cxx:894
AsgElectronSelectorTool::calculateMultipleOutputs
std::vector< float > calculateMultipleOutputs(const EventContext &ctx, const xAOD::Electron *eg, double mu=-99) const override
The result method for multiple outputs: can return multiple outputs of the MVA.
Definition: AsgElectronSelectorTool.cxx:582
plotBeamSpotVert.cuts
string cuts
Definition: plotBeamSpotVert.py:93
ElectronFwd.h
EventPrimitives.h
AsgElectronSelectorTool::interpolateCuts
static double interpolateCuts(const std::vector< double > &cuts, double et, double eta)
Interpolates cut values along pt.
Definition: AsgElectronSelectorTool.cxx:1042
AsgElectronSelectorTool::m_fractions
std::vector< double > m_fractions
Fractions to combine the output nodes of a multiclass model into one discriminant.
Definition: AsgElectronSelectorTool.h:162
AsgElectronSelectorTool::m_skipAmbiguityCut
bool m_skipAmbiguityCut
Definition: AsgElectronSelectorTool.h:153
AsgElectronSelectorTool::m_doSmoothBinInterpolation
bool m_doSmoothBinInterpolation
do smooth interpolation between bins
Definition: AsgElectronSelectorTool.h:173
ElectronDNNCalculator
Used by AsgElectronSelectorTool to calculate the score of a python trained DNN using lwtnn as interfa...
Definition: ElectronDNNCalculator.h:24
xAOD::Electron_v1
Definition: Electron_v1.h:34
AsgElectronSelectorTool::m_cutPosition_NPixel
int m_cutPosition_NPixel
The position of the NPixel cut bit in the AcceptInfo return object.
Definition: AsgElectronSelectorTool.h:184
AsgElectronSelectorTool::m_cutPosition_MVA
int m_cutPosition_MVA
The position of the MVA cut bit in the AcceptInfo return object.
Definition: AsgElectronSelectorTool.h:190
AsgElectronSelectorTool::m_cutPosition_ambiguity
int m_cutPosition_ambiguity
The position of the ambiguity cut bit in the AcceptInfo return object.
Definition: AsgElectronSelectorTool.h:188
IAsgElectronLikelihoodTool
Interface to tool to select electrons.
Definition: IAsgElectronLikelihoodTool.h:27
xAOD::score
@ score
Definition: TrackingPrimitives.h:513
AsgElectronSelectorTool::m_workingPoint
std::string m_workingPoint
Working Point.
Definition: AsgElectronSelectorTool.h:130
AsgElectronSelectorTool::m_cutBL
std::vector< int > m_cutBL
cut min on b-layer hits
Definition: AsgElectronSelectorTool.h:167
AsgElectronSelectorTool::s_fnDiscEtaBins
static const unsigned int s_fnDiscEtaBins
number of discriminants vs |eta|
Definition: AsgElectronSelectorTool.h:198
AsgElectronSelectorTool::isForwardElectron
bool isForwardElectron(const xAOD::Egamma *eg, const float eta) const
check for FwdElectron
Definition: AsgElectronSelectorTool.cxx:941
AsgElectronSelectorTool::transformMLOutput
double transformMLOutput(float score) const
Applies a logit transformation to the score returned by the underlying MVA tool.
Definition: AsgElectronSelectorTool.cxx:965
AsgElectronSelectorTool::m_cutPosition_NSilicon
int m_cutPosition_NSilicon
The position of the NSilicon cut bit in the AcceptInfo return object.
Definition: AsgElectronSelectorTool.h:182
AsgElectronSelectorTool::~AsgElectronSelectorTool
virtual ~AsgElectronSelectorTool()
Standard destructor.
AsgElectronSelectorTool::m_acceptMVA
asg::AcceptInfo m_acceptMVA
Accept info.
Definition: AsgElectronSelectorTool.h:101
AsgElectronSelectorTool::combineOutputs
double combineOutputs(const std::vector< float > &mvaScores, double eta) const
Combines the six output nodes of a multiclass model into one discriminant.
Definition: AsgElectronSelectorTool.cxx:978
AsgElectronSelectorTool::getAcceptInfo
virtual const asg::AcceptInfo & getAcceptInfo() const override
Method to get the plain AcceptInfo.
Definition: AsgElectronSelectorTool.cxx:346
AsgElectronSelectorTool::m_cutSCT
std::vector< int > m_cutSCT
cut min on precision hits
Definition: AsgElectronSelectorTool.h:171
AsgTool.h
asg::AcceptData
Definition: AcceptData.h:30
AsgElectronSelectorTool::m_cutSelectorCF
std::vector< double > m_cutSelectorCF
Definition: AsgElectronSelectorTool.h:176
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
AsgElectronSelectorTool::s_fnDiscEtBins
static const unsigned int s_fnDiscEtBins
number of discrimintants vs Et
Definition: AsgElectronSelectorTool.h:196
AsgElectronSelectorTool::m_skipDeltaPoverP
bool m_skipDeltaPoverP
Flag for skip the use of deltaPoverP in dnn calculation (like at HLT)
Definition: AsgElectronSelectorTool.h:151