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

Add Unpacker for L1T Calo Layer 1 to unpack CICADA #45037

Merged
merged 3 commits into from
Jun 25, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#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 {
std::vector<uint32_t> cicadaWords = {0, 0, 0, 0};
//the last 4 words are CICADA words
for (uint32_t i = 2; i < 6; ++i) {
cicadaWords.at(i - 2) = ((block.payload().at(i)) >> 28);
}

float cicadaScore = convertCICADABitsToFloat(cicadaWords);
res->push_back(0, cicadaScore);
return true;
}
}

//convert the 4 CICADA bits/words into a proper number
float CICADAUnpacker::convertCICADABitsToFloat(const std::vector<uint32_t>& cicadaBits) {
uint32_t tempResult = 0;
tempResult |= cicadaBits.at(0) << 12;
tempResult |= cicadaBits.at(1) << 8;
tempResult |= cicadaBits.at(2) << 4;
tempResult |= cicadaBits.at(3);
float result = 0.0;
result = (float)tempResult * pow(2.0, -8);
return result;
Comment on lines +29 to +50
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be replaced by a simpler implementation, see https://github.com/cms-sw/cmssw/pull/44222/files#r1653052470 .

In fact, it would be better to share the duplicate code between EventFilter/L1TRawToDigi/plugins/implementations_stage2/CICADAUnpacker.cc and EventFilter/L1TRawToDigi/plugins/implementations_stage2/CaloSummaryUnpacker.cc.

Copy link
Contributor Author

@aloeliger aloeliger Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am working on this this morning, however just for posterity's sake, I will note that the exact bits grabbed are ever so slightly different, being the first 4 bits of the last 4 words for FED 1356, instead of the first 4 bits of the first 4 words for FEDs 1404 & 1405.

In any case, you are entirely correct that this could be simplified down from the ad-hoc first drafts. I can do that for the uGT one while the HLT experts review. I am not sure what happens for this one now.

}
} // 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:
float convertCICADABitsToFloat(const std::vector<uint32_t>&);
};
} // 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