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
SiStripLorentzAngleFakeESSource::m_TOBmeanStdDev
double m_TOBmeanStdDev
Definition: SiStripLorentzAngleFakeESSource.cc:68
edm::eventsetup::DependentRecordImplementation::getRecord
const DepRecordT getRecord() const
Definition: DependentRecordImplementation.h:50
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
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:163
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:5
edm::eventsetup::EventSetupRecordKey
Definition: EventSetupRecordKey.h:30
SiStripLorentzAngleFakeESSource::produce
ReturnType produce(const SiStripLorentzAngleRcd &)
Definition: SiStripLorentzAngleFakeESSource.cc:182
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:103
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:173
edm::ParameterSet
Definition: ParameterSet.h:47
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:114
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:175
SiStripLorentzAngleRcd
Definition: SiStripCondDataRecords.h:25
value
Definition: value.py:1
utils.h
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
GeometricDet.h
get
#define get
cc
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
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
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
SiStripLorentzAngleFakeESSource::m_TOBmeanPerCentError
double m_TOBmeanPerCentError
Definition: SiStripLorentzAngleFakeESSource.cc:66
edm::ESProducer
Definition: ESProducer.h:104
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