Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:27:00

0001 #include "RecoMuon/MuonIdentification/plugins/InterestingEcalDetIdProducer.h"
0002 
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/EventSetup.h"
0006 #include "FWCore/Framework/interface/ESHandle.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 
0009 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0010 
0011 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0012 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0013 
0014 #include "DataFormats/DetId/interface/DetIdCollection.h"
0015 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
0016 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
0017 
0018 #include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h"
0019 
0020 InterestingEcalDetIdProducer::InterestingEcalDetIdProducer(const edm::ParameterSet& iConfig) {
0021   inputCollection_ = iConfig.getParameter<edm::InputTag>("inputCollection");
0022   produces<DetIdCollection>();
0023   muonToken_ = consumes<reco::MuonCollection>(inputCollection_);
0024   caloTopoToken_ = esConsumes<CaloTopology, CaloTopologyRecord, edm::Transition::BeginRun>();
0025 }
0026 
0027 InterestingEcalDetIdProducer::~InterestingEcalDetIdProducer() {}
0028 
0029 void InterestingEcalDetIdProducer::beginRun(const edm::Run& run, const edm::EventSetup& iSetup) {
0030   edm::ESHandle<CaloTopology> theCaloTopology = iSetup.getHandle(caloTopoToken_);
0031   caloTopology_ = &(*theCaloTopology);
0032 }
0033 
0034 void InterestingEcalDetIdProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0035   edm::Handle<reco::MuonCollection> muons;
0036   iEvent.getByToken(muonToken_, muons);
0037 
0038   auto interestingDetIdCollection = std::make_unique<DetIdCollection>();
0039 
0040   for (reco::MuonCollection::const_iterator muon = muons->begin(); muon != muons->end(); ++muon) {
0041     if (!muon->isEnergyValid())
0042       continue;
0043     if (muon->calEnergy().ecal_id.rawId() == 0)
0044       continue;
0045     const CaloSubdetectorTopology* topology =
0046         caloTopology_->getSubdetectorTopology(DetId::Ecal, muon->calEnergy().ecal_id.subdetId());
0047     const std::vector<DetId>& ids = topology->getWindow(muon->calEnergy().ecal_id, 5, 5);
0048     for (std::vector<DetId>::const_iterator id = ids.begin(); id != ids.end(); ++id)
0049       if (std::find(interestingDetIdCollection->begin(), interestingDetIdCollection->end(), *id) ==
0050           interestingDetIdCollection->end())
0051         interestingDetIdCollection->push_back(*id);
0052   }
0053   iEvent.put(std::move(interestingDetIdCollection));
0054 }