From 69e510a3156e69bcb950010e0fafa9b0f81e29aa Mon Sep 17 00:00:00 2001 From: Mariana Date: Tue, 24 Aug 2021 12:08:01 +0200 Subject: [PATCH] applied suggested changes --- HLTrigger/special/plugins/HLTPPSCalFilter.cc | 64 +++++++++----------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/HLTrigger/special/plugins/HLTPPSCalFilter.cc b/HLTrigger/special/plugins/HLTPPSCalFilter.cc index aa0d3038c4d1c..f650ac9224ea7 100644 --- a/HLTrigger/special/plugins/HLTPPSCalFilter.cc +++ b/HLTrigger/special/plugins/HLTPPSCalFilter.cc @@ -38,13 +38,13 @@ class HLTPPSCalFilter : public edm::global::EDFilter<> { bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; private: - edm::InputTag pixelLocalTrackInputTag_; // Input tag identifying the pixel detector - edm::EDGetTokenT> pixelLocalTrackToken_; + const edm::InputTag pixelLocalTrackInputTag_; // Input tag identifying the pixel detector + const edm::EDGetTokenT> pixelLocalTrackToken_; - int minTracks_; - int maxTracks_; + const int minTracks_; + const int maxTracks_; - bool do_express_; + const bool do_express_; }; void HLTPPSCalFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { @@ -66,17 +66,15 @@ void HLTPPSCalFilter::fillDescriptions(edm::ConfigurationDescriptions& descripti HLTPPSCalFilter::HLTPPSCalFilter(const edm::ParameterSet& iConfig) : pixelLocalTrackInputTag_(iConfig.getParameter("pixelLocalTrackInputTag")), pixelLocalTrackToken_(consumes>(pixelLocalTrackInputTag_)), - minTracks_(iConfig.getParameter("minTracks")), maxTracks_(iConfig.getParameter("maxTracks")), - do_express_(iConfig.getParameter("do_express")) {} bool HLTPPSCalFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const { // Helper tool to count valid tracks const auto valid_trks = [](const auto& trk) { return trk.isValid(); }; - // maps for assigning filter pass / fail + // map for assigning filter pass / fail std::unordered_map pixel_filter_; // pixel map definition @@ -86,34 +84,32 @@ bool HLTPPSCalFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::Event pixel_filter_[CTPPSPixelDetId(1, 2, 3)] = false; // filter on pixels (2017+) selection - if (!pixel_filter_.empty()) { - edm::Handle> pixelTracks; - iEvent.getByToken(pixelLocalTrackToken_, pixelTracks); - - for (const auto& rpv : *pixelTracks) { - if (pixel_filter_.count(rpv.id) == 0) { - continue; - } - // assume pass condition if there is at least one track - pixel_filter_.at(rpv.id) = true; - - // count number of valid tracks - const auto ntrks = std::count_if(rpv.begin(), rpv.end(), valid_trks); - // fail condition if ntrks not within minTracks, maxTracks values - if (minTracks_ > 0 && ntrks < minTracks_) - pixel_filter_.at(rpv.id) = false; - if (maxTracks_ > 0 && ntrks > maxTracks_) - pixel_filter_.at(rpv.id) = false; - } + edm::Handle> pixelTracks; + iEvent.getByToken(pixelLocalTrackToken_, pixelTracks); - // compilation of filter conditions - if (do_express_) { - return (pixel_filter_.at(CTPPSPixelDetId(0, 0, 3)) && pixel_filter_.at(CTPPSPixelDetId(0, 2, 3))) || - (pixel_filter_.at(CTPPSPixelDetId(1, 0, 3)) && pixel_filter_.at(CTPPSPixelDetId(1, 2, 3))); - } else { - return (pixel_filter_.at(CTPPSPixelDetId(0, 0, 3)) || pixel_filter_.at(CTPPSPixelDetId(0, 2, 3))) || - (pixel_filter_.at(CTPPSPixelDetId(1, 0, 3)) || pixel_filter_.at(CTPPSPixelDetId(1, 2, 3))); + for (const auto& rpv : *pixelTracks) { + if (pixel_filter_.count(rpv.id) == 0) { + continue; } + // assume pass condition if there is at least one track + pixel_filter_.at(rpv.id) = true; + + // count number of valid tracks + const auto ntrks = std::count_if(rpv.begin(), rpv.end(), valid_trks); + // fail condition if ntrks not within minTracks, maxTracks values + if (minTracks_ > 0 && ntrks < minTracks_) + pixel_filter_.at(rpv.id) = false; + if (maxTracks_ > 0 && ntrks > maxTracks_) + pixel_filter_.at(rpv.id) = false; + } + + // compilation of filter conditions + if (do_express_) { + return (pixel_filter_.at(CTPPSPixelDetId(0, 0, 3)) && pixel_filter_.at(CTPPSPixelDetId(0, 2, 3))) || + (pixel_filter_.at(CTPPSPixelDetId(1, 0, 3)) && pixel_filter_.at(CTPPSPixelDetId(1, 2, 3))); + } else { + return (pixel_filter_.at(CTPPSPixelDetId(0, 0, 3)) || pixel_filter_.at(CTPPSPixelDetId(0, 2, 3))) || + (pixel_filter_.at(CTPPSPixelDetId(1, 0, 3)) || pixel_filter_.at(CTPPSPixelDetId(1, 2, 3))); } return false;