14 preshStripEnergyCut_(stripEnergyCut), preshSeededNstr_(nStripCut), pathToFiles_(path)
20 string file_pt[5] = {
"20",
"30",
"40",
"50",
"60"};
21 string file_barrel_pt[5] = {
"20",
"30",
"40",
"50",
"60"};
23 string nn_paterns_file =
"";
24 for(
int j=0;j<Nfiles_EE;j++) {
25 nn_paterns_file =
"endcapPiZeroDiscriminatorWeights_et"+file_pt[j]+
".wts";
27 readWeightFile(WFile.fullPath().c_str());
34 for(
int i=0;
i<Indim*Hidden;
i++) I_H_Weight_all.push_back(I_H_Weight[
i]);
35 for(
int i=0;i<Hidden;i++) H_Thresh_all.push_back(H_Thresh[i]);
36 for(
int i=0;i<Outdim*Hidden;i++) H_O_Weight_all.push_back(H_O_Weight[i]);
37 for(
int i=0;i<Outdim;i++) O_Thresh_all.push_back(O_Thresh[i]);
40 for(
int k=0;
k<Nfiles_EB;
k++) {
41 nn_paterns_file =
"barrelPiZeroDiscriminatorWeights_et"+file_barrel_pt[
k]+
".wts";
43 readWeightFile(WFile.fullPath().c_str());
50 for(
int i=0;i<Indim*Hidden;i++) I_H_Weight_all.push_back(I_H_Weight[i]);
51 for(
int i=0;i<Hidden;i++) H_Thresh_all.push_back(H_Thresh[i]);
52 for(
int i=0;i<Outdim*Hidden;i++) H_O_Weight_all.push_back(H_O_Weight[i]);
53 for(
int i=0;i<Outdim;i++) O_Thresh_all.push_back(O_Thresh[i]);
65 vector<float> vout_stripE;
68 if ( rechits_map->size() == 0 ) {
69 edm::LogWarning(
"EndcapPiZeroDiscriminatorAlgo") <<
"RecHitsMap has size 0.";
75 vector<ESDetId> road_2d;
78 int plane = strip.
plane();
80 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPreshVectors: Preshower Seeded Algorithm - looking for clusters" <<
"n"<<
"findPreshVectors: Preshower is intersected at strip " << strip.
strip() <<
", at plane " << plane ;
84 for(
int i=0;i<11;i++) {
85 vout_stripE.push_back(-100.);
90 road_2d.push_back(strip);
96 findPi0Road(strip, navigator, plane, road_2d);
98 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo:findPreshVectors: Total number of strips in the central road: " << road_2d.size() ;
101 RecHitsMap::iterator final_strip = rechits_map->end();
105 ESDetId last_stripID = final_strip->first;
108 vector<ESDetId>::iterator itID;
109 for (itID = road_2d.begin(); itID != road_2d.end(); itID++) {
110 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPreshVectors: ID = " << *itID ;
112 RecHitsMap::iterator strip_it = rechits_map->find(*itID);
113 if(goodPi0Strip(strip_it,last_stripID)) {
114 E = strip_it->second.energy();
116 vout_stripE.push_back(E);
117 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPreshVectors: E = " << E ;
124 vector<float> vout_ElevenStrips_Energy;
125 for(
int i=0;i<11;i++)
127 vout_ElevenStrips_Energy.push_back(0.);
130 for(
unsigned int i=0;i<vout_stripE.size();i++)
132 vout_ElevenStrips_Energy[
i] = vout_stripE.at(i);
136 return vout_ElevenStrips_Energy;
144 RecHitsMap::iterator candidate_tmp = candidate_it;
147 if (candidate_tmp->first == lastID )
148 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: goodPi0Strip No such a strip in rechits_map " ;
149 if (candidate_it->second.energy() <= preshStripEnergyCut_)
150 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: goodPi0Strip Strip energy " << candidate_it->second.energy() <<
" is below threshold " ;
153 if ( (candidate_tmp->first == lastID ) ||
154 (candidate_it->second.energy() <= preshStripEnergyCut_ ) )
164 int plane, vector<ESDetId>& vout) {
165 if ( strip ==
ESDetId(0) )
return;
168 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPi0Road: starts from strip " <<
strip ;
173 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPi0Road: Go to the East " ;
176 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPi0Road: East: " << n_east <<
" current strip is " <<
next ;
178 vout.push_back(next);
180 if (n_east == preshSeededNstr_)
break;
184 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPi0Road: Go to the West " ;
188 LogTrace(
"EcalClusters") <<
"findPi0Road: West: " << n_west <<
" current strip is " <<
next ;
190 vout.push_back(next);
192 if (n_west == preshSeededNstr_)
break;
194 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPi0Road: Total number of strips found in the road at 1-st plane is " << n_east+n_west ;
197 else if (plane == 2) {
200 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPi0Road: Go to the North " ;
203 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPi0Road: North: " << n_north <<
" current strip is " <<
next;
205 vout.push_back(next);
207 if (n_north == preshSeededNstr_)
break;
211 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPi0Road: Go to the South " ;
215 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPi0Road: South: " << n_south <<
" current strip is " <<
next ;
217 vout.push_back(next);
219 if (n_south == preshSeededNstr_)
break;
221 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPi0Road: Total number of strips found in the road at 2-nd plane is " << n_south+n_north ;
225 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPi0Road: Wrong plane number, null cluster will be returned! " ;
244 bool checkinit=
false;
248 weights = fopen(Weights_file,
"r");
249 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: I opeded the Weights file = " << Weights_file ;
252 while( !feof(weights) ){
253 fscanf(weights,
"%s", line);
254 if (line[0] ==
'A') {
255 fscanf(weights,
"%d", &Layers);
256 fscanf(weights,
"%d", &Indim);
257 fscanf(weights,
"%d", &Hidden);
258 fscanf(weights,
"%d", &Outdim);
262 I_H_Weight =
new float[Indim*Hidden];
263 H_Thresh =
new float[Hidden];
264 H_O_Weight =
new float[Hidden*Outdim];
265 O_Thresh =
new float[Outdim];
267 }
else if (line[0] ==
'B') {
269 for (
int i = 0; i<Indim; i++){
270 for (
int j = 0; j<Hidden; j++){
271 fscanf(weights,
"%f", &I_H_Weight[i*Hidden+j]);
274 }
else if (line[0] ==
'C'){
276 for (
int i = 0; i<Hidden; i++){
277 fscanf(weights,
"%f", &H_Thresh[i]);
279 }
else if (line[0] ==
'D'){
281 for (
int i = 0; i<Hidden*Outdim; i++){
282 fscanf(weights,
"%f", &H_O_Weight[i]);
284 }
else if (line[0] ==
'E'){
286 for (
int i = 0; i<Outdim; i++){
287 fscanf(weights,
"%f", &O_Thresh[i]);
291 else{
edm::LogError(
"EEPi0Discrim")<<
"EndcapPiZeroDiscriminatorAlgo: Not a Net file of Corrupted Net file " << endl;
311 I_SUM =
new float[Hidden];
312 OUT =
new float[Outdim];
314 for(
int k=0;
k<Hidden;
k++) I_SUM[
k]=0.0;
315 for(
int k1=0;k1<Outdim;k1++) OUT[k1]=0.0;
317 for (
int h = 0;
h<Hidden;
h++){
319 for (
int i = 0; i<Indim; i++){
321 I_SUM[
h] += I_H_Weight_all[mij+sel_wfile*Indim*Hidden + barrelstart*Nfiles_EE*EE_Indim*EE_Hidden] * input_var[
i];
323 I_SUM[
h] += H_Thresh_all[
h+sel_wfile*Hidden + barrelstart*Nfiles_EE*EE_Hidden];
324 for (
int o1 = 0;
o1<Outdim;
o1++) {
325 OUT[
o1] += H_O_Weight_all[barrelstart*Nfiles_EE*EE_Outdim*EE_Hidden +
h*Outdim+
o1 + sel_wfile*Outdim*Hidden]*Activation_fun(I_SUM[
h]);
329 for (
int o2 = 0; o2<Outdim; o2++){
330 OUT[o2] += O_Thresh_all[barrelstart*Nfiles_EE*EE_Outdim + o2 + sel_wfile*Outdim];
332 nnout = Activation_fun(OUT[0]);
333 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: getNNoutput :: -> NNout = " << nnout ;
345 return( 1.0 / ( 1.0 +
exp(-2.0*SUM) ) );
359 float pS1_max,
float pS9_max,
float pS25_max,
int EScorr)
361 input_var =
new float[EE_Indim];
363 bool valid_NNinput =
true;
376 for(
int k = 0;
k<11;
k++) {
379 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: Oops!!! Preshower Info for strip : " <<
k <<
" of X plane Do not exists" ;
384 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: Oops!!! Preshower Info for strip : " <<
k <<
" of Y plane Do not exists" ;
406 input_var[
kk] = fabs(vph1[
kk]/0.01);
407 input_var[
kk + 11] = fabs(vph2[
kk]/0.02);
408 if(input_var[
kk] < 0.0001) input_var[
kk] = 0.;
409 if(input_var[
kk + 11] < 0.0001) input_var[
kk + 11] = 0.;
411 input_var[0] = fabs(input_var[0]/2.);
412 input_var[1] = fabs(input_var[1]/2.);
413 input_var[6] = fabs(input_var[6]/2.);
414 input_var[11] = fabs(input_var[11]/2.);
415 input_var[12] = fabs(input_var[12]/2.);
416 input_var[17] = fabs(input_var[17]/2.);
421 input_var[0] -= 0.05;
422 input_var[1] -= 0.035;
423 input_var[2] -= 0.035;
424 input_var[3] -= 0.02;
425 input_var[4] -= 0.015;
426 input_var[5] -= 0.0075;
427 input_var[6] -= 0.035;
428 input_var[7] -= 0.035;
429 input_var[8] -= 0.02;
430 input_var[9] -= 0.015;
431 input_var[10] -= 0.0075;
433 input_var[11] -= 0.05;
434 input_var[12] -= 0.035;
435 input_var[13] -= 0.035;
436 input_var[14] -= 0.02;
437 input_var[15] -= 0.015;
438 input_var[16] -= 0.0075;
439 input_var[17] -= 0.035;
440 input_var[18] -= 0.035;
441 input_var[19] -= 0.02;
442 input_var[20] -= 0.015;
443 input_var[21] -= 0.0075;
445 for(
int kk1=0;kk1<22;kk1++){
446 if(input_var[kk1] < 0 ) input_var[kk1] = 0.0;
451 float ECAL_norm_factor = 500.;
452 if(pS25_max>500&&pS25_max<=1000) ECAL_norm_factor = 1000;
453 if(pS25_max>1000) ECAL_norm_factor = 7000;
455 input_var[22] = pS1_max/ECAL_norm_factor;
456 input_var[23] = pS9_max/ECAL_norm_factor;
457 input_var[24] = pS25_max/ECAL_norm_factor;
459 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: S1/ECAL_norm_factor = " << input_var[22];
460 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: S9/ECAL_norm_factor = " << input_var[23];
461 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: S25/ECAL_norm_factor = " << input_var[24] ;
463 for(
int i=0;i<EE_Indim;i++){
464 if(input_var[i] > 1.0
e+00) {
465 valid_NNinput =
false;
470 LogTrace(
"EcalClusters") <<
" valid_NNinput = " << valid_NNinput ;
473 return valid_NNinput;
485 double m2,
double cee,
double cep,
double cpp,
486 double s4,
double s6,
double ratio,
487 double xcog,
double ycog)
489 input_var =
new float[EB_Indim];
491 double lam, lam1, lam2;
494 input_var[0] = -xcog/s25;
496 input_var[0] = xcog/s25;
499 input_var[1] = cee/0.0004;
502 input_var[2] = cpp/.001;
508 input_var[3] = s1/s9;
509 input_var[8] = s6/s9;
510 input_var[10] = (m2+s1)/s9;
519 input_var[4] = (s9-s1)/(s25-s1);
525 input_var[5] = s4/s25;
531 input_var[6] = -ycog/s25;
533 input_var[6] = ycog/s25;
536 input_var[7] =
ratio;
538 lam=
sqrt((cee -cpp)*(cee -cpp)+4*cep*cep);
539 lam1=(cee + cpp + lam)/2;
540 lam2=(cee + cpp - lam)/2;
545 input_var[9] = lam2/lam1;
548 input_var[11] = (m2+s1)/s4;
563 Layers = EE_Layers; Indim = EE_Indim; Hidden = EE_Hidden; Outdim = EE_Outdim; barrelstart = 0;
568 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo::GetNNoutput :nn_invar_presh = " ;
570 for(
int k1=0;k1<Indim;k1++) {
571 LogTrace(
"EcalClusters") << input_var[k1] <<
" " ;
578 if(EE_Et<25.0) {sel_wfile = 0;}
579 else if(EE_Et>=25.0 && EE_Et<35.0) {sel_wfile = 1;}
580 else if(EE_Et>=35.0 && EE_Et<45.0) {sel_wfile = 2;}
581 else if(EE_Et>=45.0 && EE_Et<55.0) {sel_wfile = 3;}
582 else {sel_wfile = 4;}
584 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: Et_SC = " << EE_Et <<
" and I select Weight file Number = " << sel_wfile ;
587 nnout = getNNoutput(sel_wfile);
589 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: ===================> GetNNOutput : NNout = " << nnout ;
604 Layers = EB_Layers; Indim = EB_Indim; Hidden = EB_Hidden; Outdim = EB_Outdim; barrelstart = 1;
609 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo::GetBarrelNNoutput :nn_invar_presh = " ;
611 for(
int k1=0;k1<Indim;k1++) {
612 LogTrace(
"EcalClusters") << input_var[k1] <<
" " ;
619 if(EB_Et<25.0) {sel_wfile = 0;}
620 else if(EB_Et>=25.0 && EB_Et<35.0) {sel_wfile = 1;}
621 else if(EB_Et>=35.0 && EB_Et<45.0) {sel_wfile = 2;}
622 else if(EB_Et>=45.0 && EB_Et<55.0) {sel_wfile = 3;}
623 else {sel_wfile = 4;}
624 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: E_SC = " << EB_Et <<
" and I select Weight file Number = " << sel_wfile ;
626 nnout = getNNoutput(sel_wfile);
628 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: ===================> GetNNOutput : NNout = " << nnout ;
void findPi0Road(ESDetId strip, EcalPreshowerNavigator &theESNav, int plane, std::vector< ESDetId > &vout)
float GetNNOutput(float EE_Et)
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
void calculateBarrelNNInputVariables(float et, double s1, double s9, double s25, double m2, double cee, double cep, double cpp, double s4, double s6, double ratio, double xcog, double ycog)
float Activation_fun(float SUM)
std::map< DetId, EcalRecHit > RecHitsMap
EndcapPiZeroDiscriminatorAlgo()
void setHome(const T &startingPoint)
set the starting position
std::vector< float > findPreshVector(ESDetId strip, RecHitsMap *rechits_map, CaloSubdetectorTopology *topology_p)
float getNNoutput(int sel_wfile)
T west() const
move the navigator west
T south() const
move the navigator south
T east() const
move the navigator east
void home() const
move the navigator back to the starting point
float GetBarrelNNOutput(float EB_Et)
bool goodPi0Strip(RecHitsMap::iterator candidate_it, ESDetId lastID)
et
define resolution functions of each parameter
void readWeightFile(const char *WFile)
bool calculateNNInputVariables(std::vector< float > &vph1, std::vector< float > &vph2, float pS1_max, float pS9_max, float pS25_max, int EScorr)
T north() const
move the navigator north