CMS 3D CMS Logo

L1TStage2ObjectComparison.cc
Go to the documentation of this file.
3 
8 
12 
13 #include <algorithm>
14 
15 template <typename T>
17 
18  public:
19 
21  ~L1TStage2ObjectComparison() override = default;
22  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
23 
24  protected:
25 
26  void produce(edm::Event&, const edm::EventSetup&) override;
27 
28  private:
29 
32  const bool checkBxRange_;
33  const bool checkCollSizePerBx_;
34  const bool checkObject_;
35 
36 };
37 
38 template <typename T>
40  : token1_(consumes<BXVector<T>>(ps.getParameter<edm::InputTag>("collection1"))),
41  token2_(consumes<BXVector<T>>(ps.getParameter<edm::InputTag>("collection2"))),
42  checkBxRange_(ps.getParameter<bool>("checkBxRange")),
43  checkCollSizePerBx_(ps.getParameter<bool>("checkCollSizePerBx")),
44  checkObject_(ps.getParameter<bool>("checkObject"))
45 {
47  produces<l1t::ObjectRefBxCollection<T>>("collection1ExcessObjects");
48  produces<l1t::ObjectRefBxCollection<T>>("collection2ExcessObjects");
49  }
50  if (checkObject_) {
51  produces<l1t::ObjectRefPairBxCollection<T>>("objectMatches");
52  produces<l1t::ObjectRefPairBxCollection<T>>("objectMismatches");
53  }
54 }
55 
56 template <typename T>
58 {
60  desc.add<edm::InputTag>("collection1", edm::InputTag("collection1"))->setComment("L1T object collection 1");
61  desc.add<edm::InputTag>("collection2", edm::InputTag("collection2"))->setComment("L1T object collection 2");
62  desc.add<bool>("checkBxRange", true)->setComment("Check if BX ranges match");
63  desc.add<bool>("checkCollSizePerBx", true)->setComment("Check if collection sizes within one BX match");
64  desc.add<bool>("checkObject", true)->setComment("Check if objects match");
65  descriptions.addWithDefaultLabel(desc);
66 }
67 
68 template <typename T>
70 {
71  auto excessObjRefsColl1 = std::make_unique<l1t::ObjectRefBxCollection<T>>();
72  auto excessObjRefsColl2 = std::make_unique<l1t::ObjectRefBxCollection<T>>();
73  auto matchRefPairs = std::make_unique<l1t::ObjectRefPairBxCollection<T>>();
74  auto mismatchRefPairs = std::make_unique<l1t::ObjectRefPairBxCollection<T>>();
75 
76  edm::Handle<BXVector<T>> bxColl1;
77  edm::Handle<BXVector<T>> bxColl2;
78  e.getByToken(token1_, bxColl1);
79  e.getByToken(token2_, bxColl2);
80 
81  // Set the BX ranges like the input collection BX ranges
82  excessObjRefsColl1->setBXRange(bxColl1->getFirstBX(), bxColl1->getLastBX());
83  excessObjRefsColl2->setBXRange(bxColl2->getFirstBX(), bxColl2->getLastBX());
84  // Set the BX range to the intersection of the two input collection BX ranges
85  matchRefPairs->setBXRange(std::max(bxColl1->getFirstBX(), bxColl2->getFirstBX()), std::min(bxColl1->getLastBX(), bxColl2->getLastBX()));
86  mismatchRefPairs->setBXRange(std::max(bxColl1->getFirstBX(), bxColl2->getFirstBX()), std::min(bxColl1->getLastBX(), bxColl2->getLastBX()));
87 
88  if (checkBxRange_) {
89  // Store references to objects in BX that do not exist in the other collection
90  typename BXVector<T>::const_iterator it;
91  // BX range of collection 1 > collection 2
92  for (auto iBx = bxColl1->getFirstBX(); iBx < bxColl2->getFirstBX(); ++iBx) {
93  for (it = bxColl1->begin(iBx); it != bxColl1->end(iBx); ++it) {
94  edm::Ref<BXVector<T>> ref{bxColl1, bxColl1->key(it)};
95  excessObjRefsColl1->push_back(iBx, ref);
96  }
97  }
98  for (auto iBx = bxColl1->getLastBX(); iBx > bxColl2->getLastBX(); --iBx) {
99  for (it = bxColl1->begin(iBx); it != bxColl1->end(iBx); ++it) {
100  edm::Ref<BXVector<T>> ref{bxColl1, bxColl1->key(it)};
101  excessObjRefsColl1->push_back(iBx, ref);
102  }
103  }
104  // BX range of collection 2 > collection 1
105  for (auto iBx = bxColl2->getFirstBX(); iBx < bxColl1->getFirstBX(); ++iBx) {
106  for (it = bxColl2->begin(iBx); it != bxColl2->end(iBx); ++it) {
107  edm::Ref<BXVector<T>> ref{bxColl2, bxColl2->key(it)};
108  excessObjRefsColl2->push_back(iBx, ref);
109  }
110  }
111  for (auto iBx = bxColl2->getLastBX(); iBx > bxColl1->getLastBX(); --iBx) {
112  for (it = bxColl2->begin(iBx); it != bxColl2->end(iBx); ++it) {
113  edm::Ref<BXVector<T>> ref{bxColl2, bxColl2->key(it)};
114  excessObjRefsColl2->push_back(iBx, ref);
115  }
116  }
117  }
118 
119  // Loop over all BX that exist in both collections
120  for (int iBx = matchRefPairs->getFirstBX(); iBx <= matchRefPairs->getLastBX(); ++iBx) {
121  auto it1 = bxColl1->begin(iBx);
122  auto it2 = bxColl2->begin(iBx);
123  while (it1 != bxColl1->end(iBx) && it2 != bxColl2->end(iBx)) {
124  if (checkObject_) {
125  // Store reference pairs for matching and mismatching objects
126  edm::Ref<BXVector<T>> ref1{bxColl1, bxColl1->key(it1)};
127  edm::Ref<BXVector<T>> ref2{bxColl2, bxColl2->key(it2)};
128  if (*it1 == *it2) {
129  matchRefPairs->push_back(iBx, std::make_pair(ref1, ref2));
130  } else {
131  mismatchRefPairs->push_back(iBx, std::make_pair(ref1, ref2));
132  }
133  }
134  ++it1;
135  ++it2;
136  }
137  if (checkCollSizePerBx_) {
138  // Store references to excess objects if there are more objects in one collection (per BX)
139  while (it1 != bxColl1->end(iBx)) {
140  edm::Ref<BXVector<T>> ref{bxColl1, bxColl1->key(it1)};
141  excessObjRefsColl1->push_back(iBx, ref);
142  ++it1;
143  }
144  while (it2 != bxColl2->end(iBx)) {
145  edm::Ref<BXVector<T>> ref{bxColl2, bxColl2->key(it2)};
146  excessObjRefsColl2->push_back(iBx, ref);
147  ++it2;
148  }
149  }
150  }
151 
152  // Put data in the event
154  e.put(std::move(excessObjRefsColl1), "collection1ExcessObjects");
155  e.put(std::move(excessObjRefsColl2), "collection2ExcessObjects");
156  }
157  if (checkObject_) {
158  e.put(std::move(matchRefPairs), "objectMatches");
159  e.put(std::move(mismatchRefPairs), "objectMismatches");
160  }
161 }
162 
163 //define plugins for different L1T objects
const_iterator end(int bx) const
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
L1TStage2ObjectComparison< GlobalAlgBlk > L1TStage2GlobalAlgBlkComparison
edm::EDGetTokenT< BXVector< T > > token1_
key_type key() const
Accessor for product key.
Definition: Ref.h:263
L1TStage2ObjectComparison(const edm::ParameterSet &ps)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< BXVector< T > > token2_
void produce(edm::Event &, const edm::EventSetup &) override
L1TStage2ObjectComparison< l1t::Muon > L1TStage2MuonComparison
T min(T a, T b)
Definition: MathUtil.h:58
ParameterDescriptionBase * add(U const &iLabel, T const &value)
L1TStage2ObjectComparison< l1t::Tau > L1TStage2TauComparison
~L1TStage2ObjectComparison() override=default
L1TStage2ObjectComparison< l1t::EtSum > L1TStage2EtSumComparison
HLT enums.
L1TStage2ObjectComparison< l1t::EGamma > L1TStage2EGammaComparison
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
long double T
const_iterator begin(int bx) const
L1TStage2ObjectComparison< l1t::RegionalMuonCand > L1TStage2RegionalMuonCandComparison
L1TStage2ObjectComparison< l1t::Jet > L1TStage2JetComparison
def move(src, dest)
Definition: eostools.py:511