10#include <framework/datastore/StoreArray.h>
11#include <framework/datastore/StoreObjPtr.h>
12#include <framework/dataobjects/EventMetaData.h>
13#include <framework/core/ModuleParam.templateDetails.h>
14#include <framework/gearbox/Unit.h>
15#include <framework/utilities/FileSystem.h>
16#include <analysis/utility/PCmsLabTransform.h>
17#include <trg/ecl/TrgEclMapping.h>
18#include <trg/ecl/dataobjects/TRGECLCluster.h>
19#include <trg/grl/dataobjects/GRLMLPData.h>
20#include <trg/grl/dataobjects/TRGGRLInfo.h>
21#include "trg/grl/dataobjects/TRGGRLUnpackerStore.h"
22#include "trg/grl/modules/trggrlneuralnet/GRLNeuroModule.h"
43 "The NeuroTrigger module of the GRL.\n"
44 "Takes CDC track and ECL cluster to prepare input data\n"
45 "for the training of a neural network.\n"
46 "Networks are trained after the event loop and saved."
51 "Name of the StoreArray holding the information of tracks and clusters from cdc ecl klm.",
52 string(
"TRGGRLObjects"));
54 "Name of the root file saving the output histogram.",
57 "Save the output histogram to root file.",
62 "Number of expert CDC MLPs.",
m_parameters.n_cdc_sector);
64 "Number of expert ECL MLPs.",
m_parameters.n_ecl_sector);
66 "#cdc track of expert MLPs.",
m_parameters.i_cdc_sector);
68 "#ecl cluster of expert MLPs.",
m_parameters.i_ecl_sector);
70 "Number of nodes in each hidden layer for all networks "
71 "or factor to multiply with number of inputs (1 list or nMLP lists). "
72 "The number of layers is derived from the shape.",
75 "If true, multiply nHidden with number of input nodes.",
78 "Output scale for all networks (1 value list or nMLP value lists). "
79 "Output[i] of the MLP is scaled from [-1, 1] "
80 "to [outputScale[2*i], outputScale[2*i+1]]. "
81 "(units: z[cm] / theta[degree])",
84 "Name of the file where the weights of MLPs are saved. "
85 "the default file is $BELLE2_LOCAL_DIR/data/trg/grl/weights.dat",
88 "Name of the file where the biases of MLPs are saved. "
89 "the default file is $BELLE2_LOCAL_DIR/data/trg/grl/bias.dat",
92 "Name of the StoreArray holding the information of trigger ecl clusters ",
93 string(
"TRGECLClusters"));
95 "Cut value applied to the MLP output",
98 "Flag to use database to set config",
true);
107 for (
int tc = 1; tc <= 576; tc++) {
114 for (
int tc = 1; tc <= 576; tc++) {
117 ROOT::Math::XYZVector CellPosition = trgecl_obj->
getTCPosition(tc);
118 ROOT::Math::PxPyPzEVector CellLab;
119 CellLab.SetPx(CellPosition.Unit().X());
120 CellLab.SetPy(CellPosition.Unit().Y());
121 CellLab.SetPz(CellPosition.Unit().Z());
124 TCThetaLab.push_back(CellLab.Theta()*TMath::RadToDeg());
125 TCPhiLab.push_back(CellLab.Phi()*TMath::RadToDeg() + 180.0);
139 B2FATAL(
"No database for TRG GRL config. exp " << evtMetaData->getExperiment() <<
" run "
140 << evtMetaData->getRun());
153 for (
unsigned int isector = 0; isector <
m_parameters.nMLP; isector++) {
155 B2ERROR(
"weight of GRL ecltaunn could not be loaded correctly.");
162 for (
unsigned int isector = 0; isector <
m_parameters.nMLP; isector++) {
163 h_target.push_back(
new TH1D((
"h_target_" + to_string(isector)).c_str(),
164 (
"h_target_" + to_string(isector)).c_str(), 100, 0.0, 1.0));
179 std::vector<std::tuple<float, float, float, float>> eclClusters;
182 for (
int ic = 0; ic < necl; ic++) {
183 int TC = eclTrgClusterArray[ic]->getMaxTCId();
184 float energy = eclTrgClusterArray[ic]->getEnergyDep() * 1000.0;
186 float phi = TCPhiLab[TC - 1];
187 float time = eclTrgClusterArray[ic]->getTimeAve();
188 eclClusters.emplace_back(energy, theta, phi, time);
191 std::sort(eclClusters.begin(), eclClusters.end(),
192 [](
const std::tuple<float, float, float, float>& a,
193 const std::tuple<float, float, float, float>& b) {
194 return std::get<0>(a) > std::get<0>(b);
198 std::vector<float> MLPinput;
200 MLPinput.assign(24, 0);
202 for (
size_t i = 0; i < std::min(eclClusters.size(),
size_t(6)); i++) {
203 MLPinput[i] = std::get<0>(eclClusters[i]);
204 MLPinput[6 + i] = std::get<1>(eclClusters[i]);
205 MLPinput[12 + i] = std::get<2>(eclClusters[i]);
206 MLPinput[18 + i] = std::get<3>(eclClusters[i]);
217 float LSB_ADC = 1 / 5.5;
218 float LSB_angle = 1 / 1.6025;
220 std::for_each(MLPinput.begin() + 0, MLPinput.begin() + 6, [LSB_ADC](
float & x) { x = std::ceil(x * LSB_ADC); });
221 std::for_each(MLPinput.begin() + 6, MLPinput.begin() + 12, [LSB_angle](
float & x) { x = std::ceil(x * LSB_angle);});
222 std::for_each(MLPinput.begin() + 12, MLPinput.begin() + 18, [LSB_angle](
float & x) { x = std::ceil(x * LSB_angle); });
233 float target =
m_GRLNeuro.runMLP(0, MLPinput);
238 trgInfo->setTauNN(
true);
239 }
else trgInfo->setTauNN(
false);
248 for (
unsigned int isector = 0; isector <
m_parameters.nMLP; isector++) {
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
std::vector< double > TCThetaLab
Azimuth angle of a given TRGcluster.
DBObjPtr< TRGGRLConfig > m_db_trggrlconfig
dbobject to store grl config
std::string m_HistFileName
Name of root file to save the histogram.
virtual void initialize() override
Initialize the module.
std::string m_TrgECLClusterName
Name of the StoreArray containing the ECL clusters.
std::vector< int > TCThetaID
TCID of a given TRGcluster.
GRLNeuro m_GRLNeuro
Instance of the NeuroTrigger.
virtual void event() override
Called once for each event.
GRLNeuro::Parameters m_parameters
Parameters for the NeuroTrigger.
GRLNeuroModule()
Constructor, for setting module description and parameters.
virtual void terminate() override
This method is called at the end of the event processing.
std::vector< std::string > m_weightFileNames
Name of file where network weights etc.
virtual void beginRun() override
Register run-dependent DataStore arrays.
std::string m_TrgGrlInformationName
name of TRG GRL information object
bool m_saveHist
save the output histogram
std::vector< float > m_nn_thres
cut on MVA to separate signal
std::vector< TH1D * > h_target
Histograms to save the NN classifiers.
bool m_useDB
flag to use database to load config
std::vector< std::string > m_biasFileNames
Name of file where network bias etc.
Class to represent the GRL Neuro.
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Accessor to arrays stored in the data store.
int getEntries() const
Get the number of objects in the array.
Type-safe access to single objects in the data store.
int getTCThetaIdFromTCId(int)
get [TC Theta ID] from [TC ID]
ROOT::Math::XYZVector getTCPosition(int)
TC position (cm)
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.