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 //
13  double fixedphase_ns,
14  bool phaseAsInSim,
15  const HcalTimeSlew* hcalTimeSlew_delay)
16  : fixedphasens_(fixedphase_ns),
17  phaseAsInSim_(phaseAsInSim),
18  integrator_(&(HcalPulseShapes().hbShape())),
19  hcalTimeSlew_delay_(hcalTimeSlew_delay) {
20  init(num_samples);
21 }
22 
24  int num_samples,
25  double fixedphase_ns,
26  bool phaseAsInSim,
27  const HcalTimeSlew* hcalTimeSlew_delay)
28  : fixedphasens_(fixedphase_ns),
29  phaseAsInSim_(phaseAsInSim),
30  integrator_(shape),
31  hcalTimeSlew_delay_(hcalTimeSlew_delay) {
32  init(num_samples);
33 }
34 
35 void HcalPulseContainmentAlgo::init(int num_samples) {
36  const int binsize_ns = 25;
37 
38  // First set up controlling parameters for calculating the correction factor:
39  // Integration window size...
40  //
41  integrationwindowns_ = (double)(binsize_ns * num_samples);
42 
43  // First find the point at which time bin "1" exceeds time bin "0",
44  // and call that point "time 0".
45  //
46  for (int shift_ns = 0; shift_ns < binsize_ns; shift_ns++) {
47  // Digitize by integrating to find all time sample
48  // bin values for this shift.
49  //
50  double tmin = -(double)shift_ns;
51  double bin0val = (double)integrator_(tmin, tmin + binsize_ns);
52  double bin1val = (double)integrator_(tmin + binsize_ns, tmin + 2 * binsize_ns);
53 
54 #if 0
55  char s[80];
56  sprintf (s, "%7.3f %8.5f %8.5f\n", tmin, bin0val, bin1val);
57  edm::LogPrint("HcalPulseContainmentAlgo") << s;
58 #endif
59 
60  if (bin1val > bin0val) {
61  time0shiftns_ = shift_ns;
62  break;
63  }
64  }
65 #if 0
66  edm::LogPrint("HcalPulseContainmentAlgo") << "time0shiftns_ = " << time0shiftns_;
67 #endif
68 }
69 
70 std::pair<double, double> HcalPulseContainmentAlgo::calcpair(double truefc) {
71  double timeslew_ns = hcalTimeSlew_delay_->delay(std::max(0.0, (double)truefc), HcalTimeSlew::Medium);
72 
73  double tmin = 0;
74  if (phaseAsInSim_) { // timePhase as in hcalSimParameters, no time0shift
75  tmin = fixedphasens_ - timeslew_ns;
76  } else { // Run 2: timePhase opposite to SIM, time0shift
77  double shift_ns = fixedphasens_ - time0shiftns_ + timeslew_ns;
78  //edm::LogPrint("HcalPulseContainmentAlgo") << "SHIFT " << fixedphasens_ << " " << time0shiftns_ << " " << timeslew_ns;
79  tmin = -shift_ns;
80  }
81  double tmax = tmin + integrationwindowns_;
82 
83  //double integral = shape_.integrate( tmin, tmax );
84  double integral = integrator_(tmin, tmax);
85  //edm::LogPrint("HcalPulseContainmentAlgo") << "INTEGRAL " << integral << " " << truefc << " " << tmin << " " << tmax;
86  double corfactor = 1.0 / integral;
87  double recofc = (double)truefc * integral;
88 
89 #if 0
90  char s[80];
91  sprintf (s, "%8.2f %8.4f %8.4f %8.5f %8.5f %8.5f ",
92  truefc, tmin, tmax, integral, corfactor, recofc);
93  edm::LogPrint("HcalPulseContainmentAlgo") << s;
94 #endif
95 
96  std::pair<double, double> thepair(recofc, corfactor);
97  return thepair;
98 }
HcalPulseContainmentAlgo(const HcalPulseShape *shape, int num_samples, double fixedphase_ns, bool phaseAsInSim, const HcalTimeSlew *hcalTimeSlew_delay)
std::pair< double, double > calcpair(double)
const HcalTimeSlew * hcalTimeSlew_delay_
float delay(float 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:20
Log< level::Warning, true > LogPrint
Integral< F, X >::type integral(const F &f)
Definition: Integral.h:70
static const double tmax[3]