Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-29 02:32:25

0001 /** \file
0002  *
0003  *
0004  * \author M.Schmitt, Northwestern
0005  */
0006 #include "DataFormats/CSCDigi/interface/CSCComparatorDigi.h"
0007 #include "DataFormats/CSCDigi/interface/CSCConstants.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include <iostream>
0010 #include <algorithm>
0011 #include <iterator>
0012 
0013 using namespace std;
0014 
0015 // Constructors
0016 CSCComparatorDigi::CSCComparatorDigi(int strip, int comparator, int timeBinWord)
0017     : strip_(strip), comparator_(comparator), timeBinWord_(timeBinWord) {}
0018 
0019 CSCComparatorDigi::CSCComparatorDigi() : strip_(0), comparator_(0), timeBinWord_(0) {}
0020 
0021 // Comparison
0022 
0023 bool CSCComparatorDigi::operator==(const CSCComparatorDigi& digi) const {
0024   if (getStrip() != digi.getStrip())
0025     return false;
0026   if (getComparator() != digi.getComparator())
0027     return false;
0028   if (getTimeBinWord() != digi.getTimeBinWord())
0029     return false;
0030   return true;
0031 }
0032 
0033 //@@ If one wanted to order comparator digis how would one want op< to behave?
0034 // I don't know...
0035 // I think LHS < RHS only makes sense if
0036 // i) time(LHS) .eq. time(RHS)
0037 // AND
0038 // ii) strip(LHS) .lt. strip(RHS)
0039 // But I don't see how this can be useful.
0040 
0041 bool CSCComparatorDigi::operator<(const CSCComparatorDigi& digi) const {
0042   bool result = false;
0043   if (getTimeBin() == digi.getTimeBin()) {
0044     result = (getStrip() < digi.getStrip());
0045   }
0046   return result;
0047 }
0048 
0049 // Getters
0050 
0051 int CSCComparatorDigi::getTimeBin() const {
0052   // Find first bin which fired, counting from 0
0053   uint16_t tbit = 1;
0054   int tbin = -1;
0055   for (int i = 0; i < 16; ++i) {
0056     if (tbit & timeBinWord_) {
0057       tbin = i;
0058       break;
0059     }
0060     tbit = tbit << 1;
0061   }
0062   return tbin;
0063 }
0064 
0065 /// Get the distrip number. Counts from 0.
0066 // originally defined in EventFilter/CSCRawToDigi/src/CSCComparatorData.cc
0067 int CSCComparatorDigi::getDiStrip() const { return ((strip_ - 1) % CSCConstants::NUM_STRIPS_PER_CFEB) / 2; }
0068 
0069 /// Get the CFEB number. Counts from 0.
0070 // originally defined in EventFilter/CSCRawToDigi/src/CSCComparatorData.cc
0071 int CSCComparatorDigi::getCFEB() const { return (strip_ - 1) / CSCConstants::NUM_STRIPS_PER_CFEB; }
0072 
0073 // This definition is consistent with the one used in
0074 // the function CSCComparatorData::add() in EventFilter/CSCRawToDigi
0075 // The halfstrip counts from 0!
0076 int CSCComparatorDigi::getHalfStrip() const { return (getStrip() - 1) * 2 + getComparator(); }
0077 
0078 // Return the fractional half-strip
0079 float CSCComparatorDigi::getFractionalStrip() const { return getStrip() + getComparator() * 0.5f - 0.75f; }
0080 
0081 std::vector<int> CSCComparatorDigi::getTimeBinsOn() const {
0082   std::vector<int> tbins;
0083   uint16_t tbit = timeBinWord_;
0084   const uint16_t one = 1;
0085   for (int i = 0; i < 16; ++i) {
0086     if (tbit & one)
0087       tbins.push_back(i);
0088     tbit = tbit >> 1;
0089     if (tbit == 0)
0090       break;  // end already if no more bits set
0091   }
0092   return tbins;
0093 }
0094 
0095 // Setters
0096 //@@ No way to set time word?
0097 
0098 void CSCComparatorDigi::setStrip(int strip) { strip_ = strip; }
0099 void CSCComparatorDigi::setComparator(int comparator) { comparator_ = comparator; }
0100 
0101 // Output
0102 
0103 void CSCComparatorDigi::print() const {
0104   std::ostringstream ost;
0105   ost << "CSCComparatorDigi | strip " << getStrip() << " | comparator " << getComparator() << " | first time bin "
0106       << getTimeBin() << " | time bins on ";
0107   std::vector<int> tbins = getTimeBinsOn();
0108   std::copy(tbins.begin(), tbins.end(), std::ostream_iterator<int>(ost, " "));
0109   edm::LogVerbatim("CSCDigi") << ost.str();
0110 }
0111 
0112 std::ostream& operator<<(std::ostream& o, const CSCComparatorDigi& digi) {
0113   o << "CSCComparatorDigi Strip:" << digi.getStrip() << ", Comparator: " << digi.getComparator()
0114     << ", First Time Bin On: " << digi.getTimeBin() << ", Time Bins On: ";
0115   std::vector<int> tbins = digi.getTimeBinsOn();
0116   std::copy(tbins.begin(), tbins.end(), std::ostream_iterator<int>(o, " "));
0117   return o;
0118 }