Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:51

0001 // -*- C++ -*-
0002 //
0003 // Package:    CalibTracker/SiStripESProducers
0004 // Class:      SiStripBackPlaneCorrectionFakeESSource
0005 //
0006 /**\class SiStripBackPlaneCorrectionFakeESSource SiStripBackPlaneCorrectionFakeESSource.h CalibTracker/SiStripESProducers/plugins/SiStripBackPlaneCorrectionFakeESSource.cc
0007 
0008  Description: "fake" SiStripBackPlaneCorrection ESProducer - fixed value from configuration for each module geometry
0009 
0010  Implementation:
0011      Port of SiStripBackPlaneCorrectionGenerator and templated fake ESSource to an edm::ESProducer
0012 */
0013 
0014 // system include files
0015 #include <memory>
0016 
0017 // user include files
0018 #include "FWCore/Framework/interface/ESProducer.h"
0019 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0022 
0023 #include "CondFormats/SiStripObjects/interface/SiStripBackPlaneCorrection.h"
0024 #include "CondFormats/DataRecord/interface/SiStripCondDataRecords.h"
0025 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0026 #include "Geometry/TrackerNumberingBuilder/interface/utils.h"
0027 
0028 class SiStripBackPlaneCorrectionFakeESSource : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0029 public:
0030   SiStripBackPlaneCorrectionFakeESSource(const edm::ParameterSet&);
0031   ~SiStripBackPlaneCorrectionFakeESSource() override;
0032 
0033   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0034                       const edm::IOVSyncValue& iov,
0035                       edm::ValidityInterval& iValidity) override;
0036 
0037   typedef std::unique_ptr<SiStripBackPlaneCorrection> ReturnType;
0038   ReturnType produce(const SiStripBackPlaneCorrectionRcd&);
0039 
0040 private:
0041   std::vector<double> m_valuePerModuleGeometry;
0042   edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> m_tTopoToken;
0043   edm::ESGetToken<GeometricDet, IdealGeometryRecord> m_geomDetToken;
0044 };
0045 
0046 SiStripBackPlaneCorrectionFakeESSource::SiStripBackPlaneCorrectionFakeESSource(const edm::ParameterSet& iConfig) {
0047   auto cc = setWhatProduced(this);
0048   m_tTopoToken = cc.consumes();
0049   m_geomDetToken = cc.consumes();
0050   findingRecord<SiStripBackPlaneCorrectionRcd>();
0051 
0052   m_valuePerModuleGeometry = iConfig.getParameter<std::vector<double>>("BackPlaneCorrection_PerModuleGeometry");
0053 }
0054 
0055 SiStripBackPlaneCorrectionFakeESSource::~SiStripBackPlaneCorrectionFakeESSource() {}
0056 
0057 void SiStripBackPlaneCorrectionFakeESSource::setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0058                                                             const edm::IOVSyncValue& iov,
0059                                                             edm::ValidityInterval& iValidity) {
0060   iValidity = edm::ValidityInterval{iov.beginOfTime(), iov.endOfTime()};
0061 }
0062 
0063 // ------------ method called to produce the data  ------------
0064 SiStripBackPlaneCorrectionFakeESSource::ReturnType SiStripBackPlaneCorrectionFakeESSource::produce(
0065     const SiStripBackPlaneCorrectionRcd& iRecord) {
0066   using namespace edm::es;
0067 
0068   const auto& geomDet = iRecord.getRecord<TrackerTopologyRcd>().get(m_geomDetToken);
0069   const auto& tTopo = iRecord.get(m_tTopoToken);
0070 
0071   auto backPlaneCorrection = std::make_unique<SiStripBackPlaneCorrection>();
0072 
0073   for (const auto detId : TrackerGeometryUtils::getSiStripDetIds(geomDet)) {
0074     const auto moduleGeometry = static_cast<unsigned int>(tTopo.moduleGeometry(DetId(detId))) - 1;
0075     if (moduleGeometry > m_valuePerModuleGeometry.size()) {
0076       edm::LogError("SiStripBackPlaneCorrectionGenerator")
0077           << " BackPlaneCorrection_PerModuleGeometry only contains " << m_valuePerModuleGeometry.size()
0078           << "elements and module is out of range";
0079     }
0080     float value = m_valuePerModuleGeometry[moduleGeometry];
0081     if (!backPlaneCorrection->putBackPlaneCorrection(detId, value)) {
0082       edm::LogError("SiStripBackPlaneCorrectionGenerator") << " detid already exists";
0083     }
0084   }
0085 
0086   return backPlaneCorrection;
0087 }
0088 
0089 //define this as a plug-in
0090 #include "FWCore/Framework/interface/SourceFactory.h"
0091 DEFINE_FWK_EVENTSETUP_SOURCE(SiStripBackPlaneCorrectionFakeESSource);