CMS 3D CMS Logo

CandOneToManyDeltaRMatcher.cc
Go to the documentation of this file.
1 /* \class CandOneToManyDeltaRMatcher
2  *
3  * Producer for simple match map:
4  * class to match two collections of candidate
5  * with one-to-Many matching
6  * All elements of class "matched" are matched to each element
7  * of class "source" orderd in DeltaR
8  *
9  */
10 
13 
15 
16 #include <vector>
17 #include <iostream>
18 
20 public:
22  ~CandOneToManyDeltaRMatcher() override;
23 
24 private:
25  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
26 
30 };
31 
39 
45 
46 #include <Math/VectorUtil.h>
47 #include <TMath.h>
48 
49 using namespace edm;
50 using namespace std;
51 using namespace reco;
52 using namespace ROOT::Math::VectorUtil;
53 
54 namespace reco {
55  namespace helper {
56  typedef pair<size_t, double> MatchPair;
57 
58  struct SortBySecond {
59  bool operator()(const MatchPair& p1, const MatchPair& p2) const { return p1.second < p2.second; }
60  };
61  } // namespace helper
62 } // namespace reco
63 
65  : sourceToken_(consumes<CandidateCollection>(cfg.getParameter<InputTag>("src"))),
66  matchedToken_(consumes<CandidateCollection>(cfg.getParameter<InputTag>("matched"))),
67  printdebug_(cfg.getUntrackedParameter<bool>("printDebug", false)) {
68  produces<CandMatchMapMany>();
69 }
70 
72 
78 
79  if (printdebug_) {
80  for (CandidateCollection::const_iterator c = source->begin(); c != source->end(); ++c) {
81  cout << "[CandOneToManyDeltaRMatcher] Et source " << c->et() << endl;
82  }
83  for (CandidateCollection::const_iterator c = matched->begin(); c != matched->end(); ++c) {
84  cout << "[CandOneToManyDeltaRMatcher] Et matched " << c->et() << endl;
85  }
86  }
87 
88  auto matchMap = std::make_unique<CandMatchMapMany>(
90  for (size_t c = 0; c != source->size(); ++c) {
91  const Candidate& src = (*source)[c];
92  if (printdebug_)
93  cout << "[CandOneToManyDeltaRMatcher] source (Et,Eta,Phi) =(" << src.et() << "," << src.eta() << "," << src.phi()
94  << ")" << endl;
95  vector<reco::helper::MatchPair> v;
96  for (size_t m = 0; m != matched->size(); ++m) {
97  const Candidate& match = (*matched)[m];
98  double dist = DeltaR(src.p4(), match.p4());
99  v.push_back(make_pair(m, dist));
100  }
101  if (!v.empty()) {
102  sort(v.begin(), v.end(), reco::helper::SortBySecond());
103  for (size_t m = 0; m != v.size(); ++m) {
104  if (printdebug_)
105  cout << "[CandOneToManyDeltaRMatcher] match (Et,Eta,Phi) =(" << (*matched)[v[m].first].et() << ","
106  << (*matched)[v[m].first].eta() << "," << (*matched)[v[m].first].phi() << ") DeltaR=" << v[m].second
107  << endl;
108  matchMap->insert(CandidateRef(source, c), make_pair(CandidateRef(matched, v[m].first), v[m].second));
109  }
110  }
111  }
112 
113  evt.put(std::move(matchMap));
114 }
115 
118 
muonTagProbeFilters_cff.matched
matched
Definition: muonTagProbeFilters_cff.py:62
CandOneToManyDeltaRMatcher::matchedToken_
edm::EDGetTokenT< reco::CandidateCollection > matchedToken_
Definition: CandOneToManyDeltaRMatcher.cc:28
edm::StreamID
Definition: StreamID.h:30
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
CandOneToManyDeltaRMatcher::CandOneToManyDeltaRMatcher
CandOneToManyDeltaRMatcher(const edm::ParameterSet &)
Definition: CandOneToManyDeltaRMatcher.cc:64
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
CandOneToManyDeltaRMatcher::printdebug_
bool printdebug_
Definition: CandOneToManyDeltaRMatcher.cc:29
ESHandle.h
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
findQualityFiles.v
v
Definition: findQualityFiles.py:179
edm::Handle
Definition: AssociativeIterator.h:50
reco::helper::SortBySecond::operator()
bool operator()(const MatchPair &p1, const MatchPair &p2) const
Definition: CandOneToManyDeltaRMatcher.cc:59
edm::AssociationMap::ref_type
Tag::ref_type ref_type
Holds the RefProd or RefToBaseProd of 1 or 2 collections.
Definition: AssociationMap.h:63
CandMatchMap.h
CandidateFwd.h
EDMException.h
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
source
static const std::string source
Definition: EdmProvDump.cc:47
p2
double p2[4]
Definition: TauolaWrapper.h:90
LeafCandidate.h
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:535
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:112
edm::OwnVector::const_iterator
Definition: OwnVector.h:41
edm::global::EDProducer
Definition: EDProducer.h:32
CandOneToManyDeltaRMatcher::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: CandOneToManyDeltaRMatcher.cc:73
edm::ParameterSet
Definition: ParameterSet.h:47
reco::helper::SortBySecond
Definition: CandOneToManyDeltaRMatcher.cc:58
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
Event.h
CandOneToManyDeltaRMatcher
Definition: CandOneToManyDeltaRMatcher.cc:19
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
helper
Definition: helper.py:1
ModuleDef.h
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
CandOneToManyDeltaRMatcher::sourceToken_
edm::EDGetTokenT< reco::CandidateCollection > sourceToken_
Definition: CandOneToManyDeltaRMatcher.cc:27
p1
double p1[4]
Definition: TauolaWrapper.h:89
edm::EventSetup
Definition: EventSetup.h:58
electronAnalyzer_cfi.DeltaR
DeltaR
Definition: electronAnalyzer_cfi.py:33
InputTag.h
looper.cfg
cfg
Definition: looper.py:297
reco::Candidate
Definition: Candidate.h:27
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
CandOneToManyDeltaRMatcher::~CandOneToManyDeltaRMatcher
~CandOneToManyDeltaRMatcher() override
Definition: CandOneToManyDeltaRMatcher.cc:71
ParameterSetfwd.h
EventSetup.h
reco::CandidateRef
edm::Ref< CandidateCollection > CandidateRef
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:29
Candidate.h
ParameterSet.h
EDProducer.h
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
reco::helper::MatchPair
pair< size_t, double > MatchPair
Definition: CandOneToManyDeltaRMatcher.cc:56
edm::Event
Definition: Event.h:73
CandMatchMapMany.h
edm::InputTag
Definition: InputTag.h:15
edm::OwnVector
Definition: OwnVector.h:24
reco::CandidateRefProd
edm::RefProd< CandidateCollection > CandidateRefProd
reference to a collection of Candidate objects
Definition: CandidateFwd.h:37