CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/MuonAnalysis/MuonAssociators/plugins/MatcherByPulls.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    MuonAnalysis/MuonAssociators
00004 // Class:      MatcherByPulls
00005 // 
00014 //
00015 // Original Author:  Giovanni Petrucciani (SNS Pisa and CERN PH-CMG)
00016 //         Created:  Sun Nov 16 16:14:09 CET 2008
00017 // $Id: MatcherByPulls.cc,v 1.3 2009/11/05 15:21:23 gpetrucc Exp $
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
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 //define this as a plug-in
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);