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  if(rctParameters_ == 0)
227  throw cms::Exception("L1RCTParameters Invalid")
228  << "L1RCTParameters should be set every event" << rctParameters_;
229  return ((ecal > rctParameters_->eActivityCut()) ||
230  (hcal > rctParameters_->hActivityCut()));
231 }
232 
233 // uses etScale
234 unsigned int L1RCTLookupTables::emRank(unsigned short energy) const
235 {
236  if(etScale_)
237  {
238  return etScale_->rank(energy);
239  }
240  else
241  // edm::LogInfo("L1RegionalCaloTrigger")
242  // << "CaloEtScale was not used - energy instead of rank" << std::endl;
243  return energy;
244 }
245 
246 // converts compressed ecal energy to linear (real) scale
247 float L1RCTLookupTables::convertEcal(unsigned short ecal, unsigned short iAbsEta, short sign) const
248 {
249  if(ecalScale_)
250  {
251  //std::cout << "[luts] energy " << ecal << " sign " << sign
252  //<< " iAbsEta " << iAbsEta << " iPhi " << iPhi << std::endl;
253  float dummy = 0;
254  dummy = float (ecalScale_->et( ecal, iAbsEta, sign ));
255  /*
256  if (ecal > 0)
257  {
258  std::cout << "[luts] ecal converted from " << ecal << " to "
259  << dummy << " with iAbsEta " << iAbsEta << std::endl;
260  }
261  */
262  return dummy;
263  }
264  //else if(rctParameters_ == 0)
265  // {
266  // throw cms::Exception("L1RCTParameters Invalid")
267  // << "L1RCTParameters should be set every event" << rctParameters_;
268  // }
269  else
270  {
271  return ((float) ecal) * rctParameters_->eGammaLSB();
272  }
273 }
274 
275 // converts compressed hcal energy to linear (real) scale
276 float L1RCTLookupTables::convertHcal(unsigned short hcal, unsigned short iAbsEta, short sign) const
277 {
278  if (hcalScale_ != 0)
279  {
280  return (hcalScale_->et( hcal, iAbsEta, sign ));
281  }
282  else
283  {
284  // edm::LogInfo("L1RegionalCaloTrigger")
285  // << "CaloTPGTranscoder was not used" << std::endl;
286  return ((float) hcal) * rctParameters_->jetMETLSB();
287  }
288 }
289 
290 // integerize given an LSB and set maximum value of 2^precision-1
291 unsigned long L1RCTLookupTables::convertToInteger(float et,
292  float lsb,
293  int precision) const
294 {
295  unsigned long etBits = (unsigned long)(et/lsb);
296  unsigned long maxValue = (1 << precision) - 1;
297  if(etBits > maxValue)
298  return maxValue;
299  else
300  return etBits;
301 }
302 
303 unsigned int L1RCTLookupTables::eGammaETCode(float ecal, float hcal, int iAbsEta) const
304 {
305  if(rctParameters_ == 0)
306  throw cms::Exception("L1RCTParameters Invalid")
307  << "L1RCTParameters should be set every event" << rctParameters_;
308  float etLinear = rctParameters_->EGammaTPGSum(ecal,hcal,iAbsEta);
309  return convertToInteger(etLinear, rctParameters_->eGammaLSB(), 7);
310 }
311 
312 unsigned int L1RCTLookupTables::jetMETETCode(float ecal, float hcal, int iAbsEta) const
313 {
314  if(rctParameters_ == 0)
315  throw cms::Exception("L1RCTParameters Invalid")
316  << "L1RCTParameters should be set every event" << rctParameters_;
317  float etLinear = rctParameters_->JetMETTPGSum(ecal,hcal,iAbsEta);
318  return convertToInteger(etLinear, rctParameters_->jetMETLSB(), 9);
319 }
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_
#define abs(x)
Definition: mlp_lapack.h:159
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
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