CMS 3D CMS Logo

L1GTPrescaler.cc
Go to the documentation of this file.
1 #include <vector>
2 #include <array>
3 #include <memory>
4 #include <cassert>
5 
6 template <class T, std::size_t N>
7 std::array<T, N> make_array(std::vector<T> const & values) {
8  assert(N == values.size());
9  std::array<T, N> ret;
10  std::copy(values.begin(), values.end(), ret.begin());
11  return ret;
12 }
13 
14 
21 
23 public:
25 
26  virtual bool filter(edm::Event& event, edm::EventSetup const& setup) override;
27 
28  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
29 
30 private:
32  const std::array<double, 128> m_algoPrescales;
33  const std::array<double, 64> m_techPrescales;
34  std::array<unsigned int, 128> m_algoCounters;
35  std::array<unsigned int, 64> m_techCounters;
36 
37 };
38 
40  m_l1ResultsToken( consumes<L1GlobalTriggerReadoutRecord>(config.getParameter<edm::InputTag>("l1Results")) ),
41  m_algoPrescales( make_array<double, 128>(config.getParameter<std::vector<double>>("l1AlgoPrescales")) ),
42  m_techPrescales( make_array<double, 64>(config.getParameter<std::vector<double>>("l1TechPrescales")) )
43 {
44  m_algoCounters.fill(0);
45  m_techCounters.fill(0);
46  produces<L1GlobalTriggerReadoutRecord>();
47 }
48 
51  event.getByToken(m_l1ResultsToken, handle);
52  auto algoWord = handle->decisionWord(); // make a copy of the L1 algo results
53  auto techWord = handle->technicalTriggerWord(); // make a copy of the L1 tech results
54  bool finalOr = false;
55 
56  for (unsigned int i = 0; i < 128; ++i) {
57  if (m_algoPrescales[i] == 0) {
58  // mask this trigger: reset the bit
59  algoWord[i] = 0;
60  } else if (algoWord[i]) {
61  // prescale this trigger
62  ++m_algoCounters[i];
63  if (std::fmod(m_algoCounters[i], m_algoPrescales[i]) < 1)
64  // the prescale is successful, keep the bit set
65  finalOr = true;
66  else
67  // the prescale failed, reset the bit
68  algoWord[i] = 0;
69  }
70  }
71  for (unsigned int i = 0; i < 64; ++i) {
72  if (m_techPrescales[i] == 0) {
73  // mask this trigger: reset the bit
74  techWord[i] = 0;
75  } else if (techWord[i]) {
76  ++m_techCounters[i];
77  if (std::fmod(m_techCounters[i], m_techPrescales[i]) < 1)
78  // the prescale is successful, keep the bit set
79  finalOr = true;
80  else
81  // the prescale failed, reset the bit
82  techWord[i] = 0;
83  }
84  }
85 
86  // make a copy of the L1GlobalTriggerReadoutRecord, and set the new decisions
87  std::unique_ptr<L1GlobalTriggerReadoutRecord> result(new L1GlobalTriggerReadoutRecord(*handle));
88  result->setDecisionWord(algoWord);
89  result->setTechnicalTriggerWord(techWord);
90  result->setDecision(finalOr);
91  event.put(std::move(result));
92 
93  return finalOr;
94 }
95 
98  desc.add<edm::InputTag>("l1Results", edm::InputTag("gtDigis"));
99  desc.add<std::vector<double>>("l1AlgoPrescales", std::vector<double>(128, 1));
100  desc.add<std::vector<double>>("l1TechPrescales", std::vector<double>( 64, 1));
101  descriptions.add("l1GTPrescaler", desc);
102 }
103 
104 
105 // register as a framework plugin
int i
Definition: DBlmapReader.cc:9
const TechnicalTriggerWord & technicalTriggerWord(int bxInEventValue) const
const std::array< double, 64 > m_techPrescales
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
L1GTPrescaler(edm::ParameterSet const &config)
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
Definition: config.py:1
std::array< unsigned int, 64 > m_techCounters
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const std::array< double, 128 > m_algoPrescales
std::array< unsigned int, 128 > m_algoCounters
ParameterDescriptionBase * add(U const &iLabel, T const &value)
const DecisionWord & decisionWord(int bxInEventValue) const
#define N
Definition: blowfish.cc:9
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual bool filter(edm::Event &event, edm::EventSetup const &setup) override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
const edm::EDGetTokenT< L1GlobalTriggerReadoutRecord > m_l1ResultsToken
def move(src, dest)
Definition: eostools.py:510
Definition: event.py:1
std::array< T, N > make_array(std::vector< T > const &values)
Definition: L1GTPrescaler.cc:7