CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoMuon/MuonIdentification/plugins/MuonSelectionTypeValueMapProducer.h

Go to the documentation of this file.
00001 #ifndef MuonIdentification_MuonSelectionTypeValueMapProducer_h
00002 #define MuonIdentification_MuonSelectionTypeValueMapProducer_h
00003 
00004 #include <string>
00005 #include <vector>
00006 
00007 #include "DataFormats/Common/interface/ValueMap.h"
00008 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00009 #include "DataFormats/MuonReco/interface/MuonSelectors.h"
00010 
00011 #include "FWCore/Framework/interface/EDProducer.h"
00012 #include "FWCore/Framework/interface/Event.h"
00013 #include "FWCore/Framework/interface/EventSetup.h"
00014 #include "FWCore/Framework/interface/Frameworkfwd.h"
00015 #include "FWCore/Framework/interface/MakerMacros.h"
00016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00017 
00018 class MuonSelectionTypeValueMapProducer : public edm::EDProducer {
00019     public:
00020         explicit MuonSelectionTypeValueMapProducer(const edm::ParameterSet& iConfig) :
00021             inputMuonCollection_(iConfig.getParameter<edm::InputTag>("inputMuonCollection")),
00022             selectionTypeLabel_(iConfig.getParameter<std::string>("selectionType"))
00023         {
00024             selectionType_ = muon::selectionTypeFromString(selectionTypeLabel_);
00025             produces<edm::ValueMap<bool> >().setBranchAlias("muid"+selectionTypeLabel_);
00026         }
00027         virtual ~MuonSelectionTypeValueMapProducer() {}
00028 
00029     private:
00030         virtual void produce(edm::Event&, const edm::EventSetup&);
00031 
00032         edm::InputTag inputMuonCollection_;
00033         std::string selectionTypeLabel_;
00034         muon::SelectionType selectionType_;
00035 };
00036 
00037 void
00038 MuonSelectionTypeValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00039 {
00040     // input muon collection
00041     edm::Handle<reco::MuonCollection> muonsH;
00042     iEvent.getByLabel(inputMuonCollection_, muonsH);
00043 
00044     // reserve some space
00045     std::vector<bool> values;
00046     values.reserve(muonsH->size());
00047 
00048     // isGoodMuon
00049     for(reco::MuonCollection::const_iterator it = muonsH->begin(); it != muonsH->end(); ++it)
00050         values.push_back(muon::isGoodMuon(*it, selectionType_));
00051 
00052     // create and fill value map
00053     std::auto_ptr<edm::ValueMap<bool> > out(new edm::ValueMap<bool>());
00054     edm::ValueMap<bool>::Filler filler(*out);
00055     filler.insert(muonsH, values.begin(), values.end());
00056     filler.fill();
00057 
00058     // put value map into event
00059     iEvent.put(out);
00060 }
00061 
00062 #endif