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::EDGetTokenT< edm::View< T > > srcToken_
The RECO objects.
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
pat::MatcherByPulls< reco::RecoCandidate > MatcherByPulls
StringCutObjectSelector< reco::GenParticle > mcSel_
Preselection cut on MC objects.
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< std::vector< reco::GenParticle > > matchedToken_
The MC objects to match against.
~MatcherByPulls() override
pat::MatcherByPulls< reco::Track > TrackMatcherByPulls
MatcherByPulls(const edm::ParameterSet &)
fixed size matrix
HLT enums.
void produce(edm::Event &, const edm::EventSetup &) override
MatcherByPullsAlgorithm algo_
long double T
def move(src, dest)
Definition: eostools.py:511
unsigned transform(const HcalDetId &id, unsigned transformCode)