CMS 3D CMS Logo

L1GTTripleObjectCond.cc
Go to the documentation of this file.
6 
11 
13 
16 #include "L1GTDeltaCut.h"
17 #include "L1GTSingleInOutLUT.h"
18 
19 #include <set>
20 
21 #include <ap_int.h>
22 
23 using namespace l1t;
24 
26 public:
27  explicit L1GTTripleObjectCond(const edm::ParameterSet&);
28  ~L1GTTripleObjectCond() override = default;
29 
31 
32 private:
33  bool filter(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
34 
36 
40 
42  const bool inv_mass_checks_;
43 
47 
51 };
52 
54  : scales_(config.getParameter<edm::ParameterSet>("scales")),
55  collection1Cuts_(config.getParameter<edm::ParameterSet>("collection1"), config, scales_),
56  collection2Cuts_(config.getParameter<edm::ParameterSet>("collection2"), config, scales_),
57  collection3Cuts_(config.getParameter<edm::ParameterSet>("collection3"), config, scales_),
58  enable_sanity_checks_(config.getUntrackedParameter<bool>("sanity_checks")),
59  inv_mass_checks_(config.getUntrackedParameter<bool>("inv_mass_checks")),
60  delta12Cuts_(
61  config.getParameter<edm::ParameterSet>("delta12"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
62  delta13Cuts_(
63  config.getParameter<edm::ParameterSet>("delta13"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
64  delta23Cuts_(
65  config.getParameter<edm::ParameterSet>("delta23"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
66  token1_(consumes<P2GTCandidateCollection>(collection1Cuts_.tag())),
67  token2_(collection1Cuts_.tag() == collection2Cuts_.tag()
68  ? token1_
69  : consumes<P2GTCandidateCollection>(collection2Cuts_.tag())),
70  token3_(collection1Cuts_.tag() == collection3Cuts_.tag()
71  ? token1_
72  : (collection2Cuts_.tag() == collection3Cuts_.tag()
73  ? token2_
74  : consumes<P2GTCandidateCollection>(collection3Cuts_.tag()))) {
75  produces<P2GTCandidateVectorRef>(collection1Cuts_.tag().instance());
76 
77  if (!(collection1Cuts_.tag() == collection2Cuts_.tag())) {
78  produces<P2GTCandidateVectorRef>(collection2Cuts_.tag().instance());
79  }
80 
82  produces<P2GTCandidateVectorRef>(collection3Cuts_.tag().instance());
83  }
84 
85  if (inv_mass_checks_) {
86  produces<InvariantMassErrorCollection>();
87  }
88 }
89 
92 
93  edm::ParameterSetDescription collection1Desc;
95  desc.add<edm::ParameterSetDescription>("collection1", collection1Desc);
96 
97  edm::ParameterSetDescription collection2Desc;
99  desc.add<edm::ParameterSetDescription>("collection2", collection2Desc);
100 
101  edm::ParameterSetDescription collection3Desc;
103  desc.add<edm::ParameterSetDescription>("collection3", collection3Desc);
104 
105  edm::ParameterSetDescription scalesDesc;
107  desc.add<edm::ParameterSetDescription>("scales", scalesDesc);
108 
109  desc.addUntracked<bool>("sanity_checks", false);
110  desc.addUntracked<bool>("inv_mass_checks", false);
111 
112  edm::ParameterSetDescription delta12Desc;
114  desc.add<edm::ParameterSetDescription>("delta12", delta12Desc);
115 
116  edm::ParameterSetDescription delta13Desc;
118  desc.add<edm::ParameterSetDescription>("delta13", delta13Desc);
119 
120  edm::ParameterSetDescription delta23Desc;
122  desc.add<edm::ParameterSetDescription>("delta23", delta23Desc);
123 
124  L1GTDeltaCut::fillLUTDescriptions(desc);
125 
126  descriptions.addWithDefaultLabel(desc);
127 }
128 
130  edm::Handle<P2GTCandidateCollection> col1 = event.getHandle(token1_);
131  edm::Handle<P2GTCandidateCollection> col2 = event.getHandle(token2_);
132  edm::Handle<P2GTCandidateCollection> col3 = event.getHandle(token3_);
133 
134  bool condition_result = false;
135 
136  std::set<std::size_t> triggeredIdcs1;
137  std::set<std::size_t> triggeredIdcs2;
138  std::set<std::size_t> triggeredIdcs3;
139 
140  InvariantMassErrorCollection massErrors;
141 
142  for (std::size_t idx1 = 0; idx1 < col1->size(); ++idx1) {
143  for (std::size_t idx2 = 0; idx2 < col2->size(); ++idx2) {
144  for (std::size_t idx3 = 0; idx3 < col3->size(); ++idx3) {
145  // If we're looking at the same collection then we shouldn't use the same object in one comparison.
146  if (col1.product() == col2.product() && idx1 == idx2) {
147  continue;
148  }
149 
150  if (col1.product() == col3.product() && idx1 == idx3) {
151  continue;
152  }
153 
154  if (col2.product() == col3.product() && idx2 == idx3) {
155  continue;
156  }
157 
158  bool pass = true;
159  pass &= collection1Cuts_.checkObject(col1->at(idx1));
160  pass &= collection2Cuts_.checkObject(col2->at(idx2));
161  pass &= collection3Cuts_.checkObject(col3->at(idx3));
162  pass &= delta12Cuts_.checkObjects(col1->at(idx1), col2->at(idx2), massErrors);
163  pass &= delta13Cuts_.checkObjects(col1->at(idx1), col3->at(idx3), massErrors);
164  pass &= delta23Cuts_.checkObjects(col2->at(idx2), col3->at(idx3), massErrors);
165 
166  condition_result |= pass;
167 
168  if (pass) {
169  triggeredIdcs1.emplace(idx1);
170 
171  if (col1.product() != col2.product()) {
172  triggeredIdcs2.emplace(idx2);
173  } else {
174  triggeredIdcs1.emplace(idx2);
175  }
176 
177  if (col1.product() != col3.product() && col2.product() != col3.product()) {
178  triggeredIdcs3.emplace(idx3);
179  } else if (col1.product() == col3.product()) {
180  triggeredIdcs1.emplace(idx3);
181  } else {
182  triggeredIdcs2.emplace(idx3);
183  }
184  }
185  }
186  }
187  }
188 
189  if (condition_result) {
190  std::unique_ptr<P2GTCandidateVectorRef> triggerCol1 = std::make_unique<P2GTCandidateVectorRef>();
191 
192  for (std::size_t idx : triggeredIdcs1) {
193  triggerCol1->push_back(P2GTCandidateRef(col1, idx));
194  }
195  event.put(std::move(triggerCol1), collection1Cuts_.tag().instance());
196 
197  if (col1.product() != col2.product()) {
198  std::unique_ptr<P2GTCandidateVectorRef> triggerCol2 = std::make_unique<P2GTCandidateVectorRef>();
199 
200  for (std::size_t idx : triggeredIdcs2) {
201  triggerCol2->push_back(P2GTCandidateRef(col2, idx));
202  }
203  event.put(std::move(triggerCol2), collection2Cuts_.tag().instance());
204  }
205 
206  if (col1.product() != col3.product() && col2.product() != col3.product()) {
207  std::unique_ptr<P2GTCandidateVectorRef> triggerCol3 = std::make_unique<P2GTCandidateVectorRef>();
208 
209  for (std::size_t idx : triggeredIdcs3) {
210  triggerCol3->push_back(P2GTCandidateRef(col3, idx));
211  }
212  event.put(std::move(triggerCol3), collection3Cuts_.tag().instance());
213  }
214  }
215 
216  if (inv_mass_checks_) {
217  event.put(std::make_unique<InvariantMassErrorCollection>(std::move(massErrors)), "");
218  }
219 
220  return condition_result;
221 }
222 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
L1GTTripleObjectCond(const edm::ParameterSet &)
bool checkObject(const P2GTCandidate &obj) const
std::vector< P2GTCandidate > P2GTCandidateCollection
Definition: P2GTCandidate.h:16
const L1GTSingleCollectionCut collection2Cuts_
std::string const & instance() const
Definition: InputTag.h:37
const L1GTDeltaCut delta13Cuts_
T const * product() const
Definition: Handle.h:70
const edm::InputTag & tag() const
edm::Ref< P2GTCandidateCollection > P2GTCandidateRef
Definition: P2GTCandidate.h:18
delete x;
Definition: CaloConfig.h:22
bool filter(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
Definition: config.py:1
std::vector< InvariantMassError > InvariantMassErrorCollection
const edm::EDGetTokenT< P2GTCandidateCollection > token2_
const L1GTDeltaCut delta23Cuts_
#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 L1GTSingleCollectionCut collection1Cuts_
const edm::EDGetTokenT< P2GTCandidateCollection > token3_
static void fillDescriptions(edm::ConfigurationDescriptions &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void fillPSetDescription(edm::ParameterSetDescription &desc)
const L1GTDeltaCut delta12Cuts_
HLT enums.
const L1GTSingleCollectionCut collection3Cuts_
const edm::EDGetTokenT< P2GTCandidateCollection > token1_
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1