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