CMS 3D CMS Logo

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