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
0008
0009
0010
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
0039
0040
0041 integrationwindowns_ = (double)(binsize_ns * num_samples);
0042
0043
0044
0045
0046 for (int shift_ns = 0; shift_ns < binsize_ns; shift_ns++) {
0047
0048
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_) {
0075 tmin = fixedphasens_ - timeslew_ns;
0076 } else {
0077 double shift_ns = fixedphasens_ - time0shiftns_ + timeslew_ns;
0078
0079 tmin = -shift_ns;
0080 }
0081 double tmax = tmin + integrationwindowns_;
0082
0083
0084 double integral = integrator_(tmin, tmax);
0085
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 }