CMS 3D CMS Logo

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