CMS 3D CMS Logo

MatchedProbeMaker.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_TagAndProbe_MatchedProbeMaker_H
2 #define PhysicsTools_TagAndProbe_MatchedProbeMaker_H
3 
4 // system include files
5 #include <memory>
6 #include <vector>
7 
8 // user include files
24 
25 //
26 // class decleration
27 //
28 
29 template <typename T>
31 public:
32  typedef std::vector<T> collection;
33 
34  explicit MatchedProbeMaker(const edm::ParameterSet& iConfig);
35 
36  ~MatchedProbeMaker() override;
37 
38 private:
39  void beginJob() override;
40  void produce(edm::Event&, const edm::EventSetup&) override;
41  void endJob() override;
42 
43  // ----------member data ---------------------------
47 
48  bool matched_;
49 };
50 
51 template <typename T>
53  : m_candidateSource(iConfig.getUntrackedParameter<edm::InputTag>("CandidateSource")),
54  m_referenceSource(iConfig.getUntrackedParameter<edm::InputTag>("ReferenceSource")),
55  m_resMatchMapSource(iConfig.getUntrackedParameter<edm::InputTag>("ResMatchMapSource", edm::InputTag("Dummy"))),
56  matched_(iConfig.getUntrackedParameter<bool>("Matched", true)) {
57  //register your products
58  produces<edm::RefVector<collection> >();
59 }
60 
61 template <typename T>
63 
64 template <typename T>
66  LogDebug("MatchedProbeMaker");
67 
68  using namespace edm;
69  using namespace reco;
70 
71  std::unique_ptr<edm::RefVector<collection> > outputCollection_matched(new edm::RefVector<collection>);
72  std::unique_ptr<edm::RefVector<collection> > outputCollection_unmatched(new edm::RefVector<collection>);
73 
74  // Get the candidates from the event
76  iEvent.getByLabel(m_candidateSource, Cands);
77 
79  iEvent.getByLabel(m_referenceSource, Refs);
80 
81  // Get the resolution matching map from the event
83 
84  if (iEvent.getByLabel(m_resMatchMapSource, ResMatchMap)) {
85  // Loop over the candidates looking for a match
86  for (unsigned i = 0; i < Cands->size(); i++) {
87  const edm::Ref<collection> CandRef = (*Cands)[i];
88  reco::CandidateBaseRef candBaseRef(CandRef);
89 
90  // Loop over match map
91  reco::CandViewMatchMap::const_iterator f = ResMatchMap->find(candBaseRef);
92  if (f != ResMatchMap->end()) {
93  outputCollection_matched->push_back(CandRef);
94  } else {
95  outputCollection_unmatched->push_back(CandRef);
96  }
97  }
98  } else {
100 
101  // Loop over the candidates looking for a match
102  for (unsigned i = 0; i < Cands->size(); i++) {
103  const edm::Ref<collection> CandRef = (*Cands)[i];
104  //RefToBase<Candidate> CandRef(Cands, i);
105  reco::CandidateBaseRef candBaseRef(CandRef);
106 
107  bool ppass = false;
108 
109  for (unsigned j = 0; j < Refs->size(); j++) {
110  //const edm::Ref< collection > RefRef = (*Refs)[j];
111  RefToBase<Candidate> RefRef(Refs, j);
112 
113  if (overlap(*CandRef, *RefRef)) {
114  ppass = true;
115  }
116  }
117 
118  if (ppass)
119  outputCollection_matched->push_back(CandRef);
120  else
121  outputCollection_unmatched->push_back(CandRef);
122  }
123  }
124 
125  if (matched_)
126  iEvent.put(std::move(outputCollection_matched));
127  else
128  iEvent.put(std::move(outputCollection_unmatched));
129 }
130 
131 // ------------ method called once each job just before starting event loop ------------
132 template <typename T>
134 
135 // ------------ method called once each job just after ending the event loop ------------
136 template <typename T>
138 
139 #endif
#define LogDebug(id)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
void endJob() override
const_iterator end() const
last iterator over the map (read only)
const_iterator find(const key_type &k) const
find element with specified reference key
size_type size() const
edm::InputTag m_referenceSource
void beginJob() override
int iEvent
Definition: GenABIO.cc:224
edm::InputTag m_resMatchMapSource
edm::InputTag m_candidateSource
~MatchedProbeMaker() override
double f[11][100]
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:488
std::vector< T > collection
fixed size matrix
HLT enums.
MatchedProbeMaker(const edm::ParameterSet &iConfig)
void produce(edm::Event &, const edm::EventSetup &) override
def move(src, dest)
Definition: eostools.py:511