Skip to content

Commit 8b6c42f

Browse files
committed
[PWGJE] emcalCorrectionTask: Fix clang-tidy errors and warnings
1 parent b2f0d29 commit 8b6c42f

1 file changed

Lines changed: 43 additions & 38 deletions

File tree

PWGJE/TableProducer/emcalCorrectionTask.cxx

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ struct EmcalCorrectionTask {
154154
Filter emccellfilter = aod::calo::caloType == selectedCellType;
155155

156156
// CDB service (for geometry)
157-
Service<o2::ccdb::BasicCCDBManager> mCcdbManager;
157+
Service<o2::ccdb::BasicCCDBManager> mCcdbManager{};
158158

159159
// Zorro for optional software trigger selection
160160
// this allows to save computation time
@@ -180,19 +180,19 @@ struct EmcalCorrectionTask {
180180
o2::framework::HistogramRegistry mHistManager{"EMCALCorrectionTaskQAHistograms"};
181181

182182
// Random number generator to draw cell time smearing for MC
183-
std::random_device rd{};
183+
std::random_device rd;
184184
std::mt19937_64 rdgen{rd()};
185185
std::normal_distribution<> normalgaus{0, 1}; // mean = 0, stddev = 1 (apply amplitude of smearing after drawing random for performance reasons)
186186

187187
// EMCal geometry
188-
o2::emcal::Geometry* geometry;
188+
o2::emcal::Geometry* geometry = nullptr;
189189

190190
// EMCal cell temperature calibrator
191191
std::unique_ptr<o2::emcal::EMCALTempCalibExtractor> mTempCalibExtractor;
192192
bool mIsTempCalibInitialized = false;
193193

194194
// Gain calibration
195-
std::array<float, 17664> mArrGainCalibDiff;
195+
std::array<float, 17664> mArrGainCalibDiff{};
196196

197197
std::vector<std::pair<int, int>> mExtraTimeShiftRunRanges;
198198

@@ -250,7 +250,7 @@ struct EmcalCorrectionTask {
250250
}
251251

252252
// read all the cluster definitions specified in the options
253-
if (clusterDefinitions->length()) {
253+
if (!clusterDefinitions->empty()) {
254254
std::stringstream parser(clusterDefinitions.value);
255255
std::string token;
256256
o2::aod::EMCALClusterDefinition clusDef;
@@ -265,7 +265,8 @@ struct EmcalCorrectionTask {
265265
mClusterFactories.setExoticCellDiffTime(exoticCellDiffTime);
266266
mClusterFactories.setExoticCellMinAmplitude(exoticCellMinAmplitude);
267267
mClusterFactories.setExoticCellInCrossMinAmplitude(exoticCellInCrossMinAmplitude);
268-
mClusterFactories.setUseWeightExotic(useWeightExotic);
268+
// TODO: Fix setUseWeightExotic in the O2 code to use bool as argument not float!
269+
mClusterFactories.setUseWeightExotic(static_cast<float>(useWeightExotic));
269270
for (const auto& clusterDefinition : mClusterDefinitions) {
270271
mClusterizers.emplace_back(std::make_unique<o2::emcal::Clusterizer<o2::emcal::Cell>>(clusterDefinition.timeDiff, clusterDefinition.timeMin, clusterDefinition.timeMax, clusterDefinition.gradientCut, clusterDefinition.doGradientCut, clusterDefinition.seedEnergy, clusterDefinition.minCellEnergy));
271272
LOG(info) << "Cluster definition initialized: " << clusterDefinition.toString();
@@ -281,7 +282,7 @@ struct EmcalCorrectionTask {
281282
clusterizer->setGeometry(geometry);
282283
}
283284

284-
if (mClusterizers.size() == 0) {
285+
if (mClusterizers.empty()) {
285286
LOG(error) << "No cluster definitions specified!";
286287
}
287288

@@ -297,6 +298,7 @@ struct EmcalCorrectionTask {
297298

298299
// Define the cell energy binning
299300
std::vector<double> cellEnergyBins;
301+
cellEnergyBins.reserve(166);
300302
for (int i = 0; i < 51; i++) { // o2-linter: disable=magic-number (just numbers for binning)
301303
cellEnergyBins.emplace_back(0.1 * (i - 0) + 0.0); // from 0 to 5 GeV/c, every 0.1 GeV
302304
}
@@ -456,7 +458,7 @@ struct EmcalCorrectionTask {
456458
numberCollsInBC.insert(std::pair<uint64_t, int>(bc.globalIndex(), collisionsInFoundBC.size()));
457459
numberCellsInBC.insert(std::pair<uint64_t, int>(bc.globalIndex(), cellsInBC.size()));
458460

459-
if (!cellsInBC.size()) {
461+
if (cellsInBC.size() == 0) {
460462
LOG(debug) << "No cells found for BC";
461463
countBC(collisionsInFoundBC.size(), false);
462464
continue;
@@ -478,7 +480,7 @@ struct EmcalCorrectionTask {
478480
if (static_cast<bool>(hasShaperCorrection) && emcal::intToChannelType(cell.cellType()) == emcal::ChannelType_t::LOW_GAIN) { // Apply shaper correction to LG cells
479481
amplitude = o2::emcal::NonlinearityHandler::evaluateShaperCorrectionCellEnergy(amplitude);
480482
}
481-
if (applyCellAbsScale) {
483+
if (applyCellAbsScale != ModeNone) {
482484
amplitude *= getAbsCellScale(cell.cellNumber());
483485
}
484486
if (applyGainCalibShift) {
@@ -617,7 +619,7 @@ struct EmcalCorrectionTask {
617619
numberCollsInBC.insert(std::pair<uint64_t, int>(bc.globalIndex(), collisionsInFoundBC.size()));
618620
numberCellsInBC.insert(std::pair<uint64_t, int>(bc.globalIndex(), cellsInBC.size()));
619621

620-
if (!cellsInBC.size()) {
622+
if (cellsInBC.size() == 0) {
621623
LOG(debug) << "No cells found for BC";
622624
countBC(collisionsInFoundBC.size(), false);
623625
continue;
@@ -639,7 +641,7 @@ struct EmcalCorrectionTask {
639641
if (static_cast<bool>(hasShaperCorrection) && emcal::intToChannelType(cell.cellType()) == emcal::ChannelType_t::LOW_GAIN) { // Apply shaper correction to LG cells
640642
amplitude = o2::emcal::NonlinearityHandler::evaluateShaperCorrectionCellEnergy(amplitude);
641643
}
642-
if (applyCellAbsScale) {
644+
if (applyCellAbsScale != ModeNone) {
643645
amplitude *= getAbsCellScale(cell.cellNumber());
644646
}
645647
if (applyGainCalibShift) {
@@ -779,7 +781,7 @@ struct EmcalCorrectionTask {
779781
numberCollsInBC.insert(std::pair<uint64_t, int>(bc.globalIndex(), collisionsInFoundBC.size()));
780782
numberCellsInBC.insert(std::pair<uint64_t, int>(bc.globalIndex(), cellsInBC.size()));
781783

782-
if (!cellsInBC.size()) {
784+
if (cellsInBC.size() == 0) {
783785
LOG(debug) << "No cells found for BC";
784786
countBC(collisionsInFoundBC.size(), false);
785787
continue;
@@ -973,7 +975,7 @@ struct EmcalCorrectionTask {
973975
numberCollsInBC.insert(std::pair<uint64_t, int>(bc.globalIndex(), collisionsInFoundBC.size()));
974976
numberCellsInBC.insert(std::pair<uint64_t, int>(bc.globalIndex(), cellsInBC.size()));
975977

976-
if (!cellsInBC.size()) {
978+
if (cellsInBC.size() == 0) {
977979
LOG(debug) << "No cells found for BC";
978980
countBC(collisionsInFoundBC.size(), false);
979981
continue;
@@ -1177,7 +1179,7 @@ struct EmcalCorrectionTask {
11771179
auto collisionsInBC = collisions.sliceBy(collisionsPerBC, bc.globalIndex());
11781180
auto cellsInBC = cells.sliceBy(cellsPerFoundBC, bc.globalIndex());
11791181

1180-
if (!cellsInBC.size()) {
1182+
if (cellsInBC.size() == 0) {
11811183
LOG(debug) << "No cells found for BC";
11821184
countBC(collisionsInBC.size(), false);
11831185
continue;
@@ -1365,7 +1367,7 @@ struct EmcalCorrectionTask {
13651367
mHistManager.fill(HIST("hClusterFCrossSigmaShortE"), cluster.E(), cluster.getFCross(), cluster.getM20());
13661368
}
13671369
if (indexMapPair && trackGlobalIndex) {
1368-
if (iCluster < indexMapPair->matchIndexTrack.size() && indexMapPair->matchIndexTrack.size() > 0) {
1370+
if (iCluster < indexMapPair->matchIndexTrack.size() && !indexMapPair->matchIndexTrack.empty()) {
13691371
for (unsigned int iTrack = 0; iTrack < indexMapPair->matchIndexTrack[iCluster].size(); iTrack++) {
13701372
if (indexMapPair->matchIndexTrack[iCluster][iTrack] >= 0) {
13711373
LOG(debug) << "Found track " << (*trackGlobalIndex)[indexMapPair->matchIndexTrack[iCluster][iTrack]] << " in cluster " << cluster.getID();
@@ -1376,7 +1378,7 @@ struct EmcalCorrectionTask {
13761378
}
13771379
}
13781380
if (indexMapPairSecondaries && secondariesGlobalIndex) {
1379-
if (iCluster < indexMapPairSecondaries->matchIndexTrack.size() && indexMapPairSecondaries->matchIndexTrack.size() > 0) {
1381+
if (iCluster < indexMapPairSecondaries->matchIndexTrack.size() && !indexMapPairSecondaries->matchIndexTrack.empty()) {
13801382
for (unsigned int iTrack = 0; iTrack < indexMapPairSecondaries->matchIndexTrack[iCluster].size(); iTrack++) {
13811383
if (indexMapPairSecondaries->matchIndexTrack[iCluster][iTrack] >= 0) {
13821384
LOG(debug) << "Found secondary track " << (*secondariesGlobalIndex)[indexMapPairSecondaries->matchIndexTrack[iCluster][iTrack]] << " in cluster " << cluster.getID();
@@ -1426,7 +1428,7 @@ struct EmcalCorrectionTask {
14261428
cluster.getIsExotic(), cluster.getDistanceToBadChannel(),
14271429
cluster.getNExMax(), static_cast<int>(mClusterDefinitions.at(iClusterizer)));
14281430
++nClusterAmb;
1429-
if (mClusterLabels.size() > 0) {
1431+
if (!mClusterLabels.empty()) {
14301432
mcclustersAmbiguous(mClusterLabels[iCluster].getLabels(), mClusterLabels[iCluster].getEnergyFractions());
14311433
}
14321434
for (int ncell = 0; ncell < cluster.getNCells(); ncell++) {
@@ -1539,10 +1541,11 @@ struct EmcalCorrectionTask {
15391541
// For convenience, use the clusterizer stored geometry to get the eta-phi
15401542
for (const auto& cell : cellsBC) {
15411543
mHistManager.fill(HIST("hCellE"), cell.getEnergy());
1542-
if (cell.getLowGain())
1544+
if (cell.getLowGain()) {
15431545
mHistManager.fill(HIST("hLGCellTimeEnergy"), cell.getTimeStamp(), cell.getEnergy());
1544-
else if (cell.getHighGain())
1546+
} else if (cell.getHighGain()) {
15451547
mHistManager.fill(HIST("hHGCellTimeEnergy"), cell.getTimeStamp(), cell.getEnergy());
1548+
}
15461549
mHistManager.fill(HIST("hCellTowerID"), cell.getTower());
15471550
auto res = mClusterizers.at(0)->getGeometry()->EtaPhiFromIndex(cell.getTower());
15481551
mHistManager.fill(HIST("hCellEtaPhi"), std::get<0>(res), RecoDecay::constrainAngle(std::get<1>(res)));
@@ -1561,12 +1564,12 @@ struct EmcalCorrectionTask {
15611564
return cellAbsScaleFactors.value[mClusterizers.at(0)->getGeometry()->GetSMType(iSM)];
15621565

15631566
// Apply cell scale based on columns to accoutn for material of TRD structures
1564-
} else if (applyCellAbsScale == CellScaleMode::ModeColumnWise) {
1567+
}
1568+
if (applyCellAbsScale == CellScaleMode::ModeColumnWise) {
15651569
auto res = mClusterizers.at(0)->getGeometry()->GlobalRowColFromIndex(cellID);
15661570
return cellAbsScaleFactors.value[std::get<1>(res)];
1567-
} else {
1568-
return 1.f;
15691571
}
1572+
return 1.f;
15701573
}
15711574

15721575
// Apply shift of the cell time in data and MC
@@ -1590,26 +1593,28 @@ struct EmcalCorrectionTask {
15901593
timeshift = -std::sqrt(215.f + timeCol * timeCol); // 215 is 14.67ns^2 (time it takes to get the cell at eta = 0)
15911594

15921595
// Also smear the time to account for the broader time resolution in data than in MC
1593-
if (cellEnergy < minLeaderEnergy) // Cells with tless than 300 MeV cannot be the leading cell in the cluster, so their time does not require precise calibration
1596+
if (cellEnergy < minLeaderEnergy) { // Cells with tless than 300 MeV cannot be the leading cell in the cluster, so their time does not require precise calibration
15941597
timesmear = 0.; // They will therefore not be smeared and only get their shift
1595-
else if (cellType == emcal::ChannelType_t::HIGH_GAIN) // High gain cells -> Low energies
1598+
} else if (cellType == emcal::ChannelType_t::HIGH_GAIN) { // High gain cells -> Low energies
15961599
timesmear = normalgaus(rdgen) * (1.6 + 9.5 * std::exp(-3. * cellEnergy)); // Parameters extracted from LHC24f3b & LHC22o (pp), but also usable for other periods
1597-
else if (cellType == emcal::ChannelType_t::LOW_GAIN) // Low gain cells -> High energies
1600+
} else if (cellType == emcal::ChannelType_t::LOW_GAIN) { // Low gain cells -> High energies
15981601
timesmear = normalgaus(rdgen) * (5.0); // Parameters extracted from LHC24g4 & LHC24aj (pp), but also usable for other periods
1599-
1602+
}
16001603
} else { // ---> Data
16011604
if (cellEnergy < minLeaderEnergy) { // Cells with tless than 300 MeV cannot be the leading cell in the cluster, so their time does not require precise calibration
16021605
timeshift = 0.; // In data they will not be shifted (they are close to 0 anyways)
16031606
} else if (cellType == emcal::ChannelType_t::HIGH_GAIN) { // High gain cells -> Low energies
1604-
if (cellEnergy < lowEnergyRegime) // Low energy regime
1607+
if (cellEnergy < lowEnergyRegime) { // Low energy regime
16051608
timeshift = 0.8 * std::log(2.7 * cellEnergy); // Parameters extracted from LHC22o (pp), but also usable for other periods
1606-
else // Medium energy regime
1609+
} else { // Medium energy regime
16071610
timeshift = 1.5 * std::log(0.9 * cellEnergy); // Parameters extracted from LHC22o (pp), but also usable for other periods
1608-
} else if (cellType == emcal::ChannelType_t::LOW_GAIN) { // Low gain cells -> High energies
1609-
if (cellEnergy < highEnergyRegime) // High energy regime
1610-
timeshift = 1.9 * std::log(0.09 * cellEnergy); // Parameters extracted from LHC24aj (pp), but also usable for other periods
1611-
else // Very high energy regime
1612-
timeshift = 1.9; // Parameters extracted from LHC24aj (pp), but also usable for other periods
1611+
}
1612+
} else if (cellType == emcal::ChannelType_t::LOW_GAIN) { // Low gain cells -> High energies
1613+
if (cellEnergy < highEnergyRegime) { // High energy regime
1614+
timeshift = 1.9 * std::log(0.09 * cellEnergy); // Parameters extracted from LHC24aj (pp), but also usable for other periods
1615+
} else { // Very high energy regime
1616+
timeshift = 1.9; // Parameters extracted from LHC24aj (pp), but also usable for other periods
1617+
}
16131618
}
16141619
// Temporary extra shift for bug in time calibraiton of apass4 Pb-Pb 2024, requires pos shift of 2*8.8 ns for low gain cells
16151620
if (cellType == emcal::ChannelType_t::LOW_GAIN) {
@@ -1628,17 +1633,17 @@ struct EmcalCorrectionTask {
16281633
{
16291634
auto& ccdbMgr = o2::ccdb::BasicCCDBManager::instance();
16301635
uint64_t tsOld = 1634853602000; // timestamp corresponding to LHC22o old gain calib object
1631-
o2::emcal::GainCalibrationFactors* paramsOld = ccdbMgr.getForTimeStamp<o2::emcal::GainCalibrationFactors>("EMC/Calib/GainCalibFactors", tsOld);
1636+
auto* paramsOld = ccdbMgr.getForTimeStamp<o2::emcal::GainCalibrationFactors>("EMC/Calib/GainCalibFactors", tsOld);
16321637
uint64_t tsNew = 1734853602000; // timestamp corresponding to new gain calib object (new cell compression)
1633-
o2::emcal::GainCalibrationFactors* paramsNew = ccdbMgr.getForTimeStamp<o2::emcal::GainCalibrationFactors>("EMC/Calib/GainCalibFactors", tsNew);
1634-
for (uint16_t i = 0; i < mArrGainCalibDiff.size(); ++i) {
1638+
auto* paramsNew = ccdbMgr.getForTimeStamp<o2::emcal::GainCalibrationFactors>("EMC/Calib/GainCalibFactors", tsNew);
1639+
for (uint32_t i = 0; i < mArrGainCalibDiff.size(); ++i) {
16351640
mArrGainCalibDiff[i] = paramsNew->getGainCalibFactors(i) == 0 ? 1. : paramsOld->getGainCalibFactors(i) / paramsNew->getGainCalibFactors(i);
16361641
}
16371642
}
16381643
};
16391644

1640-
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
1645+
WorkflowSpec defineDataProcessing(ConfigContext const& context)
16411646
{
16421647
return WorkflowSpec{
1643-
adaptAnalysisTask<EmcalCorrectionTask>(cfgc)};
1648+
adaptAnalysisTask<EmcalCorrectionTask>(context)};
16441649
}

0 commit comments

Comments
 (0)