Skip to content

Commit

Permalink
initial changes to get filter weights from DB
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Hiltbrand committed Jan 7, 2021
1 parent 1f286f9 commit f98da57
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Configuration/Eras/python/Era_Run3_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
from Configuration.Eras.Modifier_run3_common_cff import run3_common
from Configuration.Eras.Modifier_run3_GEM_cff import run3_GEM
from Configuration.Eras.Modifier_run3_HB_cff import run3_HB
from Configuration.Eras.Modifier_run3_HE_cff import run3_HE
from Configuration.Eras.Modifier_run2_GEM_2017_cff import run2_GEM_2017
from Configuration.Eras.Modifier_stage2L1Trigger_2021_cff import stage2L1Trigger_2021
from Configuration.Eras.Modifier_ctpps_2018_cff import ctpps_2018
from Configuration.Eras.Modifier_ctpps_2021_cff import ctpps_2021

Run3 = cms.ModifierChain(Run2_2018.copyAndExclude([run2_GEM_2017, ctpps_2018]), run3_common, run3_GEM, run3_HB, stage2L1Trigger_2021, ctpps_2021)
Run3 = cms.ModifierChain(Run2_2018.copyAndExclude([run2_GEM_2017, ctpps_2018]), run3_common, run3_GEM, run3_HB, run3_HE, stage2L1Trigger_2021, ctpps_2021)

6 changes: 6 additions & 0 deletions Configuration/Eras/python/Modifier_run3_HE_cff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import FWCore.ParameterSet.Config as cms

# This modifier is for HE-specific changes for sim, reco, etc.

run3_HE = cms.Modifier()

2 changes: 1 addition & 1 deletion Configuration/StandardSequences/python/Eras.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self):
'peripheralPbPb', 'pA_2016',
'run2_HE_2017', 'stage2L1Trigger', 'stage2L1Trigger_2017', 'stage2L1Trigger_2018', 'stage2L1Trigger_2021',
'run2_HF_2017', 'run2_HCAL_2017', 'run2_HEPlan1_2017', 'run2_HB_2018','run2_HE_2018',
'run3_HB', 'run3_common', 'run3_RPC',
'run3_HB', 'run3_HE', 'run3_common', 'run3_RPC',
'phase1Pixel', 'run3_GEM', 'run2_GEM_2017',
'run2_CSC_2018',
'phase2_common', 'phase2_tracker',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class HcalTriggerPrimitiveAlgo {
HcalTrigPrimDigiCollection& result);
void setPeakFinderAlgorithm(int algo);
void setWeightsQIE11(const edm::ParameterSet& weightsQIE11);
void setWeightsQIE11(const std::map<int, double>& weightsQIE11);
void setNCTScaleShift(int);
void setRCTScaleShift(int);

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

