Go to the documentation of this file.00001 #include <string>
00002 #include <vector>
00003
00004 #include "DataFormats/Common/interface/ValueMap.h"
00005 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00006 #include "DataFormats/MuonReco/interface/Muon.h"
00007 #include "DataFormats/TrackReco/interface/Track.h"
00008 #include "RecoMuon/MuonIdentification/interface/MuonCosmicsId.h"
00009
00010 #include "FWCore/Framework/interface/EDProducer.h"
00011 #include "FWCore/Framework/interface/Event.h"
00012 #include "FWCore/Framework/interface/EventSetup.h"
00013 #include "FWCore/Framework/interface/Frameworkfwd.h"
00014 #include "FWCore/Framework/interface/MakerMacros.h"
00015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00016
00017 #include "RecoMuon/MuonIdentification/interface/MuonCosmicCompatibilityFiller.h"
00018
00019 class CosmicsMuonIdProducer : public edm::EDProducer {
00020 public:
00021 CosmicsMuonIdProducer(const edm::ParameterSet& iConfig) :
00022 inputMuonCollection_(iConfig.getParameter<edm::InputTag>("muonCollection")),
00023 inputTrackCollections_(iConfig.getParameter<std::vector<edm::InputTag> >("trackCollections")),
00024 compatibilityFiller_(iConfig.getParameter<edm::ParameterSet>("CosmicCompFillerParameters"))
00025 {
00026 produces<edm::ValueMap<unsigned int> >().setBranchAlias("cosmicsVeto");
00027 produces<edm::ValueMap<reco::MuonCosmicCompatibility> >().setBranchAlias("cosmicCompatibility");
00028 }
00029 virtual ~CosmicsMuonIdProducer() {}
00030
00031 private:
00032 virtual void produce(edm::Event&, const edm::EventSetup&);
00033 edm::InputTag inputMuonCollection_;
00034 std::vector<edm::InputTag> inputTrackCollections_;
00035 MuonCosmicCompatibilityFiller compatibilityFiller_;
00036 };
00037
00038 void
00039 CosmicsMuonIdProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00040 {
00041 edm::Handle<reco::MuonCollection> muons;
00042 iEvent.getByLabel(inputMuonCollection_, muons);
00043
00044 std::vector<unsigned int> values;
00045 values.reserve(muons->size());
00046
00047 std::vector<reco::MuonCosmicCompatibility> compValues;
00048 compValues.reserve(muons->size());
00049
00050 for(reco::MuonCollection::const_iterator muon = muons->begin();
00051 muon != muons->end(); ++muon)
00052 {
00053 unsigned int foundPartner(0);
00054 if ( muon->innerTrack().isNonnull() ){
00055 for ( unsigned int i=0; i<inputTrackCollections_.size(); ++i )
00056 {
00057 edm::Handle<reco::TrackCollection> tracks;
00058 iEvent.getByLabel(inputTrackCollections_.at(i), tracks);
00059 if ( muonid::findOppositeTrack(tracks,*muon->innerTrack()).isNonnull() ){
00060 foundPartner = i+1;
00061 break;
00062 }
00063 }
00064 }
00065 values.push_back(foundPartner);
00066
00067 compValues.push_back(compatibilityFiller_.fillCompatibility(*muon, iEvent, iSetup));
00068 }
00069
00070
00071 std::auto_ptr<edm::ValueMap<unsigned int> > out(new edm::ValueMap<unsigned int>());
00072 edm::ValueMap<unsigned int>::Filler filler(*out);
00073 filler.insert(muons, values.begin(), values.end());
00074 filler.fill();
00075
00076
00077 std::auto_ptr<edm::ValueMap<reco::MuonCosmicCompatibility> > outC(new edm::ValueMap<reco::MuonCosmicCompatibility>());
00078 edm::ValueMap<reco::MuonCosmicCompatibility>::Filler fillerC(*outC);
00079 fillerC.insert(muons, compValues.begin(), compValues.end());
00080 fillerC.fill();
00081
00082
00083 iEvent.put(out);
00084 iEvent.put(outC);
00085 }
00086 DEFINE_FWK_MODULE(CosmicsMuonIdProducer);