Skip to content

Commit

Permalink
Merge pull request #43387 from lathomas/l1prefirinnano_13_3_X
Browse files Browse the repository at this point in the history
(Backport) Adding L1 unprefirable event info and Final OR decision in BX-1/-2
  • Loading branch information
cmsbuild authored Dec 4, 2023
2 parents 07f00d2 + f16bd24 commit 21e4dd9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 14 deletions.
65 changes: 52 additions & 13 deletions PhysicsTools/NanoAOD/plugins/L1TriggerResultsConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class L1TriggerResultsConverter : public edm::stream::EDProducer<> {

// ----------member data ---------------------------
const bool legacyL1_;
const bool store_unprefireable_bit_;
const bool store_unprefireable_bits_;
const edm::EDGetTokenT<L1GlobalTriggerReadoutRecord> tokenLegacy_;
const edm::EDGetTokenT<GlobalAlgBlkBxCollection> token_;
const edm::EDGetTokenT<GlobalExtBlkBxCollection> token_ext_;
Expand All @@ -77,12 +77,12 @@ class L1TriggerResultsConverter : public edm::stream::EDProducer<> {
//
L1TriggerResultsConverter::L1TriggerResultsConverter(const edm::ParameterSet& params)
: legacyL1_(params.getParameter<bool>("legacyL1")),
store_unprefireable_bit_(!legacyL1_ ? params.getParameter<bool>("storeUnprefireableBit") : false),
store_unprefireable_bits_(!legacyL1_ ? params.getParameter<bool>("storeUnprefireableBits") : false),
tokenLegacy_(legacyL1_ ? consumes<L1GlobalTriggerReadoutRecord>(params.getParameter<edm::InputTag>("src"))
: edm::EDGetTokenT<L1GlobalTriggerReadoutRecord>()),
token_(!legacyL1_ ? consumes<GlobalAlgBlkBxCollection>(params.getParameter<edm::InputTag>("src"))
: edm::EDGetTokenT<GlobalAlgBlkBxCollection>()),
token_ext_(store_unprefireable_bit_
token_ext_(store_unprefireable_bits_
? consumes<GlobalExtBlkBxCollection>(params.getParameter<edm::InputTag>("src_ext"))
: edm::EDGetTokenT<GlobalExtBlkBxCollection>()),
l1gtmenuToken_(esConsumes<edm::Transition::BeginRun>()),
Expand Down Expand Up @@ -117,29 +117,47 @@ void L1TriggerResultsConverter::beginRun(edm::Run const&, edm::EventSetup const&
names_.push_back(keyval.first);
indices_.push_back(keyval.second.getIndex());
}
if (store_unprefireable_bit_)
names_.push_back("L1_UnprefireableEvent");
if (store_unprefireable_bits_) {
names_.push_back("L1_UnprefireableEvent_TriggerRules");
names_.push_back("L1_UnprefireableEvent_FirstBxInTrain");
names_.push_back("L1_FinalOR_BXmin1");
names_.push_back("L1_FinalOR_BXmin2");
}
}
}

// ------------ method called to produce the data ------------

void L1TriggerResultsConverter::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
const std::vector<bool>* wordp = nullptr;
bool unprefireable_bit = false;
const std::vector<bool>* wordp_bxmin1 = nullptr;
const std::vector<bool>* wordp_bxmin2 = nullptr;
bool unprefireable_bit_triggerrules = false;
bool unprefireable_bit_firstbxintrain = false;
bool l1FinalOR_bxmin1 = false;
bool l1FinalOR_bxmin2 = false;

if (!legacyL1_) {
const auto& resultsProd = iEvent.get(token_);
if (not resultsProd.isEmpty(0)) {
wordp = &resultsProd.at(0, 0).getAlgoDecisionFinal();
}
if (store_unprefireable_bit_) {
if (not resultsProd.isEmpty(-1)) {
wordp_bxmin1 = &resultsProd.at(-1, 0).getAlgoDecisionFinal();
}
if (not resultsProd.isEmpty(-2)) {
wordp_bxmin2 = &resultsProd.at(-2, 0).getAlgoDecisionFinal();
}
if (store_unprefireable_bits_) {
auto handleExtResults = iEvent.getHandle(token_ext_);
if (handleExtResults.isValid()) {
if (not handleExtResults->isEmpty(0)) {
unprefireable_bit = handleExtResults->at(0, 0).getExternalDecision(GlobalExtBlk::maxExternalConditions - 1);
//Stores the unprefirable event decision corresponding to trigger rules (e.g.: BX0 is unprefirable because BX-3 fired and therefore BX-2/-1 are masked).
unprefireable_bit_triggerrules =
handleExtResults->at(0, 0).getExternalDecision(GlobalExtBlk::maxExternalConditions - 1);
}
} else {
LogDebug("Unprefirable bit not found, always set to false");
LogDebug("Unprefirable bit (trigger rules) not found, always set to false");
}
}
} else {
Expand All @@ -152,12 +170,33 @@ void L1TriggerResultsConverter::produce(edm::Event& iEvent, const edm::EventSetu
for (size_t nidx = 0; nidx < indices_size; nidx++) {
unsigned int const index = indices_[nidx];
bool result = wordp ? wordp->at(index) : false;
bool result_bxmin1 = wordp_bxmin1 ? wordp_bxmin1->at(index) : false;
bool result_bxmin2 = wordp_bxmin2 ? wordp_bxmin2->at(index) : false;
if (not mask_.empty())
result &= (mask_.at(index) != 0);
l1bitsAsHLTStatus[nidx] = edm::HLTPathStatus(result ? edm::hlt::Pass : edm::hlt::Fail);
//Stores the unprefirable event decision corresponding to events in the first bx of a train.
//In 2022/2023 the bx before that was manually masked.
//Technically this was done by enabling the L1_FirstBunchBeforeTrain bit in the L1 menu, and vetoing that bit after L1 Final OR is evaluated.
if (!legacyL1_) {
if (names_[nidx] == "L1_FirstBunchBeforeTrain")
unprefireable_bit_firstbxintrain = result_bxmin1;
//Checks if any other seed was fired in BX-1 or -2
else if (result_bxmin1) {
l1FinalOR_bxmin1 = true;
} else if (result_bxmin2) {
l1FinalOR_bxmin2 = true;
}
}
}
if (store_unprefireable_bits_) {
l1bitsAsHLTStatus[indices_size] =
edm::HLTPathStatus(unprefireable_bit_triggerrules ? edm::hlt::Pass : edm::hlt::Fail);
l1bitsAsHLTStatus[indices_size + 1] =
edm::HLTPathStatus(unprefireable_bit_firstbxintrain ? edm::hlt::Pass : edm::hlt::Fail);
l1bitsAsHLTStatus[indices_size + 2] = edm::HLTPathStatus(l1FinalOR_bxmin1 ? edm::hlt::Pass : edm::hlt::Fail);
l1bitsAsHLTStatus[indices_size + 3] = edm::HLTPathStatus(l1FinalOR_bxmin2 ? edm::hlt::Pass : edm::hlt::Fail);
}
if (store_unprefireable_bit_)
l1bitsAsHLTStatus[indices_size] = edm::HLTPathStatus(unprefireable_bit ? edm::hlt::Pass : edm::hlt::Fail);
//mimic HLT trigger bits for L1
auto out = std::make_unique<edm::TriggerResults>(l1bitsAsHLTStatus, names_);
iEvent.put(std::move(out));
Expand All @@ -169,8 +208,8 @@ void L1TriggerResultsConverter::fillDescriptions(edm::ConfigurationDescriptions&
desc.add<bool>("legacyL1")->setComment("is legacy L1");
desc.add<edm::InputTag>("src")->setComment(
"L1 input (L1GlobalTriggerReadoutRecord if legacy, GlobalAlgBlkBxCollection otherwise)");
desc.add<bool>("storeUnprefireableBit", false)
->setComment("Activate storage of L1 unprefireable bit (needs L1 external decision input)");
desc.add<bool>("storeUnprefireableBits", false)
->setComment("Activate storage of L1 unprefireable bits (needs L1 external decision input)");
desc.add<edm::InputTag>("src_ext", edm::InputTag(""))
->setComment("L1 external decision input (GlobalExtBlkBxCollection, only supported if not legacy");
descriptions.add("L1TriggerResultsConverter", desc);
Expand Down
2 changes: 1 addition & 1 deletion PhysicsTools/NanoAOD/python/triggerObjects_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def AND(tokens):
l1bits=cms.EDProducer("L1TriggerResultsConverter",
src=cms.InputTag("gtStage2Digis"),
legacyL1=cms.bool(False),
storeUnprefireableBit=cms.bool(True),
storeUnprefireableBits=cms.bool(True),
src_ext=cms.InputTag("simGtExtUnprefireable"))

triggerObjectTablesTask = cms.Task( unpackedPatTrigger,triggerObjectTable,l1bits)
Expand Down

0 comments on commit 21e4dd9

Please sign in to comment.