CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Functions
genlkupmap.h File Reference
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include <algorithm>
#include <math.h>
#include <iostream>

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

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 15 of file genlkupmap.h.

References gather_cfg::cout, if(), max(), asciidump::s, and slope.

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 }
static const double slope[3]
const T & max(const T &a, const T &b)
perl if(1 lt scalar(@::datatypes))
Definition: edlooper.cc:31
tuple cout
Definition: gather_cfg.py:41
string s
Definition: asciidump.py:422