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;
48  ReturnType produce(const SiStripLorentzAngleRcd&);
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())) ||
128  ((!m_TOB_EstimatedValuesMax.empty()) && (m_TOB_EstimatedValuesMin.size() != m_TOB_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);
138  setUniform(m_TIB_EstimatedValuesMin, m_TIB_EstimatedValuesMax, m_uniformTIB);
139  setUniform(m_TOB_EstimatedValuesMin, m_TOB_EstimatedValuesMax, m_uniformTOB);
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);
144  transform(m_TIB_EstimatedValuesMin.begin(),
145  m_TIB_EstimatedValuesMin.end(),
146  m_TIB_PerCent_Errs.begin(),
147  m_StdDevs_TIB.begin(),
148  computeSigma);
149  transform(m_TOB_EstimatedValuesMin.begin(),
150  m_TOB_EstimatedValuesMin.end(),
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());
168  m_TIBmeanStdDev = (m_TIBmeanPerCentError / 100) * m_TIBmeanValueMin;
169  m_TOBmeanStdDev = (m_TOBmeanPerCentError / 100) * m_TOBmeanValueMin;
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
T getParameter(std::string const &) const
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:138
static constexpr auto TEC
SiStripLorentzAngleFakeESSource(const edm::ParameterSet &)
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &iov, edm::ValidityInterval &iValidity) override
edm::ESGetToken< GeometricDet, IdealGeometryRecord > m_geomDetToken
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88
std::vector< uint32_t > getSiStripDetIds(const GeometricDet &geomDet)
Definition: utils.cc:4
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
Definition: value.py:1
T min(T a, T b)
Definition: MathUtil.h:58
static constexpr auto TOB
ReturnType produce(const SiStripLorentzAngleRcd &)
Definition: DetId.h:17
static constexpr auto TIB
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > m_tTopoToken
std::unique_ptr< SiStripLorentzAngle > ReturnType
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:91
static constexpr auto TID
unsigned transform(const HcalDetId &id, unsigned transformCode)