CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CastorPulseContainmentCorrection.cc
Go to the documentation of this file.
5 #include <algorithm> // for "max","min"
6 #include <math.h>
7 #include <iostream>
8 
10 
11 
12 template<>
14 {
15  fixedphasens_ = fixedphase_ns;
16  CastorPulseShapes shapes;
17  shape_=shapes.castorShape();
18  const int binsize_ns = 25;
19 
20  // First set up controlling parameters for calculating the correction factor:
21  // Integration window size...
22  //
23  integrationwindowns_ = (double)(binsize_ns*num_samples);
24 
25  // First find the point at which time bin "1" exceeds time bin "0",
26  // and call that point "time 0".
27  //
28  for (int shift_ns=0; shift_ns<binsize_ns; shift_ns++) {
29 
30  // Digitize by integrating to find all time sample
31  // bin values for this shift.
32  //
33  double tmin = -(double)shift_ns;
34  double bin0val = (double)shape_.integrate(tmin, tmin+binsize_ns);
35  double bin1val = (double)shape_.integrate(tmin+binsize_ns, tmin+2*binsize_ns);
36 
37 #if 0
38  char s[80];
39  sprintf (s, "%7.3f %8.5f %8.5f\n", tmin, bin0val, bin1val);
40  cout << s;
41 #endif
42 
43  if (bin1val > bin0val) {
44  time0shiftns_ = shift_ns;
45  break;
46  }
47  }
48 
49 #if 0
50  cout << "time0shiftns_ = " << time0shiftns_ << endl;
51 #endif
52 }
53 
54 template <>
55 std::pair<double,double> RecoFCcorFactorAlgo<CastorPulseShapes::Shape>::calcpair(double truefc)
56 {
57  double timeslew_ns = CastorTimeSlew::delay(std::max(0.0,(double)truefc),
59  double shift_ns = fixedphasens_ - time0shiftns_ + timeslew_ns;
60 
61  double tmin = -shift_ns;
62  double tmax = tmin+integrationwindowns_;
63 
64  double integral = shape_.integrate( tmin, tmax );
65  double corfactor = 1.0/integral;
66  double recofc = (double)truefc * integral;
67 
68 #if 0
69  char s[80];
70  sprintf (s, "%8.2f %8.4f %8.4f %8.5f %8.5f %8.5f ",
71  truefc, tmin, tmax, integral, corfactor, recofc);
72  cout << s;
73 #endif
74 
75  std::pair<double,double> thepair(recofc,corfactor);
76  return thepair;
77 }
78 
80 //
82  float fixedphase_ns,
83  float max_fracerror)
84 {
85  RecoFCcorFactorAlgo<CastorPulseShapes::Shape> corFalgo(num_samples, (double)fixedphase_ns);
86 
87  // Generate lookup map for the correction function, never exceeding
88  // a maximum fractional error for lookups.
89  //
90  genlkupmap< RecoFCcorFactorAlgo<CastorPulseShapes::Shape> > (1.0, 5000.0f, // generation domain
91  max_fracerror, // maximum fractional error
92  1.0, // min_xstep = minimum true fC increment
93  corFalgo,
94  mCorFactors_); // return lookup map
95 }
96 
97 
99 {
100  double correction;
101 
102  std::map<double,double>::const_iterator fcupper,fclower;
103 
104  fcupper = mCorFactors_.upper_bound(fc_ampl);
105  fclower = fcupper;
106  fclower--;
107 
108  if (fcupper == mCorFactors_.end()) {
109  correction = fclower->second;
110  }
111  else if (fcupper == mCorFactors_.begin()) {
112  correction = fcupper->second;
113  }
114  else {
115  if (fabs(fclower->first - fc_ampl) <
116  fabs(fcupper->first - fc_ampl) )
117  correction = fclower->second;
118  else
119  correction = fcupper->second;
120  }
121 
122 #if 0
123  char s[80];
124  sprintf (s, "%7.1f (%8.5f %8.5f) (%8.5f %8.5f) %8.5f",
125  fc_ampl,
126  fclower->first, fclower->second,
127  fcupper->first, fcupper->second,
128  correction);
129  cout << s << endl;
130 #endif
131 
132  return correction;
133 }
static double delay(double fC, BiasSetting bias=Medium)
Returns the amount (ns) by which a pulse of the given number of fC will be delayed by the timeslew ef...
std::pair< double, double > calcpair(double)
const T & max(const T &a, const T &b)
RecoFCcorFactorAlgo(int num_samples, double fixedphase_ns)
Integral< F, X >::type integral(const F &f)
Definition: Integral.h:69
static const double tmax[3]
CastorPulseContainmentCorrection(int num_samples, float fixedphase_ns, float max_fracerror)
Generate energy correction factors based on a predetermined phase of the hit + time slew...
float integrate(double tmin, double tmax) const
tuple cout
Definition: gather_cfg.py:121
const Shape & castorShape() const