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>()),
84  token_ext_(store_unprefireable_bit_
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 {
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  unprefireable_bit = handleExtResults->at(0, 0).getExternalDecision(
142  }
143  } else {
144  // Legacy access
146  iEvent.getByToken(tokenLegacy_, handleResults);
147  wordp = &handleResults->decisionWord();
148  }
149  auto const& word = *wordp;
150  HLTGlobalStatus l1bitsAsHLTStatus(names_.size());
151  unsigned indices_size = indices_.size();
152  for (size_t nidx = 0; nidx < indices_size; nidx++) {
153  unsigned int index = indices_[nidx];
154  bool result = word[index];
155  if (!mask_.empty())
156  result &= (mask_[index] != 0);
157  l1bitsAsHLTStatus[nidx] = HLTPathStatus(result ? edm::hlt::Pass : edm::hlt::Fail);
158  }
160  l1bitsAsHLTStatus[indices_size] = HLTPathStatus(unprefireable_bit ? edm::hlt::Pass : edm::hlt::Fail);
161  //mimic HLT trigger bits for L1
162  auto out = std::make_unique<edm::TriggerResults>(l1bitsAsHLTStatus, names_);
163  iEvent.put(std::move(out));
164 }
165 
166 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
169  desc.add<bool>("legacyL1")->setComment("is legacy L1");
170  desc.add<edm::InputTag>("src")->setComment(
171  "L1 input (L1GlobalTriggerReadoutRecord if legacy, GlobalAlgBlkBxCollection otherwise)");
172  desc.add<bool>("storeUnprefireableBit", false)
173  ->setComment("Activate storage of L1 unprefireable bit (needs L1 external decision input)");
174  desc.add<edm::InputTag>("src_ext", edm::InputTag(""))
175  ->setComment("L1 external decision input (GlobalExtBlkBxCollection, only supported if not legacy");
176  descriptions.add("L1TriggerResultsConverter", desc);
177 }
178 
179 //define this as a plug-in
L1GtTriggerMenu.h
electrons_cff.bool
bool
Definition: electrons_cff.py:393
L1TUtmTriggerMenuRcd.h
L1GtTriggerMaskAlgoTrigRcd.h
funct::false
false
Definition: Factorize.h:29
L1GtTriggerMask.h
ESHandle.h
TriggerResults.h
L1TUtmTriggerMenuRcd
Definition: L1TUtmTriggerMenuRcd.h:11
L1TriggerResultsConverter::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: L1TriggerResultsConverter.cc:99
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
edm::Run
Definition: Run.h:45
L1TriggerResultsConverter::legacyL1_
const bool legacyL1_
Definition: L1TriggerResultsConverter.cc:62
edm::EDGetTokenT< L1GlobalTriggerReadoutRecord >
GlobalExtBlk::maxExternalConditions
const static unsigned int maxExternalConditions
Definition: GlobalExtBlk.h:43
edm
HLT enums.
Definition: AlignableModifier.h:19
GlobalExtBlk.h
L1GtTriggerMenuRcd.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
edm::HLTGlobalStatus
Definition: HLTGlobalStatus.h:25
EDProducer.h
edm::Handle
Definition: AssociativeIterator.h:50
L1GlobalTriggerReadoutRecord
Definition: L1GlobalTriggerReadoutRecord.h:46
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
L1TriggerResultsConverter::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: L1TriggerResultsConverter.cc:167
word
uint64_t word
Definition: CTPPSTotemDataFormatter.cc:29
BXVector
Definition: BXVector.h:15
L1TriggerResultsConverter::store_unprefireable_bit_
const bool store_unprefireable_bit_
Definition: L1TriggerResultsConverter.cc:63
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
L1TriggerResultsConverter::tokenLegacy_
const edm::EDGetTokenT< L1GlobalTriggerReadoutRecord > tokenLegacy_
Definition: L1TriggerResultsConverter.cc:64
L1GtTriggerMenuRcd
Definition: L1GtTriggerMenuRcd.h:32
L1GtTriggerMaskAlgoTrigRcd
Definition: L1GtTriggerMaskAlgoTrigRcd.h:39
edm::ESHandle
Definition: DTSurvey.h:22
L1TriggerResultsConverter::token_ext_
const edm::EDGetTokenT< GlobalExtBlkBxCollection > token_ext_
Definition: L1TriggerResultsConverter.cc:66
L1TriggerResultsConverter::L1TriggerResultsConverter
L1TriggerResultsConverter(const edm::ParameterSet &)
Definition: L1TriggerResultsConverter.cc:77
L1TriggerResultsConverter::~L1TriggerResultsConverter
~L1TriggerResultsConverter() override
Definition: L1TriggerResultsConverter.cc:90
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
L1TUtmTriggerMenu.h
optionsL1T.menu
menu
Definition: optionsL1T.py:29
edm::hlt::Fail
reject
Definition: HLTenums.h:19
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
L1GtTriggerMask::gtTriggerMask
const std::vector< unsigned int > & gtTriggerMask() const
get the trigger mask
Definition: L1GtTriggerMask.h:47
L1GlobalTriggerReadoutRecord::decisionWord
const DecisionWord & decisionWord(int bxInEventValue) const
Definition: L1GlobalTriggerReadoutRecord.cc:186
BXVector::at
const T & at(int bx, unsigned i) const
edm::HLTPathStatus
Definition: HLTPathStatus.h:33
TriggerNames.h
L1TriggerResultsConverter::mask_
std::vector< unsigned int > mask_
Definition: L1TriggerResultsConverter.cc:68
iEvent
int iEvent
Definition: GenABIO.cc:224
GlobalAlgBlk.h
edm::stream::EDProducer
Definition: EDProducer.h:38
L1GtTriggerMenu::gtAlgorithmAliasMap
const AlgorithmMap & gtAlgorithmAliasMap() const
get / set the algorithm map (by alias)
Definition: L1GtTriggerMenu.h:192
L1TriggerResultsConverter
Definition: L1TriggerResultsConverter.cc:50
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
L1TriggerResultsConverter::indices_
std::vector< unsigned int > indices_
Definition: L1TriggerResultsConverter.cc:69
L1TriggerResultsConverter::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: L1TriggerResultsConverter.cc:129
L1TriggerResultsConverter::names_
std::vector< std::string > names_
Definition: L1TriggerResultsConverter.cc:67
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
Frameworkfwd.h
L1TriggerResultsConverter::token_
const edm::EDGetTokenT< GlobalAlgBlkBxCollection > token_
Definition: L1TriggerResultsConverter.cc:65
L1GtUtils.h
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
L1TriggerResultsConverter::m_triggerRulePrefireVetoBit
const unsigned int m_triggerRulePrefireVetoBit
Definition: L1TriggerResultsConverter.cc:71
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
mps_fire.result
result
Definition: mps_fire.py:311
ParameterSet.h
edm::hlt::Pass
accept
Definition: HLTenums.h:18
edm::Event
Definition: Event.h:73
taus_updatedMVAIds_cff.mapping
mapping
Definition: taus_updatedMVAIds_cff.py:29
edm::InputTag
Definition: InputTag.h:15