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
16  : strip_( strip ), comparator_( comparator ), timeBinWord_( timeBinWord ) {
17 }
18 
19 
21  : strip_( 0 ), comparator_( 0 ), timeBinWord_( 0 ) {
22 }
23 
24 
25 // Comparison
26 
27 bool
29  if ( getStrip() != digi.getStrip() ) return false;
30  if ( getComparator() != digi.getComparator() ) return false;
31  if ( getTimeBinWord() != digi.getTimeBinWord() ) return false;
32  return true;
33 }
34 
35 
36 //@@ If one wanted to order comparator digis how would one want op< to behave?
37 // I don't know...
38 // I think LHS < RHS only makes sense if
39 // i) time(LHS) .eq. time(RHS)
40 // AND
41 // ii) strip(LHS) .lt. strip(RHS)
42 // But I don't see how this can be useful.
43 
44 bool
46  bool result = false;
47  if(getTimeBin() == digi.getTimeBin()) {
48  result = (getStrip() < digi.getStrip());
49  }
50  return result;
51 }
52 
53 
54 // Getters
55 
57  // Find first bin which fired, counting from 0
58  uint16_t tbit=1;
59  int tbin=-1;
60  for(int i=0;i<16;++i) {
61  if(tbit & timeBinWord_) {
62  tbin=i;
63  break;
64  }
65  tbit=tbit<<1;
66  }
67  return tbin;
68 }
69 
70 // This definition is consistent with the one used in
71 // the function CSCCLCTData::add() in EventFilter/CSCRawToDigi
72 // The halfstrip counts from 0!
74  return (getStrip() - 1) * 2 + getComparator();
75 }
76 
77 // Return the fractional half-strip
79  return getStrip() + getComparator() * 0.5f - 0.75f;
80 }
81 
82 std::vector<int> CSCComparatorDigi::getTimeBinsOn() const {
83  std::vector<int> tbins;
84  uint16_t tbit = timeBinWord_;
85  const uint16_t one=1;
86  for(int i=0;i<16;++i) {
87  if(tbit & one) tbins.push_back(i);
88  tbit=tbit>>1;
89  if(tbit==0) break; // end already if no more bits set
90  }
91  return tbins;
92 }
93 
94 // Setters
95 //@@ No way to set time word?
96 
98  strip_ = strip;
99 }
102 }
103 
104 // Output
105 
106 void
108  std::ostringstream ost;
109  ost << "CSCComparatorDigi | strip " << getStrip()
110  << " | comparator " << getComparator()
111  << " | first time bin " << getTimeBin() << " | time bins on ";
112  std::vector<int> tbins=getTimeBinsOn();
113  for(unsigned int i=0; i<tbins.size();i++) {ost << tbins[i] << " ";}
114  edm::LogVerbatim("CSCDigi") << ost.str();
115 }
116 
117 //@@ Doesn't print all time bins
118 std::ostream & operator<<(std::ostream & o, const CSCComparatorDigi& digi) {
119  return o << " " << digi.getStrip()
120  << " " << digi.getComparator()
121  << " " << digi.getTimeBin();
122 }
123 
124 
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.