Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14_0] CICADA-uGT emulator additions #45293

Merged
merged 17 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions DataFormats/L1CaloTrigger/interface/CICADA.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef DataFormats_L1Trigger_CICADA_h
#define DataFormats_L1Trigger_CICADA_h

#include "DataFormats/L1Trigger/interface/BXVector.h"

namespace l1t {
typedef BXVector<float> CICADABxCollection;
}

#endif
1 change: 1 addition & 0 deletions DataFormats/L1CaloTrigger/src/classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
#include <vector>
#include "DataFormats/L1CaloTrigger/interface/L1CaloCollections.h"
#include "DataFormats/Common/interface/Wrapper.h"
#include "DataFormats/L1CaloTrigger/interface/CICADA.h"
4 changes: 4 additions & 0 deletions DataFormats/L1CaloTrigger/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@
<class name="std::vector<L1CaloRegion>"/>
<class name="edm::Wrapper<std::vector<L1CaloEmCand>>" splitLevel="0"/>
<class name="edm::Wrapper<std::vector<L1CaloRegion>>" splitLevel="0"/>

<class name="l1t::CICADABxCollection"/>
<class name="BXVector<float>"/>
<class name="edm::Wrapper<BXVector<float>>"/>
</lcgdict>
1 change: 1 addition & 0 deletions EventFilter/L1TRawToDigi/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<use name="DataFormats/RPCDigi"/>
<use name="DataFormats/L1DTTrackFinder"/>
<use name="DataFormats/L1TMuon"/>
<use name="DataFormats/L1CaloTrigger"/>
<use name="EventFilter/RPCRawToDigi"/>
<use name="boost_regex"/>
<export>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "EventFilter/L1TRawToDigi/plugins/UnpackerFactory.h"

#include "CICADAUnpacker.h"

#include <cmath>

using namespace edm;

namespace l1t {
namespace stage2 {
bool CICADAUnpacker::unpack(const Block& block, UnpackerCollections* coll) {
LogDebug("L1T") << "Block Size = " << block.header().getSize();
LogDebug("L1T") << "Board ID = " << block.amc().getBoardID();

auto res = static_cast<CaloLayer1Collections*>(coll)->getCICADABxCollection();
// default BX range to trigger standard -2 to 2
// Even though CICADA will never have BX information
// And everything gets put in BX 0
res->setBXRange(-2, 2);

int amc_slot = block.amc().getAMCNumber();
if (not(amc_slot == 7)) {
throw cms::Exception("CICADAUnpacker")
<< "Calo Summary (CICADA) unpacker is unpacking an unexpected AMC. Expected AMC number 7, got AMC number "
<< amc_slot << std::endl;
return false;
} else {
const uint32_t* base = block.payload().data();
//First 4 bits of the first 4 words are CICADA bits
uint32_t word = (caloCrateCicadaBitsPattern & base[0]) >> 16 | (caloCrateCicadaBitsPattern & base[1]) >> 20 |
(caloCrateCicadaBitsPattern & base[2]) >> 24 | (caloCrateCicadaBitsPattern & base[3]) >> 28;
float score = static_cast<float>(word) / 256.f;
res->push_back(0, score);
return true;
}
}

} // namespace stage2
} // namespace l1t

DEFINE_L1T_UNPACKER(l1t::stage2::CICADAUnpacker);
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef EventFilter_L1TRawToDigi_CICADAUnpacker_h
#define EventFilter_L1TRawToDigi_CICADAUnpacker_h

#include "EventFilter/L1TRawToDigi/interface/Unpacker.h"
#include "CaloLayer1Collections.h"

namespace l1t {
namespace stage2 {
class CICADAUnpacker : public Unpacker {
public:
bool unpack(const Block& block, UnpackerCollections* coll) override;

private:
static constexpr unsigned int caloCrateCicadaBitsPattern = 0xF0000000; //first 4 bits of the words are CICADA
};
} // namespace stage2
} // namespace l1t

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace l1t {
for (int i = 0; i < 5; ++i) {
event_.put(std::move(ecalDigisBx_[i]), "EcalDigisBx" + std::to_string(i + 1));
}
event_.put(std::move(cicadaDigis_), "CICADAScore");
}
} // namespace stage2
} // namespace l1t
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "DataFormats/L1CaloTrigger/interface/L1CaloCollections.h"
#include "EventFilter/L1TRawToDigi/interface/UnpackerCollections.h"
#include "L1TObjectCollections.h"
#include "DataFormats/L1CaloTrigger/interface/CICADA.h"

