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_;
70  std::vector<std::string> names_;
71  std::vector<unsigned int> mask_;
72  std::vector<unsigned int> indices_;
73 };
74 
75 //
76 // constructors and destructor
77 //
79  : legacyL1_(params.getParameter<bool>("legacyL1")),
80  store_unprefireable_bit_(!legacyL1_ ? params.getParameter<bool>("storeUnprefireableBit") : false),
81  tokenLegacy_(legacyL1_ ? consumes<L1GlobalTriggerReadoutRecord>(params.getParameter<edm::InputTag>("src"))
82  : edm::EDGetTokenT<L1GlobalTriggerReadoutRecord>()),
83  token_(!legacyL1_ ? consumes<GlobalAlgBlkBxCollection>(params.getParameter<edm::InputTag>("src"))
84  : edm::EDGetTokenT<GlobalAlgBlkBxCollection>()),
85  token_ext_(store_unprefireable_bit_
86  ? consumes<GlobalExtBlkBxCollection>(params.getParameter<edm::InputTag>("src_ext"))
87  : edm::EDGetTokenT<GlobalExtBlkBxCollection>()),
88  l1gtmenuToken_(esConsumes<edm::Transition::BeginRun>()),
89  l1gtalgoMaskToken_(esConsumes<edm::Transition::BeginRun>()),
90  l1utmTrigToken_(esConsumes<edm::Transition::BeginRun>()) {
91  produces<edm::TriggerResults>();
92 }
93 
95  // do anything here that needs to be done at destruction time
96  // (e.g. close files, deallocate resources etc.)
97 }
98 
99 //
100 // member functions
101 //
102 
104  mask_.clear();
105  names_.clear();
106  indices_.clear();
107  if (legacyL1_) {
108  auto const& mapping = setup.getHandle(l1gtmenuToken_)->gtAlgorithmAliasMap();
109  for (auto const& keyval : mapping) {
110  names_.push_back(keyval.first);
111  indices_.push_back(keyval.second.algoBitNumber());
112  }
113  mask_ = setup.getHandle(l1gtalgoMaskToken_)->gtTriggerMask();
114  } else {
115  auto const& mapping = setup.getHandle(l1utmTrigToken_)->getAlgorithmMap();
116  for (auto const& keyval : mapping) {
117  names_.push_back(keyval.first);
118  indices_.push_back(keyval.second.getIndex());
119  }
121  names_.push_back("L1_UnprefireableEvent");
122  }
123 }
124 
125 // ------------ method called to produce the data ------------
126 
128  using namespace edm;
129  const std::vector<bool>* wordp = nullptr;
130  bool unprefireable_bit = false;
131  if (!legacyL1_) {
133  iEvent.getByToken(token_, handleResults);
134  wordp = &handleResults->at(0, 0).getAlgoDecisionFinal();
136  edm::Handle<GlobalExtBlkBxCollection> handleExtResults;
137  iEvent.getByToken(token_ext_, handleExtResults);
138  if (handleExtResults->size() != 0) {
139  unprefireable_bit = handleExtResults->at(0, 0).getExternalDecision(GlobalExtBlk::maxExternalConditions - 1);
140  }
141  }
142  } else {
143  // Legacy access
145  iEvent.getByToken(tokenLegacy_, handleResults);
146  wordp = &handleResults->decisionWord();
147  }
148  auto const& word = *wordp;
149  HLTGlobalStatus l1bitsAsHLTStatus(names_.size());
150  unsigned indices_size = indices_.size();
151  for (size_t nidx = 0; nidx < indices_size; nidx++) {
152  unsigned int index = indices_[nidx];
153  bool result = word[index];
154  if (!mask_.empty())
155  result &= (mask_[index] != 0);
156  l1bitsAsHLTStatus[nidx] = HLTPathStatus(result ? edm::hlt::Pass : edm::hlt::Fail);
157  }
159  l1bitsAsHLTStatus[indices_size] = HLTPathStatus(unprefireable_bit ? edm::hlt::Pass : edm::hlt::Fail);
160  //mimic HLT trigger bits for L1
161  auto out = std::make_unique<edm::TriggerResults>(l1bitsAsHLTStatus, names_);
162  iEvent.put(std::move(out));
163 }
164 
165 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
168  desc.add<bool>("legacyL1")->setComment("is legacy L1");
169  desc.add<edm::InputTag>("src")->setComment(
170  "L1 input (L1GlobalTriggerReadoutRecord if legacy, GlobalAlgBlkBxCollection otherwise)");
171  desc.add<bool>("storeUnprefireableBit", false)
172  ->setComment("Activate storage of L1 unprefireable bit (needs L1 external decision input)");
173  desc.add<edm::InputTag>("src_ext", edm::InputTag(""))
174  ->setComment("L1 external decision input (GlobalExtBlkBxCollection, only supported if not legacy");
175  descriptions.add("L1TriggerResultsConverter", desc);
176 }
177 
178 //define this as a plug-in
L1GtTriggerMenu.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
L1GtTriggerMaskAlgoTrigRcd.h
funct::false
false
Definition: Factorize.h:29
L1GtTriggerMask.h
L1TriggerResultsConverter::l1gtmenuToken_
edm::ESGetToken< L1GtTriggerMenu, L1GtTriggerMenuRcd > l1gtmenuToken_
Definition: L1TriggerResultsConverter.cc:67
ESHandle.h
TriggerResults.h
L1TriggerResultsConverter::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: L1TriggerResultsConverter.cc:103
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:89301
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
edm::HLTGlobalStatus
Definition: HLTGlobalStatus.h:25
EDProducer.h
L1TriggerResultsConverter::l1gtalgoMaskToken_
edm::ESGetToken< L1GtTriggerMask, L1GtTriggerMaskAlgoTrigRcd > l1gtalgoMaskToken_
Definition: L1TriggerResultsConverter.cc:68
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:166
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
L1TriggerResultsConverter::token_ext_
const edm::EDGetTokenT< GlobalExtBlkBxCollection > token_ext_
Definition: L1TriggerResultsConverter.cc:66
L1TriggerResultsConverter::L1TriggerResultsConverter
L1TriggerResultsConverter(const edm::ParameterSet &)
Definition: L1TriggerResultsConverter.cc:78
L1TriggerResultsConverter::~L1TriggerResultsConverter
~L1TriggerResultsConverter() override
Definition: L1TriggerResultsConverter.cc:94
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
L1TriggerResultsConverter::l1utmTrigToken_
edm::ESGetToken< L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd > l1utmTrigToken_
Definition: L1TriggerResultsConverter.cc:69
L1TUtmTriggerMenu.h
L1TUtmTriggerMenuRcd.h
edm::hlt::Fail
reject
Definition: HLTenums.h:19
edm::ParameterSet
Definition: ParameterSet.h:47
edm::Transition
Transition
Definition: Transition.h:12
Event.h
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:71
iEvent
int iEvent
Definition: GenABIO.cc:224
GlobalAlgBlk.h
edm::stream::EDProducer
Definition: EDProducer.h:36
L1TriggerResultsConverter
Definition: L1TriggerResultsConverter.cc:50
edm::EventSetup
Definition: EventSetup.h:58
L1TriggerResultsConverter::indices_
std::vector< unsigned int > indices_
Definition: L1TriggerResultsConverter.cc:72
edm::ESGetToken< L1GtTriggerMenu, L1GtTriggerMenuRcd >
L1TriggerResultsConverter::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: L1TriggerResultsConverter.cc:127
L1TriggerResultsConverter::names_
std::vector< std::string > names_
Definition: L1TriggerResultsConverter.cc:70
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
BXVector::size
unsigned size(int bx) const
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
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
taus_updatedMVAIds_cff.mapping
mapping
Definition: taus_updatedMVAIds_cff.py:29
edm::InputTag
Definition: InputTag.h:15