CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // $Id: MatcherByPulls.cc,v 1.4 2013/02/27 20:42:45 wmtan Exp $
18 //
19 
20 
21 // system include files
22 #include <memory>
23 
24 // user include files
27 
30 
32 
36 
38 
40 
41 /* ____ _ _ _ _ _
42  * / ___| | __ _ ___ ___ __| | ___ ___| | __ _ _ __ __ _| |_(_) ___ _ __
43  * | | | |/ _` / __/ __| / _` |/ _ \/ __| |/ _` | '__/ _` | __| |/ _ \| '_ \
44  * | |___| | (_| \__ \__ \ | (_| | __/ (__| | (_| | | | (_| | |_| | (_) | | | |
45  * \____|_|\__,_|___/___/ \__,_|\___|\___|_|\__,_|_| \__,_|\__|_|\___/|_| |_|
46  */
47 namespace pat {
48  template<typename T>
50  public:
51  explicit MatcherByPulls(const edm::ParameterSet&);
53 
54  private:
55  virtual void produce(edm::Event&, const edm::EventSetup&) override;
56 
59 
62 
65 
67  };
68 }
69 
70 /* ____ _ _
71  * / ___|___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __
72  * | | / _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__|
73  * | |__| (_) | | | \__ \ |_| | | |_| | (__| || (_) | |
74  * \____\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_|
75  *
76  */
77 template<typename T>
79  src_(iConfig.getParameter<edm::InputTag>("src")),
80  matched_(iConfig.getParameter<edm::InputTag>("matched")),
81  mcSel_(iConfig.getParameter<std::string>("matchedSelector")),
82  algo_(iConfig)
83 {
84  produces<edm::Association<std::vector<reco::GenParticle> > >();
85  produces<edm::ValueMap<float> >("pulls");
86 }
87 
88 template<typename T>
90 {
91 }
92 
93 /* ____ _
94  * | _ \ _ __ ___ __| |_ _ ___ ___
95  * | |_) | '__/ _ \ / _` | | | |/ __/ _ \
96  * | __/| | | (_) | (_| | |_| | (_| __/
97  * |_| |_| \___/ \__,_|\__,_|\___\___|
98  *
99  */
100 
101 template<typename T>
102 void
104 {
105  typedef std::vector<reco::GenParticle> MCColl;
107  edm::Handle<MCColl> cands;
108  iEvent.getByLabel(src_, src);
109  iEvent.getByLabel(matched_, cands);
110 
111  std::vector<uint8_t> candGood(cands->size(),1);
112  std::transform(cands->begin(), cands->end(), candGood.begin(), mcSel_);
113 
114  std::vector<int> matches(src->size(),-1);
115  std::vector<float> pulls(src->size(), 1e39);
116  for (size_t i = 0, n = src->size(); i < n; ++i) {
117  const T &tk = (*src)[i];
118  std::pair<int,float> m = algo_.match(tk, *cands, candGood);
119  matches[i] = m.first;
120  pulls[i] = m.second;
121  }
122 
123  typedef edm::Association<MCColl> MCAsso;
124  std::auto_ptr<MCAsso> matchesMap(new MCAsso(edm::RefProd<MCColl>(cands)));
125  MCAsso::Filler matchesFiller(*matchesMap);
126  matchesFiller.insert(src, matches.begin(), matches.end());
127  matchesFiller.fill();
128  iEvent.put(matchesMap);
129 
130  std::auto_ptr<edm::ValueMap<float> > pullsMap(new edm::ValueMap<float>());
131  edm::ValueMap<float>::Filler pullsFiller(*pullsMap);
132  pullsFiller.insert(src, pulls.begin(), pulls.end());
133  pullsFiller.fill();
134  iEvent.put(pullsMap, "pulls");
135 }
136 
137 //define this as a plug-in
138 
int i
Definition: DBlmapReader.cc:9
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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.
edm::InputTag matched_
The MC objects to match against.
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
pat::MatcherByPulls< reco::Track > TrackMatcherByPulls
MatcherByPulls(const edm::ParameterSet &)
virtual void produce(edm::Event &, const edm::EventSetup &) override
edm::InputTag src_
The RECO objects.
MatcherByPullsAlgorithm algo_
long double T