Skip to content

Commit

Permalink
Merge pull request #45826 from aloeliger/CICADA_uGT_Packer
Browse files Browse the repository at this point in the history
CICADA-uGT Packer
  • Loading branch information
cmsbuild authored Sep 26, 2024
2 parents 5359de2 + 33a97a9 commit 25f557a
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
simGtStage2Digis.JetInputTag = "unpackGtStage2:Jet"
simGtStage2Digis.EtSumInputTag = "unpackGtStage2:EtSum"
simGtStage2Digis.EtSumZdcInputTag = "unpackGtStage2:EtSumZDC"
simGtStage2Digis.CICADAScoreInputTag = "unpackGtStage2:CICADAScore"
simGtStage2Digis.ExtInputTag = "unpackGtStage2" # as in default


Expand All @@ -44,6 +45,7 @@
packGtStage2.JetInputTag = "unpackGtStage2:Jet"
packGtStage2.EtSumInputTag = "unpackGtStage2:EtSum"
packGtStage2.EtSumZDCInputTag = "unpackGtStage2:EtSumZDC"
packGtStage2.CICADAScoreInputTag = "unpackGtStage2:CICADAScore"
packGtStage2.GtInputTag = "simGtStage2Digis" # as in default
packGtStage2.ExtInputTag = "unpackGtStage2" # as in default

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "FWCore/Framework/interface/Event.h"
#include "EventFilter/L1TRawToDigi/plugins/PackerFactory.h"

#include "GTTokens.h"

#include "CaloSummaryPacker.h"

namespace l1t {
namespace stage2 {
std::vector<uint32_t> CaloSummaryPacker::generateCICADAWordsFromScore(float score) {
//Shift the score up by 8 bits, and turn it into an integer for easy working with
//the bits
uint32_t cicadaBits = static_cast<uint32_t>(score * 256.f);
//CICADA word goes from most significant bits, to least significant
//But always at the start of the word, so the resultant words need to be adjusted upwards
uint32_t firstWord = (cicadaBits & 0xF000) << 16;
uint32_t secondWord = (cicadaBits & 0x0F00) << 20;
uint32_t thirdWord = (cicadaBits & 0x00F0) << 24;
uint32_t fourthWord = (cicadaBits & 0x000F) << 28;

return {firstWord, secondWord, thirdWord, fourthWord};
}

Blocks CaloSummaryPacker::pack(const edm::Event& event, const PackerTokens* toks) {
edm::Handle<CICADABxCollection> cicadaScores;
event.getByToken(static_cast<const GTTokens*>(toks)->getCICADAToken(), cicadaScores);

std::vector<uint32_t> payload;

for (int i = cicadaScores->getFirstBX(); i <= cicadaScores->getLastBX(); ++i) {
//check if we _have_ a CICADA score to work with, the emulator does not
//guarantee 5 BX worth of CICADA, but unpacked data from uGT does
//If we do not have a CICADA score for a BX, we can simply treat that as
//a zero score.
//otherwise, once we have a CICADA score, we can simply construct the 6
//words (4 with CICADA bits, 2 without), from the score
float CICADAScore = 0.0;
if (cicadaScores->size(i) != 0) {
CICADAScore = cicadaScores->at(
i, 0); //Shouldn't ever have more than one score per BX, so this should be safe if the size is not 0
}
//Make the CICADA words
std::vector<uint32_t> bxWords = generateCICADAWordsFromScore(CICADAScore);
payload.insert(payload.end(), bxWords.begin(), bxWords.end());
//Remaining two 32 bit words of CICADA are unused
payload.push_back(0);
payload.push_back(0);
}

return {Block(22, payload)};
}
} // namespace stage2
} // namespace l1t

DEFINE_L1T_PACKER(l1t::stage2::CaloSummaryPacker);
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef PACKER_STAGE2_CALOSUMMARYPACKER_H
#define PACKER_STAGE2_CALOSUMMARYPACKER_H

#include "EventFilter/L1TRawToDigi/interface/Packer.h"

namespace l1t {
namespace stage2 {
class CaloSummaryPacker : public Packer {
private:
std::vector<uint32_t> generateCICADAWordsFromScore(float);

public:
Blocks pack(const edm::Event&, const PackerTokens*) override;
};
} // namespace stage2
} // namespace l1t

#endif
20 changes: 12 additions & 8 deletions EventFilter/L1TRawToDigi/plugins/implementations_stage2/GTSetup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace l1t {
desc.addOptional<edm::InputTag>("TauInputTag")->setComment("for stage2");
desc.addOptional<edm::InputTag>("EtSumInputTag")->setComment("for stage2");
desc.addOptional<edm::InputTag>("EtSumZDCInputTag")->setComment("for stage2");
desc.addOptional<edm::InputTag>("CICADAScoreInputTag")->setComment("for 2024 and beyond");
}

