CMS 3D CMS Logo

L1GctPrintLuts.cc
Go to the documentation of this file.
2 
6 
8 
9 // GCT include files
18 
19 #include <iostream>
20 #include <fstream>
21 #include <sys/stat.h>
22 
24  : m_jetRanksOutFileName(iConfig.getUntrackedParameter<std::string>("jetRanksFilename", "gctJetRanksContents.txt")),
25  m_hfSumLutOutFileName(iConfig.getUntrackedParameter<std::string>("hfSumLutFilename", "gctHfSumLutContents.txt")),
26  m_htMissLutOutFileName(
27  iConfig.getUntrackedParameter<std::string>("htMissLutFilename", "gctHtMissLutContents.txt")),
28  m_gct(new L1GlobalCaloTrigger(L1GctJetLeafCard::hardwareJetFinder)),
29  m_jetEtCalibLuts() {
30  // Fill the jetEtCalibLuts vector
31  lutPtr nextLut(new L1GctJetEtCalibrationLut());
32 
33  for (unsigned ieta = 0; ieta < L1GctJetFinderBase::COL_OFFSET; ieta++) {
34  nextLut->setEtaBin(ieta);
35  m_jetEtCalibLuts.push_back(nextLut);
36  nextLut.reset(new L1GctJetEtCalibrationLut());
37  }
38  m_jfParsToken = esConsumes<L1GctJetFinderParams, L1GctJetFinderParamsRcd>();
39  m_etScaleToken = esConsumes<L1CaloEtScale, L1JetEtScaleRcd>();
40  m_htMissScaleToken = esConsumes<L1CaloEtScale, L1HtMissScaleRcd>();
41  m_hfRingEtScaleToken = esConsumes<L1CaloEtScale, L1HfRingEtScaleRcd>();
42 }
43 
45  // do anything here that needs to be done at desctruction time
46  // (e.g. close files, deallocate resources etc.)
47 }
48 
49 //
50 // member functions
51 //
52 
53 // ------------ method called to for each event ------------
55  // get config data from EventSetup
56  // check this has been done successfully before proceeding
57  if (configureGct(iSetup) == 0) {
58  // Write to a new file
59  struct stat buffer;
60  if (!stat(m_jetRanksOutFileName.c_str(), &buffer)) {
61  edm::LogWarning("LutFileExists") << "File " << m_jetRanksOutFileName
62  << " already exists. It will not be overwritten." << std::endl;
63  } else {
64  std::ofstream file;
65  file.open(m_jetRanksOutFileName.c_str());
66 
67  if (file.good()) {
68  // Print the calibration lut contents
69  file << " Gct lookup table printout \n"
70  << "===========================\n\n"
71  << "Jet Et Calibration lut contents\n"
72  << std::endl;
73  for (unsigned ieta = 0; ieta < m_jetEtCalibLuts.size(); ieta++) {
74  file << *m_jetEtCalibLuts.at(ieta) << std::endl;
75  }
76  } else {
77  edm::LogWarning("LutFileError") << "Error opening file " << m_jetRanksOutFileName
78  << ". No lookup tables written." << std::endl;
79  }
80  file.close();
81  }
82 
83  if (!stat(m_hfSumLutOutFileName.c_str(), &buffer)) {
84  edm::LogWarning("LutFileExists") << "File " << m_hfSumLutOutFileName
85  << " already exists. It will not be overwritten." << std::endl;
86  } else {
87  std::ofstream file;
88  file.open(m_hfSumLutOutFileName.c_str());
89 
90  if (file.good()) {
91  // Print the Hf luts
92  file << "\n\n Hf ring jet bit count luts:" << std::endl;
93  file << "\n Positive eta, ring1" << std::endl;
95  << std::endl;
96  file << "\n Positive eta, ring2" << std::endl;
98  << std::endl;
99  file << "\n Negative eta, ring1" << std::endl;
101  << std::endl;
102  file << "\n Negative eta, ring2" << std::endl;
104  << std::endl;
105  file << "\n\n Hf Et sum luts:" << std::endl;
106  file << "\n Positive eta, ring1" << std::endl;
108  << std::endl;
109  file << "\n Positive eta, ring2" << std::endl;
111  << std::endl;
112  file << "\n Negative eta, ring1" << std::endl;
114  << std::endl;
115  file << "\n Negative eta, ring2" << std::endl;
117  << std::endl;
118  } else {
119  edm::LogWarning("LutFileError") << "Error opening file " << m_hfSumLutOutFileName
120  << ". No lookup tables written." << std::endl;
121  }
122  file.close();
123  }
124 
125  if (!stat(m_htMissLutOutFileName.c_str(), &buffer)) {
126  edm::LogWarning("LutFileExists") << "File " << m_htMissLutOutFileName
127  << " already exists. It will not be overwritten." << std::endl;
128  } else {
129  std::ofstream file;
130  file.open(m_htMissLutOutFileName.c_str());
131 
132  if (file.good()) {
133  // Print the HtMiss luts
134  file << "\n\n missing Ht lut:" << std::endl;
135  file << *m_gct->getEnergyFinalStage()->getHtMissLut() << std::endl;
136  } else {
137  edm::LogWarning("LutFileError") << "Error opening file " << m_hfSumLutOutFileName
138  << ". No lookup tables written." << std::endl;
139  }
140  file.close();
141  }
142  }
143 }
144 
145 // ------------ method called once each job just before starting event loop ------------
146 // This is where we work ...
148 
149 // The configuration method for the Gct - copied from L1GctEmulator
151  int success = 0;
152 
153  if (success == 0) {
154  // get data from EventSetup
156  edm::ESHandle<L1CaloEtScale> hfRingEtScale = c.getHandle(m_hfRingEtScaleToken);
157  edm::ESHandle<L1CaloEtScale> htMissScale = c.getHandle(m_htMissScaleToken);
159 
160  if (jfPars.product() == nullptr) {
161  success = -1;
162  edm::LogWarning("L1GctConfigFailure")
163  << "Failed to find a L1GctJetFinderParamsRcd:L1GctJetFinderParams in EventSetup!" << std::endl;
164  }
165 
166  if (hfRingEtScale.product() == nullptr) {
167  success = -1;
168  edm::LogWarning("L1GctConfigFailure")
169  << "Failed to find a L1HfRingEtScaleRcd:L1CaloEtScale in EventSetup!" << std::endl;
170  }
171 
172  if (htMissScale.product() == nullptr) {
173  success = -1;
174  edm::LogWarning("L1GctConfigFailure")
175  << "Failed to find a L1HtMissScaleRcd:L1CaloEtScale in EventSetup!" << std::endl;
176  }
177 
178  // if (chanMask.product() == 0) {
179  // success = -1;
180  // edm::LogWarning("L1GctConfigFailure")
181  // << "Failed to find a L1GctChannelMaskRcd:L1GctChannelMask in EventSetup!" << std::endl;
182  // }
183 
184  if (success == 0) {
185  // tell the jet Et Luts about the scales
186  for (unsigned ieta = 0; ieta < m_jetEtCalibLuts.size(); ieta++) {
187  m_jetEtCalibLuts.at(ieta)->setFunction(jfPars.product());
188  m_jetEtCalibLuts.at(ieta)->setOutputEtScale(etScale.product());
189  }
190 
191  // pass all the setup info to the gct
193  m_gct->setJetFinderParams(jfPars.product());
194  m_gct->setHtMissScale(htMissScale.product());
195  m_gct->setupHfSumLuts(hfRingEtScale.product());
196  // m_gct->setChannelMask(chanMask.product());
197  }
198  }
199 
200  if (success != 0) {
201  edm::LogError("L1GctConfigError") << "Configuration failed - GCT emulator will not be run" << std::endl;
202  }
203  return success;
204 }
205 
206 // ------------ method called once each job just after ending the event loop ------------
208 
L1GctGlobalHfSumAlgos * getHfSumProcessor() const
provide access to hf sum processor
Jet Et calibration LUT.
L1GctGlobalEnergyAlgos * getEnergyFinalStage() const
get the energy final stage
lutPtrVector m_jetEtCalibLuts
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void setJetFinderParams(const L1GctJetFinderParams *const jfpars)
L1GctPrintLuts(const edm::ParameterSet &)
Log< level::Error, false > LogError
const L1GctHfBitCountsLut * getBCLut(const L1GctHfEtSumsLut::hfLutType type) const
Get lut pointers.
Bit-level emulation of the Global Calorimeter Trigger.
edm::ESGetToken< L1CaloEtScale, L1HtMissScaleRcd > m_htMissScaleToken
int iEvent
Definition: GenABIO.cc:224
T const * product() const
Definition: ESHandle.h:86
void setHtMissScale(const L1CaloEtScale *const scale)
setup scale for missing Ht
L1GlobalCaloTrigger::lutPtr lutPtr
typedefs
void analyze(const edm::Event &, const edm::EventSetup &) override
std::string m_hfSumLutOutFileName
int configureGct(const edm::EventSetup &c)
edm::ESGetToken< L1CaloEtScale, L1JetEtScaleRcd > m_etScaleToken
void setupHfSumLuts(const L1CaloEtScale *const scale)
setup Hf sum LUTs
static const unsigned int COL_OFFSET
The index offset between columns.
void setJetEtCalibrationLuts(const lutPtrVector &jfluts)
setup the Jet Calibration Luts
const L1GctHfEtSumsLut * getESLut(const L1GctHfEtSumsLut::hfLutType type) const
std::string m_jetRanksOutFileName
L1GlobalCaloTrigger * m_gct
std::string m_htMissLutOutFileName
edm::ESGetToken< L1GctJetFinderParams, L1GctJetFinderParamsRcd > m_jfParsToken
const L1GctHtMissLut * getHtMissLut() const
void beginJob() override
Log< level::Warning, false > LogWarning
edm::ESGetToken< L1CaloEtScale, L1HfRingEtScaleRcd > m_hfRingEtScaleToken
~L1GctPrintLuts() override
void endJob() override