Belle II Software  release-06-00-14
CDCTriggerNeuroTrainerModule.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #ifndef CDCTRIGGERNEUROTRAINERMODULE_H
9 #define CDCTRIGGERNEUROTRAINERMODULE_H
10 
11 #include <framework/core/Module.h>
12 
13 #include <trg/cdc/NeuroTrigger.h>
14 #include <trg/cdc/dataobjects/CDCTriggerMLPData.h>
15 
16 #include <TH1D.h>
17 
18 namespace Belle2 {
32  public:
35 
38 
42  virtual void initialize() override;
43 
47  virtual void event() override;
48 
50  virtual void terminate() override;
51 
54  void updateRelevantID(unsigned isector);
55 
57  void train(unsigned isector);
58 
63  void saveTraindata(const std::string& filename, const std::string& arrayname = "trainSets");
64 
70  bool loadTraindata(const std::string& filename, const std::string& arrayname = "trainSets");
71 
72  protected:
73  //module parameters
75  std::string m_hitCollectionName;
77  std::string m_EventTimeName;
79  std::string m_inputCollectionName;
85  std::string m_filename;
87  std::string m_trainFilename;
89  std::string m_logFilename;
91  std::string m_arrayname;
93  std::string m_trainArrayname;
97  bool m_load;
105  std::vector<std::vector<float>> m_IDranges;
109  bool m_cutSum;
111  double m_nTrainMin;
113  double m_nTrainMax;
117  int m_nValid;
119  int m_nTest;
125  double m_wMax;
138 
139  //other data
143  std::vector<CDCTriggerMLPData> m_trainSets;
146 
147  //monitoring histograms
148  std::vector<TH1D*> phiHistsMC;
149  std::vector<TH1D*> ptHistsMC;
150  std::vector<TH1D*> thetaHistsMC;
151  std::vector<TH1D*> zHistsMC;
152  std::vector<TH1D*> phiHists2D;
153  std::vector<TH1D*> ptHists2D;
154  };
156 }
157 
158 #endif
The trainer module for the neural networks of the CDC trigger.
bool loadTraindata(const std::string &filename, const std::string &arrayname="trainSets")
Load saved training samples.
std::string m_EventTimeName
name of the event time StoreObjPtr
int m_maxEpochs
Maximal number of training epochs.
bool m_rescaleTarget
Switch to rescale out of range target values or ignore them.
CDCTriggerNeuroTrainerModule()
Constructor, for setting module description and parameters.
std::vector< CDCTriggerMLPData > m_trainSets
Sets of training data for all sectors.
bool m_load
Switch to load saved parameters from a previous run.
NeuroTrigger::Parameters m_parameters
Parameters for the NeuroTrigger.
virtual void initialize() override
Initialize the module.
std::vector< TH1D * > thetaHistsMC
theta of MCParticles
bool m_trainOnRecoTracks
Switch between MCParticles or RecoTracks as targets.
int m_checkInterval
Training is stopped if validation error is higher than checkInterval epochs ago, i....
virtual void event() override
Called once for each event.
std::vector< TH1D * > phiHistsMC
phi of MCParticles
void updateRelevantID(unsigned isector)
calculate and set the relevant id range for given sector based on hit counters of the track segments.
std::vector< TH1D * > ptHists2D
pt of 2D tracks
std::vector< std::vector< float > > m_IDranges
Input ranges given over the module parameters.
NeuroTrigger m_NeuroTrigger
Instance of the NeuroTrigger.
std::string m_arrayname
Name of the TObjArray holding the networks.
virtual void terminate() override
Do the training for all sectors.
bool m_multiplyNTrain
Switch to multiply number of samples with number of weights.
std::string m_targetCollectionName
Name of the MCParticles/RecoTracks collection used as target values.
bool m_cutSum
Switch to apply cut to single hit counter or to sum over counters.
bool m_selectSectorByMC
Switch for sector selection during training.
int m_nThreads
Number of threads for training.
bool m_neuroTrackInputMode
Use neurotracks instead of 2dtracks as input for the neurotrigger.
int m_nTrainPrepare
Number of samples to prepare input ranges.
std::string m_logFilename
Name of file where training log is stored.
std::string m_inputCollectionName
Name of the StoreArray containing the input 2D tracks.
std::string m_trainFilename
Name of file where training samples are stored.
void train(unsigned isector)
Train a single MLP.
StoreArray< CDCTriggerTrack > m_tracks
List of input tracks.
double m_nTrainMin
Minimal number of training samples.
std::vector< TH1D * > ptHistsMC
pt of MCParticles
std::string m_filename
Name of file where network weights etc.
double m_relevantCut
Cut on the hit counters to get relevant ID ranges.
void saveTraindata(const std::string &filename, const std::string &arrayname="trainSets")
Save all training samples.
double m_nTrainMax
Maximal number of training samples.
bool m_saveDebug
If true, save training curve and parameter distribution of training data.
std::vector< TH1D * > zHistsMC
z of MCParticles
std::string m_hitCollectionName
Name of the StoreArray containing the input track segment hits.
std::string m_trainArrayname
Name of the TObjArray holding the training samples.
std::vector< TH1D * > phiHists2D
phi of 2D tracks
int m_repeatTrain
Number of training runs with different random start weights.
Base class for Modules.
Definition: Module.h:72
Class to represent the CDC Neurotrigger.
Definition: NeuroTrigger.h:38
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
Abstract base class for different kinds of events.
Struct to keep neurotrigger parameters.
Definition: NeuroTrigger.h:44