CMS 3D CMS Logo

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