CMS 3D CMS Logo

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