CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/EventFilter/CSCRawToDigi/src/CSCAnodeData2007.cc

Go to the documentation of this file.
00001 #include "EventFilter/CSCRawToDigi/interface/CSCAnodeData2007.h"
00002 #include "EventFilter/CSCRawToDigi/interface/CSCALCTHeader.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 #include <string.h> // for bzero
00005 #include<iostream>
00006 
00007 CSCAnodeData2007::CSCAnodeData2007(const CSCALCTHeader & header)
00008   : nAFEBs_(header.nLCTChipRead()), nTimeBins_(header.NTBins())
00009 {
00010   init(header);
00011   bzero(theDataFrames, sizeInWords()*2);
00013   alctBX_= header.BXNCount();
00014 }
00015 
00016 
00017 CSCAnodeData2007::CSCAnodeData2007(const CSCALCTHeader & header ,
00018                                    const unsigned short *buf) 
00019   : nAFEBs_(header.nLCTChipRead()), nTimeBins_(header.NTBins())
00020 {
00021     init(header);
00022     memcpy(theDataFrames, buf, sizeInWords()*2);
00023 
00024    alctBX_= header.BXNCount();
00025 }
00026 
00027 
00028 void CSCAnodeData2007::init(const CSCALCTHeader & header) {
00032   static unsigned short int layerParts[7]    = { 3, 3, 4, 6, 6, 8,10};
00033   static unsigned short int wireGroups[7]    = {32,32,48,64,64,96,112};
00034   //header.ALCTDigis();
00035   sizeInWords2007_=(1-header.alctHeader2007().rawOverflow)*6*
00036   header.alctHeader2007().rawBins*layerParts[header.alctHeader2007().boardType];
00037   layerParts_ = layerParts[header.alctHeader2007().boardType];
00038   maxWireGroups_ = wireGroups[header.alctHeader2007().boardType];
00039 }
00040 
00041 
00042 std::vector<CSCWireDigi> CSCAnodeData2007::wireDigis(int layer) const {
00043   std::vector<CSCWireDigi> digis;
00044   uint32_t tbinbits=0;
00045   uint32_t wireGroup=0;
00047   for(int layerPart = 0; layerPart <layerParts_; ++layerPart) {
00049     for (int j=0; (j<12)&&((layerPart*12+j)<maxWireGroups_) ;++j) {
00052       for(int tbin = 0; tbin < nTimeBins_; ++tbin) { 
00053         CSCAnodeDataFrame2007 frame = findFrame(tbin, layer, layerPart);
00054         if(frame.data() != 0) {
00055           if(frame.isHit(j)) {
00056             tbinbits=tbinbits + (1<<tbin);
00057           }
00058         }
00059       }//end of tbin loop
00060       if (tbinbits !=0 ) {
00061         wireGroup = (layerPart*12+j)+1;
00063         uint32_t wireGroupBX=alctBX_;
00064         wireGroup = wireGroup | (wireGroupBX << 16);
00065         CSCWireDigi digi(wireGroup, tbinbits);
00066         LogTrace ("CSCAnodeData|CSCRawToDigi") << "Layer " << layer << " " << digi;
00067         digis.push_back(digi);
00068         tbinbits=0;
00069       }
00070     }
00071   }
00072   
00073   return digis;
00074 }
00075 
00076 
00077 CSCAnodeDataFrame2007 CSCAnodeData2007::findFrame(int tbin, int layer, int layerPart) const {
00078   return CSCAnodeDataFrame2007(theDataFrames[index(tbin, layer, layerPart)]);
00079 }
00080 
00081 
00082 int CSCAnodeData2007::index(int tbin, int layer, int layerPart) const 
00083 {
00084   assert(tbin<nTimeBins_);
00085   assert(layer<=6);
00086   assert(layerPart<layerParts_);
00087   int result = tbin*6*layerParts_+(layer-1)*layerParts_+layerPart;
00088   assert(result < MAXFRAMES);
00089   return result;
00090 }
00091 
00092 
00093 void CSCAnodeData2007::add(const CSCWireDigi & digi, int layer) 
00094 {
00095   int wireGroup = digi.getWireGroup();
00096   //           wireGroup = (layerPart*12+j)+1;
00097   unsigned layerPart = (wireGroup-1) / 12;
00098   unsigned wireInPart = (wireGroup-1) % 12; 
00099   std::vector<int> timeBinsOn = digi.getTimeBinsOn();
00100   for(std::vector<int>::const_iterator timeBinOn = timeBinsOn.begin();
00101       timeBinOn != timeBinsOn.end(); ++timeBinOn)
00102   {
00103     // crash if there's a bad wire number, but don't freak out
00104     // if a time bin is out of range 
00105     //  assert(alctBoard < nAFEBs_);
00106     if(layerPart >= layerParts_)
00107       {
00108         edm::LogError("CSCAnodeData|CSCRawToDigi") << "Bad Wire Number for this digi.";
00109         return;
00110       }
00111 
00112     if((*timeBinOn) >= 0 && (*timeBinOn) < nTimeBins_) 
00113       {
00114         CSCAnodeDataFrame2007 frame = findFrame(*timeBinOn, layer, layerPart);
00115         frame.addHit(wireInPart);
00116         // FIXME doesn't carry over the (currently 0) leading bits
00117         theDataFrames[index(*timeBinOn, layer, layerPart)]  = frame.data();
00118       } 
00119     else 
00120       {
00121         LogTrace("CSCAnodeData|CSCRawToDigi")<< "warning: not saving anode data in bx " << *timeBinOn 
00122                               << ": out of range ";
00123       }
00124   }
00125 }
00126 
00127 void CSCAnodeData2007::selfTest()
00128 {
00129   int wireGroup = 12;
00130   int timeBin = 6;
00131   CSCWireDigi wireDigi(wireGroup, (1 << timeBin));
00132   CSCALCTHeader header(1);
00133   CSCAnodeData2007 anodeData(header);
00134   anodeData.add(wireDigi, 1);
00135   anodeData.add(wireDigi, 6);
00136 
00137   std::vector<CSCWireDigi> wires1 = anodeData.wireDigis(1);
00138   std::vector<CSCWireDigi> wires6 = anodeData.wireDigis(6);
00139 
00140   assert(wires1.size() == 1);
00141   assert(wires6.size() == 1);
00142   assert(wires1[0].getWireGroup() == wireGroup);
00143   assert(wires6[0].getWireGroup() == wireGroup);
00144   assert(wires1[0].getTimeBin() == timeBin);
00145   assert(wires6[0].getTimeBin() == timeBin);
00146 
00147 }
00148