CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CSCAnalogSignal.h
Go to the documentation of this file.
1 #ifndef MU_END_ANALOG_SIGNAL
2 #define MU_END_ANALOG_SIGNAL
3 
25 #include <cassert>
26 #include <iosfwd>
27 #include <vector>
28 
29 // TODO remove
30 #include <iostream>
31 
33 public:
35 
37  int element, float binSize, std::vector<float> &binValues, float total = 0., float timeOffset = 0.)
38  : theElement(element), invBinSize(1. / binSize), theBinValues(), theTotal(total), theTimeOffset(timeOffset) {
39  theBinValues.swap(binValues);
40  }
41 
43  // CSCAnalogSignal(int element, const CSCAnalogSignal& shape, float time,
44  // float total);
45 
46  inline int getElement() const { return theElement; };
47  inline void setElement(int element) { theElement = element; };
48  inline float getBinValue(int i) const {
49  return (i >= static_cast<int>(theBinValues.size()) || i < 0) ? 0. : theBinValues[i];
50  }
51 
52  inline float getValue(float t) const {
53  // interpolate between bins, if necessary
54  float retval = 0.;
55  float f = (t - theTimeOffset) * invBinSize + 0.000000001;
56  if (f >= 0.) {
57  int i = static_cast<int>(f);
58  f -= static_cast<float>(i);
59  retval = (1. - f) * getBinValue(i) + f * getBinValue(i + 1);
60  }
61  return retval;
62  }
63 
64  // inline void setBinValue(int i, float value) {
65  // if( i >= 0 && i < theBinValues.size() )
66  // theBinValues[i] = value;
67  // }
68 
69  inline int getSize() const { return theBinValues.size(); };
70  inline float getBinSize() const { return 1. / invBinSize; };
71  inline float getTotal() const { return theTotal; };
72  inline float getTimeOffset() const { return theTimeOffset; };
73  inline void setTimeOffset(float offset) { theTimeOffset = offset; };
74 
75  inline void superimpose(const CSCAnalogSignal &signal2) {
76  size_t n = theBinValues.size();
77  for (size_t i = 0; i < n; ++i) {
78  float t = i / invBinSize + theTimeOffset;
79  theBinValues[i] += signal2.getValue(t);
80  }
81  theTotal += signal2.theTotal;
82  }
83 
84  inline void operator+=(float offset) {
85  for (int i = 0; i < getSize(); ++i) {
86  theBinValues[i] += offset;
87  }
88  }
89 
90  inline void operator*=(float scaleFactor) {
91  for (int i = 0; i < getSize(); ++i) {
93  }
95  }
96 
97  friend std::ostream &operator<<(std::ostream &, const CSCAnalogSignal &);
98 
99  float &operator[](int i) {
100  assert(i >= 0 && i < getSize());
101  return theBinValues[i];
102  }
103 
104  const float &operator[](int i) const {
105  assert(i >= 0 && i < getSize());
106  return theBinValues[i];
107  }
108 
110  float peakTime() const;
111  unsigned size() const { return theBinValues.size(); }
112 
113 private:
115  float invBinSize;
116  std::vector<float> theBinValues;
117  float theTotal;
119 };
120 
121 #endif
float getBinValue(int i) const
float getBinSize() const
float & operator[](int i)
friend std::ostream & operator<<(std::ostream &, const CSCAnalogSignal &)
const float & operator[](int i) const
assert(be >=bs)
unsigned size() const
std::vector< float > theBinValues
int getElement() const
constructor from time and amp shape
float getTimeOffset() const
CSCAnalogSignal(int element, float binSize, std::vector< float > &binValues, float total=0., float timeOffset=0.)
int getSize() const
void superimpose(const CSCAnalogSignal &signal2)
void operator*=(float scaleFactor)
void setTimeOffset(float offset)
float getTotal() const
float peakTime() const
the time when the signal peaks
float getValue(float t) const
void setElement(int element)
void operator+=(float offset)