CMS 3D CMS Logo

SiStripLorentzAngleFakeESSource.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CalibTracker/SiStripESProducers
4 // Class: SiStripLorentzAngleFakeESSource
5 //
22 // system include files
23 #include <memory>
24 #include <numeric>
25 
26 // user include files
29 
37 
39 public:
42 
44  const edm::IOVSyncValue& iov,
45  edm::ValidityInterval& iValidity) override;
46 
47  typedef std::unique_ptr<SiStripLorentzAngle> ReturnType;
49 
50 private:
51  std::vector<double> m_TIB_EstimatedValuesMin;
52  std::vector<double> m_TIB_EstimatedValuesMax;
53  std::vector<double> m_TOB_EstimatedValuesMin;
54  std::vector<double> m_TOB_EstimatedValuesMax;
55  std::vector<double> m_TIB_PerCent_Errs;
56  std::vector<double> m_TOB_PerCent_Errs;
57  std::vector<double> m_StdDevs_TIB;
58  std::vector<double> m_StdDevs_TOB;
59  std::vector<bool> m_uniformTIB;
60  std::vector<bool> m_uniformTOB;
71 };
72 
76 
77 #include "CLHEP/Random/RandFlat.h"
78 #include "CLHEP/Random/RandGauss.h"
79 
80 namespace { // helper methods
82  void setUniform(const std::vector<double>& estimatedValuesMin,
83  const std::vector<double>& estimatedValuesMax,
84  std::vector<bool>& uniform) {
85  if (!estimatedValuesMax.empty()) {
86  std::vector<double>::const_iterator min = estimatedValuesMin.begin();
87  std::vector<double>::const_iterator max = estimatedValuesMax.begin();
88  std::vector<bool>::iterator uniformIt = uniform.begin();
89  for (; min != estimatedValuesMin.end(); ++min, ++max, ++uniformIt) {
90  if (*min != *max)
91  *uniformIt = true;
92  }
93  }
94  }
95 
96  double computeSigma(const double& value, const double& perCentError) { return (perCentError / 100) * value; }
97 
104  float hallMobility(const double& meanMin, const double& meanMax, const double& sigma, const bool uniform) {
105  if (uniform) {
106  return CLHEP::RandFlat::shoot(meanMin, meanMax);
107  } else if (sigma > 0) {
108  return CLHEP::RandGauss::shoot(meanMin, sigma);
109  } else {
110  return meanMin;
111  }
112  }
113 } // namespace
114 
116  setWhatProduced(this).setConsumes(m_tTopoToken).setConsumes(m_geomDetToken);
117  findingRecord<SiStripLorentzAngleRcd>();
118 
119  m_TIB_EstimatedValuesMin = iConfig.getParameter<std::vector<double>>("TIB_EstimatedValuesMin");
120  m_TIB_EstimatedValuesMax = iConfig.getParameter<std::vector<double>>("TIB_EstimatedValuesMax");
121  m_TOB_EstimatedValuesMin = iConfig.getParameter<std::vector<double>>("TOB_EstimatedValuesMin");
122  m_TOB_EstimatedValuesMax = iConfig.getParameter<std::vector<double>>("TOB_EstimatedValuesMax");
123  m_TIB_PerCent_Errs = iConfig.getParameter<std::vector<double>>("TIB_PerCent_Errs");
124  m_TOB_PerCent_Errs = iConfig.getParameter<std::vector<double>>("TOB_PerCent_Errs");
125 
126  // If max values are passed they must be equal in number to the min values.
127  if (((!m_TIB_EstimatedValuesMax.empty()) && (m_TIB_EstimatedValuesMin.size() != m_TIB_EstimatedValuesMax.size())) ||
129  std::cout << "ERROR: size of min and max values is different" << std::endl;
130  std::cout << "TIB_EstimatedValuesMin.size() = " << m_TIB_EstimatedValuesMin.size()
131  << ", TIB_EstimatedValuesMax.size() " << m_TIB_EstimatedValuesMax.size() << std::endl;
132  std::cout << "TOB_EstimatedValuesMin.size() = " << m_TOB_EstimatedValuesMin.size()
133  << ", TOB_EstimatedValuesMax.size() " << m_TOB_EstimatedValuesMax.size() << std::endl;
134  }
135 
136  m_uniformTIB = std::vector<bool>(m_TIB_EstimatedValuesMin.size(), false);
137  m_uniformTOB = std::vector<bool>(m_TOB_EstimatedValuesMin.size(), false);
140 
141  // Compute standard deviations
142  m_StdDevs_TIB = std::vector<double>(m_TIB_EstimatedValuesMin.size(), 0);
143  m_StdDevs_TOB = std::vector<double>(m_TOB_EstimatedValuesMin.size(), 0);
146  m_TIB_PerCent_Errs.begin(),
147  m_StdDevs_TIB.begin(),
148  computeSigma);
151  m_TOB_PerCent_Errs.begin(),
152  m_StdDevs_TOB.begin(),
153  computeSigma);
154 
155  // Compute mean values to be used with TID and TEC
156  m_TIBmeanValueMin = std::accumulate(m_TIB_EstimatedValuesMin.begin(), m_TIB_EstimatedValuesMin.end(), 0.) /
157  double(m_TIB_EstimatedValuesMin.size());
158  m_TIBmeanValueMax = std::accumulate(m_TIB_EstimatedValuesMax.begin(), m_TIB_EstimatedValuesMax.end(), 0.) /
159  double(m_TIB_EstimatedValuesMax.size());
160  m_TOBmeanValueMin = std::accumulate(m_TOB_EstimatedValuesMin.begin(), m_TOB_EstimatedValuesMin.end(), 0.) /
161  double(m_TOB_EstimatedValuesMin.size());
162  m_TOBmeanValueMax = std::accumulate(m_TOB_EstimatedValuesMax.begin(), m_TOB_EstimatedValuesMax.end(), 0.) /
163  double(m_TOB_EstimatedValuesMax.size());
165  std::accumulate(m_TIB_PerCent_Errs.begin(), m_TIB_PerCent_Errs.end(), 0.) / double(m_TIB_PerCent_Errs.size());
167  std::accumulate(m_TOB_PerCent_Errs.begin(), m_TOB_PerCent_Errs.end(), 0.) / double(m_TOB_PerCent_Errs.size());
170 }
171 
173 
175  const edm::IOVSyncValue& iov,
176  edm::ValidityInterval& iValidity) {
177  iValidity = edm::ValidityInterval{iov.beginOfTime(), iov.endOfTime()};
178 }
179 
180 // ------------ method called to produce the data ------------
182  const SiStripLorentzAngleRcd& iRecord) {
183  using namespace edm::es;
184 
185  const auto& geomDet = iRecord.getRecord<TrackerTopologyRcd>().get(m_geomDetToken);
186  const auto& tTopo = iRecord.get(m_tTopoToken);
187 
188  auto lorentzAngle = std::make_unique<SiStripLorentzAngle>();
189 
190  for (const auto detId : TrackerGeometryUtils::getSiStripDetIds(geomDet)) {
191  const DetId detectorId = DetId(detId);
192  const int subDet = detectorId.subdetId();
193 
194  float mobi{0.};
195 
196  if (subDet == int(StripSubdetector::TIB)) {
197  const int layerId = tTopo.tibLayer(detectorId) - 1;
198  mobi = hallMobility(m_TIB_EstimatedValuesMin[layerId],
199  m_TIB_EstimatedValuesMax[layerId],
200  m_StdDevs_TIB[layerId],
201  m_uniformTIB[layerId]);
202  } else if (subDet == int(StripSubdetector::TOB)) {
203  const int layerId = tTopo.tobLayer(detectorId) - 1;
204  mobi = hallMobility(m_TOB_EstimatedValuesMin[layerId],
205  m_TOB_EstimatedValuesMax[layerId],
206  m_StdDevs_TOB[layerId],
207  m_uniformTOB[layerId]);
208  } else if (subDet == int(StripSubdetector::TID)) {
209  // ATTENTION: as of now the uniform generation for TID is decided by the setting for layer 0 of TIB
211  }
212  if (subDet == int(StripSubdetector::TEC)) {
213  if (tTopo.tecRing(detectorId) < 5) {
214  // ATTENTION: as of now the uniform generation for TEC is decided by the setting for layer 0 of TIB
216  } else {
217  // ATTENTION: as of now the uniform generation for TEC is decided by the setting for layer 0 of TOB
219  }
220  }
221 
222  if (!lorentzAngle->putLorentzAngle(detId, mobi)) {
223  edm::LogError("SiStripLorentzAngleFakeESSource::produce ") << " detid already exists";
224  }
225  }
226 
227  return lorentzAngle;
228 }
229 
230 //define this as a plug-in
SiStripLorentzAngleFakeESSource::m_TOBmeanStdDev
double m_TOBmeanStdDev
Definition: SiStripLorentzAngleFakeESSource.cc:68
edm::eventsetup::DependentRecordImplementation::getRecord
const DepRecordT getRecord() const
Definition: DependentRecordImplementation.h:51
SiStripLorentzAngleFakeESSource::m_StdDevs_TIB
std::vector< double > m_StdDevs_TIB
Definition: SiStripLorentzAngleFakeESSource.cc:57
MessageLogger.h
SiStripLorentzAngleFakeESSource::m_TIB_EstimatedValuesMax
std::vector< double > m_TIB_EstimatedValuesMax
Definition: SiStripLorentzAngleFakeESSource.cc:52
ESHandle.h
min
T min(T a, T b)
Definition: MathUtil.h:58
SiStripLorentzAngleFakeESSource::m_TIBmeanPerCentError
double m_TIBmeanPerCentError
Definition: SiStripLorentzAngleFakeESSource.cc:65
SiStripLorentzAngleFakeESSource::m_TOBmeanValueMin
double m_TOBmeanValueMin
Definition: SiStripLorentzAngleFakeESSource.cc:63
SiStripLorentzAngleFakeESSource::ReturnType
std::unique_ptr< SiStripLorentzAngle > ReturnType
Definition: SiStripLorentzAngleFakeESSource.cc:47
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::ESProducer::setWhatProduced
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:138
edm::ValidityInterval
Definition: ValidityInterval.h:28
ESProducer.h
SiStripDetId.h
edm::EventSetupRecordIntervalFinder
Definition: EventSetupRecordIntervalFinder.h:33
TrackerGeometryUtils::getSiStripDetIds
std::vector< uint32_t > getSiStripDetIds(const GeometricDet &geomDet)
Definition: utils.cc:4
edm::eventsetup::EventSetupRecordKey
Definition: EventSetupRecordKey.h:30
SiStripLorentzAngleFakeESSource::produce
ReturnType produce(const SiStripLorentzAngleRcd &)
Definition: SiStripLorentzAngleFakeESSource.cc:181
SiStripLorentzAngleFakeESSource::m_tTopoToken
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > m_tTopoToken
Definition: SiStripLorentzAngleFakeESSource.cc:69
DetId
Definition: DetId.h:17
TrackerTopology.h
SiStripLorentzAngleFakeESSource::m_TIBmeanValueMax
double m_TIBmeanValueMax
Definition: SiStripLorentzAngleFakeESSource.cc:62
SiStripLorentzAngleFakeESSource
Definition: SiStripLorentzAngleFakeESSource.cc:38
StripSubdetector::TIB
static constexpr auto TIB
Definition: StripSubdetector.h:16
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
SiStripLorentzAngleFakeESSource::m_TIB_PerCent_Errs
std::vector< double > m_TIB_PerCent_Errs
Definition: SiStripLorentzAngleFakeESSource.cc:55
SiStripLorentzAngleFakeESSource::m_TIBmeanStdDev
double m_TIBmeanStdDev
Definition: SiStripLorentzAngleFakeESSource.cc:67
edm::eventsetup::DependentRecordImplementation::get
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
Definition: DependentRecordImplementation.h:112
edm::IOVSyncValue
Definition: IOVSyncValue.h:31
DEFINE_FWK_EVENTSETUP_SOURCE
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:91
EventSetupRecordIntervalFinder.h
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
SiStripLorentzAngleFakeESSource::m_geomDetToken
edm::ESGetToken< GeometricDet, IdealGeometryRecord > m_geomDetToken
Definition: SiStripLorentzAngleFakeESSource.cc:70
SourceFactory.h
SiStripLorentzAngleFakeESSource::~SiStripLorentzAngleFakeESSource
~SiStripLorentzAngleFakeESSource() override
Definition: SiStripLorentzAngleFakeESSource.cc:172
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
SiStripCondDataRecords.h
edm::IOVSyncValue::endOfTime
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
SiStripLorentzAngleFakeESSource::m_TIB_EstimatedValuesMin
std::vector< double > m_TIB_EstimatedValuesMin
Definition: SiStripLorentzAngleFakeESSource.cc:51
SiStripLorentzAngleFakeESSource::SiStripLorentzAngleFakeESSource
SiStripLorentzAngleFakeESSource(const edm::ParameterSet &)
Definition: SiStripLorentzAngleFakeESSource.cc:115
SiStripLorentzAngleFakeESSource::m_TIBmeanValueMin
double m_TIBmeanValueMin
Definition: SiStripLorentzAngleFakeESSource.cc:61
SiStripLorentzAngleFakeESSource::m_uniformTIB
std::vector< bool > m_uniformTIB
Definition: SiStripLorentzAngleFakeESSource.cc:59
SiStripLorentzAngleFakeESSource::setIntervalFor
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &iov, edm::ValidityInterval &iValidity) override
Definition: SiStripLorentzAngleFakeESSource.cc:174
SiStripLorentzAngleRcd
Definition: SiStripCondDataRecords.h:25
value
Definition: value.py:1
utils.h
GeometricDet.h
get
#define get
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd >
SiStripLorentzAngleFakeESSource::m_uniformTOB
std::vector< bool > m_uniformTOB
Definition: SiStripLorentzAngleFakeESSource.cc:60
SiStripLorentzAngleFakeESSource::m_TOB_PerCent_Errs
std::vector< double > m_TOB_PerCent_Errs
Definition: SiStripLorentzAngleFakeESSource.cc:56
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
StripSubdetector::TEC
static constexpr auto TEC
Definition: StripSubdetector.h:19
SiStripLorentzAngleFakeESSource::m_StdDevs_TOB
std::vector< double > m_StdDevs_TOB
Definition: SiStripLorentzAngleFakeESSource.cc:58
relativeConstraints.value
value
Definition: relativeConstraints.py:53
SiStripLorentzAngleFakeESSource::m_TOB_EstimatedValuesMax
std::vector< double > m_TOB_EstimatedValuesMax
Definition: SiStripLorentzAngleFakeESSource.cc:54
StripSubdetector::TOB
static constexpr auto TOB
Definition: StripSubdetector.h:18
edm::es
Definition: es_Label.h:33
edm::IOVSyncValue::beginOfTime
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88
SiStripLorentzAngleFakeESSource::m_TOBmeanPerCentError
double m_TOBmeanPerCentError
Definition: SiStripLorentzAngleFakeESSource.cc:66
edm::ESProducer
Definition: ESProducer.h:101
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
ParameterSet.h
SiStripLorentzAngleFakeESSource::m_TOBmeanValueMax
double m_TOBmeanValueMax
Definition: SiStripLorentzAngleFakeESSource.cc:64
SiStripLorentzAngle.h
SiStripLorentzAngleFakeESSource::m_TOB_EstimatedValuesMin
std::vector< double > m_TOB_EstimatedValuesMin
Definition: SiStripLorentzAngleFakeESSource.cc:53
StripSubdetector.h
StripSubdetector::TID
static constexpr auto TID
Definition: StripSubdetector.h:17