File indexing completed on 2024-04-06 12:02:16
0001 #include <climits>
0002
0003 #include "boost/serialization/export.hpp"
0004
0005 #include "CondFormats/HcalObjects/interface/OOTPileupCorrData.h"
0006
0007 OOTPileupCorrData::OOTPileupCorrData(const std::vector<OOTPileupCorrDataFcn>& corrs,
0008 const std::vector<uint32_t>& iEtaLimits,
0009 const double chargeLimit,
0010 const int requireFirstTS,
0011 const int requireNTS,
0012 const bool readjustTiming)
0013 : corrs_(corrs),
0014 iEtaLimits_(iEtaLimits),
0015 chargeLimit_(chargeLimit),
0016 requireFirstTS_(requireFirstTS),
0017 requireNTS_(requireNTS),
0018 readjustTiming_(readjustTiming) {
0019 if (!validate())
0020 throw cms::Exception("Invalid OOTPileupCorrData constructor arguments");
0021 }
0022
0023 bool OOTPileupCorrData::validate() const {
0024 const std::size_t nLimits(iEtaLimits_.size());
0025 if (!nLimits)
0026 return false;
0027 if (nLimits >= static_cast<std::size_t>(UINT_MAX))
0028 return false;
0029 for (std::size_t i = 0; i < nLimits - 1; ++i)
0030 if (!(iEtaLimits_[i] < iEtaLimits_[i + 1]))
0031 return false;
0032 if (corrs_.size() != nLimits + 1)
0033 return false;
0034 return true;
0035 }
0036
0037 void OOTPileupCorrData::apply(const HcalDetId& id,
0038 const double* inputCharge,
0039 const unsigned lenInputCharge,
0040 const BunchXParameter* ,
0041 const unsigned ,
0042 const unsigned firstTimeSlice,
0043 const unsigned nTimeSlices,
0044 double* correctedCharge,
0045 const unsigned lenCorrectedCharge,
0046 bool* pulseShapeCorrApplied,
0047 bool* leakCorrApplied,
0048 bool* readjustTiming) const {
0049
0050 if (inputCharge == nullptr || correctedCharge == nullptr || lenCorrectedCharge < lenInputCharge ||
0051 pulseShapeCorrApplied == nullptr || leakCorrApplied == nullptr || readjustTiming == nullptr)
0052 throw cms::Exception("Invalid arguments in OOTPileupCorrData::apply");
0053
0054 for (unsigned i = 0; i < lenInputCharge; ++i)
0055 correctedCharge[i] = inputCharge[i];
0056
0057
0058 const bool fixCharge = (requireFirstTS_ < 0 || requireFirstTS_ == static_cast<int32_t>(firstTimeSlice)) &&
0059 (requireNTS_ < 0 || requireNTS_ == static_cast<int32_t>(nTimeSlices));
0060 if (fixCharge)
0061 apply(id, correctedCharge, firstTimeSlice);
0062
0063 *pulseShapeCorrApplied = false;
0064 *leakCorrApplied = fixCharge;
0065 *readjustTiming = readjustTiming_;
0066 }
0067
0068 BOOST_CLASS_EXPORT_IMPLEMENT(OOTPileupCorrData)