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 {
32  public:
33  typedef std::vector< T > collection;
34 
35  explicit MatchedProbeMaker(const edm::ParameterSet& iConfig);
36 
37  ~MatchedProbeMaker() override;
38 
39  private:
40  void beginJob() override;
41  void produce(edm::Event&, const edm::EventSetup&) override;
42  void endJob() override;
43 
44  // ----------member data ---------------------------
48 
49  bool matched_;
50 
51 };
52 
53 template< typename T >
55  m_candidateSource(iConfig.getUntrackedParameter<edm::InputTag>("CandidateSource")),
56  m_referenceSource(iConfig.getUntrackedParameter<edm::InputTag>("ReferenceSource")),
57  m_resMatchMapSource(iConfig.getUntrackedParameter<edm::InputTag>("ResMatchMapSource",edm::InputTag("Dummy"))),
58  matched_(iConfig.getUntrackedParameter< bool >("Matched",true))
59 {
60  //register your products
61  produces< edm::RefVector< collection > >();
62 }
63 
64 
65 template< typename T >
67 
68 
69 template< typename T >
71 {
72  LogDebug("MatchedProbeMaker");
73 
74  using namespace edm;
75  using namespace reco;
76 
77  std::unique_ptr<edm::RefVector< collection> > outputCollection_matched(new edm::RefVector<collection>);
78  std::unique_ptr<edm::RefVector< collection> > outputCollection_unmatched(new edm::RefVector<collection>);
79 
80  // Get the candidates from the event
82  iEvent.getByLabel(m_candidateSource,Cands);
83 
85  iEvent.getByLabel(m_referenceSource,Refs);
86 
87  // Get the resolution matching map from the event
89 
90  if(iEvent.getByLabel(m_resMatchMapSource,ResMatchMap)){
91  // Loop over the candidates looking for a match
92  for (unsigned i=0; i<Cands->size(); i++) {
93  const edm::Ref< collection > CandRef = (*Cands)[i];
94  reco::CandidateBaseRef candBaseRef( CandRef );
95 
96  // Loop over match map
97  reco::CandViewMatchMap::const_iterator f = ResMatchMap->find( candBaseRef );
98  if( f!=ResMatchMap->end() ) {
99  outputCollection_matched->push_back(CandRef);
100  } else {
101  outputCollection_unmatched->push_back(CandRef);
102  }
103  }
104  } else {
106 
107  // Loop over the candidates looking for a match
108  for (unsigned i=0; i<Cands->size(); i++) {
109  const edm::Ref< collection > CandRef = (*Cands)[i];
110  //RefToBase<Candidate> CandRef(Cands, i);
111  reco::CandidateBaseRef candBaseRef( CandRef );
112 
113  bool ppass = false;
114 
115  for (unsigned j=0; j<Refs->size(); j++) {
116  //const edm::Ref< collection > RefRef = (*Refs)[j];
117  RefToBase<Candidate> RefRef(Refs, j);
118 
119  if(overlap(*CandRef,*RefRef)) {
120  ppass = true;
121  }
122  }
123 
124  if( ppass ) outputCollection_matched->push_back(CandRef);
125  else outputCollection_unmatched->push_back(CandRef);
126  }
127  }
128 
129  if(matched_) iEvent.put(std::move(outputCollection_matched));
130  else iEvent.put(std::move(outputCollection_unmatched));
131 
132 }
133 
134 // ------------ method called once each job just before starting event loop ------------
135 template< typename T >
137 {
138 }
139 
140 // ------------ method called once each job just after ending the event loop ------------
141 template< typename T >
143 {
144 }
145 
146 #endif
147 
148 
#define LogDebug(id)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
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
bool overlap(const reco::Muon &muon1, const reco::Muon &muon2, double pullX=1.0, double pullY=1.0, bool checkAdjacentChambers=false)
edm::InputTag m_referenceSource
void beginJob() override
int iEvent
Definition: GenABIO.cc:230
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:464
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:510