CMS 3D CMS Logo

HcalPulseContainmentAlgo.cc
Go to the documentation of this file.
4 #include <cmath>
5 #include <iostream>
6 
7 // Function generates a lookup map for a passed-in function (via templated object algoObject,
8 // which must contain method "calcpair" that spits out (x,y) pair from a type float seed.
9 // Each map y-value is separated from the previous value by a programmable fractional error
10 // relative to the previous value.
11 //
12 HcalPulseContainmentAlgo::HcalPulseContainmentAlgo(int num_samples, double fixedphase_ns, const HcalTimeSlew* hcalTimeSlew_delay)
13 : fixedphasens_(fixedphase_ns),
14  integrator_(&(HcalPulseShapes().hbShape())),
15  hcalTimeSlew_delay_(hcalTimeSlew_delay)
16 {
17  init(num_samples);
18 }
19 
20 HcalPulseContainmentAlgo::HcalPulseContainmentAlgo(const HcalPulseShape * shape, int num_samples, double fixedphase_ns, const HcalTimeSlew* hcalTimeSlew_delay)
21 : fixedphasens_(fixedphase_ns),
22  integrator_(shape),
23  hcalTimeSlew_delay_(hcalTimeSlew_delay)
24 {
25  init(num_samples);
26 }
27 
28 void
30 {
31  const int binsize_ns = 25;
32 
33  // First set up controlling parameters for calculating the correction factor:
34  // Integration window size...
35  //
36  integrationwindowns_ = (double)(binsize_ns*num_samples);
37 
38  // First find the point at which time bin "1" exceeds time bin "0",
39  // and call that point "time 0".
40  //
41  for (int shift_ns=0; shift_ns<binsize_ns; shift_ns++) {
42 
43  // Digitize by integrating to find all time sample
44  // bin values for this shift.
45  //
46  double tmin = -(double)shift_ns;
47  double bin0val = (double) integrator_(tmin, tmin+binsize_ns);
48  double bin1val = (double) integrator_(tmin+binsize_ns, tmin+2*binsize_ns);
49 
50 #if 0
51  char s[80];
52  sprintf (s, "%7.3f %8.5f %8.5f\n", tmin, bin0val, bin1val);
53  cout << s;
54 #endif
55 
56  if (bin1val > bin0val) {
57  time0shiftns_ = shift_ns;
58  break;
59  }
60  }
61 
62 #if 0
63  cout << "time0shiftns_ = " << time0shiftns_ << endl;
64 #endif
65 }
66 
67 std::pair<double,double>
69 {
70  double timeslew_ns = hcalTimeSlew_delay_->delay(std::max(0.0,(double)truefc), HcalTimeSlew::Medium);
71 
72  double shift_ns = fixedphasens_ - time0shiftns_ + timeslew_ns;
73  //std::cout << "SHIFT " << fixedphasens_ << " " << time0shiftns_ << " " << timeslew_ns << std::endl;
74  double tmin = -shift_ns;
75  double tmax = tmin+integrationwindowns_;
76 
77  //double integral = shape_.integrate( tmin, tmax );
78  double integral = integrator_(tmin, tmax);
79  //std::cout << "INTEGRAL " << integral << " " << truefc << " " << tmin << " " << tmax << std::endl;
80  double corfactor = 1.0/integral;
81  double recofc = (double)truefc * integral;
82 
83 #if 0
84  char s[80];
85  sprintf (s, "%8.2f %8.4f %8.4f %8.5f %8.5f %8.5f ",
86  truefc, tmin, tmax, integral, corfactor, recofc);
87  cout << s;
88 #endif
89 
90  std::pair<double,double> thepair(recofc,corfactor);
91  return thepair;
92 }
double delay(double fC, BiasSetting bias=Medium) const
Returns the amount (ns) by which a pulse of the given number of fC will be delayed by the timeslew ef...
Definition: HcalTimeSlew.cc:14
std::pair< double, double > calcpair(double)
const HcalTimeSlew * hcalTimeSlew_delay_
HcalPulseContainmentAlgo(const HcalPulseShape *shape, int num_samples, double fixedphase_ns, const HcalTimeSlew *hcalTimeSlew_delay)
Integral< F, X >::type integral(const F &f)
Definition: Integral.h:69
static const double tmax[3]