CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
20 // system include files
21 
22 // user include files
31 
32 #include <cmath>
33 #include <iostream>
34 #include <iomanip>
35 
36 //
37 // class declaration
38 //
39 
41  public L1ConfigOnlineProdBase< L1CaloHcalScaleRcd, L1CaloHcalScale > {
42  public:
45 
46  boost::shared_ptr< L1CaloHcalScale > produce(const L1CaloHcalScaleRcd& iRecord) override ;
47 
48  virtual boost::shared_ptr< L1CaloHcalScale > newObject(
49  const std::string& objectKey ) override ;
50 
51  private:
52 
56  typedef std::vector<double> RCTdecompression;
57  std::vector<RCTdecompression> hcaluncomp;
58 
59  // HcaluLUTTPGCoder* tpgCoder;// = new HcaluLUTTPGCoder();
60 
61 
63 
64  // ----------member data ---------------------------
65 };
66 
67 //
68 // constants, enums and typedefs
69 //
70 
71 //
72 // static data member definitions
73 //
74 
75 //
76 // constructors and destructor
77 //
79  const edm::ParameterSet& iConfig)
81  theTrigTowerGeometry( nullptr )
82 {
83  hcalScale = new L1CaloHcalScale(0);
85 }
86 
87 
89 {
90  // do anything here that needs to be done at desctruction time
91  // (e.g. close files, deallocate resources etc.)
92 
93  if(caloTPG != 0)
94  delete caloTPG;
95 }
96 
97 boost::shared_ptr< L1CaloHcalScale >
99 {
100  assert( theTrigTowerGeometry != nullptr );
101 
102  using namespace edm::es;
103 
104  edm::LogInfo("L1CaloHcalScaleConfigOnlineProd") << "object Key " << objectKey;
105 
106  if(objectKey == "NULL" || objectKey == "") // return default blank ecal scale
107  return boost::shared_ptr< L1CaloHcalScale >( hcalScale );
108  if(objectKey == "IDENTITY"){ // return identity ecal scale
109 
110  delete hcalScale;
111 
112  hcalScale = new L1CaloHcalScale(1);
113 
114  return boost::shared_ptr< L1CaloHcalScale >( hcalScale);
115  }
116 
117  std::vector<unsigned int> analyticalLUT(1024, 0);
118  std::vector<unsigned int> identityLUT(1024, 0);
119 
120  // Compute compression LUT
121  for (unsigned int i=0; i < 1024; i++) {
122  analyticalLUT[i] = (unsigned int)(sqrt(14.94*log(1.+i/14.94)*i) + 0.5);
123  identityLUT[i] = std::min(i,0xffu);
124  }
125 
126  hcaluncomp.clear();
127  for (int i = 0; i < 4176; i++){
128  RCTdecompression decompressionTable(256,0);
129  hcaluncomp.push_back(decompressionTable);
130  }
131 
132 
133 
134  std::vector < std::string > mainStrings;
135  mainStrings.push_back("HCAL_LUT_METADATA");
136  mainStrings.push_back("HCAL_LUT_CHAN_DATA");
137 
138  // ~~~~~~~~~ Cut values ~~~~~~~~~
139 
140 
141  std::vector< std::string > metaStrings ;
142  metaStrings.push_back("RCTLSB");
143  metaStrings.push_back("NOMINAL_GAIN");
144 
145 
146  l1t::OMDSReader::QueryResults paramResults =
147  m_omdsReader.basicQueryView( metaStrings,
148  "CMS_HCL_HCAL_COND",
149  "V_HCAL_LUT_METADATA_V1",
150  "V_HCAL_LUT_METADATA_V1.TAG_NAME",
152  "HCAL_LUT_METADATA",
153  "CMS_RCT",
154  "HCAL_SCALE_KEY",
155  "HCAL_SCALE_KEY.HCAL_TAG",
156  m_omdsReader.singleAttribute(objectKey)));
157 
158 
159 
160 
161  if( paramResults.queryFailed()
162  || (paramResults.numberRows()!=1) ) // check query successful
163  {
164  edm::LogError( "L1-O2O" ) << "Problem with L1CaloHcalScale key. Unable to find lutparam dat table" ;
165  return boost::shared_ptr< L1CaloHcalScale >() ;
166  }
167 
168  double hcalLSB, nominal_gain;
169  paramResults.fillVariable("RCTLSB",hcalLSB);
170  paramResults.fillVariable("NOMINAL_GAIN",nominal_gain);
171 
172  float rctlsb = hcalLSB;
173 
174 
175 
177  "HCAL_LUT_CHAN_DATA",
178  "CMS_RCT",
179  "HCAL_SCALE_KEY",
180  "HCAL_SCALE_KEY.HCAL_TAG",
181  m_omdsReader.singleAttribute(objectKey));
182 
183  //coral::AttributeList myresult;
184  // myresult.extend(
185 
186 
187  std::string schemaName("CMS_HCL_HCAL_COND");
188  coral::ISchema& schema = m_omdsReader.dbSession().coralSession().schema( schemaName ) ;
189  coral::IQuery* query = schema.newQuery(); ;
190 
191 
192  std::vector< std::string > channelStrings;
193  channelStrings.push_back("IPHI");
194  channelStrings.push_back("IETA");
195  channelStrings.push_back("LUT_GRANULARITY");
196  channelStrings.push_back("OUTPUT_LUT_THRESHOLD");
197  channelStrings.push_back("OBJECTNAME");
198 
199 
200 
201  std::vector< std::string >::const_iterator it = channelStrings.begin() ;
202  std::vector< std::string >::const_iterator end = channelStrings.end() ;
203  for( ; it != end ; ++it )
204  {
205  query->addToOutputList( *it ) ;
206  }
207 
208  std::string ob = "OBJECTNAME";
209  coral::AttributeList myresult;
210  myresult.extend("IPHI", typeid(int));
211  myresult.extend("IETA", typeid(int));
212  myresult.extend("LUT_GRANULARITY", typeid(int));
213  myresult.extend("OUTPUT_LUT_THRESHOLD", typeid(int));
214  myresult.extend( ob,typeid(std::string));//, typeid(std::string));
215 
216  query->defineOutput( myresult );
217 
218  query->addToTableList( "V_HCAL_LUT_CHAN_DATA_V1");
219 
220  query->setCondition(
221  "V_HCAL_LUT_CHAN_DATA_V1.TAG_NAME = :" + chanKey.columnNames().front(),
222  chanKey.attributeLists().front());
223 
224  coral::ICursor& cursor = query->execute();
225 
226  // when the query goes out of scope.
227  std::vector<coral::AttributeList> atts;
228  while (cursor.next()) {
229  atts.push_back(cursor.currentRow());
230  };
231 
232  delete query;
233 
234  l1t::OMDSReader::QueryResults chanResults(channelStrings,atts);
235  if( chanResults.queryFailed()
236  || (chanResults.numberRows()==0) ) // check query successful
237  {
238  edm::LogError( "L1-O2O" ) << "Problem with L1CaloHcalScale key. Unable to find lutparam dat table nrows" << chanResults.numberRows() ;
239  return boost::shared_ptr< L1CaloHcalScale >() ;
240  }
241 
242 
243 
244  chanResults.attributeLists();
245  for(int i = 0; i < chanResults.numberRows() ; ++i){
247  chanResults.fillVariableFromRow("OBJECTNAME",i, objectName);
248  // int
249  if(objectName == "HcalTrigTowerDetId") { //trig tower
250  int ieta, iphi, lutGranularity, threshold;
251 
252 
253  chanResults.fillVariableFromRow("LUT_GRANULARITY",i,lutGranularity);
254  chanResults.fillVariableFromRow("IPHI",i,iphi);
255  chanResults.fillVariableFromRow("IETA",i,ieta);
256  chanResults.fillVariableFromRow("OUTPUT_LUT_THRESHOLD",i,threshold);
257 
258 
259  unsigned int outputLut[1024];
260 
261  uint32_t lutId = caloTPG->getOutputLUTId(ieta,iphi);
262 
263  double eta_low = 0., eta_high = 0.;
264  const int version_of_hcal_TPs = 0;
265  theTrigTowerGeometry->towerEtaBounds(ieta,version_of_hcal_TPs, eta_low,eta_high);
266  double cosh_ieta = fabs(cosh((eta_low + eta_high)/2.));
267 
268 
269  if (!caloTPG->HTvalid(ieta, iphi)) continue;
270  double factor = 0.;
271  if (abs(ieta) >= theTrigTowerGeometry->firstHFTower(version_of_hcal_TPs))
272  factor = rctlsb;
273  else
274  factor = nominal_gain / cosh_ieta * lutGranularity;
275  for (int k = 0; k < threshold; ++k)
276  outputLut[k] = 0;
277 
278  for (unsigned int k = threshold; k < 1024; ++k)
279  outputLut[k] = (abs(ieta) < theTrigTowerGeometry->firstHFTower(version_of_hcal_TPs)) ? analyticalLUT[k] : identityLUT[k];
280 
281 
282  // tpg - compressed value
283  unsigned int tpg = outputLut[0];
284 
285  int low = 0;
286 
287  for (unsigned int k = 0; k < 1024; ++k){
288  if (outputLut[k] != tpg){
289  unsigned int mid = (low + k)/2;
290  hcaluncomp[lutId][tpg] = (tpg == 0 ? low : factor * mid);
291  low = k;
292  tpg = outputLut[k];
293  }
294  }
295  hcaluncomp[lutId][tpg] = factor * low;
296  }
297  }
298 
299 
300 
301  for( unsigned short ieta = 1 ; ieta <= L1CaloHcalScale::nBinEta; ++ieta ){
302  for(int pos = 0; pos <=1; pos++){
303  for( unsigned short irank = 0 ; irank < L1CaloHcalScale::nBinRank; ++irank ){
304 
305 
306 
307  int zside = (int) pow(-1,pos);
308  int nphi = 0;
309  double etvalue = 0.;
310 
311 
312  for(int iphi = 1; iphi<=72; iphi++){
313  if(!caloTPG->HTvalid(ieta, iphi))
314  continue;
315  uint32_t lutId = caloTPG->getOutputLUTId(ieta,iphi);
316  nphi++;
317  etvalue += (double) hcaluncomp[lutId][irank];
318 
319  } // phi
320  if (nphi > 0) etvalue /= nphi;
321 
322  hcalScale->setBin(irank, ieta, zside, etvalue);
323 
324  } // rank
325  } // zside
326  }// eta
327 
328  std::stringstream s;
329  s << std::setprecision(10);
330  hcalScale->print(s);
331  edm::LogInfo("L1CaloHcalScaleConfigOnlineProd") << s.str();
332 // ------------ method called to produce the data ------------
333  return boost::shared_ptr< L1CaloHcalScale >( hcalScale );
334 
335 }
336 
337 boost::shared_ptr< L1CaloHcalScale >
339 {
341  iRecord.getRecord<CaloGeometryRecord>().get(pG);
343 
345 }
346 
347 //define this as a plug-in
int i
Definition: DBlmapReader.cc:9
virtual boost::shared_ptr< L1CaloHcalScale > newObject(const std::string &objectKey) override
const QueryResults singleAttribute(const T &data) const
Definition: OMDSReader.h:296
tuple schema
Definition: dataDML.py:2334
L1CaloHcalScaleConfigOnlineProd(const edm::ParameterSet &iConfig)
boost::shared_ptr< L1CaloHcalScale > produce(const L1CaloHcalScaleRcd &iRecord) override
assert(m_qm.get())
void setBin(unsigned short rank, unsigned short eta, short etaSign, double et)
set scale element; use this to create non-linear scales
void towerEtaBounds(int ieta, int version, double &eta1, double &eta2) const
where this tower begins and ends in eta
int zside(DetId const &)
#define nullptr
const HcalTrigTowerGeometry * theTrigTowerGeometry
T sqrt(T t)
Definition: SSEVec.h:18
bool fillVariableFromRow(const std::string &columnName, int rowNumber, T &outputVariable) const
Definition: OMDSReader.h:320
virtual int getOutputLUTId(const HcalTrigTowerDetId &id) const
static const unsigned short nBinRank
const std::vector< coral::AttributeList > & attributeLists() const
Definition: OMDSReader.h:65
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:86
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define end
Definition: vmac.h:37
T min(T a, T b)
Definition: MathUtil.h:58
void print(std::ostream &s) const
virtual bool HTvalid(const int ieta, const int iphi) const
std::vector< RCTdecompression > hcaluncomp
T const * product() const
Definition: ESHandle.h:86
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:192
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
coral::ISessionProxy & coralSession()
Definition: Session.cc:207
cond::persistency::Session dbSession()
Definition: DataManager.h:32
static const unsigned short nBinEta
tuple query
Definition: o2o.py:269
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
int firstHFTower(int version) const