ATLAS Offline Software
Loading...
Searching...
No Matches
AsgElectronSelectorTool::SelectionLayer Struct Reference
Collaboration diagram for AsgElectronSelectorTool::SelectionLayer:

Public Member Functions

bool initialize (TEnv &env, const std::string &prefixName, const std::string &layerName, const std::string &m_modelFileName, const std::string &m_quantileFileName, asg::AsgTool *parentTool)
std::vector< float > evaluate (const std::vector< double > &inputs) const

Public Attributes

std::string name
std::string prefix
std::unique_ptr< const ElectronDNNCalculator > m_mvaTool
 Pointer to the class that calculates the MVA score.
std::vector< std::string > m_variables
 Variables used in the MVA Tool.
std::vector< int > m_enum_variables
 Enum version of used variables.
unsigned int m_nOutputs
bool m_multiClass {}
 Multiclass model or not.
bool m_CFReject {}
 Run CF rejection or not.
bool m_cfSignal {}
 Use the CF output node in the numerator or the denominator.
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< int > m_cutPi
 cut min on pixel hits
std::vector< int > m_cutSCT
 cut min on precision hits
std::vector< double > m_cutSelector
 cut on mva output
std::vector< double > m_cutSelectorCF
std::vector< float > m_defaultOutputs
 Default vector to return if calculation fails.

Detailed Description

Definition at line 137 of file AsgElectronSelectorTool.h.

Member Function Documentation

◆ evaluate()

std::vector< float > AsgElectronSelectorTool::SelectionLayer::evaluate ( const std::vector< double > & inputs) const

Definition at line 199 of file AsgElectronSelectorTool.cxx.

199 {
200 if (!m_mvaTool) return m_defaultOutputs;
201 auto scores = m_mvaTool->calculate(inputs);
202 std::vector<float> res(scores.rows());
203 for (int i = 0; i < scores.rows(); ++i) {
204 res[i] = scores(i, 0);
205 }
206 return res;
207}
std::vector< std::vector< float > > scores
std::pair< std::vector< unsigned int >, bool > res
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.

◆ initialize()

bool AsgElectronSelectorTool::SelectionLayer::initialize ( TEnv & env,
const std::string & prefixName,
const std::string & layerName,
const std::string & m_modelFileName,
const std::string & m_quantileFileName,
asg::AsgTool * parentTool )

Definition at line 89 of file AsgElectronSelectorTool.cxx.

96 {
97 prefix = prefixName;
99 unsigned int numberOfExpectedBinCombinedMVA = AsgElectronSelectorTool::s_fnDiscEtBins * AsgElectronSelectorTool::s_fnDiscEtaBins;
100 unsigned int numberOfExpectedEtaBins = AsgElectronSelectorTool::s_fnDiscEtBins;
101 // 1. Getting quantiles and model files
102 std::string modelFile = !userModelFileName.empty()
103 ? userModelFileName
104 : env.GetValue((prefix + "inputModelFileName").c_str(), "");
105
106 std::string quantileFile = !userQuantileFileName.empty()
107 ? userQuantileFileName
108 : env.GetValue((prefix + "inputQuantileFileName").c_str(), "");
109
110 std::string modelPath = PathResolverFindCalibFile(modelFile);
111 std::string quantilePath = PathResolverFindCalibFile(quantileFile);
112
113 if (modelPath.empty() || quantilePath.empty()) {
114 return false;
115 }
116
117 // 2.
118 m_multiClass = env.GetValue((prefix + "multiClass").c_str(), false);
119 m_nOutputs = env.GetValue((prefix + "n_outputs").c_str(), m_multiClass ? 6 : 1);
120 // Include cf node in numerator or denominator when combining different outputs
121 m_cfSignal = env.GetValue((prefix + "cfSignal").c_str(), false);
122
123 // 3.
124 std::string varStr = env.GetValue((prefix + "Variables").c_str(), "");
125 std::stringstream varsStream(varStr);
126 std::string substr;
127
128 std::vector<std::string> tempVariables;
129 m_enum_variables.clear();
130
131 while (std::getline(varsStream, substr, ',')) {
132 if (substr.empty()) continue;
133 if (!prefix.empty() && substr.rfind(prefix, 0) == 0) {
134 substr = substr.substr(prefix.length());
135 }
137 return false;
138 }
139 tempVariables.push_back(substr);
141 }
142
143 if (tempVariables.empty()) return false;
144
145 m_cutAmbiguity = AsgConfigHelper::HelperInt((prefix + "CutAmbiguity").c_str(), env);
146 m_cutBL = AsgConfigHelper::HelperInt((prefix + "CutBL").c_str(), env);
147 m_cutPi = AsgConfigHelper::HelperInt((prefix + "CutPi").c_str(), env);
148 m_cutSCT = AsgConfigHelper::HelperInt((prefix + "CutSCT").c_str(), env);
149 m_fractions = AsgConfigHelper::HelperDouble((prefix + "Fractions").c_str(), env);
150 m_cutSelector = AsgConfigHelper::HelperDouble((prefix + "CutSelector").c_str(), env);
151 m_cutSelectorCF = AsgConfigHelper::HelperDouble((prefix + "CutSelectorCF").c_str(), env);
152
153
154
155 if (m_cutSelector.size() != numberOfExpectedBinCombinedMVA){
156 parentTool->msg(MSG::ERROR) <<"Configuration issue : cutSelector expected size " << numberOfExpectedBinCombinedMVA <<
157 " input size " << m_cutSelector.size();
158 return false;
159 }
160 if (!m_cutSelectorCF.empty()){
161 m_CFReject = true;
162 if (m_cutSelectorCF.size() != numberOfExpectedBinCombinedMVA){
163 parentTool->msg(MSG::ERROR) <<"Configuration issue : cutSelectorCF expected size " << numberOfExpectedBinCombinedMVA <<
164 " input size " << m_cutSelectorCF.size();
165 return false;
166 }
167 if(!m_multiClass){
168 parentTool->msg(MSG::ERROR) <<"Configuration issue : CF rejection is only defined "
169 "for multiClass: TRUE";
170 return false;
171 }
172 } else {
173 m_CFReject = false;
174 }
175
176 if (m_multiClass){
177 unsigned int nFractionsPerBin = m_nOutputs - 1;
178 unsigned int expectedFractionsSize = numberOfExpectedEtaBins * nFractionsPerBin;
179
180 if (m_fractions.size() != expectedFractionsSize) {
181 parentTool->msg(MSG::ERROR) <<"Configuration issue: multiclass is TRUE, but the number of fractions ("
182 << m_fractions.size() << ") does not match " << m_nOutputs << " classes ("
183 << expectedFractionsSize << " fractions expected).";
184 return false;
185 }
186 }
187
188 m_mvaTool = std::make_unique<ElectronDNNCalculator>(
189 dynamic_cast<AsgElectronSelectorTool*>(parentTool),
190 modelPath.c_str(),
191 quantilePath.c_str(),
192 tempVariables
193 );
194
195 m_defaultOutputs = std::vector<float>(m_nOutputs, -999.0f);
196 return true;
197}
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
static const unsigned int s_fnDiscEtBins
static const unsigned int s_fnDiscEtaBins
AsgElectronSelectorTool(const std::string &myname)
Standard constructor.
MsgStream & msg() const
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:116
const std::unordered_map< std::string, int > variableMap
std::vector< int > HelperInt(const std::string &input, TEnv &env)
std::vector< double > HelperDouble(const std::string &input, TEnv &env)
mapped_type at(key_type key) const
Look up an element in the map.
const std::string & layerName(LayerIndex index)
convert LayerIndex into a string
std::vector< int > m_cutSCT
cut min on precision hits
std::vector< int > m_enum_variables
Enum version of used variables.
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< 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

