Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:47

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