Skip to content

Commit

Permalink
(Un)pack regional muon showers
Browse files Browse the repository at this point in the history
  • Loading branch information
dinyar committed Sep 27, 2021
1 parent 53e8347 commit 76d060a
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#include "EventFilter/L1TRawToDigi/plugins/PackingSetupFactory.h"
#include "EventFilter/L1TRawToDigi/plugins/UnpackerFactory.h"

#include "EventFilter/L1TRawToDigi/plugins/implementations_stage2/RegionalMuonGMTUnpacker.h"
#include "EventFilter/L1TRawToDigi/plugins/implementations_stage2/RegionalMuonGMTPacker.h"
#include "EventFilter/L1TRawToDigi/plugins/implementations_stage2/RegionalMuonGMTUnpacker.h"
#include "EventFilter/L1TRawToDigi/plugins/implementations_stage2/MuonPacker.h"
#include "EventFilter/L1TRawToDigi/plugins/implementations_stage2/IntermediateMuonUnpacker.h"
#include "EventFilter/L1TRawToDigi/plugins/implementations_stage2/MuonUnpacker.h"
#include "EventFilter/L1TRawToDigi/plugins/implementations_stage2/IntermediateMuonUnpacker.h"

#include "GMTSetup.h"

Expand All @@ -36,13 +36,18 @@ namespace l1t {
->setComment("uGMT intermediate muon from neg. OMTF side after first sorting stage");
desc.addOptional<edm::InputTag>("ImdInputLabelOMTFPos")
->setComment("uGMT intermediate muon from pos. OMTF side after first sorting stage");
desc.addOptional<edm::InputTag>("ShowerInputLabel")->setComment("for Run3");
desc.addOptional<edm::InputTag>("EMTFShowerInputLabel")->setComment("for Run3");
}

