41 #include "StPmdUtil/StPmdGeom.h"
42 #include "StPmdUtil/StPmdDetector.h"
43 #include "StPmdDiscriminatorMaker.h"
44 #include "StPmdDiscriminatorNN.h"
45 #include "StPmdUtil/StPmdClusterCollection.h"
46 #include "StPmdUtil/StPmdCluster.h"
47 #include "StPmdNeuNet.h"
48 #include "StEventTypes.h"
49 #include "StNNCluster.h"
52 ofstream fileo("test_NN",ios::app);
63 cout<<
"inside discNN, size**"<<cl_con.size()<<
" "<<mClContainer.size()<<endl;
73 StPmdDiscriminatorNN::~StPmdDiscriminatorNN()
78 void StPmdDiscriminatorNN::Discriminate()
81 sneu->setDiscMaker(m_DiscMaker);
84 sneu ->SetUseBiases();
87 Int_t NNSize=mClContainer.size();
88 sneu->SetNTrainEvents(NNSize);
89 sneu->SetArraySize(NNSize);
90 cout<<
"nTrainevts "<<sneu->GetNTrainEvents()<<endl;
92 cout<<
"No of INputs **"<<NTrain<<
"NNFlag "<<mApplyFlagNN<<endl;
98 sneu->
Export(
"NNTrain.out");
102 cout<<
" NNTrain to be imported "<<endl;
103 sneu->
Import(
"NNTrain.out");
106 Float_t Teach[20000];
107 Float_t Value[20000];
108 for(Int_t i=0;i<20000;i++){Teach[i]=999; Value[i]=0;}
110 cout<<
"NN Valid() Called "<<endl;
112 for(Int_t i=0;i<20000;i++){
113 if(Teach[i]!=999)fileo<<Teach[i]<<
" "<<Value[i]<<endl;
118 void StPmdDiscriminatorNN::Input(
StPmdNeuNet* sneu)
120 TFile * file=
new TFile(
"nninput.root",
"RECREATE");
121 m_NNedep_ph=
new TH1F(
"nnedp_ph",
"(ph) PMD edep",100,0.,1000.);
122 m_NNncell_ph=
new TH1F(
"nn_ncell_ph",
"(ph) PMD ncell",100,0.,20.);
123 m_NNsigma_ph=
new TH1F(
"nn_sigma_ph",
"(ph) PMD sigma",100,0.,20.);
124 m_NNedep_cpv_ph=
new TH1F(
"nnedp_cpv_ph",
"(ph) CPV edep",100,0.,100.);
125 m_NNedep_had=
new TH1F(
"nnedp_had",
"(had) PMD edep",100,0.,1000.);
126 m_NNncell_had=
new TH1F(
"nn_ncell_had",
"(had) PMD ncell",100,0.,20.);
127 m_NNsigma_had=
new TH1F(
"nn_sigma_had",
"(had) PMD sigma",100,0.,20.);
128 m_NNedep_cpv_had=
new TH1F(
"nnedp_cpv_had",
"(had) CPV edep",100,0.,100.);
131 Int_t totno = 0,totcpvno = 0;
132 Float_t aveEnergy = 0., aveNcell = 0., aveSigma = 0.,aveCpvEnergy = 0;
133 Float_t totEnergy = 0., totNcell = 0., totSigma = 0.,totCpvEnergy = 0;
135 for(UInt_t i=0;i<mClContainer.size();i++)
141 totEnergy = totEnergy + cl1->energy();
142 totNcell = totNcell + cl1->numberOfCells();
143 totSigma = totSigma + cl1->sigma();
146 totCpvEnergy = totCpvEnergy + cl2->energy();
150 aveEnergy = totEnergy/totno;
151 aveNcell = totNcell/totno;
152 aveSigma = totSigma/totno;
153 aveCpvEnergy = totCpvEnergy/totcpvno;
165 aveEnergy =0.000157085 ;
168 aveCpvEnergy =1.26994e-05;
172 fileo<<
" AveEnergy "<<aveEnergy<<
" AveNcell "<<aveNcell<<
" aveSigma "<<aveSigma<<
" aveCpvEne "<<aveCpvEnergy<<
" TotNo "<<totno<<
" TotCPvNo "<<totcpvno<<endl;
174 Float_t outEnergy,outNcell,outSigma,outCpvEnergy;
176 for(UInt_t i=0;i<mClContainer.size();i++)
181 if(cl1->mcPid()==1)target=1.;
182 if(cl1->mcPid()==8)target=0.;
183 sneu->fillArrayOut(target,i,0);
186 Float_t energy=cl1->energy();
187 InputRange(energy,aveEnergy,outEnergy);
188 sneu->FillArray(i,0,outEnergy);
190 Int_t ncell=cl1->numberOfCells();
191 InputRange(ncell,aveNcell,outNcell);
193 sneu->FillArray(i,1,outNcell);
195 Float_t sigma=cl1->sigma();
196 InputRange(sigma,aveSigma,outSigma);
198 sneu->FillArray(i,2,outSigma);
200 Float_t cpv_energy=0.;
202 cpv_energy=cl2->energy();
203 InputRange(cpv_energy,aveCpvEnergy,outCpvEnergy);
205 sneu->FillArray(i,3,outCpvEnergy);
208 if(target==1)m_NNncell_ph->Fill(Float_t(ncell));
209 if(target==0)m_NNncell_had->Fill(Float_t(ncell));
210 if(target==1)m_NNsigma_ph->Fill(sigma);
211 if(target==0)m_NNsigma_had->Fill(sigma);
212 if(target==1&&cpv_energy>0)m_NNedep_cpv_ph->Fill(cpv_energy);
213 if(target==0&&cpv_energy>0)m_NNedep_cpv_had->Fill(cpv_energy);
214 if(target==1)m_NNedep_ph->Fill(energy);
215 if(target==0)m_NNedep_had->Fill(energy);
218 cout<<
"In Input **"<<NTrain<<endl;
219 m_NNedep_ph->Write();
220 m_NNncell_ph->Write();
221 m_NNsigma_ph->Write();
222 m_NNedep_cpv_ph->Write();
224 m_NNedep_had->Write();
225 m_NNncell_had->Write();
226 m_NNsigma_had->Write();
227 m_NNedep_cpv_had->Write();
231 void StPmdDiscriminatorNN::setFormula()
233 cout<<
"In the Neural Network"<<npmdvalue<<ncpvvalue<<endl;
238 Float_t StPmdDiscriminatorNN::InputRange(Float_t Input,Float_t aveInput, Float_t& Output)
243 if((Input/aveInput)<10.){
244 fx = (2./(1. + exp(-ax*Input/aveInput))) - 1;
248 fx = (2./(1. + exp(-10.))) - 1.;
250 Output = 1 - 2. * fx;
virtual Double_t ApplyWeights(Float_t *, Float_t *)
virtual void SetLearnParam(Double_t learnParam=0.2, Double_t fse=0., Double_t mu=0.)
virtual void SetInitParam(Float_t lowerInitWeight=-1., Float_t upperInitWeight=1.)
Sets the initialisation parameters : max and min weights.
virtual void TrainNCycles(Int_t nCycles=10)
virtual void Export(const Text_t *fileName="exportNN.dat")
virtual void Import(const Text_t *fileName="exportNN.dat")
virtual void PrintS()
prints structure of network on screen
StPhmdCluster * PmdCluster()
destructor