CMS 3D CMS Logo

L1GT3BodyCut.h
Go to the documentation of this file.
1 #ifndef L1Trigger_Phase2L1GT_L1GT3BodyCut_h
2 #define L1Trigger_Phase2L1GT_L1GT3BodyCut_h
3 
7 
9 
11 
12 #include "L1GTSingleInOutLUT.h"
13 #include "L1GTOptionalParam.h"
14 
15 #include <optional>
16 #include <cinttypes>
17 
18 namespace l1t {
19 
20  class L1GT3BodyCut {
21  public:
23  const edm::ParameterSet& lutConfig,
24  const L1GTScales& scales,
25  bool inv_mass_checks = false)
26  : scales_(scales),
27  coshEtaLUT_(lutConfig.getParameterSet("cosh_eta_lut")),
28  coshEtaLUT2_(lutConfig.getParameterSet("cosh_eta_lut2")),
29  cosPhiLUT_(lutConfig.getParameterSet("cos_phi_lut")),
30  minInvMassSqrDiv2_(getOptionalParam<int64_t, double>("minInvMass",
31  config,
32  [&](double value) {
33  return std::round(scales.to_hw_InvMassSqrDiv2(value) *
35  })),
36  maxInvMassSqrDiv2_(getOptionalParam<int64_t, double>("maxInvMass",
37  config,
38  [&](double value) {
39  return std::round(scales.to_hw_InvMassSqrDiv2(value) *
41  })),
42  minTransMassSqrDiv2_(getOptionalParam<int64_t, double>(
43  "minTransMass",
44  config,
45  [&](double value) {
46  return std::round(scales.to_hw_TransMassSqrDiv2(value) * cosPhiLUT_.output_scale());
47  })),
48  maxTransMassSqrDiv2_(getOptionalParam<int64_t, double>(
49  "maxTransMass",
50  config,
51  [&](double value) {
52  return std::round(scales.to_hw_TransMassSqrDiv2(value) * cosPhiLUT_.output_scale());
53  })),
56  if (minInvMassSqrDiv2_) {
57  return std::max<int>(
58  std::ceil(std::log2(minInvMassSqrDiv2_.value() * cosPhiLUT_.output_scale() + 1.0)) - 16, 0);
59  } else if (maxInvMassSqrDiv2_) {
60  return std::max<int>(std::ceil(std::log2(maxInvMassSqrDiv2_.value() * cosPhiLUT_.output_scale())) - 16,
61  0);
62  } else {
63  return 0;
64  }
65  }()),
68  return std::max<int>(
69  std::ceil(std::log2(minTransMassSqrDiv2_.value() * cosPhiLUT_.output_scale() + 1.0)) - 16, 0);
70  } else if (maxTransMassSqrDiv2_) {
71  return std::max<int>(std::ceil(std::log2(maxTransMassSqrDiv2_.value() * cosPhiLUT_.output_scale())) - 16,
72  0);
73  } else {
74  return 0;
75  }
76  }()),
78 
79  bool checkObjects(const P2GTCandidate& obj1,
80  const P2GTCandidate& obj2,
81  const P2GTCandidate& obj3,
82  InvariantMassErrorCollection& massErrors) const {
83  bool res = true;
84 
86  int64_t invMassSqrDiv2 = (calc2BodyInvMass(obj1, obj2, massErrors) >> invMassResolutionReduceShift_) +
87  (calc2BodyInvMass(obj1, obj3, massErrors) >> invMassResolutionReduceShift_) +
88  (calc2BodyInvMass(obj2, obj3, massErrors) >> invMassResolutionReduceShift_);
89 
90  res &= minInvMassSqrDiv2_ ? invMassSqrDiv2 > minInvMassSqrDiv2_.value() >> invMassResolutionReduceShift_ : true;
91  res &= maxInvMassSqrDiv2_ ? invMassSqrDiv2 < maxInvMassSqrDiv2_.value() >> invMassResolutionReduceShift_ : true;
92  }
93 
95  int64_t transMassDiv2 = (calc2BodyTransMass(obj1, obj2) >> transMassResolutionReduceShift_) +
98 
100  : true;
102  : true;
103  }
104 
105  return res;
106  }
107 
109  desc.addOptional<double>("minInvMass");
110  desc.addOptional<double>("maxInvMass");
111  desc.addOptional<double>("minTransMass");
112  desc.addOptional<double>("maxTransMass");
113  }
114 
115  private:
116  static constexpr int HW_PI = 1 << (P2GTCandidate::hwPhi_t::width - 1); // assumes phi in [-pi, pi)
117 
118  int64_t calc2BodyInvMass(const P2GTCandidate& obj1,
119  const P2GTCandidate& obj2,
120  InvariantMassErrorCollection& massErrors) const {
121  uint32_t dEta = (obj1.hwEta() > obj2.hwEta()) ? obj1.hwEta().to_int() - obj2.hwEta().to_int()
122  : obj2.hwEta().to_int() - obj1.hwEta().to_int();
123  int32_t lutCoshDEta = dEta < L1GTSingleInOutLUT::DETA_LUT_SPLIT
124  ? coshEtaLUT_[dEta]
126 
127  // Ensure dPhi is always the smaller angle, i.e. always between [0, pi]
128  uint32_t dPhi = HW_PI - abs(abs(obj1.hwPhi().to_int() - obj2.hwPhi().to_int()) - HW_PI);
129 
130  // Optimization: (cos(x + pi) = -cos(x), x in [0, pi))
131  int32_t lutCosDPhi = dPhi >= HW_PI ? -cosPhiLUT_[dPhi] : cosPhiLUT_[dPhi];
132 
133  int64_t invMassSqrDiv2;
134 
136  // dEta [0, 2pi)
137  invMassSqrDiv2 = obj1.hwPT().to_int64() * obj2.hwPT().to_int64() * (lutCoshDEta - lutCosDPhi);
138  } else {
139  // dEta [2pi, 4pi), ignore cos
140  invMassSqrDiv2 = obj1.hwPT().to_int64() * obj2.hwPT().to_int64() * lutCoshDEta;
141  }
142 
143  if (inv_mass_checks_) {
144  double precInvMass =
145  scales_.pT_lsb() * std::sqrt(2 * obj1.hwPT().to_double() * obj2.hwPT().to_double() *
146  (std::cosh(dEta * scales_.eta_lsb()) - std::cos(dPhi * scales_.phi_lsb())));
147 
148  double lutInvMass =
149  scales_.pT_lsb() * std::sqrt(2 * static_cast<double>(invMassSqrDiv2) /
152 
153  double error = std::abs(precInvMass - lutInvMass);
154  massErrors.emplace_back(InvariantMassError{error, error / precInvMass, precInvMass});
155  }
156 
157  // Normalize scales required due to LUT split in dEta with different scale factors.
158  return dEta < L1GTSingleInOutLUT::DETA_LUT_SPLIT ? invMassSqrDiv2 : invMassSqrDiv2 << scaleNormalShift_;
159  }
160 
161  int64_t calc2BodyTransMass(const P2GTCandidate& obj1, const P2GTCandidate& obj2) const {
162  // Ensure dPhi is always the smaller angle, i.e. always between [0, pi]
163  uint32_t dPhi = HW_PI - abs(abs(obj1.hwPhi().to_int() - obj2.hwPhi().to_int()) - HW_PI);
164 
165  // Optimization: (cos(x + pi) = -cos(x), x in [0, pi))
166  int32_t lutCosDPhi = dPhi >= HW_PI ? -cosPhiLUT_[dPhi] : cosPhiLUT_[dPhi];
167 
168  return obj1.hwPT().to_int64() * obj2.hwPT().to_int64() *
169  (static_cast<int64_t>(std::round(cosPhiLUT_.output_scale())) - lutCosDPhi);
170  }
171 
173 
174  const L1GTSingleInOutLUT coshEtaLUT_; // [0, 2pi)
175  const L1GTSingleInOutLUT coshEtaLUT2_; // [2pi, 4pi)
177 
178  const std::optional<int64_t> minInvMassSqrDiv2_;
179  const std::optional<int64_t> maxInvMassSqrDiv2_;
180  const std::optional<int64_t> minTransMassSqrDiv2_;
181  const std::optional<int64_t> maxTransMassSqrDiv2_;
182 
183  const int scaleNormalShift_;
186 
187  const bool inv_mass_checks_;
188  };
189 
190 } // namespace l1t
191 
192 #endif // L1Trigger_Phase2L1GT_L1GT3BodyCut_h
const L1GTSingleInOutLUT cosPhiLUT_
Definition: L1GT3BodyCut.h:176
constexpr int32_t ceil(float num)
double eta_lsb() const
Definition: L1GTScales.h:91
const L1GTSingleInOutLUT coshEtaLUT2_
Definition: L1GT3BodyCut.h:175
const std::optional< int64_t > maxInvMassSqrDiv2_
Definition: L1GT3BodyCut.h:179
double pT_lsb() const
Definition: L1GTScales.h:89
double phi_lsb() const
Definition: L1GTScales.h:90
hwEta_t hwEta() const
const int transMassResolutionReduceShift_
Definition: L1GT3BodyCut.h:185
delete x;
Definition: CaloConfig.h:22
Definition: config.py:1
std::vector< InvariantMassError > InvariantMassErrorCollection
Definition: Electron.h:6
std::optional< T > getOptionalParam(const std::string &name, const edm::ParameterSet &config, std::function< T(K)> conv)
const bool inv_mass_checks_
Definition: L1GT3BodyCut.h:187
int64_t calc2BodyInvMass(const P2GTCandidate &obj1, const P2GTCandidate &obj2, InvariantMassErrorCollection &massErrors) const
Definition: L1GT3BodyCut.h:118
const std::optional< int64_t > minInvMassSqrDiv2_
Definition: L1GT3BodyCut.h:178
T sqrt(T t)
Definition: SSEVec.h:23
const std::optional< int64_t > minTransMassSqrDiv2_
Definition: L1GT3BodyCut.h:180
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Definition: value.py:1
const L1GTScales & scales_
Definition: L1GT3BodyCut.h:172
const std::optional< int64_t > maxTransMassSqrDiv2_
Definition: L1GT3BodyCut.h:181
static constexpr int HW_PI
Definition: L1GT3BodyCut.h:116
L1GT3BodyCut(const edm::ParameterSet &config, const edm::ParameterSet &lutConfig, const L1GTScales &scales, bool inv_mass_checks=false)
Definition: L1GT3BodyCut.h:22
int64_t calc2BodyTransMass(const P2GTCandidate &obj1, const P2GTCandidate &obj2) const
Definition: L1GT3BodyCut.h:161
ParameterSet const & getParameterSet(ParameterSetID const &id)
static constexpr uint32_t DETA_LUT_SPLIT
static void fillPSetDescription(edm::ParameterSetDescription &desc)
Definition: L1GT3BodyCut.h:108
bool checkObjects(const P2GTCandidate &obj1, const P2GTCandidate &obj2, const P2GTCandidate &obj3, InvariantMassErrorCollection &massErrors) const
Definition: L1GT3BodyCut.h:79
const int scaleNormalShift_
Definition: L1GT3BodyCut.h:183
const int invMassResolutionReduceShift_
Definition: L1GT3BodyCut.h:184
hwPhi_t hwPhi() const
const L1GTSingleInOutLUT coshEtaLUT_
Definition: L1GT3BodyCut.h:174
hwPT_t hwPT() const