Skip to content

Commit 6298cf0

Browse files
committed
code check for twoParticleCorrelationsMpi.cxx
1 parent d8ce1c5 commit 6298cf0

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

PWGCF/TwoParticleCorrelations/Tasks/twoParticleCorrelationsMpi.cxx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include <THn.h>
4949
#include <TList.h>
5050
#include <TNamed.h>
51+
#include <TObject.h>
5152
#include <TString.h>
5253
#include <TTree.h>
5354

@@ -58,6 +59,7 @@
5859
#include <bit>
5960
#include <chrono>
6061
#include <cmath>
62+
#include <cstddef>
6163
#include <cstdint>
6264
#include <experimental/type_traits>
6365
#include <iterator>
@@ -186,10 +188,10 @@ struct TwoParticleCorrelationsMpi {
186188
double awayPairs = 0.0;
187189
double baselinePairs = 0.0;
188190

189-
bool isValid() const { return nTriggers > 0; }
190-
double nearYield() const { return isValid() ? nearPairs / nTriggers : 0.0; }
191-
double awayYield() const { return isValid() ? awayPairs / nTriggers : 0.0; }
192-
double nuncSeeds() const
191+
[[nodiscard]] bool isValid() const { return nTriggers > 0; }
192+
[[nodiscard]] double nearYield() const { return isValid() ? nearPairs / nTriggers : 0.0; }
193+
[[nodiscard]] double awayYield() const { return isValid() ? awayPairs / nTriggers : 0.0; }
194+
[[nodiscard]] double nuncSeeds() const
193195
{
194196
const double denominator = 1.0 + nearYield() + awayYield();
195197
return isValid() && denominator > 0.0 ? nTriggers / denominator : -1.0;
@@ -576,18 +578,18 @@ struct TwoParticleCorrelationsMpi {
576578
LOGF(fatal, "Missing ensembleYieldTemplates in %s", source.c_str());
577579
return;
578580
}
579-
if (!schemaVersion || TString(schemaVersion->GetTitle()) != "1") {
581+
if (schemaVersion == nullptr || TString(schemaVersion->GetTitle()) != "1") {
580582
LOGF(fatal, "Unsupported or missing ensemble-yield template schema version in %s", source.c_str());
581583
return;
582584
}
583-
if (!correlationStep || TString(correlationStep->GetTitle()) != "kCFStepReconstructed") {
585+
if (correlationStep == nullptr || TString(correlationStep->GetTitle()) != "kCFStepReconstructed") {
584586
LOGF(fatal, "Ensemble-yield templates must be derived at kCFStepReconstructed");
585587
return;
586588
}
587589

588590
YieldTemplate value;
589591
int fitStatus = -1;
590-
double parameters[10] = {};
592+
std::array<double, 10> parameters{};
591593
tree->SetBranchAddress("trigBin", &value.trigBin);
592594
tree->SetBranchAddress("assocBin", &value.assocBin);
593595
tree->SetBranchAddress("multBin", &value.multBin);
@@ -597,7 +599,7 @@ struct TwoParticleCorrelationsMpi {
597599
tree->SetBranchAddress("trigPtHigh", &value.trigPtHigh);
598600
tree->SetBranchAddress("assocPtLow", &value.assocPtLow);
599601
tree->SetBranchAddress("assocPtHigh", &value.assocPtHigh);
600-
tree->SetBranchAddress("parameters", parameters);
602+
tree->SetBranchAddress("parameters", parameters.data());
601603
tree->SetBranchAddress("fitStatus", &fitStatus);
602604

603605
yieldTemplates.clear();
@@ -608,18 +610,20 @@ struct TwoParticleCorrelationsMpi {
608610
LOGF(warning, "Skipping failed yield template (%d, %d, %d), fit status %d", value.trigBin, value.assocBin, value.multBin, fitStatus);
609611
continue;
610612
}
611-
std::copy_n(parameters, value.parameters.size(), value.parameters.begin());
613+
value.parameters = parameters;
612614
if (value.parameters[2] <= 0.0 || value.parameters[5] <= 0.0 || value.parameters[8] <= 0.0) {
613615
LOGF(warning, "Skipping yield template (%d, %d, %d) with non-positive Gaussian width", value.trigBin, value.assocBin, value.multBin);
614616
continue;
615617
}
616618
const auto intervalMatchesAxis = [](const AxisSpec& axis, double low, double high) {
617619
constexpr double Tolerance = 1e-6;
618620
const auto& edges = axis.binEdges;
619-
return std::any_of(edges.begin(), edges.end() - 1, [&](const auto& edge) {
620-
const auto index = static_cast<std::size_t>(&edge - edges.data());
621-
return std::abs(edge - low) < Tolerance && std::abs(edges[index + 1] - high) < Tolerance;
622-
});
621+
for (std::size_t index = 0; index + 1 < edges.size(); ++index) {
622+
if (std::abs(edges[index] - low) < Tolerance && std::abs(edges[index + 1] - high) < Tolerance) {
623+
return true;
624+
}
625+
}
626+
return false;
623627
};
624628
if (!intervalMatchesAxis(AxisSpec(axisMultiplicity), value.nchLow, value.nchHigh) ||
625629
!intervalMatchesAxis(AxisSpec(axisPtTrigger), value.trigPtLow, value.trigPtHigh) ||
@@ -651,7 +655,7 @@ struct TwoParticleCorrelationsMpi {
651655
return;
652656
}
653657

654-
TList* calibration = dynamic_cast<TList*>(input->Get("ccdb_object"));
658+
auto* calibration = dynamic_cast<TList*>(input->Get("ccdb_object"));
655659
auto findObject = [&](const char* name) -> TObject* {
656660
if (auto* object = input->Get(name)) {
657661
return object;
@@ -724,8 +728,8 @@ struct TwoParticleCorrelationsMpi {
724728
void addPairProbabilities(EventSeedEstimate& estimate, const YieldTemplate& yieldTemplate, double deltaPhi) const
725729
{
726730
const auto& parameters = yieldTemplate.parameters;
727-
const double near = std::max(0.0, evaluateGaussian(deltaPhi, &parameters[0]) + evaluateGaussian(deltaPhi, &parameters[3]));
728-
const double away = std::max(0.0, evaluateGaussian(deltaPhi, &parameters[6]));
731+
const double near = std::max(0.0, evaluateGaussian(deltaPhi, parameters.data()) + evaluateGaussian(deltaPhi, parameters.data() + 3));
732+
const double away = std::max(0.0, evaluateGaussian(deltaPhi, parameters.data() + 6));
729733
const double baseline = std::max(0.0, parameters[9]);
730734
const double total = baseline + near + away;
731735
if (total <= 0.0) {

0 commit comments

Comments
 (0)