CMS 3D CMS Logo

CSCComparatorDigi.cc
Go to the documentation of this file.
1 
8 #include <iostream>
9 #include <algorithm>
10 #include <iterator>
11 
12 using namespace std;
13 
14 // Constructors
15 CSCComparatorDigi::CSCComparatorDigi(int strip, int comparator, int timeBinWord)
16  : strip_(strip), comparator_(comparator), timeBinWord_(timeBinWord) {}
17 
19 
20 // Comparison
21 
23  if (getStrip() != digi.getStrip())
24  return false;
25  if (getComparator() != digi.getComparator())
26  return false;
27  if (getTimeBinWord() != digi.getTimeBinWord())
28  return false;
29  return true;
30 }
31 
32 //@@ If one wanted to order comparator digis how would one want op< to behave?
33 // I don't know...
34 // I think LHS < RHS only makes sense if
35 // i) time(LHS) .eq. time(RHS)
36 // AND
37 // ii) strip(LHS) .lt. strip(RHS)
38 // But I don't see how this can be useful.
39 
41  bool result = false;
42  if (getTimeBin() == digi.getTimeBin()) {
43  result = (getStrip() < digi.getStrip());
44  }
45  return result;
46 }
47 
48 // Getters
49 
51  // Find first bin which fired, counting from 0
52  uint16_t tbit = 1;
53  int tbin = -1;
54  for (int i = 0; i < 16; ++i) {
55  if (tbit & timeBinWord_) {
56  tbin = i;
57  break;
58  }
59  tbit = tbit << 1;
60  }
61  return tbin;
62 }
63 
64 // This definition is consistent with the one used in
65 // the function CSCCLCTData::add() in EventFilter/CSCRawToDigi
66 // The halfstrip counts from 0!
67 int CSCComparatorDigi::getHalfStrip() const { return (getStrip() - 1) * 2 + getComparator(); }
68 
69 // Return the fractional half-strip
70 float CSCComparatorDigi::getFractionalStrip() const { return getStrip() + getComparator() * 0.5f - 0.75f; }
71 
72 std::vector<int> CSCComparatorDigi::getTimeBinsOn() const {
73  std::vector<int> tbins;
74  uint16_t tbit = timeBinWord_;
75  const uint16_t one = 1;
76  for (int i = 0; i < 16; ++i) {
77  if (tbit & one)
78  tbins.push_back(i);
79  tbit = tbit >> 1;
80  if (tbit == 0)
81  break; // end already if no more bits set
82  }
83  return tbins;
84 }
85 
86 // Setters
87 //@@ No way to set time word?
88 
90 void CSCComparatorDigi::setComparator(int comparator) { comparator_ = comparator; }
91 
92 // Output
93 
95  std::ostringstream ost;
96  ost << "CSCComparatorDigi | strip " << getStrip() << " | comparator " << getComparator() << " | first time bin "
97  << getTimeBin() << " | time bins on ";
98  std::vector<int> tbins = getTimeBinsOn();
99  for (unsigned int i = 0; i < tbins.size(); i++) {
100  ost << tbins[i] << " ";
101  }
102  edm::LogVerbatim("CSCDigi") << ost.str();
103 }
104 
105 //@@ Doesn't print all time bins
106 std::ostream& operator<<(std::ostream& o, const CSCComparatorDigi& digi) {
107  return o << " " << digi.getStrip() << " " << digi.getComparator() << " " << digi.getTimeBin();
108 }
int getHalfStrip() const
Get the associated halfstrip number for this comparator digi. Counts from 0.
int getStrip() const
Get the strip number. Counts from 1.
void setComparator(int comparator)
Set Comparator data.
void print() const
Print content of digi.
float getFractionalStrip() const
Return the fractional half-strip. Counts from 0.25.
void setStrip(int strip)
Set the strip number.
CSCComparatorDigi()
comparator here can be either 0 or 1 for left or right halfstrip of given strip
int getComparator() const
Get Comparator readings. Can be 0 or 1.
bool operator==(const CSCComparatorDigi &digi) const
Digis are equal if they are on the same strip and have same Comparator data.
int getTimeBin() const
Return bin number of first time bin which is ON. Counts from 0.
bool operator<(const CSCComparatorDigi &digi) const
sort by time first, then by strip
std::vector< int > getTimeBinsOn() const
int getTimeBinWord() const
Return the word with each bit corresponding to a time bin.
std::ostream & operator<<(std::ostream &o, const CSCComparatorDigi &digi)
Output operator.