Skip to content

Commit 5a7653e

Browse files
authored
[PWGJE,EMCAL-670] emcalCorrectionTask: remove std::optional function … (#11303)
1 parent 4713a7e commit 5a7653e

File tree

1 file changed

+33
-21
lines changed

1 file changed

+33
-21
lines changed

PWGJE/TableProducer/emcalCorrectionTask.cxx

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ struct EmcalCorrectionTask {
342342

343343
// Store the clusters in the table where a matching collision could
344344
// be identified.
345-
fillClusterTable<CollEventSels::filtered_iterator>(col, vertexPos, iClusterizer, cellIndicesBC, indexMapPair, trackGlobalIndex);
345+
fillClusterTable<CollEventSels::filtered_iterator>(col, vertexPos, iClusterizer, cellIndicesBC, &indexMapPair, &trackGlobalIndex);
346346
} else {
347347
mHistManager.fill(HIST("hBCMatchErrors"), 2);
348348
}
@@ -470,7 +470,7 @@ struct EmcalCorrectionTask {
470470

471471
// Store the clusters in the table where a matching collision could
472472
// be identified.
473-
fillClusterTable<CollEventSels::filtered_iterator>(col, vertexPos, iClusterizer, cellIndicesBC, indexMapPair, trackGlobalIndex);
473+
fillClusterTable<CollEventSels::filtered_iterator>(col, vertexPos, iClusterizer, cellIndicesBC, &indexMapPair, &trackGlobalIndex);
474474
} else {
475475
mHistManager.fill(HIST("hBCMatchErrors"), 2);
476476
}
@@ -598,7 +598,7 @@ struct EmcalCorrectionTask {
598598
}
599599
PROCESS_SWITCH(EmcalCorrectionTask, processStandalone, "run stand alone analysis", false);
600600

601-
void cellsToCluster(size_t iClusterizer, const gsl::span<o2::emcal::Cell> cellsBC, std::optional<const gsl::span<o2::emcal::CellLabel>> cellLabels = std::nullopt)
601+
void cellsToCluster(size_t iClusterizer, const gsl::span<o2::emcal::Cell> cellsBC, gsl::span<const o2::emcal::CellLabel> cellLabels = {})
602602
{
603603
mClusterizers.at(iClusterizer)->findClusters(cellsBC);
604604

@@ -614,10 +614,10 @@ struct EmcalCorrectionTask {
614614
mClusterFactories.reset();
615615
// in preparation for future O2 changes
616616
// mClusterFactories.setClusterizerSettings(mClusterDefinitions.at(iClusterizer).minCellEnergy, mClusterDefinitions.at(iClusterizer).timeMin, mClusterDefinitions.at(iClusterizer).timeMax, mClusterDefinitions.at(iClusterizer).recalcShowerShape5x5);
617-
if (cellLabels) {
618-
mClusterFactories.setContainer(*emcalClusters, cellsBC, *emcalClustersInputIndices, cellLabels);
619-
} else {
617+
if (cellLabels.empty()) {
620618
mClusterFactories.setContainer(*emcalClusters, cellsBC, *emcalClustersInputIndices);
619+
} else {
620+
mClusterFactories.setContainer(*emcalClusters, cellsBC, *emcalClustersInputIndices, cellLabels);
621621
}
622622

623623
LOG(debug) << "Cluster factory set up.";
@@ -634,24 +634,33 @@ struct EmcalCorrectionTask {
634634
}
635635

636636
template <typename Collision>
637-
void fillClusterTable(Collision const& col, math_utils::Point3D<float> const& vertexPos, size_t iClusterizer, const gsl::span<int64_t> cellIndicesBC, std::optional<std::tuple<std::vector<std::vector<int>>, std::vector<std::vector<int>>>> const& indexMapPair = std::nullopt, std::optional<std::vector<int64_t>> const& trackGlobalIndex = std::nullopt)
637+
void fillClusterTable(Collision const& col, math_utils::Point3D<float> const& vertexPos, size_t iClusterizer, const gsl::span<int64_t> cellIndicesBC, const std::tuple<std::vector<std::vector<int>>, std::vector<std::vector<int>>>* indexMapPair = nullptr, const std::vector<int64_t>* trackGlobalIndex = nullptr)
638638
{
639+
// average number of cells per cluster, only used the reseve a reasonable amount for the clustercells table
640+
const size_t NAvgNcells = 3;
639641
// we found a collision, put the clusters into the none ambiguous table
640642
clusters.reserve(mAnalysisClusters.size());
641-
if (mClusterLabels.size() > 0) {
643+
if (!mClusterLabels.empty()) {
642644
mcclusters.reserve(mClusterLabels.size());
643645
}
646+
clustercells.reserve(mAnalysisClusters.size() * NAvgNcells);
647+
648+
// get the clusterType once
649+
const auto clusterType = static_cast<int>(mClusterDefinitions[iClusterizer]);
650+
644651
int cellindex = -1;
645652
unsigned int iCluster = 0;
653+
float energy = 0.f;
646654
for (const auto& cluster : mAnalysisClusters) {
655+
energy = cluster.E();
647656
// Determine the cluster eta, phi, correcting for the vertex position.
648657
auto pos = cluster.getGlobalPosition();
649658
pos = pos - vertexPos;
650659
// Normalize the vector and rescale by energy.
651-
pos *= (cluster.E() / std::sqrt(pos.Mag2()));
660+
pos *= (energy / std::sqrt(pos.Mag2()));
652661

653662
// Correct for nonlinear behaviour
654-
float nonlinCorrEnergy = cluster.E();
663+
float nonlinCorrEnergy = energy;
655664
if (!disableNonLin) {
656665
try {
657666
nonlinCorrEnergy = mNonlinearityHandler.getCorrectedClusterEnergy(cluster);
@@ -662,27 +671,26 @@ struct EmcalCorrectionTask {
662671

663672
// save to table
664673
LOG(debug) << "Writing cluster definition "
665-
<< static_cast<int>(mClusterDefinitions.at(iClusterizer))
674+
<< clusterType
666675
<< " to table.";
667676
mHistManager.fill(HIST("hClusterType"), 1);
668-
clusters(col, cluster.getID(), nonlinCorrEnergy, cluster.getCoreEnergy(), cluster.E(),
677+
clusters(col, cluster.getID(), nonlinCorrEnergy, cluster.getCoreEnergy(), energy,
669678
pos.Eta(), TVector2::Phi_0_2pi(pos.Phi()), cluster.getM02(),
670679
cluster.getM20(), cluster.getNCells(),
671680
cluster.getClusterTime(), cluster.getIsExotic(),
672681
cluster.getDistanceToBadChannel(), cluster.getNExMax(),
673-
static_cast<int>(mClusterDefinitions.at(iClusterizer)));
674-
if (mClusterLabels.size() > 0) {
682+
clusterType);
683+
if (!mClusterLabels.empty()) {
675684
mcclusters(mClusterLabels[iCluster].getLabels(), mClusterLabels[iCluster].getEnergyFractions());
676685
}
677-
clustercells.reserve(cluster.getNCells());
678686
// loop over cells in cluster and save to table
679687
for (int ncell = 0; ncell < cluster.getNCells(); ncell++) {
680688
cellindex = cluster.getCellIndex(ncell);
681689
LOG(debug) << "trying to find cell index " << cellindex << " in map";
682690
clustercells(clusters.lastIndex(), cellIndicesBC[cellindex]);
683691
} // end of cells of cluser loop
684692
// fill histograms
685-
mHistManager.fill(HIST("hClusterE"), cluster.E());
693+
mHistManager.fill(HIST("hClusterE"), energy);
686694
mHistManager.fill(HIST("hClusterNLM"), cluster.getNExMax());
687695
mHistManager.fill(HIST("hClusterTime"), cluster.getClusterTime());
688696
mHistManager.fill(HIST("hClusterEtaPhi"), pos.Eta(), TVector2::Phi_0_2pi(pos.Phi()));
@@ -701,20 +709,25 @@ struct EmcalCorrectionTask {
701709
template <typename BC>
702710
void fillAmbigousClusterTable(BC const& bc, size_t iClusterizer, const gsl::span<int64_t> cellIndicesBC, bool hasCollision)
703711
{
712+
// average number of cells per cluster, only used the reseve a reasonable amount for the clustercells table
713+
const size_t NAvgNcells = 3;
704714
int cellindex = -1;
705715
clustersAmbiguous.reserve(mAnalysisClusters.size());
706716
if (mClusterLabels.size() > 0) {
707717
mcclustersAmbiguous.reserve(mClusterLabels.size());
708718
}
719+
clustercellsambiguous.reserve(mAnalysisClusters.size() * NAvgNcells);
709720
unsigned int iCluster = 0;
721+
float energy = 0.f;
710722
for (const auto& cluster : mAnalysisClusters) {
723+
energy = cluster.E();
711724
auto pos = cluster.getGlobalPosition();
712725
pos = pos - math_utils::Point3D<float>{0., 0., 0.};
713726
// Normalize the vector and rescale by energy.
714-
pos *= (cluster.E() / std::sqrt(pos.Mag2()));
727+
pos *= (energy / std::sqrt(pos.Mag2()));
715728

716729
// Correct for nonlinear behaviour
717-
float nonlinCorrEnergy = cluster.E();
730+
float nonlinCorrEnergy = energy;
718731
try {
719732
nonlinCorrEnergy = mNonlinearityHandler.getCorrectedClusterEnergy(cluster);
720733
} catch (o2::emcal::NonlinearityHandler::UninitException& e) {
@@ -723,22 +736,21 @@ struct EmcalCorrectionTask {
723736

724737
// We have our necessary properties. Now we store outputs
725738

726-
// LOG(debug) << "Cluster E: " << cluster.E();
739+
// LOG(debug) << "Cluster E: " << energy;
727740
if (!hasCollision) {
728741
mHistManager.fill(HIST("hClusterType"), 0);
729742
} else {
730743
mHistManager.fill(HIST("hClusterType"), 2);
731744
}
732745
clustersAmbiguous(
733-
bc, cluster.getID(), nonlinCorrEnergy, cluster.getCoreEnergy(), cluster.E(),
746+
bc, cluster.getID(), nonlinCorrEnergy, cluster.getCoreEnergy(), energy,
734747
pos.Eta(), TVector2::Phi_0_2pi(pos.Phi()), cluster.getM02(),
735748
cluster.getM20(), cluster.getNCells(), cluster.getClusterTime(),
736749
cluster.getIsExotic(), cluster.getDistanceToBadChannel(),
737750
cluster.getNExMax(), static_cast<int>(mClusterDefinitions.at(iClusterizer)));
738751
if (mClusterLabels.size() > 0) {
739752
mcclustersAmbiguous(mClusterLabels[iCluster].getLabels(), mClusterLabels[iCluster].getEnergyFractions());
740753
}
741-
clustercellsambiguous.reserve(cluster.getNCells());
742754
for (int ncell = 0; ncell < cluster.getNCells(); ncell++) {
743755
cellindex = cluster.getCellIndex(ncell);
744756
clustercellsambiguous(clustersAmbiguous.lastIndex(),

0 commit comments

Comments
 (0)