Skip to content

Commit

Permalink
applied suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
maaraujo94 committed Aug 24, 2021
1 parent aee5ef2 commit 69e510a
Showing 1 changed file with 30 additions and 34 deletions.
64 changes: 30 additions & 34 deletions HLTrigger/special/plugins/HLTPPSCalFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<edm::DetSetVector<CTPPSPixelLocalTrack>> pixelLocalTrackToken_;
const edm::InputTag pixelLocalTrackInputTag_; // Input tag identifying the pixel detector
const edm::EDGetTokenT<edm::DetSetVector<CTPPSPixelLocalTrack>> pixelLocalTrackToken_;

int minTracks_;
int maxTracks_;
const int minTracks_;
const int maxTracks_;

bool do_express_;
const bool do_express_;
};

void HLTPPSCalFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
Expand All @@ -66,17 +66,15 @@ void HLTPPSCalFilter::fillDescriptions(edm::ConfigurationDescriptions& descripti
HLTPPSCalFilter::HLTPPSCalFilter(const edm::ParameterSet& iConfig)
: pixelLocalTrackInputTag_(iConfig.getParameter<edm::InputTag>("pixelLocalTrackInputTag")),
pixelLocalTrackToken_(consumes<edm::DetSetVector<CTPPSPixelLocalTrack>>(pixelLocalTrackInputTag_)),

minTracks_(iConfig.getParameter<int>("minTracks")),
maxTracks_(iConfig.getParameter<int>("maxTracks")),

do_express_(iConfig.getParameter<bool>("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<uint32_t, bool> pixel_filter_;

// pixel map definition
Expand All @@ -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<edm::DetSetVector<CTPPSPixelLocalTrack>> 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<edm::DetSetVector<CTPPSPixelLocalTrack>> 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;
Expand Down

0 comments on commit 69e510a

Please sign in to comment.