Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:24:26

0001 #include "FWCore/Framework/interface/ESProducer.h"
0002 #include "FWCore/Utilities/interface/ESGetToken.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 
0005 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
0006 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
0007 
0008 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
0009 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
0010 
0011 #include "CondFormats/HcalObjects/interface/HcalRecoParams.h"
0012 #include "CondFormats/DataRecord/interface/HcalRecoParamsRcd.h"
0013 
0014 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0015 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0016 #include "Geometry/CaloTopology/interface/HcalTopology.h"
0017 #include "Geometry/HcalTowerAlgo/interface/HcalGeometry.h"
0018 
0019 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalSeverityLevelComputer.h"
0020 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalSeverityLevelComputerRcd.h"
0021 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalChannelProperties.h"
0022 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalChannelPropertiesAuxRecord.h"
0023 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalChannelPropertiesRecord.h"
0024 
0025 class HcalChannelPropertiesEP : public edm::ESProducer {
0026 public:
0027   typedef std::unique_ptr<HcalRecoParams> ReturnType1;
0028   typedef std::unique_ptr<HcalChannelPropertiesVec> ReturnType2;
0029 
0030   inline HcalChannelPropertiesEP(const edm::ParameterSet&) {
0031     auto cc1 = setWhatProduced(this, &HcalChannelPropertiesEP::produce1);
0032     topoToken_ = cc1.consumes();
0033     paramsToken_ = cc1.consumes();
0034 
0035     auto cc2 = setWhatProduced(this, &HcalChannelPropertiesEP::produce2);
0036     edm::ESInputTag qTag("", "withTopo");
0037     condToken_ = cc2.consumes();
0038     myParamsToken_ = cc2.consumes();
0039     sevToken_ = cc2.consumes();
0040     qualToken_ = cc2.consumes(qTag);
0041     geomToken_ = cc2.consumes();
0042   }
0043 
0044   inline ~HcalChannelPropertiesEP() override {}
0045 
0046   ReturnType1 produce1(const HcalChannelPropertiesAuxRecord& rcd) {
0047     using namespace edm;
0048 
0049     const HcalTopology& htopo = rcd.getRecord<HcalRecNumberingRecord>().get(topoToken_);
0050     const HcalRecoParams& params = rcd.getRecord<HcalRecoParamsRcd>().get(paramsToken_);
0051 
0052     ReturnType1 prod = std::make_unique<HcalRecoParams>(params);
0053     prod->setTopo(&htopo);
0054     return prod;
0055   }
0056 
0057   ReturnType2 produce2(const HcalChannelPropertiesRecord& rcd) {
0058     // There appears to be no easy way to trace the internal
0059     // dependencies of HcalDbService. So, rebuild the product
0060     // every time anything changes in the parent records.
0061     // This means that we are sometimes going to rebuild the
0062     // whole table on the lumi block boundaries instead of
0063     // just updating the list of bad channels.
0064     using namespace edm;
0065 
0066     // Retrieve various event setup records and data products
0067     const HcalDbRecord& dbRecord = rcd.getRecord<HcalDbRecord>();
0068     const HcalDbService& cond = dbRecord.get(condToken_);
0069     const HcalRecoParams& params = rcd.getRecord<HcalChannelPropertiesAuxRecord>().get(myParamsToken_);
0070     const HcalSeverityLevelComputer& severity = rcd.getRecord<HcalSeverityLevelComputerRcd>().get(sevToken_);
0071     const HcalChannelQuality& qual = dbRecord.getRecord<HcalChannelQualityRcd>().get(qualToken_);
0072     const CaloGeometry& geom = rcd.getRecord<CaloGeometryRecord>().get(geomToken_);
0073 
0074     // HcalTopology is taken from "params" created by the "produce1" method
0075     const HcalTopology& htopo(*params.topo());
0076 
0077     // Build the product
0078     ReturnType2 prod = std::make_unique<HcalChannelPropertiesVec>(htopo.ncells());
0079     std::array<HcalPipelinePedestalAndGain, 4> pedsAndGains;
0080     const HcalSubdetector subdetectors[3] = {HcalBarrel, HcalEndcap, HcalForward};
0081 
0082     for (HcalSubdetector subd : subdetectors) {
0083       const HcalGeometry* hcalGeom = static_cast<const HcalGeometry*>(geom.getSubdetectorGeometry(DetId::Hcal, subd));
0084       const std::vector<DetId>& ids = hcalGeom->getValidDetIds(DetId::Hcal, subd);
0085 
0086       for (const auto cell : ids) {
0087         const auto rawId = cell.rawId();
0088 
0089         // ADC decoding tools, etc
0090         const HcalRecoParam* param_ts = params.getValues(rawId);
0091         const HcalQIECoder* channelCoder = cond.getHcalCoder(cell);
0092         const HcalQIEShape* shape = cond.getHcalShape(channelCoder);
0093         const HcalSiPMParameter* siPMParameter = cond.getHcalSiPMParameter(cell);
0094 
0095         // Pedestals and gains
0096         const HcalCalibrations& calib = cond.getHcalCalibrations(cell);
0097         const HcalCalibrationWidths& calibWidth = cond.getHcalCalibrationWidths(cell);
0098         for (int capid = 0; capid < 4; ++capid) {
0099           pedsAndGains[capid] = HcalPipelinePedestalAndGain(calib.pedestal(capid),
0100                                                             calibWidth.pedestal(capid),
0101                                                             calib.effpedestal(capid),
0102                                                             calibWidth.effpedestal(capid),
0103                                                             calib.respcorrgain(capid),
0104                                                             calibWidth.gain(capid));
0105         }
0106 
0107         // Channel quality
0108         const HcalChannelStatus* digistatus = qual.getValues(rawId);
0109         const bool taggedBadByDb = severity.dropChannel(digistatus->getValue());
0110 
0111         // Fill the table entry
0112         const unsigned linearId = htopo.detId2denseId(cell);
0113         prod->at(linearId) =
0114             HcalChannelProperties(&calib, param_ts, channelCoder, shape, siPMParameter, pedsAndGains, taggedBadByDb);
0115       }
0116     }
0117 
0118     return prod;
0119   }
0120 
0121   HcalChannelPropertiesEP() = delete;
0122   HcalChannelPropertiesEP(const HcalChannelPropertiesEP&) = delete;
0123   HcalChannelPropertiesEP& operator=(const HcalChannelPropertiesEP&) = delete;
0124 
0125 private:
0126   edm::ESGetToken<HcalDbService, HcalDbRecord> condToken_;
0127   edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> topoToken_;
0128   edm::ESGetToken<HcalRecoParams, HcalRecoParamsRcd> paramsToken_;
0129   edm::ESGetToken<HcalSeverityLevelComputer, HcalSeverityLevelComputerRcd> sevToken_;
0130   edm::ESGetToken<HcalChannelQuality, HcalChannelQualityRcd> qualToken_;
0131   edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geomToken_;
0132   edm::ESGetToken<HcalRecoParams, HcalChannelPropertiesAuxRecord> myParamsToken_;
0133 };
0134 
0135 DEFINE_FWK_EVENTSETUP_MODULE(HcalChannelPropertiesEP);