test
CMS 3D CMS Logo

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