Skip to content

Commit

Permalink
Simplify CICADA-uGT unpacker logic
Browse files Browse the repository at this point in the history
  • Loading branch information
aloeliger committed Jun 26, 2024
1 parent 7fdb2c0 commit 368f120
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,6 @@

#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();

Expand All @@ -41,27 +27,14 @@ bool l1t::stage2::CaloSummaryUnpacker::unpack(const Block& block, UnpackerCollec
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.
unsigned short baseLocation = processedBXs * nFramesPerEvent;
const uint32_t* base = block.payload().data() + baseLocation;
//The take the first 4 bits of the first 4 words, and arrange them in order
uint32_t word = (cicadaBitsPattern & base[0]) >> 16 | (cicadaBitsPattern & base[1]) >> 20 |
(cicadaBitsPattern & base[2]) >> 24 | (cicadaBitsPattern & base[3]) >> 28;
//The score needs to be shifted 8 bits over the decimal point
float score = static_cast<float>(word) / 256.f;
res_->push_back(bx, score);
++processedBXs; //index BXs
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ namespace l1t {
~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 =
Expand Down

0 comments on commit 368f120

Please sign in to comment.