File indexing completed on 2024-09-07 04:36:38
0001 #include "HLTCSCRing2or3Filter.h"
0002
0003 #include "DataFormats/Common/interface/Handle.h"
0004 #include "FWCore/Framework/interface/ESHandle.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "FWCore/ServiceRegistry/interface/Service.h"
0007 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0009 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
0010
0011 HLTCSCRing2or3Filter::HLTCSCRing2or3Filter(const edm::ParameterSet& iConfig)
0012 : HLTFilter(iConfig),
0013 muonGeometryRecordToken_(esConsumes()),
0014 m_input(iConfig.getParameter<edm::InputTag>("input")),
0015 m_minHits(iConfig.getParameter<unsigned int>("minHits")),
0016 m_xWindow(iConfig.getParameter<double>("xWindow")),
0017 m_yWindow(iConfig.getParameter<double>("yWindow")) {
0018 cscrechitsToken = consumes<CSCRecHit2DCollection>(m_input);
0019 }
0020
0021 HLTCSCRing2or3Filter::~HLTCSCRing2or3Filter() = default;
0022
0023 void HLTCSCRing2or3Filter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0024 edm::ParameterSetDescription desc;
0025 makeHLTFilterDescription(desc);
0026 desc.add<edm::InputTag>("input", edm::InputTag("hltCsc2DRecHits"));
0027 desc.add<unsigned int>("minHits", 4);
0028 desc.add<double>("xWindow", 2.);
0029 desc.add<double>("yWindow", 2.);
0030 descriptions.add("hltCSCRing2or3Filter", desc);
0031 }
0032
0033 bool HLTCSCRing2or3Filter::hltFilter(edm::Event& iEvent,
0034 const edm::EventSetup& iSetup,
0035 trigger::TriggerFilterObjectWithRefs& filterproduct) const {
0036 edm::Handle<CSCRecHit2DCollection> hits;
0037 iEvent.getByToken(cscrechitsToken, hits);
0038
0039 edm::ESHandle<CSCGeometry> cscGeometry;
0040 bool got_cscGeometry = false;
0041
0042 std::map<int, std::vector<const CSCRecHit2D*> > chamber_tohit;
0043
0044 for (auto const& hit : *hits) {
0045 CSCDetId id(hit.geographicalId());
0046 int chamber_id = CSCDetId(id.endcap(), id.station(), id.ring(), id.chamber(), 0).rawId();
0047
0048 if (id.ring() == 2 || id.ring() == 3) {
0049 std::map<int, std::vector<const CSCRecHit2D*> >::const_iterator chamber_iter = chamber_tohit.find(chamber_id);
0050 if (chamber_iter == chamber_tohit.end()) {
0051 std::vector<const CSCRecHit2D*> newlist;
0052 newlist.push_back(&hit);
0053 }
0054 chamber_tohit[chamber_id].push_back(&hit);
0055 }
0056 }
0057
0058 unsigned int minHitsAlmostSquared = (m_minHits - 1) * (m_minHits - 2);
0059 for (std::map<int, std::vector<const CSCRecHit2D*> >::const_iterator chamber_iter = chamber_tohit.begin();
0060 chamber_iter != chamber_tohit.end();
0061 ++chamber_iter) {
0062 if (chamber_iter->second.size() >= m_minHits) {
0063 if (!got_cscGeometry) {
0064 cscGeometry = iSetup.getHandle(muonGeometryRecordToken_);
0065 got_cscGeometry = true;
0066 }
0067
0068 unsigned int pairs_in_window = 0;
0069 for (auto hit1 = chamber_iter->second.begin(); hit1 != chamber_iter->second.end(); ++hit1) {
0070 for (auto hit2 = chamber_iter->second.begin(); hit2 != hit1; ++hit2) {
0071 GlobalPoint pos1 =
0072 cscGeometry->idToDet((*hit1)->geographicalId())->surface().toGlobal((*hit1)->localPosition());
0073 GlobalPoint pos2 =
0074 cscGeometry->idToDet((*hit2)->geographicalId())->surface().toGlobal((*hit2)->localPosition());
0075
0076 if (fabs(pos1.x() - pos2.x()) < m_xWindow && fabs(pos1.y() - pos2.y()) < m_yWindow)
0077 pairs_in_window++;
0078
0079 if (pairs_in_window >= minHitsAlmostSquared)
0080 return true;
0081 }
0082 }
0083
0084 }
0085 }
0086
0087 return false;
0088 }
0089
0090
0091 #include "FWCore/Framework/interface/MakerMacros.h"
0092 DEFINE_FWK_MODULE(HLTCSCRing2or3Filter);