CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
UCTTower.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <string>
4 #include <vector>
5 #include <math.h>
6 #include <stdlib.h>
7 #include <stdint.h>
8 
9 #include "UCTTower.hh"
10 #include "UCTLogging.hh"
11 
12 using namespace l1tcalo;
13 
14 bool UCTTower::process() {
15  if(region >= NRegionsInCard) {
16  return processHFTower();
17  }
18  if(ecalET > etInputMax) ecalET = etInputMax;
19  if(hcalET > etInputMax) hcalET = etInputMax;
20  uint32_t calibratedECALET = ecalET;
21  uint32_t logECALET = (uint32_t) log2((double) ecalET);
22  if(logECALET > erMaxV) logECALET = erMaxV;
23  if(ecalLUT != 0) {
24  uint32_t etaAddress = region * NEtaInRegion + iEta;
25  uint32_t fbAddress = 0;
26  if(ecalFG) fbAddress = 1;
27  uint32_t value = (*ecalLUT)[etaAddress][fbAddress][ecalET];
28  calibratedECALET = value & etInputMax;
29  logECALET = (value & 0x7000) >> 12;
30  }
31  uint32_t calibratedHCALET = hcalET;
32  uint32_t logHCALET = (uint32_t) log2((double) hcalET);
33  if(logHCALET > erMaxV) logHCALET = erMaxV;
34  if(hcalLUT != 0) {
35  uint32_t etaAddress = region * NEtaInRegion + iEta;
36  uint32_t fbAddress = 0;
37  if((hcalFB & 0x1) != 0) fbAddress = 1;
38  uint32_t value = (*hcalLUT)[etaAddress][fbAddress][hcalET];
39  calibratedHCALET = value & etInputMax;
40  logHCALET = (value & 0x7000) >> 12;
41  }
42  towerData = calibratedECALET + calibratedHCALET;
43  if(towerData > etMask) towerData = etMask;
44  uint32_t er = 0;
45  if(calibratedECALET == 0 || calibratedHCALET == 0) {
46  er = 0;
47  towerData |= zeroFlagMask;
48  if(calibratedHCALET == 0 && calibratedECALET != 0)
49  towerData |= eohrFlagMask;
50  }
51  else if(calibratedECALET == calibratedHCALET) {
52  er = 0;
53  towerData |= eohrFlagMask;
54  }
55  else if(calibratedECALET > calibratedHCALET) {
56  er = logECALET - logHCALET;
57  if(er > erMaxV) er = erMaxV;
58  towerData |= eohrFlagMask;
59  }
60  else {
61  er = logHCALET - logECALET;
62  if(er > erMaxV) er = erMaxV;
63  }
64  towerData |= (er << erShift);
65  // Unfortunately, hcalFlag is presently bogus :(
66  // It has never been studied nor used in Run-1
67  // The same status persists in Run-2, but it is available usage
68  // Currently, summarize all hcalFeatureBits in one flag bit
69  if((hcalFB & 0x1) != 0) towerData |= hcalFlagMask; // FIXME - ignore top bits if(hcalFB != 0)
70  if(ecalFG) towerData |= ecalFlagMask;
71  // Store ecal and hcal calibrated ET in unused upper bits
72  towerData |= (calibratedECALET << ecalShift);
73  towerData |= (calibratedHCALET << hcalShift);
74  // All done!
75  return true;
76 }
77 
78 bool UCTTower::processHFTower() {
79  uint32_t calibratedET = hcalET;
80  if(hfLUT != 0) {
81  const std::vector< uint32_t > a = hfLUT->at((region - NRegionsInCard) * NHFEtaInRegion + iEta);
82  calibratedET = a[hcalET] & 0xFF;
83  }
84  uint32_t absCaloEta = abs(caloEta());
85  if(absCaloEta > 29 && absCaloEta < 40) {
86  // Divide by two (since two duplicate towers are sent)
87  calibratedET /= 2;
88  }
89  else if(absCaloEta == 40 || absCaloEta == 41) {
90  // Divide by four
91  calibratedET /= 4;
92  }
93  towerData = calibratedET | zeroFlagMask;
94  if((hcalFB & 0x1) == 0x1) towerData |= ecalFlagMask; // LSB defines short over long fiber ratio
95  if((hcalFB & 0x2) == 0x2) towerData |= hcalFlagMask; // MSB defines minbias flag
96  return true;
97 }
98 
99 bool UCTTower::setECALData(bool eFG, uint32_t eET) {
100  ecalFG = eFG;
101  ecalET = eET;
102  if(eET > etInputMax) {
103  LOG_ERROR << "UCTTower::setData - ecalET too high " << eET << "; Pegged to etInputMax" << std::endl;
104  ecalET = etInputMax;
105  }
106  return true;
107 }
108 
109 bool UCTTower::setHCALData(uint32_t hFB, uint32_t hET) {
110  hcalET = hET;
111  hcalFB = hFB;
112  if(hET > etInputMax) {
113  LOG_ERROR << "UCTTower::setData - hcalET too high " << hET << "; Pegged to etInputMax" << std::endl;
114  hcalET = etInputMax;
115  }
116  if(hFB > 0x3F) {
117  LOG_ERROR << "UCTTower::setData - too many hcalFeatureBits " << std::hex << hFB
118  << "; Used only bottom 6 bits" << std::endl;
119  hcalFB &= 0x3F;
120  }
121  return true;
122 }
123 
124 bool UCTTower::setHFData(uint32_t fbIn, uint32_t etIn) {
125  ecalFG = false; // HF has no separate ecal section
126  ecalET = 0;
127  hcalET = etIn; // We reuse HCAL place as HF
128  hcalFB = fbIn;
129  if(etIn > etInputMax) {
130  LOG_ERROR << "UCTTower::setData - HF ET too high " << etIn << "; Pegged to etInputMax" << std::endl;
131  hcalET = etInputMax;
132  }
133  if(fbIn > 0x3) {
134  LOG_ERROR << "UCTTower::setData - too many HF FeatureBits " << std::hex << fbIn
135  << "; Used only bottom 2 bits" << std::endl;
136  hcalFB &= 0x3;
137  }
138  return true;
139 }
140 
141 const uint16_t UCTTower::location() const {
142  uint16_t l = 0;
143  if(negativeEta) l = 0x8000; // Used top bit for +/- eta-side
144  l |= iPhi; // Max iPhi is 4, so bottom 2 bits for iPhi
145  l |= (iEta << 2); // Max iEta is 4, so 2 bits needed
146  l |= (region << 4); // Max region number 14, so 4 bits needed
147  l |= (card << 8); // Max card number is 6, so 3 bits needed
148  l |= (crate << 11); // Max crate number is 2, so 2 bits needed
149  return l;
150 }
151 
152 UCTTower::UCTTower(uint16_t location) {
153  if((location & 0x8000) != 0) negativeEta = true;
154  crate = (location & 0x1800) >> 11;
155  card = (location & 0x0700) >> 8;
156  region = (location & 0x00F0) >> 4;
157  iEta = (location & 0x000C) >> 2;
158  iPhi = (location & 0x0003);
159  towerData = 0;
160 }
161 
162 const uint64_t UCTTower::extendedData() const {
163  uint64_t d = rawData();
164  uint64_t l = location();
165  uint64_t r = (l << 48) + d;
166  return r;
167 }
168 
169 std::ostream& operator<<(std::ostream& os, const UCTTower& t) {
170  // if((t.ecalET + t.hcalET) == 0) return os;
171 
172  os << "Side Crt Crd Rgn iEta iPhi cEta cPhi eET eFG hET hFB Summary" << std::endl;
173 
174  UCTGeometry g;
175  std::string side = "+eta ";
176  if(t.negativeEta) side = "-eta ";
177  os << side
178  << std::showbase << std::internal << std::setfill('0') << std::setw(4) << std::hex
179  << t.crate << " "
180  << std::showbase << std::internal << std::setfill('0') << std::setw(4) << std::hex
181  << t.card << " "
182  << std::showbase << std::internal << std::setfill('0') << std::setw(4) << std::hex
183  << t.region << " "
184  << std::showbase << std::internal << std::setfill('0') << std::setw(4) << std::hex
185  << t.iEta << " "
186  << std::showbase << std::internal << std::setfill('0') << std::setw(4) << std::hex
187  << t.iPhi << " "
188  << std::setw(4) << std::setfill(' ') << std::dec
189  << g.getCaloEtaIndex(t.negativeEta, t.region, t.iEta) << " "
190  << std::setw(4) << std::setfill(' ') << std::dec
191  << g.getCaloPhiIndex(t.crate, t.card, t.region, t.iPhi) << " "
192  << std::showbase << std::internal << std::setfill('0') << std::setw(4) << std::hex
193  << t.ecalET << " "
194  << std::showbase << std::internal << std::setfill('0') << std::setw(4) << std::hex
195  << t.ecalFG << " "
196  << std::showbase << std::internal << std::setfill('0') << std::setw(4) << std::hex
197  << t.hcalET << " "
198  << std::showbase << std::internal << std::setfill('0') << std::setw(4) << std::hex
199  << t.hcalFB << " "
200  << std::showbase << std::internal << std::setfill('0') << std::setw(10) << std::hex
201  << t.towerData
202  << std::endl;
203  return os;
204 
205 }
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
tuple d
Definition: ztail.py:151
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
unsigned long long uint64_t
Definition: Time.h:15
double a
Definition: hdecay.h:121
tuple process
Definition: LaserDQM_cfg.py:3
#define LOG_ERROR
Definition: CSCDQM_Logger.h:41