CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OOTPileupCorrData.h
Go to the documentation of this file.
1 #ifndef CondFormats_HcalObjects_OOTPileupCorrData_h_
2 #define CondFormats_HcalObjects_OOTPileupCorrData_h_
3 
4 #include <cmath>
6 
7 #include "boost/cstdint.hpp"
8 #include "boost/serialization/vector.hpp"
9 #include "boost/serialization/version.hpp"
10 
13 
15 {
16 public:
17  //
18  // Constructor arguments are as follows:
19  //
20  // corrs -- Correction function to apply in different ranges
21  // of abs(iEta).
22  //
23  // iEtaLimits -- Definition of ranges for abs(iEta). This is just
24  // an increasing sequence of positive iEta values.
25  // The size of this vector must be equal to the
26  // size of "corrs" vector minus one. The correction
27  // corrs[k] will normally be applied in case
28  // iEtaLimits[k-1] <= abs(iEta) < iEtaLimits[k].
29  // In case abs(iEta) < iEtaLimits[0], corrs[0] is
30  // applied, and in case
31  // iEtaLimits[iEtaLimits.size()-1] <= abs(iEta),
32  // corrs[corrs.size()-1] is applied.
33  //
34  // chargeLimit -- Minimum charge in the triggered time slice.
35  // The observed charge must be larger than this minimum
36  // in order for corrections to be applied.
37  //
38  // requireFirstTS -- The code will check that the corrections were
39  // derived for the right triggered TS. Corrections
40  // will be applied if either requireFirstTS < 0 (check
41  // disabled) or if firstTimeSlice == requireFirstTS.
42  //
43  // requireNTS -- The code will check that the corrections were derived
44  // for the right number of time slices to integrate.
45  // Corrections will be applied if either requireNTS < 0
46  // (check disabled) or if requireNTS == nTimeSlices.
47  //
48  // readjustTiming -- Set "true" if one should use OOT pileup corrected
49  // energies to derive hit time. To use the original,
50  // uncorrected energies set this to "false".
51  //
52  OOTPileupCorrData(const std::vector<OOTPileupCorrDataFcn>& corrs,
53  const std::vector<uint32_t>& iEtaLimits,
54  double chargeLimit, int requireFirstTS,
55  int requireNTS, bool readjustTiming);
56 
57  inline virtual ~OOTPileupCorrData() {}
58 
59  // Main correction function
60  void apply(const HcalDetId& id,
61  const double* inputCharge, unsigned lenInputCharge,
62  const BunchXParameter* bcParams, unsigned lenBcParams,
63  unsigned firstTimeSlice, unsigned nTimeSlices,
64  double* correctedCharge, unsigned lenCorrectedCharge,
65  bool* pulseShapeCorrApplied, bool* leakCorrApplied,
66  bool* readjustTiming) const;
67 
68  // Are we using charge or energy?
69  inline bool inputIsEnergy() const {return false;}
70 
71  // Simplified correction function which does actual work
72  inline void apply(const HcalDetId& id, double* ts, const int tsTrig) const
73  {
74  if (ts[tsTrig] > chargeLimit_)
75  {
76  const unsigned nLimits(iEtaLimits_.size());
77  if (nLimits)
78  {
79  const uint32_t uEta = std::abs(id.ieta());
80  const uint32_t* limits(&iEtaLimits_[0]);
81  unsigned which(0U);
82  for (; which<nLimits; ++which)
83  if (uEta < limits[which])
84  break;
85  corrs_[which].pucorrection(ts, tsTrig);
86  }
87  }
88  }
89 
90  inline const OOTPileupCorrDataFcn& getCorrectionByID(const HcalDetId& id) const
91  {
92  const unsigned nLimits = iEtaLimits_.size();
93  unsigned which(0U);
94  if (nLimits)
95  {
96  const uint32_t uEta = std::abs(id.ieta());
97  const uint32_t* limits(&iEtaLimits_[0]);
98  for (; which<nLimits; ++which)
99  if (uEta < limits[which])
100  break;
101  }
102  return corrs_.at(which);
103  }
104 
105 protected:
106  // Comparison function must be implemented
107  inline bool isEqual(const AbsOOTPileupCorrection& otherBase) const
108  {
109  const OOTPileupCorrData& r =
110  static_cast<const OOTPileupCorrData&>(otherBase);
111  return corrs_ == r.corrs_ &&
112  iEtaLimits_ == r.iEtaLimits_ &&
113  chargeLimit_ == r.chargeLimit_ &&
115  requireNTS_ == r.requireNTS_ &&
117  }
118 
119 public:
120  // Default constructor needed for serialization.
121  // Do not use in application code.
122  inline OOTPileupCorrData() {}
123 
124 private:
125  bool validate() const;
126 
127  std::vector<OOTPileupCorrDataFcn> corrs_;
128  std::vector<uint32_t> iEtaLimits_;
129  double chargeLimit_;
131  int32_t requireNTS_;
133 
135 
136  template<class Archive>
137  inline void save(Archive & ar, const unsigned /* version */) const
138  {
139  if (!validate()) throw cms::Exception(
140  "In OOTPileupCorrData::save: invalid data");
141  boost::serialization::base_object<AbsOOTPileupCorrection>(*this);
144  }
145 
146  template<class Archive>
147  inline void load(Archive & ar, const unsigned /* version */)
148  {
149  boost::serialization::base_object<AbsOOTPileupCorrection>(*this);
152  if (!validate()) throw cms::Exception(
153  "In OOTPileupCorrData::load: invalid data");
154  }
155 
156  BOOST_SERIALIZATION_SPLIT_MEMBER()
157 };
158 
159 BOOST_CLASS_VERSION(OOTPileupCorrData, 1)
160 BOOST_CLASS_EXPORT_KEY(OOTPileupCorrData)
161 
162 #endif // CondFormats_HcalObjects_OOTPileupCorrData_h_
void save(Archive &ar, const unsigned) const
def which
Definition: eostools.py:335
bool inputIsEnergy() const
std::vector< uint32_t > iEtaLimits_
bool validate() const
std::vector< OOTPileupCorrDataFcn > corrs_
void load(Archive &ar, const unsigned)
void apply(const HcalDetId &id, double *ts, const int tsTrig) const
bool isEqual(const AbsOOTPileupCorrection &otherBase) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
friend class boost::serialization::access
void apply(const HcalDetId &id, const double *inputCharge, unsigned lenInputCharge, const BunchXParameter *bcParams, unsigned lenBcParams, unsigned firstTimeSlice, unsigned nTimeSlices, double *correctedCharge, unsigned lenCorrectedCharge, bool *pulseShapeCorrApplied, bool *leakCorrApplied, bool *readjustTiming) const
const OOTPileupCorrDataFcn & getCorrectionByID(const HcalDetId &id) const
virtual ~OOTPileupCorrData()