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 //
18 
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
29 
31 
35 
37 
39 
40 /* ____ _ _ _ _ _
41  * / ___| | __ _ ___ ___ __| | ___ ___| | __ _ _ __ __ _| |_(_) ___ _ __
42  * | | | |/ _` / __/ __| / _` |/ _ \/ __| |/ _` | '__/ _` | __| |/ _ \| '_ \
43  * | |___| | (_| \__ \__ \ | (_| | __/ (__| | (_| | | | (_| | |_| | (_) | | | |
44  * \____|_|\__,_|___/___/ \__,_|\___|\___|_|\__,_|_| \__,_|\__|_|\___/|_| |_|
45  */
46 namespace pat {
47  template<typename T>
49  public:
50  explicit MatcherByPulls(const edm::ParameterSet&);
52 
53  private:
54  virtual void produce(edm::Event&, const edm::EventSetup&) override;
55 
58 
61 
64 
66  };
67 }
68 
69 /* ____ _ _
70  * / ___|___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __
71  * | | / _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__|
72  * | |__| (_) | | | \__ \ |_| | | |_| | (__| || (_) | |
73  * \____\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_|
74  *
75  */
76 template<typename T>
78  srcToken_(consumes<edm::View<T> >(iConfig.getParameter<edm::InputTag>("src"))),
79  matchedToken_(consumes<std::vector<reco::GenParticle> >(iConfig.getParameter<edm::InputTag>("matched"))),
80  mcSel_(iConfig.getParameter<std::string>("matchedSelector")),
81  algo_(iConfig)
82 {
83  produces<edm::Association<std::vector<reco::GenParticle> > >();
84  produces<edm::ValueMap<float> >("pulls");
85 }
86 
87 template<typename T>
89 {
90 }
91 
92 /* ____ _
93  * | _ \ _ __ ___ __| |_ _ ___ ___
94  * | |_) | '__/ _ \ / _` | | | |/ __/ _ \
95  * | __/| | | (_) | (_| | |_| | (_| __/
96  * |_| |_| \___/ \__,_|\__,_|\___\___|
97  *
98  */
99 
100 template<typename T>
101 void
103 {
104  typedef std::vector<reco::GenParticle> MCColl;
106  edm::Handle<MCColl> cands;
107  iEvent.getByToken(srcToken_, src);
108  iEvent.getByToken(matchedToken_, cands);
109 
110  std::vector<uint8_t> candGood(cands->size(),1);
111  std::transform(cands->begin(), cands->end(), candGood.begin(), mcSel_);
112 
113  std::vector<int> matches(src->size(),-1);
114  std::vector<float> pulls(src->size(), 1e39);
115  for (size_t i = 0, n = src->size(); i < n; ++i) {
116  const T &tk = (*src)[i];
117  std::pair<int,float> m = algo_.match(tk, *cands, candGood);
118  matches[i] = m.first;
119  pulls[i] = m.second;
120  }
121 
122  typedef edm::Association<MCColl> MCAsso;
123  std::auto_ptr<MCAsso> matchesMap(new MCAsso(edm::RefProd<MCColl>(cands)));
124  MCAsso::Filler matchesFiller(*matchesMap);
125  matchesFiller.insert(src, matches.begin(), matches.end());
126  matchesFiller.fill();
127  iEvent.put(matchesMap);
128 
129  std::auto_ptr<edm::ValueMap<float> > pullsMap(new edm::ValueMap<float>());
130  edm::ValueMap<float>::Filler pullsFiller(*pullsMap);
131  pullsFiller.insert(src, pulls.begin(), pulls.end());
132  pullsFiller.fill();
133  iEvent.put(pullsMap, "pulls");
134 }
135 
136 //define this as a plug-in
137 
int i
Definition: DBlmapReader.cc:9
algo_(conf.existsAs< bool >("Correct")?conf.getParameter< bool >("Correct"):true, conf.getParameter< double >("e9e25Cut"), conf.getParameter< double >("intercept2DCut"), conf.existsAs< bool >("intercept2DSlope")?conf.getParameter< double >("intercept2DSlope"):defaultSlope2D_, conf.getParameter< std::vector< double > >("e1e9Cut"), conf.getParameter< std::vector< double > >("eCOREe9Cut"), conf.getParameter< std::vector< double > >("eSeLCut"), hfvars_)
edm::EDGetTokenT< edm::View< T > > srcToken_
The RECO objects.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
pat::MatcherByPulls< reco::RecoCandidate > MatcherByPulls
StringCutObjectSelector< reco::GenParticle > mcSel_
Preselection cut on MC objects.
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:115
edm::EDGetTokenT< std::vector< reco::GenParticle > > matchedToken_
The MC objects to match against.
pat::MatcherByPulls< reco::Track > TrackMatcherByPulls
MatcherByPulls(const edm::ParameterSet &)
virtual void produce(edm::Event &, const edm::EventSetup &) override
MatcherByPullsAlgorithm algo_
long double T