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::unique_ptr<L1MuTriggerScales> L1MuTriggerScalesOnlineProducer::newObject(const std::string& objectKey )
115 {
116  // The key we get from the O2O subsystem is the CMS_GMT.L1T_SCALES key,
117  // but the eta/phi scales have their own subtables, so let's find
118  // out.
119  vector<string> foreignKeys;
120 
121  const std::string etaKeyColumn("SC_MUON_ETA_FK");
122  const std::string phiKeyColumn("SC_MUON_PHI_FK");
123 
124  foreignKeys.push_back(etaKeyColumn);
125  foreignKeys.push_back(phiKeyColumn);
126 
127  l1t::OMDSReader::QueryResults keysRecord =
129  // SELECTed columns
130  foreignKeys,
131  // schema name
132  "CMS_GT",
133  // table name
134  "L1T_SCALES",
135  // WHERE lhs
136  "L1T_SCALES.ID",
137  // WHERE rhs
138  m_omdsReader.singleAttribute( objectKey ) );
139 
140  if( keysRecord.numberRows() != 1 ) // check if query was successful
141  {
142  throw cond::Exception("Problem finding L1MuTriggerScales associated "
143  "with scales key `" + objectKey + "'");
144  }
145 
146 
147  std::string etaKeyValue;
148  std::string phiKeyValue;
149  keysRecord.fillVariable(etaKeyColumn, etaKeyValue);
150  keysRecord.fillVariable(phiKeyColumn, phiKeyValue);
151 
152  vector<string> columns;
153 
154  // get the eta scales from the database
155  ScaleRecordHelper etaHelper("ETA_BIN_LOW", m_nbinsEta);
156  etaHelper.pushColumnNames(columns);
157 
158  l1t::OMDSReader::QueryResults etaRecord =
160  // SELECTed columns
161  columns,
162  // schema name
163  "CMS_GT",
164  // table name
165  "L1T_SCALE_MUON_ETA",
166  // WHERE lhs
167  "L1T_SCALE_MUON_ETA.ID",
168  // WHERE rhs
169  m_omdsReader.singleAttribute( etaKeyValue ) );
170 
171  vector<double> etaScales;
172  etaHelper.extractScales(etaRecord, etaScales);
173 
174  unique_ptr<L1MuSymmetricBinnedScale> ptrEtaScale(new L1MuSymmetricBinnedScale(m_nbitPackingEta, m_nbinsEta, etaScales));
175  m_scales.setGMTEtaScale(*ptrEtaScale);
176 
177  columns.clear();
178 
179  // get the phi scales from the database
180  PhiScaleHelper phiHelper;
181 
182  l1t::OMDSReader::QueryResults phiRecord =
184  // SELECTed columns
185  columns,
186  // schema name
187  "CMS_GT",
188  // table name
189  "L1T_SCALE_MUON_PHI",
190  // WHERE lhs
191  "L1T_SCALE_MUON_PHI.ID",
192  // WHERE rhs
193  m_omdsReader.singleAttribute( phiKeyValue ) );
194 
195  unique_ptr<L1MuBinnedScale> ptrPhiScale(phiHelper.makeBinnedScale(phiRecord, m_nbitPackingPhi, m_signedPackingPhi));
196 
197  m_scales.setPhiScale(*ptrPhiScale);
198 
199  return std::make_unique<L1MuTriggerScales>(m_scales);
200 }
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)
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)
std::unique_ptr< L1MuTriggerScales > newObject(const std::string &objectKey) override
void extractScales(l1t::OMDSReader::QueryResults &record, std::vector< double > &destScales)
step
Definition: StallMonitor.cc:94
static double rad2deg(double rad)
static L1MuBinnedScale * makeBinnedScale(l1t::OMDSReader::QueryResults &record, int nBits, bool signedPacking)