CMS 3D CMS Logo

L1CaloInputScalesGenerator.cc
Go to the documentation of this file.
2 
3 // system include files
4 #include <memory>
5 #include <iostream>
6 using std::cout;
7 using std::endl;
8 #include <iomanip>
9 using std::setprecision;
10 #include <fstream>
11 using std::ofstream;
12 
13 
14 // user include files
16 
20 
22 
27 
28 
29 //
30 // constants, enums and typedefs
31 //
32 
33 //
34 // static data member definitions
35 //
36 
37 //
38 // constructors and destructor
39 //
41 
42 {
43  //now do what ever initialization is needed
44 
45 }
46 
47 
49 {
50 
51  // do anything here that needs to be done at desctruction time
52  // (e.g. close files, deallocate resources etc.)
53 
54 }
55 
56 
57 //
58 // member functions
59 //
60 
61 // ------------ method called to for each event ------------
62 void
64 {
65  using namespace edm;
66 
67 
68  ESHandle<CaloTPGTranscoder> caloTPGTranscoder;
69  iSetup.get<CaloTPGRecord>().get(caloTPGTranscoder);
70 
71  EcalTPGScale* ecalTPGScale = new EcalTPGScale();
72  ecalTPGScale->setEventSetup(iSetup);
73 
74  double output;
75  ofstream scalesFile("L1CaloInputScales_cfi.py");
76 
77 
78  // Write the ecal scales, positive eta
79 
80  scalesFile << "import FWCore.ParameterSet.Config as cms\n" <<endl;
81 
82  scalesFile << "L1CaloInputScalesProducer =cms.ESProducer(\"L1CaloInputScalesProducer\"," << endl;
83  scalesFile << "L1EcalEtThresholdsPositiveEta = cms.vdouble(" << endl;
84 
85 
86  //Python does not support arrays over 255 entries so we neeed ton accomodate it by creating new array after 255 entries
87  int nEntries = 0;
88 
89 
90 
91  // loop over ietas, barrel
92  for (unsigned short absIeta = 1; absIeta <= 28; absIeta++)
93  {
94  EcalSubdetector subdet = ( absIeta <= 17 ) ? EcalBarrel : EcalEndcap ;
95  // 8 bits of input energy
96  for (unsigned short input = 0; input <= 0xFF; input++)
97  {
98  output = ecalTPGScale->getTPGInGeV( (unsigned int) input,
99  EcalTrigTowerDetId(1, subdet,
100  absIeta, 1));
101  scalesFile << setprecision (8) << output;
102  nEntries++;
103 
104  if (absIeta == 28 && input == 0xFF)
105  {
106  scalesFile << "),";
107  }
108  else if(nEntries>254)
109  {
110  scalesFile <<")+cms.vdouble(";
111  nEntries=0;
112  }
113  else
114  {
115  scalesFile << ", ";
116  }
117  }
118  scalesFile << endl;
119  }
120 
121  // Write the ecal scales, negative eta
122 
123  scalesFile << endl << "\tL1EcalEtThresholdsNegativeEta = cms.vdouble(" << endl;
124 
125  nEntries=0;
126  // loop over ietas, barrel first
127  for (unsigned short absIeta = 1; absIeta <= 28; absIeta++)
128  {
129  EcalSubdetector subdet = ( absIeta <= 17 ) ? EcalBarrel : EcalEndcap ;
130  // 8 bits of input energy
131  for (unsigned short input = 0; input <= 0xFF; input++)
132  {
133  // negative eta
134  output = ecalTPGScale->
135  getTPGInGeV( (unsigned int) input, EcalTrigTowerDetId(-1, subdet,
136  absIeta, 2));
137  scalesFile << setprecision (8) << output;
138  nEntries++;
139 
140 
141 
142  if (absIeta == 28 && input == 0xFF)
143  {
144  scalesFile << "),";
145  }
146  else if(nEntries>254)
147  {
148  scalesFile <<")+cms.vdouble(";
149  nEntries=0;
150  }
151  else
152  {
153  scalesFile << ", ";
154  }
155  }
156  scalesFile << endl;
157  }
158 
159  // Write the hcal scales (Positive Eta)
160 
161  scalesFile << endl << "\tL1HcalEtThresholdsPositiveEta = cms.vdouble(" << endl;
162 
163  // loop over ietas
164 
165  nEntries=0;
166  for (unsigned short absIeta = 1; absIeta <= 32; absIeta++)
167  {
168  for (unsigned short input = 0; input <= 0xFF; input++)
169  {
170  output = caloTPGTranscoder->hcaletValue(absIeta, input);
171  scalesFile << setprecision (8) << output ;
172  nEntries++;
173 
174 
175  if (absIeta == 32 && input == 0xFF)
176  {
177  scalesFile << "),";
178  }
179  else if(nEntries>254)
180  {
181  scalesFile <<")+cms.vdouble(";
182  nEntries=0;
183  }
184  else
185  {
186  scalesFile << ", ";
187  }
188  }
189  scalesFile << endl;
190  }
191 
192  // Write the hcal scales (Negative Eta)
193 
194  scalesFile << endl << "\tL1HcalEtThresholdsNegativeEta = cms.vdouble(" << endl;
195 
196  nEntries=0;
197  // loop over ietas
198  for (unsigned short absIeta = 1; absIeta <= 32; absIeta++)
199  {
200  for (unsigned short input = 0; input <= 0xFF; input++)
201  {
202  output = caloTPGTranscoder->hcaletValue(-absIeta, input);
203  scalesFile << setprecision (8) << output ;
204  nEntries++;
205 
206 
207  if (absIeta == 32 && input == 0xFF)
208  {
209  scalesFile << ")";
210  }
211  else if(nEntries>254)
212  {
213  scalesFile <<")+cms.vdouble(";
214  nEntries=0;
215  }
216  else
217  {
218  scalesFile << ", ";
219  }
220  }
221  scalesFile << endl;
222  }
223 
224 
225  scalesFile << ")" << endl;
226 
227  scalesFile.close();
228 }
229 
230 
231 // ------------ method called once each job just before starting event loop ------------
232 void
234 {
235 }
236 
237 // ------------ method called once each job just after ending the event loop ------------
238 void
240 }
241 
void analyze(const edm::Event &, const edm::EventSetup &) override
void setEventSetup(const edm::EventSetup &evtSetup)
Definition: EcalTPGScale.cc:19
double getTPGInGeV(const EcalTriggerPrimitiveDigi &tpDigi)
Definition: EcalTPGScale.cc:24
static std::string const input
Definition: EdmProvDump.cc:44
int iEvent
Definition: GenABIO.cc:230
L1CaloInputScalesGenerator(const edm::ParameterSet &)
HLT enums.
T get() const
Definition: EventSetup.h:63
virtual double hcaletValue(const int &ieta, const int &iphi, const int &version, const int &compressedValue) const =0
EcalSubdetector