Member Data Documentation

◆ m_CFReject

bool AsgElectronSelectorTool::SelectionLayer::m_CFReject {}

Run CF rejection or not.

Definition at line 155 of file AsgElectronSelectorTool.h.

155{};

◆ m_cfSignal

bool AsgElectronSelectorTool::SelectionLayer::m_cfSignal {}

Use the CF output node in the numerator or the denominator.

Definition at line 157 of file AsgElectronSelectorTool.h.

157{};

◆ m_cutAmbiguity

std::vector<int> AsgElectronSelectorTool::SelectionLayer::m_cutAmbiguity

do cut on ambiguity bit

Definition at line 161 of file AsgElectronSelectorTool.h.

◆ m_cutBL

std::vector<int> AsgElectronSelectorTool::SelectionLayer::m_cutBL

cut min on b-layer hits

Definition at line 163 of file AsgElectronSelectorTool.h.

◆ m_cutPi

std::vector<int> AsgElectronSelectorTool::SelectionLayer::m_cutPi

cut min on pixel hits

Definition at line 165 of file AsgElectronSelectorTool.h.

◆ m_cutSCT

std::vector<int> AsgElectronSelectorTool::SelectionLayer::m_cutSCT

cut min on precision hits

Definition at line 167 of file AsgElectronSelectorTool.h.

◆ m_cutSelector

std::vector<double> AsgElectronSelectorTool::SelectionLayer::m_cutSelector

cut on mva output

Definition at line 169 of file AsgElectronSelectorTool.h.

◆ m_cutSelectorCF

std::vector<double> AsgElectronSelectorTool::SelectionLayer::m_cutSelectorCF

Definition at line 170 of file AsgElectronSelectorTool.h.

◆ m_defaultOutputs

std::vector<float> AsgElectronSelectorTool::SelectionLayer::m_defaultOutputs

Default vector to return if calculation fails.

Definition at line 172 of file AsgElectronSelectorTool.h.

◆ m_enum_variables

std::vector<int> AsgElectronSelectorTool::SelectionLayer::m_enum_variables

Enum version of used variables.

Definition at line 148 of file AsgElectronSelectorTool.h.

◆ m_fractions

std::vector<double> AsgElectronSelectorTool::SelectionLayer::m_fractions

Fractions to combine the output nodes of a multiclass model into one discriminant.

Definition at line 159 of file AsgElectronSelectorTool.h.

◆ m_multiClass

bool AsgElectronSelectorTool::SelectionLayer::m_multiClass {}

Multiclass model or not.

Definition at line 153 of file AsgElectronSelectorTool.h.

153{};

◆ m_mvaTool

std::unique_ptr<const ElectronDNNCalculator> AsgElectronSelectorTool::SelectionLayer::m_mvaTool

Pointer to the class that calculates the MVA score.

const for thread safety

Definition at line 142 of file AsgElectronSelectorTool.h.

◆ m_nOutputs

unsigned int AsgElectronSelectorTool::SelectionLayer::m_nOutputs

Definition at line 150 of file AsgElectronSelectorTool.h.

◆ m_variables

std::vector<std::string> AsgElectronSelectorTool::SelectionLayer::m_variables

Variables used in the MVA Tool.

Definition at line 145 of file AsgElectronSelectorTool.h.

◆ name

std::string AsgElectronSelectorTool::SelectionLayer::name

Definition at line 138 of file AsgElectronSelectorTool.h.

◆ prefix

std::string AsgElectronSelectorTool::SelectionLayer::prefix

Definition at line 139 of file AsgElectronSelectorTool.h.


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