CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/CalibCalorimetry/CastorCalib/src/CastorPulseShapes.cc

Go to the documentation of this file.
00001 #include "CalibCalorimetry/CastorCalib/interface/CastorPulseShapes.h"
00002 #include <cmath>
00003 
00004 CastorPulseShapes::CastorPulseShapes() {
00005   //  computeHPDShape(hpdShape_);
00006   computeCastorShape(castorShape_);
00007 }
00008 
00009 
00010 void CastorPulseShapes::computeCastorShape(CastorPulseShapes::Shape& sh) {
00011 
00012   //  cout << endl << " ===== computeShapeHF  !!! " << endl << endl;
00013 
00014   const float ts = 3.0;           // time constant in   t * exp(-(t/ts)**2)
00015 
00016   // first create pulse shape over a range of time 0 ns to 255 ns in 1 ns steps
00017   int nbin = 256;
00018   sh.setNBin(nbin);
00019   std::vector<float> ntmp(nbin,0.0);  // 
00020 
00021   int j;
00022   float norm;
00023 
00024   // CASTOR SHAPE
00025   norm = 0.0;
00026   for( j = 0; j < 3 * ts && j < nbin; j++){
00027     ntmp[j] = ((float)j)*exp(-((float)(j*j))/(ts*ts));
00028     norm += ntmp[j];
00029   }
00030   // normalize pulse area to 1.0
00031   for( j = 0; j < 3 * ts && j < nbin; j++){
00032     ntmp[j] /= norm;
00033 
00034     //    cout << " nt [" << j << "] = " <<  ntmp[j] << endl;
00035     sh.setShapeBin(j,ntmp[j]);
00036   }
00037 }
00038 
00039 CastorPulseShapes::Shape::Shape() {
00040   nbin_=0;
00041   tpeak_=0;
00042 }
00043 
00044 void CastorPulseShapes::Shape::setNBin(int n) {
00045   nbin_=n;
00046   shape_=std::vector<float>(n,0.0f);
00047 }
00048 
00049 void CastorPulseShapes::Shape::setShapeBin(int i, float f) {
00050   if (i>=0 && i<nbin_) shape_[i]=f;
00051 }
00052 
00053 float CastorPulseShapes::Shape::operator()(double t) const {
00054   // shape is in 1 ns steps
00055   int i=(int)(t+0.5);
00056   float rv=0;
00057   if (i>=0 && i<nbin_) rv=shape_[i];
00058   return rv;
00059 }
00060 
00061 float CastorPulseShapes::Shape::at(double t) const {
00062   // shape is in 1 ns steps
00063   int i=(int)(t+0.5);
00064   float rv=0;
00065   if (i>=0 && i<nbin_) rv=shape_[i];
00066   return rv;
00067 }
00068 
00069 float CastorPulseShapes::Shape::integrate(double t1, double t2) const {
00070   static const float int_delta_ns = 0.05f; 
00071   double intval = 0.0;
00072 
00073   for (double t = t1; t < t2; t+= int_delta_ns) {
00074     float loedge = at(t);
00075     float hiedge = at(t+int_delta_ns);
00076     intval += (loedge+hiedge)*int_delta_ns/2.0;
00077   }
00078 
00079   return (float)intval;
00080 }