Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-08-23 12:58:57

0001 // -*- C++ -*-
0002 //
0003 // Package:    HcalTPGCoderULUT
0004 // Class:      HcalTPGCoderULUT
0005 //
0006 /**\class HcalTPGCoderULUT HcalTPGCoderULUT.h src/HcalTPGCoderULUT/interface/HcalTPGCoderULUT.h
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Jeremiah Mans
0015 //         Created:  Fri Sep 15 11:49:44 CDT 2006
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <string>
0022 
0023 // user include files
0024 
0025 #include "FWCore/Framework/interface/ModuleFactory.h"
0026 #include "FWCore/Framework/interface/ESProducer.h"
0027 #include "FWCore/Framework/interface/ESProductHost.h"
0028 #include "FWCore/Utilities/interface/ReusableObjectHolder.h"
0029 
0030 #include "CalibCalorimetry/HcalTPGAlgos/interface/HcaluLUTTPGCoder.h"
0031 #include "CalibFormats/HcalObjects/interface/HcalTPGRecord.h"
0032 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0033 #include "Geometry/CaloTopology/interface/HcalTopology.h"
0034 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
0035 
0036 //
0037 // class decleration
0038 //
0039 
0040 class HcalTPGCoderULUT : public edm::ESProducer {
0041 public:
0042   HcalTPGCoderULUT(const edm::ParameterSet&);
0043   ~HcalTPGCoderULUT() override;
0044 
0045   typedef std::shared_ptr<HcalTPGCoder> ReturnType;
0046 
0047   ReturnType produce(const HcalTPGRecord&);
0048 
0049 private:
0050   using HostType = edm::ESProductHost<HcaluLUTTPGCoder, HcalDbRecord>;
0051 
0052   void buildCoder(const HcalTopology*, const HcalTimeSlew*, HcaluLUTTPGCoder*);
0053 
0054   // ----------member data ---------------------------
0055   edm::ReusableObjectHolder<HostType> holder_;
0056   edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> topoToken_;
0057   edm::ESGetToken<HcalTimeSlew, HcalTimeSlewRecord> delayToken_;
0058   edm::ESGetToken<HcalDbService, HcalDbRecord> serviceToken_;
0059   bool read_FGLut_, read_Ascii_, read_XML_, LUTGenerationMode_, linearLUTs_;
0060   bool contain1TSHB_, contain1TSHE_;
0061   double containPhaseNSHB_, containPhaseNSHE_;
0062   bool applyFixPCC_;
0063   bool overrideDBweightsAndFilterHB_, overrideDBweightsAndFilterHE_;
0064   double linearLSB_QIE8_, linearLSB_QIE11Overlap_, linearLSB_QIE11_;
0065   int maskBit_;
0066   std::vector<uint32_t> FG_HF_thresholds_;
0067   edm::FileInPath fgfile_, ifilename_;
0068 };
0069 
0070 //
0071 // constants, enums and typedefs
0072 //
0073 
0074 //
0075 // static data member definitions
0076 //
0077 
0078 //
0079 // constructors and destructor
0080 //
0081 HcalTPGCoderULUT::HcalTPGCoderULUT(const edm::ParameterSet& iConfig) {
0082   read_Ascii_ = iConfig.getParameter<bool>("read_Ascii_LUTs");
0083   read_XML_ = iConfig.getParameter<bool>("read_XML_LUTs");
0084   read_FGLut_ = iConfig.getParameter<bool>("read_FG_LUTs");
0085   fgfile_ = iConfig.getParameter<edm::FileInPath>("FGLUTs");
0086   contain1TSHB_ = iConfig.getParameter<bool>("contain1TSHB");
0087   contain1TSHE_ = iConfig.getParameter<bool>("contain1TSHE");
0088   containPhaseNSHB_ = iConfig.getParameter<double>("containPhaseNSHB");
0089   containPhaseNSHE_ = iConfig.getParameter<double>("containPhaseNSHE");
0090   overrideDBweightsAndFilterHB_ = iConfig.getParameter<bool>("overrideDBweightsAndFilterHB");
0091   overrideDBweightsAndFilterHE_ = iConfig.getParameter<bool>("overrideDBweightsAndFilterHE");
0092   applyFixPCC_ = iConfig.getParameter<bool>("applyFixPCC");
0093 
0094   //the following line is needed to tell the framework what
0095   // data is being produced
0096   auto cc = setWhatProduced(this);
0097   topoToken_ = cc.consumes();
0098   delayToken_ = cc.consumes(edm::ESInputTag{"", "HBHE"});
0099 
0100   if (!(read_Ascii_ || read_XML_)) {
0101     LUTGenerationMode_ = iConfig.getParameter<bool>("LUTGenerationMode");
0102     linearLUTs_ = iConfig.getParameter<bool>("linearLUTs");
0103     auto scales = iConfig.getParameter<edm::ParameterSet>("tpScales").getParameter<edm::ParameterSet>("HBHE");
0104     linearLSB_QIE8_ = scales.getParameter<double>("LSBQIE8");
0105     linearLSB_QIE11_ = scales.getParameter<double>("LSBQIE11");
0106     linearLSB_QIE11Overlap_ = scales.getParameter<double>("LSBQIE11Overlap");
0107     maskBit_ = iConfig.getParameter<int>("MaskBit");
0108     FG_HF_thresholds_ = iConfig.getParameter<std::vector<uint32_t> >("FG_HF_thresholds");
0109     serviceToken_ = cc.consumes();
0110   } else {
0111     ifilename_ = iConfig.getParameter<edm::FileInPath>("inputLUTs");
0112   }
0113 }
0114 
0115 void HcalTPGCoderULUT::buildCoder(const HcalTopology* topo, const HcalTimeSlew* delay, HcaluLUTTPGCoder* theCoder) {
0116   using namespace edm::es;
0117   theCoder->init(topo, delay);
0118 
0119   theCoder->setOverrideDBweightsAndFilterHB(overrideDBweightsAndFilterHB_);
0120   theCoder->setOverrideDBweightsAndFilterHE(overrideDBweightsAndFilterHE_);
0121 
0122   theCoder->set1TSContainHB(contain1TSHB_);
0123   theCoder->set1TSContainHE(contain1TSHE_);
0124 
0125   theCoder->setContainPhaseHB(containPhaseNSHB_);
0126   theCoder->setContainPhaseHE(containPhaseNSHE_);
0127 
0128   theCoder->setApplyFixPCC(applyFixPCC_);
0129 
0130   if (read_Ascii_ || read_XML_) {
0131     edm::LogInfo("HCAL") << "Using ASCII/XML LUTs" << ifilename_.fullPath() << " for HcalTPGCoderULUT initialization";
0132     if (read_Ascii_) {
0133       theCoder->update(ifilename_.fullPath().c_str());
0134     } else if (read_XML_) {
0135       theCoder->updateXML(ifilename_.fullPath().c_str());
0136     }
0137     // Read FG LUT and append to most significant bit 11
0138     if (read_FGLut_) {
0139       theCoder->update(fgfile_.fullPath().c_str(), true);
0140     }
0141   } else {
0142     theCoder->setAllLinear(linearLUTs_, linearLSB_QIE8_, linearLSB_QIE11_, linearLSB_QIE11Overlap_);
0143     theCoder->setLUTGenerationMode(LUTGenerationMode_);
0144     theCoder->setMaskBit(maskBit_);
0145     theCoder->setFGHFthresholds(FG_HF_thresholds_);
0146   }
0147 }
0148 
0149 HcalTPGCoderULUT::~HcalTPGCoderULUT() {
0150   // do anything here that needs to be done at desctruction time
0151   // (e.g. close files, deallocate resources etc.)
0152 }
0153 
0154 //
0155 // member functions
0156 //
0157 
0158 // ------------ method called to produce the data  ------------
0159 HcalTPGCoderULUT::ReturnType HcalTPGCoderULUT::produce(const HcalTPGRecord& iRecord) {
0160   auto host = holder_.makeOrGet([]() { return new HostType; });
0161 
0162   const auto& topo = iRecord.get(topoToken_);
0163   const auto& delayRcd = iRecord.getRecord<HcalDbRecord>();
0164   const auto& delay = delayRcd.get(delayToken_);
0165   if (read_Ascii_ || read_XML_) {
0166     buildCoder(&topo, &delay, host.get());
0167   } else {
0168     host->ifRecordChanges<HcalDbRecord>(iRecord, [this, &topo, &delay, h = host.get()](auto const& rec) {
0169       buildCoder(&topo, &delay, h);
0170       h->update(rec.get(serviceToken_));
0171       // Temporary update for FG Lut
0172       // Will be moved to DB
0173       if (read_FGLut_)
0174         h->update(fgfile_.fullPath().c_str(), true);
0175     });
0176   }
0177   return host;
0178 }
0179 
0180 //define this as a plug-in
0181 DEFINE_FWK_EVENTSETUP_MODULE(HcalTPGCoderULUT);