Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:10

0001 #ifndef CondFormats_HcalObjects_OOTPileupCorrData_h_
0002 #define CondFormats_HcalObjects_OOTPileupCorrData_h_
0003 
0004 #include <cmath>
0005 #include "FWCore/Utilities/interface/Exception.h"
0006 
0007 #include "boost/serialization/vector.hpp"
0008 #include "boost/serialization/version.hpp"
0009 
0010 #include "CondFormats/HcalObjects/interface/AbsOOTPileupCorrection.h"
0011 #include "CondFormats/HcalObjects/interface/OOTPileupCorrDataFcn.h"
0012 #include <cstdint>
0013 
0014 class OOTPileupCorrData : public AbsOOTPileupCorrection {
0015 public:
0016   //
0017   // Constructor arguments are as follows:
0018   //
0019   // corrs          -- Correction function to apply in different ranges
0020   //                   of abs(iEta).
0021   //
0022   // iEtaLimits     -- Definition of ranges for abs(iEta). This is just
0023   //                   an increasing sequence of positive iEta values.
0024   //                   The size of this vector must be equal to the
0025   //                   size of "corrs" vector minus one. The correction
0026   //                   corrs[k] will normally be applied in case
0027   //                   iEtaLimits[k-1] <= abs(iEta) < iEtaLimits[k].
0028   //                   In case abs(iEta) < iEtaLimits[0], corrs[0] is
0029   //                   applied, and in case
0030   //                   iEtaLimits[iEtaLimits.size()-1] <= abs(iEta),
0031   //                   corrs[corrs.size()-1] is applied.
0032   //
0033   // chargeLimit    -- Minimum charge in the triggered time slice.
0034   //                   The observed charge must be larger than this minimum
0035   //                   in order for corrections to be applied.
0036   //
0037   // requireFirstTS -- The code will check that the corrections were
0038   //                   derived for the right triggered TS. Corrections
0039   //                   will be applied if either requireFirstTS < 0 (check
0040   //                   disabled) or if firstTimeSlice == requireFirstTS.
0041   //
0042   // requireNTS     -- The code will check that the corrections were derived
0043   //                   for the right number of time slices to integrate.
0044   //                   Corrections will be applied if either requireNTS < 0
0045   //                   (check disabled) or if requireNTS == nTimeSlices.
0046   //
0047   // readjustTiming -- Set "true" if one should use OOT pileup corrected
0048   //                   energies to derive hit time. To use the original,
0049   //                   uncorrected energies set this to "false".
0050   //
0051   OOTPileupCorrData(const std::vector<OOTPileupCorrDataFcn>& corrs,
0052                     const std::vector<uint32_t>& iEtaLimits,
0053                     double chargeLimit,
0054                     int requireFirstTS,
0055                     int requireNTS,
0056                     bool readjustTiming);
0057 
0058   inline ~OOTPileupCorrData() override {}
0059 
0060   // Main correction function
0061   void apply(const HcalDetId& id,
0062              const double* inputCharge,
0063              unsigned lenInputCharge,
0064              const BunchXParameter* bcParams,
0065              unsigned lenBcParams,
0066              unsigned firstTimeSlice,
0067              unsigned nTimeSlices,
0068              double* correctedCharge,
0069              unsigned lenCorrectedCharge,
0070              bool* pulseShapeCorrApplied,
0071              bool* leakCorrApplied,
0072              bool* readjustTiming) const override;
0073 
0074   // Are we using charge or energy?
0075   inline bool inputIsEnergy() const override { return false; }
0076 
0077   // Simplified correction function which does actual work
0078   inline void apply(const HcalDetId& id, double* ts, const int tsTrig) const {
0079     if (ts[tsTrig] > chargeLimit_) {
0080       const unsigned nLimits(iEtaLimits_.size());
0081       if (nLimits) {
0082         const uint32_t uEta = std::abs(id.ieta());
0083         const uint32_t* limits(&iEtaLimits_[0]);
0084         unsigned which(0U);
0085         for (; which < nLimits; ++which)
0086           if (uEta < limits[which])
0087             break;
0088         corrs_[which].pucorrection(ts, tsTrig);
0089       }
0090     }
0091   }
0092 
0093   inline const OOTPileupCorrDataFcn& getCorrectionByID(const HcalDetId& id) const {
0094     const unsigned nLimits = iEtaLimits_.size();
0095     unsigned which(0U);
0096     if (nLimits) {
0097       const uint32_t uEta = std::abs(id.ieta());
0098       const uint32_t* limits(&iEtaLimits_[0]);
0099       for (; which < nLimits; ++which)
0100         if (uEta < limits[which])
0101           break;
0102     }
0103     return corrs_.at(which);
0104   }
0105 
0106 protected:
0107   // Comparison function must be implemented
0108   inline bool isEqual(const AbsOOTPileupCorrection& otherBase) const override {
0109     const OOTPileupCorrData& r = static_cast<const OOTPileupCorrData&>(otherBase);
0110     return corrs_ == r.corrs_ && iEtaLimits_ == r.iEtaLimits_ && chargeLimit_ == r.chargeLimit_ &&
0111            requireFirstTS_ == r.requireFirstTS_ && requireNTS_ == r.requireNTS_ && readjustTiming_ == r.readjustTiming_;
0112   }
0113 
0114 public:
0115   // Default constructor needed for serialization.
0116   // Do not use in application code.
0117   inline OOTPileupCorrData() {}
0118 
0119 private:
0120   bool validate() const;
0121 
0122   std::vector<OOTPileupCorrDataFcn> corrs_;
0123   std::vector<uint32_t> iEtaLimits_;
0124   double chargeLimit_;
0125   int32_t requireFirstTS_;
0126   int32_t requireNTS_;
0127   uint8_t readjustTiming_;
0128 
0129   friend class boost::serialization::access;
0130 
0131   template <class Archive>
0132   inline void save(Archive& ar, const unsigned /* version */) const {
0133     if (!validate())
0134       throw cms::Exception("In OOTPileupCorrData::save: invalid data");
0135     boost::serialization::base_object<AbsOOTPileupCorrection>(*this);
0136     ar& corrs_& iEtaLimits_& chargeLimit_& requireFirstTS_& requireNTS_& readjustTiming_;
0137   }
0138 
0139   template <class Archive>
0140   inline void load(Archive& ar, const unsigned /* version */) {
0141     boost::serialization::base_object<AbsOOTPileupCorrection>(*this);
0142     ar& corrs_& iEtaLimits_& chargeLimit_& requireFirstTS_& requireNTS_& readjustTiming_;
0143     if (!validate())
0144       throw cms::Exception("In OOTPileupCorrData::load: invalid data");
0145   }
0146 
0147   BOOST_SERIALIZATION_SPLIT_MEMBER()
0148 };
0149 
0150 BOOST_CLASS_VERSION(OOTPileupCorrData, 1)
0151 BOOST_CLASS_EXPORT_KEY(OOTPileupCorrData)
0152 
0153 #endif  // CondFormats_HcalObjects_OOTPileupCorrData_h_