namespace l1t {
namespace stage2 {
Expand All @@ -15,7 +16,8 @@ namespace l1t {
: L1TObjectCollections(e),
ecalDigis_(new EcalTrigPrimDigiCollection()),
hcalDigis_(new HcalTrigPrimDigiCollection()),
caloRegions_(new L1CaloRegionCollection()) {
caloRegions_(new L1CaloRegionCollection()),
cicadaDigis_(std::make_unique<CICADABxCollection>()) {
// Pre-allocate:
// 72 iPhi values
// 28 iEta values in Ecal, 28 + 12 iEta values in Hcal + HF
Expand All @@ -37,13 +39,15 @@ namespace l1t {
inline EcalTrigPrimDigiCollection* getEcalDigisBx(const unsigned int copy) override {
return ecalDigisBx_[copy].get();
};
inline CICADABxCollection* getCICADABxCollection() { return cicadaDigis_.get(); };

private:
std::unique_ptr<EcalTrigPrimDigiCollection> ecalDigis_;
std::unique_ptr<HcalTrigPrimDigiCollection> hcalDigis_;
std::unique_ptr<L1CaloRegionCollection> caloRegions_;

std::array<std::unique_ptr<EcalTrigPrimDigiCollection>, 5> ecalDigisBx_;
std::unique_ptr<CICADABxCollection> cicadaDigis_;
};
} // namespace stage2
} // namespace l1t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "CaloLayer1Setup.h"

#include "DataFormats/L1CaloTrigger/interface/CICADA.h"

namespace l1t {
namespace stage2 {
std::unique_ptr<PackerTokens> CaloLayer1Setup::registerConsumes(const edm::ParameterSet& cfg,
Expand Down Expand Up @@ -58,6 +60,7 @@ namespace l1t {
for (int i = 0; i < 5; ++i) {
prod.produces<EcalTrigPrimDigiCollection>("EcalDigisBx" + std::to_string(i + 1));
}
prod.produces<CICADABxCollection>("CICADAScore");
}

std::unique_ptr<UnpackerCollections> CaloLayer1Setup::getCollections(edm::Event& e) {
Expand All @@ -72,6 +75,9 @@ namespace l1t {
if (board < 18) {
res[0] = UnpackerFactory::get()->make("stage2::CaloLayer1Unpacker");
}
if (fed == 1356 && amc == 7) { //calo summary board
res[0] = UnpackerFactory::get()->make("stage2::CICADAUnpacker");
}
}

return res;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "FWCore/Framework/interface/Event.h"

#include "CaloSummaryCollections.h"

namespace l1t {
namespace stage2 {
CaloSummaryCollections::~CaloSummaryCollections() { event_.put(std::move(cicadaDigis_)); }
} // namespace stage2
} // namespace l1t
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef EventFilter_L1TRawToDigi_CaloSummaryCollections_h
#define EventFilter_L1TRawToDigi_CaloSummaryCollections_h

#include "DataFormats/L1CaloTrigger/interface/CICADA.h"

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

namespace l1t {
namespace stage2 {
class CaloSummaryCollections : public UnpackerCollections {
public:
CaloSummaryCollections(edm::Event& e)
: UnpackerCollections(e), cicadaDigis_(std::make_unique<CICADABxCollection>()){};
~CaloSummaryCollections() override;
inline CICADABxCollection* getCICADABxCollection() { return cicadaDigis_.get(); };

private:
std::unique_ptr<CICADABxCollection> cicadaDigis_;
};
} // namespace stage2
} // namespace l1t

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "EventFilter/L1TRawToDigi/plugins/UnpackerFactory.h"

#include "L1Trigger/L1TCalorimeter/interface/CaloTools.h"

#include "L1TObjectCollections.h"

#include "DataFormats/L1CaloTrigger/interface/CICADA.h"

#include "CaloSummaryUnpacker.h"
#include "GTSetup.h"

#include <cmath>

float l1t::stage2::CaloSummaryUnpacker::processBitsToScore(const unsigned int bitsArray[]) {
float constructedScore = 0.0;
//All bits have been shifted to just left of the decimal point
//We need to convert them to float, shift them back to their proper position
//And then add them into the total
//The proper power is 4(-(bitIndex+1) + numCICADAWords/2)
// i.e. shift bitIndex to max out at half the number of CICADA words (indexed at 0) then count down
//And we shift by 4 bits a time, hence the factor of 4
for (unsigned short bitIndex = 0; bitIndex < numCICADAWords; ++bitIndex) {
constructedScore += ((float)bitsArray[bitIndex]) * pow(2.0, 4 * ((numCICADAWords / 2) - (bitIndex + 1)));
}
return constructedScore;
}

bool l1t::stage2::CaloSummaryUnpacker::unpack(const Block& block, UnpackerCollections* coll) {
LogDebug("L1T") << "Block ID = " << block.header().getID() << " size = " << block.header().getSize();

//Just a few things to help us handle the number of BXs
//Strictly, we should generally get five BXs, starting at -2, and going to 2
//With the central BX at 0. The frames count up from -2
int nBX = int(ceil(block.header().getSize() / nFramesPerEvent));
int firstBX = (nBX / 2) - nBX + 1;
int lastBX = nBX / 2;
int processedBXs = 0; //This will just help us keep track of what words we are grabbing

auto res_ = static_cast<L1TObjectCollections*>(coll)->getCICADAScore();
res_->setBXRange(firstBX, lastBX);

for (int bx = firstBX; bx <= lastBX; ++bx) {
//convert to float and then multiply by a factor based on the index?
unsigned int cicadaBits[numCICADAWords] = {0, 0, 0, 0};

for (unsigned int wordNum = 0; wordNum < numCICADAWords; ++wordNum) {
unsigned short wordLocation =
processedBXs * nFramesPerEvent +
wordNum; //Calculate the location of the needed CICADA word based on how many BXs we have already handled, and how many words of CICADA we have already grabbed.
//Frame 0 of a bx are the most significant integer bits
//Frame 1 of a bx are the least significant integer bits
//Frame 2 of a bx are the most significant decimal bits
//Frame 3 of a bx are the lest significant decimal bits
//Frames 4&5 are unused (by CICADA), they are reserved.
uint32_t raw_data = block.payload().at(wordLocation);
cicadaBits[wordNum] =
(cicadaBitsPattern & raw_data) >>
28; //The 28 shifts the extracted bits over to the start of the 32 bit result data for easier working with later
}
res_->push_back(
bx,
processBitsToScore(
cicadaBits)); //Now we insert CICADA into the proper BX, after a quick utility constructs a number from the 4 sets of bits.
++processedBXs; //index BXs
}

return true;
}

DEFINE_L1T_UNPACKER(l1t::stage2::CaloSummaryUnpacker);
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef L1T_PACKER_STAGE2_CaloSummaryUnpacker_H
#define L1T_PACKER_STAGE2_CaloSummaryUnpacker_H

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

namespace l1t {
namespace stage2 {
class CaloSummaryUnpacker : public Unpacker {
public:
CaloSummaryUnpacker() = default;
~CaloSummaryUnpacker() override = default;

bool unpack(const Block& block, UnpackerCollections* coll) override;
float processBitsToScore(const unsigned int[]);

static constexpr unsigned short numCICADAWords = 4; // We have 4 words/frames that contain CICADA bits
static constexpr unsigned int nFramesPerEvent =
6; //Calo Summary outputs 6 32 bit words (or frames in uGT parlance) per event.
static constexpr unsigned int cicadaBitsPattern =
0xF0000000; //first 4 bits of the first 4 words/frames are CICADA
};
} // namespace stage2
} // namespace l1t
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace l1t {
event_.put(std::move(zdcsums_[0]), "EtSumZDC");
event_.put(std::move(jets_[0]), "Jet");
event_.put(std::move(taus_[0]), "Tau");
event_.put(std::move(cicadaScore_), "CICADAScore");
for (int i = 1; i < 6; ++i) {
event_.put(std::move(muons_[i]), "Muon" + std::to_string(i + 1));
event_.put(std::move(muonShowers_[i]), "MuonShower" + std::to_string(i + 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "DataFormats/L1Trigger/interface/Jet.h"
#include "DataFormats/L1Trigger/interface/Tau.h"
#include "DataFormats/L1Trigger/interface/Muon.h"
#include "DataFormats/L1CaloTrigger/interface/CICADA.h"

#include "DataFormats/L1TGlobal/interface/GlobalAlgBlk.h"
#include "DataFormats/L1TGlobal/interface/GlobalExtBlk.h"
Expand All @@ -18,7 +19,10 @@ namespace l1t {
class GTCollections : public L1TObjectCollections {
public:
GTCollections(edm::Event& e)
: L1TObjectCollections(e), algBlk_(new GlobalAlgBlkBxCollection()), extBlk_(new GlobalExtBlkBxCollection()) {
: L1TObjectCollections(e),
cicadaScore_(std::make_unique<CICADABxCollection>()),
algBlk_(new GlobalAlgBlkBxCollection()),
extBlk_(new GlobalExtBlkBxCollection()) {
std::generate(muons_.begin(), muons_.end(), [] { return std::make_unique<MuonBxCollection>(); });
std::generate(
muonShowers_.begin(), muonShowers_.end(), [] { return std::make_unique<MuonShowerBxCollection>(); });
Expand All @@ -40,6 +44,7 @@ namespace l1t {
inline EtSumBxCollection* getZDCSums(const unsigned int copy) override { return zdcsums_[copy].get(); };
inline JetBxCollection* getJets(const unsigned int copy) override { return jets_[copy].get(); };
inline TauBxCollection* getTaus(const unsigned int copy) override { return taus_[copy].get(); };
inline CICADABxCollection* getCICADAScore() override { return cicadaScore_.get(); };

inline GlobalAlgBlkBxCollection* getAlgs() { return algBlk_.get(); };
inline GlobalExtBlkBxCollection* getExts() { return extBlk_.get(); };
Expand All @@ -52,6 +57,7 @@ namespace l1t {
std::array<std::unique_ptr<EtSumBxCollection>, 6> zdcsums_;
std::array<std::unique_ptr<JetBxCollection>, 6> jets_;
std::array<std::unique_ptr<TauBxCollection>, 6> taus_;
std::unique_ptr<CICADABxCollection> cicadaScore_;

std::unique_ptr<GlobalAlgBlkBxCollection> algBlk_;
std::unique_ptr<GlobalExtBlkBxCollection> extBlk_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "EventFilter/L1TRawToDigi/plugins/implementations_stage2/ZDCUnpacker.h"
#include "EventFilter/L1TRawToDigi/plugins/implementations_stage2/JetUnpacker.h"
#include "EventFilter/L1TRawToDigi/plugins/implementations_stage2/TauUnpacker.h"
#include "EventFilter/L1TRawToDigi/plugins/implementations_stage2/CaloSummaryUnpacker.h"

#include "GTSetup.h"

Expand Down Expand Up @@ -62,6 +63,7 @@ namespace l1t {
prod.produces<EtSumBxCollection>("EtSumZDC");
prod.produces<JetBxCollection>("Jet");
prod.produces<TauBxCollection>("Tau");
prod.produces<CICADABxCollection>("CICADAScore");
prod.produces<GlobalAlgBlkBxCollection>();
prod.produces<GlobalExtBlkBxCollection>();
for (int i = 2; i < 7; ++i) { // Collections from boards 2-6
Expand Down Expand Up @@ -89,6 +91,8 @@ namespace l1t {
auto zdc_unp = static_pointer_cast<l1t::stage2::ZDCUnpacker>(UnpackerFactory::get()->make("stage2::ZDCUnpacker"));
auto jet_unp = static_pointer_cast<l1t::stage2::JetUnpacker>(UnpackerFactory::get()->make("stage2::JetUnpacker"));
auto tau_unp = static_pointer_cast<l1t::stage2::TauUnpacker>(UnpackerFactory::get()->make("stage2::TauUnpacker"));
auto caloSummary_unp = static_pointer_cast<l1t::stage2::CaloSummaryUnpacker>(
UnpackerFactory::get()->make("stage2::CaloSummaryUnpacker"));

if (fw >= 0x10f2) {
etsum_unp = static_pointer_cast<l1t::stage2::EtSumUnpacker>(
Expand Down Expand Up @@ -124,6 +128,7 @@ namespace l1t {
res[16] = tau_unp;
res[18] = tau_unp;
res[20] = etsum_unp;
res[22] = caloSummary_unp;

if (amc == 1) { // only unpack first uGT board for the external signal inputs (single copy)
res[24] = ext_unp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "DataFormats/L1Trigger/interface/Tau.h"
#include "DataFormats/L1Trigger/interface/Muon.h"
#include "DataFormats/L1Trigger/interface/MuonShower.h"
#include "DataFormats/L1CaloTrigger/interface/CICADA.h"

#include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"

Expand All @@ -26,6 +27,7 @@ namespace l1t {
virtual EtSumBxCollection* getZDCSums(const unsigned int copy) { return nullptr; }
virtual JetBxCollection* getJets(const unsigned int copy) { return nullptr; }
virtual TauBxCollection* getTaus(const unsigned int copy) { return nullptr; }
virtual CICADABxCollection* getCICADAScore() { return nullptr; }

virtual EcalTrigPrimDigiCollection* getEcalDigisBx(const unsigned int copy) { return nullptr; };
};
Expand Down
Loading