Skip to content

Commit

Permalink
can now use configurable emulator to decode HGC objects (slim or not)
Browse files Browse the repository at this point in the history
  • Loading branch information
cerminar committed Apr 26, 2023
1 parent df1a217 commit 382fffe
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@

#include "DataFormats/L1TParticleFlow/interface/layer1_emulator.h"

namespace edm {
class ParameterSet;
}

namespace l1ct {
class HgcalClusterDecoderEmulator {
bool slim_;

public:
HgcalClusterDecoderEmulator(){};
HgcalClusterDecoderEmulator(bool slim = false) : slim_{slim} {};
HgcalClusterDecoderEmulator(const edm::ParameterSet &pset);

~HgcalClusterDecoderEmulator();
l1ct::HadCaloObjEmu decode(const ap_uint<256> &in) const;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "L1Trigger/Phase2L1ParticleFlow/interface/l1-converters/tkinput_ref.h"
#include "L1Trigger/Phase2L1ParticleFlow/interface/l1-converters/muonGmtToL1ct_ref.h"
#include "L1Trigger/Phase2L1ParticleFlow/interface/l1-converters/hgcalinput_ref.h"
#include "L1Trigger/Phase2L1ParticleFlow/interface/regionizer/regionizer_base_ref.h"
#include "L1Trigger/Phase2L1ParticleFlow/interface/regionizer/multififo_regionizer_ref.h"
#include "L1Trigger/Phase2L1ParticleFlow/interface/regionizer/tdr_regionizer_ref.h"
Expand Down Expand Up @@ -66,6 +67,7 @@ class L1TCorrelatorLayer1Producer : public edm::stream::EDProducer<> {
l1ct::Event event_;
std::unique_ptr<l1ct::TrackInputEmulator> trackInput_;
std::unique_ptr<l1ct::GMTMuonDecoderEmulator> muonInput_;
std::unique_ptr<l1ct::HgcalClusterDecoderEmulator> hgcalInput_;
std::unique_ptr<l1ct::RegionizerEmulator> regionizer_;
std::unique_ptr<l1ct::PFAlgoEmulatorBase> l1pfalgo_;
std::unique_ptr<l1ct::LinPuppiEmulator> l1pualgo_;
Expand Down Expand Up @@ -108,6 +110,38 @@ class L1TCorrelatorLayer1Producer : public edm::stream::EDProducer<> {

void addRawHgcalCluster(l1ct::DetectorSector<ap_uint<256>> &sec, const l1t::PFCluster &c);

template <class T>
void rawHgcalClusterEncode(ap_uint<256> &cwrd, const l1ct::DetectorSector<T> &sec, const l1t::PFCluster &c) const {
cwrd = 0;
ap_ufixed<14, 12, AP_RND_CONV, AP_SAT> w_pt = c.pt();
ap_uint<14> w_empt = round(c.emEt() / 0.25);
constexpr float ETAPHI_LSB = M_PI / 720;
ap_int<9> w_eta = round(sec.region.localEta(c.eta()) / ETAPHI_LSB);
ap_int<9> w_phi = round(sec.region.localPhi(c.phi()) / ETAPHI_LSB);
ap_uint<10> w_qual = c.hwQual();
// NOTE: this is an arbitrary choice to keep the rounding consistent with the "addDecodedHadCalo" one
ap_uint<13> w_srrtot = round(c.sigmaRR() * l1ct::Scales::SRRTOT_SCALE / l1ct::Scales::SRRTOT_LSB);
ap_uint<12> w_meanz = round(c.absZBarycenter());
// NOTE: the calibration can actually make hoe become negative....we add a small protection for now
// We use ap_ufixed to handle saturation and rounding
ap_ufixed<10, 5, AP_RND_CONV, AP_SAT> w_hoe = c.hOverE();

cwrd(13, 0) = w_pt.range();
cwrd(27, 14) = w_empt;
cwrd(72, 64) = w_eta;
cwrd(81, 73) = w_phi;
cwrd(115, 106) = w_qual;

// FIXME: we add the variables use by composite-ID. The definitin will have to be reviewd once the
// hgc format is better defined. For now we use
// hwMeanZ = word 1 bits 30-19
// hwSrrTot = word 3 bits 21 - 9
// hoe = word 1 bits 63-52 (currently spare in the interface)
cwrd(213, 201) = w_srrtot;
cwrd(94, 83) = w_meanz;
cwrd(127, 116) = w_hoe.range();
}

// fetching outputs
std::unique_ptr<l1t::PFCandidateCollection> fetchHadCalo() const;
std::unique_ptr<l1t::PFCandidateCollection> fetchEmCalo() const;
Expand Down Expand Up @@ -200,6 +234,13 @@ L1TCorrelatorLayer1Producer::L1TCorrelatorLayer1Producer(const edm::ParameterSet
} else if (muInAlgo != "Ideal")
throw cms::Exception("Configuration", "Unsupported muonInputConversionAlgo");

const std::string &hgcalInAlgo = iConfig.getParameter<std::string>("hgcalInputConversionAlgo");
if (hgcalInAlgo == "Emulator") {
hgcalInput_ = std::make_unique<l1ct::HgcalClusterDecoderEmulator>(
iConfig.getParameter<edm::ParameterSet>("hgcalInputConversionParameters"));
} else if (hgcalInAlgo != "Ideal")
throw cms::Exception("Configuration", "Unsupported hgcalInputConversionAlgo");

const std::string &regalgo = iConfig.getParameter<std::string>("regionizerAlgo");
if (regalgo == "Ideal") {
regionizer_ =
Expand Down Expand Up @@ -676,49 +717,28 @@ void L1TCorrelatorLayer1Producer::addDecodedMuon(l1ct::DetectorSector<l1ct::MuOb
void L1TCorrelatorLayer1Producer::addDecodedHadCalo(l1ct::DetectorSector<l1ct::HadCaloObjEmu> &sec,
const l1t::PFCluster &c) {
l1ct::HadCaloObjEmu calo;
calo.hwPt = l1ct::Scales::makePtFromFloat(c.pt());
calo.hwEta = l1ct::Scales::makeGlbEta(c.eta()) -
sec.region.hwEtaCenter; // important to enforce that the region boundary is on a discrete value
calo.hwPhi = l1ct::Scales::makePhi(sec.region.localPhi(c.phi()));
calo.hwEmPt = l1ct::Scales::makePtFromFloat(c.emEt());
calo.hwEmID = c.hwEmID();
calo.hwSrrTot = l1ct::Scales::makeSrrTot(c.sigmaRR());
calo.hwMeanZ = c.absZBarycenter() < 320. ? l1ct::meanz_t(0) : l1ct::Scales::makeMeanZ(c.absZBarycenter());
calo.hwHoe = l1ct::Scales::makeHoe(c.hOverE());
ap_uint<256> word = 0;
rawHgcalClusterEncode(word, sec, c);
if (hgcalInput_) {
calo = hgcalInput_->decode(word);
} else {
calo.hwPt = l1ct::Scales::makePtFromFloat(c.pt());
calo.hwEta = l1ct::Scales::makeGlbEta(c.eta()) -
sec.region.hwEtaCenter; // important to enforce that the region boundary is on a discrete value
calo.hwPhi = l1ct::Scales::makePhi(sec.region.localPhi(c.phi()));
calo.hwEmPt = l1ct::Scales::makePtFromFloat(c.emEt());
calo.hwEmID = c.hwEmID();
calo.hwSrrTot = l1ct::Scales::makeSrrTot(c.sigmaRR());
calo.hwMeanZ = c.absZBarycenter() < 320. ? l1ct::meanz_t(0) : l1ct::Scales::makeMeanZ(c.absZBarycenter());
calo.hwHoe = l1ct::Scales::makeHoe(c.hOverE());
}
calo.src = &c;
sec.obj.push_back(calo);
}

void L1TCorrelatorLayer1Producer::addRawHgcalCluster(l1ct::DetectorSector<ap_uint<256>> &sec, const l1t::PFCluster &c) {
ap_uint<256> cwrd = 0;
ap_ufixed<14, 12, AP_RND_CONV, AP_SAT> w_pt = c.pt();
ap_uint<14> w_empt = round(c.emEt() / 0.25);
constexpr float ETAPHI_LSB = M_PI / 720;
ap_int<9> w_eta = round(sec.region.localEta(c.eta()) / ETAPHI_LSB);
ap_int<9> w_phi = round(sec.region.localPhi(c.phi()) / ETAPHI_LSB);
ap_uint<10> w_qual = c.hwQual();
// NOTE: this is an arbitrary choice to keep the rounding consistent with the "addDecodedHadCalo" one
ap_uint<13> w_srrtot = round(c.sigmaRR() * l1ct::Scales::SRRTOT_SCALE / l1ct::Scales::SRRTOT_LSB);
ap_uint<12> w_meanz = round(c.absZBarycenter());
// NOTE: the calibration can actually make hoe become negative....we add a small protection for now
// We use ap_ufixed to handle saturation and rounding
ap_ufixed<10, 5, AP_RND_CONV, AP_SAT> w_hoe = c.hOverE();

cwrd(13, 0) = w_pt.range();
cwrd(27, 14) = w_empt;
cwrd(72, 64) = w_eta;
cwrd(81, 73) = w_phi;
cwrd(115, 106) = w_qual;

// FIXME: we add the variables use by composite-ID. The definitin will have to be reviewd once the
// hgc format is better defined. For now we use
// hwMeanZ = word 1 bits 30-19
// hwSrrTot = word 3 bits 21 - 9
// hoe = word 1 bits 63-52 (currently spare in the interface)
cwrd(213, 201) = w_srrtot;
cwrd(94, 83) = w_meanz;
cwrd(127, 116) = w_hoe.range();

rawHgcalClusterEncode(cwrd, sec, c);
sec.obj.push_back(cwrd);
}

Expand Down
10 changes: 10 additions & 0 deletions L1Trigger/Phase2L1ParticleFlow/python/l1ctLayer1_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
),
muonInputConversionAlgo = cms.string("Emulator"),
muonInputConversionParameters = muonInputConversionParameters.clone(),
hgcalInputConversionAlgo = cms.string("Ideal"),
regionizerAlgo = cms.string("Ideal"),
pfAlgo = cms.string("PFAlgo3"),
puAlgo = cms.string("LinearizedPuppi"),
Expand Down Expand Up @@ -195,6 +196,10 @@
),
muonInputConversionAlgo = cms.string("Emulator"),
muonInputConversionParameters = muonInputConversionParameters.clone(),
hgcalInputConversionAlgo = cms.string("Emulator"),
hgcalInputConversionParameters = cms.PSet(
slim = cms.bool(False)
),
regionizerAlgo = cms.string("Multififo"),
regionizerAlgoParameters = cms.PSet(
useAlsoVtxCoords = cms.bool(True),
Expand Down Expand Up @@ -315,6 +320,10 @@
trkPtCut = cms.double(2.0),
muonInputConversionAlgo = cms.string("Emulator"),
muonInputConversionParameters = muonInputConversionParameters.clone(),
hgcalInputConversionAlgo = cms.string("Emulator"),
hgcalInputConversionParameters = cms.PSet(
slim = cms.bool(True)
),
regionizerAlgo = cms.string("Ideal"),
pfAlgo = cms.string("PFAlgoDummy"),
puAlgo = cms.string("LinearizedPuppi"),
Expand Down Expand Up @@ -400,6 +409,7 @@
trkPtCut = cms.double(2.0),
muonInputConversionAlgo = cms.string("Ideal"),
muonInputConversionParameters = muonInputConversionParameters.clone(),
hgcalInputConversionAlgo = cms.string("Ideal"),
regionizerAlgo = cms.string("Ideal"),
pfAlgo = cms.string("PFAlgoDummy"),
puAlgo = cms.string("LinearizedPuppi"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#include "L1Trigger/Phase2L1ParticleFlow/interface/l1-converters/hgcalinput_ref.h"

#ifdef CMSSW_GIT_HASH
#include "FWCore/ParameterSet/interface/ParameterSet.h"
l1ct::HgcalClusterDecoderEmulator::HgcalClusterDecoderEmulator(const edm::ParameterSet &pset)
: slim_(pset.getParameter<bool>("slim")) {}

#endif

l1ct::HgcalClusterDecoderEmulator::~HgcalClusterDecoderEmulator() {}

l1ct::HadCaloObjEmu l1ct::HgcalClusterDecoderEmulator::decode(const ap_uint<256> &in) const {
Expand All @@ -20,10 +27,11 @@ l1ct::HadCaloObjEmu l1ct::HgcalClusterDecoderEmulator::decode(const ap_uint<256>
out.hwPhi = w_phi; // relative to the region center, at calo
out.hwEmPt = w_empt * l1ct::pt_t(l1ct::Scales::INTPT_LSB);
out.hwEmID = w_qual;

out.hwSrrTot = w_srrtot * l1ct::srrtot_t(l1ct::Scales::SRRTOT_LSB);
out.hwMeanZ = (w_meanz == 0) ? l1ct::meanz_t(0) : l1ct::meanz_t(w_meanz - l1ct::meanz_t(l1ct::Scales::MEANZ_OFFSET));
out.hwHoe = w_hoe * l1ct::hoe_t(l1ct::Scales::HOE_LSB);

if (!slim_) {
out.hwSrrTot = w_srrtot * l1ct::srrtot_t(l1ct::Scales::SRRTOT_LSB);
out.hwMeanZ =
(w_meanz == 0) ? l1ct::meanz_t(0) : l1ct::meanz_t(w_meanz - l1ct::meanz_t(l1ct::Scales::MEANZ_OFFSET));
out.hwHoe = w_hoe * l1ct::hoe_t(l1ct::Scales::HOE_LSB);
}
return out;
}

0 comments on commit 382fffe

Please sign in to comment.