CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1RCTLutWriter.cc
Go to the documentation of this file.
2 
4 
11 
12 // default scales
17 
18 // debug scales
22 
25 
26 //
27 // constants, enums and typedefs
28 //
29 
30 //
31 // static data member definitions
32 //
33 
34 //
35 // constructors and destructor
36 //
38  lookupTable_(new L1RCTLookupTables),
39  keyName_(iConfig.getParameter<std::string>("key")),
40  useDebugTpgScales_(iConfig.getParameter<bool>("useDebugTpgScales"))
41 {
42  //now do what ever initialization is needed
43 
44 }
45 
46 
48 {
49 
50  // do anything here that needs to be done at destruction time
51  // (e.g. close files, deallocate resources etc.)
52 
53  if (lookupTable_ != 0) delete lookupTable_;
54 }
55 
56 
57 //
58 // member functions
59 //
60 
61 // ------------ method called to for each event ------------
62 void
64 {
65 
66  // get all the configuration information from the event, set it
67  // in the lookuptable
68  edm::ESHandle<L1RCTParameters> rctParameters;
69  iSetup.get<L1RCTParametersRcd>().get(rctParameters);
70  rctParameters_ = rctParameters.product();
72  iSetup.get<L1EmEtScaleRcd>().get(emScale);
73  const L1CaloEtScale* s = emScale.product();
74 
75  // make dummy channel mask -- we don't want to mask
76  // any channels when writing LUTs, that comes afterwards
78  for (int i = 0; i < 18; i++)
79  {
80  for (int j = 0; j < 2; j++)
81  {
82  for (int k = 0; k < 28; k++)
83  {
84  m->ecalMask[i][j][k] = false;
85  m->hcalMask[i][j][k] = false;
86  }
87  for (int k = 0; k < 4; k++)
88  {
89  m->hfMask[i][j][k] = false;
90  }
91  }
92  }
93 
94 
95  //Same for Noisy mask
96  // make dummy channel mask -- we don't want to mask
97  // any channels when writing LUTs, that comes afterwards
99  for (int i = 0; i < 18; i++)
100  {
101  for (int j = 0; j < 2; j++)
102  {
103  for (int k = 0; k < 28; k++)
104  {
105  m2->ecalMask[i][j][k] = false;
106  m2->hcalMask[i][j][k] = false;
107  }
108  for (int k = 0; k < 4; k++)
109  {
110  m2->hfMask[i][j][k] = false;
111  }
112  }
113  }
114  m2->ecalThreshold = 0.0;
115  m2->hcalThreshold = 0.0;
116  m2->hfThreshold = 0.0;
117 
118 
119 
120  // use these dummies to get the delete right when using old-style
121  // scales to create set of L1CaloXcalScales
122  L1CaloEcalScale* dummyE(0);
123  L1CaloHcalScale* dummyH(0);
124 
125  if (useDebugTpgScales_) // generate new-style scales from tpg scales
126  {
127 
128  std::cout << "Using old-style TPG scales!" << std::endl;
129 
130  // old version of hcal energy scale to convert input
132  iSetup.get<CaloTPGRecord>().get(transcoder);
133  const CaloTPGTranscoder* h_tpg = transcoder.product();
134 
135  // old version of ecal energy scale to convert input
136  EcalTPGScale* e_tpg = new EcalTPGScale();
137  e_tpg->setEventSetup(iSetup);
138 
139  L1CaloEcalScale* ecalScale = new L1CaloEcalScale();
140  L1CaloHcalScale* hcalScale = new L1CaloHcalScale();
141 
142  // generate L1CaloXcalScales from old-style scales (thanks, werner!)
143 
144  // ECAL
145  for( unsigned short ieta = 1 ; ieta <= L1CaloEcalScale::nBinEta; ++ieta )
146  {
147  for( unsigned short irank = 0 ; irank < L1CaloEcalScale::nBinRank; ++irank )
148  {
149  EcalSubdetector subdet = ( ieta <= 17 ) ? EcalBarrel : EcalEndcap ;
150  double etGeVPos =
151  e_tpg->getTPGInGeV
152  ( irank, EcalTrigTowerDetId(1, // +ve eta
153  subdet,
154  ieta,
155  1 )); // dummy phi value
156  ecalScale->setBin( irank, ieta, 1, etGeVPos ) ;
157  }
158  }
159 
160  for( unsigned short ieta = 1 ; ieta <= L1CaloEcalScale::nBinEta; ++ieta )
161  {
162  for( unsigned short irank = 0 ; irank < L1CaloEcalScale::nBinRank; ++irank )
163  {
164  EcalSubdetector subdet = ( ieta <= 17 ) ? EcalBarrel : EcalEndcap ;
165 
166  double etGeVNeg =
167  e_tpg->getTPGInGeV
168  ( irank,
169  EcalTrigTowerDetId(-1, // -ve eta
170  subdet,
171  ieta,
172  2 )); // dummy phi value
173  ecalScale->setBin( irank, ieta, -1, etGeVNeg ) ;
174  }
175  }
176 
177  // HCAL
178  for( unsigned short ieta = 1 ; ieta <= L1CaloHcalScale::nBinEta; ++ieta )
179  {
180  for( unsigned short irank = 0 ; irank < L1CaloHcalScale::nBinRank; ++irank )
181  {
182  double etGeV = h_tpg->hcaletValue( ieta, irank ) ;
183 
184  hcalScale->setBin( irank, ieta, 1, etGeV ) ;
185  hcalScale->setBin( irank, ieta, -1, etGeV ) ;
186  }
187  }
188 
189  // set the input scales
190  lookupTable_->setEcalScale(ecalScale);
191  lookupTable_->setHcalScale(hcalScale);
192 
193  dummyE = ecalScale;
194  dummyH = hcalScale;
195 
196  delete e_tpg;
197 
198  }
199  else
200  {
201 
202  // get energy scale to convert input from ECAL
204  iSetup.get<L1CaloEcalScaleRcd>().get(ecalScale);
205  const L1CaloEcalScale* e = ecalScale.product();
206 
207  // get energy scale to convert input from HCAL
209  iSetup.get<L1CaloHcalScaleRcd>().get(hcalScale);
210  const L1CaloHcalScale* h = hcalScale.product();
211 
212  // set scales
215 
216  }
217 
221  //lookupTable_->setHcalScale(h);
222  //lookupTable_->setEcalScale(e);
224 
225  for (unsigned short nCard = 0; nCard <= 6; nCard = nCard + 2)
226  {
227  writeRcLutFile(nCard);
228  writeEicLutFile(nCard);
229  }
230  writeJscLutFile();
231 
232  unsigned int eicThreshold = rctParameters_->eicIsolationThreshold();
233  unsigned int jscThresholdBarrel = rctParameters_->jscQuietThresholdBarrel();
234  unsigned int jscThresholdEndcap = rctParameters_->jscQuietThresholdEndcap();
235  writeThresholdsFile(eicThreshold, jscThresholdBarrel, jscThresholdEndcap);
236 
237  if (dummyE != 0) delete dummyE;
238  if (dummyH != 0) delete dummyH;
239 
240 }
241 
242 
243 
244 
245 // ------------ method called once each job just after ending the event loop ------------
246 void
248 }
249 
250 
251 // ------------ method to write one receiver card lut file
252 void
253 L1RCTLutWriter::writeRcLutFile(unsigned short card)
254 {
255 
256  // don't mess yet with name
257  char filename[256];
258  char command[64];
259  if (card != 6)
260  {
261  int card2 = card + 1;
262  sprintf(filename,"RC%i%i-%s.dat",card,card2,keyName_.c_str() );
263  //sprintf(filename, "RC%i%i.dat", card, card2);
264  }
265  else
266  {
267  sprintf(filename,"RC6-%s.dat",keyName_.c_str() );
268  //sprintf(filename, "RC6.dat");
269  }
270  // open file for writing, delete any existing content
271  lutFile_.open(filename, std::ios::trunc);
272  lutFile_ << "Emulator-parameter generated lut file, card "
273  << card << " key " << keyName_ << " ";
274 
275  // close to append timestamp info
276  lutFile_.close();
277  sprintf(command, "date >> %s", filename);
278  system(command);
279 
280  // reopen file for writing values
281  lutFile_.open(filename, std::ios::app);
282 
283  unsigned long data = 0;
284 
285  // write all memory addresses in increasing order
286  // address = (1<<22)+(nLUT<<19)+(eG?<18)+(hcalEt<<10)+(ecalfg<<9)+(ecalEt<<1)
287 
288  // loop through the physical LUTs on the card, 0-7
289  for (unsigned short nLUT = 0; nLUT < 8; nLUT++)
290  {
291  // determine ieta, iphi, etc. everything
292  unsigned short iAbsEta = 0;
293  if (card != 6)
294  {
295  iAbsEta = (card/2)*8 + nLUT + 1;
296  }
297  else
298  {
299  if (nLUT < 4)
300  {
301  iAbsEta = (card/2)*8 + nLUT + 1;
302  }
303  else
304  {
305  iAbsEta = (card/2)*8 + (3 - (nLUT%4) ) + 1;
306  }
307  //std::cout << "LUT is " << nLUT << " iAbsEta is " << iAbsEta << std::endl;
308  }
309 
310 
311  // All RCT stuff uniform in phi, symmetric wrt eta = 0
312 
313  // below line always gives crate in +eta; makes no difference to us
314  unsigned short crate = rctParameters_->calcCrate(1, iAbsEta);
315  unsigned short tower = rctParameters_->calcTower(1, iAbsEta);
316 
317  // first do region sums half of LUTs, bit 18 of address is 0
318  // loop through 8 bits of hcal energy, 2^8 is 256
319  for (unsigned int hcalEt = 0; hcalEt < 256; hcalEt++)
320  {
321  // loop through 1 bit of ecal fine grain
322  for (unsigned short ecalfg = 0; ecalfg < 2; ecalfg++)
323  {
324  // loop through 8 bits of ecal energy
325  for (unsigned int ecalEt = 0; ecalEt < 256; ecalEt++)
326  {
327  // assign 10-bit (9et,1mip) sums data here!
328  unsigned long output = lookupTable_->
329  lookup(ecalEt, hcalEt, ecalfg, crate, card, tower);
330  unsigned short etIn9Bits = (output>>8)&511;
331  unsigned short tauActivityBit = (output>>17)&1;
332  data = (tauActivityBit<<9)+etIn9Bits;
333  lutFile_ << std::hex << data << std::dec << std::endl;
334  }
335  }
336  }
337  // second do egamma half of LUTs, bit 18 of address is 1
338  // loop through 8 bits of hcal energy
339  for (unsigned int hcalEt = 0; hcalEt < 256; hcalEt++)
340  {
341  // loop through 1 bit of ecal fine grain
342  for (unsigned short ecalfg = 0; ecalfg < 2; ecalfg++)
343  {
344  // loop through 8 bits of ecal energy
345  for (unsigned int ecalEt = 0; ecalEt < 256; ecalEt++)
346  {
347  // assign 8-bit (7et,1veto) egamma data here!
348  unsigned long output = lookupTable_->
349  lookup(ecalEt, hcalEt, ecalfg, crate, card, tower);
350  unsigned short etIn7Bits = output&127;
351  unsigned short heFgVetoBit = (output>>7)&1;
352  data = (heFgVetoBit<<7)+etIn7Bits;
353  lutFile_ << std::hex << data << std::dec << std::endl;
354  }
355  }
356  }
357  }
358 
359  lutFile_.close();
360  return;
361 
362 }
363 
364 // ------------ method to write one electron isolation card lut file
365 void
367 {
368  // try timestamp
369  char filename[256];
370  char command[64];
371  if (card != 6)
372  {
373  int card2 = card + 1;
374  sprintf(filename,"EIC%i%i-%s.dat", card, card2, keyName_.c_str() );
375  }
376  else
377  {
378  sprintf(filename,"EIC6-%s.dat", keyName_.c_str() );
379  }
380  // open file for writing, delete any existing content
381  lutFile_.open(filename, std::ios::trunc);
382  lutFile_ << "Emulator-parameter generated EIC lut file, card "
383  << card << " key " << keyName_ << " ";
384  // close to append timestamp info
385  lutFile_.close();
386  sprintf(command, "date >> %s", filename);
387  system(command);
388 
389  // reopen file for writing values
390  lutFile_.open(filename, std::ios::app);
391 
392  unsigned long data = 0;
393 
394  // write all memory addresses in increasing order
395  // address = (1<<22) + (etIn7Bits<<1)
396 
397  // 2^7 = 0x7f = 128
398  for (int etIn7Bits = 0; etIn7Bits < 128; etIn7Bits++)
399  {
400  data = lookupTable_->emRank(etIn7Bits);
401  if (data > 0x3f)
402  {
403  data = 0x3f;
404  }
405  lutFile_ << std::hex << data << std::dec << std::endl;
406  }
407  lutFile_.close();
408  return;
409 }
410 
411 // ------------ method to write one jet summary card lut file
412 void
414 {
415  char filename[256];
416  char command[64];
417  sprintf(filename, "JSC-%s.dat", keyName_.c_str() );
418 
419  // open file; if it already existed, delete existing content
420  lutFile_.open(filename, std::ios::trunc);
421  lutFile_ << "Emulator parameter-generated lut file, key " << keyName_
422  << " ";
423  // close to append time-stamp
424  lutFile_.close();
425  sprintf(command, "date >> %s", filename);
426  system(command);
427  // reopen file for writing
428  lutFile_.open(filename, std::ios::app);
429 
430  unsigned long data = 0;
431  unsigned long data0 = 0;
432  unsigned long data1 = 0;
433 
434  // write all memory addresses in increasing order
435  // address = (1<<22) + (lutbits<<17) + (phi1et<<9) + (phi0et<<1);
436 
437  // ecl and U93/U225 lut id bits, identify eta segment of hf
438  for (int lutbits = 0; lutbits < 4; lutbits++)
439  {
440  // 8-bit phi_1 et for each eta partition
441  for (unsigned int phi1et = 0; phi1et < 256; phi1et++)
442  {
443  // 8-bit phi_0 et for each eta
444  for (unsigned int phi0et = 0; phi0et < 256; phi0et++)
445  {
446  // lookup takes "(hf_et, crate, card, tower)"
447  // "card" convention for hf is 999, tower is 0-7
448  // but equivalent to 0-3 == lutbits
449  // crate doesn't matter, take 0
450  // only |ieta| matters
451  data0 = lookupTable_->lookup(phi0et, 0, 999, lutbits);
452  if (data0 > 0xff)
453  {
454  data0 = 0xff; // 8-bit output energy for each phi region
455  }
456  data1 = lookupTable_->lookup(phi1et, 0, 999, lutbits);
457  if (data1 > 0xff)
458  {
459  data1 = 0xff; // 8-bit output energy for each phi region
460  }
461  data = (data1<<8) + (data0);
462  lutFile_ << std::hex << data << std::dec << std::endl;
463  /*
464  if (phi0et < 10 && phi1et < 10)
465  {
466  std::cout << "Writer: jsc. lutbits=" << lutbits
467  << " phi0et=" << phi0et << " data0=" << data0
468  << " phi1et=" << phi1et << " data1=" << data1
469  << std::endl;
470  }
471  */
472  }
473  }
474  }
475 
476  lutFile_.close();
477  return;
478 }
479 
480 //-----------Write text file containing the 1 JSC and 2 EIC thresholds
481 void
482 L1RCTLutWriter::writeThresholdsFile(unsigned int eicThreshold,
483  unsigned int jscThresholdBarrel,
484  unsigned int jscThresholdEndcap)
485 {
486  //
487  std::ofstream thresholdsFile;
488  char filename[256];
489  sprintf(filename, "Thresholds-%s.dat", keyName_.c_str() );
490  thresholdsFile.open(filename, std::ios::trunc);
491 
492  thresholdsFile << "key is " << keyName_ << std::endl << std::endl;
493  thresholdsFile << "eicIsolationThreshold " << eicThreshold << std::endl;
494  thresholdsFile << "jscQuietThresholdBarrel " << jscThresholdBarrel << std::endl;
495  thresholdsFile << "jscQuietThresholdEndcap " << jscThresholdEndcap << std::endl;
496 
497  thresholdsFile.close();
498 }
499 
500 //define this as a plug-in
501 //DEFINE_FWK_MODULE(L1RCTLutWriter); // done in SealModule.cc
int i
Definition: DBlmapReader.cc:9
const L1RCTParameters * rctParameters_
L1RCTLutWriter(const edm::ParameterSet &)
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
void setEventSetup(const edm::EventSetup &evtSetup)
Definition: EcalTPGScale.cc:19
void writeRcLutFile(unsigned short card)
unsigned eicIsolationThreshold() const
bool ecalMask[18][2][28]
void setBin(unsigned short rank, unsigned short eta, short etaSign, double et)
set scale element; use this to create non-linear scales
L1RCTLookupTables * lookupTable_
void setBin(unsigned short rank, unsigned short eta, short etaSign, double et)
set scale element; use this to create non-linear scales
double getTPGInGeV(const EcalTriggerPrimitiveDigi &tpDigi)
Definition: EcalTPGScale.cc:24
unsigned jscQuietThresholdEndcap() const
std::string keyName_
int iEvent
Definition: GenABIO.cc:230
unsigned short calcTower(unsigned short rct_iphi, unsigned short absIeta) const
void setHcalScale(const L1CaloHcalScale *hcalScale)
static const unsigned short nBinRank
void writeThresholdsFile(unsigned int eicThreshold, unsigned int jscThresholdBarrel, unsigned int jscThresholdEndcap)
unsigned int emRank(unsigned short energy) const
int j
Definition: DBlmapReader.cc:9
virtual void endJob()
void setL1CaloEtScale(const L1CaloEtScale *etScale)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
void setEcalScale(const L1CaloEcalScale *ecalScale)
std::ofstream lutFile_
void setRCTParameters(const L1RCTParameters *rctParameters)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
static const unsigned short nBinRank
void setNoisyChannelMask(const L1RCTNoisyChannelMask *channelMask)
tuple filename
Definition: lut2db_cfg.py:20
static const unsigned short nBinEta
static const unsigned short nBinEta
bool hcalMask[18][2][28]
tuple cout
Definition: gather_cfg.py:145
void writeEicLutFile(unsigned short card)
EcalSubdetector
bool hfMask[18][2][4]
void setChannelMask(const L1RCTChannelMask *channelMask)
unsigned short calcCrate(unsigned short rct_iphi, short ieta) const
unsigned jscQuietThresholdBarrel() const
unsigned int lookup(unsigned short ecalInput, unsigned short hcalInput, unsigned short fgbit, unsigned short crtNo, unsigned short crdNo, unsigned short twrNo) const
virtual double hcaletValue(const int &ieta, const int &compET) const =0