Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-04 02:55:06

0001 // -*- C++ -*-
0002 //
0003 // Package:    HCALNoiseAlCaReco
0004 // Class:      HCALNoiseAlCaReco
0005 //
0006 /**\class HCALNoiseAlCaReco HCALNoiseAlCaReco.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Kenneth Case Rossato
0015 //         Created:  Wed Mar 25 13:05:10 CET 2008
0016 //
0017 //
0018 // modified to PrecalerFHN by Grigory Safronov 27/03/09
0019 
0020 // system include files
0021 #include <memory>
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/one/EDFilter.h"
0026 
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029 
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 
0032 #include "FWCore/Utilities/interface/InputTag.h"
0033 
0034 #include "FWCore/Common/interface/TriggerNames.h"
0035 #include "DataFormats/Common/interface/TriggerResults.h"
0036 #include "DataFormats/Provenance/interface/ParameterSetID.h"
0037 
0038 #include <string>
0039 
0040 //
0041 // class declaration
0042 //
0043 
0044 using namespace edm;
0045 
0046 class PrescalerFHN : public edm::one::EDFilter<> {
0047 public:
0048   explicit PrescalerFHN(const edm::ParameterSet&);
0049 
0050 private:
0051   bool filter(edm::Event&, const edm::EventSetup&) override;
0052   // ----------member data ---------------------------
0053 
0054   void init(const edm::TriggerResults&, const edm::TriggerNames& triggerNames);
0055 
0056   edm::ParameterSetID triggerNamesID_;
0057 
0058   edm::EDGetTokenT<TriggerResults> tok_trigger;
0059 
0060   std::map<std::string, unsigned int> prescales;
0061   std::map<std::string, unsigned int> prescale_counter;
0062 
0063   std::map<std::string, unsigned int> trigger_indices;
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 PrescalerFHN::PrescalerFHN(const edm::ParameterSet& iConfig) {
0078   tok_trigger = consumes<TriggerResults>(iConfig.getParameter<edm::InputTag>("TriggerResultsTag"));
0079   //now do what ever initialization is needed
0080   std::vector<edm::ParameterSet> prescales_in(iConfig.getParameter<std::vector<edm::ParameterSet> >("Prescales"));
0081 
0082   for (std::vector<edm::ParameterSet>::const_iterator cit = prescales_in.begin(); cit != prescales_in.end(); cit++) {
0083     std::string name(cit->getParameter<std::string>("HLTName"));
0084     unsigned int factor(cit->getParameter<unsigned int>("PrescaleFactor"));
0085 
0086     // does some exception get thrown if parameters aren't available? should test...
0087 
0088     prescales[name] = factor;
0089     prescale_counter[name] = 0;
0090   }
0091 }
0092 
0093 //
0094 // member functions
0095 //
0096 
0097 void PrescalerFHN::init(const edm::TriggerResults& result, const edm::TriggerNames& triggerNames) {
0098   trigger_indices.clear();
0099 
0100   for (std::map<std::string, unsigned int>::const_iterator cit = prescales.begin(); cit != prescales.end(); cit++) {
0101     auto index = triggerNames.triggerIndex(cit->first);
0102     if (index < result.size()) {
0103       trigger_indices[cit->first] = index;
0104     } else {
0105       // trigger path not found
0106       LogDebug("") << "requested HLT path does not exist: " << cit->first;
0107     }
0108   }
0109 }
0110 
0111 // ------------ method called on each new Event  ------------
0112 bool PrescalerFHN::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0113   using namespace edm;
0114 
0115   /* Goal for this skim:
0116       Prescaling MET HLT paths
0117       Option to turn off HSCP filter
0118       - Doing that by treating it as an HLT with prescale 1
0119    */
0120 
0121   // Trying to mirror HLTrigger/HLTfilters/src/HLTHighLevel.cc where possible
0122 
0123   auto const& trh = iEvent.getHandle(tok_trigger);
0124 
0125   if (trh.isValid()) {
0126     LogDebug("") << "TriggerResults found, number of HLT paths: " << trh->size();
0127   } else {
0128     LogDebug("") << "TriggerResults product not found - returning result=false!";
0129     return false;
0130   }
0131 
0132   const edm::TriggerNames& triggerNames = iEvent.triggerNames(*trh);
0133   if (triggerNamesID_ != triggerNames.parameterSetID()) {
0134     triggerNamesID_ = triggerNames.parameterSetID();
0135     init(*trh, triggerNames);
0136   }
0137 
0138   // Trigger indices are ready at this point
0139   // - Begin checking for HLT bits
0140 
0141   bool accept_event = false;
0142   for (std::map<std::string, unsigned int>::const_iterator cit = trigger_indices.begin(); cit != trigger_indices.end();
0143        cit++) {
0144     if (trh->accept(cit->second)) {
0145       prescale_counter[cit->first]++;
0146       if (prescale_counter[cit->first] >= prescales[cit->first]) {
0147         accept_event = true;
0148         prescale_counter[cit->first] = 0;
0149       }
0150     }
0151   }
0152 
0153   return accept_event;
0154 }
0155 
0156 //define this as a plug-in
0157 DEFINE_FWK_MODULE(PrescalerFHN);