File indexing completed on 2024-08-23 12:58:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 #include <memory>
0024 #include <numeric>
0025
0026
0027 #include "FWCore/Framework/interface/ESProducer.h"
0028 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0029
0030 #include "CondFormats/SiStripObjects/interface/SiStripLorentzAngle.h"
0031 #include "CondFormats/DataRecord/interface/SiStripCondDataRecords.h"
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
0034 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0035 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0036 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
0037
0038 class SiStripLorentzAngleFakeESSource : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0039 public:
0040 SiStripLorentzAngleFakeESSource(const edm::ParameterSet&);
0041 ~SiStripLorentzAngleFakeESSource() override;
0042
0043 void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0044 const edm::IOVSyncValue& iov,
0045 edm::ValidityInterval& iValidity) override;
0046
0047 typedef std::unique_ptr<SiStripLorentzAngle> ReturnType;
0048 ReturnType produce(const SiStripLorentzAngleRcd&);
0049
0050 private:
0051 std::vector<double> m_TIB_EstimatedValuesMin;
0052 std::vector<double> m_TIB_EstimatedValuesMax;
0053 std::vector<double> m_TOB_EstimatedValuesMin;
0054 std::vector<double> m_TOB_EstimatedValuesMax;
0055 std::vector<double> m_TIB_PerCent_Errs;
0056 std::vector<double> m_TOB_PerCent_Errs;
0057 std::vector<double> m_StdDevs_TIB;
0058 std::vector<double> m_StdDevs_TOB;
0059 std::vector<bool> m_uniformTIB;
0060 std::vector<bool> m_uniformTOB;
0061 double m_TIBmeanValueMin;
0062 double m_TIBmeanValueMax;
0063 double m_TOBmeanValueMin;
0064 double m_TOBmeanValueMax;
0065 double m_TIBmeanPerCentError;
0066 double m_TOBmeanPerCentError;
0067 double m_TIBmeanStdDev;
0068 double m_TOBmeanStdDev;
0069 edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> m_tTopoToken;
0070 edm::ESGetToken<GeometricDet, IdealGeometryRecord> m_geomDetToken;
0071 };
0072
0073 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0074 #include "Geometry/TrackerNumberingBuilder/interface/utils.h"
0075
0076 #include "CLHEP/Random/RandFlat.h"
0077 #include "CLHEP/Random/RandGauss.h"
0078
0079 namespace {
0080
0081 void setUniform(const std::vector<double>& estimatedValuesMin,
0082 const std::vector<double>& estimatedValuesMax,
0083 std::vector<bool>& uniform) {
0084 if (!estimatedValuesMax.empty()) {
0085 std::vector<double>::const_iterator min = estimatedValuesMin.begin();
0086 std::vector<double>::const_iterator max = estimatedValuesMax.begin();
0087 std::vector<bool>::iterator uniformIt = uniform.begin();
0088 for (; min != estimatedValuesMin.end(); ++min, ++max, ++uniformIt) {
0089 if (*min != *max)
0090 *uniformIt = true;
0091 }
0092 }
0093 }
0094
0095 double computeSigma(const double& value, const double& perCentError) { return (perCentError / 100) * value; }
0096
0097
0098
0099
0100
0101
0102
0103 float hallMobility(const double& meanMin, const double& meanMax, const double& sigma, const bool uniform) {
0104 if (uniform) {
0105 return CLHEP::RandFlat::shoot(meanMin, meanMax);
0106 } else if (sigma > 0) {
0107 return CLHEP::RandGauss::shoot(meanMin, sigma);
0108 } else {
0109 return meanMin;
0110 }
0111 }
0112 }
0113
0114 SiStripLorentzAngleFakeESSource::SiStripLorentzAngleFakeESSource(const edm::ParameterSet& iConfig) {
0115 auto cc = setWhatProduced(this);
0116 m_tTopoToken = cc.consumes();
0117 m_geomDetToken = cc.consumes();
0118 findingRecord<SiStripLorentzAngleRcd>();
0119
0120 m_TIB_EstimatedValuesMin = iConfig.getParameter<std::vector<double>>("TIB_EstimatedValuesMin");
0121 m_TIB_EstimatedValuesMax = iConfig.getParameter<std::vector<double>>("TIB_EstimatedValuesMax");
0122 m_TOB_EstimatedValuesMin = iConfig.getParameter<std::vector<double>>("TOB_EstimatedValuesMin");
0123 m_TOB_EstimatedValuesMax = iConfig.getParameter<std::vector<double>>("TOB_EstimatedValuesMax");
0124 m_TIB_PerCent_Errs = iConfig.getParameter<std::vector<double>>("TIB_PerCent_Errs");
0125 m_TOB_PerCent_Errs = iConfig.getParameter<std::vector<double>>("TOB_PerCent_Errs");
0126
0127
0128 if (((!m_TIB_EstimatedValuesMax.empty()) && (m_TIB_EstimatedValuesMin.size() != m_TIB_EstimatedValuesMax.size())) ||
0129 ((!m_TOB_EstimatedValuesMax.empty()) && (m_TOB_EstimatedValuesMin.size() != m_TOB_EstimatedValuesMax.size()))) {
0130 std::cout << "ERROR: size of min and max values is different" << std::endl;
0131 std::cout << "TIB_EstimatedValuesMin.size() = " << m_TIB_EstimatedValuesMin.size()
0132 << ", TIB_EstimatedValuesMax.size() " << m_TIB_EstimatedValuesMax.size() << std::endl;
0133 std::cout << "TOB_EstimatedValuesMin.size() = " << m_TOB_EstimatedValuesMin.size()
0134 << ", TOB_EstimatedValuesMax.size() " << m_TOB_EstimatedValuesMax.size() << std::endl;
0135 }
0136
0137 m_uniformTIB = std::vector<bool>(m_TIB_EstimatedValuesMin.size(), false);
0138 m_uniformTOB = std::vector<bool>(m_TOB_EstimatedValuesMin.size(), false);
0139 setUniform(m_TIB_EstimatedValuesMin, m_TIB_EstimatedValuesMax, m_uniformTIB);
0140 setUniform(m_TOB_EstimatedValuesMin, m_TOB_EstimatedValuesMax, m_uniformTOB);
0141
0142
0143 m_StdDevs_TIB = std::vector<double>(m_TIB_EstimatedValuesMin.size(), 0);
0144 m_StdDevs_TOB = std::vector<double>(m_TOB_EstimatedValuesMin.size(), 0);
0145 transform(m_TIB_EstimatedValuesMin.begin(),
0146 m_TIB_EstimatedValuesMin.end(),
0147 m_TIB_PerCent_Errs.begin(),
0148 m_StdDevs_TIB.begin(),
0149 computeSigma);
0150 transform(m_TOB_EstimatedValuesMin.begin(),
0151 m_TOB_EstimatedValuesMin.end(),
0152 m_TOB_PerCent_Errs.begin(),
0153 m_StdDevs_TOB.begin(),
0154 computeSigma);
0155
0156
0157 m_TIBmeanValueMin = std::accumulate(m_TIB_EstimatedValuesMin.begin(), m_TIB_EstimatedValuesMin.end(), 0.) /
0158 double(m_TIB_EstimatedValuesMin.size());
0159 m_TIBmeanValueMax = std::accumulate(m_TIB_EstimatedValuesMax.begin(), m_TIB_EstimatedValuesMax.end(), 0.) /
0160 double(m_TIB_EstimatedValuesMax.size());
0161 m_TOBmeanValueMin = std::accumulate(m_TOB_EstimatedValuesMin.begin(), m_TOB_EstimatedValuesMin.end(), 0.) /
0162 double(m_TOB_EstimatedValuesMin.size());
0163 m_TOBmeanValueMax = std::accumulate(m_TOB_EstimatedValuesMax.begin(), m_TOB_EstimatedValuesMax.end(), 0.) /
0164 double(m_TOB_EstimatedValuesMax.size());
0165 m_TIBmeanPerCentError =
0166 std::accumulate(m_TIB_PerCent_Errs.begin(), m_TIB_PerCent_Errs.end(), 0.) / double(m_TIB_PerCent_Errs.size());
0167 m_TOBmeanPerCentError =
0168 std::accumulate(m_TOB_PerCent_Errs.begin(), m_TOB_PerCent_Errs.end(), 0.) / double(m_TOB_PerCent_Errs.size());
0169 m_TIBmeanStdDev = (m_TIBmeanPerCentError / 100) * m_TIBmeanValueMin;
0170 m_TOBmeanStdDev = (m_TOBmeanPerCentError / 100) * m_TOBmeanValueMin;
0171 }
0172
0173 SiStripLorentzAngleFakeESSource::~SiStripLorentzAngleFakeESSource() {}
0174
0175 void SiStripLorentzAngleFakeESSource::setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0176 const edm::IOVSyncValue& iov,
0177 edm::ValidityInterval& iValidity) {
0178 iValidity = edm::ValidityInterval{iov.beginOfTime(), iov.endOfTime()};
0179 }
0180
0181
0182 SiStripLorentzAngleFakeESSource::ReturnType SiStripLorentzAngleFakeESSource::produce(
0183 const SiStripLorentzAngleRcd& iRecord) {
0184 using namespace edm::es;
0185
0186 const auto& geomDetRcd = iRecord.getRecord<TrackerTopologyRcd>();
0187 const auto& geomDet = geomDetRcd.get(m_geomDetToken);
0188 const auto& tTopo = iRecord.get(m_tTopoToken);
0189
0190 auto lorentzAngle = std::make_unique<SiStripLorentzAngle>();
0191
0192 for (const auto detId : TrackerGeometryUtils::getSiStripDetIds(geomDet)) {
0193 const DetId detectorId = DetId(detId);
0194 const int subDet = detectorId.subdetId();
0195
0196 float mobi{0.};
0197
0198 if (subDet == int(StripSubdetector::TIB)) {
0199 const int layerId = tTopo.tibLayer(detectorId) - 1;
0200 mobi = hallMobility(m_TIB_EstimatedValuesMin[layerId],
0201 m_TIB_EstimatedValuesMax[layerId],
0202 m_StdDevs_TIB[layerId],
0203 m_uniformTIB[layerId]);
0204 } else if (subDet == int(StripSubdetector::TOB)) {
0205 const int layerId = tTopo.tobLayer(detectorId) - 1;
0206 mobi = hallMobility(m_TOB_EstimatedValuesMin[layerId],
0207 m_TOB_EstimatedValuesMax[layerId],
0208 m_StdDevs_TOB[layerId],
0209 m_uniformTOB[layerId]);
0210 } else if (subDet == int(StripSubdetector::TID)) {
0211
0212 mobi = hallMobility(m_TIBmeanValueMin, m_TIBmeanValueMax, m_TIBmeanStdDev, m_uniformTIB[0]);
0213 }
0214 if (subDet == int(StripSubdetector::TEC)) {
0215 if (tTopo.tecRing(detectorId) < 5) {
0216
0217 mobi = hallMobility(m_TIBmeanValueMin, m_TIBmeanValueMax, m_TIBmeanStdDev, m_uniformTIB[0]);
0218 } else {
0219
0220 mobi = hallMobility(m_TOBmeanValueMin, m_TOBmeanValueMax, m_TOBmeanStdDev, m_uniformTOB[0]);
0221 }
0222 }
0223
0224 if (!lorentzAngle->putLorentzAngle(detId, mobi)) {
0225 edm::LogError("SiStripLorentzAngleFakeESSource::produce ") << " detid already exists";
0226 }
0227 }
0228
0229 return lorentzAngle;
0230 }
0231
0232
0233 #include "FWCore/Framework/interface/SourceFactory.h"
0234 DEFINE_FWK_EVENTSETUP_SOURCE(SiStripLorentzAngleFakeESSource);