Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:15

0001 #include "CalibCalorimetry/HcalAlgos/interface/HcalShapeIntegrator.h"
0002 
0003 #include <iostream>
0004 HcalShapeIntegrator::HcalShapeIntegrator(const HcalPulseShapes::Shape* shape) : nbin_(shape->nbins()), v_(nbin_, 0.) {
0005   for (int t = 0; t < nbin_; ++t) {
0006     double amount = shape->at(t);
0007     for (int ibin = t; ibin < nbin_; ++ibin) {
0008       // v_ holds the cumulative integral
0009       v_[ibin] += amount;
0010     }
0011   }
0012 }
0013 
0014 float HcalShapeIntegrator::at(double t) const {
0015   // shape is in 1 ns steps
0016   // I round down to match the old algorithm
0017   int i = (int)(t - 0.5);
0018   float rv = 0;
0019   if (i < 0) {
0020     rv = 0.;
0021   } else if (i >= nbin_) {
0022     rv = v_.back();
0023   } else {
0024     rv = v_[i];
0025     // maybe interpolate
0026     // assume 1 ns bins
0027     float f = (t - 0.5 - i);
0028     if (++i < nbin_ && f > 0) {
0029       rv = rv * (1. - f) + v_[i] * f;
0030     }
0031   }
0032   return rv;
0033 }
0034 
0035 float HcalShapeIntegrator::operator()(double startTime, double stopTime) const { return at(stopTime) - at(startTime); }