File indexing completed on 2024-09-18 05:07:47
0001 #include "CalibFormats/CaloTPG/interface/CaloTPGRecord.h"
0002 #include "CalibFormats/CaloTPG/interface/CaloTPGTranscoder.h"
0003 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
0004 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
0005 #include "CalibFormats/HcalObjects/interface/HcalTPGCoder.h"
0006 #include "CalibFormats/HcalObjects/interface/HcalTPGRecord.h"
0007 #include "CalibFormats/CaloTPG/interface/HcalTPGCompressor.h"
0008 #include "CondFormats/HcalObjects/interface/HcalElectronicsMap.h"
0009 #include "CondFormats/HcalObjects/interface/HcalLutMetadata.h"
0010 #include "CondFormats/HcalObjects/interface/HcalTPChannelParameters.h"
0011 #include "CondFormats/DataRecord/interface/HcalLutMetadataRcd.h"
0012 #include "DataFormats/Common/interface/Handle.h"
0013 #include "DataFormats/HcalDigi/interface/HBHEDataFrame.h"
0014 #include "DataFormats/HcalDigi/interface/HFDataFrame.h"
0015 #include "DataFormats/HcalDigi/interface/HcalTriggerPrimitiveDigi.h"
0016 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
0017 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0018 #include "FWCore/Framework/interface/stream/EDProducer.h"
0019 #include "FWCore/Utilities/interface/ESGetToken.h"
0020 #include "FWCore/Framework/interface/Event.h"
0021 #include "FWCore/Framework/interface/EventSetup.h"
0022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 #include "Geometry/HcalTowerAlgo/interface/HcalTrigTowerGeometry.h"
0025 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0026 #include "Geometry/HcalTowerAlgo/interface/HcalGeometry.h"
0027 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0028 #include "SimCalorimetry/HcalTrigPrimAlgos/interface/HcalTriggerPrimitiveAlgo.h"
0029
0030 #include <algorithm>
0031 #include <vector>
0032
0033 class HcalTrigPrimDigiProducer : public edm::stream::EDProducer<> {
0034 public:
0035 explicit HcalTrigPrimDigiProducer(const edm::ParameterSet& ps);
0036 ~HcalTrigPrimDigiProducer() override {}
0037
0038
0039 void beginRun(const edm::Run& r, const edm::EventSetup& c) override;
0040 void produce(edm::Event& e, const edm::EventSetup& c) override;
0041
0042 private:
0043 HcalTriggerPrimitiveAlgo theAlgo_;
0044
0045
0046 std::vector<edm::InputTag> inputLabel_;
0047 std::vector<edm::InputTag> inputUpgradeLabel_;
0048
0049 edm::EDGetTokenT<QIE11DigiCollection> tok_hbhe_up_;
0050 edm::EDGetTokenT<QIE10DigiCollection> tok_hf_up_;
0051
0052 edm::EDGetTokenT<HBHEDigiCollection> tok_hbhe_;
0053 edm::EDGetTokenT<HFDigiCollection> tok_hf_;
0054
0055 bool overrideDBvetoThresholdsHE_;
0056 bool overrideDBvetoThresholdsHB_;
0057
0058 bool overrideDBweightsAndFilterHE_;
0059 bool overrideDBweightsAndFilterHB_;
0060
0061
0062 edm::InputTag inputTagFEDRaw_;
0063 edm::EDGetTokenT<FEDRawDataCollection> tok_raw_;
0064 double MinLongEnergy_, MinShortEnergy_, LongShortSlope_, LongShortOffset_;
0065
0066 bool runZS_;
0067
0068 bool runFrontEndFormatError_;
0069
0070 bool upgrade_;
0071 bool legacy_;
0072
0073 bool HFEMB_;
0074 edm::ParameterSet LongShortCut_;
0075 edm::ESGetToken<HcalTPGCoder, HcalTPGRecord> tok_tpgCoder_;
0076 edm::ESGetToken<CaloTPGTranscoder, CaloTPGRecord> tok_tpgTranscoder_;
0077 edm::ESGetToken<HcalLutMetadata, HcalLutMetadataRcd> tok_lutMetadata_;
0078 edm::ESGetToken<HcalTrigTowerGeometry, CaloGeometryRecord> tok_trigTowerGeom_;
0079 edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> tok_hcalTopo_;
0080 edm::ESGetToken<HcalDbService, HcalDbRecord> tok_dbService_;
0081 edm::ESGetToken<HcalDbService, HcalDbRecord> tok_dbService_beginRun_;
0082 };
0083
0084 HcalTrigPrimDigiProducer::HcalTrigPrimDigiProducer(const edm::ParameterSet& ps)
0085 : theAlgo_(ps.getParameter<bool>("peakFilter"),
0086 ps.getParameter<std::vector<double> >("weights"),
0087 ps.getParameter<int>("latency"),
0088 ps.getParameter<uint32_t>("FG_threshold"),
0089 ps.getParameter<std::vector<uint32_t> >("FG_HF_thresholds"),
0090 ps.getParameter<uint32_t>("ZS_threshold"),
0091 ps.getParameter<int>("numberOfSamples"),
0092 ps.getParameter<int>("numberOfPresamples"),
0093 ps.getParameter<int>("numberOfFilterPresamplesHBQIE11"),
0094 ps.getParameter<int>("numberOfFilterPresamplesHEQIE11"),
0095 ps.getParameter<int>("numberOfSamplesHF"),
0096 ps.getParameter<int>("numberOfPresamplesHF"),
0097 ps.getParameter<bool>("useTDCInMinBiasBits"),
0098 ps.getParameter<uint32_t>("MinSignalThreshold"),
0099 ps.getParameter<uint32_t>("PMTNoiseThreshold")),
0100 inputLabel_(ps.getParameter<std::vector<edm::InputTag> >("inputLabel")),
0101 inputUpgradeLabel_(ps.getParameter<std::vector<edm::InputTag> >("inputUpgradeLabel")),
0102 inputTagFEDRaw_(ps.getParameter<edm::InputTag>("InputTagFEDRaw")),
0103 runZS_(ps.getParameter<bool>("RunZS")),
0104 runFrontEndFormatError_(ps.getParameter<bool>("FrontEndFormatError")) {
0105 std::vector<bool> upgrades = {
0106 ps.getParameter<bool>("upgradeHB"), ps.getParameter<bool>("upgradeHE"), ps.getParameter<bool>("upgradeHF")};
0107 upgrade_ = std::any_of(std::begin(upgrades), std::end(upgrades), [](bool a) { return a; });
0108 legacy_ = std::any_of(std::begin(upgrades), std::end(upgrades), [](bool a) { return !a; });
0109
0110 overrideDBvetoThresholdsHE_ = ps.getParameter<bool>("overrideDBvetoThresholdsHE");
0111 overrideDBvetoThresholdsHB_ = ps.getParameter<bool>("overrideDBvetoThresholdsHB");
0112
0113 overrideDBweightsAndFilterHE_ = ps.getParameter<bool>("overrideDBweightsAndFilterHE");
0114 overrideDBweightsAndFilterHB_ = ps.getParameter<bool>("overrideDBweightsAndFilterHB");
0115
0116 theAlgo_.setWeightsQIE11(ps.getParameter<edm::ParameterSet>("weightsQIE11"));
0117 theAlgo_.setCodedVetoThresholds(ps.getParameter<edm::ParameterSet>("codedVetoThresholds"));
0118
0119 if (ps.exists("parameters")) {
0120 auto pset = ps.getUntrackedParameter<edm::ParameterSet>("parameters");
0121 theAlgo_.overrideParameters(pset);
0122 }
0123 theAlgo_.setUpgradeFlags(upgrades[0], upgrades[1], upgrades[2]);
0124 theAlgo_.setFixSaturationFlag(ps.getParameter<bool>("applySaturationFix"));
0125
0126 HFEMB_ = false;
0127 if (ps.exists("LSConfig")) {
0128 LongShortCut_ = ps.getUntrackedParameter<edm::ParameterSet>("LSConfig");
0129 HFEMB_ = LongShortCut_.getParameter<bool>("HcalFeatureHFEMBit");
0130 MinLongEnergy_ = LongShortCut_.getParameter<double>("Min_Long_Energy");
0131 MinShortEnergy_ = LongShortCut_.getParameter<double>("Min_Short_Energy");
0132 LongShortSlope_ =
0133 LongShortCut_.getParameter<double>("Long_vrs_Short_Slope");
0134 LongShortOffset_ = LongShortCut_.getParameter<double>("Long_Short_Offset");
0135 }
0136 tok_tpgCoder_ = esConsumes<HcalTPGCoder, HcalTPGRecord>();
0137 tok_tpgTranscoder_ = esConsumes<CaloTPGTranscoder, CaloTPGRecord>();
0138 tok_lutMetadata_ = esConsumes<HcalLutMetadata, HcalLutMetadataRcd>();
0139 tok_trigTowerGeom_ = esConsumes<HcalTrigTowerGeometry, CaloGeometryRecord>();
0140 tok_hcalTopo_ = esConsumes<HcalTopology, HcalRecNumberingRecord, edm::Transition::BeginRun>();
0141
0142
0143 if (runFrontEndFormatError_) {
0144 tok_raw_ = consumes<FEDRawDataCollection>(inputTagFEDRaw_);
0145 }
0146
0147 if (legacy_) {
0148 tok_hbhe_ = consumes<HBHEDigiCollection>(inputLabel_[0]);
0149 tok_hf_ = consumes<HFDigiCollection>(inputLabel_[1]);
0150 }
0151
0152 if (upgrade_) {
0153 tok_hbhe_up_ = consumes<QIE11DigiCollection>(inputUpgradeLabel_[0]);
0154 tok_hf_up_ = consumes<QIE10DigiCollection>(inputUpgradeLabel_[1]);
0155 }
0156 tok_dbService_ = esConsumes<HcalDbService, HcalDbRecord>();
0157 tok_dbService_beginRun_ = esConsumes<HcalDbService, HcalDbRecord, edm::Transition::BeginRun>();
0158 produces<HcalTrigPrimDigiCollection>();
0159 theAlgo_.setPeakFinderAlgorithm(ps.getParameter<int>("PeakFinderAlgorithm"));
0160
0161 edm::ParameterSet hfSS = ps.getParameter<edm::ParameterSet>("tpScales").getParameter<edm::ParameterSet>("HF");
0162
0163 theAlgo_.setNCTScaleShift(hfSS.getParameter<int>("NCTShift"));
0164 theAlgo_.setRCTScaleShift(hfSS.getParameter<int>("RCTShift"));
0165 }
0166
0167 void HcalTrigPrimDigiProducer::beginRun(const edm::Run& run, const edm::EventSetup& eventSetup) {
0168 edm::ESHandle<HcalDbService> db = eventSetup.getHandle(tok_dbService_beginRun_);
0169 const HcalTopology* topo = &eventSetup.getData(tok_hcalTopo_);
0170
0171 const HcalElectronicsMap* emap = db->getHcalMapping();
0172
0173 int lastHERing = topo->lastHERing();
0174 int lastHBRing = topo->lastHBRing();
0175
0176 std::vector<HcalElectronicsId> vIds = emap->allElectronicsIdTrigger();
0177 for (std::vector<HcalElectronicsId>::const_iterator eId = vIds.begin(); eId != vIds.end(); eId++) {
0178 HcalTrigTowerDetId hcalTTDetId(emap->lookupTrigger(*eId));
0179 if (hcalTTDetId.null())
0180 continue;
0181
0182 int aieta = std::abs(hcalTTDetId.ieta());
0183
0184 if (aieta >= lastHERing)
0185 continue;
0186
0187
0188 int fixedPointWeight = 255;
0189
0190
0191 int codedVetoThreshold = 0;
0192
0193 int presamples = 0;
0194
0195
0196
0197 auto tpParam = db->getHcalTPChannelParameter(hcalTTDetId, false);
0198 if (tpParam) {
0199
0200
0201
0202 fixedPointWeight = tpParam->getauxi1();
0203 codedVetoThreshold = tpParam->getauxi2();
0204 presamples = 1;
0205 }
0206
0207
0208 if (aieta <= lastHBRing) {
0209 if (!overrideDBvetoThresholdsHB_) {
0210 theAlgo_.setCodedVetoThreshold(aieta, codedVetoThreshold);
0211 }
0212 if (!overrideDBweightsAndFilterHB_) {
0213 theAlgo_.setNumFilterPresamplesHBQIE11(presamples);
0214 theAlgo_.setWeightQIE11(aieta, fixedPointWeight);
0215 }
0216 } else if (aieta < lastHERing) {
0217 if (!overrideDBvetoThresholdsHE_) {
0218 theAlgo_.setCodedVetoThreshold(aieta, codedVetoThreshold);
0219 }
0220 if (!overrideDBweightsAndFilterHE_) {
0221 theAlgo_.setNumFilterPresamplesHEQIE11(presamples);
0222 theAlgo_.setWeightQIE11(aieta, fixedPointWeight);
0223 }
0224 }
0225 }
0226 }
0227
0228 void HcalTrigPrimDigiProducer::produce(edm::Event& iEvent, const edm::EventSetup& eventSetup) {
0229
0230 edm::ESHandle<HcalTPGCoder> inputCoder = eventSetup.getHandle(tok_tpgCoder_);
0231
0232 edm::ESHandle<CaloTPGTranscoder> outTranscoder = eventSetup.getHandle(tok_tpgTranscoder_);
0233
0234 edm::ESHandle<HcalLutMetadata> lutMetadata = eventSetup.getHandle(tok_lutMetadata_);
0235 float rctlsb = lutMetadata->getRctLsb();
0236
0237 edm::ESHandle<HcalTrigTowerGeometry> pG = eventSetup.getHandle(tok_trigTowerGeom_);
0238
0239
0240 std::unique_ptr<HcalTrigPrimDigiCollection> result(new HcalTrigPrimDigiCollection());
0241
0242 edm::Handle<HBHEDigiCollection> hbheDigis;
0243 edm::Handle<HFDigiCollection> hfDigis;
0244
0245 edm::Handle<QIE11DigiCollection> hbheUpDigis;
0246 edm::Handle<QIE10DigiCollection> hfUpDigis;
0247
0248 if (legacy_) {
0249 iEvent.getByToken(tok_hbhe_, hbheDigis);
0250 iEvent.getByToken(tok_hf_, hfDigis);
0251
0252
0253
0254
0255 if (!hbheDigis.isValid() and legacy_) {
0256 edm::LogInfo("HcalTrigPrimDigiProducer") << "\nWarning: HBHEDigiCollection with input tag " << inputLabel_[0]
0257 << "\nrequested in configuration, but not found in the event."
0258 << "\nQuit returning empty product." << std::endl;
0259
0260
0261 iEvent.put(std::move(result));
0262
0263 return;
0264 }
0265
0266 if (!hfDigis.isValid() and legacy_) {
0267 edm::LogInfo("HcalTrigPrimDigiProducer") << "\nWarning: HFDigiCollection with input tag " << inputLabel_[1]
0268 << "\nrequested in configuration, but not found in the event."
0269 << "\nQuit returning empty product." << std::endl;
0270
0271
0272 iEvent.put(std::move(result));
0273
0274 return;
0275 }
0276 }
0277
0278 if (upgrade_) {
0279 iEvent.getByToken(tok_hbhe_up_, hbheUpDigis);
0280 iEvent.getByToken(tok_hf_up_, hfUpDigis);
0281
0282 if (!hbheUpDigis.isValid() and upgrade_) {
0283 edm::LogInfo("HcalTrigPrimDigiProducer")
0284 << "\nWarning: Upgrade HBHEDigiCollection with input tag " << inputUpgradeLabel_[0]
0285 << "\nrequested in configuration, but not found in the event."
0286 << "\nQuit returning empty product." << std::endl;
0287
0288
0289 iEvent.put(std::move(result));
0290
0291 return;
0292 }
0293
0294 if (!hfUpDigis.isValid() and upgrade_) {
0295 edm::LogInfo("HcalTrigPrimDigiProducer") << "\nWarning: HFDigiCollection with input tag " << inputUpgradeLabel_[1]
0296 << "\nrequested in configuration, but not found in the event."
0297 << "\nQuit returning empty product." << std::endl;
0298
0299
0300 iEvent.put(std::move(result));
0301
0302 return;
0303 }
0304 }
0305
0306 edm::ESHandle<HcalDbService> pSetup = eventSetup.getHandle(tok_dbService_);
0307
0308 HcalFeatureBit* hfembit = nullptr;
0309
0310 if (HFEMB_) {
0311 hfembit = new HcalFeatureHFEMBit(MinShortEnergy_,
0312 MinLongEnergy_,
0313 LongShortSlope_,
0314 LongShortOffset_,
0315 *pSetup);
0316 }
0317
0318
0319 if (legacy_ and not upgrade_) {
0320 theAlgo_.run(inputCoder.product(),
0321 outTranscoder->getHcalCompressor().get(),
0322 pSetup.product(),
0323 *result,
0324 &(*pG),
0325 rctlsb,
0326 hfembit,
0327 *hbheDigis,
0328 *hfDigis);
0329 } else if (legacy_ and upgrade_) {
0330 theAlgo_.run(inputCoder.product(),
0331 outTranscoder->getHcalCompressor().get(),
0332 pSetup.product(),
0333 *result,
0334 &(*pG),
0335 rctlsb,
0336 hfembit,
0337 *hbheDigis,
0338 *hfDigis,
0339 *hbheUpDigis,
0340 *hfUpDigis);
0341 } else {
0342 theAlgo_.run(inputCoder.product(),
0343 outTranscoder->getHcalCompressor().get(),
0344 pSetup.product(),
0345 *result,
0346 &(*pG),
0347 rctlsb,
0348 hfembit,
0349 *hbheUpDigis,
0350 *hfUpDigis);
0351 }
0352
0353
0354 if (runFrontEndFormatError_) {
0355 const HcalElectronicsMap* emap = pSetup->getHcalMapping();
0356
0357 edm::Handle<FEDRawDataCollection> fedHandle;
0358 iEvent.getByToken(tok_raw_, fedHandle);
0359
0360 if (fedHandle.isValid() && emap != nullptr) {
0361 theAlgo_.runFEFormatError(fedHandle.product(), emap, *result);
0362 } else {
0363 edm::LogInfo("HcalTrigPrimDigiProducer") << "\nWarning: FEDRawDataCollection with input tag " << inputTagFEDRaw_
0364 << "\nrequested in configuration, but not found in the event."
0365 << "\nQuit returning empty product." << std::endl;
0366
0367
0368 std::unique_ptr<HcalTrigPrimDigiCollection> emptyResult(new HcalTrigPrimDigiCollection());
0369
0370 iEvent.put(std::move(emptyResult));
0371
0372 return;
0373 }
0374 }
0375
0376 if (runZS_)
0377 theAlgo_.runZS(*result);
0378
0379 edm::LogInfo("HcalTrigPrimDigiProducer") << "HcalTrigPrims: " << result->size();
0380
0381
0382 iEvent.put(std::move(result));
0383 }
0384
0385 #include "FWCore/PluginManager/interface/ModuleDef.h"
0386 #include "FWCore/Framework/interface/MakerMacros.h"
0387
0388 DEFINE_FWK_MODULE(HcalTrigPrimDigiProducer);