CMS 3D CMS Logo

CSCGEMData.cc
Go to the documentation of this file.
4 
5 #include <string>
6 #include <cstdio>
7 #include <strings.h> // for bzero
8 #include <cstring>
9 
10 #ifdef LOCAL_UNPACK
11 bool CSCGEMData::debug = false;
12 #else
13 std::atomic<bool> CSCGEMData::debug{false};
14 #endif
15 
16 CSCGEMData::CSCGEMData(int ntbins, int gems_fibers) : ntbins_(ntbins), size_(0) {
17  theData[0] = 0x6C04;
18  ntbins_ = ntbins;
19  gems_enabled_ = gems_fibers;
20  ngems_ = 0;
21  /* Not implemented in the firmware yet */
22  /*
23  for (int i=0; i<4; i++)
24  ngems_ += (gems_fibers>>i) & 0x1;
25  */
26  ngems_ = 4;
27  size_ = 2 + ntbins_ * ngems_ * 4;
28 
30  for (int i = 0; i < (size_ - 2); i++) {
31  int gem_chamber = (i % 16) / 8;
32  theData[i + 1] = 0x3FFF | (gem_chamber << 14);
33  }
34 
35  theData[size_ - 1] = 0x6D04;
36 }
37 
38 CSCGEMData::CSCGEMData(const unsigned short* buf, int length, int gems_fibers) : size_(length) {
39  size_ = length;
40  ngems_ = 0;
41  /* Not implemented in the firmware yet */
42  /*
43  for (int i=0; i<4; i++)
44  ngems_ += (gems_fibers>>i) & 0x1;
45  */
46  ngems_ = 4;
47  ntbins_ = (size_ - 2) / (4 * ngems_);
48  gems_enabled_ = gems_fibers;
49  memcpy(theData, buf, size_ * 2);
50 }
51 
52 void CSCGEMData::print() const {
53  LogTrace("CSCGEMData|CSCRawToDigi") << "CSCGEMData.Print";
54  for (int line = 0; line < ((size_)); ++line) {
55  LogTrace("CSCGEMData|CSCRawToDigi") << std::hex << theData[line];
56  }
57 }
58 
59 int CSCGEMData::getPartitionNumber(int addr, int npads) const { return addr / (npads - 1); }
60 
61 int CSCGEMData::getPartitionStripNumber(int address, int nPads, int etaPart) const {
62  return address - (nPads * etaPart);
63 }
64 
65 std::vector<GEMPadDigiCluster> CSCGEMData::digis(int gem_chamber) const {
67  std::vector<GEMPadDigiCluster> result;
68  result.clear();
69  int nPads = 192; // From geometry
70  int maxClusters = 4;
71  int nGEMs = 4;
72  // nGEMs = ngems_; // based on enabled fibers. not implemented in the firmware yet
73  for (int i = 0; i < ntbins_; i++) {
74  for (int fiber = 0; fiber < nGEMs; fiber++) {
75  for (int cluster = 0; cluster < maxClusters; cluster++) {
76  int dataAddr = 1 + (i * nGEMs + fiber) * maxClusters + cluster;
77  int gem_layer = (theData[dataAddr] >> 14) & 0x1; // gemA=0 or gemB=1
78  if (gem_layer == gem_chamber) {
79  int cl_word = theData[dataAddr] & 0x3fff;
80  int pad = theData[dataAddr] & 0xff;
81  int eta = (theData[dataAddr] >> 8) & 0x7;
82  int cluster_size = (theData[dataAddr] >> 11) & 0x7;
83  if (pad < nPads) {
84  int padInPart = eta * nPads + pad;
85  if (debug)
86  LogTrace("CSCGEMData|CSCRawToDigi")
87  << "GEMlayer" << gem_layer << " cl_word" << dataAddr << ": 0x" << std::hex << cl_word << std::dec
88  << " tbin: " << i << " fiber#: " << (fiber + 1) << " cluster#: " << (cluster + 1)
89  << " padInPart: " << padInPart << " pad: " << pad << " eta: " << eta
90  << " cluster_size: " << cluster_size << std::endl;
91  std::vector<short unsigned int> pads;
92  for (int iP = 0; iP <= cluster_size; ++iP)
93  pads.push_back(padInPart + iP);
94  GEMPadDigiCluster pad_cluster(pads, i);
95  result.push_back(pad_cluster);
96  }
97  }
98  }
99  }
100  }
101 
105  /*
106  std::vector<GEMPadDigiCluster> result;
107  result.clear();
108  int nPads = 192; // From geometry
109  int maxAddr = 1536;
110  int nGEMs = 2;
111  int maxClusters = 8;
112  // std::cout << std::hex << "markers " << theData[0] << ": " << theData[size_-1] << std::dec << " size: " << size_ << std::endl;
113  for (int i=0; i<ntbins_; i++)
114  {
115  for (int gem=0; gem<nGEMs; gem++)
116  {
117  if (gem==gem_chamber) // Return only digis for specified GEM chamber
118  {
119  for (int TMBCluster=0; TMBCluster<maxClusters; TMBCluster++)
120  {
121  int dataAddr = 1 + (i*nGEMs+gem)*maxClusters + TMBCluster;
122  int address = theData[dataAddr] & 0x7ff;
123  // std::cout << dataAddr << ": " << address <<std::endl;
124  int nExtraPads = (theData[dataAddr] >>11)&0x7;
125  if (address<maxAddr)
126  {
127  int etaPart = getPartitionNumber(address,nPads);
128  int padInPart = getPartitionStripNumber(address,nPads,etaPart);
129  vector<short unsigned int> pads;
130  for(int iP = 0; iP <= nExtraPads; ++iP)
131  pads.push_back(padInPart + iP );
132  GEMPadDigiCluster cluster ( pads, i);
133  result.push_back(cluster);
134  }
135  }
136  }
137  }
138  }
139  */
140  return result;
141 }
142 
146 std::vector<GEMPadDigiCluster> CSCGEMData::etaDigis(int gem_chamber, int eta_roll) const {
148  std::vector<GEMPadDigiCluster> result;
149  result.clear();
150  int nPads = 192; // From geometry
151  int maxClusters = 4;
152  int nGEMs = 4;
153  // nGEMs = ngems_; // based on enabled fibers. currently not implemented in the firmware
154  for (int i = 0; i < ntbins_; i++) {
155  for (int fiber = 0; fiber < nGEMs; fiber++) {
156  for (int cluster = 0; cluster < maxClusters; cluster++) {
157  int dataAddr = 1 + (i * nGEMs + fiber) * maxClusters + cluster;
158  int gem_layer = (theData[dataAddr] >> 14) & 0x1; // gemA=0 or gemB=1
159  if (gem_layer == gem_chamber) {
160  int cl_word = theData[dataAddr] & 0x3fff;
161  int pad = theData[dataAddr] & 0xff;
162  int eta = (theData[dataAddr] >> 8) & 0x7;
163  int cluster_size = (theData[dataAddr] >> 11) & 0x7;
164  if ((pad < nPads) && (eta == eta_roll)) {
165  int padInPart = pad;
166  if (debug)
167  LogTrace("CSCGEMData|CSCRawToDigi")
168  << "GEMlayer" << gem_layer << " cl_word" << dataAddr << ": 0x" << std::hex << cl_word << std::dec
169  << " tbin: " << i << " fiber#: " << (fiber + 1) << " cluster#: " << (cluster + 1)
170  << " padInPart: " << padInPart << " pad: " << pad << " eta: " << eta
171  << " cluster_size: " << cluster_size << std::endl;
172  std::vector<short unsigned int> pads;
173  for (int iP = 0; iP <= cluster_size; ++iP)
174  pads.push_back(padInPart + iP);
175  GEMPadDigiCluster pad_cluster(pads, i);
176  result.push_back(pad_cluster);
177  }
178  }
179  }
180  }
181  }
182  return result;
183 }
184 
188 void CSCGEMData::addEtaPadCluster(const GEMPadDigiCluster& digi, int gem_chamber, int eta_roll) {
189  int bx = digi.bx();
191  if ((gem_chamber < 2) && (bx < ntbins_)) {
192  int gem_layer = gem_chamber & 0x1;
193  int cluster_size = digi.pads().size() - 1;
194  int pad = digi.pads()[0];
195  int eta = eta_roll;
196  int cl_word = (gem_layer << 14) + (pad & 0xff) + ((eta & 0x7) << 8) + ((cluster_size & 0x7) << 11);
197  int dataAddr = 1 + bx * 16 + 8 * gem_layer;
198  int cluster_num = 0;
200  while (((theData[dataAddr + cluster_num] & 0x3fff) != 0x3fff) && (cluster_num < 8)) {
201  cluster_num++;
202  }
204  if (((theData[dataAddr + cluster_num] & 0x3fff) == 0x3fff) && (cluster_num < 8)) {
205  theData[dataAddr + cluster_num] = cl_word;
206  }
207  }
208 }
const std::vector< uint16_t > & pads() const
void addEtaPadCluster(const GEMPadDigiCluster &digi, int gem_chamber, int eta_roll)
Add and pack GEMPadDigiCluster digis.
Definition: CSCGEMData.cc:188
static std::atomic< bool > debug
Definition: CSCGEMData.h:46
int getPartitionNumber(int address, int nPads) const
Definition: CSCGEMData.cc:59
void print() const
Definition: CSCGEMData.cc:52
#define LogTrace(id)
int ngems_
Definition: CSCGEMData.h:51
std::vector< GEMPadDigiCluster > digis(int gem_chamber) const
Definition: CSCGEMData.cc:65
CSCGEMData(int ntbins=12, int gem_fibers_mask=0xf)
default constructor
Definition: CSCGEMData.cc:16
unsigned short theData[8 *2 *32+2]
Definition: CSCGEMData.h:53
int getPartitionStripNumber(int address, int nPads, int etaPart) const
Definition: CSCGEMData.cc:61
std::vector< GEMPadDigiCluster > etaDigis(int gem_chamber, int eta) const
Definition: CSCGEMData.cc:146
int ntbins_
Definition: CSCGEMData.h:49
int gems_enabled_
Definition: CSCGEMData.h:50