Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-05 11:11:21

0001 #include "CalibCalorimetry/HcalAlgos/interface/HcalPulseContainmentCorrection.h"
0002 #include "CalibCalorimetry/HcalAlgos/src/HcalPulseContainmentAlgo.h"
0003 #include "CalibCalorimetry/HcalAlgos/interface/HcalPulseShape.h"
0004 
0005 // Function generates a lookup map for a passed-in function (via templated object algoObject,
0006 // which must contain method "calcpair" that spits out (x,y) pair from a type float seed.
0007 // Each map y-value is separated from the previous value by a programmable fractional error
0008 // relative to the previous value.
0009 //
0010 // Currently this function coded for only monotonically increasing or
0011 // decreasing functions...
0012 
0013 #include "CalibCalorimetry/HcalAlgos/interface/genlkupmap.h"
0014 
0015 ///Generate energy correction factors based on a predetermined phase of the hit + time slew
0016 //
0017 HcalPulseContainmentCorrection::HcalPulseContainmentCorrection(int num_samples,
0018                                                                float fixedphase_ns,
0019                                                                bool phaseAsInSim,
0020                                                                float max_fracerror,
0021                                                                const HcalTimeSlew* hcalTimeSlew_delay) {
0022   HcalPulseContainmentAlgo corFalgo(num_samples, (double)fixedphase_ns, phaseAsInSim, hcalTimeSlew_delay);
0023 
0024   // Generate lookup map for the correction function, never exceeding
0025   // a maximum fractional error for lookups.
0026   //
0027   //  static const double max_recofc = 5000.0f;   // HPD,
0028   //                      max_recofc = 200000.0f; // SiPMs
0029   genlkupmap<HcalPulseContainmentAlgo>(1.0,
0030                                        200000.0f,      // generation domain
0031                                        max_fracerror,  // maximum fractional error
0032                                        1.0,            // min_xstep = minimum true fC increment
0033                                        corFalgo,
0034                                        mCorFactors_);  // return lookup map
0035 }
0036 
0037 // do the same, but with a shape passed in
0038 HcalPulseContainmentCorrection::HcalPulseContainmentCorrection(const HcalPulseShape* shape,
0039                                                                int num_samples,
0040                                                                float fixedphase_ns,
0041                                                                bool phaseAsInSim,
0042                                                                float max_fracerror,
0043                                                                const HcalTimeSlew* hcalTimeSlew_delay) {
0044   HcalPulseContainmentAlgo corFalgo(shape, num_samples, (double)fixedphase_ns, phaseAsInSim, hcalTimeSlew_delay);
0045   genlkupmap<HcalPulseContainmentAlgo>(1.0,
0046                                        200000.0f,      // generation domain
0047                                        max_fracerror,  // maximum fractional error
0048                                        1.0,            // min_xstep = minimum true fC increment
0049                                        corFalgo,
0050                                        mCorFactors_);  // return lookup map
0051 }
0052 
0053 double HcalPulseContainmentCorrection::getCorrection(double fc_ampl) const {
0054   double correction;
0055 
0056   std::map<double, double>::const_iterator fcupper, fclower;
0057 
0058   fcupper = mCorFactors_.upper_bound(fc_ampl);
0059   fclower = fcupper;
0060   fclower--;
0061 
0062   if (fcupper == mCorFactors_.end()) {
0063     correction = fclower->second;
0064   } else if (fcupper == mCorFactors_.begin()) {
0065     correction = fcupper->second;
0066   } else {
0067     if (fabs(fclower->first - fc_ampl) < fabs(fcupper->first - fc_ampl))
0068       correction = fclower->second;
0069     else
0070       correction = fcupper->second;
0071   }
0072 
0073 #if 0
0074   char s[80];
0075   sprintf (s, "%7.1f (%8.5f %8.5f) (%8.5f %8.5f) %8.5f",
0076        fc_ampl,
0077        fclower->first, fclower->second,
0078        fcupper->first, fcupper->second,
0079        correction);
0080   cout << s << endl;
0081 #endif
0082 
0083   return correction;
0084 }