diff --git a/SimMuon/MCTruth/plugins/SimMuFilter.cc b/SimMuon/MCTruth/plugins/SimMuFilter.cc new file mode 100644 index 0000000000000..e3cad7fbcb91d --- /dev/null +++ b/SimMuon/MCTruth/plugins/SimMuFilter.cc @@ -0,0 +1,110 @@ +#include "FWCore/Framework/interface/stream/EDFilter.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "SimDataFormats/Track/interface/SimTrackContainer.h" +#include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h" + +class SimMuFilter : public edm::stream::EDFilter<> +{ + public: + + explicit SimMuFilter(const edm::ParameterSet&); + ~SimMuFilter(); + + private: + + virtual void beginJob(); + virtual void endJob(); + virtual bool filter(edm::Event&, const edm::EventSetup&); + + private: + + edm::EDGetTokenT > simTracksToken_; + edm::EDGetTokenT simHitsMuonRPCToken_; + edm::EDGetTokenT simHitsMuonCSCToken_; + edm::EDGetTokenT simHitsMuonDTToken_; + + edm::Handle > simTracksHandle; + edm::Handle simHitsMuonRPCHandle; + edm::Handle simHitsMuonCSCHandle; + edm::Handle simHitsMuonDTHandle; +}; + +SimMuFilter::SimMuFilter(const edm::ParameterSet& iConfig) +{ + simTracksToken_ = consumes >(iConfig.getParameter("simTracksInput")); + simHitsMuonRPCToken_ = consumes(iConfig.getParameter("simHitsMuonRPCInput")); + simHitsMuonCSCToken_ = consumes(iConfig.getParameter("simHitsMuonCSCInput")); + simHitsMuonDTToken_ = consumes(iConfig.getParameter("simHitsMuonDTInput")); +} + +SimMuFilter::~SimMuFilter() +{ +} + +bool SimMuFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) +{ + using namespace edm; + + iEvent.getByToken(simTracksToken_,simTracksHandle); + iEvent.getByToken(simHitsMuonRPCToken_,simHitsMuonRPCHandle); + iEvent.getByToken(simHitsMuonCSCToken_,simHitsMuonCSCHandle); + iEvent.getByToken(simHitsMuonDTToken_,simHitsMuonDTHandle); + + const std::vector &simTracks = *simTracksHandle.product(); + + int nTracks = simTracks.size(); + + bool pass = 0; + + for(int it=0;itbegin();simHitIt!=simHitsMuonRPCHandle->end();simHitIt++ ) + { + if( simHitIt->trackId() != simTrk.trackId() ) continue; + + nSimHitRPC++; + } + + for( PSimHitContainer::const_iterator simHitIt = simHitsMuonCSCHandle->begin();simHitIt!=simHitsMuonCSCHandle->end();simHitIt++ ) + { + if( simHitIt->trackId() != simTrk.trackId() ) continue; + + nSimHitCSC++; + } + + for( PSimHitContainer::const_iterator simHitIt = simHitsMuonDTHandle->begin();simHitIt!=simHitsMuonDTHandle->end();simHitIt++ ) + { + if( simHitIt->trackId() != simTrk.trackId() ) continue; + + nSimHitDT++; + } + + if( nSimHitRPC+nSimHitCSC+nSimHitDT > 0 ) pass = 1; + } + + return pass; +} + +void SimMuFilter::beginJob() +{ +} + +void SimMuFilter::endJob() +{ +} + +//define this as a plug-in +DEFINE_FWK_MODULE(SimMuFilter); + diff --git a/SimMuon/MCTruth/python/SimMuFilter_cfi.py b/SimMuon/MCTruth/python/SimMuFilter_cfi.py new file mode 100644 index 0000000000000..467f9d5418969 --- /dev/null +++ b/SimMuon/MCTruth/python/SimMuFilter_cfi.py @@ -0,0 +1,10 @@ +import FWCore.ParameterSet.Config as cms + +SimMuFilter = cms.EDFilter('SimMuFilter', + + simTracksInput = cms.InputTag("g4SimHits","","SIM"), + simHitsMuonRPCInput = cms.InputTag("g4SimHits","MuonRPCHits","SIM"), + simHitsMuonCSCInput = cms.InputTag("g4SimHits","MuonCSCHits","SIM"), + simHitsMuonDTInput = cms.InputTag("g4SimHits","MuonDTHits","SIM") +) + diff --git a/SimMuon/MCTruth/test/SimMuFilter_cfg.py b/SimMuon/MCTruth/test/SimMuFilter_cfg.py new file mode 100644 index 0000000000000..679ca5a770420 --- /dev/null +++ b/SimMuon/MCTruth/test/SimMuFilter_cfg.py @@ -0,0 +1,9 @@ +import FWCore.ParameterSet.Config as cms + +from SimMuon.MCTruth.SimMuFilter_cfi import * + +process = cms.Process("SimFilter") + +process.filter = SimMuFilter + +process.p = cms.Path(process.filter)