CMS 3D CMS Logo

L1GTQuadObjectCond.cc
Go to the documentation of this file.
6 
12 
15 #include "L1GTCorrelationalCut.h"
16 #include "L1GT3BodyCut.h"
17 #include "L1GTSingleInOutLUT.h"
18 
19 #include <cinttypes>
20 #include <memory>
21 #include <vector>
22 #include <set>
23 
24 #include <ap_int.h>
25 
26 using namespace l1t;
27 
29 public:
30  explicit L1GTQuadObjectCond(const edm::ParameterSet&);
31  ~L1GTQuadObjectCond() override = default;
32 
34 
35 private:
36  bool filter(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
37 
39 
44 
46  const bool inv_mass_checks_;
47 
54 
59 
65 };
66 
68  : scales_(config.getParameter<edm::ParameterSet>("scales")),
69  collection1Cuts_(config.getParameter<edm::ParameterSet>("collection1"), config, scales_),
70  collection2Cuts_(config.getParameter<edm::ParameterSet>("collection2"), config, scales_),
71  collection3Cuts_(config.getParameter<edm::ParameterSet>("collection3"), config, scales_),
72  collection4Cuts_(config.getParameter<edm::ParameterSet>("collection4"), config, scales_),
73  enable_sanity_checks_(config.getUntrackedParameter<bool>("sanity_checks")),
74  inv_mass_checks_(config.getUntrackedParameter<bool>("inv_mass_checks")),
75  correl12Cuts_(
76  config.getParameter<edm::ParameterSet>("correl12"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
77  correl13Cuts_(
78  config.getParameter<edm::ParameterSet>("correl13"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
79  correl23Cuts_(
80  config.getParameter<edm::ParameterSet>("correl23"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
81  correl14Cuts_(
82  config.getParameter<edm::ParameterSet>("correl14"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
83  correl24Cuts_(
84  config.getParameter<edm::ParameterSet>("correl24"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
85  correl34Cuts_(
86  config.getParameter<edm::ParameterSet>("correl34"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
87  correl123Cuts_(config.getParameter<edm::ParameterSet>("correl123"), config, scales_, inv_mass_checks_),
88  correl124Cuts_(config.getParameter<edm::ParameterSet>("correl124"), config, scales_, inv_mass_checks_),
89  correl134Cuts_(config.getParameter<edm::ParameterSet>("correl134"), config, scales_, inv_mass_checks_),
90  correl234Cuts_(config.getParameter<edm::ParameterSet>("correl234"), config, scales_, inv_mass_checks_),
91  token1_(consumes<P2GTCandidateCollection>(collection1Cuts_.tag())),
92  token2_(collection1Cuts_.tag() == collection2Cuts_.tag()
93  ? token1_
94  : consumes<P2GTCandidateCollection>(collection2Cuts_.tag())),
95  token3_(collection1Cuts_.tag() == collection3Cuts_.tag()
96  ? token1_
97  : (collection2Cuts_.tag() == collection3Cuts_.tag()
98  ? token2_
99  : consumes<P2GTCandidateCollection>(collection3Cuts_.tag()))),
100  token4_(collection1Cuts_.tag() == collection4Cuts_.tag()
101  ? token1_
102  : (collection2Cuts_.tag() == collection4Cuts_.tag()
103  ? token2_
104  : (collection3Cuts_.tag() == collection4Cuts_.tag()
105  ? token3_
106  : consumes<P2GTCandidateCollection>(collection4Cuts_.tag())))),
107  primVertToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("primVertTag"))) {
108  produces<P2GTCandidateVectorRef>(collection1Cuts_.tag().instance());
109 
110  if (!(collection1Cuts_.tag() == collection2Cuts_.tag())) {
111  produces<P2GTCandidateVectorRef>(collection2Cuts_.tag().instance());
112  }
113 
115  produces<P2GTCandidateVectorRef>(collection3Cuts_.tag().instance());
116  }
117 
120  produces<P2GTCandidateVectorRef>(collection4Cuts_.tag().instance());
121  }
122 
123  if (inv_mass_checks_) {
124  produces<InvariantMassErrorCollection>();
125  }
126 }
127 
130 
131  edm::ParameterSetDescription collection1Desc;
133  desc.add<edm::ParameterSetDescription>("collection1", collection1Desc);
134 
135  edm::ParameterSetDescription collection2Desc;
137  desc.add<edm::ParameterSetDescription>("collection2", collection2Desc);
138 
139  edm::ParameterSetDescription collection3Desc;
141  desc.add<edm::ParameterSetDescription>("collection3", collection3Desc);
142 
143  edm::ParameterSetDescription collection4Desc;
145  desc.add<edm::ParameterSetDescription>("collection4", collection4Desc);
146 
147  edm::ParameterSetDescription scalesDesc;
149  desc.add<edm::ParameterSetDescription>("scales", scalesDesc);
150 
151  desc.add<edm::InputTag>("primVertTag");
152 
153  desc.addUntracked<bool>("sanity_checks", false);
154  desc.addUntracked<bool>("inv_mass_checks", false);
155 
156  edm::ParameterSetDescription correl12Desc;
158  desc.add<edm::ParameterSetDescription>("correl12", correl12Desc);
159 
160  edm::ParameterSetDescription correl13Desc;
162  desc.add<edm::ParameterSetDescription>("correl13", correl13Desc);
163 
164  edm::ParameterSetDescription correl23Desc;
166  desc.add<edm::ParameterSetDescription>("correl23", correl23Desc);
167 
168  edm::ParameterSetDescription correl14Desc;
170  desc.add<edm::ParameterSetDescription>("correl14", correl14Desc);
171 
172  edm::ParameterSetDescription correl24Desc;
174  desc.add<edm::ParameterSetDescription>("correl24", correl24Desc);
175 
176  edm::ParameterSetDescription correl34Desc;
178  desc.add<edm::ParameterSetDescription>("correl34", correl34Desc);
179 
180  edm::ParameterSetDescription correl123Desc;
181  L1GT3BodyCut::fillPSetDescription(correl123Desc);
182  desc.add<edm::ParameterSetDescription>("correl123", correl123Desc);
183 
184  edm::ParameterSetDescription correl124Desc;
185  L1GT3BodyCut::fillPSetDescription(correl124Desc);
186  desc.add<edm::ParameterSetDescription>("correl124", correl124Desc);
187 
188  edm::ParameterSetDescription correl134Desc;
189  L1GT3BodyCut::fillPSetDescription(correl134Desc);
190  desc.add<edm::ParameterSetDescription>("correl134", correl134Desc);
191 
192  edm::ParameterSetDescription correl234Desc;
193  L1GT3BodyCut::fillPSetDescription(correl234Desc);
194  desc.add<edm::ParameterSetDescription>("correl234", correl234Desc);
195 
196  L1GTCorrelationalCut::fillLUTDescriptions(desc);
197 
198  descriptions.addWithDefaultLabel(desc);
199 }
200 
202  edm::Handle<P2GTCandidateCollection> col1 = event.getHandle(token1_);
203  edm::Handle<P2GTCandidateCollection> col2 = event.getHandle(token2_);
204  edm::Handle<P2GTCandidateCollection> col3 = event.getHandle(token3_);
205  edm::Handle<P2GTCandidateCollection> col4 = event.getHandle(token4_);
206  edm::Handle<P2GTCandidateCollection> primVertCol = event.getHandle(primVertToken_);
207 
208  bool condition_result = false;
209 
210  std::set<std::size_t> triggeredIdcs1;
211  std::set<std::size_t> triggeredIdcs2;
212  std::set<std::size_t> triggeredIdcs3;
213  std::set<std::size_t> triggeredIdcs4;
214 
215  InvariantMassErrorCollection massErrors;
216 
217  for (std::size_t idx1 = 0; idx1 < col1->size(); ++idx1) {
218  bool single1Pass = collection1Cuts_.checkObject(col1->at(idx1));
219  single1Pass &= collection1Cuts_.checkPrimaryVertices(col1->at(idx1), *primVertCol);
220 
221  for (std::size_t idx2 = 0; idx2 < col2->size(); ++idx2) {
222  bool single2Pass = collection2Cuts_.checkObject(col2->at(idx2));
223  single2Pass &= collection2Cuts_.checkPrimaryVertices(col2->at(idx2), *primVertCol);
224 
225  for (std::size_t idx3 = 0; idx3 < col3->size(); ++idx3) {
226  bool single3Pass = collection3Cuts_.checkObject(col3->at(idx3));
227  single3Pass &= collection3Cuts_.checkPrimaryVertices(col3->at(idx3), *primVertCol);
228 
229  for (std::size_t idx4 = 0; idx4 < col4->size(); ++idx4) {
230  // If we're looking at the same collection then we shouldn't use the same object in one comparison.
231  if (col1.product() == col2.product() && idx1 == idx2) {
232  continue;
233  }
234 
235  if (col2.product() == col3.product() && idx2 == idx3) {
236  continue;
237  }
238 
239  if (col1.product() == col3.product() && idx1 == idx3) {
240  continue;
241  }
242 
243  if (col1.product() == col4.product() && idx1 == idx4) {
244  continue;
245  }
246 
247  if (col2.product() == col4.product() && idx2 == idx4) {
248  continue;
249  }
250 
251  if (col3.product() == col4.product() && idx3 == idx4) {
252  continue;
253  }
254 
255  bool pass = single1Pass & single2Pass & single3Pass;
256 
257  pass &= collection4Cuts_.checkObject(col4->at(idx4));
258  pass &= collection4Cuts_.checkPrimaryVertices(col4->at(idx4), *primVertCol);
259  pass &= correl12Cuts_.checkObjects(col1->at(idx1), col2->at(idx2), massErrors);
260  pass &= correl13Cuts_.checkObjects(col1->at(idx1), col3->at(idx3), massErrors);
261  pass &= correl23Cuts_.checkObjects(col2->at(idx2), col3->at(idx3), massErrors);
262  pass &= correl14Cuts_.checkObjects(col1->at(idx1), col4->at(idx4), massErrors);
263  pass &= correl24Cuts_.checkObjects(col2->at(idx2), col4->at(idx4), massErrors);
264  pass &= correl34Cuts_.checkObjects(col3->at(idx3), col4->at(idx4), massErrors);
265  pass &= correl123Cuts_.checkObjects(col1->at(idx1), col2->at(idx2), col3->at(idx3), massErrors);
266  pass &= correl124Cuts_.checkObjects(col1->at(idx1), col2->at(idx2), col4->at(idx4), massErrors);
267  pass &= correl134Cuts_.checkObjects(col1->at(idx1), col3->at(idx3), col4->at(idx4), massErrors);
268  pass &= correl234Cuts_.checkObjects(col2->at(idx2), col3->at(idx3), col4->at(idx4), massErrors);
269 
270  condition_result |= pass;
271 
272  if (pass) {
273  triggeredIdcs1.emplace(idx1);
274 
275  if (col1.product() != col2.product()) {
276  triggeredIdcs2.emplace(idx2);
277  } else {
278  triggeredIdcs1.emplace(idx2);
279  }
280 
281  if (col1.product() != col3.product() && col2.product() != col3.product()) {
282  triggeredIdcs3.emplace(idx3);
283  } else if (col1.product() == col3.product()) {
284  triggeredIdcs1.emplace(idx3);
285  } else {
286  triggeredIdcs2.emplace(idx3);
287  }
288 
289  if (col1.product() != col4.product() && col2.product() != col4.product() &&
290  col3.product() != col4.product()) {
291  triggeredIdcs4.emplace(idx4);
292  } else if (col1.product() == col4.product()) {
293  triggeredIdcs1.emplace(idx4);
294  } else if (col2.product() == col4.product()) {
295  triggeredIdcs2.emplace(idx4);
296  } else {
297  triggeredIdcs3.emplace(idx4);
298  }
299  }
300  }
301  }
302  }
303  }
304 
305  condition_result &= collection1Cuts_.checkCollection(*col1);
306  condition_result &= collection2Cuts_.checkCollection(*col2);
307  condition_result &= collection3Cuts_.checkCollection(*col3);
308  condition_result &= collection4Cuts_.checkCollection(*col4);
309 
310  if (condition_result) {
311  std::unique_ptr<P2GTCandidateVectorRef> triggerCol1 = std::make_unique<P2GTCandidateVectorRef>();
312 
313  for (std::size_t idx : triggeredIdcs1) {
314  triggerCol1->push_back(P2GTCandidateRef(col1, idx));
315  }
316  event.put(std::move(triggerCol1), collection1Cuts_.tag().instance());
317 
318  if (col1.product() != col2.product()) {
319  std::unique_ptr<P2GTCandidateVectorRef> triggerCol2 = std::make_unique<P2GTCandidateVectorRef>();
320 
321  for (std::size_t idx : triggeredIdcs2) {
322  triggerCol2->push_back(P2GTCandidateRef(col2, idx));
323  }
324  event.put(std::move(triggerCol2), collection2Cuts_.tag().instance());
325  }
326 
327  if (col1.product() != col3.product() && col2.product() != col3.product()) {
328  std::unique_ptr<P2GTCandidateVectorRef> triggerCol3 = std::make_unique<P2GTCandidateVectorRef>();
329 
330  for (std::size_t idx : triggeredIdcs3) {
331  triggerCol3->push_back(P2GTCandidateRef(col3, idx));
332  }
333  event.put(std::move(triggerCol3), collection3Cuts_.tag().instance());
334  }
335 
336  if (col1.product() != col4.product() && col2.product() != col4.product() && col3.product() != col4.product()) {
337  std::unique_ptr<P2GTCandidateVectorRef> triggerCol4 = std::make_unique<P2GTCandidateVectorRef>();
338 
339  for (std::size_t idx : triggeredIdcs4) {
340  triggerCol4->push_back(P2GTCandidateRef(col4, idx));
341  }
342  event.put(std::move(triggerCol4), collection4Cuts_.tag().instance());
343  }
344  }
345 
346  if (inv_mass_checks_) {
347  event.put(std::make_unique<InvariantMassErrorCollection>(std::move(massErrors)), "");
348  }
349 
350  return condition_result;
351 }
352 
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 L1GTCorrelationalCut correl23Cuts_
bool checkPrimaryVertices(const P2GTCandidate &obj, const P2GTCandidateCollection &primVertCol) const
const L1GTScales scales_
const L1GTCorrelationalCut correl24Cuts_
delete x;
Definition: CaloConfig.h:22
Definition: config.py:1
const edm::EDGetTokenT< P2GTCandidateCollection > token1_
std::vector< InvariantMassError > InvariantMassErrorCollection
bool checkObjects(const P2GTCandidate &obj1, const P2GTCandidate &obj2, InvariantMassErrorCollection &massErrors) const
const L1GT3BodyCut correl123Cuts_
L1GTQuadObjectCond(const edm::ParameterSet &)
bool filter(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
bool checkCollection(const P2GTCandidateCollection &col) const
const edm::EDGetTokenT< P2GTCandidateCollection > primVertToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::EDGetTokenT< P2GTCandidateCollection > token3_
const L1GTSingleCollectionCut collection3Cuts_
const L1GTSingleCollectionCut collection1Cuts_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void fillPSetDescription(edm::ParameterSetDescription &desc)
const L1GTCorrelationalCut correl12Cuts_
const L1GT3BodyCut correl134Cuts_
const L1GT3BodyCut correl234Cuts_
static void fillDescriptions(edm::ConfigurationDescriptions &)
const L1GTCorrelationalCut correl13Cuts_
HLT enums.
const L1GTCorrelationalCut correl14Cuts_
const edm::EDGetTokenT< P2GTCandidateCollection > token2_
bool checkObjects(const P2GTCandidate &obj1, const P2GTCandidate &obj2, const P2GTCandidate &obj3, InvariantMassErrorCollection &massErrors) const
Definition: L1GT3BodyCut.h:79
const L1GT3BodyCut correl124Cuts_
const L1GTSingleCollectionCut collection4Cuts_
const L1GTCorrelationalCut correl34Cuts_
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1