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 }
L1RCTParameters::eMinForFGCut
double eMinForFGCut() const
Definition: L1RCTParameters.h:67
L1RCTNoisyChannelMask.h
boostedTaus_cff.precision
precision
Definition: boostedTaus_cff.py:29
MessageLogger.h
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
L1RCTParameters.h
L1RCTParameters::hMinForHoECut
double hMinForHoECut() const
Definition: L1RCTParameters.h:72
L1RCTParameters::calcIEta
short calcIEta(unsigned short iCrate, unsigned short iCard, unsigned short iTower) const
Definition: L1RCTParameters.cc:141
L1RCTLookupTables::eGammaETCode
unsigned int eGammaETCode(float ecal, float hcal, int iAbsEta) const
Definition: L1RCTLookupTables.cc:276
L1RCTLookupTables::activityBit
bool activityBit(float ecal, float hcal) const
Definition: L1RCTLookupTables.cc:198
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
L1RCTLookupTables::lookup
unsigned int lookup(unsigned short ecalInput, unsigned short hcalInput, unsigned short fgbit, unsigned short crtNo, unsigned short crdNo, unsigned short twrNo) const
Definition: L1RCTLookupTables.cc:22
hcal
Definition: ConfigurationDatabase.cc:13
L1RCTParameters::hOeCut
double hOeCut() const
Definition: L1RCTParameters.h:69
gather_cfg.cout
cout
Definition: gather_cfg.py:144
L1RCTParameters::JetMETTPGSum
float JetMETTPGSum(const float &ecal, const float &hcal, const unsigned &iAbsEta) const
Definition: L1RCTParameters.cc:189
L1RCTLookupTables::hOeFGVetoBit
bool hOeFGVetoBit(float ecal, float hcal, bool fgbit) const
Definition: L1RCTLookupTables.cc:178
L1CaloHcalScale::et
double et(unsigned short rank, unsigned short eta, short etaSign) const
convert from rank to physically meaningful quantity
Definition: L1CaloHcalScale.cc:64
L1CaloEcalScale::et
double et(unsigned short rank, unsigned short eta, short etaSign) const
convert from rank to physically meaningful quantity
Definition: L1CaloEcalScale.cc:64
Validation_hcalonly_cfi.sign
sign
Definition: Validation_hcalonly_cfi.py:32
L1RCTChannelMask::hfMask
bool hfMask[18][2][4]
Definition: L1RCTChannelMask.h:10
L1RCTNoisyChannelMask::ecalMask
bool ecalMask[18][2][28]
Definition: L1RCTNoisyChannelMask.h:8
L1RCTParameters::eActivityCut
double eActivityCut() const
Definition: L1RCTParameters.h:73
L1RCTParameters::noiseVetoHB
bool noiseVetoHB() const
Definition: L1RCTParameters.h:78
hgcalVFEProducer_cfi.lsb
lsb
Definition: hgcalVFEProducer_cfi.py:80
ecal
Definition: ElectronicsMappingGPU.h:13
L1RCTLookupTables::channelMask_
const L1RCTChannelMask * channelMask_
Definition: L1RCTLookupTables.h:58
L1RCTLookupTables::noisyChannelMask_
const L1RCTNoisyChannelMask * noisyChannelMask_
Definition: L1RCTLookupTables.h:59
L1RCTChannelMask.h
L1RCTParameters::eGammaECalScaleFactors
const std::vector< double > & eGammaECalScaleFactors() const
Definition: L1RCTParameters.h:81
L1CaloHcalScale.h
hltEgammaHLTExtra_cfi.hcal
hcal
Definition: hltEgammaHLTExtra_cfi.py:42
L1RCTParameters::hActivityCut
double hActivityCut() const
Definition: L1RCTParameters.h:74
L1RCTParameters::eMaxForHoECut
double eMaxForHoECut() const
Definition: L1RCTParameters.h:71
MonitorHcalDiJetsAlCaReco_cfi.hfInput
hfInput
Definition: MonitorHcalDiJetsAlCaReco_cfi.py:11
L1RCTParameters::jetMETLSB
double jetMETLSB() const
Definition: L1RCTParameters.h:66
L1RCTParameters::noiseVetoHEminus
bool noiseVetoHEminus() const
Definition: L1RCTParameters.h:80
L1RCTParameters::eMaxForFGCut
double eMaxForFGCut() const
Definition: L1RCTParameters.h:68
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
L1RCTParameters::eGammaHCalScaleFactors
const std::vector< double > & eGammaHCalScaleFactors() const
Definition: L1RCTParameters.h:82
L1RCTParameters::EGammaTPGSum
float EGammaTPGSum(const float &ecal, const float &hcal, const unsigned &iAbsEta) const
Definition: L1RCTParameters.cc:240
L1RCTParameters::jetMETECalScaleFactors
const std::vector< double > & jetMETECalScaleFactors() const
Definition: L1RCTParameters.h:83
L1RCTLookupTables::convertEcal
float convertEcal(unsigned short ecal, unsigned short iAbsEta, short sign) const
Definition: L1RCTLookupTables.cc:230
L1RCTLookupTables::jetMETETCode
unsigned int jetMETETCode(float ecal, float hcal, int iAbsEta) const
Definition: L1RCTLookupTables.cc:283
L1RCTLookupTables::ecalScale_
const L1CaloEcalScale * ecalScale_
Definition: L1RCTLookupTables.h:60
seedmultiplicitymonitor_newtracking_cfi.maxValue
maxValue
Definition: seedmultiplicitymonitor_newtracking_cfi.py:8
createfilelist.int
int
Definition: createfilelist.py:10
EgHLTOffHistBins_cfi.et
et
Definition: EgHLTOffHistBins_cfi.py:8
L1RCTLookupTables.h
L1RCTLookupTables::rctParameters_
const L1RCTParameters * rctParameters_
Definition: L1RCTLookupTables.h:57
L1CaloEtScale::rank
uint16_t rank(const uint16_t linear) const
convert from linear Et scale to rank scale
Definition: L1CaloEtScale.cc:52
L1RCTParameters::jetMETHCalScaleFactors
const std::vector< double > & jetMETHCalScaleFactors() const
Definition: L1RCTParameters.h:84
L1RCTNoisyChannelMask::hfMask
bool hfMask[18][2][4]
Definition: L1RCTNoisyChannelMask.h:10
L1RCTChannelMask::hcalMask
bool hcalMask[18][2][28]
Definition: L1RCTChannelMask.h:9
L1CaloEtScale.h
L1RCTParameters::calcIPhi
unsigned short calcIPhi(unsigned short iCrate, unsigned short iCard, unsigned short iTower) const
Definition: L1RCTParameters.cc:152
L1CaloEcalScale.h
caloStage1RCTLuts_cff.eMinForHoECut
eMinForHoECut
RCTConfigProducers.eMinForHoECut = 1 RCTConfigProducers.eMaxForHoECut = 30.
Definition: caloStage1RCTLuts_cff.py:23
L1RCTParameters::eMinForHoECut
double eMinForHoECut() const
Definition: L1RCTParameters.h:70
Exception
Definition: hltDiff.cc:245
L1RCTLookupTables::convertToInteger
unsigned long convertToInteger(float et, float lsb, int precision) const
Definition: L1RCTLookupTables.cc:267
L1RCTParameters::eGammaLSB
double eGammaLSB() const
Definition: L1RCTParameters.h:65
L1RCTParameters::noiseVetoHEplus
bool noiseVetoHEplus() const
Definition: L1RCTParameters.h:79
Exception.h
bsc_activity_cfg.ecal
ecal
Definition: bsc_activity_cfg.py:25
L1RCTLookupTables::hcalScale_
const L1CaloHcalScale * hcalScale_
Definition: L1RCTLookupTables.h:61
L1TowerCalibrationProducer_cfi.iEta
iEta
Definition: L1TowerCalibrationProducer_cfi.py:60
mps_fire.result
result
Definition: mps_fire.py:311
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
L1RCTLookupTables::etScale_
const L1CaloEtScale * etScale_
Definition: L1RCTLookupTables.h:62
dummy
Definition: DummySelector.h:38
L1RCTChannelMask::ecalMask
bool ecalMask[18][2][28]
Definition: L1RCTChannelMask.h:8
PbPb_ZMuSkimMuonDPG_cff.veto
veto
Definition: PbPb_ZMuSkimMuonDPG_cff.py:61
L1RCTNoisyChannelMask::hcalThreshold
float hcalThreshold
Definition: L1RCTNoisyChannelMask.h:13
L1RCTLookupTables::convertHcal
float convertHcal(unsigned short hcal, unsigned short iAbsEta, short sign) const
Definition: L1RCTLookupTables.cc:256
L1RCTNoisyChannelMask::hcalMask
bool hcalMask[18][2][28]
Definition: L1RCTNoisyChannelMask.h:9
L1RCTLookupTables::emRank
unsigned int emRank(unsigned short energy) const
Definition: L1RCTLookupTables.cc:220