30#include "TMultiLayerPerceptron.h"
34#include <boost/assign/list_of.hpp>
43using boost::assign::list_of;
47 : fMaxNofTrainSamples(1500)
49 , fNofWrongLikeCorrect(0)
50 , fNofCorrectLikeWrong(0)
64 , fhAnnOutput_correct(nullptr)
65 , fhAnnOutput_wrong(nullptr)
66 , fhCumProb_correct(nullptr)
67 , fhCumProb_wrong(nullptr)
75void CbmKresTrainAnn::Exec(
int event,
int IdForANN,
double InvariantMass,
double OpeningAngle,
double PlaneAngle_last,
76 double ZPos, TVector3 Momentum1, TVector3 Momentum2)
79 TMath::Sqrt(Momentum1.X() * Momentum1.X() + Momentum1.Y() * Momentum1.Y() + Momentum1.Z() * Momentum1.Z());
81 TMath::Sqrt(Momentum2.X() * Momentum2.X() + Momentum2.Y() * Momentum2.Y() + Momentum2.Z() * Momentum2.Z());
103 if (
IM_correct.size() % 100 == 0 && IdForANN == 1)
129 TTree* simu =
new TTree(
"MonteCarlo",
"MontecarloData");
133 simu->Branch(
"x0", &
x[0],
"x0/D");
134 simu->Branch(
"x1", &
x[1],
"x1/D");
135 simu->Branch(
"x2", &
x[2],
"x2/D");
136 simu->Branch(
"x3", &
x[3],
"x3/D");
137 simu->Branch(
"x4", &
x[4],
"x4/D");
138 simu->Branch(
"x5", &
x[5],
"x5/D");
139 simu->Branch(
"xOut", &xOut,
"xOut/D");
141 for (
size_t i = 0; i <
IM_correct.size(); i++) {
149 if (
x[0] > 1.0)
x[0] = 1.0;
150 if (
x[1] > 1.0)
x[1] = 1.0;
151 if (
x[2] > 1.0)
x[2] = 1.0;
152 if (
x[3] > 1.0)
x[3] = 1.0;
153 if (
x[4] > 1.0)
x[4] = 1.0;
154 if (
x[5] > 1.0)
x[5] = 1.0;
160 for (
size_t i = 0; i <
IM_wrong.size(); i++) {
168 if (
x[0] > 1.0)
x[0] = 1.0;
169 if (
x[1] > 1.0)
x[1] = 1.0;
170 if (
x[2] > 1.0)
x[2] = 1.0;
171 if (
x[3] > 1.0)
x[3] = 1.0;
172 if (
x[4] > 1.0)
x[4] = 1.0;
173 if (
x[5] > 1.0)
x[5] = 1.0;
180 TMultiLayerPerceptron network(
"x0,x1,x2,x3,x4,x5:12:xOut", simu,
"Entry$+1");
181 network.Train(300,
"text,update=10");
182 network.DumpWeights(
"../../../analysis/conversion2/KresAnalysis_ann_weights.txt");
189 for (
size_t i = 0; i <
IM_correct.size(); i++) {
197 if (params[0] > 1.0) params[0] = 1.0;
198 if (params[1] > 1.0) params[1] = 1.0;
199 if (params[2] > 1.0) params[2] = 1.0;
200 if (params[3] > 1.0) params[3] = 1.0;
201 if (params[4] > 1.0) params[4] = 1.0;
202 if (params[5] > 1.0) params[5] = 1.0;
204 Double_t netEval = network.Evaluate(0, params);
208 for (
size_t i = 0; i <
IM_wrong.size(); i++) {
216 if (params[0] > 1.0) params[0] = 1.0;
217 if (params[1] > 1.0) params[1] = 1.0;
218 if (params[2] > 1.0) params[2] = 1.0;
219 if (params[3] > 1.0) params[3] = 1.0;
220 if (params[4] > 1.0) params[4] = 1.0;
221 if (params[5] > 1.0) params[5] = 1.0;
223 Double_t netEval = network.Evaluate(0, params);
232 cout <<
"nof correct pairs = " <<
IM_correct.size() << endl;
233 cout <<
"nof wrong pairs = " <<
IM_wrong.size() << endl;
239 Double_t cumProbFake = 0.;
240 Double_t cumProbTrue = 0.;
253 TCanvas* c1 =
new TCanvas(
"ann_correct_ann_output",
"ann_correct_ann_output", 400, 400);
254 c1->SetTitle(
"ann_correct_ann_output");
257 TCanvas* c2 =
new TCanvas(
"ann_wrong_ann_output",
"ann_wrong_ann_output", 400, 400);
258 c2->SetTitle(
"ann_wrong_ann_output");
261 TCanvas* c3 =
new TCanvas(
"ann_correct_cum_prob",
"ann_correct_cum_prob", 400, 400);
262 c3->SetTitle(
"ann_correct_cum_prob");
265 TCanvas* c4 =
new TCanvas(
"ann_wrong_cum_prob",
"ann_wrong_cum_prob", 400, 400);
266 c4->SetTitle(
"ann_wrong_cum_prob");
274 fhAnnOutput_correct =
new TH1D(
"fhAnnOutput_correct",
"ANN output;ANN output;Counter", 100, -1.2, 1.2);
276 fhAnnOutput_wrong =
new TH1D(
"fhAnnOutput_wrong",
"ANN output;ANN output;Counter", 100, -1.2, 1.2);
279 fhCumProb_correct =
new TH1D(
"fhCumProb_correct",
"ANN output;ANN output;Cumulative probability", 100, -1.2, 1.2);
281 fhCumProb_wrong =
new TH1D(
"fhCumProb_wrong",
"ANN output;ANN output;Cumulative probability", 100, -1.2, 1.2);
Helper functions for drawing 1D and 2D histograms and graphs.
vector< double > IM_wrong
vector< double > Mom2_correct
virtual ~CbmKresTrainAnn()
vector< double > OA_wrong
unsigned int fMaxNofTrainSamples
vector< double > Mom1_correct
vector< double > Angle_wrong
vector< double > Mom1_wrong
vector< double > OA_correct
vector< double > Mom2_wrong
vector< double > Angle_correct
TH1D * fhAnnOutput_correct
void Exec(int event, int IdForANN, double InvariantMass, double OpeningAngle, double PlaneAngle_last, double ZPos, TVector3 Momentum1, TVector3 Momentum2)
vector< double > Z_correct
vector< double > IM_correct