CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/Calibration/HcalAlCaRecoProducers/plugins/PrescalerFHN.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    HCALNoiseAlCaReco
00004 // Class:      HCALNoiseAlCaReco
00005 // 
00013 //
00014 // Original Author:  Kenneth Case Rossato
00015 //         Created:  Wed Mar 25 13:05:10 CET 2008
00016 // $Id: PrescalerFHN.cc,v 1.4 2010/02/16 22:24:16 wdd Exp $
00017 //
00018 //
00019 // modified to PrecalerFHN by Grigory Safronov 27/03/09
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDFilter.h"
00027 
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032 
00033 #include "FWCore/Utilities/interface/InputTag.h"
00034 
00035 #include "FWCore/Common/interface/TriggerNames.h"
00036 #include "DataFormats/Common/interface/TriggerResults.h"
00037 #include "DataFormats/Provenance/interface/ParameterSetID.h"
00038 
00039 #include <string>
00040 
00041 //
00042 // class declaration
00043 //
00044 
00045 using namespace edm;
00046 
00047 class PrescalerFHN : public edm::EDFilter {
00048    public:
00049       explicit PrescalerFHN(const edm::ParameterSet&);
00050       ~PrescalerFHN();
00051 
00052    private:
00053       virtual void beginJob() ;
00054       virtual bool filter(edm::Event&, const edm::EventSetup&);
00055       virtual void endJob() ;
00056       // ----------member data ---------------------------
00057 
00058   void init(const edm::TriggerResults &,
00059             const edm::TriggerNames & triggerNames);
00060 
00061   edm::ParameterSetID triggerNamesID_;
00062 
00063   edm::InputTag triggerTag;
00064 
00065   std::map<std::string, unsigned int> prescales;
00066   std::map<std::string, unsigned int> prescale_counter;
00067 
00068   std::map<std::string, unsigned int> trigger_indices;
00069 };
00070 
00071 //
00072 // constants, enums and typedefs
00073 //
00074 
00075 //
00076 // static data member definitions
00077 //
00078 
00079 //
00080 // constructors and destructor
00081 //
00082 PrescalerFHN::PrescalerFHN(const edm::ParameterSet& iConfig)
00083   : triggerTag(iConfig.getParameter<edm::InputTag>("TriggerResultsTag"))
00084 {
00085    //now do what ever initialization is needed
00086   std::vector<edm::ParameterSet> prescales_in(iConfig.getParameter<std::vector<edm::ParameterSet> >("Prescales"));
00087 
00088   for (std::vector<edm::ParameterSet>::const_iterator cit = prescales_in.begin();
00089        cit != prescales_in.end(); cit++) {
00090 
00091     std::string name(cit->getParameter<std::string>("HLTName"));
00092     unsigned int factor(cit->getParameter<unsigned int>("PrescaleFactor"));
00093 
00094     // does some exception get thrown if parameters aren't available? should test...
00095 
00096     prescales[name] = factor;
00097     prescale_counter[name] = 0;
00098   }
00099   
00100 }
00101 
00102 
00103 PrescalerFHN::~PrescalerFHN()
00104 {
00105  
00106    // do anything here that needs to be done at desctruction time
00107    // (e.g. close files, deallocate resources etc.)
00108 
00109 }
00110 
00111 
00112 //
00113 // member functions
00114 //
00115 
00116 void PrescalerFHN::init(const edm::TriggerResults &result,
00117                         const edm::TriggerNames & triggerNames)
00118 {
00119   trigger_indices.clear();
00120 
00121   for (std::map<std::string, unsigned int>::const_iterator cit = prescales.begin();
00122        cit != prescales.end(); cit++) {
00123 
00124     trigger_indices[cit->first] = triggerNames.triggerIndex(cit->first);
00125     
00126     if (trigger_indices[cit->first] >= result.size()) {
00127       // trigger path not found
00128       LogDebug("") << "requested HLT path does not exist: " << cit->first;
00129       trigger_indices.erase(cit->first);
00130     }
00131     
00132   }
00133 }
00134 
00135 // ------------ method called on each new Event  ------------
00136 bool
00137 PrescalerFHN::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00138 {
00139    using namespace edm;
00140 
00141    /* Goal for this skim:
00142       Prescaling MET HLT paths
00143       Option to turn off HSCP filter
00144       - Doing that by treating it as an HLT with prescale 1
00145    */
00146 
00147    // Trying to mirror HLTrigger/HLTfilters/src/HLTHighLevel.cc where possible
00148 
00149    Handle<TriggerResults> trh;
00150    iEvent.getByLabel(triggerTag, trh);
00151 
00152    if (trh.isValid()) {
00153      LogDebug("") << "TriggerResults found, number of HLT paths: " << trh->size();
00154    } else {
00155      LogDebug("") << "TriggerResults product not found - returning result=false!";
00156      return false;
00157    }
00158 
00159    const edm::TriggerNames & triggerNames = iEvent.triggerNames(*trh);
00160    if (triggerNamesID_ != triggerNames.parameterSetID()) {
00161      triggerNamesID_ = triggerNames.parameterSetID();
00162      init(*trh, triggerNames);
00163    }
00164 
00165    // Trigger indices are ready at this point
00166    // - Begin checking for HLT bits
00167 
00168    bool accept_event = false;
00169    for (std::map<std::string, unsigned int>::const_iterator cit = trigger_indices.begin();
00170         cit != trigger_indices.end(); cit++) {
00171      if (trh->accept(cit->second)) {
00172        prescale_counter[cit->first]++;
00173        if (prescale_counter[cit->first] >= prescales[cit->first]) {
00174          accept_event = true;
00175          prescale_counter[cit->first] = 0;
00176        }
00177      }
00178    }
00179 
00180    return accept_event;
00181 }
00182 
00183 // ------------ method called once each job just before starting event loop  ------------
00184 void 
00185 PrescalerFHN::beginJob()
00186 {
00187 }
00188 
00189 // ------------ method called once each job just after ending the event loop  ------------
00190 void 
00191 PrescalerFHN::endJob() {
00192 }
00193 
00194 //define this as a plug-in
00195 DEFINE_FWK_MODULE(PrescalerFHN);