FEDRA emulsion software from the OPERA Collaboration
EdbShowAlgE.h
Go to the documentation of this file.
1 #ifndef ROOT_EdbShowAlgE
2 #define ROOT_EdbShowAlgE
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 "TMLPAnalyzer.h"
12 #include "TCanvas.h"
13 #include "TObjString.h"
14 
15 #include "EdbVertex.h"
16 #include "EdbPVRec.h"
17 #include "EdbPhys.h"
18 #include "EdbMath.h"
19 #include "EdbMomentumEstimator.h"
20 #include "EdbLog.h"
21 #include "EdbPattern.h"
22 #include "EdbShowerP.h"
23 
24 using namespace std;
25 
26 //______________________________________________________________________________
27 //___
28 //___ Declaration of EdbShowAlgE Class:
29 //___
30 //___
31 //___ STILL TO WRITE
32 //___
33 //______________________________________________________________________________
34 
35 
36 
37 
38 
39 
40 //______________________________________________________________________________
41 
42 class EdbShowAlgE : public TObject {
43 
44 private:
45 
46  // Parametrization Name: this name sets imprtant variables depending on the parametrization:
49  Int_t eShowAlgEPlatesN; // used only to set names and distingiush. Not used for any reconstructon
50  //or measurement!
51 
52 
54 
55 
56 
57  // TObjArray storing Reconstructed Showers:
58  TObjArray* eRecoShowerArray;
60 
61 
62  // TObjArray storing TMultiLayerPerceptron for different shower film length:
63  TObjArray* eMLPArray;
64  Int_t eMLPArrayN; // (==eMLP_InputNeuronsArrayN)
65 
66  // Wheter this is used as Training or RunMethod:
67  Bool_t eDoANNTrain;
68  Bool_t eDoANNRun;
69 
70  // Variables as arrays for the In/Outut of the ANN.
71  // They have to be given in Float_t* array, to root specifications of
72  // the implementation... (?? where to read this ??)
73 
74  // TODO CHECK THIS !!!!!
75  // With the new gcc --version 7.30 (shipped with Ubuntu 18.04)
76  // compilation does stop here with an error (as of 2018/03/28).
77  // Why?
78 
79  // It seems like (found in an old root post) when putting
80  // the ! behind the commend behind the variable, then
81  // somehow it ist made transient and the cint (now cling) can handle
82  // this.
83 
84 // Float_t eInANN[70];
85  Float_t* eInANN = new Float_t[70];
86  // Float_t* eInANN; // worked with gcc 4.4, but with gcc 7.3
87  Float_t eOutANN;
88  // Float_t* eInfoANN; // worked with gcc 4.4, but with gcc 7.3
89  Float_t* eInfoANN = new Float_t[70];
90 
91  // Histograms storing the eInANN distributions:
92  TH1F* eInANN_Hist[70];
93 
94 
95 
96 
97  TMultiLayerPerceptron* eMLP_Simple;
98 
101 
102  TString eMLP_Layout;
103  TObjArray* eMLP_LayoutArray;
105 
106 
109  TString eMLP_WeightFileNameArray[10];
110 
112 
116 
120 
121 
122 
123  // Reset All Default Variables:
124  void Set0();
125 
126  // Set Default Variables
127  void Init();
128  void Init(TString ParaName);
129 
130  // Create Input Histos
131  void CreateInputHistos();
132 
133  // Fill Input Histos with Entries by eMLP_SimpleTree:
134  void FillInputHistosPara_XX();
135 
136  // Simple Layout Creation function: n:n+1:n:inputtype
137  TString CreateMLPLayout(Int_t NrOfANNInputNeurons);
138 
139 
140 
141 
142 
143  void ClearPlateBinning();
144  void ResetWeightFileNameArray();
145  void AddWeightFilePlate(TString tmpString, Int_t dospec);
146 
147  Bool_t CheckStringToShowAlgEParaName(TString tmpString2);
148 
149  // Helper Function:
150  int GetLastBinHistoFilles(TH1* h);
151 
152 
153 public:
154 
156  EdbShowAlgE(TString ShowAlgEParaName);
157  EdbShowAlgE(TObjArray* RecoShowerArray);
158  EdbShowAlgE(TObjArray* RecoShowerArray, TString ShowAlgEParaName);
159 
160 
161  virtual ~EdbShowAlgE(); // virtual constructor due to inherited class
162 
163 
164 
165 
166 
167 
168 
169 
170  // Set Functions
171  inline void SetRecoShowerArray(TObjArray* RecoShowerArray) {
172  eRecoShowerArray=RecoShowerArray;
173  }
174 
175  inline void SetMLPLayout(TString layout) {
176  eMLP_Layout = layout;
177  }
178  inline void SetMLPWeightFileName(TString weightfilename) {
179  eMLP_WeightFileName = weightfilename;
180  }
181  inline void SetMLPInputFileName(TString MLP_InputFileName) {
182  eMLP_InputFileName = MLP_InputFileName;
183  }
184  inline void SetMLPTrainEpochs(Int_t nep) {
185  eMLP_TrainEpochs = nep;
186  }
187  inline void SetMLPArrayN(Int_t MLPArrayN) {
188  eMLPArrayN = MLPArrayN;
189  }
190 
191  inline void SetPlatesN(Int_t ShowAlgEPlatesN) {
192  eShowAlgEPlatesN = ShowAlgEPlatesN;
193  }
194 
195 
196  void SetDoTrain(Int_t type);
197  void SetDoRun(Int_t type);
198 
199  void SetInputHistosPara(Int_t ParaType);
200  void SetInputHistosPara_FJ();
201  void SetInputHistosPara_YC();
202  void SetInputHistosPara_XX();
203  void SetInputHistosPara_YY();
204 
205  void SetWriteMLPWeightFile(Int_t type);
206  void SetWriteMLPInputFile(Int_t type);
207  void SetReadMLPInputFile(Int_t type);
208 
209  void ReadMLPInputFile();
210  void WriteMLPInputFile();
211 
212 
213  // Get Functions
214  inline TMultiLayerPerceptron* GetMLP() const {
215  return eMLP_Simple;
216  }
217 
218  inline TH1F* GetHistInANN(Int_t nr) const {
219  return eInANN_Hist[nr];
220  }
221 
222  inline TString GetMLPLayout() {
223  return eMLP_Layout;
224  }
225  inline TString GetMLPWeightFileName() {
226  return eMLP_WeightFileName;
227  }
228  inline TString GetMLPInputFileName() {
229  return eMLP_InputFileName;
230  }
231  inline Int_t SetMLPTrainEpochs() {
232  return eMLP_TrainEpochs;
233  }
234 
235 
236  TCanvas* GetHistoCanvas();
237  void Print();
238 
239 
240 
241  // Main functions for using this ShowerAlgorithm Object.
242  // Structure is made similar to OpRelease, where
243  // Initialize, Execute, Finalize
244  // give the three columns of the whole thing.
245  // Since these functions depend on the algorithm type they are made virtual
246  // and implemented in the inherited classes.
247  virtual void Initialize();
248  virtual void Execute();
249  virtual void Finalize();
250 
251 
252 
254 
255 // void TESTTRAIN();
256  void Create_MLP();
257  void Create_MLPTree();
258  void Fill_MLPTree();
259 // void Train_MLP();
260 // void Run_MLP();
261 
262  void TESTRUN();
263  void SetInputHistos(TH1F* h, Int_t nbin, Double_t lower, Double_t upper);
264 
265 
266 
267 
268 
269  // CreateStandardWeightFileStrings
270  void CreateStandardWeightFileStrings();
271  void CreateStandardMLPArrayN();
272  void PrintWeightFileStrings();
273  void ResetPlateBinning();
274 
275  Int_t CheckPlateAndPlateBinning(Int_t Plate);
276  void AddWeightFile(TString tmpString, Int_t Plate, TString tmpString2);
277 
278 
279  void CreateMLPLayouts();
280  void CreateMLPLayouts_FJ();
281  void CreateMLPLayouts_LT();
282  void CreateMLPLayouts_YC();
283  void CreateMLPLayouts_JC();
284  void CreateMLPLayouts_XX();
285  void CreateMLPLayouts_YY();
286  void CreateMLPLayout_YC(Int_t nr);
287  void CreateMLPLayout_XX(Int_t nr);
288  void CreateMLPLayout_YY(Int_t nr);
289 
290 
291  void FillInputNeuronsArray_YC();
292  void FillInputNeuronsArray_XX();
293  void FillInputNeuronsArray_YY();
294 
295  void CreateInputNeuronsArray_YC();
296  void CreateInputNeuronsArray_XX();
297  void CreateInputNeuronsArray_YY();
298 
299  void CreateInputNeuronsArray();
300 
301 
302  void CreateMLPs();
303  void CreateMLPArray();
304  void LoadMLPWeights();
305  void LoadMLPWeights(Int_t nr);
306 
307  void SetBinsInputHistos();
308  void SetBinsInputHistos_YC();
309  void SetBinsInputHistos_XX();
310  void SetBinsInputHistos_FJ();
311  void SetBinsInputHistos_YY();
312 
313 
314  void FillMLP_SimpleTree_YC(EdbShowerP* show, Int_t ShowAlgEParaNr);
315  void FillMLP_SimpleTree_YC();
316  void FillMLP_SimpleTree_XX(EdbShowerP* show, Int_t ShowAlgEParaNr);
317  void FillMLP_SimpleTree_XX();
318  void FillMLP_SimpleTree_YY(EdbShowerP* show, Int_t ShowAlgEParaNr);
319  void FillMLP_SimpleTree_YY();
320  void FillMLP_SimpleTree();
321 
322  void WriteMLP_SimpleTree(TString filename);
323 
324  void Train();
325  void Run();
326  void DumpWeights();
327 
328 
329  int GetMLPArrayNr(Int_t NPlToCheck);
330 
332 
333 
334  // Read parameters out of default.par file
335  int ReadShowAlgEPar(const char *file);
336 
337 
338 
339  ClassDef(EdbShowAlgE,1); // Root Class Definition for my Objects
340 };
341 
342 
343 //______________________________________________________________________________
344 
345 #endif /* ROOT_EdbShowAlg */
TObjArray * RecoShowerArray
Definition: Shower_E_FromShowerRoot.C:12
Definition: EdbShowAlgE.h:42
Int_t SetMLPTrainEpochs()
Definition: EdbShowAlgE.h:231
TString GetMLPLayout()
Definition: EdbShowAlgE.h:222
Int_t eMLP_InputNeurons
Definition: EdbShowAlgE.h:113
TObjArray * eRecoShowerArray
Definition: EdbShowAlgE.h:58
TString eMLP_Layout
Definition: EdbShowAlgE.h:102
TString GetMLPInputFileName()
Definition: EdbShowAlgE.h:228
Int_t eMLP_TrainEpochs
Definition: EdbShowAlgE.h:111
TH1F * GetHistInANN(Int_t nr) const
Definition: EdbShowAlgE.h:218
TArrayI * eMLP_InputNeuronsArray
Definition: EdbShowAlgE.h:114
TString GetMLPWeightFileName()
Definition: EdbShowAlgE.h:225
TString eShowAlgEParaName
Definition: EdbShowAlgE.h:47
void SetMLPLayout(TString layout)
Definition: EdbShowAlgE.h:175
Bool_t eMLP_SimpleIsDone
Definition: EdbShowAlgE.h:99
Float_t eOutANN
Definition: EdbShowAlgE.h:87
ClassDef(EdbShowAlgE, 1)
void SetRecoShowerArray(TObjArray *RecoShowerArray)
Definition: EdbShowAlgE.h:171
void SetMLPArrayN(Int_t MLPArrayN)
Definition: EdbShowAlgE.h:187
TMultiLayerPerceptron * GetMLP() const
Definition: EdbShowAlgE.h:214
TString eMLP_InputFileName
Definition: EdbShowAlgE.h:117
Int_t eShowAlgEPlatesN
Definition: EdbShowAlgE.h:49
Int_t eMLP_InputNeuronsArrayN
Definition: EdbShowAlgE.h:115
TObjArray * eMLP_LayoutArray
Definition: EdbShowAlgE.h:103
void SetMLPWeightFileName(TString weightfilename)
Definition: EdbShowAlgE.h:178
TMultiLayerPerceptron * eMLP_Simple
Definition: EdbShowAlgE.h:97
Bool_t eMLP_ReadMLPInputFile
Definition: EdbShowAlgE.h:119
Bool_t eDoANNRun
Definition: EdbShowAlgE.h:68
Int_t eRecoShowerArrayN
Definition: EdbShowAlgE.h:59
Int_t eMLPArrayN
Definition: EdbShowAlgE.h:64
Int_t eShowAlgEParaNr
Definition: EdbShowAlgE.h:48
TString eMLP_WeightFileName
Definition: EdbShowAlgE.h:108
TObjArray * eMLPArray
Definition: EdbShowAlgE.h:63
Bool_t eMLP_WriteWeightFile
Definition: EdbShowAlgE.h:107
Bool_t eMLP_WriteMLPInputFile
Definition: EdbShowAlgE.h:118
void SetPlatesN(Int_t ShowAlgEPlatesN)
Definition: EdbShowAlgE.h:191
Bool_t eDoANNTrain
Definition: EdbShowAlgE.h:67
TTree * eMLP_SimpleTree
Definition: EdbShowAlgE.h:100
Bool_t eMLP_LayoutArrayIsDone
Definition: EdbShowAlgE.h:104
TArrayI * eShowAlgEPlateBinning
Definition: EdbShowAlgE.h:53
void SetMLPTrainEpochs(Int_t nep)
Definition: EdbShowAlgE.h:184
void SetMLPInputFileName(TString MLP_InputFileName)
Definition: EdbShowAlgE.h:181
Definition: EdbShowerP.h:28
string filename
Definition: emthickness.cpp:34
Alg Print()
Alg Execute()
void Finalize()
Definition: ShowRec.cpp:513
void Run(bool AbsCoord=false, float X0, float Y0, float DDX, float DDY, const char *File, bool Images=false)
Definition: run.C:208
void Initialize()
Definition: rwcToEdb.cpp:28
new TCanvas()
Int_t type
Definition: testBGReduction_By_ANN.C:15
TFile * file
Definition: write_pvr.C:3