Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-05 04:09:22

0001 // -*- C++ -*-
0002 //
0003 // Package:    CalibTracker/SiStripESProducers
0004 // Class:      SiStripNoisesFakeESSource
0005 //
0006 /**\class SiStripNoisesFakeESSource SiStripNoisesFakeESSource.h CalibTracker/SiStripESProducers/plugins/SiStripNoisesFakeESSource.cc
0007 
0008  Description: "fake" SiStripNoises ESProducer
0009  - strip length mode: noise is a linear function of strip length (with different parameters for each layer - the same for all if only one is given)
0010  - random mode: noise of each strip is generated from a Gaussian distribution (with different parameters for each layer - the same for all if only one is given)
0011 
0012  Implementation:
0013      Port of SiStripNoisesGenerator and templated fake ESSource to an edm::ESProducer
0014 */
0015 
0016 // system include files
0017 #include <memory>
0018 
0019 // user include files
0020 #include "FWCore/Framework/interface/ESProducer.h"
0021 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0022 
0023 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
0024 #include "CondFormats/DataRecord/interface/SiStripCondDataRecords.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0026 
0027 #include "SiStripFakeAPVParameters.h"
0028 
0029 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
0030 
0031 class SiStripNoisesFakeESSource : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0032 public:
0033   SiStripNoisesFakeESSource(const edm::ParameterSet&);
0034   ~SiStripNoisesFakeESSource() override;
0035 
0036   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0037                       const edm::IOVSyncValue& iov,
0038                       edm::ValidityInterval& iValidity) override;
0039 
0040   typedef std::unique_ptr<SiStripNoises> ReturnType;
0041   ReturnType produce(const SiStripNoisesRcd&);
0042 
0043 private:
0044   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> m_tTopoToken;
0045   bool m_stripLengthMode;
0046   double m_noisePar0;
0047   SiStripFakeAPVParameters m_noisePar1;
0048   SiStripFakeAPVParameters m_noisePar2;
0049   uint32_t m_printDebug;
0050   SiStripDetInfo m_detInfo;
0051 };
0052 
0053 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0054 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0055 
0056 #include "CLHEP/Random/RandGauss.h"
0057 
0058 namespace {  // helper methods
0059   inline void printLog(const uint32_t detId, const unsigned short strip, const double& noise) {
0060     edm::LogInfo("SiStripNoisesDummyCalculator") << "detid: " << detId << " strip: " << strip << " noise: " << noise;
0061   }
0062 }  // namespace
0063 
0064 SiStripNoisesFakeESSource::SiStripNoisesFakeESSource(const edm::ParameterSet& iConfig)
0065     : m_tTopoToken(setWhatProduced(this).consumes()) {
0066   findingRecord<SiStripNoisesRcd>();
0067 
0068   m_stripLengthMode = iConfig.getParameter<bool>("StripLengthMode");
0069 
0070   if (!m_stripLengthMode) {
0071     //parameters for random noise generation. not used if Strip length mode is chosen
0072     m_noisePar0 = iConfig.getParameter<double>("MinPositiveNoise");
0073     m_noisePar1 = SiStripFakeAPVParameters(iConfig, "MeanNoise");
0074     m_noisePar2 = SiStripFakeAPVParameters(iConfig, "SigmaNoise");
0075   } else {
0076     //parameters for strip length proportional noise generation. not used if random mode is chosen
0077     m_noisePar0 = iConfig.getParameter<double>("electronPerAdc");
0078     m_noisePar1 = SiStripFakeAPVParameters(iConfig, "NoiseStripLengthSlope");
0079     m_noisePar2 = SiStripFakeAPVParameters(iConfig, "NoiseStripLengthQuote");
0080   }
0081 
0082   m_printDebug = iConfig.getUntrackedParameter<uint32_t>("printDebug", 5);
0083 
0084   m_detInfo = SiStripDetInfoFileReader::read(iConfig.getParameter<edm::FileInPath>("SiStripDetInfoFile").fullPath());
0085 }
0086 
0087 SiStripNoisesFakeESSource::~SiStripNoisesFakeESSource() {}
0088 
0089 void SiStripNoisesFakeESSource::setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0090                                                const edm::IOVSyncValue& iov,
0091                                                edm::ValidityInterval& iValidity) {
0092   iValidity = edm::ValidityInterval{iov.beginOfTime(), iov.endOfTime()};
0093 }
0094 
0095 // ------------ method called to produce the data  ------------
0096 SiStripNoisesFakeESSource::ReturnType SiStripNoisesFakeESSource::produce(const SiStripNoisesRcd& iRecord) {
0097   using namespace edm::es;
0098 
0099   const auto& tTopo = iRecord.get(m_tTopoToken);
0100 
0101   auto noises = std::make_unique<SiStripNoises>();
0102 
0103   uint32_t count{0};
0104   for (const auto& elm : m_detInfo.getAllData()) {
0105     //Generate Noises for det detid
0106     SiStripNoises::InputVector theSiStripVector;
0107     SiStripFakeAPVParameters::index sl = SiStripFakeAPVParameters::getIndex(&tTopo, elm.first);
0108 
0109     if (m_stripLengthMode) {
0110       // Use strip length
0111       const double linearSlope{m_noisePar1.get(sl)};
0112       const double linearQuote{m_noisePar2.get(sl)};
0113       const double stripLength{elm.second.stripLength};
0114       for (unsigned short j{0}; j < 128 * elm.second.nApvs; ++j) {
0115         const float noise = (linearSlope * stripLength + linearQuote) / m_noisePar0;
0116         if (count < m_printDebug)
0117           printLog(elm.first, j, noise);
0118         noises->setData(noise, theSiStripVector);
0119       }
0120     } else {
0121       // Use random generator
0122       const double meanN{m_noisePar1.get(sl)};
0123       const double sigmaN{m_noisePar2.get(sl)};
0124       for (unsigned short j{0}; j < 128 * elm.second.nApvs; ++j) {
0125         const float noise = std::max(CLHEP::RandGauss::shoot(meanN, sigmaN), m_noisePar0);
0126         if (count < m_printDebug)
0127           printLog(elm.first, j, noise);
0128         noises->setData(noise, theSiStripVector);
0129       }
0130     }
0131     ++count;
0132 
0133     if (!noises->put(elm.first, theSiStripVector)) {
0134       edm::LogError("SiStripNoisesFakeESSource::produce ") << " detid already exists";
0135     }
0136   }
0137 
0138   return noises;
0139 }
0140 
0141 //define this as a plug-in
0142 #include "FWCore/Framework/interface/SourceFactory.h"
0143 DEFINE_FWK_EVENTSETUP_SOURCE(SiStripNoisesFakeESSource);