CMS 3D CMS Logo

SiStripApvSimulationParametersESProducer.cc
Go to the documentation of this file.
7 #include <fstream>
8 #include <boost/range/adaptor/indexed.hpp>
9 
11 public:
14 
16  const edm::IOVSyncValue& iov,
17  edm::ValidityInterval& iValidity) override;
18 
19  std::unique_ptr<SiStripApvSimulationParameters> produce(const SiStripApvSimulationParametersRcd& record);
20 
21 private:
22  std::vector<edm::FileInPath> baselineFiles_TOB_;
23  std::vector<edm::FileInPath> baselineFiles_TIB_;
24  std::vector<edm::FileInPath> baselineFiles_TID_;
25  std::vector<edm::FileInPath> baselineFiles_TEC_;
26  unsigned int baseline_nBins_;
29  std::vector<float> puBinEdges_;
30  std::vector<float> zBinEdges_;
31  std::vector<float> rBinEdgesTID_;
32  std::vector<float> rBinEdgesTEC_;
33 
35  const std::vector<float>& rzBinEdges) const;
36 };
37 
39  : baseline_nBins_(conf.getUntrackedParameter<unsigned int>("apvBaselines_nBinsPerBaseline")),
40  baseline_min_(conf.getUntrackedParameter<double>("apvBaselines_minBaseline")),
41  baseline_max_(conf.getUntrackedParameter<double>("apvBaselines_maxBaseline")) {
42  setWhatProduced(this);
43  findingRecord<SiStripApvSimulationParametersRcd>();
44  for (const auto x : conf.getUntrackedParameter<std::vector<double>>("apvBaselines_puBinEdges")) {
45  puBinEdges_.push_back(x);
46  }
47  for (const auto x : conf.getUntrackedParameter<std::vector<double>>("apvBaselines_zBinEdges")) {
48  zBinEdges_.push_back(x);
49  }
50  for (const auto x : conf.getUntrackedParameter<std::vector<double>>("apvBaselines_rBinEdges_TID")) {
51  rBinEdgesTID_.push_back(x);
52  }
53  for (const auto x : conf.getUntrackedParameter<std::vector<double>>("apvBaselines_rBinEdges_TEC")) {
54  rBinEdgesTEC_.push_back(x);
55  }
56  baselineFiles_TIB_ = {conf.getUntrackedParameter<edm::FileInPath>("apvBaselinesFile_tib1"),
57  conf.getUntrackedParameter<edm::FileInPath>("apvBaselinesFile_tib2"),
58  conf.getUntrackedParameter<edm::FileInPath>("apvBaselinesFile_tib3"),
59  conf.getUntrackedParameter<edm::FileInPath>("apvBaselinesFile_tib4")};
60  baselineFiles_TOB_ = {conf.getUntrackedParameter<edm::FileInPath>("apvBaselinesFile_tob1"),
61  conf.getUntrackedParameter<edm::FileInPath>("apvBaselinesFile_tob2"),
62  conf.getUntrackedParameter<edm::FileInPath>("apvBaselinesFile_tob3"),
63  conf.getUntrackedParameter<edm::FileInPath>("apvBaselinesFile_tob4"),
64  conf.getUntrackedParameter<edm::FileInPath>("apvBaselinesFile_tob5"),
65  conf.getUntrackedParameter<edm::FileInPath>("apvBaselinesFile_tob6")};
66 
67  if (!rBinEdgesTID_.empty()) {
68  baselineFiles_TID_ = {conf.getUntrackedParameter<edm::FileInPath>("apvBaselinesFile_tid1"),
69  conf.getUntrackedParameter<edm::FileInPath>("apvBaselinesFile_tid2"),
70  conf.getUntrackedParameter<edm::FileInPath>("apvBaselinesFile_tid3")};
71  }
72 
73  if (!rBinEdgesTEC_.empty()) {
74  baselineFiles_TEC_ = {conf.getUntrackedParameter<edm::FileInPath>("apvBaselinesFile_tec1"),
75  conf.getUntrackedParameter<edm::FileInPath>("apvBaselinesFile_tec2"),
76  conf.getUntrackedParameter<edm::FileInPath>("apvBaselinesFile_tec3"),
77  conf.getUntrackedParameter<edm::FileInPath>("apvBaselinesFile_tec4"),
78  conf.getUntrackedParameter<edm::FileInPath>("apvBaselinesFile_tec5"),
79  conf.getUntrackedParameter<edm::FileInPath>("apvBaselinesFile_tec6"),
80  conf.getUntrackedParameter<edm::FileInPath>("apvBaselinesFile_tec7"),
81  conf.getUntrackedParameter<edm::FileInPath>("apvBaselinesFile_tec8"),
82  conf.getUntrackedParameter<edm::FileInPath>("apvBaselinesFile_tec9")};
83  }
84 }
85 
87  const edm::IOVSyncValue& iov,
88  edm::ValidityInterval& iValidity) {
89  iValidity = edm::ValidityInterval{iov.beginOfTime(), iov.endOfTime()};
90 }
91 
93  const std::string& apvBaselinesFileName, const std::vector<float>& rzBinEdges) const {
94  // Prepare histograms
95  unsigned int nZBins = rzBinEdges.size();
96  unsigned int nPUBins = puBinEdges_.size();
97 
98  if (nPUBins == 0 || nZBins == 0 || baseline_nBins_ == 0) {
99  throw cms::Exception("MissingInput") << "The parameters for the APV simulation are not correctly configured\n";
100  }
101  std::vector<float> baselineBinEdges{};
102  const auto baseline_binWidth = (baseline_max_ - baseline_min_) / baseline_nBins_;
103  for (unsigned i{0}; i != baseline_nBins_; ++i) {
104  baselineBinEdges.push_back(baseline_min_ + i * baseline_binWidth);
105  }
106  baselineBinEdges.push_back(baseline_max_);
107 
108  SiStripApvSimulationParameters::LayerParameters layerParams{baselineBinEdges, puBinEdges_, rzBinEdges};
109 
110  // Read apv baselines from text files
111  std::vector<double> theAPVBaselines;
112  std::ifstream apvBaselineFile(apvBaselinesFileName.c_str());
113  if (!apvBaselineFile.good()) {
114  throw cms::Exception("FileError") << "Problem opening APV baselines file: " << apvBaselinesFileName;
115  }
117  while (std::getline(apvBaselineFile, line)) {
118  if (!line.empty()) {
119  std::istringstream lStr{line};
120  double value;
121  while (lStr >> value) {
122  theAPVBaselines.push_back(value);
123  }
124  }
125  }
126  if (theAPVBaselines.empty()) {
127  throw cms::Exception("WrongAPVBaselines")
128  << "Problem reading from APV baselines file " << apvBaselinesFileName << ": no values read in";
129  }
130 
131  if (theAPVBaselines.size() != nZBins * nPUBins * baseline_nBins_) {
132  throw cms::Exception("WrongAPVBaselines") << "Problem reading from APV baselines file " << apvBaselinesFileName
133  << ": number of baselines read different to that expected i.e. nZBins * "
134  "nPUBins * apvBaselines_nBinsPerBaseline_";
135  }
136 
137  // Put baselines into histograms
138  for (auto const& apvBaseline : theAPVBaselines | boost::adaptors::indexed(0)) {
139  unsigned int binInCurrentHistogram = apvBaseline.index() % baseline_nBins_ + 1;
140  unsigned int binInZ = int(apvBaseline.index()) / (nPUBins * baseline_nBins_);
141  unsigned int binInPU = int(apvBaseline.index() - binInZ * (nPUBins)*baseline_nBins_) / baseline_nBins_;
142 
143  layerParams.setBinContent(binInCurrentHistogram, binInPU + 1, binInZ + 1, apvBaseline.value());
144  }
145 
146  return layerParams;
147 }
148 
149 std::unique_ptr<SiStripApvSimulationParameters> SiStripApvSimulationParametersESSource::produce(
151  auto apvSimParams = std::make_unique<SiStripApvSimulationParameters>(
153  for (unsigned int i{0}; i != baselineFiles_TIB_.size(); ++i) {
154  if (!apvSimParams->putTIB(i + 1, makeLayerParameters(baselineFiles_TIB_[i].fullPath(), zBinEdges_))) {
155  throw cms::Exception("SiStripApvSimulationParameters") << "Could not add parameters for TIB layer " << (i + 1);
156  } else {
157  LogDebug("SiStripApvSimulationParameters") << "Added parameters for TIB layer " << (i + 1);
158  }
159  }
160  for (unsigned int i{0}; i != baselineFiles_TOB_.size(); ++i) {
161  if (!apvSimParams->putTOB(i + 1, makeLayerParameters(baselineFiles_TOB_[i].fullPath(), zBinEdges_))) {
162  throw cms::Exception("SiStripApvSimulationParameters") << "Could not add parameters for TOB layer " << (i + 1);
163  } else {
164  LogDebug("SiStripApvSimulationParameters") << "Added parameters for TOB layer " << (i + 1);
165  }
166  }
167  for (unsigned int i{0}; i != baselineFiles_TID_.size(); ++i) {
168  if (!apvSimParams->putTID(i + 1, makeLayerParameters(baselineFiles_TID_[i].fullPath(), rBinEdgesTID_))) {
169  throw cms::Exception("SiStripApvSimulationParameters") << "Could not add parameters for TID wheel " << (i + 1);
170  } else {
171  LogDebug("SiStripApvSimulationParameters") << "Added parameters for TID wheel " << (i + 1);
172  }
173  }
174  for (unsigned int i{0}; i != baselineFiles_TEC_.size(); ++i) {
175  if (!apvSimParams->putTEC(i + 1, makeLayerParameters(baselineFiles_TEC_[i].fullPath(), rBinEdgesTEC_))) {
176  throw cms::Exception("SiStripApvSimulationParameters") << "Could not add parameters for TEC wheel " << (i + 1);
177  } else {
178  LogDebug("SiStripApvSimulationParameters") << "Added parameters for TEC wheel " << (i + 1);
179  }
180  }
181  return apvSimParams;
182 }
183 
SiStripApvSimulationParametersESSource::baseline_min_
float baseline_min_
Definition: SiStripApvSimulationParametersESProducer.cc:27
SiStripApvSimulationParametersESSource::produce
std::unique_ptr< SiStripApvSimulationParameters > produce(const SiStripApvSimulationParametersRcd &record)
Definition: SiStripApvSimulationParametersESProducer.cc:149
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
contentValuesFiles.fullPath
fullPath
Definition: contentValuesFiles.py:64
SiStripApvSimulationParametersESSource::baselineFiles_TID_
std::vector< edm::FileInPath > baselineFiles_TID_
Definition: SiStripApvSimulationParametersESProducer.cc:24
SiStripApvSimulationParametersESSource::setIntervalFor
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &iov, edm::ValidityInterval &iValidity) override
Definition: SiStripApvSimulationParametersESProducer.cc:86
edm::ESProducer::setWhatProduced
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
edm::ValidityInterval
Definition: ValidityInterval.h:28
SiStripApvSimulationParametersESSource::rBinEdgesTID_
std::vector< float > rBinEdgesTID_
Definition: SiStripApvSimulationParametersESProducer.cc:31
ESProducer.h
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
DDAxes::x
SiStripApvSimulationParametersRcd
Definition: SiStripCondDataRecords.h:58
edm::EventSetupRecordIntervalFinder
Definition: EventSetupRecordIntervalFinder.h:33
SiStripApvSimulationParametersESSource::baselineFiles_TIB_
std::vector< edm::FileInPath > baselineFiles_TIB_
Definition: SiStripApvSimulationParametersESProducer.cc:23
edm::eventsetup::EventSetupRecordKey
Definition: EventSetupRecordKey.h:30
SiStripApvSimulationParametersESSource::baseline_nBins_
unsigned int baseline_nBins_
Definition: SiStripApvSimulationParametersESProducer.cc:26
edm::FileInPath
Definition: FileInPath.h:61
SiStripApvSimulationParametersESSource::zBinEdges_
std::vector< float > zBinEdges_
Definition: SiStripApvSimulationParametersESProducer.cc:30
SiStripApvSimulationParametersESSource::baselineFiles_TOB_
std::vector< edm::FileInPath > baselineFiles_TOB_
Definition: SiStripApvSimulationParametersESProducer.cc:22
SiStripApvSimulationParametersESSource::baselineFiles_TEC_
std::vector< edm::FileInPath > baselineFiles_TEC_
Definition: SiStripApvSimulationParametersESProducer.cc:25
SiStripApvSimulationParametersESSource
Definition: SiStripApvSimulationParametersESProducer.cc:10
edm::IOVSyncValue
Definition: IOVSyncValue.h:31
DEFINE_FWK_EVENTSETUP_SOURCE
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:91
EventSetupRecordIntervalFinder.h
SourceFactory.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
SiStripCondDataRecords.h
edm::IOVSyncValue::endOfTime
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
SiStripApvSimulationParametersESSource::SiStripApvSimulationParametersESSource
SiStripApvSimulationParametersESSource(const edm::ParameterSet &conf)
Definition: SiStripApvSimulationParametersESProducer.cc:38
createfilelist.int
int
Definition: createfilelist.py:10
value
Definition: value.py:1
AlCaHarvesting_cff.record
record
Definition: AlCaHarvesting_cff.py:42
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SiStripApvSimulationParametersESSource::rBinEdgesTEC_
std::vector< float > rBinEdgesTEC_
Definition: SiStripApvSimulationParametersESProducer.cc:32
relativeConstraints.value
value
Definition: relativeConstraints.py:53
Exception
Definition: hltDiff.cc:245
SiStripApvSimulationParametersESSource::~SiStripApvSimulationParametersESSource
~SiStripApvSimulationParametersESSource() override
Definition: SiStripApvSimulationParametersESProducer.cc:13
SiStripApvSimulationParametersESSource::puBinEdges_
std::vector< float > puBinEdges_
Definition: SiStripApvSimulationParametersESProducer.cc:29
SiStripApvSimulationParametersESSource::makeLayerParameters
SiStripApvSimulationParameters::LayerParameters makeLayerParameters(const std::string &apvBaselinesFileName, const std::vector< float > &rzBinEdges) const
Definition: SiStripApvSimulationParametersESProducer.cc:92
SiStripApvSimulationParameters.h
edm::IOVSyncValue::beginOfTime
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88
PhysicsTools::Calibration::Histogram3D
Definition: Histogram3D.h:24
edm::ESProducer
Definition: ESProducer.h:104
ParameterSet.h
mps_splice.line
line
Definition: mps_splice.py:76
SiStripApvSimulationParametersESSource::baseline_max_
float baseline_max_
Definition: SiStripApvSimulationParametersESProducer.cc:28