-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EMCAL-688] Inclusion of EMCal Cell and Cluster labels (#12660)
- Add CellLabel class to handle the pairs of MC particle IDs and amplitdue fraction on cell level which the ClusterFactory now uses as a new container inside the `buildCluster` function. For this function an additional argument was added, more info next bullet. - Add ClusterLabel class to handel the paris of MC particle IDs and amplitude fraction on cluster level. They get filled inside the `buildCluster` function of the cluster factory where a point to an object of ClusterLabel is now an optional 2nd argument to the function. If one pointer is give, the ClusterLabel is filled with the labels and amplitude fractions and orderer inside the ClusterFactory.
- Loading branch information
1 parent
0667094
commit 4d5481e
Showing
8 changed files
with
292 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
DataFormats/Detectors/EMCAL/include/DataFormatsEMCAL/CellLabel.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2019-2020 CERN and copyright holders of ALICE O2. | ||
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. | ||
// All rights not expressly granted are reserved. | ||
// | ||
// This software is distributed under the terms of the GNU General Public | ||
// License v3 (GPL Version 3), copied verbatim in the file "COPYING". | ||
// | ||
// In applying this license CERN does not waive the privileges and immunities | ||
// granted to it by virtue of its status as an Intergovernmental Organization | ||
// or submit itself to any jurisdiction. | ||
|
||
#ifndef ALICEO2_EMCAL_CELLLABEL_H_ | ||
#define ALICEO2_EMCAL_CELLLABEL_H_ | ||
|
||
#include <fairlogger/Logger.h> | ||
#include <gsl/span> | ||
#include <vector> | ||
#include "Rtypes.h" | ||
|
||
namespace o2 | ||
{ | ||
|
||
namespace emcal | ||
{ | ||
|
||
/// \class CellLabel | ||
/// \brief cell class for MC particle IDs and their respective amplitude fraction | ||
/// \ingroup EMCALDataFormat | ||
/// \author Marvin Hemmer <[email protected]>, Goethe university Frankfurt | ||
/// \since December 13, 2023 | ||
/// | ||
|
||
class CellLabel | ||
{ | ||
public: | ||
// CellLabel() = default; | ||
|
||
/// \brief Constructor | ||
/// \param labels list of mc labels | ||
/// \param amplitudeFractions list of amplitude fractions | ||
CellLabel(const gsl::span<const int> labels, const gsl::span<const float> amplitudeFractions); | ||
|
||
// ~CellLabel() = default; | ||
// CellLabel(const CellLabel& clus) = default; | ||
// CellLabel& operator=(const CellLabel& source) = default; | ||
|
||
/// \brief Getter of label size | ||
/// \param index index which label to get | ||
size_t GetLabelSize(void) const { return mLabels.size(); } | ||
|
||
/// \brief Getter for label | ||
/// \param index index which label to get | ||
int32_t GetLabel(size_t index) const { return mLabels[index]; } | ||
|
||
/// \brief Getter for amplitude fraction | ||
/// \param index index which amplitude fraction to get | ||
float GetAmplitudeFraction(size_t index) const { return mAmplitudeFraction[index]; } | ||
|
||
protected: | ||
gsl::span<const int32_t> mLabels; ///< List of MC particles that generated the cluster, ordered in deposited energy. | ||
gsl::span<const float> mAmplitudeFraction; ///< List of the fraction of the cell energy coming from a MC particle. Index aligns with mLabels! | ||
}; | ||
|
||
} // namespace emcal | ||
} // namespace o2 | ||
#endif // ALICEO2_EMCAL_CELLLABEL_H_ |
95 changes: 95 additions & 0 deletions
95
DataFormats/Detectors/EMCAL/include/DataFormatsEMCAL/ClusterLabel.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright 2019-2020 CERN and copyright holders of ALICE O2. | ||
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. | ||
// All rights not expressly granted are reserved. | ||
// | ||
// This software is distributed under the terms of the GNU General Public | ||
// License v3 (GPL Version 3), copied verbatim in the file "COPYING". | ||
// | ||
// In applying this license CERN does not waive the privileges and immunities | ||
// granted to it by virtue of its status as an Intergovernmental Organization | ||
// or submit itself to any jurisdiction. | ||
|
||
#ifndef ALICEO2_EMCAL_CLUSTERLABEL_H_ | ||
#define ALICEO2_EMCAL_CLUSTERLABEL_H_ | ||
|
||
#include <fairlogger/Logger.h> | ||
#include <gsl/span> | ||
#include <vector> | ||
#include "Rtypes.h" | ||
|
||
namespace o2 | ||
{ | ||
|
||
namespace emcal | ||
{ | ||
|
||
/// \class ClusterLabel | ||
/// \brief cluster class for MC particle IDs and their respective energy fraction | ||
/// \ingroup EMCALDataFormat | ||
/// \author Marvin Hemmer <[email protected]>, Goethe university Frankfurt | ||
/// \since December 13, 2023 | ||
/// | ||
|
||
class ClusterLabel | ||
{ | ||
public: | ||
/// \struct labelWithE | ||
/// \brief Wrapper structure to make cluster label sortable in energy fraction | ||
struct labelWithE { | ||
|
||
/// \brief Constructor | ||
labelWithE() : energyFraction(0.), label(0) {} | ||
|
||
/// \brief Constructor | ||
/// \param e Energy fraction | ||
/// \param l MC label | ||
labelWithE(float e, int l) : energyFraction(e), label(l) {} | ||
|
||
/// \brief Comparison lower operator comparing cells based on energy | ||
/// | ||
/// std::sort will require operator>= to compile. | ||
/// | ||
/// \param rhs Label to compare to | ||
/// \return True if this cell is has a lower energy, false otherwise | ||
bool operator>=(labelWithE const& rhs) const | ||
{ | ||
return energyFraction >= rhs.energyFraction; | ||
} | ||
|
||
float energyFraction; ///< Energy Fraction | ||
int label; ///< MC label | ||
}; | ||
|
||
// ClusterLabel() = default; | ||
// ~ClusterLabel() = default; | ||
// ClusterLabel(const ClusterLabel& clus) = default; | ||
// ClusterLabel& operator=(const ClusterLabel& source) = default; | ||
|
||
/// \brief Clear the member variables | ||
void clear(); | ||
|
||
/// \brief Add label and energy fraction to the | ||
/// \param label MC label | ||
/// \param energyFraction Energy fraction | ||
void addValue(int label, float energyFraction); | ||
|
||
/// \brief Normalize the energy fraction | ||
/// \param factor normalization factor | ||
void normalize(float factor); | ||
|
||
/// \brief Getter for vector of labels | ||
std::vector<int32_t> getLabels(); | ||
|
||
/// \brief Getter for vector of energy fractions | ||
std::vector<float> getEnergyFractions(); | ||
|
||
/// \brief Sort the labels and energy fraction in descending order (largest energy fraction to smallest) | ||
void orderLabels(); | ||
|
||
protected: | ||
std::vector<labelWithE> mClusterLabels; ///< List of MC particles that generated the cluster, paired with energy fraction | ||
}; | ||
|
||
} // namespace emcal | ||
} // namespace o2 | ||
#endif // ALICEO2_EMCAL_CLUSTERLABEL_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2019-2020 CERN and copyright holders of ALICE O2. | ||
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. | ||
// All rights not expressly granted are reserved. | ||
// | ||
// This software is distributed under the terms of the GNU General Public | ||
// License v3 (GPL Version 3), copied verbatim in the file "COPYING". | ||
// | ||
// In applying this license CERN does not waive the privileges and immunities | ||
// granted to it by virtue of its status as an Intergovernmental Organization | ||
// or submit itself to any jurisdiction. | ||
|
||
/// \file CellLabel.cxx | ||
|
||
#include "DataFormatsEMCAL/CellLabel.h" | ||
|
||
using namespace o2::emcal; | ||
|
||
CellLabel::CellLabel(const gsl::span<const int> labels, const gsl::span<const float> amplitudeFractions) : mLabels(labels), mAmplitudeFraction(amplitudeFractions) | ||
{ | ||
if (labels.size() != amplitudeFractions.size()) { | ||
LOG(error) << "Size of labels " << labels.size() << " does not match size of amplitude fraction " << amplitudeFractions.size() << " !"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2019-2020 CERN and copyright holders of ALICE O2. | ||
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. | ||
// All rights not expressly granted are reserved. | ||
// | ||
// This software is distributed under the terms of the GNU General Public | ||
// License v3 (GPL Version 3), copied verbatim in the file "COPYING". | ||
// | ||
// In applying this license CERN does not waive the privileges and immunities | ||
// granted to it by virtue of its status as an Intergovernmental Organization | ||
// or submit itself to any jurisdiction. | ||
|
||
/// \file ClusterLabel.cxx | ||
|
||
#include "DataFormatsEMCAL/ClusterLabel.h" | ||
|
||
using namespace o2::emcal; | ||
|
||
//_______________________________________________________________________ | ||
void ClusterLabel::clear() | ||
{ | ||
mClusterLabels.clear(); | ||
} | ||
|
||
//_______________________________________________________________________ | ||
void ClusterLabel::addValue(int label, float energyFraction) | ||
{ | ||
auto it = std::find_if(mClusterLabels.begin(), mClusterLabels.end(), | ||
[label](const labelWithE& lWE) { return lWE.label == label; }); | ||
|
||
if (it != mClusterLabels.end()) { | ||
// label already exists, accumulate energy fraction | ||
it->energyFraction += energyFraction; | ||
} else { | ||
// label does not exist, add new energy fraction | ||
mClusterLabels.emplace_back(label, energyFraction); | ||
} | ||
} | ||
|
||
//_______________________________________________________________________ | ||
void ClusterLabel::normalize(float factor) | ||
{ | ||
for (auto& clusterlabel : mClusterLabels) { | ||
clusterlabel.energyFraction = clusterlabel.energyFraction / factor; | ||
} | ||
} | ||
|
||
//_______________________________________________________________________ | ||
std::vector<int32_t> ClusterLabel::getLabels() | ||
{ | ||
std::vector<int32_t> vLabels; | ||
vLabels.reserve(mClusterLabels.size()); | ||
for (auto& clusterlabel : mClusterLabels) { | ||
vLabels.push_back(clusterlabel.label); | ||
} | ||
return vLabels; | ||
} | ||
|
||
//_______________________________________________________________________ | ||
std::vector<float> ClusterLabel::getEnergyFractions() | ||
{ | ||
std::vector<float> vEnergyFractions; | ||
vEnergyFractions.reserve(mClusterLabels.size()); | ||
for (auto& clusterlabel : mClusterLabels) { | ||
vEnergyFractions.push_back(clusterlabel.energyFraction); | ||
} | ||
return vEnergyFractions; | ||
} | ||
|
||
//_______________________________________________________________________ | ||
void ClusterLabel::orderLabels() | ||
{ | ||
// Sort the pairs based on values in descending order | ||
std::sort(mClusterLabels.begin(), mClusterLabels.end(), | ||
[](const labelWithE& a, const labelWithE& b) { return a.label >= b.label; }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters