Skip to content

Commit 346c08b

Browse files
authored
[PWGHF] Cleanup and bug fixes using cppcheck and clang-tidy (#13287)
1 parent 6c18a8a commit 346c08b

20 files changed

+182
-255
lines changed

PWGHF/D2H/Macros/runMassFitter.C

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,14 @@ int runMassFitter(const TString& configFileName)
237237
hMass[iSliceVar] = inputFile->Get<TH1>(inputHistoName[iSliceVar].data());
238238
if (enableRefl) {
239239
hMassRefl[iSliceVar] = inputFileRefl->Get<TH1>(reflHistoName[iSliceVar].data());
240-
hMassSgn[iSliceVar] = inputFileRefl->Get<TH1>(fdHistoName[iSliceVar].data());
241-
hMassSgn[iSliceVar]->Add(inputFileRefl->Get<TH1>(promptHistoName[iSliceVar].data()));
242240
if (hMassRefl[iSliceVar] == nullptr) {
243241
throw std::runtime_error("ERROR: MC reflection histogram not found! Exit!");
244242
}
243+
hMassSgn[iSliceVar] = inputFileRefl->Get<TH1>(fdHistoName[iSliceVar].data());
245244
if (hMassSgn[iSliceVar] == nullptr) {
246245
throw std::runtime_error("ERROR: MC prompt or FD histogram not found! Exit!");
247246
}
247+
hMassSgn[iSliceVar]->Add(inputFileRefl->Get<TH1>(promptHistoName[iSliceVar].data()));
248248
}
249249
} else {
250250
hMass[iSliceVar] = inputFile->Get<TH1>(promptHistoName[iSliceVar].data());
@@ -505,9 +505,6 @@ int runMassFitter(const TString& configFileName)
505505
hRawYieldsChiSquareTotal->SetBinError(iSliceVar + 1, 1.e-20);
506506
if (enableRefl) {
507507
hReflectionOverSignal->SetBinContent(iSliceVar + 1, reflOverSgn);
508-
}
509-
510-
if (enableRefl) {
511508
if (nSliceVarBins > 1) {
512509
canvasRefl[iCanvas]->cd(iSliceVar - nCanvasesMax * iCanvas + 1);
513510
} else {
@@ -625,7 +622,7 @@ void divideCanvas(TCanvas* canvas, int nSliceVarBins)
625622
}
626623
}
627624

628-
int main(int argc, char* argv[])
625+
int main(int argc, const char* argv[])
629626
{
630627
if (argc == 1) {
631628
throw std::runtime_error("Not enough arguments. Please use\n./runMassFitter configFileName");

PWGHF/D2H/Tasks/taskCharmPolarisation.cxx

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,8 +1393,8 @@ struct HfTaskCharmPolarisation {
13931393
template <charm_polarisation::DecayChannel Channel>
13941394
bool isInSignalRegion(float invMass)
13951395
{
1396-
float invMassMin = 0.f;
1397-
float invMassMax = 100.f;
1396+
float invMassMin;
1397+
float invMassMax;
13981398
if constexpr (Channel == charm_polarisation::DecayChannel::DstarToDzeroPi) { // D*+
13991399
invMassMin = 0.142f;
14001400
invMassMax = 0.15f;
@@ -1576,7 +1576,7 @@ struct HfTaskCharmPolarisation {
15761576
// variable definition
15771577
float pxDau{-1000.f}, pyDau{-1000.f}, pzDau{-1000.f};
15781578
float pxCharmHad{-1000.f}, pyCharmHad{-1000.f}, pzCharmHad{-1000.f};
1579-
float massDau{0.f}, invMassCharmHad{0.f}, invMassCharmHadForSparse{0.f}, invMassD0{0.f}, invMassKPiLc{0.f}, invMassPKLc{0.f}, invMassPPiLc{0.f};
1579+
double massDau{0.}, invMassCharmHad{0.}, invMassCharmHadForSparse{0.}, invMassD0{0.}, invMassKPiLc{0.}, invMassPKLc{0.}, invMassPPiLc{0.};
15801580
float rapidity{-999.f};
15811581
std::array<float, 3> outputMl{-1.f, -1.f, -1.f};
15821582
int isRotatedCandidate = 0; // currently meaningful only for Lc->pKpi
@@ -1834,12 +1834,11 @@ struct HfTaskCharmPolarisation {
18341834
float const xQvec = (*qVecs).at(0);
18351835
float const yQvec = (*qVecs).at(1);
18361836
ROOT::Math::XYZVector const qVecNorm = ROOT::Math::XYZVector(yQvec, -xQvec, 0.f);
1837-
float cosThetaStarEP = -10.f;
18381837
float const phiEP = -99.f;
18391838

18401839
if (activateTHnSparseCosThStarEP) {
18411840
// EP
1842-
cosThetaStarEP = qVecNorm.Dot(threeVecDauCM) / std::sqrt(threeVecDauCM.Mag2()) / std::sqrt(qVecNorm.Mag2());
1841+
float cosThetaStarEP = qVecNorm.Dot(threeVecDauCM) / std::sqrt(threeVecDauCM.Mag2()) / std::sqrt(qVecNorm.Mag2());
18431842
fillRecoHistos<Channel, WithMl, DoMc, charm_polarisation::CosThetaStarType::EP>(invMassCharmHadForSparse, ptCharmHad, numPvContributors, rapidity, invMassD0, invMassKPiLc, cosThetaStarEP, phiEP, outputMl, isRotatedCandidate, origin, ptBhadMother, resoChannelLc, absEtaTrackMin, numItsClsMin, numTpcClsMin, charge, nMuons, partRecoDstar);
18441843
}
18451844
}
@@ -2310,8 +2309,7 @@ struct HfTaskCharmPolarisation {
23102309
TracksWithExtra const& tracks)
23112310
{
23122311
for (const auto& collision : collisions) {
2313-
float centrality = {-1.f};
2314-
centrality = o2::hf_centrality::getCentralityColl(collision, centEstimator);
2312+
const auto centrality = o2::hf_centrality::getCentralityColl(collision, centEstimator);
23152313
if (centrality < centralityMin || centrality > centralityMax) {
23162314
continue; // skip this collision if outside of the centrality range
23172315
}
@@ -2340,8 +2338,7 @@ struct HfTaskCharmPolarisation {
23402338
TracksWithExtra const& tracks)
23412339
{
23422340
for (const auto& collision : collisions) {
2343-
float centrality = {-1.f};
2344-
centrality = o2::hf_centrality::getCentralityColl(collision, centEstimator);
2341+
const auto centrality = o2::hf_centrality::getCentralityColl(collision, centEstimator);
23452342
if (centrality < centralityMin || centrality > centralityMax) {
23462343
continue; // skip this collision if outside of the centrality range
23472344
}
@@ -2371,11 +2368,10 @@ struct HfTaskCharmPolarisation {
23712368
FilteredCandDstarWSelFlagAndMc const& dstarCandidates,
23722369
TracksWithExtra const& tracks)
23732370
{
2374-
float centrality = {-1.f};
23752371
int numPvContributorsGen{0};
23762372

23772373
for (const auto& collision : collisions) { // loop over reco collisions associated to this gen collision
2378-
centrality = o2::hf_centrality::getCentralityColl(collision, centEstimator);
2374+
const auto centrality = o2::hf_centrality::getCentralityColl(collision, centEstimator);
23792375
if (centrality < centralityMin || centrality > centralityMax) {
23802376
continue; // skip this collision if outside of the centrality range
23812377
}
@@ -2400,7 +2396,7 @@ struct HfTaskCharmPolarisation {
24002396
}
24012397
for (const auto& mcParticle : mcParticles) {
24022398
const auto& recoCollsPerMcColl = collisions.sliceBy(colPerMcCollision, mcParticle.mcCollision().globalIndex());
2403-
float const cent = o2::hf_centrality::getCentralityGenColl(recoCollsPerMcColl, centEstimator);
2399+
const auto cent = o2::hf_centrality::getCentralityGenColl(recoCollsPerMcColl, centEstimator);
24042400
runMcGenPolarisationAnalysis<charm_polarisation::DecayChannel::DstarToDzeroPi, true>(mcParticle, mcParticles, numPvContributorsGen, &cent);
24052401
}
24062402
}
@@ -2412,11 +2408,10 @@ struct HfTaskCharmPolarisation {
24122408
FilteredCandDstarWSelFlagAndMcAndMl const& dstarCandidates,
24132409
TracksWithExtra const& tracks)
24142410
{
2415-
float centrality = {-1.f};
24162411
int numPvContributorsGen{0};
24172412

24182413
for (const auto& collision : collisions) { // loop over reco collisions associated to this gen collision
2419-
centrality = o2::hf_centrality::getCentralityColl(collision, centEstimator);
2414+
const auto centrality = o2::hf_centrality::getCentralityColl(collision, centEstimator);
24202415
if (centrality < centralityMin || centrality > centralityMax) {
24212416
continue; // skip this collision if outside of the centrality range
24222417
}
@@ -2441,7 +2436,7 @@ struct HfTaskCharmPolarisation {
24412436
}
24422437
for (const auto& mcParticle : mcParticles) {
24432438
const auto& recoCollsPerMcColl = collisions.sliceBy(colPerMcCollision, mcParticle.mcCollision().globalIndex());
2444-
float const cent = o2::hf_centrality::getCentralityGenColl(recoCollsPerMcColl, centEstimator);
2439+
const auto cent = o2::hf_centrality::getCentralityGenColl(recoCollsPerMcColl, centEstimator);
24452440
runMcGenPolarisationAnalysis<charm_polarisation::DecayChannel::DstarToDzeroPi, true>(mcParticle, mcParticles, numPvContributorsGen, &cent);
24462441
}
24472442
}

PWGHF/D2H/Tasks/taskSigmacToCascade.cxx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ struct HfTaskSigmacToCascade {
140140
{
141141
for (const auto& candSc : candScs) {
142142
const auto& candidateLc = candSc.prongLc_as<RecoLc>();
143-
float massSc(-1.), massLc(-1.), deltaMass(-1.);
144143
float ptSc(candSc.pt()), ptLc(candidateLc.pt());
145144
float const etaSc(candSc.eta()) /*, etaLc(candidateLc.eta())*/;
146145
float const phiSc(candSc.phi()) /*, phiLc(candidateLc.phi())*/;
@@ -149,9 +148,9 @@ struct HfTaskSigmacToCascade {
149148
float cpaLc(candidateLc.cpa()), cpaXYLc(candidateLc.cpaXY());
150149
float y(-1.);
151150

152-
massLc = hfHelper.invMassLcToK0sP(candidateLc);
153-
massSc = hfHelper.invMassScRecoLcToK0sP(candSc, candidateLc);
154-
deltaMass = massSc - massLc;
151+
auto massLc = hfHelper.invMassLcToK0sP(candidateLc);
152+
auto massSc = hfHelper.invMassScRecoLcToK0sP(candSc, candidateLc);
153+
auto deltaMass = massSc - massLc;
155154
if (candSc.charge() == 0) {
156155
y = hfHelper.ySc0(candSc);
157156
} else if (candSc.charge() == 2) {

PWGHF/HFC/Macros/DhCorrelationExtraction.cxx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ DhCorrelationExtraction::DhCorrelationExtraction(const DhCorrelationExtraction&
116116
fFilePromptMc(source.fFilePromptMc),
117117
fFileNonPromptMc(source.fFileNonPromptMc),
118118
fDirMass(source.fDirMass),
119+
fDirSE(source.fDirSE),
120+
fDirME(source.fDirME),
119121
fDirSecPart(source.fDirSecPart),
120122
fCorrectedCorrHisto(source.fCorrectedCorrHisto),
121123
fCorrectedCorrHistoBaselineSubtr(source.fCorrectedCorrHistoBaselineSubtr),
@@ -942,16 +944,15 @@ Bool_t DhCorrelationExtraction::readInputSecondaryPartContamination()
942944
TH1D* DhCorrelationExtraction::evaluateMcClosModulations(Double_t ptCandMin, Double_t ptCandMax, Double_t ptHadMin, Double_t ptHadMax)
943945
{
944946

945-
TH1D* hModul = new TH1D();
947+
TH1D* hModul = nullptr;
946948

947949
fFilePromptMc = TFile::Open(fFilePromptMcRecName.Data());
948-
fFileNonPromptMc = TFile::Open(fFileNonPromptMcRecName.Data());
949-
950950
if (fFilePromptMc == nullptr) {
951-
std::cout << "[ERROR] File prompt MC rec cannot be opened! check your file path!" << std::endl;
951+
throw std::runtime_error("[ERROR] File prompt MC rec cannot be opened! check your file path!");
952952
}
953+
fFileNonPromptMc = TFile::Open(fFileNonPromptMcRecName.Data());
953954
if (fFileNonPromptMc == nullptr) {
954-
std::cout << "[ERROR] File non-prompt MC rec cannot be opened! check your file path!" << std::endl;
955+
throw std::runtime_error("[ERROR] File non-prompt MC rec cannot be opened! check your file path!");
955956
}
956957

957958
// TODO: generalise this part
@@ -1019,15 +1020,15 @@ TH1D* DhCorrelationExtraction::evaluateMcClosModulations(Double_t ptCandMin, Dou
10191020
TH2D* DhCorrelationExtraction::getCorrelHisto(Int_t sEorMe, Int_t sorSb, Int_t pool, Double_t ptCandMin, Double_t ptCandMax, Double_t ptHadMin, Double_t ptHadMax)
10201021
{
10211022
// TODO: Subtraction of softpion
1022-
TH2D* h2D = new TH2D(); // pointer to be returned
1023+
TH2D* h2D = nullptr; // pointer to be returned
10231024

10241025
THnSparseD* hSparse = nullptr;
10251026
if (sEorMe == kSE) { // Same Event
10261027
if (sorSb == kSign) {
10271028
hSparse = reinterpret_cast<THnSparseD*>(fDirSE->Get(fSECorrelSignalRegionName.Data()));
10281029
} else if (!fSidebandDivided) {
10291030
hSparse = reinterpret_cast<THnSparseD*>(fDirSE->Get(fSECorrelSidebandsName.Data()));
1030-
} else if (fSidebandDivided) {
1031+
} else {
10311032
if (fUseSidebLeft && !fUseSidebRight) {
10321033
hSparse = reinterpret_cast<THnSparseD*>(fDirSE->Get(fSECorrelSidebandLeftName.Data()));
10331034
} else if (!fUseSidebLeft && fUseSidebRight) {
@@ -1044,7 +1045,7 @@ TH2D* DhCorrelationExtraction::getCorrelHisto(Int_t sEorMe, Int_t sorSb, Int_t p
10441045
hSparse = reinterpret_cast<THnSparseD*>(fDirME->Get(fMECorrelSignalRegionName.Data()));
10451046
} else if (!fSidebandDivided) {
10461047
hSparse = reinterpret_cast<THnSparseD*>(fDirME->Get(fMECorrelSidebandsName.Data()));
1047-
} else if (fSidebandDivided) {
1048+
} else {
10481049
if (fUseSidebLeft && !fUseSidebRight) {
10491050
hSparse = reinterpret_cast<THnSparseD*>(fDirME->Get(fMECorrelSidebandLeftName.Data()));
10501051
} else if (!fUseSidebLeft && fUseSidebRight) {
@@ -1183,7 +1184,7 @@ void DhCorrelationExtraction::getSignalAndBackgroundForNorm(Double_t ptCandMin,
11831184
TH2D* DhCorrelationExtraction::getFdTemplateHisto(Int_t promptOrFd, Double_t ptCandMin, Double_t ptCandMax, Double_t ptHadMin, Double_t ptHadMax)
11841185
{
11851186

1186-
TH2D* h2D = new TH2D(); // pointer to be returned
1187+
TH2D* h2D = nullptr; // pointer to be returned
11871188

11881189
if (promptOrFd == kPrompt) {
11891190
h2D = reinterpret_cast<TH2D*>(fFileFDTemplate->Get(Form("%s%.0f_%.0f_ptassoc%.0f_%.0f", fHistoFDTemplatePromptName.Data(), ptCandMin, ptCandMax, ptHadMin, ptHadMax)));
@@ -1215,7 +1216,7 @@ TH2D* DhCorrelationExtraction::getFdTemplateHisto(Int_t promptOrFd, Double_t ptC
12151216
TH1D* DhCorrelationExtraction::getCorrelHistoSecondaryPart(Int_t partType, Double_t ptCandMin, Double_t ptCandMax, Double_t ptHadMin, Double_t ptHadMax)
12161217
{
12171218

1218-
TH1D* h1D = new TH1D(); // pointer to be returned
1219+
TH1D* h1D = nullptr; // pointer to be returned
12191220

12201221
THnSparseD* hSparse = nullptr;
12211222

@@ -1329,8 +1330,7 @@ TH1D* DhCorrelationExtraction::reflectHistoRun2(TH1D* h, Double_t scale)
13291330
Double_t DhCorrelationExtraction::getFdPromptFrac(Double_t ptCandMin, Double_t ptCandMax, Double_t /*ptHadMin*/, Double_t /*ptHadMax*/)
13301331
{
13311332

1332-
TH1D* h1D = new TH1D();
1333-
h1D = reinterpret_cast<TH1D*>(fFileFDPromptFrac->Get(fHistoFDPromptFracName.Data()));
1333+
TH1D* h1D = reinterpret_cast<TH1D*>(fFileFDPromptFrac->Get(fHistoFDPromptFracName.Data()));
13341334

13351335
Int_t const binPtCandMin = h1D->GetXaxis()->FindBin(ptCandMin + 0.01);
13361336
Int_t const binPtCandMax = h1D->GetXaxis()->FindBin(ptCandMax - 0.01);
@@ -1380,7 +1380,7 @@ Double_t DhCorrelationExtraction::calculateBaseline(TH1D*& histo, Bool_t totalRa
13801380
// total range = 2*Pi
13811381
// half range = Pi , for histogram reflected under symmetric assumption
13821382

1383-
Double_t baseline, errBaseline;
1383+
Double_t baseline;
13841384
Int_t const nBinsPhi = histo->GetNbinsX();
13851385
Int_t const binPhiHalf = nBinsPhi / 2;
13861386
Int_t const binPhiHalfMinus1 = nBinsPhi / 2 - 1;

0 commit comments

Comments
 (0)