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.
3 #include <algorithm> // for "max","min"
4 #include <cmath>
5 #include <iostream>
6 #include <boost/scoped_ptr.hpp>
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 {
24  std::pair<double,double> thisxy, lastxy, laststoredxy;
25  std::pair<double,double> minxy = algoObject.calcpair(smin);
26  std::pair<double,double> maxxy = algoObject.calcpair(smax);
27 
28  double slope = maxxy.second - minxy.second;
29  slope = (slope >= 0.0) ? 1.0 : -1.0;
30 
31  double sstep = min_sstep;
32 
33  for (double s=smin; lastxy.first<smax; s += sstep) {
34 
35  thisxy = algoObject.calcpair(s);
36 
37  double fracerror = slope*(thisxy.second - laststoredxy.second)/ thisxy.second;
38  double fracchange = slope*(thisxy.second - lastxy.second)/ thisxy.second;
39 
40  bool store_cur_pair = false;
41  bool store_prev_pair = false;
42 
43 #if 0
44  char str[80];
45  sprintf(str, "%7.1f %7.1f (%8.3f %8.4f) %8.5f %8.5f",
46  s, sstep, thisxy.first, thisxy.second, fracerror, fracchange);
47  cout << str;
48 #endif
49 
50  if (s == smin) {
51  store_cur_pair = true;
52  }
53  else if ((fracerror > 2*max_fracerror) ||
54  (thisxy.first > smax) ) {
55  if (sstep > min_sstep) {
56  // possibly overstepped the next entry, back up and reduce the step size
57  s -= sstep;
58  sstep = std::max(0.5*sstep, min_sstep);
59 #if 0
60  cout << endl;
61 #endif
62  continue;
63  }
64  else if (lastxy.second == laststoredxy.second) {
65  store_cur_pair = true;
66 
67  // current step size is too big for the max allowed fractional error,
68  // store current value and issue a warning.
69  //
70  // edm::LogWarning("HcalPulseContainmentCorrection::genlkupmap") << " fractional error max exceeded";
71  }
72  else {
73  store_prev_pair = true;
74 
75  // re-evaluate current yval with prev yval.
76  fracerror = slope*(thisxy.second - lastxy.second)/ thisxy.second;
77 
78  if (fracerror > 2*max_fracerror) {
79  store_cur_pair = true;
80 
81  // current step size is too big for the max allowed fractional error,
82  // store current value and issue a warning.
83  //
84  // edm::LogWarning("HcalPulseContainmentCorrection::genlkupmap") << " fractional error max exceeded";
85  }
86  }
87  }
88  else if ((fracerror < 1.9*max_fracerror) &&
89  (fracchange < 0.1*max_fracerror) &&
90  (thisxy.first < 0.99 * smax) ) {
91  // adapt step size to reduce iterations
92  sstep *= 2.0;
93  }
94 
95  if (thisxy.first > smax)
96  store_cur_pair = true;
97 
98  if (store_prev_pair) {
99  m_ylookup[lastxy.first] = lastxy.second;
100  laststoredxy = lastxy;
101  }
102  if (store_cur_pair) {
103  m_ylookup[thisxy.first] = thisxy.second;
104  laststoredxy = thisxy;
105  }
106 
107  lastxy = thisxy;
108 
109 #if 0
110  sprintf(str, " %c %c",
111  store_cur_pair ? 'C' : ' ',
112  store_prev_pair ? 'P' : ' ');
113  cout << str << endl;
114 #endif
115 
116  }
117 
118 }
119 
120 //======================================================================
121 // Fixed Phase mode amplitude correction factor generation routines:
122 
123 template <class S>
125 public:
126  RecoFCcorFactorAlgo(int num_samples,
127  double fixedphase_ns);
128  std::pair<double,double> calcpair(double);
129 private:
134  const boost::scoped_ptr<HcalShapeIntegrator> integrator_;
135 };
136 
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:17
double integrationwindowns_
Definition: genlkupmap.h:131
const boost::scoped_ptr< HcalShapeIntegrator > integrator_
Definition: genlkupmap.h:134
const T & max(const T &a, const T &b)
RecoFCcorFactorAlgo(int num_samples, double fixedphase_ns)
if(dp >Float(M_PI)) dp-
tuple cout
Definition: gather_cfg.py:121