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