CMS 3D CMS Logo

L1MuTriggerScalesOnlineProducer.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // \class L1MuTriggerScalesOnlineProducer
4 //
5 // Description: A class to produce the L1 mu emulator scales record in the event setup
6 // from the OMDS database.
7 //
8 //
9 // Author :
10 // Thomas Themel
11 //
12 //--------------------------------------------------
15 #include <cmath>
16 
17 using namespace std;
18 
21  m_scales(
22  ps.getParameter<int>("nbitPackingDTEta"),
23  ps.getParameter<bool>("signedPackingDTEta"),
24  ps.getParameter<int>("nbinsDTEta"),
25  ps.getParameter<double>("minDTEta"),
26  ps.getParameter<double>("maxDTEta"),
27  ps.getParameter<int>("offsetDTEta"),
28 
29  ps.getParameter<int>("nbitPackingCSCEta"),
30  ps.getParameter<int>("nbinsCSCEta"),
31  ps.getParameter<double>("minCSCEta"),
32  ps.getParameter<double>("maxCSCEta"),
33 
34  ps.getParameter<std::vector<double> >("scaleRPCEta"),
35  ps.getParameter<int>("nbitPackingBrlRPCEta"),
36  ps.getParameter<bool>("signedPackingBrlRPCEta"),
37  ps.getParameter<int>("nbinsBrlRPCEta"),
38  ps.getParameter<int>("offsetBrlRPCEta"),
39  ps.getParameter<int>("nbitPackingFwdRPCEta"),
40  ps.getParameter<bool>("signedPackingFwdRPCEta"),
41  ps.getParameter<int>("nbinsFwdRPCEta"),
42  ps.getParameter<int>("offsetFwdRPCEta"),
43  // Fields that should now be generated from OMDS:
44  // TODO: Adjust m_scales's definition to be a bit
45  // more accessible for the partial initialization.
46  //ps.getParameter<int>("nbitPackingGMTEta"),
47  0,
48  //ps.getParameter<int>("nbinsGMTEta"),
49  0,
50  //ps.getParameter<std::vector<double> >("scaleGMTEta"),
51  std::vector<double>(1),
52  //ps.getParameter<int>("nbitPackingPhi"),
53  0,
54  //ps.getParameter<bool>("signedPackingPhi"),
55  false,
56  //ps.getParameter<int>("nbinsPhi"),
57  0,
58  //ps.getParameter<double>("minPhi"),
59  0,
60  //ps.getParameter<double>("maxPhi")
61  0
62  ),
63  /* Metadata that's not yet in the database. */
64  m_nbitPackingPhi(ps.getParameter<int>("nbitPackingPhi")),
65  m_nbitPackingEta(ps.getParameter<int>("nbitPackingGMTEta")),
66  m_nbinsEta(ps.getParameter<int>("nbinsGMTEta")),
67  m_signedPackingPhi(ps.getParameter<bool>("signedPackingPhi"))
68 {
69 }
70 
72 
73 
74 //
75 // member functions
76 //
77 
79  public:
80 
81  static L1MuBinnedScale* makeBinnedScale(l1t::OMDSReader::QueryResults& record, int nBits, bool signedPacking) {
82  short nbins=0;
83  record.fillVariable(BinsColumn, nbins);
84  float lowMark=0.;
85  record.fillVariable(LowMarkColumn, lowMark);
86  float step=0.;
87  record.fillVariable(StepColumn, step);
88 
89  return new L1MuBinnedScale(nBits, signedPacking,
90  nbins, deg2rad(lowMark),
91  deg2rad(lowMark + nbins*step));
92 
93  }
94 
95  static void pushColumnNames(vector<string>& columns) {
96  columns.push_back(BinsColumn);
97  columns.push_back(LowMarkColumn);
98  columns.push_back(StepColumn);
99  }
100 
101  static double deg2rad(double deg) { return deg*M_PI/180.0; }
102  static double rad2deg(double rad) { return rad/M_PI*180.0; }
103 
104  static const string BinsColumn;
105  static const string LowMarkColumn;
106  static const string StepColumn;
107 };
108 
109 const string PhiScaleHelper::BinsColumn = "PHI_BINS";
110 const string PhiScaleHelper::LowMarkColumn = "PHI_DEG_BIN_LOW_0";
111 const string PhiScaleHelper::StepColumn = "PHI_DEG_BIN_STEP";
112 
113 // ------------ method called to produce the data ------------
114 std::shared_ptr<L1MuTriggerScales> L1MuTriggerScalesOnlineProducer::newObject(const std::string& objectKey )
115 {
116  using namespace edm::es;
117 
118  // The key we get from the O2O subsystem is the CMS_GMT.L1T_SCALES key,
119  // but the eta/phi scales have their own subtables, so let's find
120  // out.
121  vector<string> foreignKeys;
122 
123  const std::string etaKeyColumn("SC_MUON_ETA_FK");
124  const std::string phiKeyColumn("SC_MUON_PHI_FK");
125 
126  foreignKeys.push_back(etaKeyColumn);
127  foreignKeys.push_back(phiKeyColumn);
128 
129  l1t::OMDSReader::QueryResults keysRecord =
131  // SELECTed columns
132  foreignKeys,
133  // schema name
134  "CMS_GT",
135  // table name
136  "L1T_SCALES",
137  // WHERE lhs
138  "L1T_SCALES.ID",
139  // WHERE rhs
140  m_omdsReader.singleAttribute( objectKey ) );
141 
142  if( keysRecord.numberRows() != 1 ) // check if query was successful
143  {
144  throw cond::Exception("Problem finding L1MuTriggerScales associated "
145  "with scales key `" + objectKey + "'");
146  }
147 
148 
149  std::string etaKeyValue;
150  std::string phiKeyValue;
151  keysRecord.fillVariable(etaKeyColumn, etaKeyValue);
152  keysRecord.fillVariable(phiKeyColumn, phiKeyValue);
153 
154  vector<string> columns;
155 
156  // get the eta scales from the database
157  ScaleRecordHelper etaHelper("ETA_BIN_LOW", m_nbinsEta);
158  etaHelper.pushColumnNames(columns);
159 
160  l1t::OMDSReader::QueryResults etaRecord =
162  // SELECTed columns
163  columns,
164  // schema name
165  "CMS_GT",
166  // table name
167  "L1T_SCALE_MUON_ETA",
168  // WHERE lhs
169  "L1T_SCALE_MUON_ETA.ID",
170  // WHERE rhs
171  m_omdsReader.singleAttribute( etaKeyValue ) );
172 
173  vector<double> etaScales;
174  etaHelper.extractScales(etaRecord, etaScales);
175 
176  unique_ptr<L1MuSymmetricBinnedScale> ptrEtaScale(new L1MuSymmetricBinnedScale(m_nbitPackingEta, m_nbinsEta, etaScales));
177  m_scales.setGMTEtaScale(*ptrEtaScale);
178 
179  columns.clear();
180 
181  // get the phi scales from the database
182  PhiScaleHelper phiHelper;
183 
184  l1t::OMDSReader::QueryResults phiRecord =
186  // SELECTed columns
187  columns,
188  // schema name
189  "CMS_GT",
190  // table name
191  "L1T_SCALE_MUON_PHI",
192  // WHERE lhs
193  "L1T_SCALE_MUON_PHI.ID",
194  // WHERE rhs
195  m_omdsReader.singleAttribute( phiKeyValue ) );
196 
197  unique_ptr<L1MuBinnedScale> ptrPhiScale(phiHelper.makeBinnedScale(phiRecord, m_nbitPackingPhi, m_signedPackingPhi));
198 
199  m_scales.setPhiScale(*ptrPhiScale);
200 
201  return std::make_shared<L1MuTriggerScales>(m_scales);
202 }
persistency::Exception Exception
Definition: Exception.h:25
bool fillVariable(const std::string &columnName, T &outputVariable) const
Definition: OMDSReader.h:311
const QueryResults singleAttribute(const T &data) const
Definition: OMDSReader.h:295
JetCorrectorParameters::Record record
Definition: classes.h:7
L1MuTriggerScalesOnlineProducer(const edm::ParameterSet &)
static const string LowMarkColumn
void setGMTEtaScale(const L1MuSymmetricBinnedScale &scale)
set the GMT eta scale
static void pushColumnNames(vector< string > &columns)
virtual std::shared_ptr< L1MuTriggerScales > newObject(const std::string &objectKey)
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
static double deg2rad(double deg)
void setPhiScale(const L1MuBinnedScale &scale)
set the phi scale
#define M_PI
void pushColumnNames(std::vector< std::string > &columns)
void extractScales(l1t::OMDSReader::QueryResults &record, std::vector< double > &destScales)
step
static double rad2deg(double rad)
static L1MuBinnedScale * makeBinnedScale(l1t::OMDSReader::QueryResults &record, int nBits, bool signedPacking)