#include <RecoEcal/EgammaClusterAlgos/interface/EndcapPiZeroDiscriminatorAlgo.h>
Public Types | |
enum | DebugLevel_pi0 { pDEBUG = 0, pINFO = 1, pERROR = 2 } |
typedef std::map< DetId, EcalRecHit > | RecHitsMap |
Public Member Functions | |
float | Activation_fun (float SUM) |
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) |
bool | calculateNNInputVariables (std::vector< float > &vph1, std::vector< float > &vph2, float pS1_max, float pS9_max, float pS25_max) |
EndcapPiZeroDiscriminatorAlgo (double stripEnergyCut, int nStripCut, const std::string &path, DebugLevel_pi0 debugLevel) | |
EndcapPiZeroDiscriminatorAlgo () | |
void | findPi0Road (ESDetId strip, EcalPreshowerNavigator &theESNav, int plane, std::vector< ESDetId > &vout) |
std::vector< float > | findPreshVector (ESDetId strip, RecHitsMap *rechits_map, CaloSubdetectorTopology *topology_p) |
float * | get_input_vector () |
float | GetBarrelNNOutput (float EB_Et) |
float | GetNNOutput (float EE_Et) |
float | getNNoutput (int sel_wfile) |
bool | goodPi0Strip (RecHitsMap::iterator candidate_it, ESDetId lastID) |
void | readWeightFile (const char *WFile) |
~EndcapPiZeroDiscriminatorAlgo () | |
Private Attributes | |
int | barrelstart |
int | debugLevel_ |
int | EB_Hidden |
int | EB_Indim |
int | EB_Layers |
int | EB_Outdim |
int | EE_Hidden |
int | EE_Indim |
int | EE_Layers |
int | EE_Outdim |
float * | H_O_Weight |
std::vector< float > | H_O_Weight_all |
float * | H_Thresh |
std::vector< float > | H_Thresh_all |
int | Hidden |
float * | I_H_Weight |
std::vector< float > | I_H_Weight_all |
int | Indim |
int | inp_var |
float * | input_var |
int | Layers |
int | Nfiles_EB |
int | Nfiles_EE |
float * | O_Thresh |
std::vector< float > | O_Thresh_all |
int | Outdim |
std::string | pathToFiles_ |
int | preshSeededNstr_ |
double | preshStripEnergyCut_ |
RecHitsMap * | rechits_map |
Definition at line 16 of file EndcapPiZeroDiscriminatorAlgo.h.
typedef std::map<DetId, EcalRecHit> EndcapPiZeroDiscriminatorAlgo::RecHitsMap |
Definition at line 22 of file EndcapPiZeroDiscriminatorAlgo.h.
EndcapPiZeroDiscriminatorAlgo::EndcapPiZeroDiscriminatorAlgo | ( | ) | [inline] |
Definition at line 24 of file EndcapPiZeroDiscriminatorAlgo.h.
00024 : 00025 preshStripEnergyCut_(0.), preshSeededNstr_(5), debugLevel_(pINFO), pathToFiles_("") 00026 {}
EndcapPiZeroDiscriminatorAlgo::EndcapPiZeroDiscriminatorAlgo | ( | double | stripEnergyCut, | |
int | nStripCut, | |||
const std::string & | path, | |||
DebugLevel_pi0 | debugLevel | |||
) |
EndcapPiZeroDiscriminatorAlgo::~EndcapPiZeroDiscriminatorAlgo | ( | ) | [inline] |
float EndcapPiZeroDiscriminatorAlgo::Activation_fun | ( | float | SUM | ) |
Definition at line 306 of file EndcapPiZeroDiscriminatorAlgo.cc.
References funct::exp().
Referenced by getNNoutput().
void EndcapPiZeroDiscriminatorAlgo::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 | |||
) |
Definition at line 413 of file EndcapPiZeroDiscriminatorAlgo.cc.
References EB_Indim, input_var, and funct::sqrt().
Referenced by PiZeroDiscriminatorProducer::produce().
00417 { 00418 input_var = new float[EB_Indim]; 00419 00420 double lam, lam1, lam2; 00421 if(xcog < 0.) input_var[0] = -xcog/s25; else input_var[0] = xcog/s25; 00422 if(ycog < 0.) input_var[6] = -ycog/s25; else input_var[6] = ycog/s25; 00423 input_var[1] = cee/0.0004; 00424 if(cpp<.001) input_var[2] = cpp/.001; else input_var[2] = 0.; 00425 if(s9!=0.) { input_var[3] = s1/s9; input_var[8] = s6/s9; input_var[10] = (m2+s1)/s9; } 00426 else { input_var[3] = 0.; input_var[8] = 0.; input_var[10] = 0.; } 00427 if(s25-s1>0.) input_var[4] = (s9-s1)/(s25-s1); else input_var[4] = 0.; 00428 if(s25>0.) input_var[5] = s4/s25; else input_var[5] = 0.; 00429 lam=sqrt((cee -cpp)*(cee -cpp)+4*cep*cep); lam1=(cee + cpp + lam)/2; lam2=(cee + cpp - lam)/2; 00430 if(lam1 == 0) input_var[9] = .0; else input_var[9] = lam2/lam1; 00431 if(s4!=0.) input_var[11] = (m2+s1)/s4; else input_var[11] = 0.; 00432 input_var[7] = ratio; 00433 }
bool EndcapPiZeroDiscriminatorAlgo::calculateNNInputVariables | ( | std::vector< float > & | vph1, | |
std::vector< float > & | vph2, | |||
float | pS1_max, | |||
float | pS9_max, | |||
float | pS25_max | |||
) |
Referenced by PiZeroDiscriminatorProducer::produce().
void EndcapPiZeroDiscriminatorAlgo::findPi0Road | ( | ESDetId | strip, | |
EcalPreshowerNavigator & | theESNav, | |||
int | plane, | |||
std::vector< ESDetId > & | vout | |||
) |
Referenced by findPreshVector().
vector< float > EndcapPiZeroDiscriminatorAlgo::findPreshVector | ( | ESDetId | strip, | |
RecHitsMap * | rechits_map, | |||
CaloSubdetectorTopology * | topology_p | |||
) |
Definition at line 62 of file EndcapPiZeroDiscriminatorAlgo.cc.
References GenMuonPlsPt100GeV_cfg::cout, debugLevel_, lat::endl(), findPi0Road(), goodPi0Strip(), pDEBUG, ESDetId::plane(), CaloNavigator< T >::setHome(), and ESDetId::strip().
Referenced by PreshowerClusterShapeProducer::produce().
00064 { 00065 vector<float> vout_stripE; 00066 00067 vout_stripE.clear(); 00068 00069 vector<ESDetId> road_2d; 00070 road_2d.clear(); 00071 00072 int plane = strip.plane(); 00073 00074 if ( debugLevel_ <= pDEBUG ) { 00075 cout << "findPreshVectors: Preshower Seeded Algorithm - looking for clusters" << "n" 00076 << "findPreshVectors: Preshower is intersected at strip " << strip.strip() << ", at plane " << plane << endl; 00077 } 00078 00079 if ( strip == ESDetId(0) ) { //works in case of no intersected strip found 00080 for(int i=0;i<11;i++) { 00081 vout_stripE.push_back(-100.); 00082 } 00083 } 00084 00085 // Add to the road the central strip 00086 road_2d.push_back(strip); 00087 00088 //Make a navigator, and set it to the strip cell. 00089 EcalPreshowerNavigator navigator(strip, topology_p); 00090 navigator.setHome(strip); 00091 //search for neighbours in the central road 00092 findPi0Road(strip, navigator, plane, road_2d); 00093 if ( debugLevel_ <= pDEBUG ) cout << "findPreshVectors: Total number of strips in the central road: " << road_2d.size() << endl; 00094 00095 // Find the energy of each strip 00096 RecHitsMap::iterator final_strip = rechits_map->end(); 00097 final_strip--; 00098 ESDetId last_stripID = final_strip->first; 00099 00100 float E = 0; 00101 vector<ESDetId>::iterator itID; 00102 for (itID = road_2d.begin(); itID != road_2d.end(); itID++) { 00103 if ( debugLevel_ == pDEBUG ) cout << " findPreshVectors: ID = " << *itID << endl; 00104 RecHitsMap::iterator strip_it = rechits_map->find(*itID); 00105 if(goodPi0Strip(strip_it,last_stripID)) { // continue if strip not found in rechit_map 00106 E = strip_it->second.energy(); 00107 } else E = 0; 00108 vout_stripE.push_back(E); 00109 if ( debugLevel_ == pDEBUG ) cout << " findPreshVectors: E = " << E << endl; 00110 } 00111 00112 return vout_stripE; 00113 00114 }
float* EndcapPiZeroDiscriminatorAlgo::get_input_vector | ( | ) | [inline] |
Definition at line 58 of file EndcapPiZeroDiscriminatorAlgo.h.
Referenced by PiZeroDiscriminatorProducer::produce().
00058 {return input_var;};
float EndcapPiZeroDiscriminatorAlgo::GetBarrelNNOutput | ( | float | EB_Et | ) |
Definition at line 477 of file EndcapPiZeroDiscriminatorAlgo.cc.
References barrelstart, GenMuonPlsPt100GeV_cfg::cout, debugLevel_, EB_Hidden, EB_Indim, EB_Outdim, getNNoutput(), Indim, input_var, Layers, Outdim, and pDEBUG.
Referenced by PiZeroDiscriminatorProducer::produce().
00478 { 00479 00480 Layers = EB_Layers; Indim = EB_Indim; Hidden = EB_Hidden; Outdim = EB_Outdim; barrelstart = 1; 00481 00482 float nnout = -1; 00483 // Print the NN input variables that are related to the ECAL Barrel 00484 // ------------------------------------------------------------------------ 00485 if ( debugLevel_ <= pDEBUG )cout << " EndcapPiZeroDiscriminatorAlgo::GetBarrelNNoutput :nn_invar_presh = " ; 00486 for(int k1=0;k1<Indim;k1++) { 00487 if ( debugLevel_ <= pDEBUG )cout << input_var[k1] << " " ; 00488 } 00489 if ( debugLevel_ <= pDEBUG )cout << 1 << endl; 00490 00491 // select the appropriate Weigth file 00492 int sel_wfile; 00493 if(EB_Et<25.0) {sel_wfile = 0;} 00494 else if(EB_Et>=25.0 && EB_Et<35.0) {sel_wfile = 1;} 00495 else if(EB_Et>=35.0 && EB_Et<45.0) {sel_wfile = 2;} 00496 else if(EB_Et>=45.0 && EB_Et<55.0) {sel_wfile = 3;} 00497 else {sel_wfile = 4;} 00498 00499 if ( debugLevel_ <= pDEBUG ) { 00500 cout << " E_SC = " << EB_Et << " and I select Weight file Number = " << sel_wfile << endl; 00501 } 00502 00503 nnout = getNNoutput(sel_wfile); // calculate the nnoutput for the given ECAL object 00504 if ( debugLevel_ <= pDEBUG ) cout << "===================> GetNNOutput : NNout = " << nnout << endl; 00505 00506 return nnout; 00507 }
float EndcapPiZeroDiscriminatorAlgo::GetNNOutput | ( | float | EE_Et | ) |
Definition at line 441 of file EndcapPiZeroDiscriminatorAlgo.cc.
References barrelstart, GenMuonPlsPt100GeV_cfg::cout, debugLevel_, EE_Hidden, EE_Outdim, getNNoutput(), Indim, input_var, Layers, Outdim, and pDEBUG.
Referenced by PiZeroDiscriminatorProducer::produce().
00442 { 00443 Layers = EE_Layers; Indim = EE_Indim; Hidden = EE_Hidden; Outdim = EE_Outdim; barrelstart = 0; 00444 00445 float nnout = -1; 00446 // Print the NN input variables that are related to the Preshower + ECAL 00447 // ------------------------------------------------------------------------ 00448 if ( debugLevel_ <= pDEBUG )cout << " EndcapPiZeroDiscriminatorAlgo::GetNNoutput :nn_invar_presh = " ; 00449 for(int k1=0;k1<Indim;k1++) { 00450 if ( debugLevel_ <= pDEBUG )cout << input_var[k1] << " " ; 00451 } 00452 if ( debugLevel_ <= pDEBUG )cout << endl; 00453 00454 // select the appropriate Weigth file 00455 int sel_wfile; 00456 if(EE_Et<25.0) {sel_wfile = 0;} 00457 else if(EE_Et>=25.0 && EE_Et<35.0) {sel_wfile = 1;} 00458 else if(EE_Et>=35.0 && EE_Et<45.0) {sel_wfile = 2;} 00459 else if(EE_Et>=45.0 && EE_Et<55.0) {sel_wfile = 3;} 00460 else {sel_wfile = 4;} 00461 00462 if ( debugLevel_ <= pDEBUG ) { 00463 cout << " Et_SC = " << EE_Et << " and I select Weight file Number = " << sel_wfile << endl; 00464 } 00465 00466 nnout = getNNoutput(sel_wfile); // calculate the nnoutput for the given ECAL object 00467 if ( debugLevel_ <= pDEBUG ) cout << "===================> GetNNOutput : NNout = " << nnout << endl; 00468 return nnout; 00469 }
float EndcapPiZeroDiscriminatorAlgo::getNNoutput | ( | int | sel_wfile | ) |
Definition at line 266 of file EndcapPiZeroDiscriminatorAlgo.cc.
References Activation_fun(), barrelstart, GenMuonPlsPt100GeV_cfg::cout, debugLevel_, EE_Hidden, EE_Indim, EE_Outdim, h, H_O_Weight_all, H_Thresh_all, I_H_Weight_all, Indim, input_var, k, o1, o2, O_Thresh_all, OUT, Outdim, and pDEBUG.
Referenced by GetBarrelNNOutput(), and GetNNOutput().
00267 { 00268 float* I_SUM; 00269 float* OUT; 00270 float nnout=0.0; 00271 int mij; 00272 00273 I_SUM = new float[Hidden]; 00274 OUT = new float[Outdim]; 00275 00276 for(int k=0;k<Hidden;k++) I_SUM[k]=0.0; 00277 for(int k1=0;k1<Outdim;k1++) OUT[k1]=0.0; 00278 00279 for (int h = 0; h<Hidden; h++){ 00280 mij = h - Hidden; 00281 for (int i = 0; i<Indim; i++){ 00282 mij = mij + Hidden; 00283 I_SUM[h] += I_H_Weight_all[mij+sel_wfile*Indim*Hidden + barrelstart*Nfiles_EE*EE_Indim*EE_Hidden] * input_var[i]; 00284 } 00285 I_SUM[h] += H_Thresh_all[h+sel_wfile*Hidden + barrelstart*Nfiles_EE*EE_Hidden]; 00286 for (int o1 = 0; o1<Outdim; o1++) { 00287 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]); 00288 00289 } 00290 } 00291 for (int o2 = 0; o2<Outdim; o2++){ 00292 OUT[o2] += O_Thresh_all[barrelstart*Nfiles_EE*EE_Outdim + o2 + sel_wfile*Outdim]; 00293 } 00294 nnout = Activation_fun(OUT[0]); 00295 00296 if ( debugLevel_ <= pDEBUG ) cout << "getNNoutput :: -> NNout = " << nnout << endl; 00297 00298 delete I_SUM; 00299 delete OUT; 00300 delete input_var; 00301 00302 return (nnout); 00303 }
bool EndcapPiZeroDiscriminatorAlgo::goodPi0Strip | ( | RecHitsMap::iterator | candidate_it, | |
ESDetId | lastID | |||
) |
Definition at line 117 of file EndcapPiZeroDiscriminatorAlgo.cc.
References GenMuonPlsPt100GeV_cfg::cout, debugLevel_, lat::endl(), pDEBUG, and preshStripEnergyCut_.
Referenced by findPreshVector().
00118 { 00119 RecHitsMap::iterator candidate_tmp = candidate_it; 00120 candidate_tmp--; 00121 if ( debugLevel_ == pDEBUG ) { 00122 if (candidate_tmp->first == lastID ) 00123 cout << " goodPi0Strip No such a strip in rechits_map " << endl; 00124 if (candidate_it->second.energy() <= preshStripEnergyCut_) 00125 cout << " goodPi0Strip Strip energy " << candidate_it->second.energy() <<" is below threshold " << endl; 00126 } 00127 // crystal should not be included... 00128 if ( (candidate_tmp->first == lastID ) || // ...if it corresponds to a hit 00129 (candidate_it->second.energy() <= preshStripEnergyCut_ ) ) // ...if it has a negative or zero energy 00130 { 00131 return false; 00132 } 00133 00134 return true; 00135 }
void EndcapPiZeroDiscriminatorAlgo::readWeightFile | ( | const char * | WFile | ) |
Definition at line 202 of file EndcapPiZeroDiscriminatorAlgo.cc.
References GenMuonPlsPt100GeV_cfg::cout, debugLevel_, H_O_Weight, H_Thresh, I_H_Weight, Indim, inp_var, j, Layers, parsecf::pyparsing::line(), O_Thresh, Outdim, pDEBUG, and weights.
00202 { 00203 FILE *weights; 00204 00205 char *line; 00206 line = new char[80]; 00207 00208 bool checkinit=false; 00209 // Open the weights file, generated by jetnet, and read 00210 // in the nodes and weights 00211 //******************************************************* 00212 weights = fopen(Weights_file, "r"); 00213 if ( debugLevel_ <= pDEBUG ) cout << " I opeded the Weights file = " << Weights_file << endl; 00214 00215 while( !feof(weights) ){ 00216 fscanf(weights, "%s", line); 00217 if (line[0] == 'A') { //Read in ANN nodes: Layers, input , Hidden, Output 00218 fscanf(weights, "%d", &Layers); // # of NN Layers used 00219 fscanf(weights, "%d", &Indim); // # of Inputs actually used 00220 fscanf(weights, "%d", &Hidden); // # of hidden nodes 00221 fscanf(weights, "%d", &Outdim); // # of output nodes 00222 00223 inp_var = Indim + 1; 00224 00225 I_H_Weight = new float[Indim*Hidden]; 00226 H_Thresh = new float[Hidden]; 00227 H_O_Weight = new float[Hidden*Outdim]; 00228 O_Thresh = new float[Outdim]; 00229 checkinit=true; 00230 }else if (line[0] == 'B') { // read in weights between hidden and intput nodes 00231 assert(checkinit); 00232 for (int i = 0; i<Indim; i++){ 00233 for (int j = 0; j<Hidden; j++){ 00234 fscanf(weights, "%f", &I_H_Weight[i*Hidden+j]); 00235 } 00236 } 00237 }else if (line[0] == 'C'){ // Read in the thresholds for hidden nodes 00238 assert(checkinit); 00239 for (int i = 0; i<Hidden; i++){ 00240 fscanf(weights, "%f", &H_Thresh[i]); 00241 } 00242 }else if (line[0] == 'D'){ // read in weights between hidden and output nodes 00243 assert(checkinit); 00244 for (int i = 0; i<Hidden*Outdim; i++){ 00245 fscanf(weights, "%f", &H_O_Weight[i]); 00246 } 00247 }else if (line[0] == 'E'){ // read in the threshold for the output nodes 00248 assert(checkinit); 00249 for (int i = 0; i<Outdim; i++){ 00250 fscanf(weights, "%f", &O_Thresh[i]); 00251 00252 } 00253 } 00254 else{cout << "Not a Net file of Corrupted Net file " << endl; 00255 } 00256 } 00257 fclose(weights); 00258 }
Definition at line 67 of file EndcapPiZeroDiscriminatorAlgo.h.
Referenced by GetBarrelNNOutput(), getNNoutput(), and GetNNOutput().
Definition at line 64 of file EndcapPiZeroDiscriminatorAlgo.h.
Referenced by findPreshVector(), GetBarrelNNOutput(), getNNoutput(), GetNNOutput(), goodPi0Strip(), and readWeightFile().
int EndcapPiZeroDiscriminatorAlgo::EB_Hidden [private] |
int EndcapPiZeroDiscriminatorAlgo::EB_Indim [private] |
Definition at line 74 of file EndcapPiZeroDiscriminatorAlgo.h.
Referenced by calculateBarrelNNInputVariables(), and GetBarrelNNOutput().
int EndcapPiZeroDiscriminatorAlgo::EB_Layers [private] |
Definition at line 74 of file EndcapPiZeroDiscriminatorAlgo.h.
int EndcapPiZeroDiscriminatorAlgo::EB_Outdim [private] |
int EndcapPiZeroDiscriminatorAlgo::EE_Hidden [private] |
Definition at line 73 of file EndcapPiZeroDiscriminatorAlgo.h.
Referenced by getNNoutput(), and GetNNOutput().
int EndcapPiZeroDiscriminatorAlgo::EE_Indim [private] |
int EndcapPiZeroDiscriminatorAlgo::EE_Layers [private] |
Definition at line 73 of file EndcapPiZeroDiscriminatorAlgo.h.
int EndcapPiZeroDiscriminatorAlgo::EE_Outdim [private] |
Definition at line 73 of file EndcapPiZeroDiscriminatorAlgo.h.
Referenced by getNNoutput(), and GetNNOutput().
float* EndcapPiZeroDiscriminatorAlgo::H_O_Weight [private] |
std::vector<float> EndcapPiZeroDiscriminatorAlgo::H_O_Weight_all [private] |
float* EndcapPiZeroDiscriminatorAlgo::H_Thresh [private] |
std::vector<float> EndcapPiZeroDiscriminatorAlgo::H_Thresh_all [private] |
int EndcapPiZeroDiscriminatorAlgo::Hidden [private] |
Definition at line 72 of file EndcapPiZeroDiscriminatorAlgo.h.
float* EndcapPiZeroDiscriminatorAlgo::I_H_Weight [private] |
std::vector<float> EndcapPiZeroDiscriminatorAlgo::I_H_Weight_all [private] |
int EndcapPiZeroDiscriminatorAlgo::Indim [private] |
Definition at line 72 of file EndcapPiZeroDiscriminatorAlgo.h.
Referenced by GetBarrelNNOutput(), getNNoutput(), GetNNOutput(), and readWeightFile().
int EndcapPiZeroDiscriminatorAlgo::inp_var [private] |
float* EndcapPiZeroDiscriminatorAlgo::input_var [private] |
Definition at line 86 of file EndcapPiZeroDiscriminatorAlgo.h.
Referenced by calculateBarrelNNInputVariables(), GetBarrelNNOutput(), getNNoutput(), and GetNNOutput().
int EndcapPiZeroDiscriminatorAlgo::Layers [private] |
Definition at line 72 of file EndcapPiZeroDiscriminatorAlgo.h.
Referenced by GetBarrelNNOutput(), GetNNOutput(), and readWeightFile().
int EndcapPiZeroDiscriminatorAlgo::Nfiles_EB [private] |
Definition at line 69 of file EndcapPiZeroDiscriminatorAlgo.h.
int EndcapPiZeroDiscriminatorAlgo::Nfiles_EE [private] |
Definition at line 70 of file EndcapPiZeroDiscriminatorAlgo.h.
float* EndcapPiZeroDiscriminatorAlgo::O_Thresh [private] |
std::vector<float> EndcapPiZeroDiscriminatorAlgo::O_Thresh_all [private] |
int EndcapPiZeroDiscriminatorAlgo::Outdim [private] |
Definition at line 72 of file EndcapPiZeroDiscriminatorAlgo.h.
Referenced by GetBarrelNNOutput(), getNNoutput(), GetNNOutput(), and readWeightFile().
std::string EndcapPiZeroDiscriminatorAlgo::pathToFiles_ [private] |
Definition at line 94 of file EndcapPiZeroDiscriminatorAlgo.h.
Definition at line 63 of file EndcapPiZeroDiscriminatorAlgo.h.
double EndcapPiZeroDiscriminatorAlgo::preshStripEnergyCut_ [private] |
Definition at line 91 of file EndcapPiZeroDiscriminatorAlgo.h.