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 
75 
76 #include "CLHEP/Random/RandFlat.h"
77 #include "CLHEP/Random/RandGauss.h"
78 
79 namespace { // helper methods
81  void setUniform(const std::vector<double>& estimatedValuesMin,
82  const std::vector<double>& estimatedValuesMax,
83  std::vector<bool>& uniform) {
84  if (!estimatedValuesMax.empty()) {
85  std::vector<double>::const_iterator min = estimatedValuesMin.begin();
86  std::vector<double>::const_iterator max = estimatedValuesMax.begin();
87  std::vector<bool>::iterator uniformIt = uniform.begin();
88  for (; min != estimatedValuesMin.end(); ++min, ++max, ++uniformIt) {
89  if (*min != *max)
90  *uniformIt = true;
91  }
92  }
93  }
94 
95  double computeSigma(const double& value, const double& perCentError) { return (perCentError / 100) * value; }
96 
103  float hallMobility(const double& meanMin, const double& meanMax, const double& sigma, const bool uniform) {
104  if (uniform) {
105  return CLHEP::RandFlat::shoot(meanMin, meanMax);
106  } else if (sigma > 0) {
107  return CLHEP::RandGauss::shoot(meanMin, sigma);
108  } else {
109  return meanMin;
110  }
111  }
112 } // namespace
113 
115  auto cc = setWhatProduced(this);
116  m_tTopoToken = cc.consumes();
117  m_geomDetToken = cc.consumes();
118  findingRecord<SiStripLorentzAngleRcd>();
119 
120  m_TIB_EstimatedValuesMin = iConfig.getParameter<std::vector<double>>("TIB_EstimatedValuesMin");
121  m_TIB_EstimatedValuesMax = iConfig.getParameter<std::vector<double>>("TIB_EstimatedValuesMax");
122  m_TOB_EstimatedValuesMin = iConfig.getParameter<std::vector<double>>("TOB_EstimatedValuesMin");
123  m_TOB_EstimatedValuesMax = iConfig.getParameter<std::vector<double>>("TOB_EstimatedValuesMax");
124  m_TIB_PerCent_Errs = iConfig.getParameter<std::vector<double>>("TIB_PerCent_Errs");
125  m_TOB_PerCent_Errs = iConfig.getParameter<std::vector<double>>("TOB_PerCent_Errs");
126 
127  // If max values are passed they must be equal in number to the min values.
128  if (((!m_TIB_EstimatedValuesMax.empty()) && (m_TIB_EstimatedValuesMin.size() != m_TIB_EstimatedValuesMax.size())) ||
130  std::cout << "ERROR: size of min and max values is different" << std::endl;
131  std::cout << "TIB_EstimatedValuesMin.size() = " << m_TIB_EstimatedValuesMin.size()
132  << ", TIB_EstimatedValuesMax.size() " << m_TIB_EstimatedValuesMax.size() << std::endl;
133  std::cout << "TOB_EstimatedValuesMin.size() = " << m_TOB_EstimatedValuesMin.size()
134  << ", TOB_EstimatedValuesMax.size() " << m_TOB_EstimatedValuesMax.size() << std::endl;
135  }
136 
137  m_uniformTIB = std::vector<bool>(m_TIB_EstimatedValuesMin.size(), false);
138  m_uniformTOB = std::vector<bool>(m_TOB_EstimatedValuesMin.size(), false);
141 
142  // Compute standard deviations
143  m_StdDevs_TIB = std::vector<double>(m_TIB_EstimatedValuesMin.size(), 0);
144  m_StdDevs_TOB = std::vector<double>(m_TOB_EstimatedValuesMin.size(), 0);
147  m_TIB_PerCent_Errs.begin(),
148  m_StdDevs_TIB.begin(),
149  computeSigma);
152  m_TOB_PerCent_Errs.begin(),
153  m_StdDevs_TOB.begin(),
154  computeSigma);
155 
156  // Compute mean values to be used with TID and TEC
157  m_TIBmeanValueMin = std::accumulate(m_TIB_EstimatedValuesMin.begin(), m_TIB_EstimatedValuesMin.end(), 0.) /
158  double(m_TIB_EstimatedValuesMin.size());
159  m_TIBmeanValueMax = std::accumulate(m_TIB_EstimatedValuesMax.begin(), m_TIB_EstimatedValuesMax.end(), 0.) /
160  double(m_TIB_EstimatedValuesMax.size());
161  m_TOBmeanValueMin = std::accumulate(m_TOB_EstimatedValuesMin.begin(), m_TOB_EstimatedValuesMin.end(), 0.) /
162  double(m_TOB_EstimatedValuesMin.size());
163  m_TOBmeanValueMax = std::accumulate(m_TOB_EstimatedValuesMax.begin(), m_TOB_EstimatedValuesMax.end(), 0.) /
164  double(m_TOB_EstimatedValuesMax.size());
166  std::accumulate(m_TIB_PerCent_Errs.begin(), m_TIB_PerCent_Errs.end(), 0.) / double(m_TIB_PerCent_Errs.size());
168  std::accumulate(m_TOB_PerCent_Errs.begin(), m_TOB_PerCent_Errs.end(), 0.) / double(m_TOB_PerCent_Errs.size());
171 }
172 
174 
176  const edm::IOVSyncValue& iov,
177  edm::ValidityInterval& iValidity) {
178  iValidity = edm::ValidityInterval{iov.beginOfTime(), iov.endOfTime()};
179 }
180 
181 // ------------ method called to produce the data ------------
183  const SiStripLorentzAngleRcd& iRecord) {
184  using namespace edm::es;
185 
186  const auto& geomDet = iRecord.getRecord<TrackerTopologyRcd>().get(m_geomDetToken);
187  const auto& tTopo = iRecord.get(m_tTopoToken);
188 
189  auto lorentzAngle = std::make_unique<SiStripLorentzAngle>();
190 
191  for (const auto detId : TrackerGeometryUtils::getSiStripDetIds(geomDet)) {
192  const DetId detectorId = DetId(detId);
193  const int subDet = detectorId.subdetId();
194 
195  float mobi{0.};
196 
197  if (subDet == int(StripSubdetector::TIB)) {
198  const int layerId = tTopo.tibLayer(detectorId) - 1;
199  mobi = hallMobility(m_TIB_EstimatedValuesMin[layerId],
200  m_TIB_EstimatedValuesMax[layerId],
201  m_StdDevs_TIB[layerId],
202  m_uniformTIB[layerId]);
203  } else if (subDet == int(StripSubdetector::TOB)) {
204  const int layerId = tTopo.tobLayer(detectorId) - 1;
205  mobi = hallMobility(m_TOB_EstimatedValuesMin[layerId],
206  m_TOB_EstimatedValuesMax[layerId],
207  m_StdDevs_TOB[layerId],
208  m_uniformTOB[layerId]);
209  } else if (subDet == int(StripSubdetector::TID)) {
210  // ATTENTION: as of now the uniform generation for TID is decided by the setting for layer 0 of TIB
212  }
213  if (subDet == int(StripSubdetector::TEC)) {
214  if (tTopo.tecRing(detectorId) < 5) {
215  // ATTENTION: as of now the uniform generation for TEC is decided by the setting for layer 0 of TIB
217  } else {
218  // ATTENTION: as of now the uniform generation for TEC is decided by the setting for layer 0 of TOB
220  }
221  }
222 
223  if (!lorentzAngle->putLorentzAngle(detId, mobi)) {
224  edm::LogError("SiStripLorentzAngleFakeESSource::produce ") << " detid already exists";
225  }
226  }
227 
228  return lorentzAngle;
229 }
230 
231 //define this as a plug-in
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
static constexpr auto TEC
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
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
Log< level::Error, false > LogError
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88
std::vector< uint32_t > getSiStripDetIds(const GeometricDet &geomDet)
Definition: utils.cc:5
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
static constexpr auto TOB
ReturnType produce(const SiStripLorentzAngleRcd &)
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:92
Definition: DetId.h:17
static constexpr auto TIB
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > m_tTopoToken
std::unique_ptr< SiStripLorentzAngle > ReturnType
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
static constexpr auto TID
unsigned transform(const HcalDetId &id, unsigned transformCode)