CMS 3D CMS Logo

CSCCLCTData.cc

Go to the documentation of this file.
00001 #include "EventFilter/CSCRawToDigi/interface/CSCCLCTData.h"
00002 #include "EventFilter/CSCRawToDigi/interface/CSCTMBHeader.h"
00003 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 #include <iostream>
00006 #include <stdio.h>
00007 
00008 bool CSCCLCTData::debug = false;
00009 
00010 
00011 CSCCLCTData::CSCCLCTData(const CSCTMBHeader * tmbHeader)
00012 : ncfebs_(tmbHeader->NCFEBs()), ntbins_(tmbHeader->NTBins())
00013 {
00014   size_ = nlines();
00015   zero();
00016 }
00017 
00018 
00019 CSCCLCTData::CSCCLCTData(int ncfebs, int ntbins)
00020 : ncfebs_(ncfebs), ntbins_(ntbins) 
00021 {
00022   size_ = nlines();
00023   zero();
00024 }
00025      
00026 
00027 
00028 
00029 CSCCLCTData::CSCCLCTData(int ncfebs, int ntbins, const unsigned short * buf)
00030 : ncfebs_(ncfebs), ntbins_(ntbins) 
00031 {
00032   // add two more for odd ntbins, plus one for the e0c
00033   // Oct 2004 Rick: e0c line belongs to CSCTMBTrailer
00034   size_ = (nlines()%2==1)? nlines()+2 : nlines();
00035   
00036   memcpy(theData, buf, size_*2);
00037   
00038 }
00039 
00040 
00041 void CSCCLCTData::zero()
00042 {
00043   for(int ifeb = 0; ifeb < ncfebs_; ++ifeb)
00044     {
00045       for(int tbin = 0; tbin < ntbins_; ++tbin)
00046         {
00047           for(int layer = 1; layer <= 6; ++layer)
00048             {
00049               dataWord(ifeb, tbin, layer) = CSCCLCTDataWord(ifeb, tbin, 0);
00050             }
00051         }
00052     }
00053 
00054 }
00055 
00056 
00057 std::vector<CSCComparatorDigi>  CSCCLCTData::comparatorDigis(uint32_t idlayer, unsigned cfeb) 
00058 {
00059   static const bool doStripSwapping = false;
00060   bool me1a = (CSCDetId::station(idlayer)==1) && (CSCDetId::ring(idlayer)==4);
00061   bool zplus = (CSCDetId::endcap(idlayer) == 1); 
00062   bool me1b = (CSCDetId::station(idlayer)==1) && (CSCDetId::ring(idlayer)==1);
00063   unsigned layer = CSCDetId::layer(idlayer);
00064 
00065   //looking for comp output on layer
00066   std::vector<CSCComparatorDigi> result;
00067   assert(layer>0 && layer<= 6);
00068   // this is pretty sparse data, so I wish we could check the
00069   // data word by word, not bit by bit, but I don't see how to
00070   // do the time sequencing that way.
00071   for(int distrip = 0; distrip < 8; ++distrip) 
00072     {
00073       uint16_t tbinbitsS0HS0=0;
00074       uint16_t tbinbitsS0HS1=0;
00075       uint16_t tbinbitsS1HS0=0;
00076       uint16_t tbinbitsS1HS1=0;
00077       for(int tbin = 0; tbin < ntbins_-2; ++tbin) 
00078         {
00079           if(bitValue(cfeb, tbin, layer, distrip))
00080             {
00082               CSCCLCTDataWord word = dataWord(cfeb, tbin, layer);
00083               assert(word.tbin_ == tbin);
00084               assert(word.cfeb_ == cfeb);
00085               // we have a hit.  The next two time samples
00086               // are the other two bits in the triad
00087               int bit2 = bitValue(cfeb, tbin+1, layer, distrip);
00088               int bit3 = bitValue(cfeb, tbin+2, layer, distrip);
00089               // should count from zero
00090               int chamberDistrip = distrip + cfeb*8;
00091               int HalfStrip = 4*chamberDistrip + bit2*2 + bit3;
00092               int output = 4 + bit2*2 + bit3;
00093               /*
00094                * Handles distrip logic; comparator output is for pairs of strips:
00095                * hit  bin  dec
00096                * x--- 100   4
00097                * -x-- 101   5
00098                * --x- 110   6
00099                * ---x 111   7
00100                *
00101                */
00102 
00103         if (debug)
00104           LogTrace ("CSCCLCTData|CSCRawToDigi")
00105                   << "fillComparatorOutputs: layer = "
00106                   << layer << " timebin = " << tbin
00107                   << " cfeb = " << cfeb << " distrip = " << chamberDistrip
00108                   << " HalfStrip = " << HalfStrip
00109                   << " Output " << output << std::endl;
00111 
00113               if (output==4) tbinbitsS0HS0=tbinbitsS0HS0+(1<<tbin);      
00114               if (output==5) tbinbitsS0HS1=tbinbitsS0HS1+(1<<tbin);
00115               if (output==6) tbinbitsS1HS0=tbinbitsS1HS0+(1<<tbin);
00116               if (output==7) tbinbitsS1HS1=tbinbitsS1HS1+(1<<tbin);
00117               
00118               tbin += 2;
00119             }
00120         }//end of loop over time bins
00121       //we do not have to check over the last couple of time bins if there are no hits since
00122       //comparators take 3 time bins
00123 
00124       // Store digis each of possible four halfstrips for given distrip:
00125       if (tbinbitsS0HS0 || tbinbitsS0HS1 || tbinbitsS1HS0 || tbinbitsS1HS1) {
00126         unsigned int cfeb_corr    = cfeb;
00127         unsigned int distrip_corr = distrip;
00128 
00129         if (doStripSwapping) {
00130           // Fix ordering of strips and CFEBs in ME1/1.
00131           // SV, 27/05/08: keep CFEB=4 for ME1/a until CLCT trigger logic
00132           // stops combining it with the info from the other 4 CFEBs (ME1/b).
00133           // if ( me1a )           { cfeb_corr = 0; } // reset 4 to 0
00134           if ( me1a &&  zplus ) {distrip_corr = 7-distrip;} // 0-7 -> 7-0
00135           if ( me1b && !zplus ) {distrip_corr = 7-distrip; cfeb_corr = 3-cfeb;}
00136         }
00137 
00138         int strip = 16*cfeb_corr + 2*distrip_corr + 1;
00139 
00140         if (debug)
00141           LogTrace ("CSCCLCTData|CSCRawToDigi")
00142             << "fillComparatorOutputs: cfeb_corr = " << cfeb_corr
00143             << " distrip_corr = " << distrip_corr << " strip = " << strip;
00144 
00145         if (doStripSwapping && (( me1a && zplus ) || ( me1b && !zplus ))) {
00146           // Half-strips need to be flipped too.
00147           if (tbinbitsS1HS1) result.push_back(CSCComparatorDigi(strip, 0, tbinbitsS1HS1));
00148           if (tbinbitsS1HS0) result.push_back(CSCComparatorDigi(strip, 1, tbinbitsS1HS0));
00149           if (tbinbitsS0HS1) result.push_back(CSCComparatorDigi(strip+1, 0, tbinbitsS0HS1));
00150           if (tbinbitsS0HS0) result.push_back(CSCComparatorDigi(strip+1, 1, tbinbitsS0HS0));
00151         }
00152         else {
00153           if (tbinbitsS0HS0) result.push_back(CSCComparatorDigi(strip, 0, tbinbitsS0HS0));
00154           if (tbinbitsS0HS1) result.push_back(CSCComparatorDigi(strip, 1, tbinbitsS0HS1));
00155           if (tbinbitsS1HS0) result.push_back(CSCComparatorDigi(strip+1, 0, tbinbitsS1HS0));
00156           if (tbinbitsS1HS1) result.push_back(CSCComparatorDigi(strip+1, 1, tbinbitsS1HS1));
00157         }
00158         //uh oh ugly ugly ugly!
00159       }
00160     }//end of loop over distrips
00161   return result;
00162 }
00163 
00164 
00165 
00166 std::vector<CSCComparatorDigi>  CSCCLCTData::comparatorDigis(int layer) 
00167 {
00168   //returns comparators for one layer for all cfebs
00169   std::vector<CSCComparatorDigi> result;
00170   assert(layer>0 && layer<= 6);
00171 
00172   for(int cfeb = 0; cfeb < ncfebs_; ++cfeb) 
00173     {
00174       std::vector<CSCComparatorDigi> oneCfebDigi = comparatorDigis(layer,cfeb);
00175       result.insert(result.end(), oneCfebDigi.begin(), oneCfebDigi.end());      
00176     }
00177 
00178   return result;
00179 }
00180 
00181 
00182 void CSCCLCTData::add(const CSCComparatorDigi & digi, int layer)
00183 {
00184   //FIXME do flipping
00185   int strip = digi.getStrip();
00186   int halfStrip = (strip-1)*2 + digi.getComparator();
00187   int cfeb = (strip-1)/16;
00188   int distrip = ((strip-1)%16) / 2;
00189   assert(distrip < 8 && cfeb < 6 && halfStrip < 161);
00190 
00191   std::vector<int> timeBinsOn = digi.getTimeBinsOn();
00192   for(std::vector<int>::const_iterator tbinItr = timeBinsOn.begin();
00193       tbinItr != timeBinsOn.end(); ++tbinItr)
00194   {
00195     int tbin = *tbinItr;
00196     if(tbin >= 0 && tbin < ntbins_-2) {
00197       // First triad bit indicates the presence of the hit
00198       dataWord(cfeb, tbin, layer).set(distrip, true);
00199       // Second bit indicates which of the two strips contains the hit
00200       if (strip%2 == 0)
00201         dataWord(cfeb, tbin+1, layer).set(distrip, true);
00202       // Third bit indicates whether the hit is located on the left or on the
00203       // right side of the strip.
00204       if (digi.getComparator())
00205         dataWord(cfeb, tbin+2, layer).set(distrip, true);
00206     }
00207   }
00208 }
00209 
00210 
00211 bool CSCCLCTData::check() const 
00212 {
00213   bool result = true;
00214   for(int cfeb = 0; cfeb < ncfebs_; ++cfeb) 
00215     {
00216       for(int tbin = 0; tbin < ntbins_; ++tbin)
00217         {
00218           for(int layer = 1; layer <= 6; ++layer) 
00219             {
00221               const CSCCLCTDataWord & word = dataWord(cfeb, tbin, layer);
00222               bool wordIsGood = (word.tbin_ == tbin) && (word.cfeb_ == cfeb);
00223               result = result && wordIsGood;
00224               if(!wordIsGood && debug)
00225                 {
00226                   LogTrace("CSCCLCTData|CSCRawToDigi") << "Bad CLCT data  in layer " << layer 
00227                                                << " expect CFEB " << cfeb << " tbin " << tbin;
00228                   LogTrace("CSCCLCTData|CSCRawToDigi") << " See " << word.cfeb_ << " " 
00229                                                << word.tbin_;
00230                 }
00231             }
00232         }
00233     }
00234   if(!result) LogTrace("CSCCLCTData|CSCRawToDigi") << "++ Bad CLCT Data ++ ";
00235   return result;
00236 }
00237 
00238 
00239 void CSCCLCTData::selfTest()
00240 {
00241   CSCCLCTData clctData(5, 16);
00242   // aim for output 4 in 5th time bin, = 0000000000010000
00243   CSCComparatorDigi comparatorDigi1(1, 0, 0x10);
00244   // aim for output 5 in 6th time bin, = 0000 0000 1010 0000
00245   CSCComparatorDigi comparatorDigi2(39, 1, 0xA0);
00246   // aim for output 7 in 7th time bin, = 000 0001 1100 0000
00247   CSCComparatorDigi comparatorDigi3(80, 1, 0x1C0);
00248 
00249   clctData.add(comparatorDigi1,1);
00250   clctData.add(comparatorDigi2,4);
00251   clctData.add(comparatorDigi3,6);
00252 
00253   CSCDetId layer1(1,4,1,2,1);  
00254   CSCDetId layer4(1,4,1,2,4);
00255   CSCDetId layer6(1,4,1,2,6);
00256 
00257   std::vector<CSCComparatorDigi> digis1 = clctData.comparatorDigis(1);
00258   std::vector<CSCComparatorDigi> digis2 = clctData.comparatorDigis(4);
00259   std::vector<CSCComparatorDigi> digis3 = clctData.comparatorDigis(6);
00260 
00261   assert(digis1.size() == 1);
00262   assert(digis2.size() == 1);
00263   assert(digis3.size() == 1);
00264 
00265   assert(digis1[0].getStrip() == 1);
00266   assert(digis1[0].getComparator() == 0);
00267   assert(digis1[0].getTimeBin() == 4);
00268 
00269   assert(digis2[0].getStrip() == 39);
00270   assert(digis2[0].getComparator() == 1);
00271   assert(digis2[0].getTimeBin() == 5);
00272 
00273   assert(digis3[0].getStrip() == 80);
00274   assert(digis3[0].getComparator() == 1);
00275   assert(digis3[0].getTimeBin() == 6);
00276 }
00277 

Generated on Tue Jun 9 17:34:23 2009 for CMSSW by  doxygen 1.5.4