Belle II Software  release-05-02-19
GRLNeuroTrainerModule.h
1 #ifndef GRLNEUROTRAINERMODULE_H
2 #define GRLNEUROTRAINERMODULE_H
3 
4 #include <framework/core/Module.h>
5 
6 #include <trg/grl/GRLNeuro.h>
7 #include <trg/grl/dataobjects/GRLMLPData.h>
8 
9 #include <TH1D.h>
10 
11 namespace Belle2 {
21  class GRLNeuroTrainerModule : public Module {
22  public:
25 
28 
32  virtual void initialize() override;
33 
37  virtual void event() override;
38 
40  virtual void terminate() override;
41 
44  void updateRelevantID(unsigned isector);
45 
47  void train(unsigned isector);
48 
53  void saveTraindata(const std::string& filename, const std::string& arrayname = "trainSets");
54 
60  bool loadTraindata(const std::string& filename, const std::string& arrayname = "trainSets");
61 
62  protected:
63  //module parameters
65  std::string m_TrgECLClusterName;
69  std::string m_GRLCollectionName;
71  std::string m_filename;
73  std::string m_trainFilename;
75  std::string m_logFilename;
77  std::string m_arrayname;
79  std::string m_trainArrayname;
83  bool m_load;
87  double m_nTrainMin;
89  double m_nTrainMax;
93  int m_nValid;
95  int m_nTest;
97  double m_wMax;
108 
112  std::vector<GRLMLPData> m_trainSets;
113 
114  //..ECL look up tables
115  std::vector<int> TCThetaID;
116  std::vector<float> TCPhiLab;
117  std::vector<float> TCcotThetaLab;
118  std::vector<float> TCPhiCOM;
119  std::vector<float> TCThetaCOM;
120  std::vector<float> TC1GeV;
122  double radtodeg = 0;
123 
125  int n_cdc_sector = 0;
127  int n_ecl_sector = 0;
129  int n_sector = 0;
130 
132  std::vector<TH1D*> h_cdc2d_phi_sig;
133  std::vector<TH1D*> h_cdc2d_pt_sig;
134  std::vector<TH1D*> h_selE_sig;
135  std::vector<TH1D*> h_selPhi_sig;
136  std::vector<TH1D*> h_selTheta_sig;
137  std::vector<TH1D*> h_result_sig;
138  std::vector<TH1D*> h_cdc2d_phi_bg;
139  std::vector<TH1D*> h_cdc2d_pt_bg;
140  std::vector<TH1D*> h_selE_bg;
141  std::vector<TH1D*> h_selPhi_bg;
142  std::vector<TH1D*> h_selTheta_bg;
143  std::vector<TH1D*> h_result_bg;
144  std::vector<TH1D*> h_ncdc_sig;
145  std::vector<TH1D*> h_ncdcf_sig;
146  std::vector<TH1D*> h_ncdcs_sig;
147  std::vector<TH1D*> h_ncdci_sig;
148  std::vector<TH1D*> h_necl_sig;
149  std::vector<TH1D*> h_ncdc_bg;
150  std::vector<TH1D*> h_ncdcf_bg;
151  std::vector<TH1D*> h_ncdcs_bg;
152  std::vector<TH1D*> h_ncdci_bg;
153  std::vector<TH1D*> h_necl_bg;
154 
156  std::vector<int> scale_bg;
157 
158  };
160 }
161 
162 #endif
Belle2::GRLNeuroTrainerModule
The trainer module for the neural networks of the CDC trigger.
Definition: GRLNeuroTrainerModule.h:21
Belle2::GRLNeuroTrainerModule::radtodeg
double radtodeg
convert radian to degree
Definition: GRLNeuroTrainerModule.h:122
Belle2::GRLNeuroTrainerModule::m_nTrainMax
double m_nTrainMax
Maximal number of training samples.
Definition: GRLNeuroTrainerModule.h:89
Belle2::GRLNeuroTrainerModule::m_nValid
int m_nValid
Number of validation samples.
Definition: GRLNeuroTrainerModule.h:93
Belle2::GRLNeuroTrainerModule::GRLNeuroTrainerModule
GRLNeuroTrainerModule()
Constructor, for setting module description and parameters.
Definition: GRLNeuroTrainerModule.cc:38
Belle2::GRLNeuroTrainerModule::m_nTrainMin
double m_nTrainMin
Minimal number of training samples.
Definition: GRLNeuroTrainerModule.h:87
Belle2::GRLNeuroTrainerModule::m_nTest
int m_nTest
Number of test samples.
Definition: GRLNeuroTrainerModule.h:95
Belle2::GRLNeuroTrainerModule::~GRLNeuroTrainerModule
virtual ~GRLNeuroTrainerModule()
Destructor.
Definition: GRLNeuroTrainerModule.h:27
Belle2::GRLNeuroTrainerModule::m_arrayname
std::string m_arrayname
Name of the TObjArray holding the networks.
Definition: GRLNeuroTrainerModule.h:77
Belle2::GRLNeuroTrainerModule::n_sector
int n_sector
Number of Total sectors.
Definition: GRLNeuroTrainerModule.h:129
Belle2::GRLNeuroTrainerModule::loadTraindata
bool loadTraindata(const std::string &filename, const std::string &arrayname="trainSets")
Load saved training samples.
Belle2::GRLNeuro
Class to represent the GRL Neuro.
Definition: GRLNeuro.h:27
Belle2::GRLNeuroTrainerModule::m_filename
std::string m_filename
Name of file where network weights etc.
Definition: GRLNeuroTrainerModule.h:71
Belle2::GRLNeuroTrainerModule::m_nThreads
int m_nThreads
Number of threads for training.
Definition: GRLNeuroTrainerModule.h:99
Belle2::GRLNeuroTrainerModule::m_TrgECLClusterName
std::string m_TrgECLClusterName
Name of the StoreArray containing the ECL clusters.
Definition: GRLNeuroTrainerModule.h:65
Belle2::GRLNeuro::Parameters
Struct to keep neurotrigger parameters.
Definition: GRLNeuro.h:33
Belle2::GRLNeuroTrainerModule::m_GRLNeuro
GRLNeuro m_GRLNeuro
Instance of the NeuroTrigger.
Definition: GRLNeuroTrainerModule.h:110
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::GRLNeuroTrainerModule::m_logFilename
std::string m_logFilename
Name of file where training log is stored.
Definition: GRLNeuroTrainerModule.h:75
Belle2::GRLNeuroTrainerModule::m_maxEpochs
int m_maxEpochs
Maximal number of training epochs.
Definition: GRLNeuroTrainerModule.h:105
Belle2::GRLNeuroTrainerModule::m_wMax
double m_wMax
Limit for weights.
Definition: GRLNeuroTrainerModule.h:97
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::GRLNeuroTrainerModule::saveTraindata
void saveTraindata(const std::string &filename, const std::string &arrayname="trainSets")
Save all training samples.
Definition: GRLNeuroTrainerModule.cc:644
Belle2::GRLNeuroTrainerModule::m_trainFilename
std::string m_trainFilename
Name of file where training samples are stored.
Definition: GRLNeuroTrainerModule.h:73
Belle2::GRLNeuroTrainerModule::m_load
bool m_load
Switch to load saved parameters from a previous run.
Definition: GRLNeuroTrainerModule.h:83
Belle2::GRLNeuroTrainerModule::n_cdc_sector
int n_cdc_sector
Number of CDC sectors.
Definition: GRLNeuroTrainerModule.h:125
Belle2::GRLNeuroTrainerModule::updateRelevantID
void updateRelevantID(unsigned isector)
calculate and set the relevant id range for given sector based on hit counters of the track segments.
Belle2::GRLNeuroTrainerModule::m_repeatTrain
int m_repeatTrain
Number of training runs with different random start weights.
Definition: GRLNeuroTrainerModule.h:107
Belle2::GRLNeuroTrainerModule::h_cdc2d_phi_sig
std::vector< TH1D * > h_cdc2d_phi_sig
Histograms for monitoring.
Definition: GRLNeuroTrainerModule.h:132
Belle2::GRLNeuroTrainerModule::m_trainArrayname
std::string m_trainArrayname
Name of the TObjArray holding the training samples.
Definition: GRLNeuroTrainerModule.h:79
Belle2::GRLNeuroTrainerModule::event
virtual void event() override
Called once for each event.
Definition: GRLNeuroTrainerModule.cc:226
Belle2::GRLNeuroTrainerModule::m_2DfinderCollectionName
std::string m_2DfinderCollectionName
Name of the StoreArray containing the input 2D tracks.
Definition: GRLNeuroTrainerModule.h:67
Belle2::GRLNeuroTrainerModule::scale_bg
std::vector< int > scale_bg
BG scale factor for training.
Definition: GRLNeuroTrainerModule.h:156
Belle2::GRLNeuroTrainerModule::initialize
virtual void initialize() override
Initialize the module.
Definition: GRLNeuroTrainerModule.cc:133
Belle2::GRLNeuroTrainerModule::train
void train(unsigned isector)
Train a single MLP.
Definition: GRLNeuroTrainerModule.cc:510
Belle2::GRLNeuroTrainerModule::terminate
virtual void terminate() override
Do the training for all sectors.
Definition: GRLNeuroTrainerModule.cc:483
Belle2::GRLNeuroTrainerModule::m_multiplyNTrain
bool m_multiplyNTrain
Switch to multiply number of samples with number of weights.
Definition: GRLNeuroTrainerModule.h:91
Belle2::GRLNeuroTrainerModule::m_parameters
GRLNeuro::Parameters m_parameters
Parameters for the NeuroTrigger.
Definition: GRLNeuroTrainerModule.h:85
Belle2::GRLNeuroTrainerModule::m_saveDebug
bool m_saveDebug
If true, save training curve and parameter distribution of training data.
Definition: GRLNeuroTrainerModule.h:81
Belle2::GRLNeuroTrainerModule::n_ecl_sector
int n_ecl_sector
Number of ECL sectors.
Definition: GRLNeuroTrainerModule.h:127
Belle2::GRLNeuroTrainerModule::m_trainSets
std::vector< GRLMLPData > m_trainSets
Sets of training data for all sectors.
Definition: GRLNeuroTrainerModule.h:112
Belle2::GRLNeuroTrainerModule::m_checkInterval
int m_checkInterval
Training is stopped if validation error is higher than checkInterval epochs ago, i....
Definition: GRLNeuroTrainerModule.h:103
Belle2::GRLNeuroTrainerModule::m_GRLCollectionName
std::string m_GRLCollectionName
Name of the StoreObj containing the input GRL.
Definition: GRLNeuroTrainerModule.h:69