CMS 3D CMS Logo

L1RCTParameters.cc
Go to the documentation of this file.
1 
7 #include <iostream>
8 #include <fstream>
9 #include <cmath>
10 
12 #include <iomanip>
13 
15 using namespace std;
16 
18  double jetMETLSB,
19  double eMinForFGCut,
20  double eMaxForFGCut,
21  double hOeCut,
22  double eMinForHoECut,
23  double eMaxForHoECut,
24  double hMinForHoECut,
25  double eActivityCut,
26  double hActivityCut,
27  unsigned eicIsolationThreshold,
28  unsigned jscQuietThresholdBarrel,
29  unsigned jscQuietThresholdEndcap,
30  bool noiseVetoHB,
31  bool noiseVetoHEplus,
32  bool noiseVetoHEminus,
33  bool useCorrections,
34  const std::vector<double>& eGammaECalScaleFactors,
35  const std::vector<double>& eGammaHCalScaleFactors,
36  const std::vector<double>& jetMETECalScaleFactors,
37  const std::vector<double>& jetMETHCalScaleFactors,
38  const std::vector<double>& ecal_calib,
39  const std::vector<double>& hcal_calib,
40  const std::vector<double>& hcal_high_calib,
41  const std::vector<double>& cross_terms,
42  const std::vector<double>& lowHoverE_smear,
43  const std::vector<double>& highHoverE_smear)
44  : eGammaLSB_(eGammaLSB),
45  jetMETLSB_(jetMETLSB),
46  eMinForFGCut_(eMinForFGCut),
47  eMaxForFGCut_(eMaxForFGCut),
48  hOeCut_(hOeCut),
49  eMinForHoECut_(eMinForHoECut),
50  eMaxForHoECut_(eMaxForHoECut),
51  hMinForHoECut_(hMinForHoECut),
52  eActivityCut_(eActivityCut),
53  hActivityCut_(hActivityCut),
54  eicIsolationThreshold_(eicIsolationThreshold),
55  jscQuietThresholdBarrel_(jscQuietThresholdBarrel),
56  jscQuietThresholdEndcap_(jscQuietThresholdEndcap),
57  noiseVetoHB_(noiseVetoHB),
58  noiseVetoHEplus_(noiseVetoHEplus),
59  noiseVetoHEminus_(noiseVetoHEminus),
60  useCorrections_(useCorrections),
61  eGammaECalScaleFactors_(eGammaECalScaleFactors),
62  eGammaHCalScaleFactors_(eGammaHCalScaleFactors),
63  jetMETECalScaleFactors_(jetMETECalScaleFactors),
64  jetMETHCalScaleFactors_(jetMETHCalScaleFactors),
65  HoverE_smear_low_(lowHoverE_smear),
66  HoverE_smear_high_(highHoverE_smear) {
67  ecal_calib_.resize(28);
68  hcal_calib_.resize(28);
69  hcal_high_calib_.resize(28);
70  cross_terms_.resize(28);
71 
72  for (unsigned i = 0; i < ecal_calib.size(); ++i)
73  ecal_calib_[i / 3].push_back(ecal_calib[i]);
74  for (unsigned i = 0; i < hcal_calib.size(); ++i)
75  hcal_calib_[i / 3].push_back(hcal_calib[i]);
76  for (unsigned i = 0; i < hcal_high_calib.size(); ++i)
77  hcal_high_calib_[i / 3].push_back(hcal_high_calib[i]);
78  for (unsigned i = 0; i < cross_terms.size(); ++i)
79  cross_terms_[i / 6].push_back(cross_terms[i]);
80 }
81 
82 // maps rct iphi, ieta of tower to crate
83 unsigned short L1RCTParameters::calcCrate(unsigned short rct_iphi, short ieta) const {
84  unsigned short crate = rct_iphi / 8;
85  if (abs(ieta) > 28)
86  crate = rct_iphi / 2;
87  if (ieta > 0) {
88  crate = crate + 9;
89  }
90  return crate;
91 }
92 
93 //map digi rct iphi, ieta to card
94 unsigned short L1RCTParameters::calcCard(unsigned short rct_iphi, unsigned short absIeta) const {
95  unsigned short card = 999;
96  // Note absIeta counts from 1-32 (not 0-31)
97  if (absIeta <= 24) {
98  card = ((absIeta - 1) / 8) * 2 + (rct_iphi % 8) / 4;
99  }
100  // 25 <= absIeta <= 28 (card 6)
101  else if ((absIeta >= 25) && (absIeta <= 28)) {
102  card = 6;
103  } else {
104  }
105  return card;
106 }
107 
108 //map digi rct iphi, ieta to tower
109 unsigned short L1RCTParameters::calcTower(unsigned short rct_iphi, unsigned short absIeta) const {
110  unsigned short tower = 999;
111  unsigned short iphi = rct_iphi;
112  unsigned short regionPhi = (iphi % 8) / 4;
113 
114  // Note absIeta counts from 1-32 (not 0-31)
115  if (absIeta <= 24) {
116  // assume iphi between 0 and 71; makes towers from 0-31, mod. 7Nov07
117  tower = ((absIeta - 1) % 8) * 4 + (iphi % 4); // REMOVED +1
118  }
119  // 25 <= absIeta <= 28 (card 6)
120  else if ((absIeta >= 25) && (absIeta <= 28)) {
121  if (regionPhi == 0) {
122  // towers from 0-31, modified 7Nov07 Jessica Leonard
123  tower = (absIeta - 25) * 4 + (iphi % 4); // REMOVED +1
124  } else {
125  tower = 28 + iphi % 4 + (25 - absIeta) * 4; // mod. 7Nov07 JLL
126  }
127  }
128  // absIeta >= 29 (HF regions)
129  else if ((absIeta >= 29) && (absIeta <= 32)) {
130  // SPECIAL DEFINITION OF REGIONPHI FOR HF SINCE HF IPHI IS 0-17
131  // Sept. 19 J. Leonard
132  regionPhi = iphi % 2;
133  // HF MAPPING, just regions now, don't need to worry about towers
134  // just calling it "tower" for convenience
135  tower = (regionPhi) * 4 + absIeta - 29;
136  }
137  return tower;
138 }
139 
140 // iCrate 0-17, iCard 0-6, NEW iTower 0-31
141 short L1RCTParameters::calcIEta(unsigned short iCrate, unsigned short iCard, unsigned short iTower) const {
142  unsigned short absIEta = calcIAbsEta(iCrate, iCard, iTower);
143  short iEta;
144  if (iCrate < 9)
145  iEta = -absIEta;
146  else
147  iEta = absIEta;
148  return iEta;
149 }
150 
151 // iCrate 0-17, iCard 0-6, NEW iTower 0-31
152 unsigned short L1RCTParameters::calcIPhi(unsigned short iCrate, unsigned short iCard, unsigned short iTower) const {
153  short iPhi;
154  if (iCard < 6)
155  iPhi = (iCrate % 9) * 8 + (iCard % 2) * 4 + (iTower % 4); // rm -1 7Nov07
156  else if (iCard == 6) {
157  // region 0
158  if (iTower < 16) // 17->16
159  iPhi = (iCrate % 9) * 8 + (iTower % 4); // rm -1
160  // region 1
161  else
162  iPhi = (iCrate % 9) * 8 + ((iTower - 16) % 4) + 4; // 17 -> 16
163  }
164  // HF regions
165  else
166  iPhi = (iCrate % 9) * 2 + iTower / 4;
167  return iPhi;
168 }
169 
170 // iCrate 0-17, iCard 0-6, NEW iTower 0-31
171 unsigned short L1RCTParameters::calcIAbsEta(unsigned short iCrate, unsigned short iCard, unsigned short iTower) const {
172  unsigned short absIEta;
173  if (iCard < 6)
174  absIEta = (iCard / 2) * 8 + (iTower / 4) + 1; // rm -1 JLL 7Nov07
175  else if (iCard == 6) {
176  // card 6, region 0
177  if (iTower < 16) // 17->16
178  absIEta = 25 + iTower / 4; // rm -1
179  // card 6, region 1
180  else
181  absIEta = 28 - ((iTower - 16) / 4); // 17->16
182  }
183  // HF regions
184  else
185  absIEta = 29 + iTower % 4;
186  return absIEta;
187 }
188 
189 float L1RCTParameters::JetMETTPGSum(const float& ecal, const float& hcal, const unsigned& iAbsEta) const {
190  // We never deal with HF in this function (see note below)
191  if (iAbsEta < 1 || iAbsEta > 28)
192  throw cms::Exception("L1RCTParameters invalid function call") << "Eta out of range in MET TPGSum: " << iAbsEta;
193  float ecal_c = ecal * jetMETECalScaleFactors_.at(iAbsEta - 1);
194  float hcal_c = hcal * jetMETHCalScaleFactors_.at(iAbsEta - 1);
195 
196  // scale factors will either be length 28 for legacy, or 28*(# et bins + 1) where the first set is an average over the et bins
197  // The first set provides a legacy fallthrough option
198  // Currently, # et bins is 9
199  if (jetMETECalScaleFactors_.size() == 28 * 10) {
200  int et_bin = ((int)floor(ecal) / 5);
201  // lowest bin (1) is 0-10GeV
202  if (et_bin < 1)
203  et_bin = 1;
204  // highest bin (9) is 45GeV and up
205  if (et_bin > 9)
206  et_bin = 9;
207  ecal_c = ecal * jetMETECalScaleFactors_.at(et_bin * 28 + iAbsEta - 1);
208  }
209 
210  // We may be interested in HF jets, in which case, there are four more scale factors
211  // for the 4 HF regions. HOWEVER, we will never expect to see them accessed from
212  // this function. HF scaling is done in L1Trigger/RegionalCaloTrigger/src/L1RCTLookupTables
213  if (jetMETHCalScaleFactors_.size() == 32 * 10) {
214  int ht_bin = ((int)floor(hcal) / 5);
215  // lowest bin (1) is 0-10GeV
216  if (ht_bin < 1)
217  ht_bin = 1;
218  // highest bin (9) is 45GeV and up
219  if (ht_bin > 9)
220  ht_bin = 9;
221  hcal_c = hcal * jetMETHCalScaleFactors_.at(ht_bin * 32 + iAbsEta - 1);
222  }
223 
224  float result = ecal_c + hcal_c;
225 
226  // defunct section (polynomial-parameterized corrections)
227  if (useCorrections_) {
228  if (jetMETHCalScaleFactors_.at(iAbsEta - 1) != 0)
229  hcal_c = hcal;
230 
231  if (jetMETECalScaleFactors_.at(iAbsEta - 1) != 0)
232  ecal_c = ecal * eGammaECalScaleFactors_.at(iAbsEta - 1); // Use eGamma Corrections
233 
234  result = correctedTPGSum(ecal_c, hcal_c, iAbsEta - 1);
235  }
236 
237  return result;
238 }
239 
240 float L1RCTParameters::EGammaTPGSum(const float& ecal, const float& hcal, const unsigned& iAbsEta) const {
241  // We never deal with HF in this function (EG objects don't use hcal at all, really)
242  if (iAbsEta < 1 || iAbsEta > 28)
243  throw cms::Exception("L1RCTParameters invalid function call") << "Eta out of range in MET TPGSum: " << iAbsEta;
244  float ecal_c = ecal * eGammaECalScaleFactors_.at(iAbsEta - 1);
245  float hcal_c = hcal * eGammaHCalScaleFactors_.at(iAbsEta - 1);
246 
247  // scale factors will either be length 28 for legacy, or 28*(# et bins + 1) where the first set of 28 is an average over the et bins
248  // The first set of 28 provides a legacy fallthrough option
249  // Currently, # et bins is 9
250  if (eGammaECalScaleFactors_.size() == 28 * 10) {
251  int et_bin = ((int)floor(ecal) / 5);
252  // lowest bin (1) is 0-10GeV
253  if (et_bin < 1)
254  et_bin = 1;
255  // highest bin (9) is 45GeV and up
256  if (et_bin > 9)
257  et_bin = 9;
258  ecal_c = ecal * eGammaECalScaleFactors_.at(et_bin * 28 + iAbsEta - 1);
259  }
260  if (eGammaHCalScaleFactors_.size() == 28 * 10) {
261  int ht_bin = ((int)floor(hcal) / 5);
262  // lowest bin (1) is 0-10GeV
263  if (ht_bin < 1)
264  ht_bin = 1;
265  // highest bin (9) is 45GeV and up
266  if (ht_bin > 9)
267  ht_bin = 9;
268  hcal_c = hcal * eGammaHCalScaleFactors_.at(ht_bin * 28 + iAbsEta - 1);
269  }
270 
271  float result = ecal_c + hcal_c;
272 
273  // defunct section (polynomial-parameterized corrections)
274  if (useCorrections_) {
275  if (eGammaHCalScaleFactors_.at(iAbsEta - 1) != 0)
276  hcal_c = hcal;
277 
278  result = correctedTPGSum(ecal_c, hcal_c, iAbsEta - 1);
279  }
280 
281  return result;
282 }
283 
284 // index = iAbsEta - 1... make sure you call the function like so: "correctedTPGSum(ecal,hcal, iAbsEta - 1)"
285 float L1RCTParameters::correctedTPGSum(const float& ecal, const float& hcal, const unsigned& index) const {
286  if (index >= 28 && ecal > 120 && hcal > 120)
287  return (ecal + hcal); // return plain sum if outside of calibration range or index is too high
288 
289  // let's make sure we're asking for items that are there.
290  if (ecal_calib_.at(index).size() != 3 || hcal_calib_.at(index).size() != 3 ||
291  hcal_high_calib_.at(index).size() != 3 || cross_terms_.at(index).size() != 6 ||
292  HoverE_smear_high_.size() <= index || HoverE_smear_low_.size() <= index)
293  return (ecal + hcal);
294 
295  double e = ecal, h = hcal;
296  double ec = 0.0, hc = 0.0, c = 0.0;
297 
298  ec = (ecal_calib_.at(index).at(0) * std::pow(e, 3.) + ecal_calib_.at(index).at(1) * std::pow(e, 2.) +
299  ecal_calib_.at(index).at(2) * e);
300 
301  if (e + h < 23) {
302  hc = (hcal_calib_.at(index).at(0) * std::pow(h, 3.) + hcal_calib_.at(index).at(1) * std::pow(h, 2.) +
303  hcal_calib_.at(index).at(2) * h);
304 
305  c = (cross_terms_.at(index).at(0) * std::pow(e, 2.) * h + cross_terms_.at(index).at(1) * std::pow(h, 2.) * e +
306  cross_terms_.at(index).at(2) * e * h + cross_terms_.at(index).at(3) * std::pow(e, 3.) * h +
307  cross_terms_.at(index).at(4) * std::pow(h, 3.) * e +
308  cross_terms_.at(index).at(5) * std::pow(h, 2.) * std::pow(e, 2.));
309  } else {
310  hc = (hcal_high_calib_.at(index).at(0) * std::pow(h, 3.) + hcal_high_calib_.at(index).at(1) * std::pow(h, 2.) +
311  hcal_high_calib_.at(index).at(2) * h);
312  }
313 
314  if (h / (e + h) >= 0.05) {
315  ec *= HoverE_smear_high_.at(index);
316  hc *= HoverE_smear_high_.at(index);
317  c *= HoverE_smear_high_.at(index);
318  } else {
319  ec *= HoverE_smear_low_.at(index);
320  }
321  return ec + hc + c;
322 }
323 
324 void L1RCTParameters::print(std::ostream& s) const {
325  s << "\nPrinting record L1RCTParametersRcd" << endl;
326  s << "\n\"Parameter description\" \n \"Parameter name\" \"Value\" " << endl;
327  s << "\ne/gamma least significant bit energy transmitted from receiver cards to EIC cards. \n "
328  << "eGammaLSB = " << eGammaLSB_ << endl;
329  s << "\nLSB of region Et scale from RCT to GCT (GeV) \n "
330  << "jetMETLSB = " << jetMETLSB_ << endl;
331  s << "\nminimum ECAL Et for which fine-grain veto is applied (GeV) \n "
332  << " eMinForFGCut = " << eMinForFGCut_ << endl;
333  s << "\nmaximum ECAL Et for which fine-grain veto is applied (GeV) \n "
334  << "eMaxForFGCut = " << eMaxForFGCut_ << endl;
335  s << "\nmaximum value of (HCAL Et / ECAL Et) \n "
336  << "hOeCut = " << hOeCut_ << endl;
337  s << "\nminimum ECAL Et for which H/E veto is applied (GeV) \n "
338  << "eMinForHoECut = " << eMinForHoECut_ << endl;
339  s << "\nmaximum ECAL Et for which H/E veto is applied (GeV) \n "
340  << "eMaxForHoECut = " << eMaxForHoECut_ << endl;
341  s << "\nminimum HCAL Et for which H/E veto is applied (GeV) \n "
342  << "hMinForHoECut = " << hMinForHoECut_ << endl;
343  s << "\nECAL Et threshold above which tau activity bit is set (GeV) \n "
344  << "eActivityCut = " << eActivityCut_ << endl;
345  s << "\nHCAL Et threshold above which tau activity bit is set (GeV) \n "
346  << "hActivityCut = " << hActivityCut_ << endl;
347  s << "\nNeighboring trigger tower energy minimum threshold that marks candidate as non-isolated. (LSB bits) \n "
348  << "eicIsolationThreshold = " << eicIsolationThreshold_ << endl;
349  s << "\nIf jetMet energy in RCT Barrel Region is below this value, a quiet bit is set. (LSB bits)\n "
350  << "jscQuietThreshBarrel = " << jscQuietThresholdBarrel_ << endl;
351  s << "\nIf jetMet energy in RCT Endcap Region is below this value, a quiet bit is set. (LSB bits) \n "
352  << "jscQuietThreshEndcap = " << jscQuietThresholdEndcap_ << endl;
353  s << "\nWhen set to TRUE, HCAL energy is ignored if no ECAL energy is present in corresponding trigger tower for RCT "
354  "Barrel \n "
355  << "noiseVetoHB = " << noiseVetoHB_ << endl;
356  s << "\nWhen set to TRUE, HCAL energy is ignored if no ECAL energy is present in corresponding trigger tower for RCT "
357  "Encap+ \n "
358  << "noiseVetoHEplus = " << noiseVetoHEplus_ << endl;
359  s << "\nWhen set to TRUE, HCAL energy is ignored if no ECAL energy is present in corresponding trigger tower for RCT "
360  "Endcap- \n "
361  << "noiseVetoHEminus = " << noiseVetoHEminus_ << endl;
362 
363  auto printScalefactors = [&s](const std::vector<double>& sf) {
364  if (sf.size() == 10 * 28) {
365  s << "et bin ieta ScaleFactor" << endl;
366  for (unsigned i = 0; i < sf.size(); i++)
367  s << setw(6) << i / 28 << " " << setw(4) << i % 28 + 1 << " " << sf.at(i) << endl;
368  } else if (sf.size() == 10 * 32) // jet HCAL (HF regions are 29-32)
369  {
370  s << "et bin ieta ScaleFactor" << endl;
371  for (unsigned i = 0; i < sf.size(); i++)
372  s << setw(6) << i / 32 << " " << setw(4) << i % 32 + 1 << " " << sf.at(i) << endl;
373  } else {
374  s << "ieta ScaleFactor" << endl;
375  for (unsigned i = 0; i < sf.size(); i++)
376  s << setw(4) << i + 1 << " " << sf.at(i) << endl;
377  }
378  };
379 
380  s << "\n\neta-dependent multiplicative factors for ECAL Et before summation \n "
381  << "eGammaECal Scale Factors " << endl;
382  printScalefactors(eGammaECalScaleFactors_);
383 
384  s << "\n\neta-dependent multiplicative factors for HCAL Et before summation \n "
385  << "eGammaHCal Scale Factors " << endl;
386  printScalefactors(eGammaHCalScaleFactors_);
387 
388  s << "\n\neta-dependent multiplicative factors for ECAL Et before summation \n "
389  << "jetMETECal Scale Factors " << endl;
390  printScalefactors(jetMETECalScaleFactors_);
391 
392  s << "\n\neta-dependent multiplicative factors for HCAL Et before summation \n"
393  << "jetMETHCal Scale Factors " << endl;
394  printScalefactors(jetMETHCalScaleFactors_);
395 
396  if (useCorrections_) {
397  s << "\n\nUSING calibration variables " << endl;
398 
399  s << "\n\nH over E smear low Correction Factors " << endl;
400  s << "ieta Correction Factor" << endl;
401  for (int i = 0; i < 28; i++)
402  s << setw(4) << i + 1 << " " << HoverE_smear_low_.at(i) << endl;
403 
404  s << "\n\nH over E smear high Correction Factors " << endl;
405  s << "ieta Correction Factor" << endl;
406  for (int i = 0; i < 28; i++)
407  s << setw(4) << i + 1 << " " << HoverE_smear_high_.at(i) << endl;
408 
409  s << "\n\necal calibrations " << endl;
410  s << "ieta CorrFactor1 CorrFactor2 CorrFactor3" << endl;
411  int end = ecal_calib_[0].size();
412  for (int i = 0; i < 28; i++) {
413  s << setw(4) << i;
414  for (int j = 0; j < end; j++)
415  s << setw(11) << setprecision(8) << ecal_calib_[i][j];
416 
417  s << endl;
418  }
419 
420  s << "\n\nhcal calibrations " << endl;
421  s << "ieta CorrFactor1 CorrFactor2 CorrFactor3" << endl;
422  end = hcal_calib_[0].size();
423  for (int i = 0; i < 28; i++) {
424  s << setw(4) << i;
425  for (int j = 0; j < end; j++)
426  s << setw(11) << setprecision(8) << hcal_calib_[i][j];
427 
428  s << endl;
429  }
430  s << "\n\nhcal_high calibrations " << endl;
431  s << "ieta CorrFactor1 CorrFactor2 CorrFactor3" << endl;
432  end = hcal_high_calib_[0].size();
433  for (int i = 0; i < 28; i++) {
434  s << setw(4) << i;
435  for (int j = 0; j < end; j++)
436  s << setw(11) << setprecision(8) << hcal_high_calib_[i][j];
437 
438  s << endl;
439  }
440  end = cross_terms_[0].size();
441  s << "\n\ncross terms calibrations " << endl;
442  s << "ieta CorrFactor1 CorrFactor2 CorrFactor3 CorrFactor4 CorrFactor5 CorrFactor6" << endl;
443  for (int i = 0; i < 28; i++) {
444  s << setw(4) << i;
445  for (int j = 0; j < end; j++)
446  s << setw(11) << setprecision(8) << cross_terms_[i][j];
447 
448  s << endl;
449  }
450 
451  } else
452  s << "\n\nNOT USING calibration variables " << endl;
453 
454  s << "\n\n" << endl;
455 }
std::vector< double > jetMETECalScaleFactors_
float correctedTPGSum(const float &ecal, const float &hcal, const unsigned &index) const
unsigned short calcTower(unsigned short rct_iphi, unsigned short absIeta) const
unsigned short calcCrate(unsigned short rct_iphi, short ieta) const
unsigned jscQuietThresholdBarrel_
float JetMETTPGSum(const float &ecal, const float &hcal, const unsigned &iAbsEta) const
std::vector< double > eGammaECalScaleFactors_
eMinForHoECut
RCTConfigProducers.eMinForHoECut = 1 RCTConfigProducers.eMaxForHoECut = 30.
std::vector< std::vector< double > > cross_terms_
std::vector< std::vector< double > > hcal_high_calib_
std::vector< double > HoverE_smear_low_
float EGammaTPGSum(const float &ecal, const float &hcal, const unsigned &iAbsEta) const
unsigned short calcIAbsEta(unsigned short iCrate, unsigned short iCard, unsigned short iTower) const
unsigned jscQuietThresholdEndcap_
void print(std::ostream &s) const
std::vector< double > jetMETHCalScaleFactors_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< std::vector< double > > hcal_calib_
std::vector< double > HoverE_smear_high_
std::vector< double > eGammaHCalScaleFactors_
deadvectors [0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
unsigned short calcCard(unsigned short rct_iphi, unsigned short absIeta) const
std::vector< std::vector< double > > ecal_calib_
unsigned eicIsolationThreshold_
short calcIEta(unsigned short iCrate, unsigned short iCard, unsigned short iTower) const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
hMinForHoECut
RCTConfigProducers.hMinForHoECut = 1.0.
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
unsigned short calcIPhi(unsigned short iCrate, unsigned short iCard, unsigned short iTower) const