Skip to content

Commit fb224ba

Browse files
committed
[PWGEM] Fix clang-tidy and MegaLinter errors in PCM related code
- Fix clang-tidy and MegaLinter errors in PCM related code that surfaced in recent PR #17079
1 parent e20dabd commit fb224ba

6 files changed

Lines changed: 97 additions & 106 deletions

File tree

PWGEM/PhotonMeson/Core/Pi0EtaToGammaGamma.h

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,10 @@ struct Pi0EtaToGammaGamma {
266266
std::vector<float> occ_bin_edges;
267267

268268
o2::ccdb::CcdbApi ccdbApi;
269-
o2::framework::Service<o2::ccdb::BasicCCDBManager> ccdb;
270-
int mRunNumber;
271-
float d_bz;
272-
o2::emcal::Geometry* emcalGeom;
269+
o2::framework::Service<o2::ccdb::BasicCCDBManager> ccdb{};
270+
int mRunNumber = -1;
271+
float d_bz = 0;
272+
o2::emcal::Geometry* emcalGeom = nullptr;
273273

274274
//---------------------------------------------------------------------------
275275
// In the following are tags defined which help to select the correct preslice and cuts
@@ -435,10 +435,11 @@ struct Pi0EtaToGammaGamma {
435435
}
436436

437437
auto run3grp_timestamp = collision.timestamp();
438-
o2::parameters::GRPObject* grpo = 0x0;
439-
o2::parameters::GRPMagField* grpmag = 0x0;
440-
if (!skipGRPOquery)
438+
o2::parameters::GRPObject* grpo = nullptr;
439+
o2::parameters::GRPMagField* grpmag = nullptr;
440+
if (!skipGRPOquery) {
441441
grpo = ccdb->getForTimeStamp<o2::parameters::GRPObject>(grpPath, run3grp_timestamp);
442+
}
442443
if (grpo) {
443444
// Fetch magnetic field from ccdb for current collision
444445
d_bz = grpo->getNominalL3Field();
@@ -459,9 +460,9 @@ struct Pi0EtaToGammaGamma {
459460
~Pi0EtaToGammaGamma()
460461
{
461462
delete emh1;
462-
emh1 = 0x0;
463+
emh1 = nullptr;
463464
delete emh2;
464-
emh2 = 0x0;
465+
emh2 = nullptr;
465466

466467
used_photonIds_per_col.clear();
467468
used_photonIds_per_col.shrink_to_fit();
@@ -522,8 +523,7 @@ struct Pi0EtaToGammaGamma {
522523
fV0PhotonCut.SetNClassesMl(pcmcuts.cfg_nclasses_ml);
523524
fV0PhotonCut.SetMlTimestampCCDB(pcmcuts.cfg_timestamp_ccdb);
524525
fV0PhotonCut.SetCcdbUrl(ccdburl);
525-
CentType mCentralityTypeMlEnum;
526-
mCentralityTypeMlEnum = static_cast<CentType>(cfgCentEstimator.value);
526+
auto mCentralityTypeMlEnum = static_cast<CentType>(cfgCentEstimator.value);
527527
fV0PhotonCut.SetCentralityTypeMl(mCentralityTypeMlEnum);
528528
fV0PhotonCut.SetCutDirMl(pcmcuts.cfg_cut_dir_ml);
529529
fV0PhotonCut.SetMlModelPathsCCDB(pcmcuts.cfg_model_paths_ccdb);
@@ -617,9 +617,7 @@ struct Pi0EtaToGammaGamma {
617617
int iRowLast = 24;
618618
if (emcalGeom->GetSMType(iSupMod) == o2::emcal::EMCALSMType::EMCAL_HALF) {
619619
iRowLast /= 2; // 2/3 sm case
620-
} else if (emcalGeom->GetSMType(iSupMod) == o2::emcal::EMCALSMType::EMCAL_THIRD) {
621-
iRowLast /= 3; // 1/3 sm case
622-
} else if (emcalGeom->GetSMType(iSupMod) == o2::emcal::EMCALSMType::DCAL_EXT) {
620+
} else if (emcalGeom->GetSMType(iSupMod) == o2::emcal::EMCALSMType::EMCAL_THIRD || emcalGeom->GetSMType(iSupMod) == o2::emcal::EMCALSMType::DCAL_EXT) {
623621
iRowLast /= 3; // 1/3 sm case
624622
}
625623

@@ -693,7 +691,6 @@ struct Pi0EtaToGammaGamma {
693691
fRegistry.fill(HIST("Pair/rotation/hs"), mother2.M(), mother2.Pt(), eventWeight);
694692
}
695693
}
696-
return;
697694
}
698695

699696
/// \brief function to run the photon pairing
@@ -732,7 +729,7 @@ struct Pi0EtaToGammaGamma {
732729
continue;
733730
}
734731

735-
const float centralities[3] = {collision.centFT0M(), collision.centFT0A(), collision.centFT0C()};
732+
const std::array<float, 3> centralities = {collision.centFT0M(), collision.centFT0A(), collision.centFT0C()};
736733
fV0PhotonCut.SetCentrality(centralities[cfgCentEstimator]);
737734
if (centralities[cfgCentEstimator] < cfgCentMin || cfgCentMax < centralities[cfgCentEstimator]) {
738735
continue;
@@ -770,9 +767,7 @@ struct Pi0EtaToGammaGamma {
770767
}
771768

772769
int occbin = -1;
773-
if (cfgOccupancyEstimator == 0) {
774-
occbin = lower_bound(occ_bin_edges.begin(), occ_bin_edges.end(), collision.ft0cOccupancyInTimeRange()) - occ_bin_edges.begin() - 1;
775-
} else if (cfgOccupancyEstimator == 1) {
770+
if (cfgOccupancyEstimator == 1) {
776771
occbin = lower_bound(occ_bin_edges.begin(), occ_bin_edges.end(), collision.trackOccupancyInTimeRange()) - occ_bin_edges.begin() - 1;
777772
} else {
778773
occbin = lower_bound(occ_bin_edges.begin(), occ_bin_edges.end(), collision.ft0cOccupancyInTimeRange()) - occ_bin_edges.begin() - 1;

PWGEM/PhotonMeson/Core/Pi0EtaToGammaGammaMC.h

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -228,16 +228,16 @@ struct Pi0EtaToGammaGammaMC {
228228
o2::framework::Configurable<float> cfg_min_Ecluster{"cfg_min_Ecluster", 0.3, "Minimum cluster energy for PHOS in GeV"};
229229
} phoscuts;
230230

231-
TF1* f1fd_k0s_to_pi0;
231+
TF1* f1fd_k0s_to_pi0 = nullptr;
232232
o2::framework::HistogramRegistry fRegistry{"output", {}, o2::framework::OutputObjHandlingPolicy::AnalysisObject, false, false};
233233
// static constexpr std::string_view event_types[2] = {"before/", "after/"};
234234
// static constexpr std::string_view event_pair_types[2] = {"same/", "mix/"};
235-
static constexpr std::string_view kParnames[2] = {"Pi0/", "Eta/"};
235+
static constexpr std::array<std::string_view, 2> kParnames = {"Pi0/", "Eta/"};
236236

237237
o2::ccdb::CcdbApi ccdbApi;
238-
o2::framework::Service<o2::ccdb::BasicCCDBManager> ccdb;
239-
int mRunNumber;
240-
float d_bz;
238+
o2::framework::Service<o2::ccdb::BasicCCDBManager> ccdb{};
239+
int mRunNumber = 0;
240+
float d_bz = 0;
241241

242242
void init(o2::framework::InitContext&)
243243
{
@@ -291,10 +291,11 @@ struct Pi0EtaToGammaGammaMC {
291291
}
292292

293293
auto run3grp_timestamp = collision.timestamp();
294-
o2::parameters::GRPObject* grpo = 0x0;
295-
o2::parameters::GRPMagField* grpmag = 0x0;
296-
if (!skipGRPOquery)
294+
o2::parameters::GRPObject* grpo = nullptr;
295+
o2::parameters::GRPMagField* grpmag = nullptr;
296+
if (!skipGRPOquery) {
297297
grpo = ccdb->getForTimeStamp<o2::parameters::GRPObject>(grpPath, run3grp_timestamp);
298+
}
298299
if (grpo) {
299300
// Fetch magnetic field from ccdb for current collision
300301
d_bz = grpo->getNominalL3Field();
@@ -315,7 +316,7 @@ struct Pi0EtaToGammaGammaMC {
315316
~Pi0EtaToGammaGammaMC()
316317
{
317318
delete f1fd_k0s_to_pi0;
318-
f1fd_k0s_to_pi0 = 0x0;
319+
f1fd_k0s_to_pi0 = nullptr;
319320
}
320321

321322
void DefineEMEventCut()
@@ -370,8 +371,7 @@ struct Pi0EtaToGammaGammaMC {
370371
fV0PhotonCut.SetNClassesMl(pcmcuts.cfg_nclasses_ml);
371372
fV0PhotonCut.SetMlTimestampCCDB(pcmcuts.cfg_timestamp_ccdb);
372373
fV0PhotonCut.SetCcdbUrl(ccdburl);
373-
CentType mCentralityTypeMlEnum;
374-
mCentralityTypeMlEnum = static_cast<CentType>(cfgCentEstimator.value);
374+
auto mCentralityTypeMlEnum = static_cast<CentType>(cfgCentEstimator.value);
375375
fV0PhotonCut.SetCentralityTypeMl(mCentralityTypeMlEnum);
376376
fV0PhotonCut.SetCutDirMl(pcmcuts.cfg_cut_dir_ml);
377377
fV0PhotonCut.SetMlModelPathsCCDB(pcmcuts.cfg_model_paths_ccdb);
@@ -597,7 +597,7 @@ struct Pi0EtaToGammaGammaMC {
597597
continue;
598598
}
599599

600-
const float centralities[3] = {collision.centFT0M(), collision.centFT0A(), collision.centFT0C()};
600+
const std::array<float, 3> centralities = {collision.centFT0M(), collision.centFT0A(), collision.centFT0C()};
601601
fV0PhotonCut.SetCentrality(centralities[cfgCentEstimator]);
602602
if (centralities[cfgCentEstimator] < cfgCentMin || cfgCentMax < centralities[cfgCentEstimator]) {
603603
continue;
@@ -730,10 +730,11 @@ struct Pi0EtaToGammaGammaMC {
730730
}
731731

732732
if (g1mc.globalIndex() == g2mc.globalIndex()) {
733-
if (o2::aod::pwgem::dilepton::utils::mcutil::getMotherPDGCode(g1mc, mcparticles) == PDG_t::kPi0)
733+
if (o2::aod::pwgem::dilepton::utils::mcutil::getMotherPDGCode(g1mc, mcparticles) == PDG_t::kPi0) {
734734
fRegistry.fill(HIST("Pair/Pi0/hs_FromSameGamma"), v12.M(), v12.Pt(), wpair);
735-
else if (o2::aod::pwgem::dilepton::utils::mcutil::getMotherPDGCode(g1mc, mcparticles) == o2::constants::physics::Pdg::kEta)
735+
} else if (o2::aod::pwgem::dilepton::utils::mcutil::getMotherPDGCode(g1mc, mcparticles) == o2::constants::physics::Pdg::kEta) {
736736
fRegistry.fill(HIST("Pair/Eta/hs_FromSameGamma"), v12.M(), v12.Pt(), wpair);
737+
}
737738
continue;
738739
}
739740

@@ -951,7 +952,7 @@ struct Pi0EtaToGammaGammaMC {
951952
continue;
952953
}
953954

954-
float centralities[3] = {collision.centFT0M(), collision.centFT0A(), collision.centFT0C()};
955+
std::array<float, 3> centralities = {collision.centFT0M(), collision.centFT0A(), collision.centFT0C()};
955956
if (centralities[cfgCentEstimator] < cfgCentMin || cfgCentMax < centralities[cfgCentEstimator]) {
956957
continue;
957958
}

PWGEM/PhotonMeson/Core/V0PhotonCut.cxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void V0PhotonCut::SetAPRange(float max_alpha, float max_qt)
7474
}
7575
void V0PhotonCut::SetMaxMeePsiPairDep(std::function<float(float)> psiDepCut)
7676
{
77-
mMaxMeePsiPairDep = psiDepCut;
77+
mMaxMeePsiPairDep = std::move(psiDepCut);
7878
LOG(info) << "V0 Photon Cut, set max mee psi pair dep: " << mMaxMeePsiPairDep(0.1);
7979
}
8080
void V0PhotonCut::SetRxyRange(float min, float max, float midL, float midH)
@@ -209,7 +209,7 @@ void V0PhotonCut::SetMaxDcaZ(float maxDcaZ)
209209

210210
void V0PhotonCut::SetMaxDcaXYPtDep(std::function<float(float)> ptDepCut)
211211
{
212-
mMaxDcaXYPtDep = ptDepCut;
212+
mMaxDcaXYPtDep = std::move(ptDepCut);
213213
LOG(info) << "V0 Photon Cut, set max DCA xy pt dep: " << mMaxDcaXYPtDep(1.0);
214214
}
215215

@@ -341,9 +341,9 @@ void V0PhotonCut::SetNClassesMl(int nClasses)
341341
LOG(info) << "V0 Photon Cut, set number of classes ML: " << mNClassesMl;
342342
}
343343

344-
void V0PhotonCut::SetNamesInputFeatures(const std::vector<std::string>& featureNames)
344+
void V0PhotonCut::SetNamesInputFeatures(const std::vector<std::string>& namesInputFeaturesVec)
345345
{
346-
mNamesInputFeatures = featureNames;
346+
mNamesInputFeatures = namesInputFeaturesVec;
347347
mMlInputFeatures.reserve(mNamesInputFeatures.size());
348348
LOG(info) << "V0 Photon Cut, set ML input feature names with size:" << mNamesInputFeatures.size();
349349
}

PWGEM/PhotonMeson/Core/V0PhotonCut.h

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@
4646
#include <utility>
4747
#include <vector>
4848

49-
namespace o2::analysis
50-
{
51-
52-
// namespace per channel
53-
namespace em_cuts_ml
49+
namespace o2::analysis::em_cuts_ml
5450
{
5551
// direction of the cut
5652
enum CutDirection {
@@ -64,7 +60,7 @@ static constexpr int NBins = 12;
6460
static constexpr int NBinsPt = 12;
6561
static constexpr int NCutScores = 2;
6662
// default values for the pT bin edges, offset by 1 from the bin numbers in cuts array
67-
constexpr double BinsPt[NBinsPt + 1] = {
63+
constexpr std::array<double, NBins + 1> BinsPt = {
6864
0.,
6965
0.25,
7066
0.5,
@@ -78,9 +74,9 @@ constexpr double BinsPt[NBinsPt + 1] = {
7874
20.,
7975
50.,
8076
100.};
81-
const auto vecBinsPt = std::vector<double>{BinsPt, BinsPt + NBinsPt + 1};
77+
const auto vecBinsPt = std::vector<double>{BinsPt.begin(), BinsPt.end()};
8278
static constexpr int NBinsCent = 11;
83-
constexpr double BinsCent[NBinsCent + 1] = {
79+
constexpr std::array<double, NBinsCent + 1> BinsCent = {
8480
0.,
8581
5,
8682
10,
@@ -93,30 +89,29 @@ constexpr double BinsCent[NBinsCent + 1] = {
9389
80,
9490
90,
9591
100.};
96-
const auto vecBinsCent = std::vector<double>{BinsCent, BinsCent + NBinsCent + 1};
92+
const auto vecBinsCent = std::vector<double>{BinsCent.begin(), BinsCent.end()};
9793

9894
// default values for the ML model paths, one model per pT bin
9995
static const std::vector<std::string> modelPaths = {
10096
""};
10197

10298
// default values for the cut directions
103-
constexpr int CutDir[NCutScores] = {CutGreater, CutSmaller};
104-
const auto vecCutDir = std::vector<int>{CutDir, CutDir + NCutScores};
99+
constexpr std::array<int, NCutScores> CutDir = {CutGreater, CutSmaller};
100+
const auto vecCutDir = std::vector<int>{CutDir.begin(), CutDir.end()};
105101

106102
// default values for the cuts
107-
constexpr double Cuts[NBins][NCutScores] = {
108-
{0.5, 0.5},
109-
{0.5, 0.5},
110-
{0.5, 0.5},
111-
{0.5, 0.5},
112-
{0.5, 0.5},
113-
{0.5, 0.5},
114-
{0.5, 0.5},
115-
{0.5, 0.5},
116-
{0.5, 0.5},
117-
{0.5, 0.5},
118-
{0.5, 0.5},
119-
{0.5, 0.5}};
103+
constexpr std::array<std::array<double, NCutScores>, NBins> Cuts = {{{0.5, 0.5},
104+
{0.5, 0.5},
105+
{0.5, 0.5},
106+
{0.5, 0.5},
107+
{0.5, 0.5},
108+
{0.5, 0.5},
109+
{0.5, 0.5},
110+
{0.5, 0.5},
111+
{0.5, 0.5},
112+
{0.5, 0.5},
113+
{0.5, 0.5},
114+
{0.5, 0.5}}};
120115

121116
// row labels
122117
static const std::vector<std::string> labelsPt = {
@@ -148,9 +143,8 @@ static const std::vector<std::string> labelsCent = {
148143

149144
// column labels
150145
static const std::vector<std::string> labelsCutScore = {"score background", "score primary photons"};
151-
} // namespace em_cuts_ml
152146

153-
} // namespace o2::analysis
147+
} // namespace o2::analysis::em_cuts_ml
154148

155149
namespace o2::analysis::em::v0
156150
{
@@ -214,8 +208,8 @@ class V0PhotonCut : public TNamed
214208
kRadAndAngle = 2
215209
};
216210

217-
const std::string getName() const { return name; }
218-
const std::string getTitle() const { return title; }
211+
const std::string& getName() const { return name; }
212+
const std::string& getTitle() const { return title; }
219213

220214
/// \brief add histograms to registry
221215
/// \param fRegistry pointer to histogram registry
@@ -307,7 +301,7 @@ class V0PhotonCut : public TNamed
307301
void fillBeforePhotonHistogram(TV0 const& v0, TLeg1 const& pos, TLeg2 const& ele, o2::framework::HistogramRegistry* fRegistry = nullptr) const
308302
{
309303

310-
if (mDoQA == false || fRegistry == nullptr) {
304+
if (!mDoQA || fRegistry == nullptr) {
311305
return;
312306
}
313307

@@ -337,7 +331,7 @@ class V0PhotonCut : public TNamed
337331
void fillAfterPhotonHistogram(TV0 const& v0, TLeg1 const& pos, TLeg2 const& ele, o2::framework::HistogramRegistry* fRegistry = nullptr) const
338332
{
339333

340-
if (mDoQA == false || fRegistry == nullptr) {
334+
if (!mDoQA || fRegistry == nullptr) {
341335
return;
342336
}
343337

@@ -1018,7 +1012,7 @@ class V0PhotonCut : public TNamed
10181012
int binsNCent = static_cast<int>(mBinsCentMl.size()) - 1;
10191013
int binsN = binsNPt * binsNCent;
10201014
if (binsN * static_cast<int>(mCutDirMl.size()) != static_cast<int>(mCutsMlFlat.size())) {
1021-
LOG(fatal) << "Mismatch in number of bins and cuts provided for 2D ML application: binsN * mCutDirMl: " << int(binsN) * int(mCutDirMl.size()) << " bins vs. mCutsMlFlat: " << mCutsMlFlat.size() << " cuts";
1015+
LOG(fatal) << "Mismatch in number of bins and cuts provided for 2D ML application: binsN * mCutDirMl: " << binsN * static_cast<int>(mCutDirMl.size()) << " bins vs. mCutsMlFlat: " << mCutsMlFlat.size() << " cuts";
10221016
}
10231017
if (binsN != static_cast<int>(mOnnxFileNames.size())) {
10241018
LOG(fatal) << "Mismatch in number of bins and ONNX files provided for 2D ML application: binsN " << binsN << " bins vs. mOnnxFileNames: " << mOnnxFileNames.size() << " ONNX files";
@@ -1064,7 +1058,7 @@ class V0PhotonCut : public TNamed
10641058
mEmMlResponse->init();
10651059
}
10661060

1067-
const std::span<float> getBDTValue() const
1061+
std::span<float> getBDTValue() const
10681062
{
10691063
return mMlBDTScores;
10701064
}
@@ -1178,15 +1172,15 @@ class V0PhotonCut : public TNamed
11781172
float mMaxPCA{2.f};
11791173
float mMaxChi2KF{1e+10};
11801174
float mMaxMarginZ{7.f};
1181-
std::function<float(float)> mMaxMeePsiPairDep{}; // max mee as a function of psipair
1175+
std::function<float(float)> mMaxMeePsiPairDep; // max mee as a function of psipair
11821176
bool mIsOnWwireIB{false};
11831177
bool mIsOnWwireOB{false};
11841178
bool mRejectITSib{false};
11851179
TooCloseCuts mTooCloseType{V0PhotonCut::TooCloseCuts::kRadAndAngle}; // for TooCloseV0Cut: either squared distance between conversion points OR opening angle and deltaR
11861180
float mMinV0DistSquared{1.}; // for TooCloseV0Cut: cut value when using squared distance between conversion points
11871181
float mDeltaR{6.}; // for TooCloseV0Cut: V0PhotonCut::TooCloseCuts::kRadAndAngle when deltaR < this -> compare chi2
11881182
float mMinOpeningAngle{0.02}; // for TooCloseV0Cut: V0PhotonCut::TooCloseCuts::kRadAndAngle when opening angle < this -> compare chi2
1189-
mutable std::vector<uint8_t> mRejectMask{};
1183+
mutable std::vector<uint8_t> mRejectMask;
11901184

11911185
// ML cuts
11921186
bool mApplyMlCuts{false};
@@ -1208,9 +1202,9 @@ class V0PhotonCut : public TNamed
12081202
std::vector<double> mCutsMlFlat{std::vector<double>{0.5}};
12091203
o2::analysis::EmMlResponsePCM<float>* mEmMlResponse{nullptr};
12101204
mutable bool mIsSelectedMl{false};
1211-
mutable std::vector<float> mOutputML{};
1212-
mutable std::vector<float> mMlInputFeatures{};
1213-
mutable std::span<float> mMlBDTScores{};
1205+
mutable std::vector<float> mOutputML;
1206+
mutable std::vector<float> mMlInputFeatures;
1207+
mutable std::span<float> mMlBDTScores;
12141208
CentType mCentralityTypeMl{CentType::CentFT0C};
12151209
mutable V0PhotonCandidate mV0PhotonForMl;
12161210

@@ -1232,9 +1226,9 @@ class V0PhotonCut : public TNamed
12321226
float mMinChi2PerClusterITS{-1e10f}, mMaxChi2PerClusterITS{1e10f}; // max its fit chi2 per ITS cluster
12331227
float mMinMeanClusterSizeITS{-1e10f}, mMaxMeanClusterSizeITS{1e10f}; // max <its cluster size> x cos(Lmabda)
12341228

1235-
float mMaxDcaXY{1e10f}; // max dca in xy plane
1236-
float mMaxDcaZ{1e10f}; // max dca in z direction
1237-
std::function<float(float)> mMaxDcaXYPtDep{}; // max dca in xy plane as function of pT
1229+
float mMaxDcaXY{1e10f}; // max dca in xy plane
1230+
float mMaxDcaZ{1e10f}; // max dca in z direction
1231+
std::function<float(float)> mMaxDcaXYPtDep; // max dca in xy plane as function of pT
12381232
bool mRequireITSTPC{false};
12391233
bool mRequireITSonly{false};
12401234
bool mRequireTPConly{false};

0 commit comments

Comments
 (0)