CMS 3D CMS Logo

L1TriggerResultsConverter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PhysicsTools/NanoAOD
4 // Class: L1TriggerResultsConverter
5 //
13 //
14 // Original Author: Andrea Rizzi
15 // Created: Mon, 11 Aug 2017 11:20:30 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 #include <algorithm>
22 
23 // user include files
33 
36 
39 
41 
44 
46 //
47 // class declaration
48 //
49 
51 public:
53  ~L1TriggerResultsConverter() override;
54 
55  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
56 
57 private:
58  void produce(edm::Event&, const edm::EventSetup&) override;
59  void beginRun(edm::Run const&, edm::EventSetup const&) override;
60 
61  // ----------member data ---------------------------
62  const bool legacyL1_;
67  std::vector<std::string> names_;
68  std::vector<unsigned int> mask_;
69  std::vector<unsigned int> indices_;
70 
71  const unsigned int m_triggerRulePrefireVetoBit = 255;
72 };
73 
74 //
75 // constructors and destructor
76 //
78  : legacyL1_(params.getParameter<bool>("legacyL1")),
79  store_unprefireable_bit_(!legacyL1_ ? params.getParameter<bool>("storeUnprefireableBit") : false),
80  tokenLegacy_(legacyL1_ ? consumes<L1GlobalTriggerReadoutRecord>(params.getParameter<edm::InputTag>("src"))
81  : edm::EDGetTokenT<L1GlobalTriggerReadoutRecord>()),
82  token_(!legacyL1_ ? consumes<GlobalAlgBlkBxCollection>(params.getParameter<edm::InputTag>("src"))
83  : edm::EDGetTokenT<GlobalAlgBlkBxCollection>()),
85  ? consumes<GlobalExtBlkBxCollection>(params.getParameter<edm::InputTag>("src_ext"))
86  : edm::EDGetTokenT<GlobalExtBlkBxCollection>()) {
87  produces<edm::TriggerResults>();
88 }
89 
91  // do anything here that needs to be done at destruction time
92  // (e.g. close files, deallocate resources etc.)
93 }
94 
95 //
96 // member functions
97 //
98 
100  mask_.clear();
101  names_.clear();
102  indices_.clear();
103  if (legacyL1_) {
105  edm::ESHandle<L1GtTriggerMask> handleAlgoMask;
106  setup.get<L1GtTriggerMenuRcd>().get(handleMenu);
107  auto const& mapping = handleMenu->gtAlgorithmAliasMap();
108  for (auto const& keyval : mapping) {
109  names_.push_back(keyval.first);
110  indices_.push_back(keyval.second.algoBitNumber());
111  }
112  setup.get<L1GtTriggerMaskAlgoTrigRcd>().get(handleAlgoMask);
113  mask_ = handleAlgoMask->gtTriggerMask();
114  } else {
116  setup.get<L1TUtmTriggerMenuRcd>().get(menu);
117  auto const& mapping = menu->getAlgorithmMap();
118  for (auto const& keyval : mapping) {
119  names_.push_back(keyval.first);
120  indices_.push_back(keyval.second.getIndex());
121  }
123  names_.push_back("L1_UnprefireableEvent");
124  }
125 }
126 
127 // ------------ method called to produce the data ------------
128 
130  using namespace edm;
131  const std::vector<bool>* wordp = nullptr;
132  bool unprefireable_bit = false;
133  if (!legacyL1_) {
135  iEvent.getByToken(token_, handleResults);
136  wordp = &handleResults->at(0, 0).getAlgoDecisionFinal();
138  edm::Handle<GlobalExtBlkBxCollection> handleExtResults;
139  iEvent.getByToken(token_ext_, handleExtResults);
140  if (handleExtResults->size() != 0) {
141  unprefireable_bit = handleExtResults->at(0, 0).getExternalDecision(
143  }
144  }
145  } else {
146  // Legacy access
148  iEvent.getByToken(tokenLegacy_, handleResults);
149  wordp = &handleResults->decisionWord();
150  }
151  auto const& word = *wordp;
152  HLTGlobalStatus l1bitsAsHLTStatus(names_.size());
153  unsigned indices_size = indices_.size();
154  for (size_t nidx = 0; nidx < indices_size; nidx++) {
155  unsigned int index = indices_[nidx];
156  bool result = word[index];
157  if (!mask_.empty())
158  result &= (mask_[index] != 0);
159  l1bitsAsHLTStatus[nidx] = HLTPathStatus(result ? edm::hlt::Pass : edm::hlt::Fail);
160  }
162  l1bitsAsHLTStatus[indices_size] = HLTPathStatus(unprefireable_bit ? edm::hlt::Pass : edm::hlt::Fail);
163  //mimic HLT trigger bits for L1
164  auto out = std::make_unique<edm::TriggerResults>(l1bitsAsHLTStatus, names_);
165  iEvent.put(std::move(out));
166 }
167 
168 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
171  desc.add<bool>("legacyL1")->setComment("is legacy L1");
172  desc.add<edm::InputTag>("src")->setComment(
173  "L1 input (L1GlobalTriggerReadoutRecord if legacy, GlobalAlgBlkBxCollection otherwise)");
174  desc.add<bool>("storeUnprefireableBit", false)
175  ->setComment("Activate storage of L1 unprefireable bit (needs L1 external decision input)");
176  desc.add<edm::InputTag>("src_ext", edm::InputTag(""))
177  ->setComment("L1 external decision input (GlobalExtBlkBxCollection, only supported if not legacy");
178  descriptions.add("L1TriggerResultsConverter", desc);
179 }
180 
181 //define this as a plug-in
std::vector< unsigned int > indices_
std::vector< std::string > names_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
unsigned size(int bx) const
static const unsigned int maxExternalConditions
Definition: GlobalExtBlk.h:47
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
reject
Definition: HLTenums.h:20
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void beginRun(edm::Run const &, edm::EventSetup const &) override
void produce(edm::Event &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
accept
Definition: HLTenums.h:19
const std::vector< unsigned int > & gtTriggerMask() const
get the trigger mask
const edm::EDGetTokenT< GlobalAlgBlkBxCollection > token_
L1TriggerResultsConverter(const edm::ParameterSet &)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
const edm::EDGetTokenT< GlobalExtBlkBxCollection > token_ext_
const DecisionWord & decisionWord(int bxInEventValue) const
const edm::EDGetTokenT< L1GlobalTriggerReadoutRecord > tokenLegacy_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< unsigned int > mask_
const std::map< std::string, L1TUtmAlgorithm > & getAlgorithmMap() const
HLT enums.
T get() const
Definition: EventSetup.h:71
const AlgorithmMap & gtAlgorithmAliasMap() const
get / set the algorithm map (by alias)
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45
const unsigned int m_triggerRulePrefireVetoBit
const T & at(int bx, unsigned i) const