Skip to content

Commit 94f1295

Browse files
committed
[PWGJE] Clean up EMCALClusters header and add getClusterDefinitionFromString function
- Add Default value for `algorithm` of `EMCALClusterDefinition` - Update constructor with member initilizer - Add new function `getClusterDefinitionFromID` to obtain the cluster definition via the storage ID - Change function `getClusterDefinitionFromString` to use an `unordered_map<std::string,int>` instead of multiple if statements with string comparison - Rename `ClusterAlgorithm_t` to `ClusterAlgorithm` to fit naming conventions - Return type of both functions to get the ClusterDefinition is now `const EMCALClusterDefinition&`, was `const EMCALClusterDefinition` before (not a reference but a copy) - Add `inline` to the different `EMCALClusterDefinition` definitions to ensure they are only in memory ONCE and not per file that includes them.
1 parent c598d12 commit 94f1295

2 files changed

Lines changed: 113 additions & 87 deletions

File tree

PWGJE/DataModel/EMCALClusterDefinition.h

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,22 @@
1616
#ifndef PWGJE_DATAMODEL_EMCALCLUSTERDEFINITION_H_
1717
#define PWGJE_DATAMODEL_EMCALCLUSTERDEFINITION_H_
1818

19+
#include <cstdint>
1920
#include <string>
2021
#include <utility>
2122

