CMS 3D CMS Logo

ESTrivialConditionRetriever.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <vector>
4 
8 
10 
11 //#include "DataFormats/Provenance/interface/Timestamp.h"
12 
14 
15 using namespace edm;
16 
18  // initilize parameters used to produce cond DB objects
19  adcToGeVLowConstant_ = ps.getUntrackedParameter<double>("adcToGeVLowConstant", 1.0);
20  adcToGeVHighConstant_ = ps.getUntrackedParameter<double>("adcToGeVHighConstant", 1.0);
21 
22  intercalibConstantMean_ = ps.getUntrackedParameter<double>("intercalibConstantMean", 1.0);
23  intercalibConstantSigma_ = ps.getUntrackedParameter<double>("intercalibConstantSigma", 0.0);
24 
25  // intercalibErrorMean_ = ps.getUntrackedParameter<double>("IntercalibErrorMean",0.0);
26 
27  ESpedMean_ = ps.getUntrackedParameter<double>("ESpedMean", 200.);
28  ESpedRMS_ = ps.getUntrackedParameter<double>("ESpedRMS", 1.00);
29 
30  getWeightsFromFile_ = ps.getUntrackedParameter<bool>("getWeightsFromFile", false);
31 
32  std::string path = "CalibCalorimetry/EcalTrivialCondModules/data/";
33  std::string weightType;
34  std::ostringstream str;
35 
36  weightType = str.str();
37 
38  amplWeightsFile_ = ps.getUntrackedParameter<std::string>("amplWeightsFile", path + "ampWeightsES" + weightType);
39 
40  // default weights for MGPA shape after pedestal subtraction
41  getWeightsFromConfiguration(ps);
42 
43  producedESPedestals_ = ps.getUntrackedParameter<bool>("producedESPedestals", true);
44  producedESWeights_ = ps.getUntrackedParameter<bool>("producedESWeights", true);
45 
46  producedESADCToGeVConstant_ = ps.getUntrackedParameter<bool>("producedESADCToGeVConstant", true);
47 
48  verbose_ = ps.getUntrackedParameter<int>("verbose", 0);
49 
50  //Tell Producer what we produce
51  //setWhatproduce(this);
52  if (producedESPedestals_)
54 
55  if (producedESWeights_) {
58  }
59 
60  if (producedESADCToGeVConstant_)
62 
63  // intercalibration constants
64  producedESIntercalibConstants_ = ps.getUntrackedParameter<bool>("producedESIntercalibConstants", true);
65  intercalibConstantsFile_ = ps.getUntrackedParameter<std::string>("intercalibConstantsFile", "");
66 
67  if (producedESIntercalibConstants_) { // user asks to produce constants
68  if (intercalibConstantsFile_.empty()) { // if file provided read constants
69  // setWhatProduced (this, &ESTrivialConditionRetriever::getIntercalibConstantsFromConfiguration ) ;
70  // } else { // set all constants to 1. or smear as specified by user
72  }
73  findingRecord<ESIntercalibConstantsRcd>();
74  }
75 
76  // intercalibration constants errors
77  /* producedESIntercalibErrors_ = ps.getUntrackedParameter<bool>("producedESIntercalibErrors",true);
78  intercalibErrorsFile_ = ps.getUntrackedParameter<std::string>("intercalibErrorsFile","") ;
79 
80  if (producedESIntercalibErrors_) { // user asks to produce constants
81  if(intercalibErrorsFile_ != "") { // if file provided read constants
82  setWhatProduced (this, &ESTrivialConditionRetriever::getIntercalibErrorsFromConfiguration ) ;
83  } else { // set all constants to 1. or smear as specified by user
84  setWhatProduced (this, &ESTrivialConditionRetriever::produceESIntercalibErrors ) ;
85  }
86  findingRecord<ESIntercalibErrorsRcd> () ;
87  }
88  */
89 
90  // channel status
91  producedESChannelStatus_ = ps.getUntrackedParameter<bool>("producedESChannelStatus", true);
92  channelStatusFile_ = ps.getUntrackedParameter<std::string>("channelStatusFile", "");
93 
94  if (producedESChannelStatus_) {
95  if (!channelStatusFile_.empty()) { // if file provided read channel map
97  } else { // set all channels to working -- FIXME might be changed
99  }
100  findingRecord<ESChannelStatusRcd>();
101  }
102 
103  //Tell Finder what records we find
104  if (producedESPedestals_)
105  findingRecord<ESPedestalsRcd>();
106 
107  if (producedESWeights_) {
108  findingRecord<ESWeightStripGroupsRcd>();
109  findingRecord<ESTBWeightsRcd>();
110  }
111 
112  if (producedESADCToGeVConstant_)
113  findingRecord<ESADCToGeVConstantRcd>();
114 }
115 
117 
118 //
119 // member functions
120 //
122  const edm::IOVSyncValue& iTime,
123  edm::ValidityInterval& oValidity) {
124  if (verbose_ >= 1)
125  std::cout << "ESTrivialConditionRetriever::setIntervalFor(): record key = " << rk.name()
126  << "\ttime: " << iTime.time().value() << std::endl;
127  //For right now, we will just use an infinite interval of validity
129 }
130 
131 //produce methods
133  std::cout << " producing pedestals" << std::endl;
134  auto peds = std::make_unique<ESPedestals>();
135  ESPedestals::Item ESitem;
136  ESitem.mean = ESpedMean_;
137  ESitem.rms = ESpedRMS_;
138 
139  for (int istrip = ESDetId::ISTRIP_MIN; istrip <= ESDetId::ISTRIP_MAX; istrip++) {
140  for (int ix = ESDetId::IX_MIN; ix <= ESDetId::IX_MAX; ix++) {
141  for (int iy = ESDetId::IY_MIN; iy <= ESDetId::IY_MAX; iy++) {
142  for (int iplane = 1; iplane <= 2; iplane++) {
143  for (int izeta = -1; izeta <= 1; ++izeta) {
144  if (izeta == 0)
145  continue;
146  try {
147  //ESDetId Plane iplane Zside izeta
148  ESDetId aPositiveId(istrip, ix, iy, iplane, izeta);
149  peds->insert(std::make_pair(aPositiveId.rawId(), ESitem));
150  } catch (cms::Exception& e) {
151  }
152  }
153  }
154  }
155  }
156  }
157  //return std::unique_ptr<ESPedestals>( peds );
158  std::cout << " produced pedestals" << std::endl;
159  return peds;
160 }
161 
162 std::unique_ptr<ESWeightStripGroups> ESTrivialConditionRetriever::produceESWeightStripGroups(
163  const ESWeightStripGroupsRcd&) {
164  auto xtalGroups = std::make_unique<ESWeightStripGroups>();
165  ESStripGroupId defaultGroupId(1);
166  std::cout << "entering produce weight groups" << std::endl;
167  for (int istrip = ESDetId::ISTRIP_MIN; istrip <= ESDetId::ISTRIP_MAX; istrip++) {
168  for (int ix = ESDetId::IX_MIN; ix <= ESDetId::IX_MAX; ix++) {
169  for (int iy = ESDetId::IY_MIN; iy <= ESDetId::IY_MAX; iy++) {
170  for (int iplane = 1; iplane <= 2; iplane++) {
171  for (int izeta = -1; izeta <= 1; ++izeta) {
172  if (izeta == 0)
173  continue;
174  try {
175  //ESDetId Plane iplane Zside izeta
176  ESDetId anESId(istrip, ix, iy, iplane, izeta);
177  // xtalGroups->setValue(ebid.rawId(), ESStripGroupId(ieta) ); // define rings in eta
178  xtalGroups->setValue(anESId.rawId(), defaultGroupId); // define rings in eta
179  } catch (cms::Exception& e) {
180  }
181  }
182  }
183  }
184  }
185  }
186  std::cout << "done with produce weight groups" << std::endl;
187 
188  return xtalGroups;
189 }
190 
191 std::unique_ptr<ESIntercalibConstants> ESTrivialConditionRetriever::produceESIntercalibConstants(
192  const ESIntercalibConstantsRcd&) {
193  auto ical = std::make_unique<ESIntercalibConstants>();
194  std::cout << "entring produce intercalib " << std::endl;
195 
196  for (int istrip = ESDetId::ISTRIP_MIN; istrip <= ESDetId::ISTRIP_MAX; istrip++) {
197  for (int ix = ESDetId::IX_MIN; ix <= ESDetId::IX_MAX; ix++) {
198  for (int iy = ESDetId::IY_MIN; iy <= ESDetId::IY_MAX; iy++) {
199  for (int iplane = 1; iplane <= 2; iplane++) {
200  for (int izeta = -1; izeta <= 1; ++izeta) {
201  if (izeta == 0)
202  continue;
203  try {
204  //ESDetId Plane iplane Zside izeta
205  ESDetId anESId(istrip, ix, iy, iplane, izeta);
206  double r = (double)std::rand() / (double(RAND_MAX) + double(1));
207  ical->setValue(anESId.rawId(), intercalibConstantMean_ + r * intercalibConstantSigma_);
208  } catch (cms::Exception& e) {
209  }
210  }
211  }
212  }
213  }
214  }
215  std::cout << "done produce intercalib" << std::endl;
216 
217  return ical;
218 }
219 
220 std::unique_ptr<ESADCToGeVConstant> ESTrivialConditionRetriever::produceESADCToGeVConstant(
221  const ESADCToGeVConstantRcd&) {
222  return std::make_unique<ESADCToGeVConstant>(adcToGeVLowConstant_, adcToGeVHighConstant_);
223 }
224 
226  // create weights for the test-beam
227  auto tbwgt = std::make_unique<ESTBWeights>();
228 
229  int igrp = 1;
230  ESWeightSet wgt = ESWeightSet(amplWeights_);
231  // ESWeightSet::ESWeightMatrix& mat1 = wgt.getWeights();
232 
233  tbwgt->setValue(igrp, wgt);
234 
235  return tbwgt;
236 }
237 
240 
241  if (!getWeightsFromFile_) {
242  // vampl.set(1.);
243 
244  // amplwgtv[0]= ps.getUntrackedParameter< std::vector<double> >("amplWeights", vampl);
245  } else if (getWeightsFromFile_) {
246  edm::LogInfo("ESTrivialConditionRetriever")
247  << "Reading amplitude weights from file " << edm::FileInPath(amplWeightsFile_).fullPath().c_str();
248  std::ifstream amplFile(edm::FileInPath(amplWeightsFile_).fullPath().c_str());
249  while (!amplFile.eof()) {
250  for (int j = 0; j < 2; ++j) {
251  std::vector<float> vec(3);
252  for (int k = 0; k < 3; ++k) {
253  float ww;
254  amplFile >> ww;
255  vec[k] = ww;
256  }
257  // vampl.putRow(vec);
258  }
259  }
260  } else {
261  //Not supported
262  edm::LogError("ESTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
263  throw cms::Exception("WrongConfig");
264  }
265 
266  amplWeights_ = ESWeightSet(vampl);
267 }
268 
269 // --------------------------------------------------------------------------------
270 
272  const ESChannelStatusRcd&) {
273  auto ecalStatus = std::make_unique<ESChannelStatus>();
274 
275  // start by setting all statuses to 0
276 
277  for (int istrip = ESDetId::ISTRIP_MIN; istrip <= ESDetId::ISTRIP_MAX; istrip++) {
278  for (int ix = ESDetId::IX_MIN; ix <= ESDetId::IX_MAX; ix++) {
279  for (int iy = ESDetId::IY_MIN; iy <= ESDetId::IY_MAX; iy++) {
280  for (int iplane = 1; iplane <= 2; iplane++) {
281  for (int izeta = -1; izeta <= 1; ++izeta) {
282  if (izeta == 0)
283  continue;
284  try {
285  //ESDetId Plane iplane Zside izeta
286  ESDetId anESId(istrip, ix, iy, iplane, izeta);
287  // xtalGroups->setValue(ebid.rawId(), ESStripGroupId(ieta) ); // define rings in eta
288  ecalStatus->setValue(anESId, 0);
289  } catch (cms::Exception& e) {
290  }
291  }
292  }
293  }
294  }
295  }
296 
297  // overwrite the statuses which are in the file
298 
299  edm::LogInfo("ESTrivialConditionRetriever")
300  << "Reading channel statuses from file " << edm::FileInPath(channelStatusFile_).fullPath().c_str();
301  std::ifstream statusFile(edm::FileInPath(channelStatusFile_).fullPath().c_str());
302  if (!statusFile.good()) {
303  edm::LogError("ESTrivialConditionRetriever") << "*** Problems opening file: " << channelStatusFile_;
304  throw cms::Exception("Cannot open ECAL channel status file");
305  }
306 
307  std::string ESSubDet;
309  int hashIndex(0);
310  int status(0);
311 
312  while (!statusFile.eof()) {
313  statusFile >> ESSubDet;
314  if (ESSubDet != std::string("ES")) {
315  std::getline(statusFile, str);
316  continue;
317  } else {
318  statusFile >> hashIndex >> status;
319  }
320  // std::cout << ESSubDet << " " << hashIndex << " " << status;
321 
322  if (ESSubDet == std::string("ES")) {
323  ESDetId esid = ESDetId::unhashIndex(hashIndex);
324  ecalStatus->setValue(esid, status);
325  } else {
326  edm::LogError("ESTrivialConditionRetriever") << " *** " << ESSubDet << " is not ES ";
327  }
328  }
329  // the file is supposed to be in the form
330  // ES hashed_index status
331  // ES 132332 1 --> higher than 0 means bad
332 
333  statusFile.close();
334  return ecalStatus;
335 }
336 
338  auto ical = std::make_unique<ESChannelStatus>();
339  for (int istrip = ESDetId::ISTRIP_MIN; istrip <= ESDetId::ISTRIP_MAX; istrip++) {
340  for (int ix = ESDetId::IX_MIN; ix <= ESDetId::IX_MAX; ix++) {
341  for (int iy = ESDetId::IY_MIN; iy <= ESDetId::IY_MAX; iy++) {
342  for (int iplane = 1; iplane <= 2; iplane++) {
343  for (int izeta = -1; izeta <= 1; ++izeta) {
344  if (izeta == 0)
345  continue;
346  try {
347  //ESDetId Plane iplane Zside izeta
348  ESDetId anESId(istrip, ix, iy, iplane, izeta);
349  // xtalGroups->setValue(ebid.rawId(), ESStripGroupId(ieta) ); // define rings in eta
350  ical->setValue(anESId, 0);
351  } catch (cms::Exception& e) {
352  }
353  }
354  }
355  }
356  }
357  }
358 
359  return ical;
360 }
361 
362 // --------------------------------------------------------------------------------
ESPedestalsRcd
Definition: ESPedestalsRcd.h:5
ESTrivialConditionRetriever::getChannelStatusFromConfiguration
virtual std::unique_ptr< ESChannelStatus > getChannelStatusFromConfiguration(const ESChannelStatusRcd &)
Definition: ESTrivialConditionRetriever.cc:271
ESTrivialConditionRetriever.h
MessageLogger.h
ESDetId::ISTRIP_MIN
static const int ISTRIP_MIN
Definition: ESDetId.h:68
ESTrivialConditionRetriever::produceESChannelStatus
virtual std::unique_ptr< ESChannelStatus > produceESChannelStatus(const ESChannelStatusRcd &)
Definition: ESTrivialConditionRetriever.cc:337
ESChannelStatusRcd
Definition: ESChannelStatusRcd.h:5
mps_update.status
status
Definition: mps_update.py:69
contentValuesFiles.fullPath
fullPath
Definition: contentValuesFiles.py:64
edm
HLT enums.
Definition: AlignableModifier.h:19
ESADCToGeVConstantRcd
Definition: ESADCToGeVConstantRcd.h:5
gather_cfg.cout
cout
Definition: gather_cfg.py:144
ESTBWeightsRcd
Definition: ESTBWeightsRcd.h:5
edm::ValidityInterval
Definition: ValidityInterval.h:28
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::Timestamp::value
TimeValue_t value() const
Definition: Timestamp.h:45
ESDetId
Definition: ESDetId.h:15
ESDetId.h
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::eventsetup::EventSetupRecordKey
Definition: EventSetupRecordKey.h:30
ESDetId::IY_MIN
static const int IY_MIN
Definition: ESDetId.h:65
edm::FileInPath
Definition: FileInPath.h:64
ESTrivialConditionRetriever::ESTrivialConditionRetriever
ESTrivialConditionRetriever(const edm::ParameterSet &pset)
Definition: ESTrivialConditionRetriever.cc:17
ESPedestal
Definition: ESPedestals.h:8
str
#define str(s)
Definition: TestProcessor.cc:51
ESStripGroupId
Definition: ESStripGroupId.h:6
edm::eventsetup::EventSetupRecordKey::name
const char * name() const
Definition: EventSetupRecordKey.h:46
dqmdumpme.k
k
Definition: dqmdumpme.py:60
ESTrivialConditionRetriever::produceESIntercalibConstants
virtual std::unique_ptr< ESIntercalibConstants > produceESIntercalibConstants(const ESIntercalibConstantsRcd &)
Definition: ESTrivialConditionRetriever.cc:191
ESIntercalibConstantsRcd
Definition: ESIntercalibConstantsRcd.h:5
edm::IOVSyncValue
Definition: IOVSyncValue.h:31
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ESTrivialConditionRetriever::produceESPedestals
virtual std::unique_ptr< ESPedestals > produceESPedestals(const ESPedestalsRcd &)
Definition: ESTrivialConditionRetriever.cc:132
edm::ParameterSet
Definition: ParameterSet.h:47
edm::IOVSyncValue::endOfTime
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
ESDetId::ISTRIP_MAX
static const int ISTRIP_MAX
Definition: ESDetId.h:69
ESTrivialConditionRetriever::setIntervalFor
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
Definition: ESTrivialConditionRetriever.cc:121
ESTrivialConditionRetriever::produceESADCToGeVConstant
virtual std::unique_ptr< ESADCToGeVConstant > produceESADCToGeVConstant(const ESADCToGeVConstantRcd &)
Definition: ESTrivialConditionRetriever.cc:220
ESTrivialConditionRetriever::getWeightsFromConfiguration
void getWeightsFromConfiguration(const edm::ParameterSet &ps)
Definition: ESTrivialConditionRetriever.cc:238
ESPedestal::rms
float rms
Definition: ESPedestals.h:17
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
ESDetId::IY_MAX
static const int IY_MAX
Definition: ESDetId.h:67
alignCSCRings.r
r
Definition: alignCSCRings.py:93
ESPedestal::mean
float mean
Definition: ESPedestals.h:16
ESWeightSet
Definition: ESWeightSet.h:10
edm::IOVSyncValue::time
const Timestamp & time() const
Definition: IOVSyncValue.h:42
ESWeightSet::ESWeightMatrix
math::Matrix< 2, 3 >::type ESWeightMatrix
Definition: ESWeightSet.h:12
ESWeightStripGroupsRcd
Definition: ESWeightStripGroupsRcd.h:5
cond::ValidityInterval
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:17
ESTrivialConditionRetriever::produceESTBWeights
virtual std::unique_ptr< ESTBWeights > produceESTBWeights(const ESTBWeightsRcd &)
Definition: ESTrivialConditionRetriever.cc:225
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
ESDetId::unhashIndex
static ESDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: ESDetId.cc:32
ESTrivialConditionRetriever::~ESTrivialConditionRetriever
~ESTrivialConditionRetriever() override
Definition: ESTrivialConditionRetriever.cc:116
Exception
Definition: hltDiff.cc:246
edm::IOVSyncValue::beginOfTime
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88
Exception.h
ESDetId::IX_MIN
static const int IX_MIN
Definition: ESDetId.h:64
ESTrivialConditionRetriever::produceESWeightStripGroups
virtual std::unique_ptr< ESWeightStripGroups > produceESWeightStripGroups(const ESWeightStripGroupsRcd &)
Definition: ESTrivialConditionRetriever.cc:162
cms::Exception
Definition: Exception.h:70
ESDetId::IX_MAX
static const int IX_MAX
Definition: ESDetId.h:66
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
ParameterSet.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:163
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37