Go to the documentation of this file.00001
00002
00003
00004
00005
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <memory>
00023
00024
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDProducer.h"
00027
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032
00033 #include "DataFormats/Common/interface/Association.h"
00034 #include "DataFormats/Common/interface/View.h"
00035 #include "DataFormats/Common/interface/RefProd.h"
00036
00037 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
00038
00039 #include "MuonAnalysis/MuonAssociators/interface/MatcherByPullsAlgorithm.h"
00040
00041
00042
00043
00044
00045
00046
00047 namespace pat {
00048 template<typename T>
00049 class MatcherByPulls : public edm::EDProducer {
00050 public:
00051 explicit MatcherByPulls(const edm::ParameterSet&);
00052 ~MatcherByPulls();
00053
00054 private:
00055 virtual void produce(edm::Event&, const edm::EventSetup&);
00056
00058 edm::InputTag src_;
00059
00061 edm::InputTag matched_;
00062
00064 StringCutObjectSelector<reco::GenParticle> mcSel_;
00065
00066 MatcherByPullsAlgorithm algo_;
00067 };
00068 }
00069
00070
00071
00072
00073
00074
00075
00076
00077 template<typename T>
00078 pat::MatcherByPulls<T>::MatcherByPulls(const edm::ParameterSet &iConfig) :
00079 src_(iConfig.getParameter<edm::InputTag>("src")),
00080 matched_(iConfig.getParameter<edm::InputTag>("matched")),
00081 mcSel_(iConfig.getParameter<std::string>("matchedSelector")),
00082 algo_(iConfig)
00083 {
00084 produces<edm::Association<std::vector<reco::GenParticle> > >();
00085 produces<edm::ValueMap<float> >("pulls");
00086 }
00087
00088 template<typename T>
00089 pat::MatcherByPulls<T>::~MatcherByPulls()
00090 {
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 template<typename T>
00102 void
00103 pat::MatcherByPulls<T>::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00104 {
00105 typedef std::vector<reco::GenParticle> MCColl;
00106 edm::Handle<edm::View<T> > src;
00107 edm::Handle<MCColl> cands;
00108 iEvent.getByLabel(src_, src);
00109 iEvent.getByLabel(matched_, cands);
00110
00111 std::vector<uint8_t> candGood(cands->size(),1);
00112 std::transform(cands->begin(), cands->end(), candGood.begin(), mcSel_);
00113
00114 std::vector<int> matches(src->size(),-1);
00115 std::vector<float> pulls(src->size(), 1e39);
00116 for (size_t i = 0, n = src->size(); i < n; ++i) {
00117 const T &tk = (*src)[i];
00118 std::pair<int,float> m = algo_.match(tk, *cands, candGood);
00119 matches[i] = m.first;
00120 pulls[i] = m.second;
00121 }
00122
00123 typedef edm::Association<MCColl> MCAsso;
00124 std::auto_ptr<MCAsso> matchesMap(new MCAsso(edm::RefProd<MCColl>(cands)));
00125 MCAsso::Filler matchesFiller(*matchesMap);
00126 matchesFiller.insert(src, matches.begin(), matches.end());
00127 matchesFiller.fill();
00128 iEvent.put(matchesMap);
00129
00130 std::auto_ptr<edm::ValueMap<float> > pullsMap(new edm::ValueMap<float>());
00131 edm::ValueMap<float>::Filler pullsFiller(*pullsMap);
00132 pullsFiller.insert(src, pulls.begin(), pulls.end());
00133 pullsFiller.fill();
00134 iEvent.put(pullsMap, "pulls");
00135 }
00136
00137
00138
00139 typedef pat::MatcherByPulls<reco::RecoCandidate> MatcherByPulls;
00140 typedef pat::MatcherByPulls<reco::Track> TrackMatcherByPulls;
00141 DEFINE_FWK_MODULE(MatcherByPulls);
00142 DEFINE_FWK_MODULE(TrackMatcherByPulls);