Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-07-16 00:28:47

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 
0004 #include "L1TriggerConfig/GctConfigProducers/interface/L1GctConfigProducers.h"
0005 
0006 #include "CondFormats/DataRecord/interface/L1GctJetFinderParamsRcd.h"
0007 #include "CondFormats/DataRecord/interface/L1JetEtScaleRcd.h"
0008 #include "CondFormats/DataRecord/interface/L1GctChannelMaskRcd.h"
0009 
0010 #include "CondFormats/L1TObjects/interface/L1CaloGeometry.h"
0011 #include "CondFormats/L1TObjects/interface/L1GctJetFinderParams.h"
0012 #include "CondFormats/L1TObjects/interface/L1GctChannelMask.h"
0013 
0014 #include <cmath>
0015 //
0016 // constants, enums and typedefs
0017 //
0018 
0019 //
0020 // static data member definitions
0021 //
0022 
0023 //
0024 // constructors and destructor
0025 //
0026 L1GctConfigProducers::L1GctConfigProducers(const edm::ParameterSet& iConfig)
0027     : m_rgnEtLsb(iConfig.getParameter<double>("RctRegionEtLSB")),
0028       m_htLsb(iConfig.getParameter<double>("GctHtLSB")),
0029       m_CenJetSeed(iConfig.getParameter<double>("JetFinderCentralJetSeed")),
0030       m_FwdJetSeed(iConfig.getParameter<double>("JetFinderForwardJetSeed")),
0031       m_TauJetSeed(iConfig.getParameter<double>("JetFinderCentralJetSeed")),  // no separate tau jet seed yet
0032       m_tauIsoThresh(iConfig.getParameter<double>("TauIsoEtThreshold")),
0033       m_htJetThresh(iConfig.getParameter<double>("HtJetEtThreshold")),
0034       m_mhtJetThresh(iConfig.getParameter<double>("MHtJetEtThreshold")),
0035       m_EtaBoundry(7),  // not programmable!
0036       m_corrFunType(0),
0037       m_convertToEnergy(iConfig.getParameter<bool>("ConvertEtValuesToEnergy")),
0038       m_jetCalibFunc(),
0039       m_tauCalibFunc(),
0040       m_metEtaMask(iConfig.getParameter<unsigned>("MEtEtaMask")),
0041       m_tetEtaMask(iConfig.getParameter<unsigned>("TEtEtaMask")),
0042       m_mhtEtaMask(iConfig.getParameter<unsigned>("MHtEtaMask")),
0043       m_thtEtaMask(iConfig.getParameter<unsigned>("HtEtaMask")) {
0044   //the following lines are needed to tell the framework what
0045   // data is being produced
0046   m_caloGeomToken = setWhatProduced(this, &L1GctConfigProducers::produceJfParams).consumes();
0047   setWhatProduced(this, &L1GctConfigProducers::produceChanMask);
0048 
0049   //now do what ever other initialization is needed
0050   std::string CalibStyle = iConfig.getParameter<std::string>("CalibrationStyle");
0051   edm::ParameterSet calibCoeffs;
0052 
0053   if (CalibStyle == "PowerSeries") {
0054     m_corrFunType = 1;
0055     calibCoeffs = iConfig.getParameter<edm::ParameterSet>("PowerSeriesCoefficients");
0056   }
0057 
0058   if (CalibStyle == "ORCAStyle") {
0059     m_corrFunType = 2;
0060     calibCoeffs = iConfig.getParameter<edm::ParameterSet>("OrcaStyleCoefficients");
0061   }
0062 
0063   if (CalibStyle == "Simple") {
0064     m_corrFunType = 3;
0065     calibCoeffs = iConfig.getParameter<edm::ParameterSet>("SimpleCoefficients");
0066   }
0067 
0068   if (CalibStyle == "PiecewiseCubic") {
0069     m_corrFunType = 4;
0070     calibCoeffs = iConfig.getParameter<edm::ParameterSet>("PiecewiseCubicCoefficients");
0071   }
0072 
0073   if (CalibStyle == "PF") {
0074     m_corrFunType = 5;
0075     calibCoeffs = iConfig.getParameter<edm::ParameterSet>("PFCoefficients");
0076   }
0077 
0078   // check
0079   if (CalibStyle != "None") {
0080     // Read the coefficients from file
0081     // coefficients for non-tau jet corrections
0082     for (unsigned i = 0; i < L1GctJetFinderParams::NUMBER_ETA_VALUES; ++i) {
0083       std::stringstream ss;
0084       std::string str;
0085       ss << "nonTauJetCalib" << i;
0086       ss >> str;
0087       m_jetCalibFunc.push_back(calibCoeffs.getParameter<std::vector<double> >(str));
0088     }
0089     // coefficients for tau jet corrections
0090     for (unsigned i = 0; i < L1GctJetFinderParams::N_CENTRAL_ETA_VALUES; ++i) {
0091       std::stringstream ss;
0092       std::string str;
0093       ss << "tauJetCalib" << i;
0094       ss >> str;
0095       m_tauCalibFunc.push_back(calibCoeffs.getParameter<std::vector<double> >(str));
0096     }
0097 
0098   } else {
0099     // No corrections to be applied
0100     m_corrFunType = 0;  // no correction
0101     // Set the vector sizes to those expected by the CalibrationFunction
0102     m_jetCalibFunc.resize(L1GctJetFinderParams::NUMBER_ETA_VALUES);
0103     m_tauCalibFunc.resize(L1GctJetFinderParams::N_CENTRAL_ETA_VALUES);
0104   }
0105 
0106   edm::LogWarning("L1GctConfig") << "Calibration Style option " << CalibStyle << std::endl;
0107 }
0108 
0109 L1GctConfigProducers::~L1GctConfigProducers() {
0110   // do anything here that needs to be done at desctruction time
0111   // (e.g. close files, deallocate resources etc.)
0112 }
0113 
0114 // The producer methods are handled by the "Configurer" objects
0115 
0116 L1GctConfigProducers::JfParamsReturnType L1GctConfigProducers::produceJfParams(const L1GctJetFinderParamsRcd& aRcd) {
0117   // get geometry
0118   edm::ESHandle<L1CaloGeometry> geom = aRcd.getHandle(m_caloGeomToken);
0119 
0120   // construct jet finder params object
0121   auto pL1GctJetFinderParams = std::make_unique<L1GctJetFinderParams>(m_rgnEtLsb,
0122                                                                       m_htLsb,
0123                                                                       m_CenJetSeed,
0124                                                                       m_FwdJetSeed,
0125                                                                       m_TauJetSeed,
0126                                                                       m_tauIsoThresh,
0127                                                                       m_htJetThresh,
0128                                                                       m_mhtJetThresh,
0129                                                                       m_EtaBoundry,
0130                                                                       m_corrFunType,
0131                                                                       m_jetCalibFunc,
0132                                                                       m_tauCalibFunc,
0133                                                                       m_convertToEnergy,
0134                                                                       etToEnergyConversion(geom.product()));
0135 
0136   return pL1GctJetFinderParams;
0137 }
0138 
0139 L1GctConfigProducers::ChanMaskReturnType L1GctConfigProducers::produceChanMask(const L1GctChannelMaskRcd&) {
0140   L1GctChannelMask* mask = new L1GctChannelMask;
0141 
0142   for (unsigned ieta = 0; ieta < 22; ++ieta) {
0143     if (((m_metEtaMask >> ieta) & 0x1) == 1)
0144       mask->maskMissingEt(ieta);
0145     if (((m_tetEtaMask >> ieta) & 0x1) == 1)
0146       mask->maskTotalEt(ieta);
0147     if (((m_mhtEtaMask >> ieta) & 0x1) == 1)
0148       mask->maskMissingHt(ieta);
0149     if (((m_thtEtaMask >> ieta) & 0x1) == 1)
0150       mask->maskTotalHt(ieta);
0151   }
0152 
0153   return std::unique_ptr<L1GctChannelMask>(mask);
0154 }
0155 
0156 /// Legacy nonsense
0157 
0158 /// Calculate Et-to-energy conversion factors for eta bins
0159 std::vector<double> L1GctConfigProducers::etToEnergyConversion(const L1CaloGeometry* geom) const {
0160   //  L1CaloGeometry* geom = new L1CaloGeometry();
0161   std::vector<double> result;
0162   // Factors for central eta bins
0163   for (unsigned ieta = 0; ieta < 7; ieta++) {
0164     double bineta = geom->etaBinCenter(ieta, true);
0165     double factor = 0.5 * (exp(bineta) + exp(-bineta));  // Conversion from eta to cosec(theta)
0166     result.push_back(factor);
0167   }
0168   // Factors for forward eta bins
0169   for (unsigned ieta = 0; ieta < 4; ieta++) {
0170     double bineta = geom->etaBinCenter(ieta, false);
0171     double factor = 0.5 * (exp(bineta) + exp(-bineta));  // Conversion from eta to cosec(theta)
0172     result.push_back(factor);
0173   }
0174   return result;
0175 }
0176 
0177 //define this as a plug-in
0178 DEFINE_FWK_EVENTSETUP_MODULE(L1GctConfigProducers);