Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:25:10

0001 /**\class SiStripClusterizerConditionsESProducer
0002  *
0003  * Create a cache object for fast access to conditions needed by the SiStrip clusterizer
0004  *
0005  * @see SiStripClusterizerConditions
0006  */
0007 #include <memory>
0008 
0009 #include "FWCore/Framework/interface/ModuleFactory.h"
0010 #include "FWCore/Framework/interface/ESProducer.h"
0011 #include "FWCore/Framework/interface/ESHandle.h"
0012 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0014 
0015 #include "RecoLocalTracker/Records/interface/SiStripClusterizerConditionsRcd.h"
0016 #include "CalibFormats/SiStripObjects/interface/SiStripClusterizerConditions.h"
0017 
0018 #include "CalibFormats/SiStripObjects/interface/SiStripGain.h"
0019 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
0020 
0021 class SiStripClusterizerConditionsESProducer : public edm::ESProducer {
0022 public:
0023   SiStripClusterizerConditionsESProducer(const edm::ParameterSet&);
0024   ~SiStripClusterizerConditionsESProducer() override {}
0025 
0026   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0027 
0028   using ReturnType = std::unique_ptr<SiStripClusterizerConditions>;
0029   ReturnType produce(const SiStripClusterizerConditionsRcd&);
0030 
0031 private:
0032   edm::ESGetToken<SiStripGain, SiStripGainRcd> m_gainToken;
0033   edm::ESGetToken<SiStripNoises, SiStripNoisesRcd> m_noisesToken;
0034   edm::ESGetToken<SiStripQuality, SiStripQualityRcd> m_qualityToken;
0035 };
0036 
0037 SiStripClusterizerConditionsESProducer::SiStripClusterizerConditionsESProducer(const edm::ParameterSet& iConfig) {
0038   auto cc = setWhatProduced(this, iConfig.getParameter<std::string>("Label"));
0039 
0040   m_gainToken = cc.consumesFrom<SiStripGain, SiStripGainRcd>();
0041   m_noisesToken = cc.consumesFrom<SiStripNoises, SiStripNoisesRcd>();
0042   m_qualityToken = cc.consumesFrom<SiStripQuality, SiStripQualityRcd>(
0043       edm::ESInputTag{"", iConfig.getParameter<std::string>("QualityLabel")});
0044 }
0045 
0046 void SiStripClusterizerConditionsESProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0047   edm::ParameterSetDescription desc;
0048   desc.add<std::string>("QualityLabel", "");
0049   desc.add<std::string>("Label", "");
0050   descriptions.add("SiStripClusterizerConditionsESProducer", desc);
0051 }
0052 
0053 SiStripClusterizerConditionsESProducer::ReturnType SiStripClusterizerConditionsESProducer::produce(
0054     const SiStripClusterizerConditionsRcd& iRecord) {
0055   auto gainsH = iRecord.getTransientHandle(m_gainToken);
0056   const auto& noises = iRecord.get(m_noisesToken);
0057   const auto& quality = iRecord.get(m_qualityToken);
0058 
0059   auto product = std::make_unique<SiStripClusterizerConditions>(&quality);
0060 
0061   const auto& connected = quality.cabling()->connected();
0062   const auto& detCabling = quality.cabling()->getDetCabling();
0063   product->reserve(connected.size());
0064   for (const auto& conn : connected) {
0065     const auto det = conn.first;
0066     if (!quality.IsModuleBad(det)) {
0067       const auto gainRange = gainsH->getRange(det);
0068       std::vector<float> invGains;
0069       invGains.reserve(6);
0070       std::transform(
0071           gainRange.first, gainRange.second, std::back_inserter(invGains), [](auto gain) { return 1.f / gain; });
0072 
0073       static const std::vector<const FedChannelConnection*> noConn{};
0074       const auto detConn_it = detCabling.find(det);
0075 
0076       product->emplace_back(det,
0077                             quality.getRange(det),
0078                             noises.getRange(det),
0079                             invGains,
0080                             (detCabling.end() != detConn_it) ? (*detConn_it).second : noConn);
0081     }
0082   }
0083   LogDebug("SiStripClusterizerConditionsESProducer")
0084       << "Produced a SiStripClusterizerConditions object for " << product->allDets().size() << " modules";
0085   return product;
0086 }
0087 
0088 DEFINE_FWK_EVENTSETUP_MODULE(SiStripClusterizerConditionsESProducer);