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

Access Conditions DB for HCAL Pulse Filtering Weights #32717

Merged
merged 16 commits into from
Mar 25, 2021
Merged
4 changes: 2 additions & 2 deletions CalibCalorimetry/CaloTPG/src/CaloTPGTranscoderULUT.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void CaloTPGTranscoderULUT::loadHCALCompress(HcalLutMetadata const& lutMetadata,
}
} else {
for (unsigned int i = threshold; i < lutsize; ++i)
outputLUT_[index][i] = version == 0 ? linearRctLUT[i] : linearNctLUT[i];
outputLUT_[index][i] = version == 1 ? linearNctLUT[i] : linearRctLUT[i];
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand these changes. Why would the output LUT need to change between version 1 and version 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted v2 TPs to be associated with Rct like v0 TPs are since the choice here does not depend whether v0 or v2 for HBHE TPs. Likewise, Nct is associated with v1, so I "flipped" the logic to explicitly associate v1 with Nct and anything else (v0 or v2) with Rct. However, maybe I am misunderstanding other implications of this.

}

double eta_low = 0., eta_high = 0.;
Expand Down Expand Up @@ -126,7 +126,7 @@ void CaloTPGTranscoderULUT::loadHCALCompress(HcalLutMetadata const& lutMetadata,
for (unsigned int i = 0; i < lutsize; ++i) {
if (outputLUT_[index][i] != tpg) {
tpg = outputLUT_[index][i];
hcaluncomp_[index][tpg] = lsb_factor_ * i / (version == 0 ? rct_factor_ : nct_factor_);
hcaluncomp_[index][tpg] = lsb_factor_ * i / (version == 1 ? nct_factor_ : rct_factor_);
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion CalibCalorimetry/HcalTPGAlgos/interface/HcaluLUTTPGCoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ class HcaluLUTTPGCoder : public HcalTPGCoder {
void set1TSContainHE(bool contain1TSHE) { contain1TSHE_ = contain1TSHE; }
void setContainPhaseHB(double containPhaseNSHB) { containPhaseNSHB_ = containPhaseNSHB; }
void setContainPhaseHE(double containPhaseNSHE) { containPhaseNSHE_ = containPhaseNSHE; }
void setOverrideDBweightsAndFilterHB(bool overrideDBweightsAndFilterHB) {
overrideDBweightsAndFilterHB_ = overrideDBweightsAndFilterHB;
}
void setOverrideDBweightsAndFilterHE(bool overrideDBweightsAndFilterHE) {
overrideDBweightsAndFilterHE_ = overrideDBweightsAndFilterHE;
}
void lookupMSB(const HBHEDataFrame& df, std::vector<bool>& msb) const;
void lookupMSB(const QIE10DataFrame& df, std::vector<std::bitset<2>>& msb) const;
void lookupMSB(const QIE11DataFrame& df, std::vector<std::bitset<2>>& msb) const;
Expand Down Expand Up @@ -114,9 +120,12 @@ class HcaluLUTTPGCoder : public HcalTPGCoder {
double cosh_ieta_28_HE_low_depths_, cosh_ieta_28_HE_high_depths_, cosh_ieta_29_HE_;
bool allLinear_;
bool contain1TSHB_, contain1TSHE_;
double containPhaseNSHB_, containPhaseNSHE_;
double containPhaseNSHB_ = 6.0;
double containPhaseNSHE_ = 6.0;
double linearLSB_QIE8_, linearLSB_QIE11_, linearLSB_QIE11Overlap_;
std::unique_ptr<HcalPulseContainmentManager> pulseCorr_;
bool overrideDBweightsAndFilterHB_ = false;
bool overrideDBweightsAndFilterHE_ = false;
};

#endif
46 changes: 41 additions & 5 deletions CalibCalorimetry/HcalTPGAlgos/src/HcaluLUTTPGCoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,43 @@ void HcaluLUTTPGCoder::update(const HcalDbService& conditions) {

make_cosh_ieta_map();

// Here we will determine if we are using new version of TPs (1TS)
// i.e. are we using a new pulse filter scheme.
const HcalElectronicsMap* emap = conditions.getHcalMapping();

int lastHBRing = topo_->lastHBRing();
int lastHERing = topo_->lastHERing();

// First, determine if we should configure for the filter scheme
// Check the tp version to make this determination
bool foundHB = false;
bool foundHE = false;
bool newHBtp = false;
bool newHEtp = false;
std::vector<HcalElectronicsId> vIds = emap->allElectronicsIdTrigger();
for (std::vector<HcalElectronicsId>::const_iterator eId = vIds.begin(); eId != vIds.end(); eId++) {
// The first HB or HE id is enough to tell whether to use new scheme in HB or HE
if (foundHB and foundHE)
break;

HcalTrigTowerDetId hcalTTDetId(emap->lookupTrigger(*eId));
if (hcalTTDetId.null())
continue;

int aieta = abs(hcalTTDetId.ieta());
int tp_version = hcalTTDetId.version();

if (aieta <= lastHBRing) {
foundHB = true;
if (tp_version > 1)
newHBtp = true;
} else if (aieta > lastHBRing and aieta < lastHERing) {
foundHE = true;
if (tp_version > 1)
newHEtp = true;
}
}

for (const auto& id : metadata->getAllChannels()) {
if (not(id.det() == DetId::Hcal and topo_->valid(id)))
continue;
Expand Down Expand Up @@ -419,11 +456,10 @@ void HcaluLUTTPGCoder::update(const HcalDbService& conditions) {

double correctionPhaseNS = conditions.getHcalRecoParam(cell)->correctionPhaseNS();

// When containPhaseNS is not -999.0, and for QIE11 only, override from configuration
if (qieType == QIE11) {
if (containPhaseNSHB_ != -999.0 and cell.ietaAbs() <= topo_->lastHBRing())
if (overrideDBweightsAndFilterHB_ and cell.ietaAbs() <= lastHBRing)
correctionPhaseNS = containPhaseNSHB_;
else if (containPhaseNSHE_ != -999.0 and cell.ietaAbs() > topo_->lastHBRing())
else if (overrideDBweightsAndFilterHE_ and cell.ietaAbs() > lastHBRing)
correctionPhaseNS = containPhaseNSHE_;
}
for (unsigned int adc = 0; adc < SIZE; ++adc) {
Expand All @@ -444,8 +480,8 @@ void HcaluLUTTPGCoder::update(const HcalDbService& conditions) {
pulseCorr_->correction(cell, 2, correctionPhaseNS, correctedCharge);
if (qieType == QIE11) {
// When contain1TS_ is set, it should still only apply for QIE11-related things
if ((contain1TSHB_ and cell.ietaAbs() <= topo_->lastHBRing()) or
(contain1TSHE_ and cell.ietaAbs() > topo_->lastHBRing())) {
if ((((contain1TSHB_ and overrideDBweightsAndFilterHB_) or newHBtp) and cell.ietaAbs() <= lastHBRing) or
(((contain1TSHE_ and overrideDBweightsAndFilterHE_) or newHEtp) and cell.ietaAbs() > lastHBRing)) {
containmentCorrection = containmentCorrection1TS;
} else {
containmentCorrection = containmentCorrection2TSCorrected;
Expand Down
8 changes: 8 additions & 0 deletions CalibCalorimetry/HcalTPGEventSetup/src/HcalTPGCoderULUT.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class HcalTPGCoderULUT : public edm::ESProducer {
bool read_FGLut_, read_Ascii_, read_XML_, LUTGenerationMode_, linearLUTs_;
bool contain1TSHB_, contain1TSHE_;
double containPhaseNSHB_, containPhaseNSHE_;
bool overrideDBweightsAndFilterHB_, overrideDBweightsAndFilterHE_;
double linearLSB_QIE8_, linearLSB_QIE11Overlap_, linearLSB_QIE11_;
int maskBit_;
std::vector<uint32_t> FG_HF_thresholds_;
Expand All @@ -86,6 +87,8 @@ HcalTPGCoderULUT::HcalTPGCoderULUT(const edm::ParameterSet& iConfig) {
contain1TSHE_ = iConfig.getParameter<bool>("contain1TSHE");
containPhaseNSHB_ = iConfig.getParameter<double>("containPhaseNSHB");
containPhaseNSHE_ = iConfig.getParameter<double>("containPhaseNSHE");
overrideDBweightsAndFilterHB_ = iConfig.getParameter<bool>("overrideDBweightsAndFilterHB");
overrideDBweightsAndFilterHE_ = iConfig.getParameter<bool>("overrideDBweightsAndFilterHE");

//the following line is needed to tell the framework what
// data is being produced
Expand All @@ -111,8 +114,13 @@ HcalTPGCoderULUT::HcalTPGCoderULUT(const edm::ParameterSet& iConfig) {
void HcalTPGCoderULUT::buildCoder(const HcalTopology* topo, const HcalTimeSlew* delay, HcaluLUTTPGCoder* theCoder) {
using namespace edm::es;
theCoder->init(topo, delay);

theCoder->setOverrideDBweightsAndFilterHB(overrideDBweightsAndFilterHB_);
theCoder->setOverrideDBweightsAndFilterHE(overrideDBweightsAndFilterHE_);

theCoder->set1TSContainHB(contain1TSHB_);
theCoder->set1TSContainHE(contain1TSHE_);

theCoder->setContainPhaseHB(containPhaseNSHB_);
theCoder->setContainPhaseHE(containPhaseNSHE_);

Expand Down
7 changes: 4 additions & 3 deletions Geometry/CaloTopology/src/HcalTopology.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ bool HcalTopology::validHT(const HcalTrigTowerDetId& id) const {
if (id.ietaAbs() > lastHBRing_ && id.ietaAbs() < firstHFRing_)
return false;
}
if (id.version() == 0) {
// Version 2 TPs should be for HBHE when using 1TS filter scheme
if (id.version() == 0 or id.version() == 2) {
if (id.ietaAbs() > 28) {
if (triggerMode_ >= HcalTopologyMode::TriggerMode_2017)
return false;
Expand All @@ -265,8 +266,8 @@ bool HcalTopology::validHT(const HcalTrigTowerDetId& id) const {
return false;
if (id.ietaAbs() > 39 && ((id.iphi() % 4) != 3))
return false;
} else if (id.version() > 1) {
// only versions 0 and 1 are supported
} else if (id.version() > 2) {
// only versions 0, 1, and 2 are supported
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions Geometry/HcalTowerAlgo/interface/HcalTrigTowerGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class HcalTrigTowerGeometry {
std::vector<HcalTrigTowerDetId> towerIds(const HcalDetId& cellId) const;
std::vector<HcalDetId> detIds(const HcalTrigTowerDetId&) const;

int firstHFTower(int version) const { return (version == 0) ? (29) : (30); }
int firstHFTower(int version) const { return (version == 1) ? (30) : (29); }

/// where this tower begins and ends in eta
void towerEtaBounds(int ieta, int version, double& eta1, double& eta2) const;

/// number of towers (version dependent)
int nTowers(int version) const { return (version == 0) ? (32) : (41); }
int nTowers(int version) const { return (version == 1) ? (41) : (32); }

// get the topology pointer
const HcalTopology& topology() const { return *theTopology; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,14 @@ class HcalTriggerPrimitiveAlgo {
HcalTrigPrimDigiCollection& result);
void setPeakFinderAlgorithm(int algo);
void setWeightsQIE11(const edm::ParameterSet& weightsQIE11);
void setWeightQIE11(int aieta, double weight);
void setNCTScaleShift(int);
void setRCTScaleShift(int);

void setNumFilterPresamplesHBQIE11(int presamples) { numberOfFilterPresamplesHBQIE11_ = presamples; }

void setNumFilterPresamplesHEQIE11(int presamples) { numberOfFilterPresamplesHEQIE11_ = presamples; }

void setUpgradeFlags(bool hb, bool he, bool hf);
void overrideParameters(const edm::ParameterSet& ps);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,12 @@ void HcalTriggerPrimitiveAlgo::setWeightsQIE11(const edm::ParameterSet& weightsQ
}
}

void HcalTriggerPrimitiveAlgo::setWeightQIE11(int aieta, double weight) {
// Simple map of |ieta| in HBHE to weight
// Only one weight for SOI-1 TS
weightsQIE11_[aieta] = {{weight, 1.0}};
}

void HcalTriggerPrimitiveAlgo::setPeakFinderAlgorithm(int algo) {
if (algo <= 0 || algo > 2)
throw cms::Exception("ERROR: Only algo 1 & 2 are supported.") << std::endl;
Expand Down
6 changes: 4 additions & 2 deletions SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
linearLUTs = cms.bool(False),
contain1TSHB = cms.bool(False),
contain1TSHE = cms.bool(False),
containPhaseNSHE = cms.double(-999.0),
containPhaseNSHB = cms.double(-999.0),
containPhaseNSHE = cms.double(6.0),
containPhaseNSHB = cms.double(6.0),
overrideDBweightsAndFilterHB = cms.bool(False),
overrideDBweightsAndFilterHE = cms.bool(False),
tpScales = tpScales,
MaskBit = cms.int32(0x8000),
FG_HF_thresholds = cms.vuint32(17, 255),
Expand Down
2 changes: 2 additions & 0 deletions SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
cms.InputTag('simHcalUnsuppressedDigis:HBHEQIE11DigiCollection'),
cms.InputTag('simHcalUnsuppressedDigis:HFQIE10DigiCollection')),
InputTagFEDRaw = cms.InputTag("rawDataCollector"),
overrideDBweightsAndFilterHB = cms.bool(False),
overrideDBweightsAndFilterHE = cms.bool(False),
RunZS = cms.bool(False),
FrontEndFormatError = cms.bool(False), # Front End Format Error, for real data only
PeakFinderAlgorithm = cms.int32(2),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "CalibFormats/CaloTPG/interface/HcalTPGCompressor.h"
#include "CondFormats/HcalObjects/interface/HcalElectronicsMap.h"
#include "CondFormats/HcalObjects/interface/HcalTPChannelParameters.h"

#include <algorithm>

Expand Down Expand Up @@ -40,12 +40,16 @@ HcalTrigPrimDigiProducer::HcalTrigPrimDigiProducer(const edm::ParameterSet& ps)
upgrade_ = std::any_of(std::begin(upgrades), std::end(upgrades), [](bool a) { return a; });
legacy_ = std::any_of(std::begin(upgrades), std::end(upgrades), [](bool a) { return !a; });

overrideDBweightsAndFilterHE_ = ps.getParameter<bool>("overrideDBweightsAndFilterHE");
overrideDBweightsAndFilterHB_ = ps.getParameter<bool>("overrideDBweightsAndFilterHB");

theAlgo_.setWeightsQIE11(ps.getParameter<edm::ParameterSet>("weightsQIE11"));

if (ps.exists("parameters")) {
auto pset = ps.getUntrackedParameter<edm::ParameterSet>("parameters");
theAlgo_.overrideParameters(pset);
}
theAlgo_.setUpgradeFlags(upgrades[0], upgrades[1], upgrades[2]);
theAlgo_.setWeightsQIE11(ps.getParameter<edm::ParameterSet>("weightsQIE11"));

HFEMB_ = false;
if (ps.exists("LSConfig")) {
Expand All @@ -61,6 +65,8 @@ HcalTrigPrimDigiProducer::HcalTrigPrimDigiProducer(const edm::ParameterSet& ps)
tok_tpgTranscoder_ = esConsumes<CaloTPGTranscoder, CaloTPGRecord>();
tok_lutMetadata_ = esConsumes<HcalLutMetadata, HcalLutMetadataRcd>();
tok_trigTowerGeom_ = esConsumes<HcalTrigTowerGeometry, CaloGeometryRecord>();
tok_hcalTopo_ = esConsumes<HcalTopology, HcalRecNumberingRecord, edm::Transition::BeginRun>();

// register for data access
if (runFrontEndFormatError_) {
tok_raw_ = consumes<FEDRawDataCollection>(inputTagFEDRaw_);
Expand All @@ -76,6 +82,7 @@ HcalTrigPrimDigiProducer::HcalTrigPrimDigiProducer(const edm::ParameterSet& ps)
tok_hf_up_ = consumes<QIE10DigiCollection>(inputUpgradeLabel_[1]);
}
tok_dbService_ = esConsumes<HcalDbService, HcalDbRecord>();
tok_dbService_beginRun_ = esConsumes<HcalDbService, HcalDbRecord, edm::Transition::BeginRun>();
produces<HcalTrigPrimDigiCollection>();
theAlgo_.setPeakFinderAlgorithm(ps.getParameter<int>("PeakFinderAlgorithm"));

Expand All @@ -85,6 +92,92 @@ HcalTrigPrimDigiProducer::HcalTrigPrimDigiProducer(const edm::ParameterSet& ps)
theAlgo_.setRCTScaleShift(hfSS.getParameter<int>("RCTShift"));
}

void HcalTrigPrimDigiProducer::beginRun(const edm::Run& run, const edm::EventSetup& eventSetup) {
edm::ESHandle<HcalDbService> db = eventSetup.getHandle(tok_dbService_beginRun_);
const HcalTopology* topo = &eventSetup.getData(tok_hcalTopo_);

const HcalElectronicsMap* emap = db->getHcalMapping();

int lastHERing = topo->lastHERing();
int lastHBRing = topo->lastHBRing();

// First, determine if we should configure for the filter scheme
// Check the tp version to make this determination
bool foundHB = false;
bool foundHE = false;
bool newHBtp = false;
bool newHEtp = false;
std::vector<HcalElectronicsId> vIds = emap->allElectronicsIdTrigger();
for (std::vector<HcalElectronicsId>::const_iterator eId = vIds.begin(); eId != vIds.end(); eId++) {
// The first HB or HE id is enough to tell whether to use new scheme in HB or HE
if (foundHB and foundHE)
break;

HcalTrigTowerDetId hcalTTDetId(emap->lookupTrigger(*eId));
if (hcalTTDetId.null())
continue;

int aieta = abs(hcalTTDetId.ieta());
int tp_version = hcalTTDetId.version();

if (aieta <= lastHBRing) {
foundHB = true;
if (tp_version > 1)
newHBtp = true;
} else if (aieta > lastHBRing and aieta < lastHERing) {
foundHE = true;
if (tp_version > 1)
newHEtp = true;
}
}

std::vector<HcalElectronicsId> eIds = emap->allElectronicsIdPrecision();
for (std::vector<HcalElectronicsId>::const_iterator eId = eIds.begin(); eId != eIds.end(); eId++) {
HcalGenericDetId gid(emap->lookup(*eId));
if (gid.null() or (gid.genericSubdet() != HcalGenericDetId::HcalGenBarrel and
gid.genericSubdet() != HcalGenericDetId::HcalGenEndcap))
continue;

HcalDetId hcalDetId(emap->lookup(*eId));
if (hcalDetId.null())
continue;

int aieta = abs(hcalDetId.ieta());

// Do not let ieta 29 in the map
// If the aieta already has a weight in the map, then move on
if (aieta < lastHERing) {
// Filter weight represented in fixed point 8 bit
int fixedPointWeight = db->getHcalTPChannelParameter(hcalDetId)->getauxi1();

if (aieta <= lastHBRing) {
// Fix number of filter presamples to one if we are using DB weights
// Size of filter is already known when using DB weights
// Weight from DB represented as 8-bit integer
if (!overrideDBweightsAndFilterHB_) {
if (newHBtp) {
theAlgo_.setNumFilterPresamplesHBQIE11(1);
theAlgo_.setWeightQIE11(aieta, -static_cast<double>(fixedPointWeight) / 256.0);
} else {
theAlgo_.setNumFilterPresamplesHBQIE11(0);
theAlgo_.setWeightQIE11(aieta, 1.0);
}
}
} else if (aieta > lastHBRing) {
if (!overrideDBweightsAndFilterHE_) {
if (newHEtp) {
theAlgo_.setNumFilterPresamplesHEQIE11(1);
theAlgo_.setWeightQIE11(aieta, -static_cast<double>(fixedPointWeight) / 256.0);
} else {
theAlgo_.setNumFilterPresamplesHEQIE11(0);
theAlgo_.setWeightQIE11(aieta, 1.0);
}
}
}
}
}
}

void HcalTrigPrimDigiProducer::produce(edm::Event& iEvent, const edm::EventSetup& eventSetup) {
// Step A: get the conditions, for the decoding
edm::ESHandle<HcalTPGCoder> inputCoder = eventSetup.getHandle(tok_tpgCoder_);
Expand Down
Loading