9#include "trg/cdc/dataobjects/CDCTriggerHoughMLP.h"
16#include "framework/logging/Logger.h"
21 m_neuroParametersHough(neuroParametersHough)
23 std::vector<size_t> nHidden = m_neuroParametersHough.nHidden;
24 m_nodes = {
static_cast<size_t>(m_neuroParametersHough.nInput)};
25 for (
size_t hiddenLayerIdx = 0; hiddenLayerIdx < nHidden.size(); ++hiddenLayerIdx) {
26 m_nodes.push_back(nHidden[hiddenLayerIdx]);
28 m_nodes.push_back(m_neuroParametersHough.nOutput);
29 m_floatWeights.assign(getNumberOfWeights(), 0.0f);
33size_t CDCTriggerHoughMLP::getNumberOfWeights()
const
36 size_t nLayers = getNumberOfLayers();
37 for (
size_t i = 1; i < nLayers; ++i) {
39 nWeights += (m_nodes[i - 1] + 1) * m_nodes[i];
45void CDCTriggerHoughMLP::saveMLPToFile(
const std::string& fileName,
const std::string& objName)
const
47 B2INFO(std::string(
"Saving network to file ") + fileName +
", object " + objName);
48 TFile datafile(fileName.c_str(),
"UPDATE");
49 this->Write(objName.c_str(), TObject::kSingleKey | TObject::kOverwrite);
56 NeuroParametersHough neuroParametersHough;
57 std::ifstream configFile(fileName);
58 if (!configFile.is_open()) {
59 B2ERROR(
"Could not open configuration file: " + fileName);
62 std::string completeLine;
63 while (std::getline(configFile, completeLine)) {
64 std::size_t hashtag = completeLine.find(
'#');
65 std::string line = completeLine.substr(0, hashtag);
66 std::string configParameter;
67 std::string parameterValue;
68 if (line.length() < 3 || line.find(
'=') == std::string::npos) {
71 line.erase(std::remove(line.begin(), line.end(),
' '), line.end());
72 size_t equalPosition = line.find(
'=');
73 configParameter = line.substr(0, equalPosition);
74 parameterValue = line.substr((equalPosition + 1), line.length() - equalPosition - 1);
75 if (configParameter ==
"nInput") {
76 neuroParametersHough.nInput = std::stoull(parameterValue);
77 }
else if (configParameter ==
"nOutput") {
78 neuroParametersHough.nOutput = std::stoull(parameterValue);
79 }
else if (configParameter ==
"nHidden") {
80 neuroParametersHough.nHidden = readArray<size_t>(parameterValue);
81 }
else if (configParameter ==
"outputScale") {
82 neuroParametersHough.outputScale = readArray<float>(parameterValue);
84 B2WARNING(
"Unknown config parameter: " + configParameter);
87 return neuroParametersHough;
92std::vector<T> CDCTriggerHoughMLP::readArray(
const std::string& rawString)
94 std::vector<T> configVector;
95 std::string strippedString = rawString.substr(1, rawString.size() - 2);
96 std::stringstream strippedStream(strippedString);
98 while (std::getline(strippedStream, entry,
',')) {
99 configVector.push_back(
static_cast<T
>(std::stod(entry)));
Abstract base class for different kinds of events.