CMS 3D CMS Logo

MatcherByPulls.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: MuonAnalysis/MuonAssociators
4 // Class: MatcherByPulls
5 //
14 //
15 // Original Author: Giovanni Petrucciani (SNS Pisa and CERN PH-CMG)
16 // Created: Sun Nov 16 16:14:09 CET 2008
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
30 
34 
36 
38 
39 /* ____ _ _ _ _ _
40  * / ___| | __ _ ___ ___ __| | ___ ___| | __ _ _ __ __ _| |_(_) ___ _ __
41  * | | | |/ _` / __/ __| / _` |/ _ \/ __| |/ _` | '__/ _` | __| |/ _ \| '_ \
42  * | |___| | (_| \__ \__ \ | (_| | __/ (__| | (_| | | | (_| | |_| | (_) | | | |
43  * \____|_|\__,_|___/___/ \__,_|\___|\___|_|\__,_|_| \__,_|\__|_|\___/|_| |_|
44  */
45 namespace pat {
46  template <typename T>
48  public:
49  explicit MatcherByPulls(const edm::ParameterSet&);
50  ~MatcherByPulls() override;
51 
52  private:
53  void produce(edm::Event&, const edm::EventSetup&) override;
54 
57 
60 
63 
65  };
66 } // namespace pat
67 
68 /* ____ _ _
69  * / ___|___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __
70  * | | / _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__|
71  * | |__| (_) | | | \__ \ |_| | | |_| | (__| || (_) | |
72  * \____\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_|
73  *
74  */
75 template <typename T>
77  : srcToken_(consumes<edm::View<T> >(iConfig.getParameter<edm::InputTag>("src"))),
78  matchedToken_(consumes<std::vector<reco::GenParticle> >(iConfig.getParameter<edm::InputTag>("matched"))),
79  mcSel_(iConfig.getParameter<std::string>("matchedSelector")),
80  algo_(iConfig) {
81  produces<edm::Association<std::vector<reco::GenParticle> > >();
82  produces<edm::ValueMap<float> >("pulls");
83 }
84 
85 template <typename T>
87 
88 /* ____ _
89  * | _ \ _ __ ___ __| |_ _ ___ ___
90  * | |_) | '__/ _ \ / _` | | | |/ __/ _ \
91  * | __/| | | (_) | (_| | |_| | (_| __/
92  * |_| |_| \___/ \__,_|\__,_|\___\___|
93  *
94  */
95 
96 template <typename T>
98  typedef std::vector<reco::GenParticle> MCColl;
101  iEvent.getByToken(srcToken_, src);
102  iEvent.getByToken(matchedToken_, cands);
103 
104  std::vector<uint8_t> candGood(cands->size(), 1);
105  std::transform(cands->begin(), cands->end(), candGood.begin(), mcSel_);
106 
107  std::vector<int> matches(src->size(), -1);
108  std::vector<float> pulls(src->size(), 1e39);
109  for (size_t i = 0, n = src->size(); i < n; ++i) {
110  const T& tk = (*src)[i];
111  std::pair<int, float> m = algo_.match(tk, *cands, candGood);
112  matches[i] = m.first;
113  pulls[i] = m.second;
114  }
115 
116  typedef edm::Association<MCColl> MCAsso;
117  std::unique_ptr<MCAsso> matchesMap(new MCAsso(edm::RefProd<MCColl>(cands)));
118  MCAsso::Filler matchesFiller(*matchesMap);
119  matchesFiller.insert(src, matches.begin(), matches.end());
120  matchesFiller.fill();
121  iEvent.put(std::move(matchesMap));
122 
123  std::unique_ptr<edm::ValueMap<float> > pullsMap(new edm::ValueMap<float>());
124  edm::ValueMap<float>::Filler pullsFiller(*pullsMap);
125  pullsFiller.insert(src, pulls.begin(), pulls.end());
126  pullsFiller.fill();
127  iEvent.put(std::move(pullsMap), "pulls");
128 }
129 
130 //define this as a plug-in
131 
edm::RefProd
Definition: EDProductfwd.h:25
RefProd.h
MatcherByPullsAlgorithm.h
edm::helper::Filler::insert
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
mps_fire.i
i
Definition: mps_fire.py:428
pat::MatcherByPulls
Definition: MatcherByPulls.cc:47
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
EDProducer.h
sistrip::View
View
Definition: ConstantsForView.h:26
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
pat::MatcherByPulls::~MatcherByPulls
~MatcherByPulls() override
Definition: MatcherByPulls.cc:86
oniaPATMuonsWithTrigger_cff.matches
matches
Definition: oniaPATMuonsWithTrigger_cff.py:77
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
edm::helper::Filler::fill
void fill()
Definition: ValueMap.h:65
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
Association.h
edm::Handle
Definition: AssociativeIterator.h:50
GenParticle
Definition: GenParticle.py:1
pat::MatcherByPulls::matchedToken_
edm::EDGetTokenT< std::vector< reco::GenParticle > > matchedToken_
The MC objects to match against.
Definition: MatcherByPulls.cc:59
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
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HLT_FULL_cff.cands
cands
Definition: HLT_FULL_cff.py:15146
MatcherByPulls
pat::MatcherByPulls< reco::RecoCandidate > MatcherByPulls
Definition: MatcherByPulls.cc:132
edm::ParameterSet
Definition: ParameterSet.h:47
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
Event.h
pat::MatcherByPulls::srcToken_
edm::EDGetTokenT< edm::View< T > > srcToken_
The RECO objects.
Definition: MatcherByPulls.cc:56
iEvent
int iEvent
Definition: GenABIO.cc:224
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
pat::MatcherByPulls::MatcherByPulls
MatcherByPulls(const edm::ParameterSet &)
Definition: MatcherByPulls.cc:76
edm::Association
Definition: Association.h:18
edm::EventSetup
Definition: EventSetup.h:58
pat
Definition: HeavyIon.h:7
MatcherByPullsAlgorithm
Definition: MatcherByPullsAlgorithm.h:34
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
StringCutObjectSelector.h
pat::MatcherByPulls::algo_
MatcherByPullsAlgorithm algo_
Definition: MatcherByPulls.cc:64
Frameworkfwd.h
T
long double T
Definition: Basic3DVectorLD.h:48
edm::ValueMap< float >
StringCutObjectSelector< reco::GenParticle >
edm::EDProducer
Definition: EDProducer.h:35
pat::MatcherByPulls::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: MatcherByPulls.cc:97
edm::helper::Filler
Definition: ValueMap.h:22
View.h
ParameterSet.h
edm::Event
Definition: Event.h:73
TrackMatcherByPulls
pat::MatcherByPulls< reco::Track > TrackMatcherByPulls
Definition: MatcherByPulls.cc:133
pat::MatcherByPulls::mcSel_
StringCutObjectSelector< reco::GenParticle > mcSel_
Preselection cut on MC objects.
Definition: MatcherByPulls.cc:62