CMS 3D CMS Logo

L1GTPrescaler.cc
Go to the documentation of this file.
1 #include <array>
2 #include <cassert>
3 #include <memory>
4 #include <vector>
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 
20 
22 public:
24 
25  bool filter(edm::Event &event, edm::EventSetup const &setup) override;
26 
27  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
28 
29 private:
31  const std::array<double, 128> m_algoPrescales;
32  const std::array<double, 64> m_techPrescales;
33  std::array<unsigned int, 128> m_algoCounters;
34  std::array<unsigned int, 64> m_techCounters;
35 };
36 
39  config.getParameter<edm::InputTag>("l1Results"))),
40  m_algoPrescales(make_array<double, 128>(
41  config.getParameter<std::vector<double>>("l1AlgoPrescales"))),
42  m_techPrescales(make_array<double, 64>(
43  config.getParameter<std::vector<double>>("l1TechPrescales"))) {
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 =
54  handle->technicalTriggerWord(); // make a copy of the L1 tech results
55  bool finalOr = false;
56 
57  for (unsigned int i = 0; i < 128; ++i) {
58  if (m_algoPrescales[i] == 0) {
59  // mask this trigger: reset the bit
60  algoWord[i] = false;
61  } else if (algoWord[i]) {
62  // prescale this trigger
63  ++m_algoCounters[i];
64  if (std::fmod(m_algoCounters[i], m_algoPrescales[i]) < 1)
65  // the prescale is successful, keep the bit set
66  finalOr = true;
67  else
68  // the prescale failed, reset the bit
69  algoWord[i] = false;
70  }
71  }
72  for (unsigned int i = 0; i < 64; ++i) {
73  if (m_techPrescales[i] == 0) {
74  // mask this trigger: reset the bit
75  techWord[i] = false;
76  } else if (techWord[i]) {
77  ++m_techCounters[i];
78  if (std::fmod(m_techCounters[i], m_techPrescales[i]) < 1)
79  // the prescale is successful, keep the bit set
80  finalOr = true;
81  else
82  // the prescale failed, reset the bit
83  techWord[i] = false;
84  }
85  }
86 
87  // make a copy of the L1GlobalTriggerReadoutRecord, and set the new decisions
88  std::unique_ptr<L1GlobalTriggerReadoutRecord> result(
89  new L1GlobalTriggerReadoutRecord(*handle));
90  result->setDecisionWord(algoWord);
91  result->setTechnicalTriggerWord(techWord);
92  result->setDecision(finalOr);
93  event.put(std::move(result));
94 
95  return finalOr;
96 }
97 
99  edm::ConfigurationDescriptions &descriptions) {
101  desc.add<edm::InputTag>("l1Results", edm::InputTag("gtDigis"));
102  desc.add<std::vector<double>>("l1AlgoPrescales", std::vector<double>(128, 1));
103  desc.add<std::vector<double>>("l1TechPrescales", std::vector<double>(64, 1));
104  descriptions.add("l1GTPrescaler", desc);
105 }
106 
107 // register as a framework plugin
const TechnicalTriggerWord & technicalTriggerWord(int bxInEventValue) const
const std::array< double, 64 > m_techPrescales
def copy(args, dbName)
L1GTPrescaler(edm::ParameterSet const &config)
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
Definition: config.py:1
std::array< unsigned int, 64 > m_techCounters
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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)
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:511
Definition: event.py:1
std::array< T, N > make_array(std::vector< T > const &values)
Definition: L1GTPrescaler.cc:7