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 
33 
35 public:
38 
40 
41  typedef std::unique_ptr<SiStripLorentzAngle> ReturnType;
42  ReturnType produce(const SiStripLorentzAngleRcd&);
43 
44 private:
45  std::vector<double> m_TIB_EstimatedValuesMin;
46  std::vector<double> m_TIB_EstimatedValuesMax;
47  std::vector<double> m_TOB_EstimatedValuesMin;
48  std::vector<double> m_TOB_EstimatedValuesMax;
49  std::vector<double> m_TIB_PerCent_Errs;
50  std::vector<double> m_TOB_PerCent_Errs;
51  std::vector<double> m_StdDevs_TIB;
52  std::vector<double> m_StdDevs_TOB;
53  std::vector<bool> m_uniformTIB;
54  std::vector<bool> m_uniformTOB;
63 };
64 
69 
70 #include "CLHEP/Random/RandFlat.h"
71 #include "CLHEP/Random/RandGauss.h"
72 
73 namespace { // helper methods
75  void setUniform(const std::vector<double>& estimatedValuesMin, const std::vector<double>& estimatedValuesMax, std::vector<bool>& uniform) {
76  if ( ! estimatedValuesMax.empty() ) {
77  std::vector<double>::const_iterator min = estimatedValuesMin.begin();
78  std::vector<double>::const_iterator max = estimatedValuesMax.begin();
79  std::vector<bool>::iterator uniformIt = uniform.begin();
80  for ( ; min != estimatedValuesMin.end(); ++min, ++max, ++uniformIt ) {
81  if ( *min != *max ) *uniformIt = true;
82  }
83  }
84  }
85 
86  double computeSigma(const double & value, const double & perCentError)
87  {
88  return (perCentError/100)*value;
89  }
90 
97  float hallMobility( const double& meanMin, const double& meanMax, const double& sigma, const bool uniform )
98  {
99  if ( uniform ) {
100  return CLHEP::RandFlat::shoot(meanMin, meanMax);
101  } else if ( sigma > 0 ) {
102  return CLHEP::RandGauss::shoot(meanMin, sigma);
103  } else {
104  return meanMin;
105  }
106  }
107 }
108 
110 {
111  setWhatProduced(this);
112  findingRecord<SiStripLorentzAngleRcd>();
113 
114  m_TIB_EstimatedValuesMin = iConfig.getParameter<std::vector<double>>("TIB_EstimatedValuesMin");
115  m_TIB_EstimatedValuesMax = iConfig.getParameter<std::vector<double>>("TIB_EstimatedValuesMax");
116  m_TOB_EstimatedValuesMin = iConfig.getParameter<std::vector<double>>("TOB_EstimatedValuesMin");
117  m_TOB_EstimatedValuesMax = iConfig.getParameter<std::vector<double>>("TOB_EstimatedValuesMax");
118  m_TIB_PerCent_Errs = iConfig.getParameter<std::vector<double>>("TIB_PerCent_Errs");
119  m_TOB_PerCent_Errs = iConfig.getParameter<std::vector<double>>("TOB_PerCent_Errs");
120 
121  // If max values are passed they must be equal in number to the min values.
122  if ( ( ( ! m_TIB_EstimatedValuesMax.empty() ) && ( m_TIB_EstimatedValuesMin.size() != m_TIB_EstimatedValuesMax.size() ) )
123  || ( ( ! m_TOB_EstimatedValuesMax.empty() ) && ( m_TOB_EstimatedValuesMin.size() != m_TOB_EstimatedValuesMax.size() ) ) )
124  {
125  std::cout << "ERROR: size of min and max values is different" << std::endl;
126  std::cout << "TIB_EstimatedValuesMin.size() = " << m_TIB_EstimatedValuesMin.size() << ", TIB_EstimatedValuesMax.size() " << m_TIB_EstimatedValuesMax.size() << std::endl;
127  std::cout << "TOB_EstimatedValuesMin.size() = " << m_TOB_EstimatedValuesMin.size() << ", TOB_EstimatedValuesMax.size() " << m_TOB_EstimatedValuesMax.size() << std::endl;
128  }
129 
130  m_uniformTIB = std::vector<bool>(m_TIB_EstimatedValuesMin.size(), false);
131  m_uniformTOB = std::vector<bool>(m_TOB_EstimatedValuesMin.size(), false);
132  setUniform(m_TIB_EstimatedValuesMin, m_TIB_EstimatedValuesMax, m_uniformTIB);
133  setUniform(m_TOB_EstimatedValuesMin, m_TOB_EstimatedValuesMax, m_uniformTOB);
134 
135  // Compute standard deviations
136  m_StdDevs_TIB = std::vector<double>(m_TIB_EstimatedValuesMin.size(), 0);
137  m_StdDevs_TOB = std::vector<double>(m_TOB_EstimatedValuesMin.size(), 0);
138  transform(m_TIB_EstimatedValuesMin.begin(), m_TIB_EstimatedValuesMin.end(), m_TIB_PerCent_Errs.begin(), m_StdDevs_TIB.begin(), computeSigma);
139  transform(m_TOB_EstimatedValuesMin.begin(), m_TOB_EstimatedValuesMin.end(), m_TOB_PerCent_Errs.begin(), m_StdDevs_TOB.begin(), computeSigma);
140 
141  // Compute mean values to be used with TID and TEC
142  m_TIBmeanValueMin = std::accumulate(m_TIB_EstimatedValuesMin.begin(), m_TIB_EstimatedValuesMin.end(), 0.)/double(m_TIB_EstimatedValuesMin.size());
143  m_TIBmeanValueMax = std::accumulate(m_TIB_EstimatedValuesMax.begin(), m_TIB_EstimatedValuesMax.end(), 0.)/double(m_TIB_EstimatedValuesMax.size());
144  m_TOBmeanValueMin = std::accumulate(m_TOB_EstimatedValuesMin.begin(), m_TOB_EstimatedValuesMin.end(), 0.)/double(m_TOB_EstimatedValuesMin.size());
145  m_TOBmeanValueMax = std::accumulate(m_TOB_EstimatedValuesMax.begin(), m_TOB_EstimatedValuesMax.end(), 0.)/double(m_TOB_EstimatedValuesMax.size());
146  m_TIBmeanPerCentError = std::accumulate(m_TIB_PerCent_Errs.begin(), m_TIB_PerCent_Errs.end(), 0.)/double(m_TIB_PerCent_Errs.size());
147  m_TOBmeanPerCentError = std::accumulate(m_TOB_PerCent_Errs.begin(), m_TOB_PerCent_Errs.end(), 0.)/double(m_TOB_PerCent_Errs.size());
148  m_TIBmeanStdDev = (m_TIBmeanPerCentError/100)*m_TIBmeanValueMin;
149  m_TOBmeanStdDev = (m_TOBmeanPerCentError/100)*m_TOBmeanValueMin;
150 }
151 
153 
155 {
156  iValidity = edm::ValidityInterval{iov.beginOfTime(), iov.endOfTime()};
157 }
158 
159 // ------------ method called to produce the data ------------
162 {
163  using namespace edm::es;
164 
166  iRecord.getRecord<TrackerTopologyRcd>().get(tTopo);
167 
168  auto lorentzAngle = std::make_unique<SiStripLorentzAngle>();
169 
171  for ( const auto& detId : reader->getAllDetIds() ) {
172  const DetId detectorId = DetId(detId);
173  const int subDet = detectorId.subdetId();
174 
175  float mobi{0.};
176 
177  if ( subDet == int(StripSubdetector::TIB) ) {
178  const int layerId = tTopo->tibLayer(detectorId) -1;
179  mobi = hallMobility(m_TIB_EstimatedValuesMin[layerId], m_TIB_EstimatedValuesMax[layerId], m_StdDevs_TIB[layerId], m_uniformTIB[layerId]);
180  } else if ( subDet == int(StripSubdetector::TOB) ) {
181  const int layerId = tTopo->tobLayer(detectorId) -1;
182  mobi = hallMobility(m_TOB_EstimatedValuesMin[layerId], m_TOB_EstimatedValuesMax[layerId], m_StdDevs_TOB[layerId], m_uniformTOB[layerId]);
183  } else if ( subDet == int (StripSubdetector::TID) ) {
184  // ATTENTION: as of now the uniform generation for TID is decided by the setting for layer 0 of TIB
186  }
187  if ( subDet == int(StripSubdetector::TEC) ) {
188  if ( tTopo->tecRing(detectorId) < 5 ) {
189  // ATTENTION: as of now the uniform generation for TEC is decided by the setting for layer 0 of TIB
191  } else {
192  // ATTENTION: as of now the uniform generation for TEC is decided by the setting for layer 0 of TOB
194  }
195  }
196 
197  if ( ! lorentzAngle->putLorentzAngle(detId, mobi) ) {
198  edm::LogError("SiStripLorentzAngleFakeESSource::produce ") << " detid already exists";
199  }
200  }
201 
202  return lorentzAngle;
203 }
204 
205 //define this as a plug-in
T getParameter(std::string const &) const
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:124
SiStripLorentzAngleFakeESSource(const edm::ParameterSet &)
unsigned int tibLayer(const DetId &id) const
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &iov, edm::ValidityInterval &iValidity) override
unsigned int tecRing(const DetId &id) const
ring id
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
Definition: value.py:1
T min(T a, T b)
Definition: MathUtil.h:58
ReturnType produce(const SiStripLorentzAngleRcd &)
Definition: DetId.h:18
std::unique_ptr< SiStripLorentzAngle > ReturnType
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:91
unsigned int tobLayer(const DetId &id) const