Skip to content

Commit

Permalink
Add stage-1 emulator w/o truncation (cms-sw#110)
Browse files Browse the repository at this point in the history
* Add stage1 emulator w/o truncation

* First round of cleanup

* Further cleanup

* code format+code checks

* Adding rotatedphi function to HGCalTriggerTools

* Remove duplicate file

* Better col/chn/frame packing and add module dependence to dummy mapping

* Code checks and code format

* Renaming rotatedphi function

* Fix number of bits for frame and channel

* Set latestfw back to truncationfw for now
  • Loading branch information
adewit authored Jul 4, 2024
1 parent 68eca2b commit 7c1de40
Show file tree
Hide file tree
Showing 19 changed files with 489 additions and 18 deletions.
12 changes: 12 additions & 0 deletions DataFormats/L1THGCal/interface/HGCalCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,20 @@ namespace l1t {
void setModule(uint32_t module) { module_ = module; }
uint32_t module() const { return module_; }

void setColumn(int column) { column_ = column; }
int column() const { return column_; }

void setFrame(unsigned frame) { frame_ = frame; }
unsigned frame() const { return frame_; }

void setChannel(unsigned channel) { channel_ = channel; }
unsigned channel() const { return channel_; }

private:
uint32_t module_;
unsigned channel_;
unsigned frame_;
int column_;
};

typedef BXVector<HGCalCluster> HGCalClusterBxCollection;
Expand Down
4 changes: 4 additions & 0 deletions DataFormats/L1THGCal/interface/HGCalTriggerCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ namespace l1t {
void setCompressedCharge(uint32_t value) { compressedCharge_ = value; }
uint32_t compressedCharge() const { return compressedCharge_; }

void setModuleId(uint32_t value) { moduleId_ = value; }
uint32_t moduleId() { return moduleId_; }

void setPt(double pT);

private:
Expand All @@ -46,6 +49,7 @@ namespace l1t {

uint32_t uncompressedCharge_{0};
uint32_t compressedCharge_{0};
uint32_t moduleId_{0};
};

} // namespace l1t
Expand Down
6 changes: 4 additions & 2 deletions DataFormats/L1THGCal/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@

<class name="l1t::HGCalClusterT<l1t::HGCalTriggerCell>" />
<class name="l1t::HGCalClusterT<l1t::HGCalTriggerSums>" />
<class name="l1t::HGCalCluster" ClassVersion="19">
<class name="l1t::HGCalCluster" ClassVersion="20">
<version ClassVersion="20" checksum="3312252455"/>
<version ClassVersion="19" checksum="214410871"/>
<version ClassVersion="18" checksum="3346067797"/>
<version ClassVersion="17" checksum="2841504063"/>
Expand Down Expand Up @@ -67,7 +68,8 @@
<class name="l1t::HGCalMulticlusterBxCollection"/>
<class name="edm::Wrapper<l1t::HGCalMulticlusterBxCollection>"/>

<class name="l1t::HGCalTriggerCell" ClassVersion="12">
<class name="l1t::HGCalTriggerCell" ClassVersion="13">
<version ClassVersion="13" checksum="990350208"/>
<version ClassVersion="12" checksum="3538848072"/>
<version ClassVersion="11" checksum="646735227"/>
<version ClassVersion="10" checksum="1275348814"/>
Expand Down
7 changes: 7 additions & 0 deletions L1Trigger/L1THGCal/interface/HGCalAlgoWrapperBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ typedef HGCalAlgoWrapperBaseT<std::vector<edm::Ptr<l1t::HGCalTriggerCell>>,
std::tuple<const HGCalTriggerGeometryBase* const, const unsigned&, const uint32_t&>>
HGCalLayer1TruncationWrapperBase;

typedef HGCalAlgoWrapperBaseT<std::vector<edm::Ptr<l1t::HGCalTriggerCell>>,
l1t::HGCalClusterBxCollection,
std::tuple<const HGCalTriggerGeometryBase* const, const unsigned&, const uint32_t&>>
HGCalLayer1PhiOrderWrapperBase;

#include "FWCore/PluginManager/interface/PluginFactory.h"
typedef edmplugin::PluginFactory<HGCalHistoClusteringWrapperBase*(const edm::ParameterSet&)>
HGCalHistoClusteringWrapperBaseFactory;
Expand All @@ -39,5 +44,7 @@ typedef edmplugin::PluginFactory<HGCalStage2FilteringWrapperBase*(const edm::Par
HGCalStage2FilteringWrapperBaseFactory;
typedef edmplugin::PluginFactory<HGCalLayer1TruncationWrapperBase*(const edm::ParameterSet&)>
HGCalLayer1TruncationWrapperBaseFactory;
typedef edmplugin::PluginFactory<HGCalLayer1PhiOrderWrapperBase*(const edm::ParameterSet&)>
HGCalLayer1PhiOrderWrapperBaseFactory;

#endif
4 changes: 4 additions & 0 deletions L1Trigger/L1THGCal/interface/HGCalTriggerTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class HGCalTriggerTools {
float getTCPhi(const DetId& id) const;
float getTCPt(const DetId& id, const float& hitEnergy, const float& vertex_z = 0.) const;

uint32_t getModuleId(const DetId& id) const;

inline const HGCalTriggerGeometryBase* getTriggerGeometry() const { return geom_; };

float getLayerZ(const unsigned& layerWithOffset) const;
Expand All @@ -93,6 +95,8 @@ class HGCalTriggerTools {
};
SubDetectorType getSubDetectorType(const DetId& id) const;

double rotatePhiToSectorZero(double phi, unsigned sector) const;

private:
const HGCalTriggerGeometryBase* geom_;
unsigned eeLayers_;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef __L1Trigger_L1THGCal_HGCalBackendLayer1ProcessorPhiOrderFw_h__
#define __L1Trigger_L1THGCal_HGCalBackendLayer1ProcessorPhiOrderFw_h__

#include "L1Trigger/L1THGCal/interface/HGCalProcessorBase.h"
#include "L1Trigger/L1THGCal/interface/HGCalAlgoWrapperBase.h"

#include "DataFormats/L1THGCal/interface/HGCalTriggerCell.h"
#include "DataFormats/L1THGCal/interface/HGCalCluster.h"

#include "L1Trigger/L1THGCal/interface/backend_emulator/HGCalLayer1PhiOrderFwImpl.h"
#include "L1Trigger/L1THGCal/interface/backend/HGCalClusteringDummyImpl.h"

class HGCalBackendLayer1ProcessorPhiOrderFw : public HGCalBackendLayer1ProcessorBase {
public:
HGCalBackendLayer1ProcessorPhiOrderFw(const edm::ParameterSet& conf);

void run(const std::pair<uint32_t, std::vector<edm::Ptr<l1t::HGCalTriggerCell>>>& fpga_id_tcs,
l1t::HGCalClusterBxCollection& clusters) override;

private:
std::unique_ptr<HGCalClusteringDummyImpl> clusteringDummy_;
std::unique_ptr<HGCalLayer1PhiOrderWrapperBase> PhiOrderWrapper_;
const edm::ParameterSet conf_;
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#ifndef __L1Trigger_L1THGCal_HGCalLayer1PhiOrderFwConfig_h__
#define __L1Trigger_L1THGCal_HGCalLayer1PhiOrderFwConfig_h__

#include <vector>
#include <cstdint> // uint32_t
#include <unordered_map>

namespace l1thgcfirmware {

class HGCalLayer1PhiOrderFwConfig {
public:
HGCalLayer1PhiOrderFwConfig() {}

void setSector120(const unsigned sector) { sector120_ = sector; }
void setFPGAID(const uint32_t fpga_id) { fpga_id_ = fpga_id; }

void
configureMappingInfo() { //creates a map between column number and a vector of pairs containing the available (channel,frame) combinations. Each frame accepts 4 TCs, so each (channel,frame) combination appears 4 times in the vector. We could optionally add a unique "slot" index to this vector, but it is not strictly necessary. The function also creates a vector of pairs between column number and number of TCs the column can accept.
for (unsigned i = 0; i < 20; ++i) {
//std::pair<unsigned, int> mod_col_pair = std::make_pair(dummyModId_,i);//
for (unsigned j = 0; j < 2; ++j) {
for (unsigned k = 0; k < 4; ++k) { //number of slots per frame
chn_frame_slots_per_mod_and_col_[dummyModId_][i].push_back(std::make_pair(i + 3, j));
}
for (unsigned k = 0; k < 4; ++k) { //number of slots per frame
chn_frame_slots_per_mod_and_col_[dummyModId_][i].push_back(std::make_pair(i + 4, j));
}
}
max_tcs_per_module_and_column_[dummyModId_].push_back(
std::make_pair(i, chn_frame_slots_per_mod_and_col_[dummyModId_][i].size()));
}
}

unsigned phiSector() const { return sector120_; }
uint32_t fpgaID() const { return fpga_id_; }
unsigned getColBudgetAtIndex(unsigned moduleId, unsigned theColumnIndex) const {
return max_tcs_per_module_and_column_.at(dummyModId_).at(theColumnIndex).second;
} //Get TC budget for column at index theColumnIndex in the vector
int getColFromBudgetMapAtIndex(unsigned moduleId, unsigned theColumnIndex) const {
return max_tcs_per_module_and_column_.at(dummyModId_).at(theColumnIndex).first;
} //Get column number at index theColumnIndex in the vector
unsigned getChannelAtIndex(unsigned moduleId, int theColumn, unsigned theChnFrameIndex) const {
return chn_frame_slots_per_mod_and_col_.at(dummyModId_).at(theColumn).at(theChnFrameIndex).first;
} //Extract channel number for colnr theColumn, at given channel+frame index in the vector
unsigned getFrameAtIndex(unsigned moduleId, int theColumn, unsigned theChnFrameIndex) const {
return chn_frame_slots_per_mod_and_col_.at(dummyModId_).at(theColumn).at(theChnFrameIndex).second;
} //Extract frame number for colnr theColumn, at given channel+frame index in the vector

private:
unsigned sector120_;
uint32_t fpga_id_;
std::unordered_map<unsigned, std::vector<std::pair<int, unsigned>>> max_tcs_per_module_and_column_;
std::unordered_map<unsigned, std::unordered_map<int, std::vector<std::pair<unsigned, unsigned>>>>
chn_frame_slots_per_mod_and_col_;
const uint32_t dummyModId_ = 1879048191; // Just to avoid filling maps for random module ID values. Temporary!!
};

} // namespace l1thgcfirmware

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#ifndef __L1Trigger_L1THGCal_HGCalLayer1PhiOrderFwImpl_h__
#define __L1Trigger_L1THGCal_HGCalLayer1PhiOrderFwImpl_h__

#include "L1Trigger/L1THGCal/interface/backend_emulator/HGCalTriggerCell_SA.h"
#include "L1Trigger/L1THGCal/interface/backend_emulator/HGCalLayer1PhiOrderFwConfig.h"
#include "L1Trigger/L1THGCal/interface/backend_emulator/BatcherSorter.h"

#include <vector>
#include <cstdint> // uint32_t, unsigned
#include <unordered_map> // std::unordered_map

namespace l1thgcfirmware {

class HGCalLayer1PhiOrderFwImpl {
public:
HGCalLayer1PhiOrderFwImpl();
~HGCalLayer1PhiOrderFwImpl() {}

void runAlgorithm() const;

unsigned run(const l1thgcfirmware::HGCalTriggerCellSACollection& tcs_in,
const l1thgcfirmware::HGCalLayer1PhiOrderFwConfig& theConf,
l1thgcfirmware::HGCalTriggerCellSACollection& tcs_out) const;

private:
const int columnMask_ = 0x1F; //5 bits
const int columnOffset_ = 11; //7 bits frame, 4 bits channel
const int channelMask_ = 0xF; //4 bits for channel
const int channelOffset_ = 7; //Frame has 7 bits (to fit 108 frames)
const int frameMask_ = 0x7F; //7 bits for frame
const int frameOffset_ = 0;

int packColChnFrame(int column, unsigned channel, unsigned frame) const;
void unpackColChnFrame(int packedbin, int& column, unsigned& channel, unsigned& frame) const;

std::vector<std::pair<l1thgcfirmware::HGCalTriggerCell, int>> assignTCToCol(
const l1thgcfirmware::HGCalLayer1PhiOrderFwConfig& theConf,
std::vector<l1thgcfirmware::HGCalTriggerCell> tcs) const;
std::vector<std::pair<l1thgcfirmware::HGCalTriggerCell, int>> assignTCToChnAndFrame(
const l1thgcfirmware::HGCalLayer1PhiOrderFwConfig& theConf,
std::vector<std::pair<l1thgcfirmware::HGCalTriggerCell, int>> ord_tcs) const;
};

} // namespace l1thgcfirmware

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ namespace l1thgcfirmware {
void setY(const unsigned int Y) { Y_ = Y; }
void setDeltaR2(const unsigned int deltaR2) { deltaR2_ = deltaR2; }
void setCmsswIndex(const std::pair<int, int> index) { index_cmssw_ = index; }
void setModuleId(const unsigned int moduleid) { moduleId_ = moduleid; }
void setColumn(const int column) { column_ = column; }
void setFrame(const unsigned frame) { frame_ = frame; }
void setChannel(const unsigned channel) { channel_ = channel; }

// Getters
unsigned int clock() const { return clock_; }
Expand All @@ -50,7 +54,11 @@ namespace l1thgcfirmware {
unsigned int Y() const { return Y_; }
bool frameValid() const { return frameValid_; }
bool dataValid() const { return dataValid_; }
unsigned int moduleId() const { return moduleId_; }
const std::pair<int, int>& cmsswIndex() const { return index_cmssw_; }
int column() const { return column_; }
unsigned frame() const { return frame_; }
unsigned channel() const { return channel_; }

// Operators
bool operator==(const HGCalTriggerCell& rhs) const;
Expand All @@ -69,7 +77,11 @@ namespace l1thgcfirmware {
unsigned int Y_;
bool frameValid_;
bool dataValid_;
unsigned int moduleId_;
std::pair<int, int> index_cmssw_;
int column_;
unsigned frame_;
unsigned channel_;
};

typedef std::vector<HGCalTriggerCell> HGCalTriggerCellSACollection;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "L1Trigger/L1THGCal/interface/backend/HGCalBackendLayer1ProcessorPhiOrderFw.h"
#include "DataFormats/ForwardDetId/interface/HGCalTriggerBackendDetId.h"

DEFINE_EDM_PLUGIN(HGCalBackendLayer1Factory,
HGCalBackendLayer1ProcessorPhiOrderFw,
"HGCalBackendLayer1ProcessorPhiOrderFw");

HGCalBackendLayer1ProcessorPhiOrderFw::HGCalBackendLayer1ProcessorPhiOrderFw(const edm::ParameterSet& conf)
: HGCalBackendLayer1ProcessorBase(conf), conf_(conf) {
const edm::ParameterSet& PhiOrderParamConfig = conf.getParameterSet("phiorder_parameters");
const std::string& PhiOrderWrapperName = PhiOrderParamConfig.getParameter<std::string>("AlgoName");

PhiOrderWrapper_ = std::unique_ptr<HGCalLayer1PhiOrderWrapperBase>{
HGCalLayer1PhiOrderWrapperBaseFactory::get()->create(PhiOrderWrapperName, PhiOrderParamConfig)};
}

void HGCalBackendLayer1ProcessorPhiOrderFw::run(
const std::pair<uint32_t, std::vector<edm::Ptr<l1t::HGCalTriggerCell>>>& fpga_id_tcs,
l1t::HGCalClusterBxCollection& clusters) {
const unsigned sector120 = HGCalTriggerBackendDetId(fpga_id_tcs.first).sector();
const uint32_t fpga_id = fpga_id_tcs.first;

// Configuration
const std::tuple<const HGCalTriggerGeometryBase* const, unsigned, uint32_t> configuration{
geometry(), sector120, fpga_id};
PhiOrderWrapper_->configure(configuration);

PhiOrderWrapper_->process(fpga_id_tcs.second, clusters);
}
Loading

0 comments on commit 7c1de40

Please sign in to comment.