CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CSCComparatorDigi.cc
Go to the documentation of this file.
1 
9 #include <iostream>
10 #include <algorithm>
11 #include <iterator>
12 
13 using namespace std;
14 
15 // Constructors
16 CSCComparatorDigi::CSCComparatorDigi(int strip, int comparator, int timeBinWord)
17  : strip_(strip), comparator_(comparator), timeBinWord_(timeBinWord) {}
18 
19 CSCComparatorDigi::CSCComparatorDigi() : strip_(0), comparator_(0), timeBinWord_(0) {}
20 
21 // Comparison
22 
24  if (getStrip() != digi.getStrip())
25  return false;
26  if (getComparator() != digi.getComparator())
27  return false;
28  if (getTimeBinWord() != digi.getTimeBinWord())
29  return false;
30  return true;
31 }
32 
33 //@@ If one wanted to order comparator digis how would one want op< to behave?
34 // I don't know...
35 // I think LHS < RHS only makes sense if
36 // i) time(LHS) .eq. time(RHS)
37 // AND
38 // ii) strip(LHS) .lt. strip(RHS)
39 // But I don't see how this can be useful.
40 
42  bool result = false;
43  if (getTimeBin() == digi.getTimeBin()) {
44  result = (getStrip() < digi.getStrip());
45  }
46  return result;
47 }
48 
49 // Getters
50 
52  // Find first bin which fired, counting from 0
53  uint16_t tbit = 1;
54  int tbin = -1;
55  for (int i = 0; i < 16; ++i) {
56  if (tbit & timeBinWord_) {
57  tbin = i;
58  break;
59  }
60  tbit = tbit << 1;
61  }
62  return tbin;
63 }
64 
66 // originally defined in EventFilter/CSCRawToDigi/src/CSCComparatorData.cc
68 
70 // originally defined in EventFilter/CSCRawToDigi/src/CSCComparatorData.cc
72 
73 // This definition is consistent with the one used in
74 // the function CSCComparatorData::add() in EventFilter/CSCRawToDigi
75 // The halfstrip counts from 0!
76 int CSCComparatorDigi::getHalfStrip() const { return (getStrip() - 1) * 2 + getComparator(); }
77 
78 // Return the fractional half-strip
79 float CSCComparatorDigi::getFractionalStrip() const { return getStrip() + getComparator() * 0.5f - 0.75f; }
80 
81 std::vector<int> CSCComparatorDigi::getTimeBinsOn() const {
82  std::vector<int> tbins;
83  uint16_t tbit = timeBinWord_;
84  const uint16_t one = 1;
85  for (int i = 0; i < 16; ++i) {
86  if (tbit & one)
87  tbins.push_back(i);
88  tbit = tbit >> 1;
89  if (tbit == 0)
90  break; // end already if no more bits set
91  }
92  return tbins;
93 }
94 
95 // Setters
96 //@@ No way to set time word?
97 
99 void CSCComparatorDigi::setComparator(int comparator) { comparator_ = comparator; }
100 
101 // Output
102 
104  std::ostringstream ost;
105  ost << "CSCComparatorDigi | strip " << getStrip() << " | comparator " << getComparator() << " | first time bin "
106  << getTimeBin() << " | time bins on ";
107  std::vector<int> tbins = getTimeBinsOn();
108  std::copy(tbins.begin(), tbins.end(), std::ostream_iterator<int>(ost, " "));
109  edm::LogVerbatim("CSCDigi") << ost.str();
110 }
111 
112 std::ostream& operator<<(std::ostream& o, const CSCComparatorDigi& digi) {
113  o << "CSCComparatorDigi Strip:" << digi.getStrip() << ", Comparator: " << digi.getComparator()
114  << ", First Time Bin On: " << digi.getTimeBin() << ", Time Bins On: ";
115  std::vector<int> tbins = digi.getTimeBinsOn();
116  std::copy(tbins.begin(), tbins.end(), std::ostream_iterator<int>(o, " "));
117  return o;
118 }
Log< level::Info, true > LogVerbatim
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.
int getCFEB() const
Get the CFEB number. Counts from 0.
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
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:167
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.
tuple result
Definition: mps_fire.py:311
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.
int getDiStrip() const
Get the distrip number. Counts from 0.