2223
namespace o2::aod
2324
{
24-
enum class ClusterAlgorithm_t {
25-
kV1,
25+
enum class ClusterAlgorithm : uint8_t {
26+
kV1 = 0,
2627
kV3
2728
};
2829
/// \struct EMCALClusterDefinition
2930
/// \brief struct for the cluster definition, i.e. what is considered a cluster by the clusterizer.
3031
/// The cluster definition contains information about the used algorithm, seed threshold,
3132
/// cell energy, gradient as well as timing cut
3233
struct EMCALClusterDefinition {
33-
ClusterAlgorithm_t algorithm;
34+
ClusterAlgorithm algorithm{ClusterAlgorithm::kV3};
3435
int storageID = -1; // integer ID used to store cluster definition in a flat table
3536
int selectedCellType = 1; // EMCal cell type (CURRENTLY NOT USED TO AVOID MULTIPLE CELL LOOPS)
3637
std::string name = "kUndefined"; // name of the cluster definition
@@ -46,23 +47,11 @@ struct EMCALClusterDefinition {
4647
// default constructor
4748
EMCALClusterDefinition() = default;
4849
// constructor
49-
EMCALClusterDefinition(ClusterAlgorithm_t pAlgorithm, int pStorageID, int pSelectedCellType, std::string pName, double pSeedEnergy, double pMinCellEnergy, double pTimeMin, double pTimeMax, double ptimeDiff, bool pDoGradientCut, double pGradientCut, bool precalcShowerShape5x5)
50+
EMCALClusterDefinition(ClusterAlgorithm pAlgorithm, int pStorageID, int pSelectedCellType, std::string pName, double pSeedEnergy, double pMinCellEnergy, double pTimeMin, double pTimeMax, double ptimeDiff, bool pDoGradientCut, double pGradientCut, bool precalcShowerShape5x5) : algorithm(pAlgorithm), storageID(pStorageID), selectedCellType(pSelectedCellType), name(std::move(pName)), seedEnergy(pSeedEnergy), minCellEnergy(pMinCellEnergy), timeMin(pTimeMin), timeMax(pTimeMax), timeDiff(ptimeDiff), doGradientCut(pDoGradientCut), gradientCut(pGradientCut), recalcShowerShape5x5(precalcShowerShape5x5)
5051
{
51-
algorithm = pAlgorithm;
52-
storageID = pStorageID;
53-
selectedCellType = pSelectedCellType;
54-
name = std::move(pName);
55-
seedEnergy = pSeedEnergy;
56-
minCellEnergy = pMinCellEnergy;
57-
timeMin = pTimeMin;
58-
timeMax = pTimeMax;
59-
timeDiff = ptimeDiff;
60-
doGradientCut = pDoGradientCut;
61-
gradientCut = pGradientCut;
62-
recalcShowerShape5x5 = precalcShowerShape5x5;
6352
}
6453

65-
// implement comparison operators for int std::string and ClusterAlgorithm_t
54+
// implement comparison operators for int std::string and ClusterAlgorithm
6655
bool operator==(const EMCALClusterDefinition& rhs) const
6756
{
6857
return (algorithm == rhs.algorithm && storageID == rhs.storageID && name == rhs.name && seedEnergy == rhs.seedEnergy && minCellEnergy == rhs.minCellEnergy && timeMin == rhs.timeMin && timeMax == rhs.timeMax && timeDiff == rhs.timeDiff && gradientCut == rhs.gradientCut && doGradientCut == rhs.doGradientCut && recalcShowerShape5x5 == rhs.recalcShowerShape5x5);
@@ -87,11 +76,11 @@ struct EMCALClusterDefinition {
8776
{
8877
return !(name == rhs);
8978
}
90-
bool operator==(const ClusterAlgorithm_t rhs) const
79+
bool operator==(const ClusterAlgorithm rhs) const
9180
{
9281
return (algorithm == rhs);
9382
}
94-
bool operator!=(const ClusterAlgorithm_t rhs) const
83+
bool operator!=(const ClusterAlgorithm rhs) const
9584
{
9685
return !(algorithm == rhs);
9786
}
@@ -107,11 +96,11 @@ struct EMCALClusterDefinition {
10796
return name;
10897
}
10998

110-
operator ClusterAlgorithm_t() const
99+
operator ClusterAlgorithm() const
111100
{
112101
return algorithm;
113102
}
114-
std::string toString() const
103+
[[nodiscard]] std::string toString() const
115104
{
116105
return name;
117106
}

PWGJE/DataModel/EMCALClusters.h

Lines changed: 103 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
/// \file EMCALClusters.h
1313
/// \brief Table definitions for EMCAL analysis clusters
14-
/// \author Raymond Ehlers <raymond.ehlers@cern.ch>, ORNL
14+
/// \author Raymond Ehlers <raymond.ehlers@cern.ch>, ORNL, Florian Jonas <florian.jonas@cern.ch>, Marvin Hemmer <marvin.hemmer@cern.ch>
1515

1616
#ifndef PWGJE_DATAMODEL_EMCALCLUSTERS_H_
1717
#define PWGJE_DATAMODEL_EMCALCLUSTERS_H_
@@ -23,6 +23,7 @@
2323

2424
#include <stdexcept>
2525
#include <string>
26+
#include <unordered_map>
2627
#include <vector>
2728

2829
namespace o2::aod
@@ -32,76 +33,112 @@ namespace emcalcluster
3233

3334
// define global cluster definitions
3435
// New definitions should be added here!
35-
const EMCALClusterDefinition kV3NoSplit(ClusterAlgorithm_t::kV3, 0, 1, "kV3NoSplit", 0.5, 0.1, -10000, 10000, 20000, false, 0., false);
36-
const EMCALClusterDefinition kV3NoSplitLowSeed(ClusterAlgorithm_t::kV3, 1, 1, "kV3NoSplitLowSeed", 0.3, 0.1, -10000, 10000, 20000, false, 0., false);
37-
const EMCALClusterDefinition kV3NoSplitLowerSeed(ClusterAlgorithm_t::kV3, 2, 1, "kV3NoSplitLowerSeed", 0.2, 0.1, -10000, 10000, 20000, false, 0., false);
38-
const EMCALClusterDefinition kV3Default(ClusterAlgorithm_t::kV3, 10, 1, "kV3Default", 0.5, 0.1, -10000, 10000, 20000, true, 0.03, false);
39-
const EMCALClusterDefinition kV3MostSplit(ClusterAlgorithm_t::kV3, 11, 1, "kV3MostSplit", 0.5, 0.1, -10000, 10000, 20000, true, 0., false);
40-
const EMCALClusterDefinition kV3LowSeed(ClusterAlgorithm_t::kV3, 12, 1, "kV3LowSeed", 0.3, 0.1, -10000, 10000, 20000, true, 0.03, false);
41-
const EMCALClusterDefinition kV3MostSplitLowSeed(ClusterAlgorithm_t::kV3, 13, 1, "kV3MostSplitLowSeed", 0.3, 0.1, -10000, 10000, 20000, true, 0., false);
42-
const EMCALClusterDefinition kV3StrictTime(ClusterAlgorithm_t::kV3, 20, 1, "kV3StrictTime", 0.5, 0.1, -500, 500, 20000, true, 0.03, false);
43-
const EMCALClusterDefinition kV3StricterTime(ClusterAlgorithm_t::kV3, 21, 1, "kV3StricterTime", 0.5, 0.1, -100, 100, 20000, true, 0.03, false);
44-
const EMCALClusterDefinition kV3MostStrictTime(ClusterAlgorithm_t::kV3, 22, 1, "kV3MostStrictTime", 0.5, 0.1, -50, 50, 20000, true, 0.03, false);
45-
const EMCALClusterDefinition kV3Default5x5(ClusterAlgorithm_t::kV3, 30, 1, "kV3Default5x5", 0.5, 0.1, -10000, 10000, 20000, true, 0.03, true);
46-
const EMCALClusterDefinition kV3SmallTimeDiff(ClusterAlgorithm_t::kV3, 40, 1, "kV3SmallTimeDiff", 0.5, 0.1, -10000, 10000, 500, true, 0.03, false);
47-
const EMCALClusterDefinition kV3SmallerTimeDiff(ClusterAlgorithm_t::kV3, 41, 1, "kV3SmallerTimeDiff", 0.5, 0.1, -10000, 10000, 100, true, 0.03, false);
48-
const EMCALClusterDefinition kV3SmallestTimeDiff(ClusterAlgorithm_t::kV3, 42, 1, "kV3SmallestTimeDiff", 0.5, 0.1, -10000, 10000, 50, true, 0.03, false);
49-
const EMCALClusterDefinition kV3MostSplitSmallTimeDiff(ClusterAlgorithm_t::kV3, 43, 1, "kV3MostSplitSmallTimeDiff", 0.5, 0.1, -10000, 10000, 500, true, 0., false);
50-
const EMCALClusterDefinition kV3MostSplitSmallerTimeDiff(ClusterAlgorithm_t::kV3, 44, 1, "kV3MostSplitSmallerTimeDiff", 0.5, 0.1, -10000, 10000, 100, true, 0., false);
51-
const EMCALClusterDefinition kV3MostSplitSmallestTimeDiff(ClusterAlgorithm_t::kV3, 45, 1, "kV3MostSplitSmallestTimeDiff", 0.5, 0.1, -10000, 10000, 50, true, 0., false);
52-
const EMCALClusterDefinition kV3MostSplitSmallestTimeDiffLowestSeed(ClusterAlgorithm_t::kV3, 50, 1, "kV3MostSplitSmallestTimeDiffLowestSeed", 0.1, 0.1, -10000, 10000, 50, true, 0., false);
53-
const EMCALClusterDefinition kV3MostSplitSmallestTimeDiffLowSeed(ClusterAlgorithm_t::kV3, 51, 1, "kV3MostSplitSmallestTimeDiffLowSeed", 0.3, 0.1, -10000, 10000, 50, true, 0., false);
54-
const EMCALClusterDefinition kV3MostSplitSmallestTimeDiffLowerSeed(ClusterAlgorithm_t::kV3, 52, 1, "kV3MostSplitSmallestTimeDiffLowerSeed", 0.2, 0.1, -10000, 10000, 50, true, 0., false);
36+
inline const EMCALClusterDefinition kV3NoSplit(ClusterAlgorithm::kV3, 0, 1, "kV3NoSplit", 0.5, 0.1, -10000, 10000, 20000, false, 0., false);
37+
inline const EMCALClusterDefinition kV3NoSplitLowSeed(ClusterAlgorithm::kV3, 1, 1, "kV3NoSplitLowSeed", 0.3, 0.1, -10000, 10000, 20000, false, 0., false);
38+
inline const EMCALClusterDefinition kV3NoSplitLowerSeed(ClusterAlgorithm::kV3, 2, 1, "kV3NoSplitLowerSeed", 0.2, 0.1, -10000, 10000, 20000, false, 0., false);
39+
inline const EMCALClusterDefinition kV3Default(ClusterAlgorithm::kV3, 10, 1, "kV3Default", 0.5, 0.1, -10000, 10000, 20000, true, 0.03, false);
40+
inline const EMCALClusterDefinition kV3MostSplit(ClusterAlgorithm::kV3, 11, 1, "kV3MostSplit", 0.5, 0.1, -10000, 10000, 20000, true, 0., false);
41+
inline const EMCALClusterDefinition kV3LowSeed(ClusterAlgorithm::kV3, 12, 1, "kV3LowSeed", 0.3, 0.1, -10000, 10000, 20000, true, 0.03, false);
42+
inline const EMCALClusterDefinition kV3MostSplitLowSeed(ClusterAlgorithm::kV3, 13, 1, "kV3MostSplitLowSeed", 0.3, 0.1, -10000, 10000, 20000, true, 0., false);
43+
inline const EMCALClusterDefinition kV3StrictTime(ClusterAlgorithm::kV3, 20, 1, "kV3StrictTime", 0.5, 0.1, -500, 500, 20000, true, 0.03, false);
44+
inline const EMCALClusterDefinition kV3StricterTime(ClusterAlgorithm::kV3, 21, 1, "kV3StricterTime", 0.5, 0.1, -100, 100, 20000, true, 0.03, false);
45+
inline const EMCALClusterDefinition kV3MostStrictTime(ClusterAlgorithm::kV3, 22, 1, "kV3MostStrictTime", 0.5, 0.1, -50, 50, 20000, true, 0.03, false);
46+
inline const EMCALClusterDefinition kV3Default5x5(ClusterAlgorithm::kV3, 30, 1, "kV3Default5x5", 0.5, 0.1, -10000, 10000, 20000, true, 0.03, true);
47+
inline const EMCALClusterDefinition kV3SmallTimeDiff(ClusterAlgorithm::kV3, 40, 1, "kV3SmallTimeDiff", 0.5, 0.1, -10000, 10000, 500, true, 0.03, false);
48+
inline const EMCALClusterDefinition kV3SmallerTimeDiff(ClusterAlgorithm::kV3, 41, 1, "kV3SmallerTimeDiff", 0.5, 0.1, -10000, 10000, 100, true, 0.03, false);
49+
inline const EMCALClusterDefinition kV3SmallestTimeDiff(ClusterAlgorithm::kV3, 42, 1, "kV3SmallestTimeDiff", 0.5, 0.1, -10000, 10000, 50, true, 0.03, false);
50+
inline const EMCALClusterDefinition kV3MostSplitSmallTimeDiff(ClusterAlgorithm::kV3, 43, 1, "kV3MostSplitSmallTimeDiff", 0.5, 0.1, -10000, 10000, 500, true, 0., false);
51+
inline const EMCALClusterDefinition kV3MostSplitSmallerTimeDiff(ClusterAlgorithm::kV3, 44, 1, "kV3MostSplitSmallerTimeDiff", 0.5, 0.1, -10000, 10000, 100, true, 0., false);
52+
inline const EMCALClusterDefinition kV3MostSplitSmallestTimeDiff(ClusterAlgorithm::kV3, 45, 1, "kV3MostSplitSmallestTimeDiff", 0.5, 0.1, -10000, 10000, 50, true, 0., false);
53+
inline const EMCALClusterDefinition kV3MostSplitSmallestTimeDiffLowestSeed(ClusterAlgorithm::kV3, 50, 1, "kV3MostSplitSmallestTimeDiffLowestSeed", 0.1, 0.1, -10000, 10000, 50, true, 0., false);
54+
inline const EMCALClusterDefinition kV3MostSplitSmallestTimeDiffLowSeed(ClusterAlgorithm::kV3, 51, 1, "kV3MostSplitSmallestTimeDiffLowSeed", 0.3, 0.1, -10000, 10000, 50, true, 0., false);
55+
inline const EMCALClusterDefinition kV3MostSplitSmallestTimeDiffLowerSeed(ClusterAlgorithm::kV3, 52, 1, "kV3MostSplitSmallestTimeDiffLowerSeed", 0.2, 0.1, -10000, 10000, 50, true, 0., false);
56+
57+
/// \brief function returns EMCALClusterDefinition for the given storage ID
58+
/// \param storageID storage ID of the cluster definition
59+
/// \return EMCALClusterDefinition for the given storage ID
60+
inline const EMCALClusterDefinition& getClusterDefinitionFromID(int storageID)
61+
{
62+
switch (storageID) {
63+
case 0:
64+
return kV3NoSplit;
65+
case 1:
66+
return kV3NoSplitLowSeed;
67+
case 2:
68+
return kV3NoSplitLowerSeed;
69+
case 10:
70+
return kV3Default;
71+
case 11:
72+
return kV3MostSplit;
73+
case 12:
74+
return kV3LowSeed;
75+
case 13:
76+
return kV3MostSplitLowSeed;
77+
case 20:
78+
return kV3StrictTime;
79+
case 21:
80+
return kV3StricterTime;
81+
case 22:
82+
return kV3MostStrictTime;
83+
case 30:
84+
return kV3Default5x5;
85+
case 40:
86+
return kV3SmallTimeDiff;
87+
case 41:
88+
return kV3SmallerTimeDiff;
89+
case 42:
90+
return kV3SmallestTimeDiff;
91+
case 43:
92+
return kV3MostSplitSmallTimeDiff;
93+
case 44:
94+
return kV3MostSplitSmallerTimeDiff;
95+
case 45:
96+
return kV3MostSplitSmallestTimeDiff;
97+
case 50:
98+
return kV3MostSplitSmallestTimeDiffLowestSeed;
99+
case 51:
100+
return kV3MostSplitSmallestTimeDiffLowSeed;
101+
case 52:
102+
return kV3MostSplitSmallestTimeDiffLowerSeed;
103+
default:
104+
throw std::invalid_argument("Cluster definition storageID not recognized: " + std::to_string(storageID));
105+
}
106+
}
55107

56108
/// \brief function returns EMCALClusterDefinition for the given name
57-
/// \param name name of the cluster definition
109+
/// \param clusterDefinitionName name of the cluster definition
58110
/// \return EMCALClusterDefinition for the given name
59-
inline const EMCALClusterDefinition getClusterDefinitionFromString(const std::string& clusterDefinitionName)
111+
inline const EMCALClusterDefinition& getClusterDefinitionFromString(const std::string& clusterDefinitionName)
60112
{
61-
if (clusterDefinitionName == "kV3NoSplit") {
62-
return kV3NoSplit;
63-
} else if (clusterDefinitionName == "kV3NoSplitLowSeed") {
64-
return kV3NoSplitLowSeed;
65-
} else if (clusterDefinitionName == "kV3NoSplitLowerSeed") {
66-
return kV3NoSplitLowerSeed;
67-
} else if (clusterDefinitionName == "kV3Default") {
68-
return kV3Default;
69-
} else if (clusterDefinitionName == "kV3MostSplit") {
70-
return kV3MostSplit;
71-
} else if (clusterDefinitionName == "kV3LowSeed") {
72-
return kV3LowSeed;
73-
} else if (clusterDefinitionName == "kV3MostSplitLowSeed") {
74-
return kV3MostSplitLowSeed;
75-
} else if (clusterDefinitionName == "kV3StrictTime") {
76-
return kV3StrictTime;
77-
} else if (clusterDefinitionName == "kV3StricterTime") {
78-
return kV3StricterTime;
79-
} else if (clusterDefinitionName == "kV3MostStrictTime") {
80-
return kV3MostStrictTime;
81-
} else if (clusterDefinitionName == "kV3Default5x5") {
82-
return kV3Default5x5;
83-
} else if (clusterDefinitionName == "kV3SmallTimeDiff") {
84-
return kV3SmallTimeDiff;
85-
} else if (clusterDefinitionName == "kV3SmallerTimeDiff") {
86-
return kV3SmallerTimeDiff;
87-
} else if (clusterDefinitionName == "kV3SmallestTimeDiff") {
88-
return kV3SmallestTimeDiff;
89-
} else if (clusterDefinitionName == "kV3MostSplitSmallTimeDiff") {
90-
return kV3MostSplitSmallTimeDiff;
91-
} else if (clusterDefinitionName == "kV3MostSplitSmallerTimeDiff") {
92-
return kV3MostSplitSmallerTimeDiff;
93-
} else if (clusterDefinitionName == "kV3MostSplitSmallestTimeDiff") {
94-
return kV3MostSplitSmallestTimeDiff;
95-
} else if (clusterDefinitionName == "kV3MostSplitSmallestTimeDiffLowestSeed") {
96-
return kV3MostSplitSmallestTimeDiffLowestSeed;
97-
} else if (clusterDefinitionName == "kV3MostSplitSmallestTimeDiffLowSeed") {
98-
return kV3MostSplitSmallestTimeDiffLowSeed;
99-
} else if (clusterDefinitionName == "kV3MostSplitSmallestTimeDiffLowerSeed") {
100-
return kV3MostSplitSmallestTimeDiffLowerSeed;
101-
} else {
102-
throw std::invalid_argument("Cluster definition name not recognized");
113+
static const std::unordered_map<std::string, int> nameToID = {
114+
{"kV3NoSplit", 0},
115+
{"kV3NoSplitLowSeed", 1},
116+
{"kV3NoSplitLowerSeed", 2},
117+
{"kV3Default", 10},
118+
{"kV3MostSplit", 11},
119+
{"kV3LowSeed", 12},
120+
{"kV3MostSplitLowSeed", 13},
121+
{"kV3StrictTime", 20},
122+
{"kV3StricterTime", 21},
123+
{"kV3MostStrictTime", 22},
124+
{"kV3Default5x5", 30},
125+
{"kV3SmallTimeDiff", 40},
126+
{"kV3SmallerTimeDiff", 41},
127+
{"kV3SmallestTimeDiff", 42},
128+
{"kV3MostSplitSmallTimeDiff", 43},
129+
{"kV3MostSplitSmallerTimeDiff", 44},
130+
{"kV3MostSplitSmallestTimeDiff", 45},
131+
{"kV3MostSplitSmallestTimeDiffLowestSeed", 50},
132+
{"kV3MostSplitSmallestTimeDiffLowSeed", 51},
133+
{"kV3MostSplitSmallestTimeDiffLowerSeed", 52},
134+
};
135+
136+
auto it = nameToID.find(clusterDefinitionName);
137+
if (it == nameToID.end()) {
138+
throw std::invalid_argument("Cluster definition name not recognized: " + clusterDefinitionName);
103139
}
104-
};
140+
return getClusterDefinitionFromID(it->second);
141+
}
105142

106143
DECLARE_SOA_INDEX_COLUMN(Collision, collision); //! collisionID used as index for matched clusters
107144
DECLARE_SOA_INDEX_COLUMN(BC, bc); //! bunch crossing ID used as index for ambiguous clusters

0 commit comments

Comments
 (0)