Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 10:03:38

0001 #ifndef HcalSimAlgos_HcalHitFilter_h
0002 #define HcalSimAlgos_HcalHitFilter_h
0003 
0004 #include "SimCalorimetry/CaloSimAlgos/interface/CaloVHitFilter.h"
0005 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
0006 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0007 
0008 #include <algorithm>
0009 #include <vector>
0010 
0011 template <HcalSubdetector... subdets>
0012 class HcalHitFilter : public CaloVHitFilter {
0013 public:
0014   HcalHitFilter() : theSubdets({subdets...}) { std::sort(theSubdets.begin(), theSubdets.end()); }
0015   ~HcalHitFilter() override {}
0016 
0017   void setDetIds(const std::vector<DetId>& detIds) {
0018     theDetIds = detIds;
0019     std::sort(theDetIds.begin(), theDetIds.end());
0020   }
0021 
0022   bool accepts(const PCaloHit& hit) const override {
0023     HcalDetId hcalDetId(hit.id());
0024     return ((theSubdets.empty() || std::binary_search(theSubdets.begin(), theSubdets.end(), hcalDetId.subdet())) &&
0025             (theDetIds.empty() || std::binary_search(theDetIds.begin(), theDetIds.end(), DetId(hit.id()))));
0026   }
0027 
0028 protected:
0029   std::vector<HcalSubdetector> theSubdets;
0030   // empty DetIds will always be accepted
0031   std::vector<DetId> theDetIds;
0032 };
0033 
0034 typedef HcalHitFilter<HcalBarrel, HcalEndcap> HBHEHitFilter;
0035 typedef HcalHitFilter<HcalForward> HFHitFilter;
0036 typedef HcalHitFilter<HcalOuter> HOHitFilter;
0037 
0038 #endif