CMS 3D CMS Logo

L1RCTParametersOnlineProd.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1RCTParametersOnlineProd
4 // Class: L1RCTParametersOnlineProd
5 //
13 //
14 // Original Author: Werner Man-Li Sun
15 // Created: Tue Sep 16 22:43:22 CEST 2008
16 //
17 //
18 
19 // system include files
20 
21 // user include files
23 
26 
27 // #include "FWCore/Framework/interface/HCTypeTagTemplate.h"
28 // #include "FWCore/Framework/interface/EventSetup.h"
29 
30 //
31 // class declaration
32 //
33 
34 class L1RCTParametersOnlineProd : public L1ConfigOnlineProdBase<L1RCTParametersRcd, L1RCTParameters> {
35 public:
37  ~L1RCTParametersOnlineProd() override;
38 
39  std::unique_ptr<L1RCTParameters> newObject(const std::string& objectKey) override;
40 
41  void fillScaleFactors(const l1t::OMDSReader::QueryResults& results, std::vector<double>& output, int nfactor = 1);
42  /*
43 
44  void fillScaleFactors(
45  const l1t::OMDSReader::QueryResults& results,
46  std::vector< std::vector< double > >& output ) ;
47  */
48 private:
49  // ----------member data ---------------------------
50 };
51 
52 //
53 // constants, enums and typedefs
54 //
55 
56 //
57 // static data member definitions
58 //
59 
60 //
61 // constructors and destructor
62 //
65  //the following line is needed to tell the framework what
66  // data is being produced
67 
68  //now do what ever other initialization is needed
69 }
70 
72  // do anything here that needs to be done at desctruction time
73  // (e.g. close files, deallocate resources etc.)
74 }
75 
76 std::unique_ptr<L1RCTParameters> L1RCTParametersOnlineProd::newObject(const std::string& objectKey) {
77  std::string rctSchema = "CMS_RCT";
78  const l1t::OMDSReader::QueryResults paremKeyResults = m_omdsReader.singleAttribute(objectKey);
79 
80  // ~~~~~~~~~ Cut values ~~~~~~~~~
81 
82  // select egamma_lsb, jetmet_lsb, e_min_for_fg_cut, e_max_for_fg_cut,
83  // h_ove r_e_cut, e_min_for_h_over_e_cut, e_max_for_h_over_e_cut,
84  // h_min_for_h_over_e_cut, e_activity_cut, h_activity_cut,
85  // eic_isolation_threshold, jsc_quiet_threshold_barrel,
86  // jsc_quiet_threshold_endcap, noisevetohb, noisevetoheplus,
87  // noisevetoheminus from parem_conf where parem_conf.parem_key =
88  // (select rct_parameter from rct_conf where rct_conf.rct_key =
89  // 'rct_cmssw_def');
90 
91  std::vector<std::string> queryStrings;
92  queryStrings.push_back("EGAMMA_LSB");
93  queryStrings.push_back("JETMET_LSB");
94  queryStrings.push_back("E_MIN_FOR_FG_CUT");
95  queryStrings.push_back("E_MAX_FOR_FG_CUT");
96  queryStrings.push_back("H_OVER_E_CUT");
97  queryStrings.push_back("E_MIN_FOR_H_OVER_E_CUT");
98  queryStrings.push_back("E_MAX_FOR_H_OVER_E_CUT");
99  queryStrings.push_back("H_MIN_FOR_H_OVER_E_CUT");
100  queryStrings.push_back("E_ACTIVITY_CUT");
101  queryStrings.push_back("H_ACTIVITY_CUT");
102  queryStrings.push_back("EIC_ISOLATION_THRESHOLD");
103  queryStrings.push_back("JSC_QUIET_THRESHOLD_BARREL");
104  queryStrings.push_back("JSC_QUIET_THRESHOLD_ENDCAP");
105  queryStrings.push_back("NOISEVETOHB");
106  queryStrings.push_back("NOISEVETOHEPLUS");
107  queryStrings.push_back("NOISEVETOHEMINUS");
108  queryStrings.push_back("USECORR");
109  l1t::OMDSReader::QueryResults paremResults =
110  m_omdsReader.basicQuery(queryStrings, rctSchema, "PAREM_CONF", "PAREM_CONF.PAREM_KEY", paremKeyResults);
111 
112  if (paremResults.queryFailed() || paremResults.numberRows() != 1) // check query successful
113  {
114  edm::LogError("L1-O2O") << "Problem with L1RCTParameters key.";
115  return std::unique_ptr<L1RCTParameters>();
116  }
117 
120  double eActivityCut, hActivityCut;
121  double jscQuietThreshBarrel, jscQuietThreshEndcap, eicIsolationThreshold;
123 
124  paremResults.fillVariable("EGAMMA_LSB", eGammaLSB);
125  paremResults.fillVariable("JETMET_LSB", jetMETLSB);
126  paremResults.fillVariable("E_MIN_FOR_FG_CUT", eMinForFGCut);
127  paremResults.fillVariable("E_MAX_FOR_FG_CUT", eMaxForFGCut);
128  paremResults.fillVariable("H_OVER_E_CUT", hOeCut);
129  paremResults.fillVariable("E_MIN_FOR_H_OVER_E_CUT", eMinForHoECut);
130  paremResults.fillVariable("E_MAX_FOR_H_OVER_E_CUT", eMaxForHoECut);
131  paremResults.fillVariable("H_MIN_FOR_H_OVER_E_CUT", hMinForHoECut);
132  paremResults.fillVariable("E_ACTIVITY_CUT", eActivityCut);
133  paremResults.fillVariable("H_ACTIVITY_CUT", hActivityCut);
134  paremResults.fillVariable("JSC_QUIET_THRESHOLD_BARREL", jscQuietThreshBarrel);
135  paremResults.fillVariable("JSC_QUIET_THRESHOLD_ENDCAP", jscQuietThreshEndcap);
136  paremResults.fillVariable("EIC_ISOLATION_THRESHOLD", eicIsolationThreshold);
137  paremResults.fillVariable("NOISEVETOHB", noiseVetoHB);
138  paremResults.fillVariable("NOISEVETOHEPLUS", noiseVetoHEplus);
139  paremResults.fillVariable("NOISEVETOHEMINUS", noiseVetoHEminus);
140  paremResults.fillVariable("USECORR", useCorr);
141  // std::cout << "eGammaLSB = " << eGammaLSB << std::endl ;
142  // std::cout << "jetMETLSB = " << jetMETLSB << std::endl ;
143  // std::cout << "eMinForFGCut = " << eMinForFGCut << std::endl ;
144  // std::cout << "eMaxForFGCut = " << eMaxForFGCut << std::endl ;
145  // std::cout << "hOeCut = " << hOeCut << std::endl ;
146  // std::cout << "eMinForHoECut = " << eMinForHoECut << std::endl ;
147  // std::cout << "eMaxForHoECut = " << eMaxForHoECut << std::endl ;
148  // std::cout << "hMinForHoECut = " << hMinForHoECut << std::endl ;
149  // std::cout << "eActivityCut = " << eActivityCut << std::endl ;
150  // std::cout << "hActivityCut = " << hActivityCut << std::endl ;
151  // std::cout << "eicIsolationThreshold = " << eicIsolationThreshold << std::endl ;
152  // std::cout << "jscQuietThreshBarrel = " << jscQuietThreshBarrel << std::endl ;
153  // std::cout << "jscQuietThreshEndcap = " << jscQuietThreshEndcap << std::endl ;
154  // std::cout << "noiseVetoHB = " << noiseVetoHB << std::endl ;
155  // std::cout << "noiseVetoHEplus = " << noiseVetoHEplus << std::endl ;
156  // std::cout << "noiseVetoHEminus = " << noiseVetoHEminus << std::endl ;
157 
158  // ~~~~~~~~~ EGamma ECAL scale factors ~~~~~~~~~
159 
160  // select scalefactor, fk_rct_eta from egamma_ecal_scalefactor where
161  // egamma_ecal_scalefactor.fk_version =
162  // (select egamma_ecal from parem_conf where parem_conf.parem_key =
163  // (select rct_parameter from rct_conf where rct_conf.rct_key=
164  // 'rct_cmssw_def'));
165 
166  std::vector<std::string> scaleFactorQueryStrings;
167  scaleFactorQueryStrings.push_back("SCALEFACTOR");
168  scaleFactorQueryStrings.push_back("FK_RCT_ETA");
169 
171  scaleFactorQueryStrings,
172  rctSchema,
173  "EGAMMA_ECAL_SCALEFACTOR",
174  "EGAMMA_ECAL_SCALEFACTOR.FK_VERSION",
175  m_omdsReader.basicQuery("EGAMMA_ECAL", rctSchema, "PAREM_CONF", "PAREM_CONF.PAREM_KEY", paremKeyResults));
176 
177  if (egammaEcalResults.queryFailed()) // check query successful
178  {
179  edm::LogError("L1-O2O") << "Problem with EgammaEcal key.";
180  return std::unique_ptr<L1RCTParameters>();
181  }
182 
183  // std::cout << "egammaEcal " ;
184  std::vector<double> egammaEcalScaleFactors;
185  fillScaleFactors(egammaEcalResults, egammaEcalScaleFactors);
186 
187  // ~~~~~~~~~ EGamma HCAL scale factors ~~~~~~~~~
188 
189  // select scalefactor, fk_rct_eta from egamma_hcal_scalefactor where
190  // egamma_hcal_scalefactor.fk_version =
191  // (select egamma_hcal from parem_conf where parem_conf.parem_key =
192  // (select rct_parameter from rct_conf where rct_conf.rct_key=
193  // 'rct_cmssw_def'));
194 
196  scaleFactorQueryStrings,
197  rctSchema,
198  "EGAMMA_HCAL_SCALEFACTOR",
199  "EGAMMA_HCAL_SCALEFACTOR.FK_VERSION",
200  m_omdsReader.basicQuery("EGAMMA_HCAL", rctSchema, "PAREM_CONF", "PAREM_CONF.PAREM_KEY", paremKeyResults));
201 
202  if (egammaHcalResults.queryFailed()) // check query successful
203  {
204  edm::LogError("L1-O2O") << "Problem with EgammaHcal key.";
205  return std::unique_ptr<L1RCTParameters>();
206  }
207 
208  // std::cout << "egammaHcal " ;
209  std::vector<double> egammaHcalScaleFactors;
210  fillScaleFactors(egammaHcalResults, egammaHcalScaleFactors);
211 
212  // ~~~~~~~~~ JetMET ECAL scale factors ~~~~~~~~~
213 
214  // select scalefactor, fk_rct_eta from jetmet_ecal_scalefactor where
215  // jetmet_ecal_scalefactor.fk_version =
216  // (select jetmet_ecal from parem_conf where parem_conf.parem_key =
217  // (select rct_parameter from rct_conf where rct_conf.rct_key=
218  // 'rct_cmssw_def'));
219 
221  scaleFactorQueryStrings,
222  rctSchema,
223  "JETMET_ECAL_SCALEFACTOR",
224  "JETMET_ECAL_SCALEFACTOR.FK_VERSION",
225  m_omdsReader.basicQuery("JETMET_ECAL", rctSchema, "PAREM_CONF", "PAREM_CONF.PAREM_KEY", paremKeyResults));
226 
227  if (jetmetEcalResults.queryFailed()) // check query successful
228  {
229  edm::LogError("L1-O2O") << "Problem with JetmetEcal key.";
230  return std::unique_ptr<L1RCTParameters>();
231  }
232 
233  // std::cout << "jetmetEcal " ;
234  std::vector<double> jetmetEcalScaleFactors;
235  fillScaleFactors(jetmetEcalResults, jetmetEcalScaleFactors);
236 
237  // ~~~~~~~~~ JetMET HCAL scale factors ~~~~~~~~~
238 
239  // select scalefactor, fk_rct_eta from jetmet_hcal_scalefactor where
240  // jetmet_hcal_scalefactor.fk_version =
241  // (select jetmet_hcal from parem_conf where parem_conf.parem_key =
242  // (select rct_parameter from rct_conf where rct_conf.rct_key=
243  // 'rct_cmssw_def'));
244 
246  scaleFactorQueryStrings,
247  rctSchema,
248  "JETMET_HCAL_SCALEFACTOR",
249  "JETMET_HCAL_SCALEFACTOR.FK_VERSION",
250  m_omdsReader.basicQuery("JETMET_HCAL", rctSchema, "PAREM_CONF", "PAREM_CONF.PAREM_KEY", paremKeyResults));
251 
252  if (jetmetHcalResults.queryFailed()) // check query successful
253  {
254  edm::LogError("L1-O2O") << "Problem with JetmetHcal key.";
255  return std::unique_ptr<L1RCTParameters>();
256  }
257 
258  // std::cout << "jetmetHcal " ;
259  std::vector<double> jetmetHcalScaleFactors;
260  fillScaleFactors(jetmetHcalResults, jetmetHcalScaleFactors);
261 
262  //Lindsay variables
263 
264  /*
265  std::vector< std::vector< double > > hcalCalibScaleFactors ;
266  std::vector< std::vector< double > > hcalCalibHighScaleFactors ;
267  std::vector< std::vector< double > > ecalCalibScaleFactors ;
268  std::vector< std::vector< double > > crossTermsScaleFactors ;
269  */
270  std::vector<double> lowHoverE_smear, highHoverE_smear;
271  std::vector<double> hcalCalibScaleFactors, ecalCalibScaleFactors;
272  std::vector<double> hcalCalibHighScaleFactors, crossTermsScaleFactors;
273 
274  if (useCorr) { //lindsay corrections
275 
276  std::vector<std::string> scaleFactorQuery3Strings;
277  scaleFactorQuery3Strings.push_back("SCALEFACTOR");
278  scaleFactorQuery3Strings.push_back("SF2");
279  scaleFactorQuery3Strings.push_back("SF3");
280  scaleFactorQuery3Strings.push_back("FK_RCT_ETA");
281 
283  scaleFactorQuery3Strings,
284  rctSchema,
285  "HCAL_CALIB_FACTOR",
286  "HCAL_CALIB_FACTOR.VERSION",
288  "HCAL_CALIB_VERSION", rctSchema, "PAREM_CONF", "PAREM_CONF.PAREM_KEY", paremKeyResults));
289 
290  if (hcalCalibResults.queryFailed()) { // check query successful
291 
292  edm::LogError("L1-O2O") << "Problem with JetmetHcal key.";
293  return std::unique_ptr<L1RCTParameters>();
294  }
295 
296  // std::cout << "jetmetHcal " ;
297 
298  fillScaleFactors(hcalCalibResults, hcalCalibScaleFactors, 3);
299 
301  scaleFactorQuery3Strings,
302  rctSchema,
303  "HCAL_CALIB_HIGH_FACTOR",
304  "HCAL_CALIB_HIGH_FACTOR.VERSION",
306  "HCAL_CALIB_HIGH_VERSION", rctSchema, "PAREM_CONF", "PAREM_CONF.PAREM_KEY", paremKeyResults));
307 
308  if (hcalCalibHighResults.queryFailed()) // check query successful
309  {
310  edm::LogError("L1-O2O") << "Problem with hcalHigh key.";
311  return std::unique_ptr<L1RCTParameters>();
312  }
313 
314  fillScaleFactors(hcalCalibHighResults, hcalCalibHighScaleFactors, 3);
315 
317  scaleFactorQuery3Strings,
318  rctSchema,
319  "ECAL_CALIB_FACTOR",
320  "ECAL_CALIB_FACTOR.VERSION",
322  "ECAL_CALIB_VERSION", rctSchema, "PAREM_CONF", "PAREM_CONF.PAREM_KEY", paremKeyResults));
323 
324  if (ecalCalibResults.queryFailed()) // check query successful
325  {
326  edm::LogError("L1-O2O") << "Problem with ecal calib key.";
327  return std::unique_ptr<L1RCTParameters>();
328  }
329 
330  fillScaleFactors(ecalCalibResults, ecalCalibScaleFactors, 3);
331 
332  std::vector<std::string> scaleFactorQuery6Strings;
333  scaleFactorQuery6Strings.push_back("SCALEFACTOR");
334  scaleFactorQuery6Strings.push_back("SF2");
335  scaleFactorQuery6Strings.push_back("SF3");
336  scaleFactorQuery6Strings.push_back("SF4");
337  scaleFactorQuery6Strings.push_back("SF5");
338  scaleFactorQuery6Strings.push_back("SF6");
339  scaleFactorQuery6Strings.push_back("FK_RCT_ETA");
341  scaleFactorQuery6Strings,
342  rctSchema,
343  "CROSS_TERMS_FACTOR",
344  "CROSS_TERMS_FACTOR.VERSION",
346  "CROSS_TERMS_VERSION", rctSchema, "PAREM_CONF", "PAREM_CONF.PAREM_KEY", paremKeyResults));
347 
348  if (crossTermResults.queryFailed()) // check query successful
349  {
350  edm::LogError("L1-O2O") << "Problem with crossTerms key.";
351  return std::unique_ptr<L1RCTParameters>();
352  }
353 
354  fillScaleFactors(crossTermResults, crossTermsScaleFactors, 6);
355 
356  l1t::OMDSReader::QueryResults hoveresmearhighResults = m_omdsReader.basicQuery(
357  scaleFactorQueryStrings,
358  rctSchema,
359  "H_OVER_E_SMEAR_HIGH_FACTOR",
360  "H_OVER_E_SMEAR_HIGH_FACTOR.FK_VERSION",
362  "H_OVER_E_SMEAR_HIGH_VERSION", rctSchema, "PAREM_CONF", "PAREM_CONF.PAREM_KEY", paremKeyResults));
363 
364  if (hoveresmearhighResults.queryFailed()) // check query successful
365  {
366  edm::LogError("L1-O2O") << "Problem with low h over e smear key.";
367  return std::unique_ptr<L1RCTParameters>();
368  }
369 
370  // std::cout << "egammaEcal " ;
371  fillScaleFactors(hoveresmearhighResults, highHoverE_smear);
372 
373  l1t::OMDSReader::QueryResults hoveresmearlowResults = m_omdsReader.basicQuery(
374  scaleFactorQueryStrings,
375  rctSchema,
376  "H_OVER_E_SMEAR_LOW_FACTOR",
377  "H_OVER_E_SMEAR_LOW_FACTOR.FK_VERSION",
379  "H_OVER_E_SMEAR_LOW_VERSION", rctSchema, "PAREM_CONF", "PAREM_CONF.PAREM_KEY", paremKeyResults));
380 
381  if (hoveresmearlowResults.queryFailed()) // check query successful
382  {
383  edm::LogError("L1-O2O") << "Problem with low h over e smear key.";
384  return std::unique_ptr<L1RCTParameters>();
385  }
386 
387  // std::cout << "egammaEcal " ;
388  fillScaleFactors(hoveresmearlowResults, lowHoverE_smear);
389  }
390 
391  //~~~~~~~~~ Instantiate new L1RCTParameters object. ~~~~~~~~~
392 
393  // Default objects for Lindsey
394 
395  return std::make_unique<L1RCTParameters>(eGammaLSB,
396  jetMETLSB,
397  eMinForFGCut,
398  eMaxForFGCut,
399  hOeCut,
403  eActivityCut,
404  hActivityCut,
405  (unsigned int)eicIsolationThreshold,
406  (int)jscQuietThreshBarrel,
407  (int)jscQuietThreshEndcap,
408  noiseVetoHB,
411  useCorr, // useLindsey
412  egammaEcalScaleFactors,
413  egammaHcalScaleFactors,
414  jetmetEcalScaleFactors,
415  jetmetHcalScaleFactors,
416  ecalCalibScaleFactors,
417  hcalCalibScaleFactors,
418  hcalCalibHighScaleFactors,
419  crossTermsScaleFactors,
420  lowHoverE_smear,
421  highHoverE_smear);
422 }
423 
424 //
425 // member functions
426 //
427 
429  std::vector<double>& output,
430  int nfactors) {
431  if ((nfactors < 1) || (nfactors > 6)) {
432  edm::LogError("L1-O2O") << "invalid number of factors in scale factors fill";
433  return;
434  }
435 
436  std::vector<std::string> scaleFactorQuery6Strings;
437  scaleFactorQuery6Strings.push_back("SCALEFACTOR");
438  scaleFactorQuery6Strings.push_back("SF2");
439  scaleFactorQuery6Strings.push_back("SF3");
440  scaleFactorQuery6Strings.push_back("SF4");
441  scaleFactorQuery6Strings.push_back("SF5");
442  scaleFactorQuery6Strings.push_back("SF6");
443  // Store scale factors in temporary array to get ordering right.
444  // Reserve space for 100 bins.
445 
446  // static const int reserve = 100 ;
447  std::vector<double> sfTmp[100];
448  /*
449  for( int i = 0 ; i < reserve ; ++i )
450  {
451  sfTmp[ i ] = 0. ;
452  }
453  */
454  short maxBin = 0;
455  for (int i = 0; i < results.numberRows(); ++i) {
456  double sf[6];
457  for (int nf = 0; nf < nfactors; nf++) {
458  results.fillVariableFromRow(scaleFactorQuery6Strings.at(nf), i, sf[nf]);
459  }
460  short ieta = 0;
461  results.fillVariableFromRow("FK_RCT_ETA", i, ieta);
462 
463  for (int nf = 0; nf < nfactors; nf++)
464  // sfTmp[ ieta-1 ] = sf ; // eta bins start at 1.
465  sfTmp[ieta - 1].push_back(sf[nf]);
466 
467  if (ieta > maxBin) {
468  maxBin = ieta;
469  }
470  }
471 
472  for (short i = 0; i < maxBin; ++i) {
473  for (short nf = 0; nf < nfactors; nf++)
474  output.push_back(sfTmp[i].at(nf));
475  }
476 }
477 
478 // ------------ method called to produce the data ------------
479 
480 //define this as a plug-in
const QueryResults singleAttribute(const T &data) const
Definition: OMDSReader.h:259
constexpr unsigned int maxBin
eMinForHoECut
RCTConfigProducers.eMinForHoECut = 1 RCTConfigProducers.eMaxForHoECut = 30.
Log< level::Error, false > LogError
void fillScaleFactors(const l1t::OMDSReader::QueryResults &results, std::vector< double > &output, int nfactor=1)
std::unique_ptr< L1RCTParameters > newObject(const std::string &objectKey) override
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:75
bool fillVariable(const std::string &columnName, T &outputVariable) const
Definition: OMDSReader.h:274
L1RCTParametersOnlineProd(const edm::ParameterSet &)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
deadvectors [0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
hMinForHoECut
RCTConfigProducers.hMinForHoECut = 1.0.