CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
38 
39  private:
40  virtual void beginJob() ;
41  virtual void produce(edm::Event&, const edm::EventSetup&) override;
42  virtual void endJob() ;
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::auto_ptr< edm::RefVector< collection > > outputCollection_matched( new edm::RefVector< collection > );
78  std::auto_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  reco::CandidateBaseRef refBaseRef( RefRef );
119 
120  if(overlap(*CandRef,*RefRef)) {
121  ppass = true;
122  }
123  }
124 
125  if( ppass ) outputCollection_matched->push_back(CandRef);
126  else outputCollection_unmatched->push_back(CandRef);
127  }
128  }
129 
130  if( matched_ ) iEvent.put( outputCollection_matched );
131  else iEvent.put( outputCollection_unmatched );
132 
133 }
134 
135 // ------------ method called once each job just before starting event loop ------------
136 template< typename T >
138 {
139 }
140 
141 // ------------ method called once each job just after ending the event loop ------------
142 template< typename T >
144 {
145 }
146 
147 #endif
148 
149 
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
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
int iEvent
Definition: GenABIO.cc:230
edm::InputTag m_resMatchMapSource
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
edm::InputTag m_candidateSource
int j
Definition: DBlmapReader.cc:9
double f[11][100]
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:405
virtual void endJob()
virtual void beginJob()
std::vector< T > collection
MatchedProbeMaker(const edm::ParameterSet &iConfig)
virtual void produce(edm::Event &, const edm::EventSetup &) override