Project
Loading...
Searching...
No Matches
ClusterLabel.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13
15
16using namespace o2::emcal;
17
18//_______________________________________________________________________
20{
21 mClusterLabels.clear();
22}
23
24//_______________________________________________________________________
25void ClusterLabel::addValue(int label, float energyFraction)
26{
27 auto it = std::find_if(mClusterLabels.begin(), mClusterLabels.end(),
28 [label](const labelWithE& lWE) { return lWE.label == label; });
29
30 if (it != mClusterLabels.end()) {
31 // label already exists, accumulate energy fraction
32 it->energyFraction += energyFraction;
33 } else {
34 // label does not exist, add new energy fraction
35 mClusterLabels.emplace_back(label, energyFraction);
36 }
37}
38
39//_______________________________________________________________________
40void ClusterLabel::normalize(float factor)
41{
42 for (auto& clusterlabel : mClusterLabels) {
43 clusterlabel.energyFraction = clusterlabel.energyFraction / factor;
44 }
45}
46
47//_______________________________________________________________________
48std::vector<int32_t> ClusterLabel::getLabels()
49{
50 std::vector<int32_t> vLabels;
51 vLabels.reserve(mClusterLabels.size());
52 for (auto& clusterlabel : mClusterLabels) {
53 vLabels.push_back(clusterlabel.label);
54 }
55 return vLabels;
56}
57
58//_______________________________________________________________________
60{
61 std::vector<float> vEnergyFractions;
62 vEnergyFractions.reserve(mClusterLabels.size());
63 for (auto& clusterlabel : mClusterLabels) {
64 vEnergyFractions.push_back(clusterlabel.energyFraction);
65 }
66 return vEnergyFractions;
67}
68
69//_______________________________________________________________________
71{
72 // Sort the pairs based on values in descending order
73 std::sort(mClusterLabels.begin(), mClusterLabels.end(),
74 [](const labelWithE& a, const labelWithE& b) { return a.energyFraction > b.energyFraction; });
75}
void orderLabels()
Sort the labels and energy fraction in descending order (largest energy fraction to smallest)
void clear()
Clear the member variables.
void normalize(float factor)
Normalize the energy fraction.
void addValue(int label, float energyFraction)
Add label and energy fraction to the.
std::vector< labelWithE > mClusterLabels
List of MC particles that generated the cluster, paired with energy fraction.
std::vector< float > getEnergyFractions()
Getter for vector of energy fractions.
std::vector< int32_t > getLabels()
Getter for vector of labels.
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLuint GLsizei const GLchar * label
Definition glcorearb.h:2519
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
Wrapper structure to make cluster label sortable in energy fraction.