Skip to content

Commit b666a09

Browse files
author
mlesch
committed
Implementing changes
1 parent 8949fb1 commit b666a09

4 files changed

Lines changed: 38 additions & 33 deletions

File tree

Modules/TPC/include/TPC/DCSPTempReductor.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ class DCSPTempReductor : public quality_control::postprocessing::ReductorConditi
5757
Float_t tempGradYPerSide[2];
5858
Float_t tempGradYPerSideErr[2]; // uncertainties
5959
} mStats;
60-
61-
void calcMeanAndStddev(std::vector<float>& values, float& mean, float& stddev);
6260
};
6361

6462
} // namespace o2::quality_control_modules::tpc

Modules/TPC/include/TPC/Utility.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,11 @@ void calculateStatistics(const double* yValues, const double* yErrors, bool useE
107107
/// \param mean double&, reference to double that should store mean
108108
/// \param stddevOfMean double&, reference to double that should store stddev of mean
109109
void retrieveStatistics(std::vector<double>& values, std::vector<double>& errors, bool useErrors, double& mean, double& stddevOfMean);
110+
111+
/// \brief Calculates mean and stddev from a vector
112+
/// \param values std::vector<values>& vector that contains the data points
113+
/// \param mean float&, reference to float that should store mean
114+
/// \param stddev float&, reference to float that should store stddev of mean
115+
void calcMeanAndStddev(const std::vector<float>& values, float& mean, float& stddev);
110116
} // namespace o2::quality_control_modules::tpc
111117
#endif // QUALITYCONTROL_TPCUTILITY_H

Modules/TPC/src/DCSPTempReductor.cxx

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "TPC/DCSPTempReductor.h"
1818
#include "DataFormatsTPC/DCS.h"
19+
#include "TPC/Utility.h"
1920

2021
namespace o2::quality_control_modules::tpc
2122
{
@@ -36,9 +37,9 @@ bool DCSPTempReductor::update(ConditionRetriever& retriever)
3637

3738
int sensorCounter = 0;
3839
std::vector<float> sensorData[18];
39-
for (const auto sensor : dcstemp->raw) {
40+
for (const auto& sensor : dcstemp->raw) {
4041
for (const auto& value : sensor.data) {
41-
sensorData[sensorCounter].push_back(value.value);
42+
sensorData[sensorCounter].emplace_back(value.value);
4243
}
4344
calcMeanAndStddev(sensorData[sensorCounter], mStats.tempSensor[sensorCounter], mStats.tempSensorErr[sensorCounter]);
4445
sensorCounter++;
@@ -50,9 +51,9 @@ bool DCSPTempReductor::update(ConditionRetriever& retriever)
5051

5152
// A-Side
5253
for (const auto& value : dcstemp->statsA.data) {
53-
sideData[0].push_back(value.value.mean);
54-
sideData[1].push_back(value.value.gradX);
55-
sideData[2].push_back(value.value.gradY);
54+
sideData[0].emplace_back(value.value.mean);
55+
sideData[1].emplace_back(value.value.gradX);
56+
sideData[2].emplace_back(value.value.gradY);
5657
}
5758

5859
calcMeanAndStddev(sideData[0], mStats.tempMeanPerSide[0], mStats.tempMeanPerSideErr[0]);
@@ -65,9 +66,9 @@ bool DCSPTempReductor::update(ConditionRetriever& retriever)
6566

6667
// C-Side
6768
for (const auto& value : dcstemp->statsC.data) {
68-
sideData[0].push_back(value.value.mean);
69-
sideData[1].push_back(value.value.gradX);
70-
sideData[2].push_back(value.value.gradY);
69+
sideData[0].emplace_back(value.value.mean);
70+
sideData[1].emplace_back(value.value.gradX);
71+
sideData[2].emplace_back(value.value.gradY);
7172
}
7273

7374
calcMeanAndStddev(sideData[0], mStats.tempMeanPerSide[1], mStats.tempMeanPerSideErr[1]);
@@ -79,27 +80,4 @@ bool DCSPTempReductor::update(ConditionRetriever& retriever)
7980
return false;
8081
}
8182

82-
void DCSPTempReductor::calcMeanAndStddev(std::vector<float>& values, float& mean, float& stddev)
83-
{
84-
if (values.size() == 0) {
85-
mean = 0.;
86-
stddev = 0.;
87-
return;
88-
}
89-
90-
// Mean
91-
float sum = std::accumulate(values.begin(), values.end(), 0.0);
92-
mean = sum / values.size();
93-
94-
// Stddev
95-
if (values.size() == 1) { // we only have one point -> no stddev
96-
stddev = 0.;
97-
} else { // for >= 2 points, we calculate the spread
98-
std::vector<double> diff(values.size());
99-
std::transform(values.begin(), values.end(), diff.begin(), [mean](double x) { return x - mean; });
100-
double sq_sum = std::inner_product(diff.begin(), diff.end(), diff.begin(), 0.0);
101-
stddev = std::sqrt(sq_sum / (values.size() * (values.size() - 1.)));
102-
}
103-
}
104-
10583
} // namespace o2::quality_control_modules::tpc

Modules/TPC/src/Utility.cxx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,4 +341,27 @@ void retrieveStatistics(std::vector<double>& values, std::vector<double>& errors
341341
}
342342
}
343343

344+
void calcMeanAndStddev(const std::vector<float>& values, float& mean, float& stddev)
345+
{
346+
if (values.size() == 0) {
347+
mean = 0.;
348+
stddev = 0.;
349+
return;
350+
}
351+
352+
// Mean
353+
const float sum = std::accumulate(values.begin(), values.end(), 0.0);
354+
mean = sum / values.size();
355+
356+
// Stddev
357+
if (values.size() == 1) { // we only have one point -> no stddev
358+
stddev = 0.;
359+
} else { // for >= 2 points, we calculate the spread
360+
std::vector<float> diff(values.size());
361+
std::transform(values.begin(), values.end(), diff.begin(), [mean](auto x) { return x - mean; });
362+
const auto sq_sum = std::inner_product(diff.begin(), diff.end(), diff.begin(), 0.f);
363+
stddev = std::sqrt(sq_sum / (values.size() * (values.size() - 1.)));
364+
}
365+
}
366+
344367
} // namespace o2::quality_control_modules::tpc

0 commit comments

Comments
 (0)