CMS 3D CMS Logo

L1GTTripleObjectCond.cc
Go to the documentation of this file.
6 
11 
13 
16 #include "L1GTCorrelationalCut.h"
17 #include "L1GT3BodyCut.h"
18 #include "L1GTSingleInOutLUT.h"
19 
20 #include <set>
21 
22 #include <ap_int.h>
23 
24 using namespace l1t;
25 
27 public:
28  explicit L1GTTripleObjectCond(const edm::ParameterSet&);
29  ~L1GTTripleObjectCond() override = default;
30 
32 
33 private:
34  bool filter(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
35 
37 
41 
43  const bool inv_mass_checks_;
44 
48 
50 
55 };
56 
58  : scales_(config.getParameter<edm::ParameterSet>("scales")),
59  collection1Cuts_(config.getParameter<edm::ParameterSet>("collection1"), config, scales_),
60  collection2Cuts_(config.getParameter<edm::ParameterSet>("collection2"), config, scales_),
61  collection3Cuts_(config.getParameter<edm::ParameterSet>("collection3"), config, scales_),
62  enable_sanity_checks_(config.getUntrackedParameter<bool>("sanity_checks")),
63  inv_mass_checks_(config.getUntrackedParameter<bool>("inv_mass_checks")),
64  correl12Cuts_(
65  config.getParameter<edm::ParameterSet>("correl12"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
66  correl13Cuts_(
67  config.getParameter<edm::ParameterSet>("correl13"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
68  correl23Cuts_(
69  config.getParameter<edm::ParameterSet>("correl23"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
70  correl123Cuts_(config, config, scales_, inv_mass_checks_),
71  token1_(consumes<P2GTCandidateCollection>(collection1Cuts_.tag())),
72  token2_(collection1Cuts_.tag() == collection2Cuts_.tag()
73  ? token1_
74  : consumes<P2GTCandidateCollection>(collection2Cuts_.tag())),
75  token3_(collection1Cuts_.tag() == collection3Cuts_.tag()
76  ? token1_
77  : (collection2Cuts_.tag() == collection3Cuts_.tag()
78  ? token2_
79  : consumes<P2GTCandidateCollection>(collection3Cuts_.tag()))),
80  primVertToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("primVertTag"))) {
81  produces<P2GTCandidateVectorRef>(collection1Cuts_.tag().instance());
82 
83  if (!(collection1Cuts_.tag() == collection2Cuts_.tag())) {
84  produces<P2GTCandidateVectorRef>(collection2Cuts_.tag().instance());
85  }
86 
88  produces<P2GTCandidateVectorRef>(collection3Cuts_.tag().instance());
89  }
90 
91  if (inv_mass_checks_) {
92  produces<InvariantMassErrorCollection>();
93  }
94 }
95 
98 
99  edm::ParameterSetDescription collection1Desc;
101  desc.add<edm::ParameterSetDescription>("collection1", collection1Desc);
102 
103  edm::ParameterSetDescription collection2Desc;
105  desc.add<edm::ParameterSetDescription>("collection2", collection2Desc);
106 
107  edm::ParameterSetDescription collection3Desc;
109  desc.add<edm::ParameterSetDescription>("collection3", collection3Desc);
110 
111  edm::ParameterSetDescription scalesDesc;
113  desc.add<edm::ParameterSetDescription>("scales", scalesDesc);
114 
115  desc.add<edm::InputTag>("primVertTag");
116 
117  desc.addUntracked<bool>("sanity_checks", false);
118  desc.addUntracked<bool>("inv_mass_checks", false);
119 
120  edm::ParameterSetDescription correl12Desc;
122  desc.add<edm::ParameterSetDescription>("correl12", correl12Desc);
123 
124  edm::ParameterSetDescription correl13Desc;
126  desc.add<edm::ParameterSetDescription>("correl13", correl13Desc);
127 
128  edm::ParameterSetDescription correl23Desc;
130  desc.add<edm::ParameterSetDescription>("correl23", correl23Desc);
131 
133 
134  L1GTCorrelationalCut::fillLUTDescriptions(desc);
135 
136  descriptions.addWithDefaultLabel(desc);
137 }
138 
140  edm::Handle<P2GTCandidateCollection> col1 = event.getHandle(token1_);
141  edm::Handle<P2GTCandidateCollection> col2 = event.getHandle(token2_);
142  edm::Handle<P2GTCandidateCollection> col3 = event.getHandle(token3_);
143  edm::Handle<P2GTCandidateCollection> primVertCol = event.getHandle(primVertToken_);
144 
145  bool condition_result = false;
146 
147  std::set<std::size_t> triggeredIdcs1;
148  std::set<std::size_t> triggeredIdcs2;
149  std::set<std::size_t> triggeredIdcs3;
150 
151  InvariantMassErrorCollection massErrors;
152 
153  for (std::size_t idx1 = 0; idx1 < col1->size(); ++idx1) {
154  bool single1Pass = collection1Cuts_.checkObject(col1->at(idx1));
155  single1Pass &= collection1Cuts_.checkPrimaryVertices(col1->at(idx1), *primVertCol);
156 
157  for (std::size_t idx2 = 0; idx2 < col2->size(); ++idx2) {
158  bool single2Pass = collection2Cuts_.checkObject(col2->at(idx2));
159  single2Pass &= collection2Cuts_.checkPrimaryVertices(col2->at(idx2), *primVertCol);
160 
161  for (std::size_t idx3 = 0; idx3 < col3->size(); ++idx3) {
162  // If we're looking at the same collection then we shouldn't use the same object in one comparison.
163  if (col1.product() == col2.product() && idx1 == idx2) {
164  continue;
165  }
166 
167  if (col1.product() == col3.product() && idx1 == idx3) {
168  continue;
169  }
170 
171  if (col2.product() == col3.product() && idx2 == idx3) {
172  continue;
173  }
174 
175  bool pass = single1Pass & single2Pass;
176 
177  pass &= collection3Cuts_.checkObject(col3->at(idx3));
178  pass &= collection3Cuts_.checkPrimaryVertices(col3->at(idx3), *primVertCol);
179  pass &= correl12Cuts_.checkObjects(col1->at(idx1), col2->at(idx2), massErrors);
180  pass &= correl13Cuts_.checkObjects(col1->at(idx1), col3->at(idx3), massErrors);
181  pass &= correl23Cuts_.checkObjects(col2->at(idx2), col3->at(idx3), massErrors);
182  pass &= correl123Cuts_.checkObjects(col1->at(idx1), col2->at(idx2), col3->at(idx3), massErrors);
183 
184  condition_result |= pass;
185 
186  if (pass) {
187  triggeredIdcs1.emplace(idx1);
188 
189  if (col1.product() != col2.product()) {
190  triggeredIdcs2.emplace(idx2);
191  } else {
192  triggeredIdcs1.emplace(idx2);
193  }
194 
195  if (col1.product() != col3.product() && col2.product() != col3.product()) {
196  triggeredIdcs3.emplace(idx3);
197  } else if (col1.product() == col3.product()) {
198  triggeredIdcs1.emplace(idx3);
199  } else {
200  triggeredIdcs2.emplace(idx3);
201  }
202  }
203  }
204  }
205  }
206 
207  if (condition_result) {
208  std::unique_ptr<P2GTCandidateVectorRef> triggerCol1 = std::make_unique<P2GTCandidateVectorRef>();
209 
210  for (std::size_t idx : triggeredIdcs1) {
211  triggerCol1->push_back(P2GTCandidateRef(col1, idx));
212  }
213  event.put(std::move(triggerCol1), collection1Cuts_.tag().instance());
214 
215  if (col1.product() != col2.product()) {
216  std::unique_ptr<P2GTCandidateVectorRef> triggerCol2 = std::make_unique<P2GTCandidateVectorRef>();
217 
218  for (std::size_t idx : triggeredIdcs2) {
219  triggerCol2->push_back(P2GTCandidateRef(col2, idx));
220  }
221  event.put(std::move(triggerCol2), collection2Cuts_.tag().instance());
222  }
223 
224  if (col1.product() != col3.product() && col2.product() != col3.product()) {
225  std::unique_ptr<P2GTCandidateVectorRef> triggerCol3 = std::make_unique<P2GTCandidateVectorRef>();
226 
227  for (std::size_t idx : triggeredIdcs3) {
228  triggerCol3->push_back(P2GTCandidateRef(col3, idx));
229  }
230  event.put(std::move(triggerCol3), collection3Cuts_.tag().instance());
231  }
232  }
233 
234  if (inv_mass_checks_) {
235  event.put(std::make_unique<InvariantMassErrorCollection>(std::move(massErrors)), "");
236  }
237 
238  return condition_result;
239 }
240 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
const L1GTCorrelationalCut correl23Cuts_
L1GTTripleObjectCond(const edm::ParameterSet &)
bool checkObject(const P2GTCandidate &obj) const
const edm::EDGetTokenT< P2GTCandidateCollection > primVertToken_
std::vector< P2GTCandidate > P2GTCandidateCollection
Definition: P2GTCandidate.h:16
const L1GTSingleCollectionCut collection2Cuts_
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
bool checkPrimaryVertices(const P2GTCandidate &obj, const P2GTCandidateCollection &primVertCol) const
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_
bool checkObjects(const P2GTCandidate &obj1, const P2GTCandidate &obj2, InvariantMassErrorCollection &massErrors) const
const L1GTCorrelationalCut correl12Cuts_
const L1GTCorrelationalCut correl13Cuts_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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 L1GT3BodyCut correl123Cuts_
HLT enums.
bool checkObjects(const P2GTCandidate &obj1, const P2GTCandidate &obj2, const P2GTCandidate &obj3, InvariantMassErrorCollection &massErrors) const
Definition: L1GT3BodyCut.h:79
const L1GTSingleCollectionCut collection3Cuts_
const edm::EDGetTokenT< P2GTCandidateCollection > token1_
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1