PackerMap GTSetup::getPackers(int fed, unsigned int fw) {
Expand All @@ -44,14 +45,17 @@ namespace l1t {
static_pointer_cast<l1t::stage2::GTMuonPacker>(PackerFactory::get()->make("stage2::GTMuonPacker"));
gt_muon_packer->setFed(fed);
gt_muon_packer->setFwVersion(fw);
res[{1, 1}] = {gt_muon_packer,
PackerFactory::get()->make("stage2::GTEGammaPacker"),
PackerFactory::get()->make("stage2::GTEtSumPacker"),
PackerFactory::get()->make("stage2::GTEtSumZDCPacker"),
PackerFactory::get()->make("stage2::GTJetPacker"),
PackerFactory::get()->make("stage2::GTTauPacker"),
PackerFactory::get()->make("stage2::GlobalAlgBlkPacker"),
PackerFactory::get()->make("stage2::GlobalExtBlkPacker")};
res[{1, 1}] = {
gt_muon_packer,
PackerFactory::get()->make("stage2::GTEGammaPacker"),
PackerFactory::get()->make("stage2::GTEtSumPacker"),
PackerFactory::get()->make("stage2::GTEtSumZDCPacker"),
PackerFactory::get()->make("stage2::GTJetPacker"),
PackerFactory::get()->make("stage2::GTTauPacker"),
PackerFactory::get()->make("stage2::GlobalAlgBlkPacker"),
PackerFactory::get()->make("stage2::GlobalExtBlkPacker"),
PackerFactory::get()->make("stage2::CaloSummaryPacker"),
};
}

return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace l1t {
auto etsumzdctag = cfg.getParameter<edm::InputTag>("EtSumZDCInputTag");
auto muontag = cfg.getParameter<edm::InputTag>("MuonInputTag");
auto muonshowertag = cfg.getParameter<edm::InputTag>("ShowerInputLabel");
auto cicadascoretag = cfg.getParameter<edm::InputTag>("CICADAScoreInputTag");

//cout << "DEBUG: GmtInputTag" << muontag << "\n";

Expand All @@ -28,6 +29,7 @@ namespace l1t {
tauToken_ = cc.consumes<TauBxCollection>(tautag);
algToken_ = cc.consumes<GlobalAlgBlkBxCollection>(gttag);
extToken_ = cc.consumes<GlobalExtBlkBxCollection>(exttag);
cicadaToken_ = cc.consumes<CICADABxCollection>(cicadascoretag);
}
} // namespace stage2
} // namespace l1t
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "DataFormats/L1Trigger/interface/Muon.h"
#include "DataFormats/L1TGlobal/interface/GlobalAlgBlk.h"
#include "DataFormats/L1TGlobal/interface/GlobalExtBlk.h"
#include "DataFormats/L1CaloTrigger/interface/CICADA.h"

#include "CommonTokens.h"

Expand All @@ -19,10 +20,12 @@ namespace l1t {

inline const edm::EDGetTokenT<GlobalAlgBlkBxCollection>& getAlgToken() const { return algToken_; };
inline const edm::EDGetTokenT<GlobalExtBlkBxCollection>& getExtToken() const { return extToken_; };
inline const edm::EDGetTokenT<CICADABxCollection>& getCICADAToken() const { return cicadaToken_; };

private:
edm::EDGetTokenT<GlobalAlgBlkBxCollection> algToken_;
edm::EDGetTokenT<GlobalExtBlkBxCollection> extToken_;
edm::EDGetTokenT<CICADABxCollection> cicadaToken_;
};
} // namespace stage2
} // namespace l1t
Expand Down
1 change: 1 addition & 0 deletions EventFilter/L1TRawToDigi/python/gtStage2Raw_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
JetInputTag = cms.InputTag("simCaloStage2Digis"),
EtSumInputTag = cms.InputTag("simCaloStage2Digis"),
EtSumZDCInputTag = cms.InputTag("l1tZDCEtSums"),
CICADAScoreInputTag = cms.InputTag("simCaloStage2Layer1Summary", "CICADAScore"),
FedId = cms.int32(1404),
FWId = cms.uint32(0x1150), # FW w/ 2loose hadronic showers.
lenSlinkHeader = cms.untracked.int32(8),
Expand Down

0 comments on commit 25f557a

Please sign in to comment.