CMS 3D CMS Logo

PrescalerFHN.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HCALNoiseAlCaReco
4 // Class: HCALNoiseAlCaReco
5 //
13 //
14 // Original Author: Kenneth Case Rossato
15 // Created: Wed Mar 25 13:05:10 CET 2008
16 //
17 //
18 // modified to PrecalerFHN by Grigory Safronov 27/03/09
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
29 
31 
33 
37 
38 #include <string>
39 
40 //
41 // class declaration
42 //
43 
44 using namespace edm;
45 
46 class PrescalerFHN : public edm::one::EDFilter<> {
47 public:
48  explicit PrescalerFHN(const edm::ParameterSet&);
49 
50 private:
51  bool filter(edm::Event&, const edm::EventSetup&) override;
52  // ----------member data ---------------------------
53 
55 
57 
59 
60  std::map<std::string, unsigned int> prescales;
61  std::map<std::string, unsigned int> prescale_counter;
62 
63  std::map<std::string, unsigned int> trigger_indices;
64 };
65 
66 //
67 // constants, enums and typedefs
68 //
69 
70 //
71 // static data member definitions
72 //
73 
74 //
75 // constructors and destructor
76 //
78  tok_trigger = consumes<TriggerResults>(iConfig.getParameter<edm::InputTag>("TriggerResultsTag"));
79  //now do what ever initialization is needed
80  std::vector<edm::ParameterSet> prescales_in(iConfig.getParameter<std::vector<edm::ParameterSet> >("Prescales"));
81 
82  for (std::vector<edm::ParameterSet>::const_iterator cit = prescales_in.begin(); cit != prescales_in.end(); cit++) {
83  std::string name(cit->getParameter<std::string>("HLTName"));
84  unsigned int factor(cit->getParameter<unsigned int>("PrescaleFactor"));
85 
86  // does some exception get thrown if parameters aren't available? should test...
87 
89  prescale_counter[name] = 0;
90  }
91 }
92 
93 //
94 // member functions
95 //
96 
98  trigger_indices.clear();
99 
100  for (std::map<std::string, unsigned int>::const_iterator cit = prescales.begin(); cit != prescales.end(); cit++) {
101  auto index = triggerNames.triggerIndex(cit->first);
102  if (index < result.size()) {
103  trigger_indices[cit->first] = index;
104  } else {
105  // trigger path not found
106  LogDebug("") << "requested HLT path does not exist: " << cit->first;
107  }
108  }
109 }
110 
111 // ------------ method called on each new Event ------------
113  using namespace edm;
114 
115  /* Goal for this skim:
116  Prescaling MET HLT paths
117  Option to turn off HSCP filter
118  - Doing that by treating it as an HLT with prescale 1
119  */
120 
121  // Trying to mirror HLTrigger/HLTfilters/src/HLTHighLevel.cc where possible
122 
124  iEvent.getByToken(tok_trigger, trh);
125 
126  if (trh.isValid()) {
127  LogDebug("") << "TriggerResults found, number of HLT paths: " << trh->size();
128  } else {
129  LogDebug("") << "TriggerResults product not found - returning result=false!";
130  return false;
131  }
132 
133  const edm::TriggerNames& triggerNames = iEvent.triggerNames(*trh);
134  if (triggerNamesID_ != triggerNames.parameterSetID()) {
135  triggerNamesID_ = triggerNames.parameterSetID();
136  init(*trh, triggerNames);
137  }
138 
139  // Trigger indices are ready at this point
140  // - Begin checking for HLT bits
141 
142  bool accept_event = false;
143  for (std::map<std::string, unsigned int>::const_iterator cit = trigger_indices.begin(); cit != trigger_indices.end();
144  cit++) {
145  if (trh->accept(cit->second)) {
146  prescale_counter[cit->first]++;
147  if (prescale_counter[cit->first] >= prescales[cit->first]) {
148  accept_event = true;
149  prescale_counter[cit->first] = 0;
150  }
151  }
152  }
153 
154  return accept_event;
155 }
156 
157 //define this as a plug-in
init
int init
Definition: HydjetWrapper.h:64
PrescalerFHN::filter
bool filter(edm::Event &, const edm::EventSetup &) override
Definition: PrescalerFHN.cc:112
PrescalerFHN::init
void init(const edm::TriggerResults &, const edm::TriggerNames &triggerNames)
Definition: PrescalerFHN.cc:97
TriggerResults.h
edm::EDGetTokenT< TriggerResults >
PrescalerFHN::prescale_counter
std::map< std::string, unsigned int > prescale_counter
Definition: PrescalerFHN.cc:61
edm
HLT enums.
Definition: AlignableModifier.h:19
PrescalerFHN
Definition: PrescalerFHN.cc:46
edm::Handle
Definition: AssociativeIterator.h:50
EDFilter.h
PrescalerFHN::triggerNamesID_
edm::ParameterSetID triggerNamesID_
Definition: PrescalerFHN.cc:56
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::HLTGlobalStatus::size
unsigned int size() const
Get number of paths stored.
Definition: HLTGlobalStatus.h:35
L1TEGammaOffline_cfi.triggerNames
triggerNames
Definition: L1TEGammaOffline_cfi.py:40
edm::Hash< ParameterSetType >
DQMScaleToClient_cfi.factor
factor
Definition: DQMScaleToClient_cfi.py:8
ALCARECOTkAlBeamHalo_cff.filter
filter
Definition: ALCARECOTkAlBeamHalo_cff.py:27
PrescalerFHN::prescales
std::map< std::string, unsigned int > prescales
Definition: PrescalerFHN.cc:60
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
hltrates_dqm_sourceclient-live_cfg.prescales
prescales
Definition: hltrates_dqm_sourceclient-live_cfg.py:90
TriggerNames.h
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:58
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
InputTag.h
PrescalerFHN::tok_trigger
edm::EDGetTokenT< TriggerResults > tok_trigger
Definition: PrescalerFHN.cc:58
PrescalerFHN::trigger_indices
std::map< std::string, unsigned int > trigger_indices
Definition: PrescalerFHN.cc:63
Frameworkfwd.h
edm::one::EDFilter
Definition: EDFilter.h:30
edm::TriggerNames
Definition: TriggerNames.h:55
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
PrescalerFHN::PrescalerFHN
PrescalerFHN(const edm::ParameterSet &)
Definition: PrescalerFHN.cc:77
edm::HLTGlobalStatus::accept
bool accept() const
Has at least one path accepted the event?
Definition: HLTGlobalStatus.h:49
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
ParameterSetID.h
mps_fire.result
result
Definition: mps_fire.py:311
ParameterSet.h
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
edm::TriggerResults
Definition: TriggerResults.h:35