CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCAnodeData2007.cc
Go to the documentation of this file.
4 #include <string.h> // for bzero
5 #include<iostream>
6 
8  : nAFEBs_(header.nLCTChipRead()), nTimeBins_(header.NTBins())
9 {
10  init(header);
11  bzero(theDataFrames, sizeInWords()*2);
13  alctBX_= header.BXNCount();
14 }
15 
16 
18  const unsigned short *buf)
19  : nAFEBs_(header.nLCTChipRead()), nTimeBins_(header.NTBins())
20 {
21  init(header);
22  memcpy(theDataFrames, buf, sizeInWords()*2);
23  alctBX_= header.BXNCount();
25 }
26 
27 
28 void CSCAnodeData2007::init(const CSCALCTHeader & header) {
32  static unsigned short int layerParts[7] = { 3, 3, 4, 6, 6, 8,10};
33  static unsigned short int wireGroups[7] = {32,32,48,64,64,96,112};
34  //header.ALCTDigis();
36  header.alctHeader2007().rawBins*layerParts[header.alctHeader2007().boardType];
37  layerParts_ = layerParts[header.alctHeader2007().boardType];
38  maxWireGroups_ = wireGroups[header.alctHeader2007().boardType];
39 }
40 
41 
42 std::vector<CSCWireDigi> CSCAnodeData2007::wireDigis(int layer) const {
43  std::vector<CSCWireDigi> digis;
44  uint32_t tbinbits=0;
45  uint32_t wireGroup=0;
47  for(int layerPart = 0; layerPart <layerParts_; ++layerPart) {
49  for (int j=0; (j<12)&&((layerPart*12+j)<maxWireGroups_) ;++j) {
52  for(int tbin = 0; tbin < nTimeBins_; ++tbin) {
53  CSCAnodeDataFrame2007 frame = findFrame(tbin, layer, layerPart);
54  if(frame.data() != 0) {
55  if(frame.isHit(j)) {
56  tbinbits=tbinbits + (1<<tbin);
57  }
58  }
59  }//end of tbin loop
60  if (tbinbits !=0 ) {
61  wireGroup = (layerPart*12+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  return digis;
74 }
75 
76 
77 CSCAnodeDataFrame2007 CSCAnodeData2007::findFrame(int tbin, int layer, int layerPart) const {
78  return CSCAnodeDataFrame2007(theDataFrames[index(tbin, layer, layerPart)]);
79 }
80 
81 
82 int CSCAnodeData2007::index(int tbin, int layer, int layerPart) const
83 {
84  assert(tbin<nTimeBins_);
85  assert(layer<=6);
86  assert(layerPart<layerParts_);
87  int result = tbin*6*layerParts_+(layer-1)*layerParts_+layerPart;
88  assert(result < MAXFRAMES);
89  return result;
90 }
91 
92 
93 void CSCAnodeData2007::add(const CSCWireDigi & digi, int layer)
94 {
95  int wireGroup = digi.getWireGroup();
96  // wireGroup = (layerPart*12+j)+1;
97  unsigned layerPart = (wireGroup-1) / 12;
98  unsigned wireInPart = (wireGroup-1) % 12;
99  std::vector<int> timeBinsOn = digi.getTimeBinsOn();
100  for(std::vector<int>::const_iterator timeBinOn = timeBinsOn.begin();
101  timeBinOn != timeBinsOn.end(); ++timeBinOn)
102  {
103  // crash if there's a bad wire number, but don't freak out
104  // if a time bin is out of range
105  // assert(alctBoard < nAFEBs_);
106  if(layerPart >= layerParts_)
107  {
108  edm::LogError("CSCAnodeData|CSCRawToDigi") << "Bad Wire Number for this digi.";
109  return;
110  }
111 
112  if((*timeBinOn) >= 0 && (*timeBinOn) < nTimeBins_)
113  {
114  CSCAnodeDataFrame2007 frame = findFrame(*timeBinOn, layer, layerPart);
115  frame.addHit(wireInPart);
116  // FIXME doesn't carry over the (currently 0) leading bits
117  theDataFrames[index(*timeBinOn, layer, layerPart)] = frame.data();
118  }
119  else
120  {
121  LogTrace("CSCAnodeData|CSCRawToDigi")<< "warning: not saving anode data in bx " << *timeBinOn
122  << ": out of range ";
123  }
124  }
125 }
126 
128 {
129  int wireGroup = 12;
130  int timeBin = 6;
131  CSCWireDigi wireDigi(wireGroup, (1 << timeBin));
132  CSCALCTHeader header(1);
133  CSCAnodeData2007 anodeData(header);
134  anodeData.add(wireDigi, 1);
135  anodeData.add(wireDigi, 6);
136 
137  std::vector<CSCWireDigi> wires1 = anodeData.wireDigis(1);
138  std::vector<CSCWireDigi> wires6 = anodeData.wireDigis(6);
139 
140  assert(wires1.size() == 1);
141  assert(wires6.size() == 1);
142  assert(wires1[0].getWireGroup() == wireGroup);
143  assert(wires6[0].getWireGroup() == wireGroup);
144  assert(wires1[0].getTimeBin() == timeBin);
145  assert(wires6[0].getTimeBin() == timeBin);
146 
147 }
148 
void init(const CSCALCTHeader &)
CSCAnodeData2007(const CSCALCTHeader &)
a blank one, for Monte Carlo
CSCALCTHeader2007 alctHeader2007() const
Definition: CSCALCTHeader.h:93
bool isHit(unsigned wireGroup) const
given a wiregroup between 0 and 11, it tells whether this bit was on
std::vector< int > getTimeBinsOn() const
return vector of time bins ON
Definition: CSCWireDigi.cc:48
static void selfTest()
tuple result
Definition: query.py:137
int j
Definition: DBlmapReader.cc:9
int index(int tbin, int layer, int layerPart) const
#define LogTrace(id)
CSCAnodeDataFrame2007 findFrame(int tbin, int layer, int layerPart) const
unsigned int alctBX_
number of wiregroups in the ALCT
int getWireGroup() const
default
Definition: CSCWireDigi.h:24
unsigned short theDataFrames[MAXFRAMES]
virtual unsigned short int sizeInWords() const
the amount of the input binary buffer read, in 16-bit words
unsigned short int sizeInWords2007_
virtual void add(const CSCWireDigi &, int layer)
unsigned short int maxWireGroups_
number of layer parts in the ALCT
void addHit(unsigned wireGroup)
unsigned short data() const
unsigned short int BXNCount() const
Definition: CSCALCTHeader.h:56
unsigned short int nTimeBins_
unsigned short int layerParts_
virtual std::vector< CSCWireDigi > wireDigis(int layer) const
input layer is from 1 to 6