void HcalTriggerPrimitiveAlgo::setWeightsQIE11(const std::map<int, double>& weightsQIE11) {
// Simple map of |ieta| in HBHE to weight
for (auto& pair : weightsQIE11) {
// Only one weight for SOI-1 TS
weightsQIE11_[pair.first] = {{pair.second, 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
4 changes: 4 additions & 0 deletions SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from Configuration.Eras.Modifier_run2_HCAL_2018_cff import run2_HCAL_2018
from Configuration.Eras.Modifier_pp_on_AA_2018_cff import pp_on_AA_2018
from Configuration.Eras.Modifier_run3_HB_cff import run3_HB
from Configuration.Eras.Modifier_run3_HE_cff import run3_HE

from SimCalorimetry.HcalTrigPrimProducers.hcaltpdigi_cfi import *
from CalibCalorimetry.CaloTPG.CaloTPGTranscoder_cfi import *
Expand Down Expand Up @@ -33,3 +35,5 @@
run2_HCAL_2018.toModify(HcalTPGCoderULUT, linearLUTs=cms.bool(True))
pp_on_AA_2018.toModify(CaloTPGTranscoder, FG_HF_thresholds = cms.vuint32(15, 19))
pp_on_AA_2018.toModify(HcalTPGCoderULUT, FG_HF_thresholds = cms.vuint32(15, 19))
run3_HB.toModify(HcalTPGCoderULUT, contain1TSHB=cms.bool(True), containPhaseNSHB=cms.double(3.0))
run3_HE.toModify(HcalTPGCoderULUT, contain1TSHE=cms.bool(True), containPhaseNSHE=cms.double(3.0))
5 changes: 5 additions & 0 deletions SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from Configuration.Eras.Modifier_run2_HE_2017_cff import run2_HE_2017
from Configuration.Eras.Modifier_run2_HF_2017_cff import run2_HF_2017
from Configuration.Eras.Modifier_run3_HB_cff import run3_HB
from Configuration.Eras.Modifier_run3_HE_cff import run3_HE

LSParameter =cms.untracked.PSet(
HcalFeatureHFEMBit= cms.bool(False),
Expand Down Expand Up @@ -81,6 +82,8 @@
cms.InputTag('simHcalUnsuppressedDigis:HBHEQIE11DigiCollection'),
cms.InputTag('simHcalUnsuppressedDigis:HFQIE10DigiCollection')),
InputTagFEDRaw = cms.InputTag("rawDataCollector"),
useDBweightsHB = cms.bool(False),
useDBweightsHE = cms.bool(False),
RunZS = cms.bool(False),
FrontEndFormatError = cms.bool(False), # Front End Format Error, for real data only
PeakFinderAlgorithm = cms.int32(2),
Expand All @@ -95,5 +98,7 @@
numberOfPresamplesHF = cms.int32(1)
)
run2_HF_2017.toModify(tpScales.HF, NCTShift=cms.int32(2))
run3_HE.toModify(simHcalTriggerPrimitiveDigis, numberOfFilterPresamplesHEQIE11=cms.int32(1))
run3_HB.toModify(simHcalTriggerPrimitiveDigis, numberOfFilterPresamplesHBQIE11=cms.int32(1))
run3_HB.toModify(simHcalTriggerPrimitiveDigis, upgradeHB=cms.bool(True))
run3_HB.toModify(tpScales.HBHE, LSBQIE11Overlap=cms.double(1/16.))
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#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 +41,18 @@ 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; });

useDBweightsHE_ = ps.getParameter<bool>("useDBweightsHE");
useDBweightsHB_ = ps.getParameter<bool>("useDBweightsHB");

// Only if we are using DB weights for all HBHE do we skip this
if (!useDBweightsHE_ or !useDBweightsHB_)
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 +68,7 @@ HcalTrigPrimDigiProducer::HcalTrigPrimDigiProducer(const edm::ParameterSet& ps)
tok_tpgTranscoder_ = esConsumes<CaloTPGTranscoder, CaloTPGRecord>();
tok_lutMetadata_ = esConsumes<HcalLutMetadata, HcalLutMetadataRcd>();
tok_trigTowerGeom_ = esConsumes<HcalTrigTowerGeometry, CaloGeometryRecord>();
tok_caloGeom_ = esConsumes<CaloGeometry, CaloGeometryRecord, edm::Transition::BeginRun>();
// register for data access
if (runFrontEndFormatError_) {
tok_raw_ = consumes<FEDRawDataCollection>(inputTagFEDRaw_);
Expand All @@ -76,6 +84,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 +94,51 @@ HcalTrigPrimDigiProducer::HcalTrigPrimDigiProducer(const edm::ParameterSet& ps)
theAlgo_.setRCTScaleShift(hfSS.getParameter<int>("RCTShift"));
}

void HcalTrigPrimDigiProducer::beginRun(const edm::Run& run, const edm::EventSetup& eventSetup) {
bool useDBweights = useDBweightsHB_ or useDBweightsHE_;

if (useDBweights) {
const CaloGeometry& geom = eventSetup.getData(tok_caloGeom_);

std::map<int, double> weightsMap;
edm::ESHandle<HcalDbService> db = eventSetup.getHandle(tok_dbService_beginRun_);
edm::ESHandle<HcalTopology> topo;
eventSetup.get<HcalRecNumberingRecord>().get(topo);
int lastHERing = (*topo).lastHERing();
const HcalSubdetector subdetectors[2] = {HcalBarrel, HcalEndcap};

for (HcalSubdetector subd : subdetectors) {
// Skip HB or HE if we don't want to use DB weights
if ((subd == HcalBarrel and !useDBweightsHB_) or (subd == HcalEndcap and !useDBweightsHE_))
continue;

const HcalGeometry* hcalGeom = static_cast<const HcalGeometry*>(geom.getSubdetectorGeometry(DetId::Hcal, subd));
const std::vector<DetId>& ids = hcalGeom->getValidDetIds(DetId::Hcal, subd);

for (const auto cell : ids) {
const auto hcalDetId = HcalDetId(cell);
int aieta = hcalDetId.ietaAbs();

// Do not let ieta 29 in the map
// If the aieta already has a weight in the map, then move on
if (weightsMap.find(aieta) != weightsMap.end() or aieta >= lastHERing)
continue;

// Filter weight represented in fixed point 8 bit
int fixedPointWeight = db->getHcalTPChannelParameter(hcalDetId)->getauxi1();
std::cout << "|ieta|: " << aieta << " weight: " << fixedPointWeight << std::endl;

// Weight represented as 8-bit integer
double weight = -fixedPointWeight / pow(2, 8);

weightsMap[aieta] = weight;
}
}

theAlgo_.setWeightsQIE11(weightsMap);
}
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#include "CondFormats/DataRecord/interface/HcalLutMetadataRcd.h"
#include "Geometry/HcalTowerAlgo/interface/HcalTrigTowerGeometry.h"
#include "Geometry/Records/interface/CaloGeometryRecord.h"
#include "Geometry/HcalTowerAlgo/interface/HcalGeometry.h"
#include "Geometry/CaloGeometry/interface/CaloGeometry.h"

#include <vector>

class HcalTrigPrimDigiProducer : public edm::stream::EDProducer<> {
Expand All @@ -26,6 +29,7 @@ class HcalTrigPrimDigiProducer : public edm::stream::EDProducer<> {
~HcalTrigPrimDigiProducer() override {}

/**Produces the EDM products,*/
virtual void beginRun(const edm::Run& r, const edm::EventSetup& c);
void produce(edm::Event& e, const edm::EventSetup& c) override;

private:
Expand All @@ -41,6 +45,9 @@ class HcalTrigPrimDigiProducer : public edm::stream::EDProducer<> {
edm::EDGetTokenT<HBHEDigiCollection> tok_hbhe_;
edm::EDGetTokenT<HFDigiCollection> tok_hf_;

bool useDBweightsHE_;
bool useDBweightsHB_;

/// input tag for FEDRawDataCollection
edm::InputTag inputTagFEDRaw_;
edm::EDGetTokenT<FEDRawDataCollection> tok_raw_;
Expand All @@ -59,7 +66,9 @@ class HcalTrigPrimDigiProducer : public edm::stream::EDProducer<> {
edm::ESGetToken<CaloTPGTranscoder, CaloTPGRecord> tok_tpgTranscoder_;
edm::ESGetToken<HcalLutMetadata, HcalLutMetadataRcd> tok_lutMetadata_;
edm::ESGetToken<HcalTrigTowerGeometry, CaloGeometryRecord> tok_trigTowerGeom_;
edm::ESGetToken<CaloGeometry, CaloGeometryRecord> tok_caloGeom_;
edm::ESGetToken<HcalDbService, HcalDbRecord> tok_dbService_;
edm::ESGetToken<HcalDbService, HcalDbRecord> tok_dbService_beginRun_;
};

#endif

0 comments on commit f98da57

Please sign in to comment.