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