StRoot
1
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
StEmcUtil
neuralNet
macros
example.C
1
17
void
NNLoad()
18
{
19
gSystem->Load(
"$ROOTSYS/lib/libProof.so"
);
20
gSystem->Load(
"$ROOTSYS/lib/libTree.so"
);
21
gSystem->Load(
"$ROOTSYS/lib/libTreePlayer.so"
);
22
gSystem->Load(
"$ROOTSYS/lib/libTreeViewer.so"
);
23
gSystem->Load(
"St_base"
);
24
gSystem->Load(
"StarClassLibrary"
);
25
gSystem->Load(
"St_Tables"
);
26
gSystem->Load(
"StChain"
);
27
gSystem->Load(
"StEvent"
);
28
gSystem->Load(
"StEmcUtil"
);
29
}
30
36
void
NNTrain()
37
{
38
// instantiate the neural net
39
StEmcNeuralNet *n =
new
StEmcNeuralNet();
40
// set the file that contains the signal events
41
n->setSignalFile(
"NNsignal_less1GeV.root"
);
42
// set the file that contains the background events
43
n->setBackFile(
"NNbackg_less1GeV.root"
);
44
// set the number of parameters
45
n->setNParameters(6);
46
// set the neural net formula
47
n->setFormula(
"v1:v2:v3:v5:v6:v7"
);
48
// initializes the neural net for training
49
n->initNNet(0,48);
50
// train the neural net. If second parameter is set to 0, no evolution graph is displayed.
51
n->train(6000,200);
52
// saves the neural net kernel
53
n->saveKernel(
"kernel.dat"
);
54
// draw QA histograms
55
n->drawNNetHists();
56
}
57
63
void
NNUse()
64
{
65
// instantiante neuralnet
66
StEmcNeuralNet *n =
new
StEmcNeuralNet();
67
// set number of parameters
68
n->setNParameters(6);
69
// set the neural net formula
70
n->setFormula(
"v1:v2:v3:v5:v6:v7"
);
71
// initializes the neural net (if no parameters are entered, neural net is not supposed to be trained)
72
n->initNNet();
73
// loads the neural net kernel
74
n->loadKernel(
"kernel.dat"
);
75
76
// this just creates an histogram to write the output of the
77
// neural net.
78
//
79
// to use the neural net, just put the parameters in a float
80
// array (x[] in this example) and just ask for the neural
81
// net output for this set of parameters by using the
82
// method getNNGuess(x), as seen in this example
83
//
84
TH1F *h=
new
TH1F(
"test"
,
"test"
,100,0,1);
85
TFile f(
"test.root"
);
86
TTree *nn = (TTree*)f.Get(
"Scaled_Electrons;1"
);
87
double
xx[15];
88
float
x[6];
89
nn->SetBranchAddress(
"Scaled_Electrons_Branch"
,&xx[0]);
90
for
(
int
i=0;i<40;i++)
91
{
92
nn->GetEntry(i+1);
93
x[0]=xx[1];x[1]=xx[2];x[2]=xx[3];x[3]=xx[5];x[4]=xx[6];x[5]=xx[7];
94
float
o = n->getNNGuess(x);
95
h->Fill(o);
96
}
97
h->Draw();
98
}
Generated by
1.8.5