CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/SimMuon/CSCDigitizer/src/CSCAnalogSignal.h

Go to the documentation of this file.
00001 #ifndef MU_END_ANALOG_SIGNAL
00002 #define MU_END_ANALOG_SIGNAL
00003 
00026 #include <vector>
00027 #include <iosfwd>
00028 #include <cassert>
00029 
00030 //TODO remove
00031 #include <iostream>
00032 
00033 class CSCAnalogSignal
00034 {
00035 public:
00036 
00037   inline CSCAnalogSignal() : theElement(0), invBinSize(0.), theBinValues(0), 
00038                                theTotal(0), theTimeOffset(0.) 
00039   {}
00040   
00041   inline CSCAnalogSignal(int element, float binSize, std::vector<float> & binValues, float total=0., float timeOffset=0.)  :
00042     theElement(element), invBinSize(1./binSize), 
00043     theBinValues(), theTotal(total), theTimeOffset(timeOffset) {
00044     theBinValues.swap(binValues);
00045   }
00046 
00048 //  CSCAnalogSignal(int element, const CSCAnalogSignal& shape, float time, float total);
00049 
00050 
00051   inline int getElement() const {return theElement;};
00052   inline void setElement(int element)  {theElement = element;};
00053   inline float  getBinValue(int i) const {
00054     return (i >= static_cast<int>(theBinValues.size()) || i < 0 ) ? 0. : theBinValues[i];
00055   }
00056 
00057 
00058   inline float getValue(float t) const {
00059   // interpolate between bins, if necessary
00060     float retval = 0.;
00061     float f = (t-theTimeOffset)*invBinSize + 0.000000001;
00062     if(f>=0.) {
00063       int i = static_cast<int>(f);
00064       f -= static_cast<float>(i);
00065       retval = (1.-f)*getBinValue(i) + f*getBinValue(i + 1);
00066     }
00067     return retval;
00068   }
00069 
00070 //  inline void  setBinValue(int i, float value) {
00071 //    if( i >= 0 && i < theBinValues.size() )
00072 //      theBinValues[i] = value;
00073 //  } 
00074  
00075   inline int   getSize()    const {return theBinValues.size();};
00076   inline float getBinSize() const {return 1./invBinSize;};
00077   inline float getTotal()   const {return theTotal;};
00078   inline float getTimeOffset() const {return theTimeOffset;};
00079   inline void  setTimeOffset(float offset) {theTimeOffset = offset;};
00080 
00081   inline void superimpose(const CSCAnalogSignal & signal2) {
00082     size_t n = theBinValues.size();
00083     for(size_t i = 0; i < n; ++i) {
00084        float t = i/invBinSize + theTimeOffset;
00085        theBinValues[i]+=signal2.getValue(t);
00086     }
00087     theTotal += signal2.theTotal; 
00088   }
00089 
00090   inline void operator+=(float offset) {
00091     for(int i = 0; i < getSize(); ++i) {
00092       theBinValues[i] += offset;
00093     }
00094   }
00095 
00096   inline void operator*=(float scaleFactor) {
00097     for(int i = 0; i < getSize(); ++i) {
00098       theBinValues[i] *= scaleFactor;
00099      }
00100     theTotal *= scaleFactor;
00101   }
00102 
00103   friend std::ostream & operator<<(std::ostream &, const CSCAnalogSignal &);
00104 
00105   float & operator[](int i) {
00106     assert(i>=0 && i < getSize());
00107     return theBinValues[i];
00108   }
00109 
00110   const float & operator[](int i) const {
00111     assert(i>=0 && i < getSize());
00112     return theBinValues[i];
00113   }
00114 
00116   float peakTime() const;
00117   unsigned size() const {return theBinValues.size();}
00118 
00119 private:
00120   int theElement;
00121   float invBinSize;
00122   std::vector<float> theBinValues;
00123   float theTotal;
00124   float theTimeOffset;
00125 };
00126 
00127 #endif
00128