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.7 2012/08/28 14:18:14 yana 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 
84  int maxDepthHB = 2;
85  int maxDepthHE = 3;
86  if( iConfig.exists( "hcalTopologyConstants" ))
87  {
88  const edm::ParameterSet hcalTopoConsts = iConfig.getParameter<edm::ParameterSet>( "hcalTopologyConstants" );
90  mode = (HcalTopologyMode::Mode) parser.parseString(hcalTopoConsts.getParameter<std::string>("mode"));
91  maxDepthHB = hcalTopoConsts.getParameter<int>("maxDepthHB");
92  maxDepthHE = hcalTopoConsts.getParameter<int>("maxDepthHE");
93  }
94 
95  theTrigTowerGeometry = new HcalTrigTowerGeometry( new HcalTopology( mode, maxDepthHB, maxDepthHE ));
96 }
97 
98 
100 {
101  // do anything here that needs to be done at desctruction time
102  // (e.g. close files, deallocate resources etc.)
103 
104  if(caloTPG != 0)
105  delete caloTPG;
106 }
107 
108 boost::shared_ptr< L1CaloHcalScale >
110 {
111  using namespace edm::es;
112 
113  std:: cout << "object Key " << objectKey <<std::endl <<std::flush;
114 
115  if(objectKey == "NULL" || objectKey == "") // return default blank ecal scale
116  return boost::shared_ptr< L1CaloHcalScale >( hcalScale );
117  if(objectKey == "IDENTITY"){ // return identity ecal scale
118 
119  delete hcalScale;
120 
121  hcalScale = new L1CaloHcalScale(1);
122 
123  return boost::shared_ptr< L1CaloHcalScale >( hcalScale);
124  }
125 
126  std::vector<unsigned int> analyticalLUT(1024, 0);
127  std::vector<unsigned int> identityLUT(1024, 0);
128 
129  // Compute compression LUT
130  for (unsigned int i=0; i < 1024; i++) {
131  analyticalLUT[i] = (unsigned int)(sqrt(14.94*log(1.+i/14.94)*i) + 0.5);
132  identityLUT[i] = std::min(i,0xffu);
133  }
134 
135  hcaluncomp.clear();
136  for (int i = 0; i < 4176; i++){
137  RCTdecompression decompressionTable(256,0);
138  hcaluncomp.push_back(decompressionTable);
139  }
140 
141 
142 
143  std::vector < std::string > mainStrings;
144  mainStrings.push_back("HCAL_LUT_METADATA");
145  mainStrings.push_back("HCAL_LUT_CHAN_DATA");
146 
147  // ~~~~~~~~~ Cut values ~~~~~~~~~
148 
149 
150  std::vector< std::string > metaStrings ;
151  metaStrings.push_back("RCTLSB");
152  metaStrings.push_back("NOMINAL_GAIN");
153 
154 
155  l1t::OMDSReader::QueryResults paramResults =
156  m_omdsReader.basicQueryView( metaStrings,
157  "CMS_HCL_HCAL_COND",
158  "V_HCAL_LUT_METADATA_V1",
159  "V_HCAL_LUT_METADATA_V1.TAG_NAME",
161  "HCAL_LUT_METADATA",
162  "CMS_RCT",
163  "HCAL_SCALE_KEY",
164  "HCAL_SCALE_KEY.HCAL_TAG",
165  m_omdsReader.singleAttribute(objectKey)));
166 
167 
168 
169 
170  if( paramResults.queryFailed()
171  || (paramResults.numberRows()!=1) ) // check query successful
172  {
173  edm::LogError( "L1-O2O" ) << "Problem with L1CaloHcalScale key. Unable to find lutparam dat table" ;
174  return boost::shared_ptr< L1CaloHcalScale >() ;
175  }
176 
177  double hcalLSB, nominal_gain;
178  paramResults.fillVariable("RCTLSB",hcalLSB);
179  paramResults.fillVariable("NOMINAL_GAIN",nominal_gain);
180 
181  float rctlsb = hcalLSB;
182 
183 
184 
186  "HCAL_LUT_CHAN_DATA",
187  "CMS_RCT",
188  "HCAL_SCALE_KEY",
189  "HCAL_SCALE_KEY.HCAL_TAG",
190  m_omdsReader.singleAttribute(objectKey));
191 
192  //coral::AttributeList myresult;
193  // myresult.extend(
194 
195 
196  std::string schemaName("CMS_HCL_HCAL_COND");
197  coral::ISchema& schema = m_omdsReader.dbSession()->schema( schemaName ) ;
198  coral::IQuery* query = schema.newQuery(); ;
199 
200 
201  std::vector< std::string > channelStrings;
202  channelStrings.push_back("IPHI");
203  channelStrings.push_back("IETA");
204  channelStrings.push_back("LUT_GRANULARITY");
205  channelStrings.push_back("OUTPUT_LUT_THRESHOLD");
206  channelStrings.push_back("OBJECTNAME");
207 
208 
209 
210  std::vector< std::string >::const_iterator it = channelStrings.begin() ;
211  std::vector< std::string >::const_iterator end = channelStrings.end() ;
212  for( ; it != end ; ++it )
213  {
214  query->addToOutputList( *it ) ;
215  }
216 
217  std::string ob = "OBJECTNAME";
218  coral::AttributeList myresult;
219  myresult.extend("IPHI", typeid(int));
220  myresult.extend("IETA", typeid(int));
221  myresult.extend("LUT_GRANULARITY", typeid(int));
222  myresult.extend("OUTPUT_LUT_THRESHOLD", typeid(int));
223  myresult.extend( ob,typeid(std::string));//, typeid(std::string));
224 
225  query->defineOutput( myresult );
226 
227  query->addToTableList( "V_HCAL_LUT_CHAN_DATA_V1");
228 
229  query->setCondition(
230  "V_HCAL_LUT_CHAN_DATA_V1.TAG_NAME = :" + chanKey.columnNames().front(),
231  chanKey.attributeLists().front());
232 
233  coral::ICursor& cursor = query->execute();
234 
235  // when the query goes out of scope.
236  std::vector<coral::AttributeList> atts;
237  while (cursor.next()) {
238  atts.push_back(cursor.currentRow());
239  };
240 
241  delete query;
242 
243  l1t::OMDSReader::QueryResults chanResults(channelStrings,atts);
244  if( chanResults.queryFailed()
245  || (chanResults.numberRows()==0) ) // check query successful
246  {
247  edm::LogError( "L1-O2O" ) << "Problem with L1CaloHcalScale key. Unable to find lutparam dat table nrows" << chanResults.numberRows() ;
248  return boost::shared_ptr< L1CaloHcalScale >() ;
249  }
250 
251 
252 
253  chanResults.attributeLists();
254  for(int i = 0; i < chanResults.numberRows() ; ++i){
256  chanResults.fillVariableFromRow("OBJECTNAME",i, objectName);
257  // int
258  if(objectName == "HcalTrigTowerDetId") { //trig tower
259  int ieta, iphi, lutGranularity, threshold;
260 
261 
262  chanResults.fillVariableFromRow("LUT_GRANULARITY",i,lutGranularity);
263  chanResults.fillVariableFromRow("IPHI",i,iphi);
264  chanResults.fillVariableFromRow("IETA",i,ieta);
265  chanResults.fillVariableFromRow("OUTPUT_LUT_THRESHOLD",i,threshold);
266 
267 
268  unsigned int outputLut[1024];
269 
270  uint32_t lutId = caloTPG->getOutputLUTId(ieta,iphi);
271 
272  double eta_low = 0., eta_high = 0.;
273  theTrigTowerGeometry->towerEtaBounds(ieta,eta_low,eta_high);
274  double cosh_ieta = fabs(cosh((eta_low + eta_high)/2.));
275 
276 
277  if (!caloTPG->HTvalid(ieta, iphi)) continue;
278  double factor = 0.;
279  if (abs(ieta) >= theTrigTowerGeometry->firstHFTower())
280  factor = rctlsb;
281  else
282  factor = nominal_gain / cosh_ieta * lutGranularity;
283  for (int k = 0; k < threshold; ++k)
284  outputLut[k] = 0;
285 
286  for (unsigned int k = threshold; k < 1024; ++k)
287  outputLut[k] = (abs(ieta) < theTrigTowerGeometry->firstHFTower()) ? analyticalLUT[k] : identityLUT[k];
288 
289 
290  // tpg - compressed value
291  unsigned int tpg = outputLut[0];
292 
293  int low = 0;
294 
295  for (unsigned int k = 0; k < 1024; ++k){
296  if (outputLut[k] != tpg){
297  unsigned int mid = (low + k)/2;
298  hcaluncomp[lutId][tpg] = (tpg == 0 ? low : factor * mid);
299  low = k;
300  tpg = outputLut[k];
301  }
302  }
303  hcaluncomp[lutId][tpg] = factor * low;
304  }
305  }
306 
307 
308 
309  for( unsigned short ieta = 1 ; ieta <= L1CaloHcalScale::nBinEta; ++ieta ){
310  for(int pos = 0; pos <=1; pos++){
311  for( unsigned short irank = 0 ; irank < L1CaloHcalScale::nBinRank; ++irank ){
312 
313 
314 
315  int zside = (int) pow(-1,pos);
316  int nphi = 0;
317  double etvalue = 0.;
318 
319 
320  for(int iphi = 1; iphi<=72; iphi++){
321  if(!caloTPG->HTvalid(ieta, iphi))
322  continue;
323  uint32_t lutId = caloTPG->getOutputLUTId(ieta,iphi);
324  nphi++;
325  etvalue += (double) hcaluncomp[lutId][irank];
326 
327  } // phi
328  if (nphi > 0) etvalue /= nphi;
329 
330  hcalScale->setBin(irank, ieta, zside, etvalue);
331 
332  } // rank
333  } // zside
334  }// eta
335 
336  std::cout << std::setprecision(10);
338 // ------------ method called to produce the data ------------
339  return boost::shared_ptr< L1CaloHcalScale >( hcalScale );
340 
341 }
342 //define this as a plug-in
T getParameter(std::string const &) const
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)
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
#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: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
#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: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