16#include "G4FastTrack.hh"
17#include "G4FastStep.hh"
20#include "lwtnn/parse_json.hh"
27 : base_class(
type, name, parent) {
32 ATH_MSG_DEBUG(
"[ punchthroughclassifier ] Initializing PunchThroughG4Classifier" );
43 return StatusCode::SUCCESS;
48 ATH_MSG_DEBUG(
"[punchthroughclassifier] finalize() successful" );
50 return StatusCode::SUCCESS;
55 std::unique_ptr<XMLCoreNode> doc = p.parse (scalerConfigFile);
57 ATH_MSG_DEBUG(
"[ punchthroughclassifier ] Loading scaler: " << scalerConfigFile);
61 if (
node->get_name() ==
"ScalerValues") {
65 else if (
node->get_name() ==
"VarScales") {
66 std::string name =
node->get_attrib (
"name");
72 return StatusCode::SUCCESS;
77 ATH_MSG_DEBUG(
"[ punchthroughclassifier ] Loading classifier: " << networkConfigFile);
79 std::ifstream input(networkConfigFile);
81 ATH_MSG_ERROR(
"Could not find json file " << networkConfigFile );
82 return StatusCode::FAILURE;
85 m_graph = std::make_unique<lwt::LightweightGraph>(lwt::parse_json_graph(input));
87 ATH_MSG_ERROR(
"Could not parse graph json file " << networkConfigFile );
88 return StatusCode::FAILURE;
92 return StatusCode::SUCCESS;
97 std::unique_ptr<XMLCoreNode> doc = p.parse (calibratorConfigFile);
100 ATH_MSG_DEBUG(
"[ punchthroughclassifier ] Loading calibrator: " << calibratorConfigFile);
102 for (
const XMLCoreNode*
node : doc->get_children (
"Transformations/*"))
104 if (
node->get_name() ==
"LimitValues") {
108 else if (
node->get_name() ==
"LinearNorm") {
109 double orig =
node->get_double_attrib (
"orig");
110 double norm =
node->get_double_attrib (
"norm");
115 return StatusCode::SUCCESS;
120 std::map<std::string, std::map<std::string, double> > networkInputs =
computeInputs(fastTrack, simE, simEfrac);
124 std::map<std::string, double> networkOutputs =
m_graph->compute(networkInputs);
128 return calibratedOutput;
135 std::map<std::string, std::map<std::string, double> > networkInputs;
138 networkInputs[
"node_0"] = {
139 {
"variable_0", fastTrack.GetPrimaryTrack()->GetMomentum().mag() },
140 {
"variable_1", std::abs(fastTrack.GetPrimaryTrack()->GetPosition().eta()) },
141 {
"variable_2", fastTrack.GetPrimaryTrack()->GetPosition().phi() },
142 {
"variable_3", simE},
146 for (
unsigned int i = 0; i < simEfrac.size(); i++) {
147 networkInputs[
"node_0"].insert({
"variable_" + std::to_string(i + 4), simEfrac[i]});
150 return networkInputs;
157 for (
auto& var : inputs[
"node_0"]) {
186 auto lower =
upper--;
189 double m = (
upper->second - lower->second)/(
upper->first - lower->first);
190 double c = lower->second - m * lower->first;
191 double calibrated = m * networkOutput + c;
#define ATH_CHECK
Evaluate an expression and check for errors.
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Simple DOM-like node structure to hold the result of XML parsing.
std::unique_ptr< lwt::LightweightGraph > m_graph
NN graph.
std::map< std::string, double > m_scalerMaxMap
virtual StatusCode initialize() override
AlgTool initialize method.
double m_scalerMin
input variable MinMaxScaler members
StringProperty m_scalerConfigFileName
std::map< std::string, std::map< std::string, double > > scaleInputs(std::map< std::string, std::map< std::string, double > > &inputs) const
scale NN inputs using MinMaxScaler
StringProperty m_networkConfigFileName
std::map< double, double > m_calibrationMap
PunchThroughG4Classifier(const std::string &, const std::string &, const IInterface *)
Constructor.
std::map< std::string, double > m_scalerMinMap
StatusCode initializeCalibrator(const std::string &calibratorConfigFile)
isotonic regressor calibrator initialize method
virtual StatusCode finalize() override
AlgTool finalize method.
StatusCode initializeScaler(const std::string &scalerConfigFile)
input variable MinMaxScaler initialize method
StatusCode initializeNetwork(const std::string &networkConfigFile)
neural network initialize method
double calibrateOutput(double &networkOutput) const
calibrate NN output using isotonic regressor
StringProperty m_calibratorConfigFileName
static std::map< std::string, std::map< std::string, double > > computeInputs(const G4FastTrack &fastTrack, const double simE, const std::vector< double > &simEfrac)
calcalate NN inputs based on G4FastTrack and simulstate
virtual double computePunchThroughProbability(const G4FastTrack &fastTrack, const double simE, const std::vector< double > &simEfrac) const override
interface method to return probability prediction of punch through
Simple DOM-like node structure to hold the result of XML parsing.