SampleTailer.cxx
Go to the documentation of this file.
1 // SampleTailer.cxx
2 
3 #include "SampleTailer.h"
4 #include <cmath>
5 #include "TH1F.h"
6 
7 //**********************************************************************
8 
9 SampleTailer::SampleTailer(float a_decayTime, float a_alpha)
10 : m_decayTime(a_decayTime),
11  m_beta(exp(-1.0/m_decayTime)),
12  m_alpha(a_alpha),
13  m_pedestal(0.0),
14  m_ppedvec(nullptr),
15  m_tail0(0.0) {
16  setDecayTime(a_decayTime, false);
17  setAlpha(a_alpha);
18 }
19 
20 //**********************************************************************
21 
22 SampleTailer::SampleTailer(float a_decayTime)
23 : SampleTailer(a_decayTime, 0) {
24  setDecayTime(a_decayTime, true);
25 }
26 
27 //**********************************************************************
28 
30  clear();
31 }
32 
33 //**********************************************************************
34 
36  m_d.clear();
37  m_s.clear();
38  m_t.clear();
39  delete m_phd;
40  m_phd = nullptr;
41  delete m_phs;
42  m_phs = nullptr;
43  delete m_pht;
44  m_pht = nullptr;
45 }
46 
47 //**********************************************************************
48 
49 int SampleTailer::setDecayTime(float val, bool cancelSignal) {
50  clear();
51  if ( val > 0.0 ) {
52  m_decayTime = val;
53  m_beta = exp(-1.0/m_decayTime);
54  if ( cancelSignal ) m_alpha = 1.0/m_beta - 1;
55  } else {
56  m_decayTime = 0.0;
57  m_beta = 0.0;
58  if ( cancelSignal ) m_alpha = 0.0;
59  return 1;
60  }
61  return 0;
62 }
63 
64 //**********************************************************************
65 
66 int SampleTailer::setBeta(float val, bool cancelSignal) {
67  clear();
68  if ( val > 0.0 ) {
69  m_beta = val;
70  m_decayTime = -1.0/log(m_beta);
71  if ( cancelSignal ) m_alpha = 1.0/m_beta - 1;
72  } else {
73  m_decayTime = 0.0;
74  m_beta = 0.0;
75  if ( cancelSignal ) m_alpha = 0.0;
76  return 1;
77  }
78  return 0;
79 }
80 
81 //**********************************************************************
82 
84  clear();
85  m_alpha = val;
86  return 0;
87 }
88 
89 //**********************************************************************
90 
92  clear();
93  m_pedestal = val;
94  m_ppedvec = nullptr;
95  return 0;
96 }
97 
98 //**********************************************************************
99 
101  clear();
102  m_pedestal = 0.0;
103  m_ppedvec = ppeds;
104  return 0;
105 }
106 
107 //**********************************************************************
108 
110  clear();
111  m_tail0 = val;
112  return 0;
113 }
114 
115 //**********************************************************************
116 
117 int SampleTailer::setData(const FloatVector& inData) {
118  clear();
119  if ( ! isValid() ) return 1;
120  m_d = inData;
121  Index nsam = m_d.size();
122  bool havePedVector = m_ppedvec != nullptr;
123  if ( havePedVector && m_ppedvec->size() < nsam ) return 2;
124  m_s.resize(nsam, 0.0);
125  m_t.resize(nsam, 0.0);
126  double t = m_tail0;
127  double s = 0.0;
128  double ped = m_pedestal;
129  for ( Index isam=0; isam<nsam; ++isam ) {
130  if ( isam > 0 ) t = m_beta*t - m_alpha*s;
131  if ( havePedVector ) ped = (*m_ppedvec)[isam];
132  s = m_d[isam] - t - ped;
133  m_t[isam] = t;
134  m_s[isam] = s;
135  }
136  return 0;
137 }
138 
139 //**********************************************************************
140 
142  FloatVector dats(nsam, 0.0);
143  return setData(dats);
144 }
145 
146 //**********************************************************************
147 
148 int SampleTailer::setSignal(const FloatVector& inSignal) {
149  clear();
150  if ( ! isValid() ) return 1;
151  m_s = inSignal;
152  Index nsam = m_s.size();
153  bool havePedVector = m_ppedvec != nullptr;
154  if ( havePedVector && m_ppedvec->size() < nsam ) return 2;
155  m_d.resize(nsam, 0.0);
156  m_t.resize(nsam, 0.0);
157  double t = m_tail0;
158  double s = 0.0;
159  double ped = m_pedestal;
160  for ( Index isam=0; isam<nsam; ++isam ) {
161  if ( isam > 0 ) t = m_beta*t - m_alpha*s;
162  s = m_s[isam];
163  m_t[isam] = t;
164  if ( havePedVector ) ped = (*m_ppedvec)[isam];
165  m_d[isam] = s + t + ped;
166  }
167  return 0;
168 }
169 
170 //**********************************************************************
171 
173  if ( m_phd != nullptr ) return m_phd;
174  Index nsam = m_d.size();
175  if ( nsam == 0 ) return nullptr;
176  Name hnam = "hst_data";
177  Name httl = "Sample data; Tick;" + unit();
178  TH1* ph = new TH1F(hnam.c_str(), httl.c_str(), nsam, 0, nsam);
179  ph->SetDirectory(nullptr);
180  ph->SetLineWidth(2);
181  ph->SetStats(0);
182  for ( Index isam=0; isam<nsam; ++isam ) {
183  ph->SetBinContent(isam+1, m_d[isam]);
184  }
185  m_phd = ph;
186  return ph;
187 }
188 
189 //**********************************************************************
190 
192  if ( m_phs != nullptr ) return m_phs;
193  Index nsam = m_s.size();
194  if ( nsam == 0 ) return nullptr;
195  Name hnam = "hst_signal";
196  Name httl = "Sample signal; Tick;" + unit();
197  TH1* ph = new TH1F(hnam.c_str(), httl.c_str(), nsam, 0, nsam);
198  ph->SetDirectory(nullptr);
199  ph->SetLineWidth(2);
200  ph->SetStats(0);
201  for ( Index isam=0; isam<nsam; ++isam ) {
202  ph->SetBinContent(isam+1, m_s[isam]);
203  }
204  m_phs = ph;
205  return ph;
206 }
207 
208 //**********************************************************************
209 
211  if ( m_pht != nullptr ) return m_pht;
212  Index nsam = m_t.size();
213  if ( nsam == 0 ) return nullptr;
214  Name hnam = "hst_tail";
215  Name httl = "Sample tail; Tick;" + unit();
216  TH1* ph = new TH1F(hnam.c_str(), httl.c_str(), nsam, 0, nsam);
217  ph->SetDirectory(nullptr);
218  ph->SetLineWidth(2);
219  ph->SetStats(0);
220  for ( Index isam=0; isam<nsam; ++isam ) {
221  ph->SetBinContent(isam+1, m_t[isam]);
222  }
223  m_pht = ph;
224  return ph;
225 }
226 
227 //**********************************************************************
228 
230  dataHist();
231  tailHist();
232  signalHist();
233 }
234 
235 //**********************************************************************
236 
std::vector< float > FloatVector
Definition: SampleTailer.h:42
bool isValid() const
Definition: SampleTailer.h:80
int setData(const FloatVector &inData)
const FloatVector * m_ppedvec
Definition: SampleTailer.h:112
TH1 * signalHist() const
Definition: SampleTailer.h:97
int setSignal(const FloatVector &inSignal)
TH1 * dataHist() const
Definition: SampleTailer.h:96
Name unit() const
Definition: SampleTailer.h:95
int setPedestal(float val)
float m_pedestal
Definition: SampleTailer.h:111
FloatVector m_t
Definition: SampleTailer.h:117
FloatVector m_d
Definition: SampleTailer.h:115
int setBeta(float val, bool cancelSignal)
int setDecayTime(float val, bool cancelSignal)
int setTail0(float val)
int setPedestalVector(const FloatVector *pval)
std::string Name
Definition: SampleTailer.h:43
FloatVector m_s
Definition: SampleTailer.h:116
float m_decayTime
Definition: SampleTailer.h:108
static QCString * s
Definition: config.cpp:1042
int setAlpha(float val)
unsigned int Index
Definition: SampleTailer.h:41
int setDataZero(Index nsam)
SampleTailer(float a_decayTime)
TH1 * tailHist() const
Definition: SampleTailer.h:98