24 ", could not be found! It is necessary for the neural network based PID variables.");
26 m_model = std::make_unique<fdeep::model>(fdeep::read_model_from_string((*m_pidNeuralNetworkParametersDB)->getModelDefinition(),
28 [](
const std::string&) {}
33 std::map<std::string, std::string> inputNameMap;
36 const auto oldName =
"pidLogLikelihood_Of_" + std::to_string(abs(hypeType.getPDGCode())) +
"_From_" +
Const::parseDetectors(
38 const auto newName =
"pidLogLikelihoodValueExpert(" + std::to_string(abs(hypeType.getPDGCode())) +
',' +
Const::parseDetectors(
40 inputNameMap[oldName] = newName;
43 inputNameMap[
"momentum"] =
"p";
47 for (std::string name : (*m_pidNeuralNetworkParametersDB)->getInputNames()) {
48 const auto itr = inputNameMap.find(name);
49 if (itr != inputNameMap.end()) name = itr->second;
55 m_extraInfoNames[outputPdgCode] =
"pidNeuralNetworkValueExpert(" + std::to_string(outputPdgCode) \
66 for (
auto const& inputToCut : (*m_pidNeuralNetworkParametersDB)->getInputsToCut()) {
67 const auto [inputSetIndex, inputCutIndex, rangeStart, rangeEnd, setValue] = inputToCut;
68 if (!std::isnan(rangeStart) and !std::isnan(rangeEnd)) {
69 if (input[inputCutIndex] >= rangeStart and input[inputCutIndex] <= rangeEnd)
70 input[inputSetIndex] = setValue;
71 }
else if (!std::isnan(rangeStart)) {
72 if (input[inputCutIndex] >= rangeStart)
73 input[inputSetIndex] = setValue;
74 }
else if (!std::isnan(rangeEnd)) {
75 if (input[inputCutIndex] <= rangeEnd)
76 input[inputSetIndex] = setValue;
82 for (
size_t i = 0; i < input.size(); ++i) {
83 input[i] = (input[i] - (*m_pidNeuralNetworkParametersDB)->getMeanValues()[i]) /
84 (*m_pidNeuralNetworkParametersDB)->getStandardDeviations()[i];
88 for (
auto const& index_value : (*m_pidNeuralNetworkParametersDB)->getHandleMissingInputs()) {
89 const auto [index, value] = index_value;
90 if (std::isnan(input[index])) input[index] = value;
94 const auto inputFdeep = fdeep::tensor(fdeep::tensor_shape(input.size()), input);
95 const auto result =
m_model->predict({inputFdeep});
97 std::map<int, double> probabilities;
99 const int outputIndex = (*m_pidNeuralNetworkParametersDB)->pdg2OutputIndex(pdgCode);
100 probabilities[pdgCode] = result.front().get(fdeep::tensor_pos(outputIndex));
102 return probabilities;