CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/EventFilter/CSCRawToDigi/src/CSCAnodeData2006.cc

Go to the documentation of this file.
00001 #include "EventFilter/CSCRawToDigi/interface/CSCAnodeData2006.h"
00002 #include "EventFilter/CSCRawToDigi/interface/CSCALCTHeader.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 #include <string.h> // for bzero
00005 
00006 bool debug = false;
00007 #include <iostream>
00008 
00009 CSCAnodeDataFrame2006::CSCAnodeDataFrame2006(unsigned chip, unsigned tbin, unsigned data)
00010 : theFrame(0)
00011 {
00012    // lowest bit, plus the OR of the next two.
00013    unsigned packedChip = ( (chip&1) + 2*(chip>1) );
00014    theFrame = data + ((tbin&0x1F) << 8) + (packedChip<<13);
00015 }
00016 
00017 
00018 CSCAnodeData2006::CSCAnodeData2006(const CSCALCTHeader & header) 
00019   : nAFEBs_(header.nLCTChipRead()), nTimeBins_(header.NTBins()) 
00020 {
00021   LogTrace ("CSCAnodeData|CSCRawToDigi") << "Making Anode data " 
00022                               << sizeInWords() << " AFEB " << nAFEBs_ 
00023                               << " TBINS " << nTimeBins_;
00024   bzero(theDataFrames, sizeInWords()*2);
00025   for(int afeb = 0; afeb < nAFEBs_; ++afeb) {
00026     for(int tbin = 0; tbin < nTimeBins_; ++tbin) {
00027       for(int layer = 1; layer <= 6; ++layer) {
00028         for(int halfLayer = 0; halfLayer < 2; ++halfLayer) {
00029           theDataFrames[index(afeb, tbin, layer)+halfLayer] = CSCAnodeDataFrame2006(afeb, tbin, 0).frame();
00030         }
00031       }
00032     }
00033   }
00035     alctBX_= header.BXNCount();
00036 }
00037 
00038 // initialize
00039 CSCAnodeData2006::CSCAnodeData2006(const CSCALCTHeader & header ,
00040                                const unsigned short *buf) 
00041   : nAFEBs_(header.nLCTChipRead()), 
00042     nTimeBins_(header.NTBins())
00043 {
00044 
00048   LogTrace ("CSCAnodeData|CSCRawToDigi") << "nAFEBs = " << nAFEBs_ << "  nTimeBins = " 
00049                                 << nTimeBins_ << " nFrames = " << sizeInWords();  
00050   LogTrace ("CSCAnodeData|CSCRawToDigi") << header << " HEADER CHECK " << header.check();
00051 
00052   memcpy(theDataFrames, buf, sizeInWords()*2);
00053 }
00054 
00055 
00056 std::vector<CSCWireDigi> CSCAnodeData2006::wireDigis(int layer) const {
00057   std::vector<CSCWireDigi> digis;
00058   uint32_t tbinbits=0;
00059   uint16_t wireGroup=0;
00060     for(int afeb = 0; afeb < nAFEBs_; ++afeb) {
00061       for(int halfLayer = 0; halfLayer <2; ++halfLayer) {
00062         for (int j=0;j<8;++j) {
00063           for(int tbin = 0; tbin < nTimeBins_; ++tbin) {
00064             CSCAnodeDataFrame2006 frame(rawHit(afeb,tbin,layer, halfLayer));
00065             // see if there's anything in 1st 8 bits.  Usually zero
00066             if(frame.data() != 0) {
00067               if(frame.isHit(j)) {
00068                 tbinbits=tbinbits + (1<<tbin);      
00069               }
00070             }
00071           }//end of tbin loop
00072           if (tbinbits !=0 ) {
00073             wireGroup = (afeb*16+halfLayer*8+j)+1;
00074             uint32_t wireGroupBX=alctBX_;
00075             wireGroup = wireGroup | (wireGroupBX << 16);
00076             CSCWireDigi digi(wireGroup, tbinbits);
00077             if (debug)
00078               LogTrace ("CSCAnodeData|CSCRawToDigi") << "Layer " << layer << " " << digi;
00079             digis.push_back(digi);
00080             tbinbits=0;
00081           }
00082         }
00083       }
00084     }
00085     
00086   return digis;
00087 }
00088 
00089 
00090 void CSCAnodeData2006::add(const CSCWireDigi & digi, int layer) 
00091 {
00092 
00093   int wireGroup = digi.getWireGroup();
00094   int bxn=digi.getBeamCrossingTag(); 
00095   int alctBoard  = (wireGroup-1) / 16;
00096   int localGroup = (wireGroup-1) % 16;
00097 
00098   // crash if there's a bad wire number, but don't freak out
00099   // if a time bin is out of range 
00100   //  assert(alctBoard < nAFEBs_);
00101   if(alctBoard > nAFEBs_)
00102     {
00103       edm::LogError("CSCAnodeData|CSCRawToDigi") << "Bad Wire Number for this digi.";
00104       return;
00105     }
00106   if(bxn >= 0 && bxn < nTimeBins_) 
00107     {
00108       // 12 16-bit words per time bin, two per layer
00109       // wiregroups 0-7 go on the first line, 8-15 go on the 2nd.
00110       unsigned halfLayer = (localGroup > 7);
00111       unsigned bitNumber = localGroup % 8;
00112       // and pack it in the 8 bits allocated
00113       addHit(alctBoard, bxn, layer, halfLayer, bitNumber);
00114     } 
00115   else 
00116     {
00117       LogTrace("CSCAnodeData|CSCRawToDigi")<< "warning: not saving anode data in bx " << bxn 
00118                               << ": out of range ";
00119     }
00120 }
00121 
00122 
00123 void CSCAnodeData2006::addHit(int afeb, int tbin, int layer, int halfLayer, unsigned wireBit)
00124 {
00125   int i = index(afeb,tbin,layer) + halfLayer;
00126   CSCAnodeDataFrame2006 frame(theDataFrames[i]);
00127   frame.addHit(wireBit);
00128   theDataFrames[i] = frame.frame(); 
00129 }
00130 
00131 
00132 CSCAnodeDataFrame2006 CSCAnodeData2006::rawHit(int afeb, int tbin, int layer, int halfLayer) const
00133 {
00134   return CSCAnodeDataFrame2006(theDataFrames[index(afeb, tbin, layer)+halfLayer]);
00135 }
00136 
00137 
00138 int CSCAnodeData2006::index(int afeb, int tbin, int layer) const {
00139   int result = (layer-1)*2 + 12*tbin + afeb*12*nTimeBins_;
00140   assert(result < sizeInWords());
00141   return result;
00142 }
00143 
00144 #include <iostream>
00145 void CSCAnodeData2006::selfTest()
00146 {
00147   CSCAnodeDataFrame2006 frame(2, 15, 32); 
00148   assert(frame.chip() == 2);
00149   assert(frame.tbin() == 15);
00150   assert(frame.data() == 32);
00151   assert(frame.isHit(5));
00152   assert(!frame.isHit(7));
00153   frame.addHit(7);
00154   assert(frame.isHit(7));
00155 
00156   CSCWireDigi wireDigi(10, (1 << 4));
00157   CSCALCTHeader header(7);
00158   CSCAnodeData2006 anodeData(header);
00159   anodeData.add(wireDigi, 1);
00160   anodeData.add(wireDigi, 6);
00161 
00162   std::vector<CSCWireDigi> wires1 = anodeData.wireDigis(1);
00163   std::vector<CSCWireDigi> wires6 = anodeData.wireDigis(6);
00164 
00165   assert(wires1.size() == 1);
00166   assert(wires6.size() == 1);
00167   assert(wires1[0].getWireGroup() == 10);
00168   assert(wires6[0].getWireGroup() == 10);
00169 }
00170 
00171