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