CMS 3D CMS Logo

L1GTDoubleObjectCond.cc
Go to the documentation of this file.
6 
12 
14 
16 
17 #include "L1GTOptionalParam.h"
19 #include "L1GTCorrelationalCut.h"
20 #include "L1GTSingleInOutLUT.h"
21 
22 #include <cinttypes>
23 #include <memory>
24 #include <vector>
25 #include <set>
26 
27 #include <ap_int.h>
28 
29 using namespace l1t;
30 
32 public:
33  explicit L1GTDoubleObjectCond(const edm::ParameterSet&);
34  ~L1GTDoubleObjectCond() override = default;
35 
37 
38 private:
39  bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
40 
42 
45 
47  const bool inv_mass_checks_;
48 
50 
54 };
55 
57  : scales_(config.getParameter<edm::ParameterSet>("scales")),
58  collection1Cuts_(config.getParameterSet("collection1"), config, scales_),
59  collection2Cuts_(config.getParameterSet("collection2"), config, scales_),
60  enable_sanity_checks_(config.getUntrackedParameter<bool>("sanity_checks")),
61  inv_mass_checks_(config.getUntrackedParameter<bool>("inv_mass_checks")),
62  deltaCuts_(config, config, scales_, enable_sanity_checks_, inv_mass_checks_),
63  token1_(consumes<P2GTCandidateCollection>(collection1Cuts_.tag())),
64  token2_(collection1Cuts_.tag() == collection2Cuts_.tag()
65  ? token1_
66  : consumes<P2GTCandidateCollection>(collection2Cuts_.tag())),
67  primVertToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("primVertTag"))) {
68  produces<P2GTCandidateVectorRef>(collection1Cuts_.tag().instance());
69 
70  if (!(collection1Cuts_.tag() == collection2Cuts_.tag())) {
71  produces<P2GTCandidateVectorRef>(collection2Cuts_.tag().instance());
72  }
73 
74  if (inv_mass_checks_) {
75  produces<InvariantMassErrorCollection>();
76  }
77 }
78 
81 
82  edm::ParameterSetDescription collection1Desc;
84  desc.add<edm::ParameterSetDescription>("collection1", collection1Desc);
85 
86  edm::ParameterSetDescription collection2Desc;
88  desc.add<edm::ParameterSetDescription>("collection2", collection2Desc);
89 
90  desc.add<edm::InputTag>("primVertTag");
91 
92  desc.addUntracked<bool>("sanity_checks", false);
93  desc.addUntracked<bool>("inv_mass_checks", false);
94 
96  L1GTCorrelationalCut::fillLUTDescriptions(desc);
97 
100  desc.add<edm::ParameterSetDescription>("scales", scalesDesc);
101 
102  descriptions.addWithDefaultLabel(desc);
103 }
104 
106  edm::Handle<P2GTCandidateCollection> col1 = event.getHandle(token1_);
107  edm::Handle<P2GTCandidateCollection> col2 = event.getHandle(token2_);
108  edm::Handle<P2GTCandidateCollection> primVertCol = event.getHandle(primVertToken_);
109 
110  bool condition_result = false;
111 
112  std::set<std::size_t> triggeredIdcs1;
113  std::set<std::size_t> triggeredIdcs2;
114 
115  InvariantMassErrorCollection massErrors;
116 
117  for (std::size_t idx1 = 0; idx1 < col1->size(); ++idx1) {
118  bool single1Pass = collection1Cuts_.checkObject(col1->at(idx1));
119  single1Pass &= collection1Cuts_.checkPrimaryVertices(col1->at(idx1), *primVertCol);
120 
121  for (std::size_t idx2 = 0; idx2 < col2->size(); ++idx2) {
122  // If we're looking at the same collection then we shouldn't use the same object in one comparison.
123  if (col1.product() == col2.product() && idx1 == idx2) {
124  continue;
125  }
126 
127  bool pass = single1Pass;
128  pass &= collection2Cuts_.checkObject(col2->at(idx2));
129  pass &= collection2Cuts_.checkPrimaryVertices(col2->at(idx2), *primVertCol);
130  pass &= deltaCuts_.checkObjects(col1->at(idx1), col2->at(idx2), massErrors);
131 
132  condition_result |= pass;
133 
134  if (pass) {
135  triggeredIdcs1.emplace(idx1);
136  if (col1.product() != col2.product()) {
137  triggeredIdcs2.emplace(idx2);
138  } else {
139  triggeredIdcs1.emplace(idx2);
140  }
141  }
142  }
143  }
144 
145  if (condition_result) {
146  std::unique_ptr<P2GTCandidateVectorRef> triggerCol1 = std::make_unique<P2GTCandidateVectorRef>();
147 
148  for (std::size_t idx : triggeredIdcs1) {
149  triggerCol1->push_back(P2GTCandidateRef(col1, idx));
150  }
151  event.put(std::move(triggerCol1), collection1Cuts_.tag().instance());
152 
153  if (col1.product() != col2.product()) {
154  std::unique_ptr<P2GTCandidateVectorRef> triggerCol2 = std::make_unique<P2GTCandidateVectorRef>();
155 
156  for (std::size_t idx : triggeredIdcs2) {
157  triggerCol2->push_back(P2GTCandidateRef(col2, idx));
158  }
159  event.put(std::move(triggerCol2), collection2Cuts_.tag().instance());
160  }
161  }
162 
163  if (inv_mass_checks_) {
164  event.put(std::make_unique<InvariantMassErrorCollection>(std::move(massErrors)), "");
165  }
166 
167  return condition_result;
168 }
169 
const edm::EDGetTokenT< P2GTCandidateCollection > token1_
const edm::EDGetTokenT< P2GTCandidateCollection > primVertToken_
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
const L1GTCorrelationalCut deltaCuts_
bool checkObject(const P2GTCandidate &obj) const
std::vector< P2GTCandidate > P2GTCandidateCollection
Definition: P2GTCandidate.h:16
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
Definition: config.py:1
std::vector< InvariantMassError > InvariantMassErrorCollection
bool checkObjects(const P2GTCandidate &obj1, const P2GTCandidate &obj2, InvariantMassErrorCollection &massErrors) const
const edm::EDGetTokenT< P2GTCandidateCollection > token2_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static void fillDescriptions(edm::ConfigurationDescriptions &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void fillPSetDescription(edm::ParameterSetDescription &desc)
const L1GTSingleCollectionCut collection2Cuts_
L1GTDoubleObjectCond(const edm::ParameterSet &)
ParameterSet const & getParameterSet(ParameterSetID const &id)
HLT enums.
bool filter(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
const L1GTSingleCollectionCut collection1Cuts_
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1