CMS 3D CMS Logo

Classes | Functions
genlkupmap.h File Reference
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "CalibCalorimetry/HcalAlgos/interface/HcalShapeIntegrator.h"
#include <algorithm>
#include <cmath>
#include <iostream>
#include <memory>

Go to the source code of this file.

Classes

class  RecoFCcorFactorAlgo< S >
 

Functions

template<class T_algo >
void genlkupmap (double smin, double smax, double max_fracerror, double min_sstep, T_algo &algoObject, std::map< double, double > &m_ylookup)
 

Function Documentation

◆ genlkupmap()

template<class T_algo >
void genlkupmap ( double  smin,
double  smax,
double  max_fracerror,
double  min_sstep,
T_algo &  algoObject,
std::map< double, double > &  m_ylookup 
)

Definition at line 17 of file genlkupmap.h.

References gather_cfg::cout, caHitNtupletGeneratorKernels::if(), SiStripPI::max, alignCSCRings::s, slope, and str.

22  {
23  std::pair<double, double> thisxy, lastxy, laststoredxy;
24  std::pair<double, double> minxy = algoObject.calcpair(smin);
25  std::pair<double, double> maxxy = algoObject.calcpair(smax);
26 
27  double slope = maxxy.second - minxy.second;
28  slope = (slope >= 0.0) ? 1.0 : -1.0;
29 
30  double sstep = min_sstep;
31 
32  for (double s = smin; lastxy.first < smax; s += sstep) {
33  thisxy = algoObject.calcpair(s);
34 
35  double fracerror = slope * (thisxy.second - laststoredxy.second) / thisxy.second;
36  double fracchange = slope * (thisxy.second - lastxy.second) / thisxy.second;
37 
38  bool store_cur_pair = false;
39  bool store_prev_pair = false;
40 
41 #if 0
42  char str[80];
43  sprintf(str, "%7.1f %7.1f (%8.3f %8.4f) %8.5f %8.5f",
44  s, sstep, thisxy.first, thisxy.second, fracerror, fracchange);
45  cout << str;
46 #endif
47 
48  if (s == smin) {
49  store_cur_pair = true;
50  } else if ((fracerror > 2 * max_fracerror) || (thisxy.first > smax)) {
51  if (sstep > min_sstep) {
52  // possibly overstepped the next entry, back up and reduce the step size
53  s -= sstep;
54  sstep = std::max(0.5 * sstep, min_sstep);
55 #if 0
56  cout << endl;
57 #endif
58  continue;
59  } else if (lastxy.second == laststoredxy.second) {
60  store_cur_pair = true;
61 
62  // current step size is too big for the max allowed fractional error,
63  // store current value and issue a warning.
64  //
65  // edm::LogWarning("HcalPulseContainmentCorrection::genlkupmap") << " fractional error max exceeded";
66  } else {
67  store_prev_pair = true;
68 
69  // re-evaluate current yval with prev yval.
70  fracerror = slope * (thisxy.second - lastxy.second) / thisxy.second;
71 
72  if (fracerror > 2 * max_fracerror) {
73  store_cur_pair = true;
74 
75  // current step size is too big for the max allowed fractional error,
76  // store current value and issue a warning.
77  //
78  // edm::LogWarning("HcalPulseContainmentCorrection::genlkupmap") << " fractional error max exceeded";
79  }
80  }
81  } else if ((fracerror < 1.9 * max_fracerror) && (fracchange < 0.1 * max_fracerror) &&
82  (thisxy.first < 0.99 * smax)) {
83  // adapt step size to reduce iterations
84  sstep *= 2.0;
85  }
86 
87  if (thisxy.first > smax)
88  store_cur_pair = true;
89 
90  if (store_prev_pair) {
91  m_ylookup[lastxy.first] = lastxy.second;
92  laststoredxy = lastxy;
93  }
94  if (store_cur_pair) {
95  m_ylookup[thisxy.first] = thisxy.second;
96  laststoredxy = thisxy;
97  }
98 
99  lastxy = thisxy;
100 
101 #if 0
102  sprintf(str, " %c %c",
103  store_cur_pair ? 'C' : ' ',
104  store_prev_pair ? 'P' : ' ');
105  cout << str << endl;
106 #endif
107  }
108 }
static const double slope[3]
#define str(s)