CMS 3D CMS Logo

L1RCTLookupTables.cc
Go to the documentation of this file.
1 #include <iostream>
2 using std::cout;
3 using std::endl;
4 
5 #include <cmath>
6 #include <fstream>
7 #include <string>
8 #include <vector>
9 
12 
14 
21 
22 unsigned int L1RCTLookupTables::lookup(unsigned short ecalInput,
23  unsigned short hcalInput,
24  unsigned short fgbit,
25  unsigned short crtNo,
26  unsigned short crdNo,
27  unsigned short twrNo) const {
28  if (rctParameters_ == nullptr)
29  throw cms::Exception("L1RCTParameters Invalid") << "L1RCTParameters should be set every event" << rctParameters_;
30  if (channelMask_ == nullptr)
31  throw cms::Exception("L1RCTChannelMask Invalid") << "L1RCTChannelMask should be set every event" << channelMask_;
32  if (noisyChannelMask_ == nullptr)
33  throw cms::Exception("L1RCTNoisyChannelMask Invalid")
34  << "L1RCTNoisyChannelMask should be set every event" << noisyChannelMask_;
35  if (ecalInput > 0xFF)
36  throw cms::Exception("Invalid Data") << "ECAL compressedET should be less than 0xFF, is " << ecalInput;
37  if (hcalInput > 0xFF)
38  throw cms::Exception("Invalid Data") << "HCAL compressedET should be less than 0xFF, is " << hcalInput;
39  if (fgbit > 1)
40  throw cms::Exception("Invalid Data") << "ECAL finegrain should be a single bit, is " << fgbit;
41  short iEta = (short)rctParameters_->calcIEta(crtNo, crdNo, twrNo);
42  unsigned short iAbsEta = (unsigned short)abs(iEta);
43  short sign = iEta / iAbsEta;
44  unsigned short iPhi = rctParameters_->calcIPhi(crtNo, crdNo, twrNo);
45  unsigned short phiSide = (iPhi / 4) % 2;
46  if (iAbsEta < 1 || iAbsEta > 28)
47  throw cms::Exception("Invalid Data") << "1 <= |IEta| <= 28, is " << iAbsEta;
48 
49  // Pre Input bits
50  unsigned short ecalAfterMask = 0;
51  unsigned short hcalAfterMask = 0;
52 
53  // using channel mask to mask off ecal channels
54  // Mike: Introducing the hot channel mask
55  // If the Et is above the threshold then mask it as well
56 
57  float ecalBeforeMask = convertEcal(ecalInput, iAbsEta, sign);
58 
59  bool resetECAL = (channelMask_->ecalMask[crtNo][phiSide][iAbsEta - 1]) || // channel mask
60  (noisyChannelMask_->ecalMask[crtNo][phiSide][iAbsEta - 1] &&
61  ecalBeforeMask < noisyChannelMask_->ecalThreshold) || // hot mask
62  (rctParameters_->eGammaECalScaleFactors()[iAbsEta - 1] == 0. &&
63  rctParameters_->jetMETECalScaleFactors()[iAbsEta - 1] == 0.);
64 
65  if (resetECAL) {
66  ecalAfterMask = 0;
67  } else {
68  ecalAfterMask = ecalInput;
69  }
70 
71  float ecal = convertEcal(ecalAfterMask, iAbsEta, sign);
72 
73  // masking off hcal for channels in channel mask
74  float hcalBeforeMask = convertHcal(hcalInput, iAbsEta, sign);
75 
76  bool resetHCAL = channelMask_->hcalMask[crtNo][phiSide][iAbsEta - 1] ||
77  (noisyChannelMask_->hcalMask[crtNo][phiSide][iAbsEta - 1] &&
78  hcalBeforeMask < noisyChannelMask_->hcalThreshold) || // hot mask
79  (rctParameters_->eGammaHCalScaleFactors()[iAbsEta - 1] == 0. &&
80  rctParameters_->jetMETHCalScaleFactors()[iAbsEta - 1] == 0.);
81 
82  if (resetHCAL) {
83  hcalAfterMask = 0;
84  } else {
85  hcalAfterMask = hcalInput;
86  }
87 
88  float hcal = convertHcal(hcalAfterMask, iAbsEta, sign);
89 
90  unsigned long etIn7Bits;
91  unsigned long etIn9Bits;
92 
93  if ((ecalAfterMask == 0 && hcalAfterMask > 0) &&
94  ((rctParameters_->noiseVetoHB() && iAbsEta > 0 && iAbsEta < 18) ||
95  (rctParameters_->noiseVetoHEplus() && iAbsEta > 17 && crtNo > 8) ||
96  (rctParameters_->noiseVetoHEminus() && iAbsEta > 17 && crtNo < 9))) {
97  etIn7Bits = 0;
98  etIn9Bits = 0;
99  } else {
100  etIn7Bits = eGammaETCode(ecal, hcal, iAbsEta);
101  etIn9Bits = jetMETETCode(ecal, hcal, iAbsEta);
102  }
103  // Saturated input towers cause tower ET pegging at the highest value
104  if ((ecalAfterMask == 0xFF && rctParameters_->eGammaECalScaleFactors()[iAbsEta - 1] != 0.) ||
105  (hcalAfterMask == 0xFF && rctParameters_->eGammaHCalScaleFactors()[iAbsEta - 1] != 0.)) {
106  etIn7Bits = 0x7F; // egamma path
107  }
108  if ((ecalAfterMask == 0xFF && rctParameters_->jetMETECalScaleFactors()[iAbsEta - 1] != 0.) ||
109  (hcalAfterMask == 0xFF && rctParameters_->jetMETHCalScaleFactors()[iAbsEta - 1] != 0.)) {
110  etIn9Bits = 0x1FF; // sums path
111  }
112 
113  unsigned long shiftEtIn9Bits = etIn9Bits << 8;
114  unsigned long shiftHE_FGBit = hOeFGVetoBit(ecal, hcal, fgbit) << 7;
115  unsigned long shiftActivityBit = 0;
116  if (rctParameters_->jetMETECalScaleFactors()[iAbsEta - 1] == 0. &&
117  rctParameters_->jetMETHCalScaleFactors()[iAbsEta - 1] == 0.) {
118  // do nothing, it's already zero
119  } else if (rctParameters_->jetMETECalScaleFactors()[iAbsEta - 1] == 0.) {
120  shiftActivityBit = activityBit(0., hcal) << 17;
121  } else if (rctParameters_->jetMETHCalScaleFactors()[iAbsEta - 1] == 0.) {
122  shiftActivityBit = activityBit(ecal, 0.) << 17;
123  } else {
124  shiftActivityBit = activityBit(ecal, hcal) << 17;
125  }
126  unsigned long output = etIn7Bits + shiftHE_FGBit + shiftEtIn9Bits + shiftActivityBit;
127  return output;
128 }
129 
130 unsigned int L1RCTLookupTables::lookup(unsigned short hfInput,
131  unsigned short crtNo,
132  unsigned short crdNo,
133  unsigned short twrNo) const {
134  if (rctParameters_ == nullptr)
135  throw cms::Exception("L1RCTParameters Invalid") << "L1RCTParameters should be set every event" << rctParameters_;
136  if (channelMask_ == nullptr)
137  throw cms::Exception("L1RCTChannelMask Invalid") << "L1RCTChannelMask should be set every event" << channelMask_;
138  if (hfInput > 0xFF)
139  throw cms::Exception("Invalid Data") << "HF compressedET should be less than 0xFF, is " << hfInput;
140  short iEta = rctParameters_->calcIEta(crtNo, crdNo, twrNo);
141  unsigned short iAbsEta = abs(iEta);
142  short sign = (iEta / iAbsEta);
143  unsigned short phiSide = twrNo / 4;
144  if (iAbsEta < 29 || iAbsEta > 32)
145  throw cms::Exception("Invalid Data") << "29 <= |iEta| <= 32, is " << iAbsEta;
146 
147  float et = convertHcal(hfInput, iAbsEta, sign);
148  ;
149 
150  if (channelMask_->hfMask[crtNo][phiSide][iAbsEta - 29] ||
151  (noisyChannelMask_->hfMask[crtNo][phiSide][iAbsEta - 29] && et < noisyChannelMask_->hfThreshold)) {
152  et = 0;
153  }
154 
155  // cout << (int) rctParameters_->jetMETHCalScaleFactors()[iAbsEta-1] << endl;
156 
157  float scalehf = 1.;
158  if (rctParameters_->jetMETHCalScaleFactors().size() == 32) {
159  scalehf = (float)rctParameters_->jetMETHCalScaleFactors()[iAbsEta - 1];
160  } // The max eta for the various scale factors is 32, check to see if used.
161  else if (rctParameters_->jetMETHCalScaleFactors().size() == 32 * 10) {
162  int ht_bin = ((int)floor(et) / 5);
163  // lowest bin (1) is 0-10GeV
164  if (ht_bin < 1)
165  ht_bin = 1;
166  // highest bin (9) is 45GeV and up
167  if (ht_bin > 9)
168  ht_bin = 9;
169  scalehf = (float)rctParameters_->jetMETHCalScaleFactors()[32 * ht_bin + iAbsEta - 1];
170  } // et-dependent scale factors (optional, of course, if set to 1)
171 
172  et = scalehf * et; // Allow for scaling the HF as well e.g. zero out if needed
173 
174  unsigned int result = convertToInteger(et, rctParameters_->jetMETLSB(), 8);
175  return result;
176 }
177 
178 bool L1RCTLookupTables::hOeFGVetoBit(float ecal, float hcal, bool fgbit) const {
179  if (rctParameters_ == nullptr)
180  throw cms::Exception("L1RCTParameters Invalid") << "L1RCTParameters should be set every event" << rctParameters_;
181  bool veto = false;
183  if (fgbit)
184  veto = true;
185  }
187  if ((hcal / ecal) > rctParameters_->hOeCut())
188  veto = true;
189  }
190  // else
191  if (ecal < rctParameters_->eMinForHoECut()) {
193  veto = true; // Changed from eMinForHoECut() - JLL 2008-Feb-13
194  }
195  return veto;
196 }
197 
198 bool L1RCTLookupTables::activityBit(float ecal, float hcal) const {
199  // Redefined for upgrade as EM activity only
200  if (rctParameters_ == nullptr)
201  throw cms::Exception("L1RCTParameters Invalid") << "L1RCTParameters should be set every event" << rctParameters_;
202  bool aBit = false;
204  // For RCT operations HoE cut and tauVeto are used
206  } else {
207  // We redefine tauVeto() for upgrade as EM activity only --
208  // both EG and Tau make it through the EIC and JSC to CTP cards
209  // In the CTP card we want to rechannel EG/Tau candidates to EG and Tau
210  if (ecal > rctParameters_->eActivityCut()) {
211  if ((hcal / ecal) < rctParameters_->hOeCut()) {
212  aBit = true;
213  }
214  }
215  }
216  return aBit;
217 }
218 
219 // uses etScale
220 unsigned int L1RCTLookupTables::emRank(unsigned short energy) const {
221  if (etScale_) {
222  return etScale_->rank(energy);
223  } else
224  // edm::LogInfo("L1RegionalCaloTrigger")
225  // << "CaloEtScale was not used - energy instead of rank" << std::endl;
226  return energy;
227 }
228 
229 // converts compressed ecal energy to linear (real) scale
230 float L1RCTLookupTables::convertEcal(unsigned short ecal, unsigned short iAbsEta, short sign) const {
231  if (ecalScale_) {
232  // std::cout << "[luts] energy " << ecal << " sign " << sign
233  //<< " iAbsEta " << iAbsEta << " iPhi " << iPhi << std::endl;
234  float dummy = 0;
235  dummy = float(ecalScale_->et(ecal, iAbsEta, sign));
236  /*
237  if (ecal > 0)
238  {
239  std::cout << "[luts] ecal converted from " << ecal << " to "
240  << dummy << " with iAbsEta " << iAbsEta << std::endl;
241  }
242  */
243  return dummy;
244  }
245  // else if(rctParameters_ == 0)
246  // {
247  // throw cms::Exception("L1RCTParameters Invalid")
248  // << "L1RCTParameters should be set every event" << rctParameters_;
249  // }
250  else {
251  return ((float)ecal) * rctParameters_->eGammaLSB();
252  }
253 }
254 
255 // converts compressed hcal energy to linear (real) scale
256 float L1RCTLookupTables::convertHcal(unsigned short hcal, unsigned short iAbsEta, short sign) const {
257  if (hcalScale_ != nullptr) {
258  return (hcalScale_->et(hcal, iAbsEta, sign));
259  } else {
260  // edm::LogInfo("L1RegionalCaloTrigger")
261  // << "CaloTPGTranscoder was not used" << std::endl;
262  return ((float)hcal) * rctParameters_->jetMETLSB();
263  }
264 }
265 
266 // integerize given an LSB and set maximum value of 2^precision-1
267 unsigned long L1RCTLookupTables::convertToInteger(float et, float lsb, int precision) const {
268  unsigned long etBits = (unsigned long)(et / lsb);
269  unsigned long maxValue = (1 << precision) - 1;
270  if (etBits > maxValue)
271  return maxValue;
272  else
273  return etBits;
274 }
275 
276 unsigned int L1RCTLookupTables::eGammaETCode(float ecal, float hcal, int iAbsEta) const {
277  if (rctParameters_ == nullptr)
278  throw cms::Exception("L1RCTParameters Invalid") << "L1RCTParameters should be set every event" << rctParameters_;
279  float etLinear = rctParameters_->EGammaTPGSum(ecal, hcal, iAbsEta);
280  return convertToInteger(etLinear, rctParameters_->eGammaLSB(), 7);
281 }
282 
283 unsigned int L1RCTLookupTables::jetMETETCode(float ecal, float hcal, int iAbsEta) const {
284  if (rctParameters_ == nullptr)
285  throw cms::Exception("L1RCTParameters Invalid") << "L1RCTParameters should be set every event" << rctParameters_;
286  float etLinear = rctParameters_->JetMETTPGSum(ecal, hcal, iAbsEta);
287  return convertToInteger(etLinear, rctParameters_->jetMETLSB(), 9);
288 }
double hMinForHoECut() const
const std::vector< double > & jetMETHCalScaleFactors() const
unsigned int eGammaETCode(float ecal, float hcal, int iAbsEta) const
double eMinForFGCut() const
const std::vector< double > & jetMETECalScaleFactors() const
unsigned int lookup(unsigned short ecalInput, unsigned short hcalInput, unsigned short fgbit, unsigned short crtNo, unsigned short crdNo, unsigned short twrNo) const
double eGammaLSB() const
double jetMETLSB() const
double hActivityCut() const
double et(unsigned short rank, unsigned short eta, short etaSign) const
convert from rank to physically meaningful quantity
bool hOeFGVetoBit(float ecal, float hcal, bool fgbit) const
double eMaxForFGCut() const
bool activityBit(float ecal, float hcal) const
float JetMETTPGSum(const float &ecal, const float &hcal, const unsigned &iAbsEta) const
bool ecalMask[18][2][28]
const L1RCTChannelMask * channelMask_
eMinForHoECut
RCTConfigProducers.eMinForHoECut = 1 RCTConfigProducers.eMaxForHoECut = 30.
bool noiseVetoHEminus() const
const L1RCTNoisyChannelMask * noisyChannelMask_
float EGammaTPGSum(const float &ecal, const float &hcal, const unsigned &iAbsEta) const
double eMaxForHoECut() const
float convertEcal(unsigned short ecal, unsigned short iAbsEta, short sign) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double eActivityCut() const
const L1CaloEcalScale * ecalScale_
double hOeCut() const
unsigned int jetMETETCode(float ecal, float hcal, int iAbsEta) const
const L1RCTParameters * rctParameters_
const std::vector< double > & eGammaECalScaleFactors() const
unsigned long convertToInteger(float et, float lsb, int precision) const
bool noiseVetoHEplus() const
uint16_t rank(const uint16_t linear) const
convert from linear Et scale to rank scale
const std::vector< double > & eGammaHCalScaleFactors() const
double eMinForHoECut() const
short calcIEta(unsigned short iCrate, unsigned short iCard, unsigned short iTower) const
bool hcalMask[18][2][28]
double et(unsigned short rank, unsigned short eta, short etaSign) const
convert from rank to physically meaningful quantity
bool noiseVetoHB() const
float convertHcal(unsigned short hcal, unsigned short iAbsEta, short sign) const
const L1CaloHcalScale * hcalScale_
unsigned int emRank(unsigned short energy) const
const L1CaloEtScale * etScale_
bool hfMask[18][2][4]
unsigned short calcIPhi(unsigned short iCrate, unsigned short iCard, unsigned short iTower) const