QwAnalysis
QwSIS3320_Samples.h
Go to the documentation of this file.
1 /**
2  * \class QwSIS3320_Samples QwSIS3320_Samples.h
3  *
4  * \brief SIS3320 sampling ADC samples
5  *
6  * \author W. Deconinck
7  * \date 2009-09-04 18:06:23
8  * \ingroup QwCompton
9  *
10  * The QwSIS3320_Samples should allow convenient access to the sampling data
11  * collected with the SIS3320 for the Compton photon detector. This class
12  * implements its own sum, difference, and ratio methods inherited from the
13  * general VQwDataElement.
14  *
15  */
16 
17 #ifndef __QwSIS3320_Samples__
18 #define __QwSIS3320_Samples__
19 
20 // System headers
21 #include <iostream>
22 #include <vector>
23 
24 // ROOT headers
25 #include <TObject.h>
26 #include <TGraph.h>
27 #include <TTree.h>
28 
29 /// At this point the samples are hard-coded to be of Float_t data type.
30 /// Ideally, this should be templated out, so that the channel can have
31 /// UInt_t raw samples, Float_t processed samples, and Double_t average
32 /// samples. Seems to cause too many problems right now and needs some
33 /// thinking.
34 typedef Double_t QwSIS3320_Type;
35 
36 class QwSIS3320_Samples: public TObject {
37 
38  public:
39 
40  QwSIS3320_Samples(UInt_t nsamples = 256) {
41  fGraph = 0;
44  SetNumberOfSamples(nsamples);
45  };
46  virtual ~QwSIS3320_Samples() {
47  if (fGraph) delete fGraph;
48  };
49 
50  size_t GetMinIndex() const { return GetMin().first; };
51  size_t GetMaxIndex() const { return GetMax().first; };
52  QwSIS3320_Type GetMinSample() const { return GetMin().second; };
53  QwSIS3320_Type GetMaxSample() const { return GetMax().second; };
54 
55  QwSIS3320_Type GetSum() const;
56  QwSIS3320_Type GetSample(size_t i) const { return fSamples.at(i); };
57  QwSIS3320_Type GetPedestal() const { return GetSample(0); };
58  QwSIS3320_Type GetSumInTimeWindow(const UInt_t start, const UInt_t stop) const;
59 
60  UInt_t GetNumberOfDataWords() const { return fNumberOfDataWords; };
61  void SetNumberOfDataWords(const UInt_t &numwords) {
62  fNumberOfDataWords = numwords;
63  };
64 
65  UInt_t GetNumberOfSamples() const { return fSamples.size(); };
66  void SetNumberOfSamples(const UInt_t nsamples) {
67  // Initialize index vector
68  fIndex.resize(nsamples);
69  for (size_t i = 0; i < fIndex.size(); i++) fIndex[i] = i;
70  // Initialize sample vector
71  fSamples.resize(nsamples);
73  };
74 
75  UInt_t GetSamplePointer() const { return fSamplePointer; };
76  void SetSamplePointer(const UInt_t samplepointer) {
77  fSamplePointer = samplepointer;
78  };
79 
80  UInt_t GetSamplesPerWord() const { return fSamplesPerWord; };
81  void SetSamplesPerWord(const UInt_t nsamples) {
82  fSamplesPerWord = nsamples;
84  };
85 
86  // Return the graph (not const because TGraph::Draw is not const)
87  TGraph* GetGraph() const { return fGraph; };
88 
89  // Update the graph from the index and value vectors
90  void UpdateGraph();
91 
92 
93  void ClearEventData() { fSamples.clear(); };
94  Int_t ProcessEvBuffer(UInt_t* buffer, UInt_t num_words_left, UInt_t subelement = 0);
95 
96  QwSIS3320_Samples& operator/= (const Double_t &value);
97  QwSIS3320_Samples& operator*= (const Double_t &value);
98  QwSIS3320_Samples& operator+= (const Double_t &value);
99  QwSIS3320_Samples& operator-= (const Double_t &value);
100  const QwSIS3320_Samples operator/ (const Double_t &value) const;
101  const QwSIS3320_Samples operator* (const Double_t &value) const;
102  const QwSIS3320_Samples operator+ (const Double_t &value) const;
103  const QwSIS3320_Samples operator- (const Double_t &value) const;
104 
108  const QwSIS3320_Samples operator+ (const QwSIS3320_Samples &value) const;
109  const QwSIS3320_Samples operator- (const QwSIS3320_Samples &value) const;
110 
111  // Output stream operator<< for an accumulator
112  friend std::ostream& operator<< (std::ostream& stream, const QwSIS3320_Samples& s);
113 
114  private:
115 
116  // Private helper methods for getting minimum and maximum index and samples
117  std::pair<size_t,QwSIS3320_Type> GetMin() const; //!
118  std::pair<size_t,QwSIS3320_Type> GetMax() const; //!
119 
120  private:
121 
122  /// Number of 12-bit sample values per data word
124  /// Number of data words in this data element
126  /// Sample position in buffer
128 
129  //! Samples index
130  static std::vector<QwSIS3320_Type> fIndex; //!
131  //! Samples values
132  std::vector<QwSIS3320_Type> fSamples;
133  //! Graph of samples
134  TGraph* fGraph;
135 
136  // Ntuple array indices
137  size_t fTreeArrayIndex; //!< Index of this data element in tree
138  size_t fTreeArrayNumEntries; //!< Number of entries from this data element
139 
141 };
142 
143 // Output stream operator<< for the samples
144 inline std::ostream& operator<< (std::ostream& stream, const QwSIS3320_Samples& s)
145 {
146  for (size_t i = 0; i < s.GetNumberOfSamples(); i++)
147  stream << s.GetSample(i) << " ";
148  return stream;
149 }
150 
151 #endif // __QwSIS3320_Samples__
UInt_t GetSamplesPerWord() const
SIS3320 sampling ADC samples.
std::ostream & operator<<(std::ostream &out, const QwColor &color)
Output stream operator which uses the enum-to-escape-code mapping.
Definition: QwColor.h:153
UInt_t fSamplePointer
Sample position in buffer.
UInt_t GetNumberOfSamples() const
const QwSIS3320_Samples operator-(const Double_t &value) const
QwSIS3320_Samples & operator-=(const Double_t &value)
std::vector< QwSIS3320_Type > fSamples
Samples values.
TGraph * fGraph
Graph of samples.
size_t fTreeArrayNumEntries
Number of entries from this data element.
TGraph * GetGraph() const
size_t GetMaxIndex() const
QwSIS3320_Samples(UInt_t nsamples=256)
UInt_t fNumberOfDataWords
Number of data words in this data element.
static std::vector< QwSIS3320_Type > fIndex
Samples index.
QwSIS3320_Type GetPedestal() const
ClassDef(QwSIS3320_Samples, 1)
void SetNumberOfSamples(const UInt_t nsamples)
void SetSamplesPerWord(const UInt_t nsamples)
std::pair< size_t, QwSIS3320_Type > GetMin() const
QwSIS3320_Samples & operator=(const QwSIS3320_Samples &value)
virtual ~QwSIS3320_Samples()
const QwSIS3320_Samples operator*(const Double_t &value) const
QwSIS3320_Type GetSumInTimeWindow(const UInt_t start, const UInt_t stop) const
size_t GetMinIndex() const
void SetNumberOfDataWords(const UInt_t &numwords)
Double_t QwSIS3320_Type
Int_t ProcessEvBuffer(UInt_t *buffer, UInt_t num_words_left, UInt_t subelement=0)
UInt_t GetSamplePointer() const
QwSIS3320_Samples & operator/=(const Double_t &value)
QwSIS3320_Type GetSum() const
QwSIS3320_Samples & operator+=(const Double_t &value)
size_t fTreeArrayIndex
Index of this data element in tree.
UInt_t GetNumberOfDataWords() const
void SetSamplePointer(const UInt_t samplepointer)
std::pair< size_t, QwSIS3320_Type > GetMax() const
QwSIS3320_Type GetMinSample() const
QwSIS3320_Type GetMaxSample() const
const QwSIS3320_Samples operator/(const Double_t &value) const
QwSIS3320_Samples & operator*=(const Double_t &value)
QwSIS3320_Type GetSample(size_t i) const
friend std::ostream & operator<<(std::ostream &stream, const QwSIS3320_Samples &s)
const QwSIS3320_Samples operator+(const Double_t &value) const
UInt_t fSamplesPerWord
Number of 12-bit sample values per data word.