CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCCLCTData.cc
Go to the documentation of this file.
5 #include <iostream>
6 #include <cstdio>
7 #include <cstring>
8 
9 bool CSCCLCTData::debug = false;
10 
11 
13 : ncfebs_(tmbHeader->NCFEBs()), ntbins_(tmbHeader->NTBins())
14 {
15  size_ = nlines();
16  zero();
17 }
18 
19 
20 CSCCLCTData::CSCCLCTData(int ncfebs, int ntbins)
21 : ncfebs_(ncfebs), ntbins_(ntbins)
22 {
23  size_ = nlines();
24  zero();
25 }
26 
27 
28 
29 
30 CSCCLCTData::CSCCLCTData(int ncfebs, int ntbins, const unsigned short * buf)
31 : ncfebs_(ncfebs), ntbins_(ntbins)
32 {
33  // add two more for odd ntbins, plus one for the e0c
34  // Oct 2004 Rick: e0c line belongs to CSCTMBTrailer
35  size_ = (nlines()%2==1)? nlines()+2 : nlines();
36 
37  memcpy(theData, buf, size_*2);
38 
39 }
40 
41 
43 {
44  for(int ifeb = 0; ifeb < ncfebs_; ++ifeb)
45  {
46  for(int tbin = 0; tbin < ntbins_; ++tbin)
47  {
48  for(int layer = 1; layer <= 6; ++layer)
49  {
50  dataWord(ifeb, tbin, layer) = CSCCLCTDataWord(ifeb, tbin, 0);
51  }
52  }
53  }
54 
55 }
56 
57 
58 std::vector<CSCComparatorDigi> CSCCLCTData::comparatorDigis(uint32_t idlayer, unsigned cfeb)
59 {
60  static const bool doStripSwapping = true;
61  bool me1a = (CSCDetId::station(idlayer)==1) && (CSCDetId::ring(idlayer)==4);
62  bool zplus = (CSCDetId::endcap(idlayer) == 1);
63  bool me1b = (CSCDetId::station(idlayer)==1) && (CSCDetId::ring(idlayer)==1);
64  unsigned layer = CSCDetId::layer(idlayer);
65 
66  //looking for comp output on layer
67  std::vector<CSCComparatorDigi> result;
68  assert(layer>0 && layer<= 6);
69  // this is pretty sparse data, so I wish we could check the
70  // data word by word, not bit by bit, but I don't see how to
71  // do the time sequencing that way.
72  for(int distrip = 0; distrip < 8; ++distrip)
73  {
74  uint16_t tbinbitsS0HS0=0;
75  uint16_t tbinbitsS0HS1=0;
76  uint16_t tbinbitsS1HS0=0;
77  uint16_t tbinbitsS1HS1=0;
78  for(int tbin = 0; tbin < ntbins_-2; ++tbin)
79  {
80  if(bitValue(cfeb, tbin, layer, distrip))
81  {
83  CSCCLCTDataWord word = dataWord(cfeb, tbin, layer);
84  assert(word.tbin_ == tbin);
85  assert(word.cfeb_ == cfeb);
86  // we have a hit. The next two time samples
87  // are the other two bits in the triad
88  int bit2 = bitValue(cfeb, tbin+1, layer, distrip);
89  int bit3 = bitValue(cfeb, tbin+2, layer, distrip);
90  // should count from zero
91  int chamberDistrip = distrip + cfeb*8;
92  int HalfStrip = 4*chamberDistrip + bit2*2 + bit3;
93  int output = 4 + bit2*2 + bit3;
94  /*
95  * Handles distrip logic; comparator output is for pairs of strips:
96  * hit bin dec
97  * x--- 100 4
98  * -x-- 101 5
99  * --x- 110 6
100  * ---x 111 7
101  *
102  */
103 
104  if (debug)
105  LogTrace ("CSCCLCTData|CSCRawToDigi")
106  << "fillComparatorOutputs: layer = "
107  << layer << " timebin = " << tbin
108  << " cfeb = " << cfeb << " distrip = " << chamberDistrip
109  << " HalfStrip = " << HalfStrip
110  << " Output " << output << std::endl;
112 
114  if (output==4) tbinbitsS0HS0=tbinbitsS0HS0+(1<<tbin);
115  if (output==5) tbinbitsS0HS1=tbinbitsS0HS1+(1<<tbin);
116  if (output==6) tbinbitsS1HS0=tbinbitsS1HS0+(1<<tbin);
117  if (output==7) tbinbitsS1HS1=tbinbitsS1HS1+(1<<tbin);
118 
119  tbin += 2;
120  }
121  }//end of loop over time bins
122  //we do not have to check over the last couple of time bins if there are no hits since
123  //comparators take 3 time bins
124 
125  // Store digis each of possible four halfstrips for given distrip:
126  if (tbinbitsS0HS0 || tbinbitsS0HS1 || tbinbitsS1HS0 || tbinbitsS1HS1) {
127  unsigned int cfeb_corr = cfeb;
128  unsigned int distrip_corr = distrip;
129 
130  if (doStripSwapping) {
131  // Fix ordering of strips and CFEBs in ME1/1.
132  // SV, 27/05/08: keep CFEB=4 for ME1/a until CLCT trigger logic
133  // stops combining it with the info from the other 4 CFEBs (ME1/b).
134  // if ( me1a ) { cfeb_corr = 0; } // reset 4 to 0
135  if ( me1a && zplus ) {distrip_corr = 7-distrip;} // 0-7 -> 7-0
136  if ( me1b && !zplus ) {distrip_corr = 7-distrip; cfeb_corr = 3-cfeb;}
137  }
138 
139  int strip = 16*cfeb_corr + 2*distrip_corr + 1;
140 
141  if (debug)
142  LogTrace ("CSCCLCTData|CSCRawToDigi")
143  << "fillComparatorOutputs: cfeb_corr = " << cfeb_corr
144  << " distrip_corr = " << distrip_corr << " strip = " << strip;
145 
146  if (doStripSwapping && (( me1a && zplus ) || ( me1b && !zplus ))) {
147  // Half-strips need to be flipped too.
148  if (tbinbitsS1HS1) result.push_back(CSCComparatorDigi(strip, 0, tbinbitsS1HS1));
149  if (tbinbitsS1HS0) result.push_back(CSCComparatorDigi(strip, 1, tbinbitsS1HS0));
150  if (tbinbitsS0HS1) result.push_back(CSCComparatorDigi(strip+1, 0, tbinbitsS0HS1));
151  if (tbinbitsS0HS0) result.push_back(CSCComparatorDigi(strip+1, 1, tbinbitsS0HS0));
152  }
153  else {
154  if (tbinbitsS0HS0) result.push_back(CSCComparatorDigi(strip, 0, tbinbitsS0HS0));
155  if (tbinbitsS0HS1) result.push_back(CSCComparatorDigi(strip, 1, tbinbitsS0HS1));
156  if (tbinbitsS1HS0) result.push_back(CSCComparatorDigi(strip+1, 0, tbinbitsS1HS0));
157  if (tbinbitsS1HS1) result.push_back(CSCComparatorDigi(strip+1, 1, tbinbitsS1HS1));
158  }
159  //uh oh ugly ugly ugly!
160  }
161  }//end of loop over distrips
162  return result;
163 }
164 
165 
166 
167 std::vector<CSCComparatorDigi> CSCCLCTData::comparatorDigis(int layer)
168 {
169  //returns comparators for one layer for all cfebs
170  std::vector<CSCComparatorDigi> result;
171  assert(layer>0 && layer<= 6);
172 
173  for(int cfeb = 0; cfeb < ncfebs_; ++cfeb)
174  {
175  std::vector<CSCComparatorDigi> oneCfebDigi = comparatorDigis(layer,cfeb);
176  result.insert(result.end(), oneCfebDigi.begin(), oneCfebDigi.end());
177  }
178 
179  return result;
180 }
181 
182 
183 void CSCCLCTData::add(const CSCComparatorDigi & digi, int layer)
184 {
185  //FIXME do flipping
186  int strip = digi.getStrip();
187  int halfStrip = (strip-1)*2 + digi.getComparator();
188  int cfeb = (strip-1)/16;
189  int distrip = ((strip-1)%16) / 2;
190  assert(distrip < 8 && cfeb < 6 && halfStrip < 161);
191 
192  std::vector<int> timeBinsOn = digi.getTimeBinsOn();
193  for(std::vector<int>::const_iterator tbinItr = timeBinsOn.begin();
194  tbinItr != timeBinsOn.end(); ++tbinItr)
195  {
196  int tbin = *tbinItr;
197  if(tbin >= 0 && tbin < ntbins_-2) {
198  // First triad bit indicates the presence of the hit
199  dataWord(cfeb, tbin, layer).set(distrip, true);
200  // Second bit indicates which of the two strips contains the hit
201  if (strip%2 == 0)
202  dataWord(cfeb, tbin+1, layer).set(distrip, true);
203  // Third bit indicates whether the hit is located on the left or on the
204  // right side of the strip.
205  if (digi.getComparator())
206  dataWord(cfeb, tbin+2, layer).set(distrip, true);
207  }
208  }
209 }
210 
211 
212 bool CSCCLCTData::check() const
213 {
214  bool result = true;
215  for(int cfeb = 0; cfeb < ncfebs_; ++cfeb)
216  {
217  for(int tbin = 0; tbin < ntbins_; ++tbin)
218  {
219  for(int layer = 1; layer <= 6; ++layer)
220  {
222  const CSCCLCTDataWord & word = dataWord(cfeb, tbin, layer);
223  bool wordIsGood = (word.tbin_ == tbin) && (word.cfeb_ == cfeb);
224  result = result && wordIsGood;
225  if(!wordIsGood && debug)
226  {
227  LogTrace("CSCCLCTData|CSCRawToDigi") << "Bad CLCT data in layer " << layer
228  << " expect CFEB " << cfeb << " tbin " << tbin;
229  LogTrace("CSCCLCTData|CSCRawToDigi") << " See " << word.cfeb_ << " "
230  << word.tbin_;
231  }
232  }
233  }
234  }
235  if(!result) LogTrace("CSCCLCTData|CSCRawToDigi") << "++ Bad CLCT Data ++ ";
236  return result;
237 }
238 
239 
240 void CSCCLCTData::dump() const {
241  for (int i=0;i<size_;i++) {
242  printf("%04x %04x %04x %04x\n", theData[i+3], theData[i+2], theData[i+1], theData[i]);
243  i+=3;
244  }
245 }
246 
247 
249 {
250  CSCCLCTData clctData(5, 16);
251  // aim for output 4 in 5th time bin, = 0000000000010000
252  CSCComparatorDigi comparatorDigi1(1, 0, 0x10);
253  // aim for output 5 in 6th time bin, = 0000 0000 0010 0000
254  CSCComparatorDigi comparatorDigi2(39, 1, 0x20);
255  // aim for output 7 in 7th time bin, = 000 0000 0100 0000
256  CSCComparatorDigi comparatorDigi3(80, 1, 0x40);
257 
258  clctData.add(comparatorDigi1,1);
259  clctData.add(comparatorDigi2,4);
260  clctData.add(comparatorDigi3,6);
261 
262  CSCDetId layer1(1,4,1,2,1);
263  CSCDetId layer4(1,4,1,2,4);
264  CSCDetId layer6(1,4,1,2,6);
265 
266  std::vector<CSCComparatorDigi> digis1 = clctData.comparatorDigis(1);
267  std::vector<CSCComparatorDigi> digis2 = clctData.comparatorDigis(4);
268  std::vector<CSCComparatorDigi> digis3 = clctData.comparatorDigis(6);
269 
270  assert(digis1.size() == 1);
271  assert(digis2.size() == 1);
272  assert(digis3.size() == 1);
273 
274  assert(digis1[0].getStrip() == 1);
275  assert(digis1[0].getComparator() == 0);
276  assert(digis1[0].getTimeBin() == 4);
277 
278  assert(digis2[0].getStrip() == 39);
279  assert(digis2[0].getComparator() == 1);
280  assert(digis2[0].getTimeBin() == 5);
281 
282  assert(digis3[0].getStrip() == 80);
283  assert(digis3[0].getComparator() == 1);
284  assert(digis3[0].getTimeBin() == 6);
285 }
286 
int i
Definition: DBlmapReader.cc:9
int nlines() const
Definition: CSCCLCTData.h:41
int getStrip() const
Get the strip number.
static void selfTest()
Definition: CSCCLCTData.cc:248
void set(int distrip, bool value)
@ not right! doesn&#39;t set zero
Definition: CSCCLCTData.h:12
CSCCLCTDataWord & dataWord(int iline) const
Definition: CSCCLCTData.h:46
unsigned short cfeb_
Definition: CSCCLCTData.h:15
int getComparator() const
Get Comparator readings.
int layer() const
Definition: CSCDetId.h:63
int endcap() const
Definition: CSCDetId.h:95
unsigned short theData[5 *6 *32]
Definition: CSCCLCTData.h:83
void dump() const
Definition: CSCCLCTData.cc:240
bool bitValue(int cfeb, int tbin, int layer, int distrip)
Definition: CSCCLCTData.h:60
tuple result
Definition: query.py:137
std::vector< int > getTimeBinsOn() const
CSCCLCTData(const CSCTMBHeader *tmbHeader)
Definition: CSCCLCTData.cc:12
#define LogTrace(id)
std::vector< CSCComparatorDigi > comparatorDigis(int layer)
layers count from one
Definition: CSCCLCTData.cc:167
int ring() const
Definition: CSCDetId.h:77
unsigned short tbin_
Definition: CSCCLCTData.h:14
void add(const CSCComparatorDigi &digi, int layer)
TODO for packing. Doesn&#39;t do flipping yet.
Definition: CSCCLCTData.cc:183
bool check() const
Definition: CSCCLCTData.cc:212
static bool debug
Definition: CSCCLCTData.h:79
int station() const
Definition: CSCDetId.h:88
void zero()
Definition: CSCCLCTData.cc:42