CMS 3D CMS Logo

genlkupmap.h
Go to the documentation of this file.
3 #include <algorithm> // for "max","min"
4 #include <cmath>
5 #include <iostream>
6 #include <memory>
7 
8 // Function generates a lookup map for a passed-in function (via templated object algoObject,
9 // which must contain method "calcpair" that spits out (x,y) pair from a type float seed.
10 // Each map y-value is separated from the previous value by a programmable fractional error
11 // relative to the previous value.
12 //
13 // Currently this function coded for only monotonically increasing or
14 // decreasing functions...
15 
16 template <class T_algo>
17 void genlkupmap(double smin,
18  double smax,
19  double max_fracerror,
20  double min_sstep,
21  T_algo& algoObject,
22  std::map<double, double>& m_ylookup) {
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 }
109 
110 //======================================================================
111 // Fixed Phase mode amplitude correction factor generation routines:
112 
113 template <class S>
115 public:
116  RecoFCcorFactorAlgo(int num_samples, double fixedphase_ns);
117  std::pair<double, double> calcpair(double);
118 
119 private:
124  const std::unique_ptr<HcalShapeIntegrator> integrator_;
125 };
MessageLogger.h
RecoFCcorFactorAlgo::calcpair
std::pair< double, double > calcpair(double)
genlkupmap
void genlkupmap(double smin, double smax, double max_fracerror, double min_sstep, T_algo &algoObject, std::map< double, double > &m_ylookup)
Definition: genlkupmap.h:17
gather_cfg.cout
cout
Definition: gather_cfg.py:144
if
if(0==first)
Definition: CAHitNtupletGeneratorKernelsImpl.h:48
RecoFCcorFactorAlgo::RecoFCcorFactorAlgo
RecoFCcorFactorAlgo(int num_samples, double fixedphase_ns)
alignCSCRings.s
s
Definition: alignCSCRings.py:92
RecoFCcorFactorAlgo::integrator_
const std::unique_ptr< HcalShapeIntegrator > integrator_
Definition: genlkupmap.h:124
RecoFCcorFactorAlgo::integrationwindowns_
double integrationwindowns_
Definition: genlkupmap.h:121
str
#define str(s)
Definition: TestProcessor.cc:52
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
RecoFCcorFactorAlgo::time0shiftns_
double time0shiftns_
Definition: genlkupmap.h:122
RecoFCcorFactorAlgo::shape_
S shape_
Definition: genlkupmap.h:123
S
Definition: CSCDBL1TPParametersExtended.h:16
RecoFCcorFactorAlgo::fixedphasens_
double fixedphasens_
Definition: genlkupmap.h:120
slope
static const double slope[3]
Definition: CastorTimeSlew.cc:6
RecoFCcorFactorAlgo
Definition: genlkupmap.h:114
HcalShapeIntegrator.h