CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
genlkupmap.h
Go to the documentation of this file.
2 #include <algorithm> // for "max","min"
3 #include <math.h>
4 #include <iostream>
5 
6 // Function generates a lookup map for a passed-in function (via templated object algoObject,
7 // which must contain method "calcpair" that spits out (x,y) pair from a type float seed.
8 // Each map y-value is separated from the previous value by a programmable fractional error
9 // relative to the previous value.
10 //
11 // Currently this function coded for only monotonically increasing or
12 // decreasing functions...
13 
14 template <class T_algo>
15 void genlkupmap(double smin,
16  double smax,
17  double max_fracerror,
18  double min_sstep,
19  T_algo& algoObject,
20  std::map<double,double>& m_ylookup)
21 {
22  std::pair<double,double> thisxy, lastxy, laststoredxy;
23  std::pair<double,double> minxy = algoObject.calcpair(smin);
24  std::pair<double,double> maxxy = algoObject.calcpair(smax);
25 
26  double slope = maxxy.second - minxy.second;
27  slope = (slope >= 0.0) ? 1.0 : -1.0;
28 
29  double sstep = min_sstep;
30 
31  for (double s=smin; lastxy.first<smax; s += sstep) {
32 
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  }
51  else if ((fracerror > 2*max_fracerror) ||
52  (thisxy.first > smax) ) {
53  if (sstep > min_sstep) {
54  // possibly overstepped the next entry, back up and reduce the step size
55  s -= sstep;
56  sstep = std::max(0.5*sstep, min_sstep);
57 #if 0
58  cout << endl;
59 #endif
60  continue;
61  }
62  else if (lastxy.second == laststoredxy.second) {
63  store_cur_pair = true;
64 
65  // current step size is too big for the max allowed fractional error,
66  // store current value and issue a warning.
67  //
68  edm::LogWarning("HcalPulseContainmentCorrection::genlkupmap") << " fractional error max exceeded";
69  }
70  else {
71  store_prev_pair = true;
72 
73  // re-evaluate current yval with prev yval.
74  fracerror = slope*(thisxy.second - lastxy.second)/ thisxy.second;
75 
76  if (fracerror > 2*max_fracerror) {
77  store_cur_pair = true;
78 
79  // current step size is too big for the max allowed fractional error,
80  // store current value and issue a warning.
81  //
82  edm::LogWarning("HcalPulseContainmentCorrection::genlkupmap") << " fractional error max exceeded";
83  }
84  }
85  }
86  else if ((fracerror < 1.9*max_fracerror) &&
87  (fracchange < 0.1*max_fracerror) &&
88  (thisxy.first < 0.99 * smax) ) {
89  // adapt step size to reduce iterations
90  sstep *= 2.0;
91  }
92 
93  if (thisxy.first > smax)
94  store_cur_pair = true;
95 
96  if (store_prev_pair) {
97  m_ylookup[lastxy.first] = lastxy.second;
98  laststoredxy = lastxy;
99  }
100  if (store_cur_pair) {
101  m_ylookup[thisxy.first] = thisxy.second;
102  laststoredxy = thisxy;
103  }
104 
105  lastxy = thisxy;
106 
107 #if 0
108  sprintf(str, " %c %c",
109  store_cur_pair ? 'C' : ' ',
110  store_prev_pair ? 'P' : ' ');
111  cout << str << endl;
112 #endif
113 
114  }
115 
116 }
117 
118 //======================================================================
119 // Fixed Phase mode amplitude correction factor generation routines:
120 
121 template <class S>
123 public:
124  RecoFCcorFactorAlgo(int num_samples,
125  double fixedphase_ns);
126 
127  std::pair<double,double> calcpair(double);
128 
129 private:
134 };
135 
std::pair< double, double > calcpair(double)
static const double slope[3]
void genlkupmap(double smin, double smax, double max_fracerror, double min_sstep, T_algo &algoObject, std::map< double, double > &m_ylookup)
Definition: genlkupmap.h:15
double integrationwindowns_
Definition: genlkupmap.h:131
const T & max(const T &a, const T &b)
RecoFCcorFactorAlgo(int num_samples, double fixedphase_ns)
perl if(1 lt scalar(@::datatypes))
Definition: edlooper.cc:31
tuple cout
Definition: gather_cfg.py:41
string s
Definition: asciidump.py:422