CMS 3D CMS Logo

CSCAnodeData2006.cc
Go to the documentation of this file.
5 #include <cstring> // for bzero
6 #include <iostream>
7 
8 CSCAnodeDataFrame2006::CSCAnodeDataFrame2006(unsigned chip, unsigned tbin, unsigned data) : theFrame(0) {
9  // lowest bit, plus the OR of the next two.
10  unsigned packedChip = ((chip & 1) + 2 * (chip > 1));
11  theFrame = data + ((tbin & 0x1F) << 8) + (packedChip << 13);
12 }
13 
15  : nAFEBs_(header.nLCTChipRead()), nTimeBins_(header.NTBins()) {
16  LogTrace("CSCAnodeData|CSCRawToDigi") << "Making Anode data " << sizeInWords() << " AFEB " << nAFEBs_ << " TBINS "
17  << nTimeBins_;
18  bzero(theDataFrames, sizeInWords() * 2);
19  for (int afeb = 0; afeb < nAFEBs_; ++afeb) {
20  for (int tbin = 0; tbin < nTimeBins_; ++tbin) {
22  for (int halfLayer = 0; halfLayer < 2; ++halfLayer) {
23  theDataFrames[index(afeb, tbin, layer) + halfLayer] = CSCAnodeDataFrame2006(afeb, tbin, 0).frame();
24  }
25  }
26  }
27  }
29  alctBX_ = header.BXNCount();
30 }
31 
32 // initialize
34  : nAFEBs_(header.nLCTChipRead()), nTimeBins_(header.NTBins()) {
38  LogTrace("CSCAnodeData|CSCRawToDigi") << "nAFEBs = " << nAFEBs_ << " nTimeBins = " << nTimeBins_
39  << " nFrames = " << sizeInWords();
40  LogTrace("CSCAnodeData|CSCRawToDigi") << header << " HEADER CHECK " << header.check();
41 
42  memcpy(theDataFrames, buf, sizeInWords() * 2);
43 }
44 
45 std::vector<CSCWireDigi> CSCAnodeData2006::wireDigis(int layer) const {
46  std::vector<CSCWireDigi> digis;
47  uint32_t tbinbits = 0;
48  uint16_t wireGroup = 0;
49  for (int afeb = 0; afeb < nAFEBs_; ++afeb) {
50  for (int halfLayer = 0; halfLayer < 2; ++halfLayer) {
51  for (int j = 0; j < 8; ++j) {
52  for (int tbin = 0; tbin < nTimeBins_; ++tbin) {
53  CSCAnodeDataFrame2006 frame(rawHit(afeb, tbin, layer, halfLayer));
54  // see if there's anything in 1st 8 bits. Usually zero
55  if (frame.data() != 0) {
56  if (frame.isHit(j)) {
57  tbinbits = tbinbits + (1 << tbin);
58  }
59  }
60  } //end of tbin loop
61  if (tbinbits != 0) {
62  wireGroup = (afeb * 16 + halfLayer * 8 + j) + 1;
63  uint32_t wireGroupBX = alctBX_;
64  wireGroup = wireGroup | (wireGroupBX << 16);
65  CSCWireDigi digi(wireGroup, tbinbits);
66  LogTrace("CSCAnodeData|CSCRawToDigi") << "Layer " << layer << " " << digi;
67  digis.push_back(digi);
68  tbinbits = 0;
69  }
70  }
71  }
72  }
73 
74  return digis;
75 }
76 
77 void CSCAnodeData2006::add(const CSCWireDigi &digi, int layer) {
78  int wireGroup = digi.getWireGroup();
79  int bxn = digi.getBeamCrossingTag();
80  int alctBoard = (wireGroup - 1) / 16;
81  int localGroup = (wireGroup - 1) % 16;
82 
83  // crash if there's a bad wire number, but don't freak out
84  // if a time bin is out of range
85  // assert(alctBoard < nAFEBs_);
86  if (alctBoard > nAFEBs_) {
87  edm::LogError("CSCAnodeData|CSCRawToDigi") << "Bad Wire Number for this digi.";
88  return;
89  }
90  if (bxn >= 0 && bxn < nTimeBins_) {
91  // 12 16-bit words per time bin, two per layer
92  // wiregroups 0-7 go on the first line, 8-15 go on the 2nd.
93  unsigned halfLayer = (localGroup > 7);
94  unsigned bitNumber = localGroup % 8;
95  // and pack it in the 8 bits allocated
96  addHit(alctBoard, bxn, layer, halfLayer, bitNumber);
97  } else {
98  LogTrace("CSCAnodeData|CSCRawToDigi") << "warning: not saving anode data in bx " << bxn << ": out of range ";
99  }
100 }
101 
102 void CSCAnodeData2006::addHit(int afeb, int tbin, int layer, int halfLayer, unsigned wireBit) {
103  int i = index(afeb, tbin, layer) + halfLayer;
105  frame.addHit(wireBit);
106  theDataFrames[i] = frame.frame();
107 }
108 
109 CSCAnodeDataFrame2006 CSCAnodeData2006::rawHit(int afeb, int tbin, int layer, int halfLayer) const {
110  return CSCAnodeDataFrame2006(theDataFrames[index(afeb, tbin, layer) + halfLayer]);
111 }
112 
113 int CSCAnodeData2006::index(int afeb, int tbin, int layer) const {
114  int result = (layer - 1) * 2 + 12 * tbin + afeb * 12 * nTimeBins_;
116  return result;
117 }
118 
119 #include <iostream>
121  CSCAnodeDataFrame2006 frame(2, 15, 32);
122  assert(frame.chip() == 2);
123  assert(frame.tbin() == 15);
124  assert(frame.data() == 32);
125  assert(frame.isHit(5));
126  assert(!frame.isHit(7));
127  frame.addHit(7);
128  assert(frame.isHit(7));
129 
130  CSCWireDigi wireDigi(10, (1 << 4));
132  CSCAnodeData2006 anodeData(header);
133  anodeData.add(wireDigi, 1);
134  anodeData.add(wireDigi, 6);
135 
136  std::vector<CSCWireDigi> wires1 = anodeData.wireDigis(1);
137  std::vector<CSCWireDigi> wires6 = anodeData.wireDigis(6);
138 
139  assert(wires1.size() == 1);
140  assert(wires6.size() == 1);
141  assert(wires1[0].getWireGroup() == 10);
142  assert(wires6[0].getWireGroup() == 10);
143 }
int index(int afeb, int tbin, int layer) const
the index into theDataFrames
unsigned chip() const
unsigned int alctBX_
unsigned short frame() const
unsigned short theDataFrames[2700]
we don&#39;t know the size at first. Max should be 7 boards * 32 bins * 6 layers * 2
Log< level::Error, false > LogError
unsigned tbin() const
time bin
assert(be >=bs)
#define LogTrace(id)
unsigned short theFrame
unsigned short data() const
static void selfTest()
CSCAnodeDataFrame2006 rawHit(int afeb, int tbin, int layer, int halfLayer) const
CSCAnodeData2006(const CSCALCTHeader &)
a blank one, for Monte Carlo
static int minLayerId()
Definition: CSCDetId.h:242
int nAFEBs_
in 2007 format the max number of frames is 1860
void add(const CSCWireDigi &, int layer) override
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
void addHit(int afeb, int tbin, int layer, int halfLayer, unsigned wireBit)
unsigned short int sizeInWords() const override
the amount of the input binary buffer read, in 16-bit words
std::vector< CSCWireDigi > wireDigis(int layer) const override
input layer is from 1 to 6
int getBeamCrossingTag() const
return tbin number, (obsolete, use getTimeBin() instead)
Definition: CSCWireDigi.cc:33
static int maxLayerId()
Definition: CSCDetId.h:243
int getWireGroup() const
default
Definition: CSCWireDigi.h:22