18 : preshStripEnergyCut_(stripEnergyCut), preshSeededNstr_(nStripCut) {
20 constexpr std::array<char const*, Nfiles_EE> file_pt{{
"20",
"30",
"40",
"50",
"60"}};
21 constexpr std::array<char const*, 5> file_barrel_pt{{
"20",
"30",
"40",
"50",
"60"}};
23 for (
auto ptName : file_pt) {
24 string nn_paterns_file =
"endcapPiZeroDiscriminatorWeights_et";
25 nn_paterns_file += ptName;
26 nn_paterns_file +=
".wts";
28 readWeightFile(WFile.fullPath().c_str(), EE_Layers, EE_Indim, EE_Hidden, EE_Outdim);
31 for (
auto ptName : file_barrel_pt) {
32 string nn_paterns_file =
"barrelPiZeroDiscriminatorWeights_et";
33 nn_paterns_file += ptName;
34 nn_paterns_file +=
".wts";
36 readWeightFile(WFile.fullPath().c_str(), EB_Layers, EB_Indim, EB_Hidden, EB_Outdim);
43 vector<float> vout_stripE;
46 if (rechits_map->empty()) {
47 edm::LogWarning(
"EndcapPiZeroDiscriminatorAlgo") <<
"RecHitsMap has size 0.";
53 vector<ESDetId> road_2d;
56 int plane = strip.
plane();
59 <<
"EndcapPiZeroDiscriminatorAlgo: findPreshVectors: Preshower Seeded Algorithm - looking for clusters" 61 <<
"findPreshVectors: Preshower is intersected at strip " << strip.
strip() <<
", at plane " << plane;
64 for (
int i = 0;
i < 11;
i++) {
65 vout_stripE.push_back(-100.);
70 road_2d.push_back(strip);
76 findPi0Road(strip, navigator, plane, road_2d);
79 <<
"EndcapPiZeroDiscriminatorAlgo:findPreshVectors: Total number of strips in the central road: " 83 RecHitsMap::iterator final_strip = rechits_map->end();
87 ESDetId last_stripID = final_strip->first;
89 vector<ESDetId>::iterator itID;
90 for (itID = road_2d.begin(); itID != road_2d.end(); itID++) {
91 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPreshVectors: ID = " << *itID;
94 RecHitsMap::iterator strip_it = rechits_map->find(*itID);
95 if (goodPi0Strip(strip_it, last_stripID)) {
96 E = strip_it->second.energy();
98 vout_stripE.push_back(E);
99 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPreshVectors: E = " << E;
105 vector<float> vout_ElevenStrips_Energy;
106 for (
int i = 0;
i < 11;
i++) {
107 vout_ElevenStrips_Energy.push_back(0.);
110 for (
unsigned int i = 0;
i < vout_stripE.size();
i++) {
111 vout_ElevenStrips_Energy[
i] = vout_stripE.at(
i);
115 return vout_ElevenStrips_Energy;
121 RecHitsMap::iterator candidate_tmp = candidate_it;
125 if (candidate_tmp->first == lastID)
127 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: goodPi0Strip No such a strip in rechits_map ";
129 }
else if (candidate_it->second.energy() <= preshStripEnergyCut_)
131 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: goodPi0Strip Strip energy " 132 << candidate_it->second.energy() <<
" is below threshold ";
143 vector<ESDetId>& vout) {
148 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPi0Road: starts from strip " <<
strip;
153 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPi0Road: Go to the East ";
156 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPi0Road: East: " << n_east <<
" current strip is " 159 vout.push_back(next);
161 if (n_east == preshSeededNstr_)
166 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPi0Road: Go to the West ";
170 LogTrace(
"EcalClusters") <<
"findPi0Road: West: " << n_west <<
" current strip is " <<
next;
172 vout.push_back(next);
174 if (n_west == preshSeededNstr_)
178 <<
"EndcapPiZeroDiscriminatorAlgo: findPi0Road: Total number of strips found in the road at 1-st plane is " 181 }
else if (plane == 2) {
184 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPi0Road: Go to the North ";
187 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPi0Road: North: " << n_north
188 <<
" current strip is " <<
next;
190 vout.push_back(next);
192 if (n_north == preshSeededNstr_)
197 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPi0Road: Go to the South ";
201 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: findPi0Road: South: " << n_south
202 <<
" current strip is " <<
next;
204 vout.push_back(next);
206 if (n_south == preshSeededNstr_)
210 <<
"EndcapPiZeroDiscriminatorAlgo: findPi0Road: Total number of strips found in the road at 2-nd plane is " 211 << n_south + n_north;
215 <<
"EndcapPiZeroDiscriminatorAlgo: findPi0Road: Wrong plane number, null cluster will be returned! ";
228 const char* Weights_file,
int& Layers,
int& Indim,
int& Hidden,
int& Outdim) {
233 bool checkinit =
false;
237 weights = fopen(Weights_file,
"r");
238 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: I opeded the Weights file = " << Weights_file;
239 if (weights ==
nullptr) {
240 throw cms::Exception(
"MissingWeightFile") <<
"Could not open the weights file: " << Weights_file;
243 const auto I_H_W_offset = I_H_Weight_all.size();
244 const auto H_O_W_offset = H_O_Weight_all.size();
245 const auto H_T_offset = H_Thresh_all.size();
246 const auto O_T_offset = O_Thresh_all.size();
248 while (!feof(weights)) {
249 fscanf(weights,
"%s", line);
250 if (line[0] ==
'A') {
251 fscanf(weights,
"%d", &Layers);
252 fscanf(weights,
"%d", &Indim);
253 fscanf(weights,
"%d", &Hidden);
254 fscanf(weights,
"%d", &Outdim);
256 I_H_Weight_all.resize(I_H_W_offset + Indim * Hidden);
257 H_Thresh_all.resize(H_T_offset + Hidden);
258 H_O_Weight_all.resize(H_O_W_offset + Hidden * Outdim);
259 O_Thresh_all.resize(O_T_offset + Outdim);
261 }
else if (line[0] ==
'B') {
263 for (
int i = 0;
i < Indim;
i++) {
264 for (
int j = 0;
j < Hidden;
j++) {
265 fscanf(weights,
"%f", &I_H_Weight_all[I_H_W_offset +
i * Hidden +
j]);
268 }
else if (line[0] ==
'C') {
270 for (
int i = 0;
i < Hidden;
i++) {
271 fscanf(weights,
"%f", &H_Thresh_all[H_T_offset +
i]);
273 }
else if (line[0] ==
'D') {
275 for (
int i = 0;
i < Hidden * Outdim;
i++) {
276 fscanf(weights,
"%f", &H_O_Weight_all[H_O_W_offset +
i]);
278 }
else if (line[0] ==
'E') {
280 for (
int i = 0;
i < Outdim;
i++) {
281 fscanf(weights,
"%f", &O_Thresh_all[O_T_offset +
i]);
284 edm::LogError(
"EEPi0Discrim") <<
"EndcapPiZeroDiscriminatorAlgo: Not a Net file of Corrupted Net file " << endl;
297 int sel_wfile,
int Layers,
int Indim,
int Hidden,
int Outdim,
int barrelstart)
const {
301 std::vector<float> I_SUM(
size_t(Hidden), 0.0);
302 std::vector<float>
OUT(
size_t(Outdim), 0.0);
304 for (
int h = 0;
h < Hidden;
h++) {
306 for (
int i = 0;
i < Indim;
i++) {
308 I_SUM[
h] += I_H_Weight_all[mij + sel_wfile * Indim * Hidden + barrelstart * Nfiles_EE * EE_Indim * EE_Hidden] *
311 I_SUM[
h] += H_Thresh_all[
h + sel_wfile * Hidden + barrelstart * Nfiles_EE * EE_Hidden];
312 for (
int o1 = 0;
o1 < Outdim;
o1++) {
313 OUT[
o1] += H_O_Weight_all[barrelstart * Nfiles_EE * EE_Outdim * EE_Hidden +
h * Outdim +
o1 +
314 sel_wfile * Outdim * Hidden] *
315 Activation_fun(I_SUM[
h]);
318 for (
int o2 = 0; o2 < Outdim; o2++) {
319 OUT[o2] += O_Thresh_all[barrelstart * Nfiles_EE * EE_Outdim + o2 + sel_wfile * Outdim];
321 nnout = Activation_fun(OUT[0]);
322 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: getNNoutput :: -> NNout = " << nnout;
340 vector<float>& vph1, vector<float>& vph2,
float pS1_max,
float pS9_max,
float pS25_max,
int EScorr) {
342 bool valid_NNinput =
true;
355 for (
int k = 0;
k < 11;
k++) {
357 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: Oops!!! Preshower Info for strip : " <<
k 358 <<
" of X plane Do not exists";
363 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: Oops!!! Preshower Info for strip : " <<
k 364 <<
" of Y plane Do not exists";
384 for (
int kk = 0;
kk < 11;
kk++) {
426 for (
int kk1 = 0; kk1 < 22; kk1++) {
433 float ECAL_norm_factor = 500.;
434 if (pS25_max > 500 && pS25_max <= 1000)
435 ECAL_norm_factor = 1000;
437 ECAL_norm_factor = 7000;
439 input_var[22] = pS1_max / ECAL_norm_factor;
440 input_var[23] = pS9_max / ECAL_norm_factor;
441 input_var[24] = pS25_max / ECAL_norm_factor;
443 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: S1/ECAL_norm_factor = " <<
input_var[22];
444 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: S9/ECAL_norm_factor = " <<
input_var[23];
445 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: S25/ECAL_norm_factor = " <<
input_var[24];
447 for (
int i = 0;
i < EE_Indim;
i++) {
449 valid_NNinput =
false;
454 LogTrace(
"EcalClusters") <<
" valid_NNinput = " << valid_NNinput;
456 return valid_NNinput;
481 double lam, lam1, lam2;
527 lam =
sqrt((cee - cpp) * (cee - cpp) + 4 * cep * cep);
528 lam1 = (cee + cpp + lam) / 2;
529 lam2 = (cee + cpp - lam) / 2;
552 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo::GetNNoutput :nn_invar_presh = ";
554 LogTrace(
"EcalClusters").log([&](
auto& lt) {
565 }
else if (EE_Et >= 25.0 && EE_Et < 35.0) {
567 }
else if (EE_Et >= 35.0 && EE_Et < 45.0) {
569 }
else if (EE_Et >= 45.0 && EE_Et < 55.0) {
575 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: Et_SC = " << EE_Et
576 <<
" and I select Weight file Number = " << sel_wfile;
579 sel_wfile, EE_Layers, EE_Indim, EE_Hidden, EE_Outdim, 0);
581 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: ===================> GetNNOutput : NNout = " << nnout;
595 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo::GetBarrelNNoutput :nn_invar_presh = ";
597 LogTrace(
"EcalCluster").log([&](
auto& lt) {
608 }
else if (EB_Et >= 25.0 && EB_Et < 35.0) {
610 }
else if (EB_Et >= 35.0 && EB_Et < 45.0) {
612 }
else if (EB_Et >= 45.0 && EB_Et < 55.0) {
617 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: E_SC = " << EB_Et
618 <<
" and I select Weight file Number = " << sel_wfile;
621 sel_wfile, EB_Layers, EB_Indim, EB_Hidden, EB_Outdim, 1);
623 LogTrace(
"EcalClusters") <<
"EndcapPiZeroDiscriminatorAlgo: ===================> GetNNOutput : NNout = " << nnout;
void findPi0Road(ESDetId strip, EcalPreshowerNavigator &theESNav, int plane, std::vector< ESDetId > &vout)
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
float GetNNOutput(float EE_Et)
float Activation_fun(float SUM) const
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 getNNoutput(int sel_wfile, int Layers, int Indim, int Hidden, int Outdim, int barrelstart) const
std::map< DetId, EcalRecHit > RecHitsMap
EndcapPiZeroDiscriminatorAlgo()
void readWeightFile(const char *WFile, int &Layers, int &Indim, int &Hidden, int &Outdim)
void setHome(const T &startingPoint)
set the starting position
std::vector< float > findPreshVector(ESDetId strip, RecHitsMap *rechits_map, CaloSubdetectorTopology *topology_p)
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)
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