File indexing completed on 2024-04-06 12:19:52
0001 #include "L1Trigger/GlobalCaloTrigger/plugins/L1GctPrintLuts.h"
0002
0003 #include "FWCore/PluginManager/interface/ModuleDef.h"
0004 #include "FWCore/Framework/interface/MakerMacros.h"
0005 #include "FWCore/Framework/interface/ESHandle.h"
0006
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008
0009
0010 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetEtCalibrationLut.h"
0011 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctWheelJetFpga.h"
0012 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctGlobalEnergyAlgos.h"
0013 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctGlobalHfSumAlgos.h"
0014 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctHfBitCountsLut.h"
0015 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctHtMissLut.h"
0016 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctHfEtSumsLut.h"
0017 #include "L1Trigger/GlobalCaloTrigger/interface/L1GlobalCaloTrigger.h"
0018
0019 #include <iostream>
0020 #include <fstream>
0021 #include <sys/stat.h>
0022
0023 L1GctPrintLuts::L1GctPrintLuts(const edm::ParameterSet& iConfig)
0024 : m_jetRanksOutFileName(iConfig.getUntrackedParameter<std::string>("jetRanksFilename", "gctJetRanksContents.txt")),
0025 m_hfSumLutOutFileName(iConfig.getUntrackedParameter<std::string>("hfSumLutFilename", "gctHfSumLutContents.txt")),
0026 m_htMissLutOutFileName(
0027 iConfig.getUntrackedParameter<std::string>("htMissLutFilename", "gctHtMissLutContents.txt")),
0028 m_gct(new L1GlobalCaloTrigger(L1GctJetLeafCard::hardwareJetFinder)),
0029 m_jetEtCalibLuts() {
0030
0031 lutPtr nextLut(new L1GctJetEtCalibrationLut());
0032
0033 for (unsigned ieta = 0; ieta < L1GctJetFinderBase::COL_OFFSET; ieta++) {
0034 nextLut->setEtaBin(ieta);
0035 m_jetEtCalibLuts.push_back(nextLut);
0036 nextLut.reset(new L1GctJetEtCalibrationLut());
0037 }
0038 m_jfParsToken = esConsumes<L1GctJetFinderParams, L1GctJetFinderParamsRcd>();
0039 m_etScaleToken = esConsumes<L1CaloEtScale, L1JetEtScaleRcd>();
0040 m_htMissScaleToken = esConsumes<L1CaloEtScale, L1HtMissScaleRcd>();
0041 m_hfRingEtScaleToken = esConsumes<L1CaloEtScale, L1HfRingEtScaleRcd>();
0042 }
0043
0044 L1GctPrintLuts::~L1GctPrintLuts() {
0045
0046
0047 }
0048
0049
0050
0051
0052
0053
0054 void L1GctPrintLuts::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0055
0056
0057 if (configureGct(iSetup) == 0) {
0058
0059 struct stat buffer;
0060 if (!stat(m_jetRanksOutFileName.c_str(), &buffer)) {
0061 edm::LogWarning("LutFileExists") << "File " << m_jetRanksOutFileName
0062 << " already exists. It will not be overwritten." << std::endl;
0063 } else {
0064 std::ofstream file;
0065 file.open(m_jetRanksOutFileName.c_str());
0066
0067 if (file.good()) {
0068
0069 file << " Gct lookup table printout \n"
0070 << "===========================\n\n"
0071 << "Jet Et Calibration lut contents\n"
0072 << std::endl;
0073 for (unsigned ieta = 0; ieta < m_jetEtCalibLuts.size(); ieta++) {
0074 file << *m_jetEtCalibLuts.at(ieta) << std::endl;
0075 }
0076 } else {
0077 edm::LogWarning("LutFileError") << "Error opening file " << m_jetRanksOutFileName
0078 << ". No lookup tables written." << std::endl;
0079 }
0080 file.close();
0081 }
0082
0083 if (!stat(m_hfSumLutOutFileName.c_str(), &buffer)) {
0084 edm::LogWarning("LutFileExists") << "File " << m_hfSumLutOutFileName
0085 << " already exists. It will not be overwritten." << std::endl;
0086 } else {
0087 std::ofstream file;
0088 file.open(m_hfSumLutOutFileName.c_str());
0089
0090 if (file.good()) {
0091
0092 file << "\n\n Hf ring jet bit count luts:" << std::endl;
0093 file << "\n Positive eta, ring1" << std::endl;
0094 file << *m_gct->getEnergyFinalStage()->getHfSumProcessor()->getBCLut(L1GctHfEtSumsLut::bitCountPosEtaRing1)
0095 << std::endl;
0096 file << "\n Positive eta, ring2" << std::endl;
0097 file << *m_gct->getEnergyFinalStage()->getHfSumProcessor()->getBCLut(L1GctHfEtSumsLut::bitCountPosEtaRing2)
0098 << std::endl;
0099 file << "\n Negative eta, ring1" << std::endl;
0100 file << *m_gct->getEnergyFinalStage()->getHfSumProcessor()->getBCLut(L1GctHfEtSumsLut::bitCountNegEtaRing1)
0101 << std::endl;
0102 file << "\n Negative eta, ring2" << std::endl;
0103 file << *m_gct->getEnergyFinalStage()->getHfSumProcessor()->getBCLut(L1GctHfEtSumsLut::bitCountNegEtaRing2)
0104 << std::endl;
0105 file << "\n\n Hf Et sum luts:" << std::endl;
0106 file << "\n Positive eta, ring1" << std::endl;
0107 file << *m_gct->getEnergyFinalStage()->getHfSumProcessor()->getESLut(L1GctHfEtSumsLut::etSumPosEtaRing1)
0108 << std::endl;
0109 file << "\n Positive eta, ring2" << std::endl;
0110 file << *m_gct->getEnergyFinalStage()->getHfSumProcessor()->getESLut(L1GctHfEtSumsLut::etSumPosEtaRing2)
0111 << std::endl;
0112 file << "\n Negative eta, ring1" << std::endl;
0113 file << *m_gct->getEnergyFinalStage()->getHfSumProcessor()->getESLut(L1GctHfEtSumsLut::etSumNegEtaRing1)
0114 << std::endl;
0115 file << "\n Negative eta, ring2" << std::endl;
0116 file << *m_gct->getEnergyFinalStage()->getHfSumProcessor()->getESLut(L1GctHfEtSumsLut::etSumNegEtaRing2)
0117 << std::endl;
0118 } else {
0119 edm::LogWarning("LutFileError") << "Error opening file " << m_hfSumLutOutFileName
0120 << ". No lookup tables written." << std::endl;
0121 }
0122 file.close();
0123 }
0124
0125 if (!stat(m_htMissLutOutFileName.c_str(), &buffer)) {
0126 edm::LogWarning("LutFileExists") << "File " << m_htMissLutOutFileName
0127 << " already exists. It will not be overwritten." << std::endl;
0128 } else {
0129 std::ofstream file;
0130 file.open(m_htMissLutOutFileName.c_str());
0131
0132 if (file.good()) {
0133
0134 file << "\n\n missing Ht lut:" << std::endl;
0135 file << *m_gct->getEnergyFinalStage()->getHtMissLut() << std::endl;
0136 } else {
0137 edm::LogWarning("LutFileError") << "Error opening file " << m_hfSumLutOutFileName
0138 << ". No lookup tables written." << std::endl;
0139 }
0140 file.close();
0141 }
0142 }
0143 }
0144
0145
0146
0147 void L1GctPrintLuts::beginJob() {}
0148
0149
0150 int L1GctPrintLuts::configureGct(const edm::EventSetup& c) {
0151 int success = 0;
0152
0153 if (success == 0) {
0154
0155 edm::ESHandle<L1GctJetFinderParams> jfPars = c.getHandle(m_jfParsToken);
0156 edm::ESHandle<L1CaloEtScale> hfRingEtScale = c.getHandle(m_hfRingEtScaleToken);
0157 edm::ESHandle<L1CaloEtScale> htMissScale = c.getHandle(m_htMissScaleToken);
0158 edm::ESHandle<L1CaloEtScale> etScale = c.getHandle(m_etScaleToken);
0159
0160 if (jfPars.product() == nullptr) {
0161 success = -1;
0162 edm::LogWarning("L1GctConfigFailure")
0163 << "Failed to find a L1GctJetFinderParamsRcd:L1GctJetFinderParams in EventSetup!" << std::endl;
0164 }
0165
0166 if (hfRingEtScale.product() == nullptr) {
0167 success = -1;
0168 edm::LogWarning("L1GctConfigFailure")
0169 << "Failed to find a L1HfRingEtScaleRcd:L1CaloEtScale in EventSetup!" << std::endl;
0170 }
0171
0172 if (htMissScale.product() == nullptr) {
0173 success = -1;
0174 edm::LogWarning("L1GctConfigFailure")
0175 << "Failed to find a L1HtMissScaleRcd:L1CaloEtScale in EventSetup!" << std::endl;
0176 }
0177
0178
0179
0180
0181
0182
0183
0184 if (success == 0) {
0185
0186 for (unsigned ieta = 0; ieta < m_jetEtCalibLuts.size(); ieta++) {
0187 m_jetEtCalibLuts.at(ieta)->setFunction(jfPars.product());
0188 m_jetEtCalibLuts.at(ieta)->setOutputEtScale(etScale.product());
0189 }
0190
0191
0192 m_gct->setJetEtCalibrationLuts(m_jetEtCalibLuts);
0193 m_gct->setJetFinderParams(jfPars.product());
0194 m_gct->setHtMissScale(htMissScale.product());
0195 m_gct->setupHfSumLuts(hfRingEtScale.product());
0196
0197 }
0198 }
0199
0200 if (success != 0) {
0201 edm::LogError("L1GctConfigError") << "Configuration failed - GCT emulator will not be run" << std::endl;
0202 }
0203 return success;
0204 }
0205
0206
0207 void L1GctPrintLuts::endJob() {}
0208
0209 DEFINE_FWK_MODULE(L1GctPrintLuts);