Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:58:08

0001 #include "CalibCalorimetry/HcalAlgos/src/HcalPulseContainmentAlgo.h"
0002 #include "CalibCalorimetry/HcalAlgos/interface/HcalTimeSlew.h"
0003 #include "CalibCalorimetry/HcalAlgos/interface/HcalPulseShapes.h"
0004 #include <cmath>
0005 #include <iostream>
0006 
0007 // Function generates a lookup map for a passed-in function (via templated object algoObject,
0008 // which must contain method "calcpair" that spits out (x,y) pair from a type float seed.
0009 // Each map y-value is separated from the previous value by a programmable fractional error
0010 // relative to the previous value.
0011 //
0012 HcalPulseContainmentAlgo::HcalPulseContainmentAlgo(int num_samples,
0013                                                    double fixedphase_ns,
0014                                                    bool phaseAsInSim,
0015                                                    const HcalTimeSlew* hcalTimeSlew_delay)
0016     : fixedphasens_(fixedphase_ns),
0017       phaseAsInSim_(phaseAsInSim),
0018       integrator_(&(HcalPulseShapes().hbShape())),
0019       hcalTimeSlew_delay_(hcalTimeSlew_delay) {
0020   init(num_samples);
0021 }
0022 
0023 HcalPulseContainmentAlgo::HcalPulseContainmentAlgo(const HcalPulseShape* shape,
0024                                                    int num_samples,
0025                                                    double fixedphase_ns,
0026                                                    bool phaseAsInSim,
0027                                                    const HcalTimeSlew* hcalTimeSlew_delay)
0028     : fixedphasens_(fixedphase_ns),
0029       phaseAsInSim_(phaseAsInSim),
0030       integrator_(shape),
0031       hcalTimeSlew_delay_(hcalTimeSlew_delay) {
0032   init(num_samples);
0033 }
0034 
0035 void HcalPulseContainmentAlgo::init(int num_samples) {
0036   const int binsize_ns = 25;
0037 
0038   // First set up controlling parameters for calculating the correction factor:
0039   // Integration window size...
0040   //
0041   integrationwindowns_ = (double)(binsize_ns * num_samples);
0042 
0043   // First find the point at which time bin "1" exceeds time bin "0",
0044   // and call that point "time 0".
0045   //
0046   for (int shift_ns = 0; shift_ns < binsize_ns; shift_ns++) {
0047     // Digitize by integrating to find all time sample
0048     // bin values for this shift.
0049     //
0050     double tmin = -(double)shift_ns;
0051     double bin0val = (double)integrator_(tmin, tmin + binsize_ns);
0052     double bin1val = (double)integrator_(tmin + binsize_ns, tmin + 2 * binsize_ns);
0053 
0054 #if 0
0055     char s[80];
0056     sprintf (s, "%7.3f %8.5f %8.5f\n", tmin, bin0val, bin1val);
0057     edm::LogPrint("HcalPulseContainmentAlgo") << s;
0058 #endif
0059 
0060     if (bin1val > bin0val) {
0061       time0shiftns_ = shift_ns;
0062       break;
0063     }
0064   }
0065 #if 0
0066   edm::LogPrint("HcalPulseContainmentAlgo") << "time0shiftns_ = " << time0shiftns_;
0067 #endif
0068 }
0069 
0070 std::pair<double, double> HcalPulseContainmentAlgo::calcpair(double truefc) {
0071   double timeslew_ns = hcalTimeSlew_delay_->delay(std::max(0.0, (double)truefc), HcalTimeSlew::Medium);
0072 
0073   double tmin = 0;
0074   if (phaseAsInSim_) {  // timePhase as in hcalSimParameters, no time0shift
0075     tmin = fixedphasens_ - timeslew_ns;
0076   } else {  // Run 2: timePhase opposite to SIM, time0shift
0077     double shift_ns = fixedphasens_ - time0shiftns_ + timeslew_ns;
0078     //edm::LogPrint("HcalPulseContainmentAlgo") << "SHIFT " << fixedphasens_ << " " << time0shiftns_ << " " << timeslew_ns;
0079     tmin = -shift_ns;
0080   }
0081   double tmax = tmin + integrationwindowns_;
0082 
0083   //double integral  = shape_.integrate( tmin, tmax );
0084   double integral = integrator_(tmin, tmax);
0085   //edm::LogPrint("HcalPulseContainmentAlgo") << "INTEGRAL " << integral << " " << truefc << " " << tmin << " "  << tmax;
0086   double corfactor = 1.0 / integral;
0087   double recofc = (double)truefc * integral;
0088 
0089 #if 0
0090   char s[80];
0091   sprintf (s, "%8.2f %8.4f %8.4f %8.5f %8.5f %8.5f ",
0092        truefc, tmin, tmax, integral, corfactor, recofc);
0093   edm::LogPrint("HcalPulseContainmentAlgo") << s;
0094 #endif
0095 
0096   std::pair<double, double> thepair(recofc, corfactor);
0097   return thepair;
0098 }