CMS 3D CMS Logo

L1TkEtMissEmuAlgo.cc
Go to the documentation of this file.
2 
3 using namespace std;
4 
5 namespace l1tmetemu {
6  std::vector<global_phi_t> generateCosLUT(unsigned int size) { // Fill cosine LUT with integer values
7  float phi = 0;
8  std::vector<global_phi_t> cosLUT;
9  for (unsigned int LUT_idx = 0; LUT_idx < size; LUT_idx++) {
10  cosLUT.push_back((global_phi_t)(floor(cos(phi) * (kGlobalPhiBins - 1))));
11  phi += l1tmetemu::kStepPhi;
12  }
13  cosLUT.push_back((global_phi_t)(0)); //Prevent overflow in last bin
14  return cosLUT;
15  }
16 
17  // Generate Eta LUT for track to vertex association
18  std::vector<eta_t> generateEtaRegionLUT(vector<double> EtaRegions) {
19  std::vector<eta_t> LUT;
20  for (unsigned int q = 0; q < EtaRegions.size(); q++) {
21  LUT.push_back(digitizeSignedValue<eta_t>(EtaRegions[q], l1tmetemu::kInternalEtaWidth, l1tmetemu::kStepEta));
22  //std::cout << LUT[q] << "|" << EtaRegions[q] << std::endl;
23  }
24  return LUT;
25  }
26 
27  std::vector<z_t> generateDeltaZLUT(vector<double> DeltaZBins) {
28  std::vector<z_t> LUT;
29  for (unsigned int q = 0; q < DeltaZBins.size(); q++) {
30  LUT.push_back(digitizeSignedValue<z_t>(DeltaZBins[q], l1tmetemu::kInternalVTXWidth, l1tmetemu::kStepZ0));
31  //std::cout << LUT[q] << "|" << DeltaZBins[q] << std::endl;
32  }
33  return LUT;
34  }
35 
36  int unpackSignedValue(unsigned int bits, unsigned int nBits) {
37  int isign = 1;
38  unsigned int digitized_maximum = (1 << nBits) - 1;
39  if (bits & (1 << (nBits - 1))) { // check the sign
40  isign = -1;
41  bits = (1 << (nBits + 1)) - bits; // if negative, flip everything for two's complement encoding
42  }
43  return (int(bits & digitized_maximum)) * isign;
44  }
45 
46  unsigned int transformSignedValue(unsigned int bits, unsigned int oldnBits, unsigned int newnBits) {
47  int isign = 1;
48  unsigned int olddigitized_maximum = (1 << oldnBits) - 1;
49  unsigned int newdigitized_maximum = (1 << newnBits) - 1;
50  if (bits & (1 << (oldnBits - 1))) { // check the sign
51  isign = -1;
52  bits = (1 << (oldnBits + 1)) - bits; // if negative, flip everything for two's complement encoding
53  }
54  unsigned int temp = (int(bits & olddigitized_maximum));
55 
56  temp = round(temp / (1 << (oldnBits - newnBits)));
57 
58  if (temp > newdigitized_maximum)
59  temp = newdigitized_maximum;
60  if (isign < 0)
61  temp = (1 << newnBits) - 1 - temp; // two's complement encoding
62 
63  return temp;
64  }
65 
66 } // namespace l1tmetemu
size
Write out results.
const unsigned int kGlobalPhiBins
int unpackSignedValue(unsigned int bits, unsigned int nBits)
constexpr uint32_t bits
Definition: gpuClustering.h:23
const double kStepEta
const unsigned int kInternalVTXWidth
unsigned int transformSignedValue(unsigned int bits, unsigned int oldnBits, unsigned int newnBits)
const double kStepZ0
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
std::vector< eta_t > generateEtaRegionLUT(vector< double > EtaRegions)
ap_uint< kInternalPhiWidth+kGlobalPhiExtra > global_phi_t
std::vector< global_phi_t > generateCosLUT(unsigned int size)
std::vector< z_t > generateDeltaZLUT(vector< double > DeltaZBins)
const unsigned int kInternalEtaWidth
std::vector< unsigned short int > LUT
Definition: DTTracoLUTs.h:31
const double kStepPhi