CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/CalibCalorimetry/HcalAlgos/src/HcalPulseContainmentAlgo.cc

Go to the documentation of this file.
00001 #include "CalibCalorimetry/HcalAlgos/src/HcalPulseContainmentAlgo.h"
00002 #include "CalibCalorimetry/HcalAlgos/interface/HcalTimeSlew.h"
00003 #include "CalibCalorimetry/HcalAlgos/interface/HcalPulseShapes.h"
00004 #include <math.h>
00005 #include <iostream>
00006 
00007 // Function generates a lookup map for a passed-in function (via templated object algoObject,
00008 // which must contain method "calcpair" that spits out (x,y) pair from a type float seed.
00009 // Each map y-value is separated from the previous value by a programmable fractional error
00010 // relative to the previous value.
00011 //
00012 HcalPulseContainmentAlgo::HcalPulseContainmentAlgo(int num_samples, double fixedphase_ns)
00013 : fixedphasens_(fixedphase_ns),
00014   integrator_(&(HcalPulseShapes().hbShape()))
00015 {
00016   init(num_samples);
00017 }
00018 
00019 HcalPulseContainmentAlgo::HcalPulseContainmentAlgo
00020   (const HcalPulseShape * shape, int num_samples, double fixedphase_ns)
00021 : fixedphasens_(fixedphase_ns),
00022   integrator_(shape)
00023 {
00024   init(num_samples);
00025 }
00026 
00027 void
00028 HcalPulseContainmentAlgo::init(int num_samples)
00029 {
00030   const int binsize_ns = 25;
00031 
00032   // First set up controlling parameters for calculating the correction factor:
00033   // Integration window size...
00034   //
00035   integrationwindowns_ = (double)(binsize_ns*num_samples);
00036 
00037   // First find the point at which time bin "1" exceeds time bin "0",
00038   // and call that point "time 0".
00039   //
00040   for (int shift_ns=0; shift_ns<binsize_ns; shift_ns++) {
00041 
00042     // Digitize by integrating to find all time sample
00043     // bin values for this shift.
00044     //
00045     double tmin    = -(double)shift_ns;
00046     double bin0val = (double) integrator_(tmin, tmin+binsize_ns);
00047     double bin1val = (double) integrator_(tmin+binsize_ns, tmin+2*binsize_ns);
00048 
00049 #if 0
00050     char s[80];
00051     sprintf (s, "%7.3f %8.5f %8.5f\n", tmin, bin0val, bin1val);
00052     cout << s;
00053 #endif
00054 
00055     if (bin1val > bin0val) {
00056       time0shiftns_ = shift_ns;
00057       break;
00058     }
00059   }
00060 
00061 #if 0
00062   cout << "time0shiftns_ = " << time0shiftns_ << endl;
00063 #endif
00064 }
00065 
00066 std::pair<double,double> 
00067 HcalPulseContainmentAlgo::calcpair(double truefc)
00068 {
00069   double timeslew_ns = HcalTimeSlew::delay(std::max(0.0,(double)truefc),
00070                                            HcalTimeSlew::Medium);
00071   double shift_ns  = fixedphasens_ - time0shiftns_ + timeslew_ns;
00072   //std::cout << "SHIFT " << fixedphasens_ << " " << time0shiftns_ << " " << timeslew_ns << std::endl;
00073   double tmin      = -shift_ns;
00074   double tmax      = tmin+integrationwindowns_;
00075 
00076   //double integral  = shape_.integrate( tmin, tmax );
00077   double integral = integrator_(tmin, tmax);
00078   //std::cout << "INTEGRAL " << integral << " " << truefc << " " << tmin << " "  << tmax << std::endl;
00079   double corfactor = 1.0/integral;
00080   double recofc    = (double)truefc * integral;
00081 
00082 #if 0
00083   char s[80];
00084   sprintf (s, "%8.2f %8.4f %8.4f %8.5f %8.5f %8.5f ",
00085            truefc, tmin, tmax, integral, corfactor, recofc);
00086   cout << s;
00087 #endif
00088 
00089   std::pair<double,double> thepair(recofc,corfactor);
00090   return thepair;
00091 }