CMS 3D CMS Logo

CastorPulseContainmentCorrection.cc
Go to the documentation of this file.
5 #include <algorithm> // for "max","min"
6 #include <cmath>
7 #include <iostream>
8 
10 
11 template <>
13  fixedphasens_ = fixedphase_ns;
14  CastorPulseShapes shapes;
15  shape_ = shapes.castorShape();
16  const int binsize_ns = 25;
17 
18  // First set up controlling parameters for calculating the correction factor:
19  // Integration window size...
20  //
21  integrationwindowns_ = (double)(binsize_ns * num_samples);
22 
23  // First find the point at which time bin "1" exceeds time bin "0",
24  // and call that point "time 0".
25  //
26  for (int shift_ns = 0; shift_ns < binsize_ns; shift_ns++) {
27  // Digitize by integrating to find all time sample
28  // bin values for this shift.
29  //
30  double tmin = -(double)shift_ns;
31  double bin0val = (double)shape_.integrate(tmin, tmin + binsize_ns);
32  double bin1val = (double)shape_.integrate(tmin + binsize_ns, tmin + 2 * binsize_ns);
33 
34 #if 0
35  char s[80];
36  sprintf (s, "%7.3f %8.5f %8.5f\n", tmin, bin0val, bin1val);
37  cout << s;
38 #endif
39 
40  if (bin1val > bin0val) {
41  time0shiftns_ = shift_ns;
42  break;
43  }
44  }
45 
46 #if 0
47  cout << "time0shiftns_ = " << time0shiftns_ << endl;
48 #endif
49 }
50 
51 template <>
52 std::pair<double, double> RecoFCcorFactorAlgo<CastorPulseShapes::Shape>::calcpair(double truefc) {
53  double timeslew_ns = CastorTimeSlew::delay(std::max(0.0, (double)truefc), CastorTimeSlew::Medium);
54  double shift_ns = fixedphasens_ - time0shiftns_ + timeslew_ns;
55 
56  double tmin = -shift_ns;
57  double tmax = tmin + integrationwindowns_;
58 
59  double integral = shape_.integrate(tmin, tmax);
60  double corfactor = 1.0 / integral;
61  double recofc = (double)truefc * integral;
62 
63 #if 0
64  char s[80];
65  sprintf (s, "%8.2f %8.4f %8.4f %8.5f %8.5f %8.5f ",
66  truefc, tmin, tmax, integral, corfactor, recofc);
67  cout << s;
68 #endif
69 
70  std::pair<double, double> thepair(recofc, corfactor);
71  return thepair;
72 }
73 
75 //
77  float fixedphase_ns,
78  float max_fracerror) {
79  RecoFCcorFactorAlgo<CastorPulseShapes::Shape> corFalgo(num_samples, (double)fixedphase_ns);
80 
81  // Generate lookup map for the correction function, never exceeding
82  // a maximum fractional error for lookups.
83  //
84  genlkupmap<RecoFCcorFactorAlgo<CastorPulseShapes::Shape> >(1.0,
85  5000.0f, // generation domain
86  max_fracerror, // maximum fractional error
87  1.0, // min_xstep = minimum true fC increment
88  corFalgo,
89  mCorFactors_); // return lookup map
90 }
91 
93  double correction;
94 
95  std::map<double, double>::const_iterator fcupper, fclower;
96 
97  fcupper = mCorFactors_.upper_bound(fc_ampl);
98  fclower = fcupper;
99  fclower--;
100 
101  if (fcupper == mCorFactors_.end()) {
102  correction = fclower->second;
103  } else if (fcupper == mCorFactors_.begin()) {
104  correction = fcupper->second;
105  } else {
106  if (fabs(fclower->first - fc_ampl) < fabs(fcupper->first - fc_ampl))
107  correction = fclower->second;
108  else
109  correction = fcupper->second;
110  }
111 
112 #if 0
113  char s[80];
114  sprintf (s, "%7.1f (%8.5f %8.5f) (%8.5f %8.5f) %8.5f",
115  fc_ampl,
116  fclower->first, fclower->second,
117  fcupper->first, fcupper->second,
118  correction);
119  cout << s << endl;
120 #endif
121 
122  return correction;
123 }
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)
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
const Shape & castorShape() const