PackerMap GMTSetup::getPackers(int fed, unsigned int fw) {
PackerMap res;
if (fed == 1402) {
auto gmt_in_packer = static_pointer_cast<l1t::stage2::RegionalMuonGMTPacker>(
PackerFactory::get()->make("stage2::RegionalMuonGMTPacker"));
if (fw >= 0x7000000) {
gmt_in_packer->setUseEmtfShowers();
}
if (fw >= 0x6010000) {
gmt_in_packer->setUseEmtfDisplacementInfo();
}
Expand Down Expand Up @@ -76,6 +81,12 @@ namespace l1t {
prod.produces<MuonBxCollection>("imdMuonsEMTFPos");
prod.produces<MuonBxCollection>("imdMuonsOMTFNeg");
prod.produces<MuonBxCollection>("imdMuonsOMTFPos");

prod.produces<RegionalMuonShowerBxCollection>("EMTF");
prod.produces<MuonShowerBxCollection>("MuonShower");
for (int i = 1; i < 6; ++i) {
prod.produces<MuonShowerBxCollection>("MuonShowerCopy" + std::to_string(i));
}
}

std::unique_ptr<UnpackerCollections> GMTSetup::getCollections(edm::Event& e) {
Expand All @@ -89,6 +100,9 @@ namespace l1t {
// input muons on links 36-71
auto gmt_in_unp = static_pointer_cast<l1t::stage2::RegionalMuonGMTUnpacker>(
UnpackerFactory::get()->make("stage2::RegionalMuonGMTUnpacker"));
if (fw >= 0x7000000) {
gmt_in_unp->setUseEmtfShowers();
}
if (fw >= 0x6010000) {
gmt_in_unp->setUseEmtfDisplacementInfo();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Framework/interface/Event.h"
#include "EventFilter/L1TRawToDigi/plugins/PackerFactory.h"

Expand All @@ -8,62 +9,121 @@
namespace l1t {
namespace stage2 {
Blocks RegionalMuonGMTPacker::pack(const edm::Event& event, const PackerTokens* toks) {
GMTObjectMap bmtfObjMap;
GMTObjectMap omtfObjMap;
GMTObjectMap emtfObjMap;
auto bmtfToken = static_cast<const GMTTokens*>(toks)->getRegionalMuonCandTokenBMTF();
auto omtfToken = static_cast<const GMTTokens*>(toks)->getRegionalMuonCandTokenOMTF();
auto emtfToken = static_cast<const GMTTokens*>(toks)->getRegionalMuonCandTokenEMTF();

// First we put the muons in our object map.
std::pair<int, int> bmtfMuonBx = getMuons(bmtfObjMap, event, bmtfToken);
std::pair<int, int> omtfMuonBx = getMuons(omtfObjMap, event, omtfToken);
std::pair<int, int> emtfMuonBx = getMuons(emtfObjMap, event, emtfToken);

// Then the showers (We don't expect to have shower data from BMTF and OMTF -- at the moment, at least)
std::pair<int, int> emtfMuonShowerBx{0, 0};
if (useEmtfShowers_) {
auto emtfShowerToken = static_cast<const GMTTokens*>(toks)->getRegionalMuonShowerTokenEMTF();
emtfMuonShowerBx = getMuonShowers(emtfObjMap, event, emtfShowerToken);
}

Blocks blocks;

// pack the muons for each TF in blocks
packTF(event, bmtfToken, blocks);
packTF(event, omtfToken, blocks);
packTF(event, emtfToken, blocks);
// Pack the muons and showers for each TF in blocks
packTF(bmtfObjMap, bmtfMuonBx.first, bmtfMuonBx.second, 0, 0, blocks);
packTF(omtfObjMap, omtfMuonBx.first, omtfMuonBx.second, 0, 0, blocks);
packTF(emtfObjMap, emtfMuonBx.first, emtfMuonBx.second, emtfMuonShowerBx.first, emtfMuonShowerBx.second, blocks);

return blocks;
}

void RegionalMuonGMTPacker::packTF(const edm::Event& event,
const edm::EDGetTokenT<RegionalMuonCandBxCollection>& tfToken,
Blocks& blocks) {
std::pair<int, int> RegionalMuonGMTPacker::getMuonShowers(
GMTObjectMap& objMap,
const edm::Event& event,
const edm::EDGetTokenT<RegionalMuonShowerBxCollection>& tfShowerToken) {
edm::Handle<RegionalMuonShowerBxCollection> muonShowers;
event.getByToken(tfShowerToken, muonShowers);
for (int bx = muonShowers->getFirstBX(); bx <= muonShowers->getLastBX(); ++bx) {
for (auto muShower = muonShowers->begin(bx); muShower != muonShowers->end(bx); ++muShower) {
objMap[bx][muShower->link()].shower = *muShower;
}
}
return std::make_pair(muonShowers->getFirstBX(), muonShowers->getLastBX());
}

std::pair<int, int> RegionalMuonGMTPacker::getMuons(GMTObjectMap& objMap,
const edm::Event& event,
const edm::EDGetTokenT<RegionalMuonCandBxCollection>& tfToken) {
edm::Handle<RegionalMuonCandBxCollection> muons;
event.getByToken(tfToken, muons);
for (int bx = muons->getFirstBX(); bx <= muons->getLastBX(); ++bx) {
for (auto mu = muons->begin(bx); mu != muons->end(bx); ++mu) {
objMap[bx][mu->link()].mus.push_back(*mu);
}
}
return std::make_pair(muons->getFirstBX(), muons->getLastBX());
}

constexpr unsigned wordsPerBx = 6; // number of 32 bit words per BX
void RegionalMuonGMTPacker::packTF(const GMTObjectMap& objMap,
const int firstMuonBx,
const int lastMuonBx,
const int firstMuonShowerBx,
const int lastMuonShowerBx,
Blocks& blocks) {
const auto firstBx{std::min(firstMuonShowerBx, firstMuonBx)};
const auto lastBx{std::max(lastMuonShowerBx, lastMuonBx)};
const auto nBx{lastBx - firstBx + 1};

PayloadMap payloadMap;

const auto nBx = muons->getLastBX() - muons->getFirstBX() + 1;
unsigned bxCtr = 0;
for (int i = muons->getFirstBX(); i <= muons->getLastBX(); ++i, ++bxCtr) {
for (auto mu = muons->begin(i); mu != muons->end(i); ++mu) {
const auto linkTimes2 = mu->link() * 2;

// If the map key is new reserve the payload size.
if (payloadMap.count(linkTimes2) == 0) {
payloadMap[linkTimes2].reserve(wordsPerBx * nBx);
// If there was no muon on the link of this muon in previous
// BX the payload up to this BX must be filled with zeros.
if (bxCtr > 0) {
while (payloadMap[linkTimes2].size() < bxCtr * wordsPerBx) {
payloadMap[linkTimes2].push_back(0);
for (int bx{firstBx}; bx < lastBx; ++bx, ++bxCtr) {
if (objMap.count(bx) > 0) {
for (const auto& linkMap : objMap.at(bx)) {
const auto linkTimes2{linkMap.first * 2};
const auto gmtObjects{linkMap.second};

// If the payload map key is new reserve the payload size.
if (payloadMap.count(linkTimes2) == 0) {
payloadMap[linkTimes2].reserve(wordsPerBx_ * nBx);
// If there was no muon on the link of this muon in previous
// BX the payload up to this BX must be filled with zeros.
if (bxCtr > 0) {
while (payloadMap[linkTimes2].size() < bxCtr * wordsPerBx_) {
payloadMap[linkTimes2].push_back(0);
}
}
}
}

// Fill the muon in the payload for this link.
uint32_t msw = 0;
uint32_t lsw = 0;
if (gmtObjects.mus.size() > 3) {
edm::LogError("L1T") << "Muon collection for link " << linkMap.first << " has " << gmtObjects.mus.size()
<< " entries, but 3 is the maximum!";
}

RegionalMuonRawDigiTranslator::generatePackedDataWords(*mu, lsw, msw, isKbmtf_, useEmtfDisplacementInfo_);
std::array<uint32_t, 6> buf{}; // Making sure contents of buf are initialised to 0.
size_t frameIdx{0};
for (const auto& mu : gmtObjects.mus) {
// Fill the muon in the payload for this link.
uint32_t msw{0};
uint32_t lsw{0};

payloadMap[linkTimes2].push_back(lsw);
payloadMap[linkTimes2].push_back(msw);
}
RegionalMuonRawDigiTranslator::generatePackedDataWords(mu, lsw, msw, isKbmtf_, useEmtfDisplacementInfo_);

// padding to 3 muons per block id (link) per BX
// This can be empty muons as well.
buf.at(frameIdx++) = lsw;
buf.at(frameIdx++) = msw;
}
// Add shower bits to the payload buffer.
RegionalMuonRawDigiTranslator::generatePackedShowerPayload(gmtObjects.shower, buf, useEmtfShowers_);

payloadMap[linkTimes2].insert(
payloadMap[linkTimes2].end(), std::move_iterator(buf.begin()), std::move_iterator(buf.end()));
}
}
// We now loop over all channels in the payload map and make sure that they are filled up to the current BX
// If they are not, we fill them with zeros
for (auto& kv : payloadMap) {
while (kv.second.size() < (bxCtr + 1) * wordsPerBx) {
while (kv.second.size() < (bxCtr + 1) * wordsPerBx_) {
kv.second.push_back(0);
}
}
Expand All @@ -74,6 +134,7 @@ namespace l1t {
blocks.push_back(Block(kv.first, kv.second));
}
}

} // namespace stage2
} // namespace l1t

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "EventFilter/L1TRawToDigi/interface/PackerTokens.h"
#include "EventFilter/L1TRawToDigi/interface/Block.h"
#include "DataFormats/L1TMuon/interface/RegionalMuonCand.h"
#include "DataFormats/L1TMuon/interface/RegionalMuonShower.h"
#include "FWCore/Framework/interface/Event.h"

namespace l1t {
Expand All @@ -15,13 +16,33 @@ namespace l1t {
Blocks pack(const edm::Event&, const PackerTokens*) override;
void setIsKbmtf() { isKbmtf_ = true; };
void setUseEmtfDisplacementInfo() { useEmtfDisplacementInfo_ = true; };
void setUseEmtfShowers() { useEmtfShowers_ = true; };

private:
struct GMTObjects {
std::vector<RegionalMuonCand> mus;
RegionalMuonShower shower;
};
typedef std::map<size_t, std::map<size_t, GMTObjects>> GMTObjectMap; // Map of BX --> linkID --> objects
typedef std::map<unsigned int, std::vector<uint32_t>> PayloadMap;
void packTF(const edm::Event&, const edm::EDGetTokenT<RegionalMuonCandBxCollection>&, Blocks&);
void packTF(const GMTObjectMap& objMap,
int firstMuonBx,
int lastMuonBx,
int firstMuonShowerBx,
int lastMuonShowerBx,
Blocks&);
std::pair<int, int> getMuons(GMTObjectMap& objMap,
const edm::Event& event,
const edm::EDGetTokenT<RegionalMuonCandBxCollection>& tfToken);
std::pair<int, int> getMuonShowers(GMTObjectMap& objMap,
const edm::Event& event,
const edm::EDGetTokenT<RegionalMuonShowerBxCollection>& tfShowerToken);

static constexpr size_t wordsPerBx_ = 6; // number of 32 bit words per BX

bool isKbmtf_{false};
bool useEmtfDisplacementInfo_{false};
bool useEmtfShowers_{false};
};
} // namespace stage2
} // namespace l1t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,19 @@ namespace l1t {
// decide which collection to use according to the link ID
unsigned int linkId = blockId / 2;
int processor;
RegionalMuonCandBxCollection* res;
RegionalMuonCandBxCollection* regionalMuonCollection;
RegionalMuonShowerBxCollection* regionalMuonShowerCollection;
tftype trackFinder;
if (linkId > 47 && linkId < 60) {
res = static_cast<GMTCollections*>(coll)->getRegionalMuonCandsBMTF();
regionalMuonCollection = static_cast<GMTCollections*>(coll)->getRegionalMuonCandsBMTF();
regionalMuonShowerCollection =
new RegionalMuonShowerBxCollection(); // To avoid warning re uninitialised collection
trackFinder = tftype::bmtf;
processor = linkId - 48;
} else if (linkId > 41 && linkId < 66) {
res = static_cast<GMTCollections*>(coll)->getRegionalMuonCandsOMTF();
regionalMuonCollection = static_cast<GMTCollections*>(coll)->getRegionalMuonCandsOMTF();
regionalMuonShowerCollection =
new RegionalMuonShowerBxCollection(); // To avoid warning re uninitialised collection
if (linkId < 48) {
trackFinder = tftype::omtf_pos;
processor = linkId - 42;
Expand All @@ -49,7 +54,8 @@ namespace l1t {
processor = linkId - 60;
}
} else if (linkId > 35 && linkId < 72) {
res = static_cast<GMTCollections*>(coll)->getRegionalMuonCandsEMTF();
regionalMuonCollection = static_cast<GMTCollections*>(coll)->getRegionalMuonCandsEMTF();
regionalMuonShowerCollection = static_cast<GMTCollections*>(coll)->getRegionalMuonShowersEMTF();
if (linkId < 42) {
trackFinder = tftype::emtf_pos;
processor = linkId - 36;
Expand All @@ -61,7 +67,8 @@ namespace l1t {
edm::LogError("L1T") << "No TF muon expected for link " << linkId;
return false;
}
res->setBXRange(firstBX, lastBX);
regionalMuonCollection->setBXRange(firstBX, lastBX);
regionalMuonShowerCollection->setBXRange(firstBX, lastBX);

LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX;

Expand Down Expand Up @@ -108,7 +115,13 @@ namespace l1t {
<< mu.hwPt() << " qual " << mu.hwQual() << " sign " << mu.hwSign() << " sign valid "
<< mu.hwSignValid() << " unconstrained pT " << mu.hwPtUnconstrained();

res->push_back(bx, mu);
regionalMuonCollection->push_back(bx, mu);
}
// Fill RegionalMuonShower objects. For this we need to look at all six words together.
RegionalMuonShower muShower;
if (RegionalMuonRawDigiTranslator::fillRegionalMuonShower(
muShower, bxPayload, processor, trackFinder, useEmtfShowers_)) {
regionalMuonShowerCollection->push_back(bx, muShower);
}
} else {
unsigned int nWords =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ namespace l1t {
bool unpack(const Block& block, UnpackerCollections* coll) override;
void setIsKbmtf() { isKbmtf_ = true; }
void setUseEmtfDisplacementInfo() { useEmtfDisplacementInfo_ = true; }
void setUseEmtfShowers() { useEmtfShowers_ = true; }

private:
static constexpr unsigned nWords_ = 6; // every link transmits 6 words (3 muons) per bx
static constexpr unsigned bxzs_enable_shift_ = 1;

bool isKbmtf_{false};
bool useEmtfDisplacementInfo_{false};
bool useEmtfShowers_{false};
};
} // namespace stage2
} // namespace l1t
Expand Down
4 changes: 3 additions & 1 deletion EventFilter/L1TRawToDigi/python/gmtStage2Raw_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
ImdInputLabelEMTFPos = cms.InputTag("simGmtStage2Digis", "imdMuonsEMTFPos"),
ImdInputLabelOMTFNeg = cms.InputTag("simGmtStage2Digis", "imdMuonsOMTFNeg"),
ImdInputLabelOMTFPos = cms.InputTag("simGmtStage2Digis", "imdMuonsOMTFPos"),
EMTFShowerInputLabel = cms.InputTag("simEmtfShowers", "EMTF"),
ShowerInputLabel = cms.InputTag("simGmtShowerDigis"),
FedId = cms.int32(1402),
FWId = cms.uint32(0x3000000), # First used uGMT firmware version
lenSlinkHeader = cms.untracked.int32(8),
Expand All @@ -32,4 +34,4 @@

### Era: Run3_2021
from Configuration.Eras.Modifier_stage2L1Trigger_2021_cff import stage2L1Trigger_2021
stage2L1Trigger_2021.toModify(gmtStage2Raw, BMTFInputLabel = cms.InputTag("simKBmtfDigis", "BMTF"), FWId = cms.uint32(0x6010000))
stage2L1Trigger_2021.toModify(gmtStage2Raw, BMTFInputLabel = cms.InputTag("simKBmtfDigis", "BMTF"), FWId = cms.uint32(0x7000000))

0 comments on commit 76d060a

Please sign in to comment.