Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:31:13

0001 //-------------------------------------------------
0002 //
0003 //   \class L1MuTriggerScalesOnlineProducer
0004 //
0005 //   Description:  A class to produce the L1 mu emulator scales record in the event setup
0006 //                 from the OMDS database.
0007 //
0008 //
0009 //   Author :
0010 //   Thomas Themel
0011 //
0012 //--------------------------------------------------
0013 #include "L1TriggerConfig/L1ScalesProducers/interface/L1MuTriggerScalesOnlineProducer.h"
0014 #include "L1TriggerConfig/L1ScalesProducers/interface/ScaleRecordHelper.h"
0015 #include <cmath>
0016 
0017 using namespace std;
0018 
0019 L1MuTriggerScalesOnlineProducer::L1MuTriggerScalesOnlineProducer(const edm::ParameterSet& ps)
0020     : L1ConfigOnlineProdBase<L1MuTriggerScalesRcd, L1MuTriggerScales>(ps),
0021       m_scales(ps.getParameter<int>("nbitPackingDTEta"),
0022                ps.getParameter<bool>("signedPackingDTEta"),
0023                ps.getParameter<int>("nbinsDTEta"),
0024                ps.getParameter<double>("minDTEta"),
0025                ps.getParameter<double>("maxDTEta"),
0026                ps.getParameter<int>("offsetDTEta"),
0027 
0028                ps.getParameter<int>("nbitPackingCSCEta"),
0029                ps.getParameter<int>("nbinsCSCEta"),
0030                ps.getParameter<double>("minCSCEta"),
0031                ps.getParameter<double>("maxCSCEta"),
0032 
0033                ps.getParameter<std::vector<double> >("scaleRPCEta"),
0034                ps.getParameter<int>("nbitPackingBrlRPCEta"),
0035                ps.getParameter<bool>("signedPackingBrlRPCEta"),
0036                ps.getParameter<int>("nbinsBrlRPCEta"),
0037                ps.getParameter<int>("offsetBrlRPCEta"),
0038                ps.getParameter<int>("nbitPackingFwdRPCEta"),
0039                ps.getParameter<bool>("signedPackingFwdRPCEta"),
0040                ps.getParameter<int>("nbinsFwdRPCEta"),
0041                ps.getParameter<int>("offsetFwdRPCEta"),
0042                // Fields that should now be generated from OMDS:
0043                // TODO: Adjust m_scales's definition to be a bit
0044                //       more accessible for the partial initialization.
0045                //ps.getParameter<int>("nbitPackingGMTEta"),
0046                0,
0047                //ps.getParameter<int>("nbinsGMTEta"),
0048                0,
0049                //ps.getParameter<std::vector<double> >("scaleGMTEta"),
0050                std::vector<double>(1),
0051                //ps.getParameter<int>("nbitPackingPhi"),
0052                0,
0053                //ps.getParameter<bool>("signedPackingPhi"),
0054                false,
0055                //ps.getParameter<int>("nbinsPhi"),
0056                0,
0057                //ps.getParameter<double>("minPhi"),
0058                0,
0059                //ps.getParameter<double>("maxPhi")
0060                0),
0061       /* Metadata that's not yet in the database. */
0062       m_nbitPackingPhi(ps.getParameter<int>("nbitPackingPhi")),
0063       m_nbitPackingEta(ps.getParameter<int>("nbitPackingGMTEta")),
0064       m_nbinsEta(ps.getParameter<int>("nbinsGMTEta")),
0065       m_signedPackingPhi(ps.getParameter<bool>("signedPackingPhi")) {}
0066 
0067 L1MuTriggerScalesOnlineProducer::~L1MuTriggerScalesOnlineProducer() {}
0068 
0069 //
0070 // member functions
0071 //
0072 
0073 class PhiScaleHelper {
0074 public:
0075   static L1MuBinnedScale* makeBinnedScale(l1t::OMDSReader::QueryResults& record, int nBits, bool signedPacking) {
0076     short nbins = 0;
0077     record.fillVariable(BinsColumn, nbins);
0078     float lowMark = 0.;
0079     record.fillVariable(LowMarkColumn, lowMark);
0080     float step = 0.;
0081     record.fillVariable(StepColumn, step);
0082 
0083     return new L1MuBinnedScale(nBits, signedPacking, nbins, deg2rad(lowMark), deg2rad(lowMark + nbins * step));
0084   }
0085 
0086   static void pushColumnNames(vector<string>& columns) {
0087     columns.push_back(BinsColumn);
0088     columns.push_back(LowMarkColumn);
0089     columns.push_back(StepColumn);
0090   }
0091 
0092   static double deg2rad(double deg) { return deg * M_PI / 180.0; }
0093   static double rad2deg(double rad) { return rad / M_PI * 180.0; }
0094 
0095   static const string BinsColumn;
0096   static const string LowMarkColumn;
0097   static const string StepColumn;
0098 };
0099 
0100 const string PhiScaleHelper::BinsColumn = "PHI_BINS";
0101 const string PhiScaleHelper::LowMarkColumn = "PHI_DEG_BIN_LOW_0";
0102 const string PhiScaleHelper::StepColumn = "PHI_DEG_BIN_STEP";
0103 
0104 // ------------ method called to produce the data  ------------
0105 std::unique_ptr<L1MuTriggerScales> L1MuTriggerScalesOnlineProducer::newObject(const std::string& objectKey) {
0106   // The key we get from the O2O subsystem is the CMS_GMT.L1T_SCALES key,
0107   // but the eta/phi scales have their own subtables, so let's find
0108   // out.
0109   vector<string> foreignKeys;
0110 
0111   const std::string etaKeyColumn("SC_MUON_ETA_FK");
0112   const std::string phiKeyColumn("SC_MUON_PHI_FK");
0113 
0114   foreignKeys.push_back(etaKeyColumn);
0115   foreignKeys.push_back(phiKeyColumn);
0116 
0117   l1t::OMDSReader::QueryResults keysRecord = m_omdsReader.basicQuery(
0118       // SELECTed columns
0119       foreignKeys,
0120       // schema name
0121       "CMS_GT",
0122       // table name
0123       "L1T_SCALES",
0124       // WHERE lhs
0125       "L1T_SCALES.ID",
0126       // WHERE rhs
0127       m_omdsReader.singleAttribute(objectKey));
0128 
0129   if (keysRecord.numberRows() != 1)  // check if query was successful
0130   {
0131     throw cond::Exception(
0132         "Problem finding L1MuTriggerScales associated "
0133         "with scales key `" +
0134         objectKey + "'");
0135   }
0136 
0137   std::string etaKeyValue;
0138   std::string phiKeyValue;
0139   keysRecord.fillVariable(etaKeyColumn, etaKeyValue);
0140   keysRecord.fillVariable(phiKeyColumn, phiKeyValue);
0141 
0142   vector<string> columns;
0143 
0144   // get the eta scales from the database
0145   ScaleRecordHelper etaHelper("ETA_BIN_LOW", m_nbinsEta);
0146   etaHelper.pushColumnNames(columns);
0147 
0148   l1t::OMDSReader::QueryResults etaRecord = m_omdsReader.basicQuery(
0149       // SELECTed columns
0150       columns,
0151       // schema name
0152       "CMS_GT",
0153       // table name
0154       "L1T_SCALE_MUON_ETA",
0155       // WHERE lhs
0156       "L1T_SCALE_MUON_ETA.ID",
0157       // WHERE rhs
0158       m_omdsReader.singleAttribute(etaKeyValue));
0159 
0160   vector<double> etaScales;
0161   etaHelper.extractScales(etaRecord, etaScales);
0162 
0163   unique_ptr<L1MuSymmetricBinnedScale> ptrEtaScale(
0164       new L1MuSymmetricBinnedScale(m_nbitPackingEta, m_nbinsEta, etaScales));
0165   m_scales.setGMTEtaScale(*ptrEtaScale);
0166 
0167   columns.clear();
0168 
0169   // get the phi scales from the database
0170   PhiScaleHelper phiHelper;
0171 
0172   l1t::OMDSReader::QueryResults phiRecord = m_omdsReader.basicQuery(
0173       // SELECTed columns
0174       columns,
0175       // schema name
0176       "CMS_GT",
0177       // table name
0178       "L1T_SCALE_MUON_PHI",
0179       // WHERE lhs
0180       "L1T_SCALE_MUON_PHI.ID",
0181       // WHERE rhs
0182       m_omdsReader.singleAttribute(phiKeyValue));
0183 
0184   unique_ptr<L1MuBinnedScale> ptrPhiScale(phiHelper.makeBinnedScale(phiRecord, m_nbitPackingPhi, m_signedPackingPhi));
0185 
0186   m_scales.setPhiScale(*ptrPhiScale);
0187 
0188   return std::make_unique<L1MuTriggerScales>(m_scales);
0189 }