CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TCaloStage1LutWriter.cc
Go to the documentation of this file.
1 // L1TCaloStage1LutWriter.cc
2 // Author: Leonard Apanasevich
3 //
4 
10 
15 
17 
18 #include <iostream>
19 #include <fstream>
20 #include <sys/stat.h>
21 
22 //
23 // class declaration
24 //
25 
26 namespace l1t {
27 
29 public:
32 
33  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
34 
35  void writeIsoTauLut(const std::string& fileName);
36  bool openOutputFile(const std::string& fileName, std::ofstream& file);
37 
38 private:
39  virtual void beginJob() override;
40  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
41  virtual void endJob() override;
42 
45 
47 
49  // output file names
51  // std::string m_EGammaLutName;
52 };
53 
54 //
55 // constructors and destructor
56 //
58 {
59  //now do what ever initialization is needed
60  m_writeIsoTauLut = iConfig.getUntrackedParameter<bool>("writeIsoTauLut", false );
61  m_isoTauLutName = iConfig.getUntrackedParameter<std::string>("isoTauLutName", "isoTauLut.txt" );
62  m_conditionsLabel = iConfig.getParameter<std::string>("conditionsLabel");
63 
65  isoTauLut = new Stage1TauIsolationLUT(m_params);
66 
67 };
68 
70 {
71  delete isoTauLut;
72 };
73 
74 // ------------ method called for each event ------------
75 void
77 {
78  edm::ESHandle<CaloParams> paramsHandle;
79  iSetup.get<L1TCaloParamsRcd>().get(m_conditionsLabel, paramsHandle);
80  m_params = new (m_params) CaloParamsHelper(*paramsHandle.product());
81  if (! m_params){
82  std::cout << "Could not retrieve params from Event Setup" << std::endl;
83  return;
84  }
85  LogDebug("L1TDebug") << *m_params << std::endl;
86 
88 
89 }
90 
91 bool
93 {
94  // Write to a new file
95  struct stat buffer ;
96  if ( !stat( fileName.c_str(), &buffer ) ) {
97  std::cout << "File " << fileName << " already exists. It will not be overwritten." << std::endl;
98  return false;
99  } else {
100  file.open( fileName.c_str() );
101  if ( ! file.good()) {
102  std::cout << "Error opening file " << fileName << std::endl;
103  return false;
104  }
105  }
106  return true;
107 }
108 
110 {
111  std::ofstream file;
112  if (openOutputFile(fileName,file)) {
113  std::cout << "Writing tau isolation LUT to: " << fileName << std::endl;
114  file << "########################################\n"
115  << "# tauIsolation LUT for ISOL(A)= " << m_params->tauMaxJetIsolationA()
116  << " ISOL(B)= " << m_params->tauMaxJetIsolationB() << "\n"
117  << "# Switch to ISOLB value at pt= " << m_params->tauMinPtJetIsolationB() << "\n"
118  << "#<header> V" << Stage1TauIsolationLUT::lut_version << " "
120  << Stage1TauIsolationLUT::nbits_data << " </header>\n"
121  << "# Format: Address Payload ## hwTauPt hwJetPt\n"
122  << "########################################\n";
123 
125  for (unsigned iAdd=0; iAdd<maxAdd; iAdd++) {
126  int isoFlag= isoTauLut->lutPayload(iAdd);
127  file << iAdd << " " << isoFlag << "\n";
128  }
129  } else {
130  std::cout << "%Error opening output file. Tau isolation LUT not written." << std::endl;
131  }
132  file.close();
133 
134 }
135 // ------------ method called once each job just before starting event loop ------------
137 {
138 
139 }
140 
141 // ------------ method called once each job just after ending the event loop ------------
143 {
144 }
145 
146 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
147 void
149  //The following says we do not know what parameters are allowed so do no validation
150  // Please change this to state exactly what you do use, even if it is no parameters
152  desc.setUnknown();
153  descriptions.addDefault(desc);
154 }
155 
156 }
157 using namespace l1t;
158 
159 //define this as a plug-in
161 
162 
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
static const unsigned int nbits_data
double tauMaxJetIsolationB() const
double tauMinPtJetIsolationB() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Stage1TauIsolationLUT * isoTauLut
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
static const unsigned int nbitsTau
static const unsigned int nbitsJet
virtual void beginJob() override
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
static const unsigned int lut_version
L1TCaloStage1LutWriter(const edm::ParameterSet &)
void writeIsoTauLut(const std::string &fileName)
int lutPayload(unsigned int) const
tuple cout
Definition: gather_cfg.py:121
bool openOutputFile(const std::string &fileName, std::ofstream &file)
volatile std::atomic< bool > shutdown_flag false
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
double tauMaxJetIsolationA() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)