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
MatchedProbeMaker::matched_
bool matched_
Definition: MatchedProbeMaker.h:48
OverlapChecker
Definition: OverlapChecker.h:17
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:372
edm::AssociationMap::find
const_iterator find(const key_type &k) const
find element with specified reference key
Definition: AssociationMap.h:173
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
EDProducer.h
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
MatchedProbeMaker::m_referenceSource
edm::InputTag m_referenceSource
Definition: MatchedProbeMaker.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
MatchedProbeMaker::m_resMatchMapSource
edm::InputTag m_resMatchMapSource
Definition: MatchedProbeMaker.h:46
edm::RefVector
Definition: EDProductfwd.h:27
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
CandMatchMap.h
edm::Ref
Definition: AssociativeIterator.h:58
CandidateFwd.h
deltaR.h
edm::AssociationMap::end
const_iterator end() const
last iterator over the map (read only)
Definition: AssociationMap.h:171
edm::View::size
size_type size() const
funct::true
true
Definition: Factorize.h:173
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
RefVector.h
Event.h
iEvent
int iEvent
Definition: GenABIO.cc:224
MatchedProbeMaker::MatchedProbeMaker
MatchedProbeMaker(const edm::ParameterSet &iConfig)
Definition: MatchedProbeMaker.h:52
MatchedProbeMaker::beginJob
void beginJob() override
Definition: MatchedProbeMaker.h:133
goodZToMuMu_cfi.overlap
overlap
Definition: goodZToMuMu_cfi.py:108
edm::EventSetup
Definition: EventSetup.h:57
MatchedProbeMaker
Definition: MatchedProbeMaker.h:30
MatchedProbeMaker::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: MatchedProbeMaker.h:65
InputTag.h
MatchedProbeMaker::m_candidateSource
edm::InputTag m_candidateSource
Definition: MatchedProbeMaker.h:44
eostools.move
def move(src, dest)
Definition: eostools.py:511
Ref.h
MatchedProbeMaker::~MatchedProbeMaker
~MatchedProbeMaker() override
Definition: MatchedProbeMaker.h:62
Frameworkfwd.h
edm::EDProducer
Definition: EDProducer.h:36
edm::RefToBase< Candidate >
OverlapChecker.h
Candidate.h
ParameterSet.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
edm::AssociationMap::const_iterator
const iterator
Definition: AssociationMap.h:76
edm::InputTag
Definition: InputTag.h:15
MatchedProbeMaker::endJob
void endJob() override
Definition: MatchedProbeMaker.h:137
MatchedProbeMaker::collection
std::vector< T > collection
Definition: MatchedProbeMaker.h:32