Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:20:39

0001 // -*- C++ -*-
0002 //
0003 // Package:    HLTCSCAcceptBusyFilter
0004 // Class:      HLTCSCAcceptBusyFilter
0005 //
0006 /**\class HLTCSCAcceptBusyFilter HLTCSCAcceptBusyFilter.cc Analyzers/HLTCSCAcceptBusyFilter/src/HLTCSCAcceptBusyFilter.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Ingo Bloch
0015 //         Created:  Mon Mar 15 11:39:08 CDT 2010
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 //include "FWCore/Framework/interface/EDFilter.h"
0025 
0026 #include "HLTrigger/HLTcore/interface/HLTFilter.h"
0027 
0028 #include "FWCore/Framework/interface/Event.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030 
0031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0032 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0033 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0034 
0035 #include "FWCore/Framework/interface/EventSetup.h"
0036 #include "FWCore/Framework/interface/ESHandle.h"
0037 
0038 #include "DataFormats/CSCRecHit/interface/CSCRecHit2DCollection.h"
0039 
0040 #include <string>
0041 
0042 //
0043 // class declaration
0044 //
0045 
0046 class HLTCSCAcceptBusyFilter : public HLTFilter {
0047 public:
0048   explicit HLTCSCAcceptBusyFilter(const edm::ParameterSet&);
0049   ~HLTCSCAcceptBusyFilter() override;
0050   bool hltFilter(edm::Event&,
0051                  const edm::EventSetup&,
0052                  trigger::TriggerFilterObjectWithRefs& filterproduct) const override;
0053   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0054 
0055 private:
0056   bool AcceptManyHitsInChamber(unsigned int maxRecHitsPerChamber,
0057                                const edm::Handle<CSCRecHit2DCollection>& recHits) const;
0058 
0059   // ----------member data ---------------------------
0060   edm::EDGetTokenT<CSCRecHit2DCollection> cscrechitsToken;
0061   edm::InputTag cscrechitsTag;
0062   bool invert;
0063   unsigned int maxRecHitsPerChamber;
0064 };
0065 
0066 //
0067 // constants, enums and typedefs
0068 //
0069 
0070 //
0071 // static data member definitions
0072 //
0073 
0074 //
0075 // constructors and destructor
0076 //
0077 HLTCSCAcceptBusyFilter::HLTCSCAcceptBusyFilter(const edm::ParameterSet& iConfig) : HLTFilter(iConfig) {
0078   //now do what ever initialization is needed
0079   cscrechitsTag = iConfig.getParameter<edm::InputTag>("cscrechitsTag");
0080   invert = iConfig.getParameter<bool>("invert");
0081   maxRecHitsPerChamber = iConfig.getParameter<unsigned int>("maxRecHitsPerChamber");
0082   cscrechitsToken = consumes<CSCRecHit2DCollection>(cscrechitsTag);
0083 }
0084 
0085 HLTCSCAcceptBusyFilter::~HLTCSCAcceptBusyFilter() {
0086   // do anything here that needs to be done at desctruction time
0087   // (e.g. close files, deallocate resources etc.)
0088 }
0089 
0090 void HLTCSCAcceptBusyFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0091   edm::ParameterSetDescription desc;
0092   makeHLTFilterDescription(desc);
0093   desc.add<edm::InputTag>("cscrechitsTag", edm::InputTag("hltCsc2DRecHits"));
0094   desc.add<bool>("invert", true);
0095   desc.add<unsigned int>("maxRecHitsPerChamber", 200);
0096   descriptions.add("hltCSCAcceptBusyFilter", desc);
0097 }
0098 
0099 //
0100 // member functions
0101 //
0102 
0103 // ------------ method called on each new Event  ------------
0104 bool HLTCSCAcceptBusyFilter::hltFilter(edm::Event& iEvent,
0105                                        const edm::EventSetup& iSetup,
0106                                        trigger::TriggerFilterObjectWithRefs& filterproduct) const {
0107   using namespace edm;
0108 
0109   // Get the RecHits collection :
0110   Handle<CSCRecHit2DCollection> recHits;
0111   iEvent.getByToken(cscrechitsToken, recHits);
0112 
0113   if (AcceptManyHitsInChamber(maxRecHitsPerChamber, recHits)) {
0114     return (!invert);
0115   } else {
0116     return (invert);
0117   }
0118 }
0119 
0120 // ------------ method to find chamber with nMax hits
0121 bool HLTCSCAcceptBusyFilter::AcceptManyHitsInChamber(unsigned int maxRecHitsPerChamber,
0122                                                      const edm::Handle<CSCRecHit2DCollection>& recHits) const {
0123   unsigned int maxNRecHitsPerChamber(0);
0124 
0125   const unsigned int nEndcaps(2);
0126   const unsigned int nStations(4);
0127   const unsigned int nRings(4);
0128   const unsigned int nChambers(36);
0129   unsigned int allRechits[nEndcaps][nStations][nRings][nChambers];
0130   for (auto& allRechit : allRechits) {
0131     for (unsigned int iS = 0; iS < nStations; ++iS) {
0132       for (unsigned int iR = 0; iR < nRings; ++iR) {
0133         for (unsigned int iC = 0; iC < nChambers; ++iC) {
0134           allRechit[iS][iR][iC] = 0;
0135         }
0136       }
0137     }
0138   }
0139 
0140   for (auto const& it : *recHits) {
0141     ++allRechits[it.cscDetId().endcap() - 1][it.cscDetId().station() - 1][it.cscDetId().ring() - 1]
0142                 [it.cscDetId().chamber() - 1];
0143   }
0144 
0145   for (auto& allRechit : allRechits) {
0146     for (unsigned int iS = 0; iS < nStations; ++iS) {
0147       for (unsigned int iR = 0; iR < nRings; ++iR) {
0148         for (unsigned int iC = 0; iC < nChambers; ++iC) {
0149           if (allRechit[iS][iR][iC] > maxNRecHitsPerChamber) {
0150             maxNRecHitsPerChamber = allRechit[iS][iR][iC];
0151           }
0152           if (maxNRecHitsPerChamber > maxRecHitsPerChamber) {
0153             return true;
0154           }
0155         }
0156       }
0157     }
0158   }
0159 
0160   return false;
0161 }
0162 
0163 // declare this class as a framework plugin
0164 DEFINE_FWK_MODULE(HLTCSCAcceptBusyFilter);