CMS 3D CMS Logo

L1GTQuadObjectCond.cc
Go to the documentation of this file.
6 
12 
15 #include "L1GTDeltaCut.h"
16 #include "L1GTSingleInOutLUT.h"
17 
18 #include <cinttypes>
19 #include <memory>
20 #include <vector>
21 #include <set>
22 
23 #include <ap_int.h>
24 
25 using namespace l1t;
26 
28 public:
29  explicit L1GTQuadObjectCond(const edm::ParameterSet&);
30  ~L1GTQuadObjectCond() override = default;
31 
33 
34 private:
35  bool filter(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
36 
38 
43 
45  const bool inv_mass_checks_;
46 
53 
58 };
59 
61  : scales_(config.getParameter<edm::ParameterSet>("scales")),
62  collection1Cuts_(config.getParameter<edm::ParameterSet>("collection1"), config, scales_),
63  collection2Cuts_(config.getParameter<edm::ParameterSet>("collection2"), config, scales_),
64  collection3Cuts_(config.getParameter<edm::ParameterSet>("collection3"), config, scales_),
65  collection4Cuts_(config.getParameter<edm::ParameterSet>("collection4"), config, scales_),
66  enable_sanity_checks_(config.getUntrackedParameter<bool>("sanity_checks")),
67  inv_mass_checks_(config.getUntrackedParameter<bool>("inv_mass_checks")),
68  delta12Cuts_(
69  config.getParameter<edm::ParameterSet>("delta12"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
70  delta13Cuts_(
71  config.getParameter<edm::ParameterSet>("delta13"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
72  delta23Cuts_(
73  config.getParameter<edm::ParameterSet>("delta23"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
74  delta14Cuts_(
75  config.getParameter<edm::ParameterSet>("delta14"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
76  delta24Cuts_(
77  config.getParameter<edm::ParameterSet>("delta24"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
78  delta34Cuts_(
79  config.getParameter<edm::ParameterSet>("delta34"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
80  token1_(consumes<P2GTCandidateCollection>(collection1Cuts_.tag())),
81  token2_(collection1Cuts_.tag() == collection2Cuts_.tag()
82  ? token1_
83  : consumes<P2GTCandidateCollection>(collection2Cuts_.tag())),
84  token3_(collection1Cuts_.tag() == collection3Cuts_.tag()
85  ? token1_
86  : (collection2Cuts_.tag() == collection3Cuts_.tag()
87  ? token2_
88  : consumes<P2GTCandidateCollection>(collection3Cuts_.tag()))),
89  token4_(collection1Cuts_.tag() == collection4Cuts_.tag()
90  ? token1_
91  : (collection2Cuts_.tag() == collection4Cuts_.tag()
92  ? token2_
93  : (collection3Cuts_.tag() == collection4Cuts_.tag()
94  ? token3_
95  : consumes<P2GTCandidateCollection>(collection4Cuts_.tag())))) {
96  produces<P2GTCandidateVectorRef>(collection1Cuts_.tag().instance());
97 
98  if (!(collection1Cuts_.tag() == collection2Cuts_.tag())) {
99  produces<P2GTCandidateVectorRef>(collection2Cuts_.tag().instance());
100  }
101 
103  produces<P2GTCandidateVectorRef>(collection3Cuts_.tag().instance());
104  }
105 
108  produces<P2GTCandidateVectorRef>(collection4Cuts_.tag().instance());
109  }
110 
111  if (inv_mass_checks_) {
112  produces<InvariantMassErrorCollection>();
113  }
114 }
115 
118 
119  edm::ParameterSetDescription collection1Desc;
121  desc.add<edm::ParameterSetDescription>("collection1", collection1Desc);
122 
123  edm::ParameterSetDescription collection2Desc;
125  desc.add<edm::ParameterSetDescription>("collection2", collection2Desc);
126 
127  edm::ParameterSetDescription collection3Desc;
129  desc.add<edm::ParameterSetDescription>("collection3", collection3Desc);
130 
131  edm::ParameterSetDescription collection4Desc;
133  desc.add<edm::ParameterSetDescription>("collection4", collection4Desc);
134 
135  edm::ParameterSetDescription scalesDesc;
137  desc.add<edm::ParameterSetDescription>("scales", scalesDesc);
138 
139  desc.addUntracked<bool>("sanity_checks", false);
140  desc.addUntracked<bool>("inv_mass_checks", false);
141 
142  edm::ParameterSetDescription delta12Desc;
144  desc.add<edm::ParameterSetDescription>("delta12", delta12Desc);
145 
146  edm::ParameterSetDescription delta13Desc;
148  desc.add<edm::ParameterSetDescription>("delta13", delta13Desc);
149 
150  edm::ParameterSetDescription delta23Desc;
152  desc.add<edm::ParameterSetDescription>("delta23", delta23Desc);
153 
154  edm::ParameterSetDescription delta14Desc;
156  desc.add<edm::ParameterSetDescription>("delta14", delta14Desc);
157 
158  edm::ParameterSetDescription delta24Desc;
160  desc.add<edm::ParameterSetDescription>("delta24", delta24Desc);
161 
162  edm::ParameterSetDescription delta34Desc;
164  desc.add<edm::ParameterSetDescription>("delta34", delta34Desc);
165 
166  L1GTDeltaCut::fillLUTDescriptions(desc);
167 
168  descriptions.addWithDefaultLabel(desc);
169 }
170 
172  edm::Handle<P2GTCandidateCollection> col1 = event.getHandle(token1_);
173  edm::Handle<P2GTCandidateCollection> col2 = event.getHandle(token2_);
174  edm::Handle<P2GTCandidateCollection> col3 = event.getHandle(token3_);
175  edm::Handle<P2GTCandidateCollection> col4 = event.getHandle(token4_);
176 
177  bool condition_result = false;
178 
179  std::set<std::size_t> triggeredIdcs1;
180  std::set<std::size_t> triggeredIdcs2;
181  std::set<std::size_t> triggeredIdcs3;
182  std::set<std::size_t> triggeredIdcs4;
183 
184  InvariantMassErrorCollection massErrors;
185 
186  for (std::size_t idx1 = 0; idx1 < col1->size(); ++idx1) {
187  for (std::size_t idx2 = 0; idx2 < col2->size(); ++idx2) {
188  for (std::size_t idx3 = 0; idx3 < col3->size(); ++idx3) {
189  for (std::size_t idx4 = 0; idx4 < col4->size(); ++idx4) {
190  // If we're looking at the same collection then we shouldn't use the same object in one comparison.
191  if (col1.product() == col2.product() && idx1 == idx2) {
192  continue;
193  }
194 
195  if (col2.product() == col3.product() && idx2 == idx3) {
196  continue;
197  }
198 
199  if (col1.product() == col3.product() && idx1 == idx3) {
200  continue;
201  }
202 
203  if (col1.product() == col4.product() && idx1 == idx4) {
204  continue;
205  }
206 
207  if (col2.product() == col4.product() && idx2 == idx4) {
208  continue;
209  }
210 
211  if (col3.product() == col4.product() && idx3 == idx4) {
212  continue;
213  }
214 
215  bool pass = true;
216  pass &= collection1Cuts_.checkObject(col1->at(idx1));
217  pass &= collection2Cuts_.checkObject(col2->at(idx2));
218  pass &= collection3Cuts_.checkObject(col3->at(idx3));
219  pass &= collection4Cuts_.checkObject(col4->at(idx4));
220  pass &= delta12Cuts_.checkObjects(col1->at(idx1), col2->at(idx2), massErrors);
221  pass &= delta13Cuts_.checkObjects(col1->at(idx1), col3->at(idx3), massErrors);
222  pass &= delta23Cuts_.checkObjects(col2->at(idx2), col3->at(idx3), massErrors);
223  pass &= delta14Cuts_.checkObjects(col1->at(idx1), col4->at(idx4), massErrors);
224  pass &= delta24Cuts_.checkObjects(col2->at(idx2), col4->at(idx4), massErrors);
225  pass &= delta34Cuts_.checkObjects(col3->at(idx3), col4->at(idx4), massErrors);
226  condition_result |= pass;
227 
228  if (pass) {
229  triggeredIdcs1.emplace(idx1);
230 
231  if (col1.product() != col2.product()) {
232  triggeredIdcs2.emplace(idx2);
233  } else {
234  triggeredIdcs1.emplace(idx2);
235  }
236 
237  if (col1.product() != col3.product() && col2.product() != col3.product()) {
238  triggeredIdcs3.emplace(idx3);
239  } else if (col1.product() == col3.product()) {
240  triggeredIdcs1.emplace(idx3);
241  } else {
242  triggeredIdcs2.emplace(idx3);
243  }
244 
245  if (col1.product() != col4.product() && col2.product() != col4.product() &&
246  col3.product() != col4.product()) {
247  triggeredIdcs4.emplace(idx4);
248  } else if (col1.product() == col4.product()) {
249  triggeredIdcs1.emplace(idx4);
250  } else if (col2.product() == col4.product()) {
251  triggeredIdcs2.emplace(idx4);
252  } else {
253  triggeredIdcs3.emplace(idx4);
254  }
255  }
256  }
257  }
258  }
259  }
260 
261  if (condition_result) {
262  std::unique_ptr<P2GTCandidateVectorRef> triggerCol1 = std::make_unique<P2GTCandidateVectorRef>();
263 
264  for (std::size_t idx : triggeredIdcs1) {
265  triggerCol1->push_back(P2GTCandidateRef(col1, idx));
266  }
267  event.put(std::move(triggerCol1), collection1Cuts_.tag().instance());
268 
269  if (col1.product() != col2.product()) {
270  std::unique_ptr<P2GTCandidateVectorRef> triggerCol2 = std::make_unique<P2GTCandidateVectorRef>();
271 
272  for (std::size_t idx : triggeredIdcs2) {
273  triggerCol2->push_back(P2GTCandidateRef(col2, idx));
274  }
275  event.put(std::move(triggerCol2), collection2Cuts_.tag().instance());
276  }
277 
278  if (col1.product() != col3.product() && col2.product() != col3.product()) {
279  std::unique_ptr<P2GTCandidateVectorRef> triggerCol3 = std::make_unique<P2GTCandidateVectorRef>();
280 
281  for (std::size_t idx : triggeredIdcs3) {
282  triggerCol3->push_back(P2GTCandidateRef(col3, idx));
283  }
284  event.put(std::move(triggerCol3), collection3Cuts_.tag().instance());
285  }
286 
287  if (col1.product() != col4.product() && col2.product() != col4.product() && col3.product() != col4.product()) {
288  std::unique_ptr<P2GTCandidateVectorRef> triggerCol4 = std::make_unique<P2GTCandidateVectorRef>();
289 
290  for (std::size_t idx : triggeredIdcs4) {
291  triggerCol4->push_back(P2GTCandidateRef(col4, idx));
292  }
293  event.put(std::move(triggerCol4), collection4Cuts_.tag().instance());
294  }
295  }
296 
297  if (inv_mass_checks_) {
298  event.put(std::make_unique<InvariantMassErrorCollection>(std::move(massErrors)), "");
299  }
300 
301  return condition_result;
302 }
303 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
const L1GTSingleCollectionCut collection2Cuts_
bool checkObject(const P2GTCandidate &obj) const
const bool enable_sanity_checks_
std::vector< P2GTCandidate > P2GTCandidateCollection
Definition: P2GTCandidate.h:16
const edm::EDGetTokenT< P2GTCandidateCollection > token4_
std::string const & instance() const
Definition: InputTag.h:37
T const * product() const
Definition: Handle.h:70
const edm::InputTag & tag() const
edm::Ref< P2GTCandidateCollection > P2GTCandidateRef
Definition: P2GTCandidate.h:18
const L1GTScales scales_
delete x;
Definition: CaloConfig.h:22
Definition: config.py:1
const edm::EDGetTokenT< P2GTCandidateCollection > token1_
std::vector< InvariantMassError > InvariantMassErrorCollection
L1GTQuadObjectCond(const edm::ParameterSet &)
bool filter(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
const L1GTDeltaCut delta12Cuts_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool checkObjects(const P2GTCandidate &obj1, const P2GTCandidate &obj2, InvariantMassErrorCollection &massErrors) const
Definition: L1GTDeltaCut.h:67
const edm::EDGetTokenT< P2GTCandidateCollection > token3_
const L1GTSingleCollectionCut collection3Cuts_
const L1GTSingleCollectionCut collection1Cuts_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void fillPSetDescription(edm::ParameterSetDescription &desc)
const L1GTDeltaCut delta23Cuts_
const L1GTDeltaCut delta14Cuts_
static void fillDescriptions(edm::ConfigurationDescriptions &)
HLT enums.
const edm::EDGetTokenT< P2GTCandidateCollection > token2_
const L1GTDeltaCut delta24Cuts_
const L1GTDeltaCut delta13Cuts_
const L1GTSingleCollectionCut collection4Cuts_
const L1GTDeltaCut delta34Cuts_
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1