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