CMS 3D CMS Logo

L1CaloHcalScaleConfigOnlineProd.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1EmEtScaleOnlineProd
4 // Class: L1EmEtScaleOnlineProd
5 //
13 //
14 // Original Author: Werner Man-Li Sun
15 // Created: Tue Sep 16 22:43:22 CEST 2008
16 //
17 //
18 
19 // system include files
20 
21 // user include files
30 
31 #include <cmath>
32 #include <iostream>
33 #include <iomanip>
34 
35 //
36 // class declaration
37 //
38 
39 class L1CaloHcalScaleConfigOnlineProd : public L1ConfigOnlineProdBase<L1CaloHcalScaleRcd, L1CaloHcalScale> {
40 public:
43 
44  std::unique_ptr<L1CaloHcalScale> produce(const L1CaloHcalScaleRcd& iRecord) override;
45 
46  std::unique_ptr<L1CaloHcalScale> newObject(const std::string& objectKey) override;
47 
48 private:
51  typedef std::vector<double> RCTdecompression;
52  std::vector<RCTdecompression> hcaluncomp;
53 
54  // HcaluLUTTPGCoder* tpgCoder;// = new HcaluLUTTPGCoder();
55 
57 
58  // ----------member data ---------------------------
59 };
60 
61 //
62 // constants, enums and typedefs
63 //
64 
65 //
66 // static data member definitions
67 //
68 
69 //
70 // constructors and destructor
71 //
73  : L1ConfigOnlineProdBase<L1CaloHcalScaleRcd, L1CaloHcalScale>(iConfig), theTrigTowerGeometry(nullptr) {
75 }
76 
78  // do anything here that needs to be done at desctruction time
79  // (e.g. close files, deallocate resources etc.)
80 
81  if (caloTPG != nullptr)
82  delete caloTPG;
83 }
84 
85 std::unique_ptr<L1CaloHcalScale> L1CaloHcalScaleConfigOnlineProd::newObject(const std::string& objectKey) {
86  assert(theTrigTowerGeometry != nullptr);
87 
88  edm::LogInfo("L1CaloHcalScaleConfigOnlineProd") << "object Key " << objectKey;
89 
90  if (objectKey == "NULL" || objectKey.empty()) { // return default blank ecal scale
91  return std::make_unique<L1CaloHcalScale>(0);
92  }
93  if (objectKey == "IDENTITY") { // return identity ecal scale
94  return std::make_unique<L1CaloHcalScale>(1);
95  }
96 
97  std::vector<unsigned int> analyticalLUT(1024, 0);
98  std::vector<unsigned int> identityLUT(1024, 0);
99 
100  // Compute compression LUT
101  for (unsigned int i = 0; i < 1024; i++) {
102  analyticalLUT[i] = (unsigned int)(sqrt(14.94 * log(1. + i / 14.94) * i) + 0.5);
103  identityLUT[i] = std::min(i, 0xffu);
104  }
105 
106  hcaluncomp.clear();
107  for (int i = 0; i < 4176; i++) {
108  RCTdecompression decompressionTable(256, 0);
109  hcaluncomp.push_back(decompressionTable);
110  }
111 
112  std::vector<std::string> mainStrings;
113  mainStrings.push_back("HCAL_LUT_METADATA");
114  mainStrings.push_back("HCAL_LUT_CHAN_DATA");
115 
116  // ~~~~~~~~~ Cut values ~~~~~~~~~
117 
118  std::vector<std::string> metaStrings;
119  metaStrings.push_back("RCTLSB");
120  metaStrings.push_back("NOMINAL_GAIN");
121 
122  l1t::OMDSReader::QueryResults paramResults =
123  m_omdsReader.basicQueryView(metaStrings,
124  "CMS_HCL_HCAL_COND",
125  "V_HCAL_LUT_METADATA_V1",
126  "V_HCAL_LUT_METADATA_V1.TAG_NAME",
127  m_omdsReader.basicQuery("HCAL_LUT_METADATA",
128  "CMS_RCT",
129  "HCAL_SCALE_KEY",
130  "HCAL_SCALE_KEY.HCAL_TAG",
131  m_omdsReader.singleAttribute(objectKey)));
132 
133  if (paramResults.queryFailed() || (paramResults.numberRows() != 1)) // check query successful
134  {
135  edm::LogError("L1-O2O") << "Problem with L1CaloHcalScale key. Unable to find lutparam dat table";
136  return std::unique_ptr<L1CaloHcalScale>();
137  }
138 
139  double hcalLSB, nominal_gain;
140  paramResults.fillVariable("RCTLSB", hcalLSB);
141  paramResults.fillVariable("NOMINAL_GAIN", nominal_gain);
142 
143  float rctlsb = hcalLSB;
144 
145  l1t::OMDSReader::QueryResults chanKey = m_omdsReader.basicQuery("HCAL_LUT_CHAN_DATA",
146  "CMS_RCT",
147  "HCAL_SCALE_KEY",
148  "HCAL_SCALE_KEY.HCAL_TAG",
149  m_omdsReader.singleAttribute(objectKey));
150 
151  //coral::AttributeList myresult;
152  // myresult.extend(
153 
154  std::string schemaName("CMS_HCL_HCAL_COND");
155  coral::ISchema& schema = m_omdsReader.dbSession().coralSession().schema(schemaName);
156  coral::IQuery* query = schema.newQuery();
157  ;
158 
159  std::vector<std::string> channelStrings;
160  channelStrings.push_back("IPHI");
161  channelStrings.push_back("IETA");
162  channelStrings.push_back("DEPTH");
163  channelStrings.push_back("LUT_GRANULARITY");
164  channelStrings.push_back("OUTPUT_LUT_THRESHOLD");
165  channelStrings.push_back("OBJECTNAME");
166 
167  std::vector<std::string>::const_iterator it = channelStrings.begin();
168  std::vector<std::string>::const_iterator end = channelStrings.end();
169  for (; it != end; ++it) {
170  query->addToOutputList(*it);
171  }
172 
173  std::string ob = "OBJECTNAME";
174  coral::AttributeList myresult;
175  myresult.extend("IPHI", typeid(int));
176  myresult.extend("IETA", typeid(int));
177  myresult.extend("DEPTH", typeid(int));
178  myresult.extend("LUT_GRANULARITY", typeid(int));
179  myresult.extend("OUTPUT_LUT_THRESHOLD", typeid(int));
180  myresult.extend(ob, typeid(std::string)); //, typeid(std::string));
181 
182  query->defineOutput(myresult);
183 
184  query->addToTableList("V_HCAL_LUT_CHAN_DATA_V1");
185 
186  query->setCondition("V_HCAL_LUT_CHAN_DATA_V1.TAG_NAME = :" + chanKey.columnNames().front(),
187  chanKey.attributeLists().front());
188 
189  coral::ICursor& cursor = query->execute();
190 
191  // when the query goes out of scope.
192  std::vector<coral::AttributeList> atts;
193  while (cursor.next()) {
194  atts.push_back(cursor.currentRow());
195  };
196 
197  delete query;
198 
199  l1t::OMDSReader::QueryResults chanResults(channelStrings, atts);
200  if (chanResults.queryFailed() || (chanResults.numberRows() == 0)) // check query successful
201  {
202  edm::LogError("L1-O2O") << "Problem with L1CaloHcalScale key. Unable to find lutparam dat table nrows"
203  << chanResults.numberRows();
204  return std::unique_ptr<L1CaloHcalScale>();
205  }
206 
207  chanResults.attributeLists();
208  for (int i = 0; i < chanResults.numberRows(); ++i) {
210  chanResults.fillVariableFromRow("OBJECTNAME", i, objectName);
211  // int
212  if (objectName == "HcalTrigTowerDetId") { //trig tower
213  int ieta, iphi, depth, lutGranularity, threshold;
214 
215  chanResults.fillVariableFromRow("LUT_GRANULARITY", i, lutGranularity);
216  chanResults.fillVariableFromRow("IPHI", i, iphi);
217  chanResults.fillVariableFromRow("IETA", i, ieta);
218  chanResults.fillVariableFromRow("DEPTH", i, depth);
219  chanResults.fillVariableFromRow("OUTPUT_LUT_THRESHOLD", i, threshold);
220 
221  unsigned int outputLut[1024];
222 
223  const int tp_version = depth / 10;
224  uint32_t lutId = caloTPG->getOutputLUTId(ieta, iphi, tp_version);
225 
226  double eta_low = 0., eta_high = 0.;
227  theTrigTowerGeometry->towerEtaBounds(ieta, tp_version, eta_low, eta_high);
228  double cosh_ieta = fabs(cosh((eta_low + eta_high) / 2.));
229 
230  if (!caloTPG->HTvalid(ieta, iphi, tp_version))
231  continue;
232  double factor = 0.;
233  if (abs(ieta) >= theTrigTowerGeometry->firstHFTower(tp_version))
234  factor = rctlsb;
235  else
236  factor = nominal_gain / cosh_ieta * lutGranularity;
237  for (int k = 0; k < threshold; ++k)
238  outputLut[k] = 0;
239 
240  for (unsigned int k = threshold; k < 1024; ++k)
241  outputLut[k] = (abs(ieta) < theTrigTowerGeometry->firstHFTower(tp_version)) ? analyticalLUT[k] : identityLUT[k];
242 
243  // tpg - compressed value
244  unsigned int tpg = outputLut[0];
245 
246  int low = 0;
247 
248  for (unsigned int k = 0; k < 1024; ++k) {
249  if (outputLut[k] != tpg) {
250  unsigned int mid = (low + k) / 2;
251  hcaluncomp[lutId][tpg] = (tpg == 0 ? low : factor * mid);
252  low = k;
253  tpg = outputLut[k];
254  }
255  }
256  hcaluncomp[lutId][tpg] = factor * low;
257  }
258  }
259 
260  auto hcalScale = std::make_unique<L1CaloHcalScale>(0);
261 
262  // XXX L1CaloHcalScale is only setup for 2x3 TP
263  const int tp_version = 0;
264  for (unsigned short ieta = 1; ieta <= L1CaloHcalScale::nBinEta; ++ieta) {
265  for (int pos = 0; pos <= 1; pos++) {
266  for (unsigned short irank = 0; irank < L1CaloHcalScale::nBinRank; ++irank) {
267  int zside = (int)pow(-1, pos);
268  int nphi = 0;
269  double etvalue = 0.;
270 
271  for (int iphi = 1; iphi <= 72; iphi++) {
272  if (!caloTPG->HTvalid(ieta, iphi, tp_version))
273  continue;
274  uint32_t lutId = caloTPG->getOutputLUTId(ieta, iphi, tp_version);
275  nphi++;
276  etvalue += (double)hcaluncomp[lutId][irank];
277 
278  } // phi
279  if (nphi > 0)
280  etvalue /= nphi;
281 
282  hcalScale->setBin(irank, ieta, zside, etvalue);
283 
284  } // rank
285  } // zside
286  } // eta
287 
288  std::stringstream s;
289  s << std::setprecision(10);
290  hcalScale->print(s);
291  edm::LogInfo("L1CaloHcalScaleConfigOnlineProd") << s.str();
292  // ------------ method called to produce the data ------------
293  return hcalScale;
294 }
295 
296 std::unique_ptr<L1CaloHcalScale> L1CaloHcalScaleConfigOnlineProd::produce(const L1CaloHcalScaleRcd& iRecord) {
298  iRecord.getRecord<CaloGeometryRecord>().get(pG);
300 
302 }
303 
304 //define this as a plug-in
l1t::OMDSReader::QueryResults
Definition: OMDSReader.h:49
edm::eventsetup::DependentRecordImplementation::getRecord
const DepRecordT getRecord() const
Definition: DependentRecordImplementation.h:51
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
CaloTPGTranscoder_cfi.nominal_gain
nominal_gain
Definition: CaloTPGTranscoder_cfi.py:25
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
L1CaloHcalScale
Definition: L1CaloHcalScale.h:28
OMDSReader.h
L1ConfigOnlineProdBase< L1CaloHcalScaleRcd, L1CaloHcalScale >::m_omdsReader
l1t::OMDSReader m_omdsReader
Definition: L1ConfigOnlineProdBase.h:65
min
T min(T a, T b)
Definition: MathUtil.h:58
ecaldqm::zside
int zside(DetId const &)
Definition: EcalDQMCommonUtils.cc:189
CaloGeometryRecord
Definition: CaloGeometryRecord.h:30
pos
Definition: PixelAliasList.h:18
edm::LogInfo
Definition: MessageLogger.h:254
L1CaloHcalScale::nBinRank
static const unsigned short nBinRank
Definition: L1CaloHcalScale.h:31
cms::cuda::assert
assert(be >=bs)
l1t::OMDSReader::singleAttribute
const QueryResults singleAttribute(const T &data) const
Definition: OMDSReader.h:259
L1ConfigOnlineProdBase
Definition: L1ConfigOnlineProdBase.h:52
end
#define end
Definition: vmac.h:39
L1CaloHcalScaleConfigOnlineProd::hcaluncomp
std::vector< RCTdecompression > hcaluncomp
Definition: L1CaloHcalScaleConfigOnlineProd.cc:52
L1CaloHcalScale.h
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
L1CaloHcalScaleConfigOnlineProd::ttDetId
HcalTrigTowerDetId * ttDetId
Definition: L1CaloHcalScaleConfigOnlineProd.cc:56
nphi
const int nphi
Definition: CMTRawAnalyzer.h:424
alignCSCRings.s
s
Definition: alignCSCRings.py:92
CaloTPGTranscoderULUT::HTvalid
virtual bool HTvalid(const int ieta, const int iphi, const int version) const
Definition: CaloTPGTranscoderULUT.cc:198
l1t::OMDSReader::QueryResults::fillVariableFromRow
bool fillVariableFromRow(const std::string &columnName, int rowNumber, T &outputVariable) const
Definition: OMDSReader.h:279
query
Definition: query.py:1
l1t::OMDSReader::QueryResults::fillVariable
bool fillVariable(const std::string &columnName, T &outputVariable) const
Definition: OMDSReader.h:274
l1t::OMDSReader::QueryResults::columnNames
const std::vector< std::string > & columnNames() const
Definition: OMDSReader.h:57
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
L1CaloHcalScaleConfigOnlineProd::L1CaloHcalScaleConfigOnlineProd
L1CaloHcalScaleConfigOnlineProd(const edm::ParameterSet &iConfig)
Definition: L1CaloHcalScaleConfigOnlineProd.cc:72
edm::ESHandle
Definition: DTSurvey.h:22
L1CaloHcalScaleConfigOnlineProd
Definition: L1CaloHcalScaleConfigOnlineProd.cc:39
DQMScaleToClient_cfi.factor
factor
Definition: DQMScaleToClient_cfi.py:8
dqmdumpme.k
k
Definition: dqmdumpme.py:60
CaloTPGTranscoderULUT.h
LEDCalibrationChannels.depth
depth
Definition: LEDCalibrationChannels.py:65
CaloGeometryRecord.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
L1CaloHcalScaleConfigOnlineProd::RCTdecompression
std::vector< double > RCTdecompression
Definition: L1CaloHcalScaleConfigOnlineProd.cc:51
CaloTPGTranscoderULUT::getOutputLUTId
virtual int getOutputLUTId(const HcalTrigTowerDetId &id) const
Definition: CaloTPGTranscoderULUT.cc:207
L1CaloHcalScale::nBinEta
static const unsigned short nBinEta
Definition: L1CaloHcalScale.h:32
LEDCalibrationChannels.ieta
ieta
Definition: LEDCalibrationChannels.py:63
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
createfilelist.int
int
Definition: createfilelist.py:10
HcalTrigTowerGeometry::firstHFTower
int firstHFTower(int version) const
Definition: HcalTrigTowerGeometry.h:18
cond::persistency::Session::coralSession
coral::ISessionProxy & coralSession()
Definition: Session.cc:218
L1CaloHcalScaleConfigOnlineProd::caloTPG
CaloTPGTranscoderULUT * caloTPG
Definition: L1CaloHcalScaleConfigOnlineProd.cc:50
l1t::OMDSReader::QueryResults::numberRows
int numberRows() const
Definition: OMDSReader.h:60
HcalTrigTowerGeometry.h
l1t::OMDSReader::basicQuery
const QueryResults basicQuery(const std::vector< std::string > &columnNames, const std::string &schemaName, const std::string &tableName, const std::string &conditionLHS="", const QueryResults conditionRHS=QueryResults(), const std::string &conditionRHSName="")
Definition: OMDSReader.cc:75
HcalTrigTowerGeometry
Definition: HcalTrigTowerGeometry.h:10
get
#define get
L1CaloHcalScaleConfigOnlineProd::produce
std::unique_ptr< L1CaloHcalScale > produce(const L1CaloHcalScaleRcd &iRecord) override
Definition: L1CaloHcalScaleConfigOnlineProd.cc:296
L1CaloHcalScaleRcd.h
L1CaloHcalScaleConfigOnlineProd::theTrigTowerGeometry
const HcalTrigTowerGeometry * theTrigTowerGeometry
Definition: L1CaloHcalScaleConfigOnlineProd.cc:49
DEFINE_FWK_EVENTSETUP_MODULE
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
l1t::OMDSReader::QueryResults::queryFailed
bool queryFailed() const
Definition: OMDSReader.h:59
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
contentValuesFiles.query
query
Definition: contentValuesFiles.py:38
l1t::OMDSReader::basicQueryView
const QueryResults basicQueryView(const std::vector< std::string > &columnNames, const std::string &schemaName, const std::string &viewName, const std::string &conditionLHS="", const QueryResults conditionRHS=QueryResults(), const std::string &conditionRHSName="")
Definition: OMDSReader.cc:158
l1t::DataManager::dbSession
cond::persistency::Session dbSession()
Definition: DataManager.h:26
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
L1CaloHcalScaleConfigOnlineProd::~L1CaloHcalScaleConfigOnlineProd
~L1CaloHcalScaleConfigOnlineProd() override
Definition: L1CaloHcalScaleConfigOnlineProd.cc:77
remoteMonitoring_LED_IterMethod_cfg.threshold
threshold
Definition: remoteMonitoring_LED_IterMethod_cfg.py:426
HcalTrigTowerGeometry::towerEtaBounds
void towerEtaBounds(int ieta, int version, double &eta1, double &eta2) const
where this tower begins and ends in eta
Definition: HcalTrigTowerGeometry.cc:237
CaloTPGTranscoderULUT
Definition: CaloTPGTranscoderULUT.h:18
LaserClient_cfi.low
low
Definition: LaserClient_cfi.py:52
L1ConfigOnlineProdBase.h
l1t::OMDSReader::QueryResults::attributeLists
const std::vector< coral::AttributeList > & attributeLists() const
Definition: OMDSReader.h:58
L1CaloHcalScaleRcd
Definition: L1CaloHcalScaleRcd.h:13
L1CaloHcalScaleConfigOnlineProd::newObject
std::unique_ptr< L1CaloHcalScale > newObject(const std::string &objectKey) override
Definition: L1CaloHcalScaleConfigOnlineProd.cc:85
summarizeEdmComparisonLogfiles.objectName
objectName
Definition: summarizeEdmComparisonLogfiles.py:105
HcalTrigTowerDetId
Definition: HcalTrigTowerDetId.h:14