CMS 3D CMS Logo

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