CbmRoot
Loading...
Searching...
No Matches
CbmTrdElectronsTrainAnn.h
Go to the documentation of this file.
1/* Copyright (C) 2009-2018 UGiessen, JINR-LIT
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Semen Lebedev [committer], Florian Uhlig */
4
10#ifndef CBM_TRD_ELECTRONS_TRAIN_ANN
11#define CBM_TRD_ELECTRONS_TRAIN_ANN
12
13#include "FairTask.h"
14#include "TMVA/Factory.h"
15#include "TMVA/Reader.h"
16#include "TMultiLayerPerceptron.h"
17
18#include <string>
19#include <vector>
20
21class TH1D;
22class TTree;
23class TGraph;
24class TRandom;
25//class TMultiLayerPerceptron;
26
28{
29 kANN = 0,
30 kBDT = 1,
33 kMeanCut = 4
34};
35
44class TrdEloss {
45 public:
46 TrdEloss() : TrdEloss(0., 0., 0.) {}
47
48 TrdEloss(double eloss, double dedx = 0., double tr = 0.) : fEloss(eloss), fdEdX(dedx), fTR(tr) {}
49
50 double fEloss;
51 double fdEdX;
52 double fTR;
53};
54
55
56class CbmTrdElectronsTrainAnn : public FairTask {
57 public:
61 CbmTrdElectronsTrainAnn(int nofTrdLayers);
62
67
71 virtual InitStatus Init();
72
76 virtual void Exec(Option_t* opt);
77
81 virtual void Finish();
82
86 void Draw(Option_t* = "");
87
88 private:
92 void FillElossVectorSim();
93
98
102 void FillElossHist();
103
108
109 void Run();
110
111 void DoTrain();
112
113 void DoTest();
114
115 void DoPreTest();
116
117 TTree* CreateTree();
118
119 std::string CreateAnnString();
120
121 TMVA::Factory* CreateFactory(TTree* simu);
122
123 TMVA::Reader* CreateTmvaReader();
124
125 void Transform();
126
127 void Transform1();
128
129 void Transform2();
130
131 Double_t FindOptimalCut();
132
134
135 TGraph* CreateRocDiagramm();
136
137 Double_t Likelihood();
138
139 Double_t Median();
140
141 Double_t MeanCut();
142
143 Double_t Eval(Bool_t isEl);
144
145 public:
146 void SetIsDoTrain(Bool_t doTrain) { fIsDoTrain = doTrain; }
147
148 void SetTransformType(Int_t type) { fTransformType = type; }
149
150 void SetIdMethod(IdMethod idMethod) { fIdMethod = idMethod; }
151
152 void SetOutputDir(const std::string& outputDir) { fOutputDir = outputDir; }
153
154 void SetNofAnnEpochs(Int_t nofAnnEpochs) { fNofAnnEpochs = nofAnnEpochs; }
155
156 void SetNofTrainSamples(Int_t nofTr) { fNofTrainSamples = nofTr; }
157
158 void SetSigmaError(Double_t sigma) { fSigmaError = sigma; }
159
160 void SetBeamDataFile(std::string beamDataFile) { fBeamDataFile = beamDataFile; }
161 void SetBeamDataPiHist(std::string beamDataPiHist) { fBeamDataPiHist = beamDataPiHist; }
162 void SetBeamDataElHist(std::string beamDataElHist) { fBeamDataElHist = beamDataElHist; }
163
164 void RunBeamData();
165
166 private:
167 void FillAnnInputHist(Bool_t isEl);
168
169 // Input arrays of simulated events
170 TClonesArray* fMCTracks;
171 TClonesArray* fTrdPoints;
172 TClonesArray* fTrdTracks;
173 TClonesArray* fTrdTrackMatches;
174 TClonesArray* fTrdHits;
175
176 // store energy loss information from TrdTrack
177 // 1st index -> [0] = electrons, [1] = pions
178 // 2nd index -> track index
179 // 3rd index -> hit index in track
180 std::vector<std::vector<std::vector<TrdEloss>>> fEloss;
181
182 std::vector<TH1*> fHists; //store all pointers to histograms
183
184 TH1* fhResults; // histograms for the results storing: pi suppression, el efficiency etc.
185
186 // [0] = electrons, [1] = pions
187 std::vector<TH1*> fhMeanEloss; // sum of energy losses in all layers divided by number of layers
188 std::vector<TH1*> fhEloss; // energy losses in one layer
189
190 // store sorted energy losses and cumulative probability for each TRD layer
191 // 1st index -> [0] = electrons, [1] = pions
192 // 2nd index -> layer number
193 std::vector<std::vector<TH1*>> fhElossSort;
194
195 Int_t fEventNum; // event number
196 std::string fOutputDir; // output directory
197 Double_t fSigmaError; // additional sigma error for energy loss measurements
198 Bool_t fIsDoTrain; // do you want to run training procedure?
199 Int_t fTransformType; // Energy loss transformation type
200
201 std::string fBeamDataFile; // path to file with beamtime data for energy losses
202 std::string fBeamDataPiHist; // histogram name with energy losses for pions
203 std::string fBeamDataElHist; // histogram name with energy losses for electrons
204
205 std::vector<Float_t> fAnnInput; // input vector for ANN
206 Float_t fXOut; // output value from ANN
207
208 Int_t fNofTrdLayers; // number of TRD layers
209
210 Double_t fMaxEval;
211 Double_t fMinEval;
212
213 TMultiLayerPerceptron* fNN;
214 TMVA::Reader* fReader;
219
220 // Histograms for testing
221 // [0] = electron, [1] = pion
222 std::vector<TH1*> fhOutput; // algorithm output
223 std::vector<TH1*> fhCumProbOutput; // Cumulative probabilities for algorithm's output
224 std::vector<std::vector<TH1*>> fhInput; // Input data for algorithm for each input
225
228
230};
231
232#endif
virtual ~CbmTrdElectronsTrainAnn()
Destructor.
void FillElossHist()
Fill histograms with energy loss information.
void Draw(Option_t *="")
Draw results.
void SetIsDoTrain(Bool_t doTrain)
void SetNofAnnEpochs(Int_t nofAnnEpochs)
virtual InitStatus Init()
Inherited from FairTask.
void SetOutputDir(const std::string &outputDir)
virtual void Finish()
Inherited from FairTask.
CbmTrdElectronsTrainAnn(int nofTrdLayers)
Default constructor.
ClassDef(CbmTrdElectronsTrainAnn, 1)
void FillElossVectorSim()
Fill vector with energy loss information for simulated data.
void SortElossAndFillHist()
Sort energy losses and fill histograms.
void SetBeamDataFile(std::string beamDataFile)
std::vector< TH1 * > fhCumProbOutput
void FillElossVectorReal()
Fill vector with energy loss information simulated from real data spectra.
std::vector< std::vector< TH1 * > > fhInput
std::vector< std::vector< std::vector< TrdEloss > > > fEloss
void SetSigmaError(Double_t sigma)
CbmTrdElectronsTrainAnn(const CbmTrdElectronsTrainAnn &)
TMVA::Factory * CreateFactory(TTree *simu)
std::vector< Float_t > fAnnInput
void SetIdMethod(IdMethod idMethod)
virtual void Exec(Option_t *opt)
Inherited from FairTask.
TMultiLayerPerceptron * fNN
void SetBeamDataPiHist(std::string beamDataPiHist)
std::vector< std::vector< TH1 * > > fhElossSort
CbmTrdElectronsTrainAnn & operator=(const CbmTrdElectronsTrainAnn &)
void SetBeamDataElHist(std::string beamDataElHist)
Represents information about energy losses in one layer.
TrdEloss(double eloss, double dedx=0., double tr=0.)