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