Skip to content

Commit a3d98b2

Browse files
committed
standard deviation from histogram
1 parent e6f32a1 commit a3d98b2

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/CounterStats.cxx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,35 @@ void CounterStats::getHisto(std::vector<double>& x, std::vector<CounterValue>& c
153153
}
154154
}
155155

156+
double CounterStats::getStdDev()
157+
{
158+
double sum = 0;
159+
CounterValue count = 0;
160+
double avg = getAverage();
161+
if (histoNbin) {
162+
for (unsigned int i = 0; i < histoNbin; i++) {
163+
double x;
164+
if (histoLogScale) {
165+
x = histoVmax * pow(histoStep, histoNbin - 1 - i);
166+
} else {
167+
if (i == 0) {
168+
x = histoVmin;
169+
} else if (i == histoNbin - 1) {
170+
x = histoVmax;
171+
} else {
172+
x = histoVmin + (i - 1) * histoStep;
173+
}
174+
}
175+
CounterValue c = histoCounts[i];
176+
if (c) {
177+
double d = (x-avg);
178+
sum += c * d * d;
179+
count += c;
180+
}
181+
}
182+
}
183+
if (count) {
184+
return sqrt(sum/(count-1));
185+
}
186+
return 0;
187+
}

src/CounterStats.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class CounterStats
3232
CounterValue get(); // get latest value
3333
CounterValue getTotal(); // get total of previous values set
3434
double getAverage();
35+
double getStdDev(); // get standard deviation (when histogram enabled)
3536
CounterValue getMinimum();
3637
CounterValue getMaximum();
3738
CounterValue getCount();

0 commit comments

Comments
 (0)