CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HcalShapeIntegrator.cc
Go to the documentation of this file.
2 
3 #include <iostream>
4 HcalShapeIntegrator::HcalShapeIntegrator(const HcalPulseShapes::Shape* shape) : nbin_(shape->nbins()), v_(nbin_, 0.) {
5  for (int t = 0; t < nbin_; ++t) {
6  double amount = shape->at(t);
7  for (int ibin = t; ibin < nbin_; ++ibin) {
8  // v_ holds the cumulative integral
9  v_[ibin] += amount;
10  }
11  }
12 }
13 
14 float HcalShapeIntegrator::at(double t) const {
15  // shape is in 1 ns steps
16  // I round down to match the old algorithm
17  int i = (int)(t - 0.5);
18  float rv = 0;
19  if (i < 0) {
20  rv = 0.;
21  } else if (i >= nbin_) {
22  rv = v_.back();
23  } else {
24  rv = v_[i];
25  // maybe interpolate
26  // assume 1 ns bins
27  float f = (t - 0.5 - i);
28  if (++i < nbin_ && f > 0) {
29  rv = rv * (1. - f) + v_[i] * f;
30  }
31  }
32  return rv;
33 }
34 
35 float HcalShapeIntegrator::operator()(double startTime, double stopTime) const { return at(stopTime) - at(startTime); }
float at(double time) const
HcalShapeIntegrator(const HcalPulseShapes::Shape *aShape)
float at(double time) const
float operator()(double startTime, double stopTime) const
std::vector< float > v_