FEDRA emulsion software from the OPERA Collaboration
EdbShowAlg_NN.h
Go to the documentation of this file.
1 #ifndef ROOT_EdbShowAlg_NN
2 #define ROOT_EdbShowAlg_NN
3 
4 #include "TROOT.h"
5 #include "TFile.h"
6 #include "TVector3.h"
7 #include "TIndexCell.h"
8 #include "TArrayF.h"
9 #include "TBenchmark.h"
10 #include "TMultiLayerPerceptron.h"
11 #include "EdbVertex.h"
12 #include "EdbPVRec.h"
13 #include "EdbPhys.h"
14 #include "EdbMath.h"
15 #include "EdbMomentumEstimator.h"
16 #include "EdbLog.h"
17 #include "EdbPattern.h"
18 #include "EdbShowerP.h"
19 using namespace std;
20 
21 //______________________________________________________________________________
22 //___
23 //___ Declaration of EdbShowAlg Class:
24 //___ Following structure is foreseen: The (inherited) class instances of
25 //___ EdbShowAlg DO the reconstruction. They DONT manage the data.
26 //___ Following the principle "separate algorithms and data" (like ATHENA,
27 //___ the ATLAS framework). Therefore the EdbPVRec Object, the Initiator
28 //___ Base Tracks and the shower arrays are only handed over either as
29 //___ reference or as pointers. Saving/manipulating/preparing of these
30 //___ objects will only be done in the EdbShowRec class instances!
31 //___
32 //______________________________________________________________________________
33 
34 
35 
36 
37 
38 
39 
40 //______________________________________________________________________________
41 
42 class EdbShowAlg_NN : public EdbShowAlg {
43 
44  // Neural Network algorithm distinguishing
45  // Signal from Backgroundbasetracks of a shower
46  // using topological variables
47 
48 
49 private:
52  TTree* eANNTree;
53  TMultiLayerPerceptron* eTMlpANN;
54 
55 
56  // variables for the eANN Branches:
94 
95 
96 public:
97 
99  //EdbShowAlg_NN(Bool_t ANN_DoTrain);
100  virtual ~EdbShowAlg_NN(); // virtual constructor due to inherited class
101 
102  void Init();
103  void CreateANNTree();
104  TMultiLayerPerceptron* Create_NN_ALG_MLP(TTree* inputtree, Int_t inputneurons);
105  void LoadANNWeights();
106  void LoadANNWeights(TMultiLayerPerceptron* TMlpANN, TString WeightFileString);
107  void SetANNWeightString();
108 
109  inline void SetWeightFileString(TString WeightFileString) {
110  eWeightFileString=WeightFileString;
111  return;
112  }
113  inline TString GetWeightFileString() {
114  return eWeightFileString;
115  }
116 
117  // Helper Functions:
118  Int_t GetNSegBeforeAndAfter(EdbPVRec* local_gAli, Int_t patterloop_cnt, EdbSegP* seg, Int_t n_patterns, Int_t BeforeOrAfter);
119  Int_t GetMeansBeforeAndAfter(Float_t& mean_dT, Float_t& mean_dR, EdbPVRec* local_gAli, Int_t patterloop_cnt, EdbSegP* seg, Int_t n_patterns, Int_t BeforeOrAfter);
120  Int_t GetMinsBeforeAndAfter(Float_t& min_dT, Float_t& min_dR, EdbPVRec* local_gAli, Int_t patterloop_cnt, EdbSegP* seg, Int_t n_patterns, Int_t BeforeOrAfter);
121 
122  // Print Generic Information about the Algorithm
123  void Print();
124 
125 
126  // Main functions for using this ShowerAlgorithm Object.
127  // Structure is made similar to OpRelease, where
128  // Initialize, Execute, Finalize
129  // give the three columns of the whole thing.
130  void Initialize();
131  void Execute();
132  void Finalize();
133 
134  ClassDef(EdbShowAlg_NN,1); // Root Class Definition for my Objects
135 };
136 
137 
138 
139 
140 //______________________________________________________________________________
141 
142 class EdbShowAlg_N3 : public EdbShowAlg {
143 
144  // New Neural Network (3N) algorithm distinguishing
145  // Signal from Background Basetracks of a shower
146  // using topological variables
147 
148 private:
151  TTree* eANNTree;
152  TMultiLayerPerceptron* eTMlpANN;
154 
155  // Variables for the eANN Branches:
156  Bool_t eANN_DoTrain=kTRUE;
157  Double_t eANN_Inputvar[24]; // 24 maximal input neurons
158  Int_t eANN_Inputtype; // 0: BG-Track, 1: SG-Track
159  Double_t eANN_OutputValue=0; // result from the network
160  // Values valid for ShowerReco Algorithm 11 = N3 ALG: NewNeuralNetwork ("N":3-times)
161  // Brick data related inputs
162  // The number of Input Variables is calculated only from this:
163  Int_t eANN_PLATE_DELTANMAX; // 0,1,2,3,4,5.
164  // 0: no separate information BT(i,j) is used.
165  // 1: additional information BT(i,j) for DeltNPL==0 (same plate) is used.
166  // 2: additional information BT(i,j) for DeltNPL==-1 ( one plate upstream) is used.
167  // 3: additional information BT(i,j) for DeltNPL==+1 ( one plate downstream) is used.
168  // 4: additional information BT(i,j) for DeltNPL==-2 ( two plate upstream) is used.
169  // 5: additional information BT(i,j) for DeltNPL==+2 ( two plate downstream) is used.
170  // Order: same plate, one plate upstream, one plate downstream, two plate upstream, two plate downstream
171 
172  // Algorithm method related inputs
173  Int_t eANN_NTRAINEPOCHS; // 1,2,3,4 = 50,100,150,200
174  Int_t eANN_NHIDDENLAYER; // 1,2,3,4 = 2,3,5,7
175  Double_t eANN_OUTPUTTHRESHOLD; // 0..10 = 0.5, 0.55, 0.6 ...
176  Int_t eANN_EQUALIZESGBG; // 0: no, 1: yes
177  // 1: not all BG BTs will be taken for NN training, some are randomly left out of the trainingssample so that N(SG) ca. N(BG) for one shower event (for training)
178 
179  // This is dependent by the other variables, thus it
180  // is explicitely calculated for ease of view
182 
183 
184 public:
185 
186  EdbShowAlg_N3(Bool_t ANN_DoTrain);
187  virtual ~EdbShowAlg_N3(); // virtual constructor due to inherited class
188 
189  void Init();
190  void CreateANNTree();
191  TMultiLayerPerceptron* Create_NN_ALG_MLP(TTree* inputtree, Int_t inputneurons);
192  TString eLayout;
193 
194  void LoadANNWeights();
195  void LoadANNWeights(TMultiLayerPerceptron* TMlpANN, TString WeightFileString);
196  void SetANNWeightString();
197 
198 
199  inline void SetWeightFileString(TString WeightFileString) {
200  eWeightFileString=WeightFileString;
201  return;
202  }
203  inline TString GetWeightFileString() {
204  return eWeightFileString;
205  }
206 
207  // Print Generic Information about the Algorithm
208  void Print();
209 
210  // Main functions for using this ShowerAlgorithm Object.
211  // Structure is made similar to OpRelease, where
212  // Initialize, Execute, Finalize
213  // give the three columns of the whole thing.
214  void Initialize();
215  void Execute();
216  void Finalize();
217 
218  ClassDef(EdbShowAlg_N3,1); // Root Class Definition for my Objects
219 };
220 
221 #endif /* ROOT_EdbShowAlg_NN */
Int_t GetMinsBeforeAndAfter(Float_t &min_dT, Float_t &min_dR, EdbPVRec *local_gAli, Int_t patterloop_cnt, EdbSegP *seg, Int_t n_patterns, Int_t BeforeOrAfter)
Definition: ShowRec.cpp:7295
Int_t GetMeansBeforeAndAfter(Float_t &mean_dT, Float_t &mean_dR, EdbPVRec *local_gAli, Int_t patterloop_cnt, EdbSegP *seg, Int_t n_patterns, Int_t BeforeOrAfter)
Definition: ShowRec.cpp:7383
Int_t GetNSegBeforeAndAfter(EdbPVRec *local_gAli, Int_t patterloop_cnt, EdbSegP *seg, Int_t n_patterns, Int_t BeforeOrAfter)
Definition: ShowRec.cpp:7462
TMultiLayerPerceptron * TMlpANN
Definition: ShowRec.h:340
Definition: EdbPVRec.h:148
Definition: EdbSegP.h:18
Definition: EdbShowAlg_NN.h:142
TString eWeightFileString
Definition: EdbShowAlg_NN.h:149
Int_t eANN_Inputtype
Definition: EdbShowAlg_NN.h:158
TFile * eANNTrainingsTreeFile
Definition: EdbShowAlg_NN.h:153
Double_t eANN_OUTPUTTHRESHOLD
Definition: EdbShowAlg_NN.h:175
TString eWeightFileLayoutString
Definition: EdbShowAlg_NN.h:150
ClassDef(EdbShowAlg_N3, 1)
TMultiLayerPerceptron * eTMlpANN
Definition: EdbShowAlg_NN.h:152
TString GetWeightFileString()
Definition: EdbShowAlg_NN.h:203
Int_t eANN_NHIDDENLAYER
Definition: EdbShowAlg_NN.h:174
Int_t eANN_EQUALIZESGBG
Definition: EdbShowAlg_NN.h:176
TString eLayout
Definition: EdbShowAlg_NN.h:192
Int_t eANN_NTRAINEPOCHS
Definition: EdbShowAlg_NN.h:173
Int_t eANN_INPUTNEURONS
Definition: EdbShowAlg_NN.h:181
TTree * eANNTree
Definition: EdbShowAlg_NN.h:151
Int_t eANN_PLATE_DELTANMAX
Definition: EdbShowAlg_NN.h:163
void SetWeightFileString(TString WeightFileString)
Definition: EdbShowAlg_NN.h:199
Definition: EdbShowAlg_NN.h:42
Int_t eANN_var_nseg_2before
Definition: EdbShowAlg_NN.h:87
Float_t eANN_var_dR_TestBT_To_InBT
Definition: EdbShowAlg_NN.h:60
Float_t eANN_var_zDist_TestBT_To_InBT
Definition: EdbShowAlg_NN.h:61
Float_t eANN_var_min_dR_after
Definition: EdbShowAlg_NN.h:83
Float_t eANN_var_mean_dR_same
Definition: EdbShowAlg_NN.h:71
Float_t eANN_var_mean_dR_before
Definition: EdbShowAlg_NN.h:69
TTree * eANNTree
Definition: EdbShowAlg_NN.h:52
Float_t eANN_var_min_dR_before
Definition: EdbShowAlg_NN.h:79
TString eWeightFileLayoutString
Definition: EdbShowAlg_NN.h:51
Float_t eANN_var_min_dR_2after
Definition: EdbShowAlg_NN.h:85
Float_t eANN_var_min_dR_same
Definition: EdbShowAlg_NN.h:81
Float_t eANN_var_mean_dR_after
Definition: EdbShowAlg_NN.h:73
ClassDef(EdbShowAlg_NN, 1)
Float_t eANN_var_InBT_To_TestBT
Definition: EdbShowAlg_NN.h:57
Float_t eANN_var_mean_dT_same
Definition: EdbShowAlg_NN.h:70
Float_t eANN_var_min_dT_before
Definition: EdbShowAlg_NN.h:78
Float_t eANN_var_min_dT_after
Definition: EdbShowAlg_NN.h:82
Float_t eANN_var_mean_dT_before
Definition: EdbShowAlg_NN.h:68
Float_t eANN_var_SpatialDist_TestBT_To_InBT
Definition: EdbShowAlg_NN.h:62
Float_t eANN_var_min_dT_2before
Definition: EdbShowAlg_NN.h:76
TMultiLayerPerceptron * eTMlpANN
Definition: EdbShowAlg_NN.h:53
Int_t eANN_var_nseg_3after
Definition: EdbShowAlg_NN.h:91
Int_t eANN_var_nseg_1after
Definition: EdbShowAlg_NN.h:89
Float_t eANN_var_dR_NextBT_To_TestBT
Definition: EdbShowAlg_NN.h:65
Float_t eANN_var_zDiff_TestBT_To_InBT
Definition: EdbShowAlg_NN.h:63
Int_t eANN_var_nseg_3before
Definition: EdbShowAlg_NN.h:88
TString GetWeightFileString()
Definition: EdbShowAlg_NN.h:113
Float_t eANN_var_mean_dT_after
Definition: EdbShowAlg_NN.h:72
Float_t eANN_var_dT_NextBT_To_TestBT
Definition: EdbShowAlg_NN.h:64
Float_t eANN_var_dT_InBT_To_TestBT
Definition: EdbShowAlg_NN.h:58
Float_t eANN_var_mean_dT_2before
Definition: EdbShowAlg_NN.h:66
Int_t eANN_var_nseg_same
Definition: EdbShowAlg_NN.h:92
Float_t eANN_var_dR_InBT_To_TestBT
Definition: EdbShowAlg_NN.h:59
Int_t eANN_var_nseg_2after
Definition: EdbShowAlg_NN.h:90
TString eWeightFileString
Definition: EdbShowAlg_NN.h:50
Float_t eANN_var_mean_dR_2after
Definition: EdbShowAlg_NN.h:75
Int_t eANN_var_nseg_1before
Definition: EdbShowAlg_NN.h:86
Float_t eANN_var_min_dT_2after
Definition: EdbShowAlg_NN.h:84
Float_t eANN_var_min_dT_same
Definition: EdbShowAlg_NN.h:80
void SetWeightFileString(TString WeightFileString)
Definition: EdbShowAlg_NN.h:109
Int_t eANN_Inputtype
Definition: EdbShowAlg_NN.h:93
Float_t eANN_var_mean_dT_2after
Definition: EdbShowAlg_NN.h:74
Float_t eANN_var_mean_dR_2before
Definition: EdbShowAlg_NN.h:67
Float_t eANN_var_min_dR_2before
Definition: EdbShowAlg_NN.h:77
Definition: EdbShowAlg.h:40
Alg Print()
Alg Execute()
void Finalize()
Definition: ShowRec.cpp:513
void Initialize()
Definition: rwcToEdb.cpp:28