00001 #include "L1Trigger/GlobalCaloTrigger/plugins/L1GctPrintLuts.h"
00002
00003 #include "FWCore/PluginManager/interface/ModuleDef.h"
00004 #include "FWCore/Framework/interface/MakerMacros.h"
00005 #include "FWCore/Framework/interface/ESHandle.h"
00006
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008
00009
00010 #include "CondFormats/L1TObjects/interface/L1GctJetFinderParams.h"
00011 #include "CondFormats/L1TObjects/interface/L1GctJetEtCalibrationFunction.h"
00012 #include "CondFormats/L1TObjects/interface/L1GctJetCounterSetup.h"
00013 #include "CondFormats/L1TObjects/interface/L1GctChannelMask.h"
00014 #include "CondFormats/DataRecord/interface/L1GctJetFinderParamsRcd.h"
00015 #include "CondFormats/DataRecord/interface/L1GctJetCalibFunRcd.h"
00016 #include "CondFormats/DataRecord/interface/L1GctJetCounterPositiveEtaRcd.h"
00017 #include "CondFormats/DataRecord/interface/L1GctJetCounterNegativeEtaRcd.h"
00018 #include "CondFormats/DataRecord/interface/L1GctChannelMaskRcd.h"
00019 #include "CondFormats/DataRecord/interface/L1GctHfLutSetupRcd.h"
00020
00021
00022 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetEtCalibrationLut.h"
00023 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctWheelJetFpga.h"
00024 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetCounter.h"
00025 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetCounterLut.h"
00026 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctGlobalEnergyAlgos.h"
00027 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctGlobalHfSumAlgos.h"
00028 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctHfBitCountsLut.h"
00029 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctHfEtSumsLut.h"
00030 #include "L1Trigger/GlobalCaloTrigger/interface/L1GlobalCaloTrigger.h"
00031
00032 #include <iostream>
00033 #include <fstream>
00034 #include <sys/stat.h>
00035
00036
00037 L1GctPrintLuts::L1GctPrintLuts(const edm::ParameterSet& iConfig) :
00038 m_jetRanksOutFileName(iConfig.getUntrackedParameter<std::string>("jetRanksFilename","gctJetRanksContents.txt")),
00039 m_jetCountOutFileName(iConfig.getUntrackedParameter<std::string>("jetCountFilename","gctJetCountContents.txt")),
00040 m_hfSumLutOutFileName(iConfig.getUntrackedParameter<std::string>("hfSumLutFilename","gctHfSumLutContents.txt")),
00041 m_gct(new L1GlobalCaloTrigger(L1GctJetLeafCard::hardwareJetFinder)),
00042 m_jetEtCalibLuts()
00043 {
00044
00045 lutPtr nextLut( new L1GctJetEtCalibrationLut() );
00046
00047 for (unsigned ieta=0; ieta<L1GctJetFinderBase::COL_OFFSET; ieta++) {
00048 nextLut->setEtaBin(ieta);
00049 m_jetEtCalibLuts.push_back(nextLut);
00050 nextLut.reset ( new L1GctJetEtCalibrationLut() );
00051 }
00052
00053 }
00054
00055 L1GctPrintLuts::~L1GctPrintLuts()
00056 {
00057
00058
00059
00060
00061 }
00062
00063
00064
00065
00066
00067
00068
00069 void
00070 L1GctPrintLuts::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00071 {
00072 }
00073
00074
00075
00076 void
00077 L1GctPrintLuts::beginJob(const edm::EventSetup& c)
00078 {
00079
00080
00081 if (configureGct(c) == 0) {
00082
00083
00084 struct stat buffer ;
00085 if ( !stat( m_jetRanksOutFileName.c_str(), &buffer ) ) {
00086 edm::LogWarning("LutFileExists") << "File " << m_jetRanksOutFileName << " already exists. It will not be overwritten." << std::endl;
00087 } else {
00088
00089 std::ofstream file;
00090 file.open( m_jetRanksOutFileName.c_str() );
00091
00092 if (file.good()) {
00093
00094 file << " Gct lookup table printout \n"
00095 << "===========================\n\n"
00096 << "Jet Et Calibration lut contents\n" << std::endl;
00097 for (unsigned ieta=0; ieta<m_jetEtCalibLuts.size(); ieta++) {
00098 file << *m_jetEtCalibLuts.at(ieta) << std::endl;
00099 }
00100 } else {
00101 edm::LogWarning("LutFileError") << "Error opening file " << m_jetRanksOutFileName << ". No lookup tables written." << std::endl;
00102 }
00103 file.close();
00104 }
00105
00106 if ( !stat( m_jetCountOutFileName.c_str(), &buffer ) ) {
00107 edm::LogWarning("LutFileExists") << "File " << m_jetCountOutFileName << " already exists. It will not be overwritten." << std::endl;
00108 } else {
00109
00110 std::ofstream file;
00111 file.open( m_jetCountOutFileName.c_str() );
00112
00113 if (file.good()) {
00114
00115 for (int wheel=0; wheel<m_gct->N_WHEEL_CARDS; wheel++) {
00116
00117
00118
00119 int nCounters = m_gct->getWheelJetFpgas().at(wheel)->N_JET_COUNTERS;
00120 file << "\n\n" << (wheel==0 ? "Positive " : "Negative ") << "wheel has "
00121 << nCounters << " jet counters" << std::endl;
00122 for (int ctr=0; ctr<nCounters; ctr++) {
00123 file << "\nJet counter number " << ctr << " lookup table contents \n" << std::endl;
00124 file << *m_gct->getWheelJetFpgas().at(wheel)->getJetCounter(ctr)->getJetCounterLut() << std::endl;
00125 }
00126 }
00127 } else {
00128 edm::LogWarning("LutFileError") << "Error opening file " << m_jetCountOutFileName << ". No lookup tables written." << std::endl;
00129 }
00130 file.close();
00131 }
00132
00133 if ( !stat( m_hfSumLutOutFileName.c_str(), &buffer ) ) {
00134 edm::LogWarning("LutFileExists") << "File " << m_hfSumLutOutFileName << " already exists. It will not be overwritten." << std::endl;
00135 } else {
00136
00137 std::ofstream file;
00138 file.open( m_hfSumLutOutFileName.c_str() );
00139
00140 if (file.good()) {
00141
00142 file << "\n\n Hf ring jet bit count luts:" << std::endl;
00143 file << "\n Positive eta, ring1" << std::endl;
00144 file << *m_gct->getEnergyFinalStage()->getHfSumProcessor()->getBCLut(L1GctHfLutSetup::bitCountPosEtaRing1) << std::endl;
00145 file << "\n Positive eta, ring2" << std::endl;
00146 file << *m_gct->getEnergyFinalStage()->getHfSumProcessor()->getBCLut(L1GctHfLutSetup::bitCountPosEtaRing2) << std::endl;
00147 file << "\n Negative eta, ring1" << std::endl;
00148 file << *m_gct->getEnergyFinalStage()->getHfSumProcessor()->getBCLut(L1GctHfLutSetup::bitCountNegEtaRing1) << std::endl;
00149 file << "\n Negative eta, ring2" << std::endl;
00150 file << *m_gct->getEnergyFinalStage()->getHfSumProcessor()->getBCLut(L1GctHfLutSetup::bitCountNegEtaRing2) << std::endl;
00151 file << "\n\n Hf Et sum luts:" << std::endl;
00152 file << "\n Positive eta, ring1" << std::endl;
00153 file << *m_gct->getEnergyFinalStage()->getHfSumProcessor()->getESLut(L1GctHfLutSetup::etSumPosEtaRing1) << std::endl;
00154 file << "\n Positive eta, ring2" << std::endl;
00155 file << *m_gct->getEnergyFinalStage()->getHfSumProcessor()->getESLut(L1GctHfLutSetup::etSumPosEtaRing2) << std::endl;
00156 file << "\n Negative eta, ring1" << std::endl;
00157 file << *m_gct->getEnergyFinalStage()->getHfSumProcessor()->getESLut(L1GctHfLutSetup::etSumNegEtaRing1) << std::endl;
00158 file << "\n Negative eta, ring2" << std::endl;
00159 file << *m_gct->getEnergyFinalStage()->getHfSumProcessor()->getESLut(L1GctHfLutSetup::etSumNegEtaRing2) << std::endl;
00160 } else {
00161 edm::LogWarning("LutFileError") << "Error opening file " << m_hfSumLutOutFileName << ". No lookup tables written." << std::endl;
00162 }
00163 file.close();
00164 }
00165 }
00166 }
00167
00168
00169 int L1GctPrintLuts::configureGct(const edm::EventSetup& c)
00170 {
00171 int success = 0;
00172 if (&c==0) {
00173 success = -1;
00174 edm::LogWarning("L1GctConfigFailure") << "Cannot find EventSetup information." << std::endl;
00175 }
00176
00177 if (success == 0) {
00178
00179 edm::ESHandle< L1GctJetFinderParams > jfPars ;
00180 c.get< L1GctJetFinderParamsRcd >().get( jfPars ) ;
00181 edm::ESHandle< L1GctJetCounterSetup > jcPosPars ;
00182 c.get< L1GctJetCounterPositiveEtaRcd >().get( jcPosPars ) ;
00183 edm::ESHandle< L1GctJetCounterSetup > jcNegPars ;
00184 c.get< L1GctJetCounterNegativeEtaRcd >().get( jcNegPars ) ;
00185 edm::ESHandle< L1GctJetEtCalibrationFunction > calibFun ;
00186 c.get< L1GctJetCalibFunRcd >().get( calibFun ) ;
00187 edm::ESHandle< L1GctHfLutSetup > hfLSetup ;
00188 c.get< L1GctHfLutSetupRcd >().get( hfLSetup ) ;
00189 edm::ESHandle< L1GctChannelMask > chanMask ;
00190 c.get< L1GctChannelMaskRcd >().get( chanMask ) ;
00191 edm::ESHandle< L1CaloEtScale > etScale ;
00192 c.get< L1JetEtScaleRcd >().get( etScale ) ;
00193
00194 if (jfPars.product() == 0) {
00195 success = -1;
00196 edm::LogWarning("L1GctConfigFailure")
00197 << "Failed to find a L1GctJetFinderParamsRcd:L1GctJetFinderParams in EventSetup!" << std::endl;
00198 }
00199
00200 if (calibFun.product() == 0) {
00201 success = -1;
00202 edm::LogWarning("L1GctConfigFailure")
00203 << "Failed to find a L1GctJetCalibFunRcd:L1GctJetEtCalibrationFunction in EventSetup!" << std::endl;
00204 }
00205
00206 if (hfLSetup.product() == 0) {
00207 success = -1;
00208 edm::LogWarning("L1GctConfigFailure")
00209 << "Failed to find a L1GctHfLutSetupRcd:L1GctHfLutSetup in EventSetup!" << std::endl;
00210 }
00211
00212 if (chanMask.product() == 0) {
00213 success = -1;
00214 edm::LogWarning("L1GctConfigFailure")
00215 << "Failed to find a L1GctChannelMaskRcd:L1GctChannelMask in EventSetup!" << std::endl;
00216 }
00217
00218 if (success==0) {
00219
00220 for (unsigned ieta=0; ieta<m_jetEtCalibLuts.size(); ieta++) {
00221 m_jetEtCalibLuts.at(ieta)->setFunction(calibFun.product());
00222 m_jetEtCalibLuts.at(ieta)->setOutputEtScale(etScale.product());
00223 }
00224
00225
00226
00227 m_gct->setJetEtCalibrationLuts(m_jetEtCalibLuts);
00228 m_gct->setJetFinderParams(jfPars.product());
00229 m_gct->setupJetCounterLuts(jcPosPars.product(), jcNegPars.product());
00230 m_gct->setupHfSumLuts(hfLSetup.product());
00231 m_gct->setChannelMask(chanMask.product());
00232
00233 }
00234 }
00235
00236 if (success != 0) {
00237 edm::LogError("L1GctConfigError")
00238 << "Configuration failed - GCT emulator will not be run" << std::endl;
00239 }
00240 return success;
00241 }
00242
00243
00244 void
00245 L1GctPrintLuts::endJob() {
00246 }
00247
00248 DEFINE_ANOTHER_FWK_MODULE(L1GctPrintLuts);
00249