Skip to content

Commit

Permalink
Implementing changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mlesch committed Nov 19, 2024
1 parent 8949fb1 commit b666a09
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 33 deletions.
2 changes: 0 additions & 2 deletions Modules/TPC/include/TPC/DCSPTempReductor.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ class DCSPTempReductor : public quality_control::postprocessing::ReductorConditi
Float_t tempGradYPerSide[2];
Float_t tempGradYPerSideErr[2]; // uncertainties
} mStats;

void calcMeanAndStddev(std::vector<float>& values, float& mean, float& stddev);
};

} // namespace o2::quality_control_modules::tpc
Expand Down
6 changes: 6 additions & 0 deletions Modules/TPC/include/TPC/Utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,11 @@ void calculateStatistics(const double* yValues, const double* yErrors, bool useE
/// \param mean double&, reference to double that should store mean
/// \param stddevOfMean double&, reference to double that should store stddev of mean
void retrieveStatistics(std::vector<double>& values, std::vector<double>& errors, bool useErrors, double& mean, double& stddevOfMean);

/// \brief Calculates mean and stddev from a vector
/// \param values std::vector<values>& vector that contains the data points
/// \param mean float&, reference to float that should store mean
/// \param stddev float&, reference to float that should store stddev of mean
void calcMeanAndStddev(const std::vector<float>& values, float& mean, float& stddev);
} // namespace o2::quality_control_modules::tpc
#endif // QUALITYCONTROL_TPCUTILITY_H
40 changes: 9 additions & 31 deletions Modules/TPC/src/DCSPTempReductor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "TPC/DCSPTempReductor.h"
#include "DataFormatsTPC/DCS.h"
#include "TPC/Utility.h"

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

int sensorCounter = 0;
std::vector<float> sensorData[18];
for (const auto sensor : dcstemp->raw) {
for (const auto& sensor : dcstemp->raw) {
for (const auto& value : sensor.data) {
sensorData[sensorCounter].push_back(value.value);
sensorData[sensorCounter].emplace_back(value.value);
}
calcMeanAndStddev(sensorData[sensorCounter], mStats.tempSensor[sensorCounter], mStats.tempSensorErr[sensorCounter]);
sensorCounter++;
Expand All @@ -50,9 +51,9 @@ bool DCSPTempReductor::update(ConditionRetriever& retriever)

// A-Side
for (const auto& value : dcstemp->statsA.data) {
sideData[0].push_back(value.value.mean);
sideData[1].push_back(value.value.gradX);
sideData[2].push_back(value.value.gradY);
sideData[0].emplace_back(value.value.mean);
sideData[1].emplace_back(value.value.gradX);
sideData[2].emplace_back(value.value.gradY);
}

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

// C-Side
for (const auto& value : dcstemp->statsC.data) {
sideData[0].push_back(value.value.mean);
sideData[1].push_back(value.value.gradX);
sideData[2].push_back(value.value.gradY);
sideData[0].emplace_back(value.value.mean);
sideData[1].emplace_back(value.value.gradX);
sideData[2].emplace_back(value.value.gradY);
}

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

void DCSPTempReductor::calcMeanAndStddev(std::vector<float>& values, float& mean, float& stddev)
{
if (values.size() == 0) {
mean = 0.;
stddev = 0.;
return;
}

// Mean
float sum = std::accumulate(values.begin(), values.end(), 0.0);
mean = sum / values.size();

// Stddev
if (values.size() == 1) { // we only have one point -> no stddev
stddev = 0.;
} else { // for >= 2 points, we calculate the spread
std::vector<double> diff(values.size());
std::transform(values.begin(), values.end(), diff.begin(), [mean](double x) { return x - mean; });
double sq_sum = std::inner_product(diff.begin(), diff.end(), diff.begin(), 0.0);
stddev = std::sqrt(sq_sum / (values.size() * (values.size() - 1.)));
}
}

} // namespace o2::quality_control_modules::tpc
23 changes: 23 additions & 0 deletions Modules/TPC/src/Utility.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,27 @@ void retrieveStatistics(std::vector<double>& values, std::vector<double>& errors
}
}

void calcMeanAndStddev(const std::vector<float>& values, float& mean, float& stddev)
{
if (values.size() == 0) {
mean = 0.;
stddev = 0.;
return;
}

// Mean
const float sum = std::accumulate(values.begin(), values.end(), 0.0);
mean = sum / values.size();

// Stddev
if (values.size() == 1) { // we only have one point -> no stddev
stddev = 0.;
} else { // for >= 2 points, we calculate the spread
std::vector<float> diff(values.size());
std::transform(values.begin(), values.end(), diff.begin(), [mean](auto x) { return x - mean; });
const auto sq_sum = std::inner_product(diff.begin(), diff.end(), diff.begin(), 0.f);
stddev = std::sqrt(sq_sum / (values.size() * (values.size() - 1.)));
}
}

} // namespace o2::quality_control_modules::tpc

0 comments on commit b666a09

Please sign in to comment.