Select which slice(s) to use.
29 unsigned int sliceCounter{0};
36 for (
const CaloHitList &sliceHits : inputSliceVector)
38 CaloHitList localHitList{};
40 for (
const CaloHit *
const pSliceCaloHit : sliceHits)
41 localHitList.push_back(static_cast<const CaloHit *>(pSliceCaloHit->GetParentAddress()));
43 for (
const CaloHit *
const pCaloHit : localHitList)
45 float thisTargetParticleWeight{0.f}, thisTotalWeight{0.f};
46 const MCParticleWeightMap &hitMCParticleWeightMap(pCaloHit->GetMCParticleWeightMap());
48 if (hitMCParticleWeightMap.empty())
51 MCParticleList mcParticleList;
52 for (
const auto &mapEntry : hitMCParticleWeightMap)
53 mcParticleList.push_back(mapEntry.first);
56 for (
const MCParticle *
const pMCParticle : mcParticleList)
58 const float weight{hitMCParticleWeightMap.at(pMCParticle)};
61 if (this->
IsTarget(pParentMCParticle))
62 thisTargetParticleWeight +=
weight;
68 if (thisTotalWeight > std::numeric_limits<float>::epsilon())
70 thisTargetParticleWeight *= 1.f / thisTotalWeight;
71 thisTotalWeight = 1.f;
75 thisTargetParticleWeight = 0.f;
76 thisTotalWeight = 0.f;
78 targetWeights[sliceCounter] += thisTargetParticleWeight;
79 otherWeights[sliceCounter] += (1. - thisTargetParticleWeight);
85 float totalTargetWeight{0.f};
86 for (
const float weight : targetWeights)
87 totalTargetWeight +=
weight;
90 for (
unsigned int i = 0; i < targetWeights.size(); ++i)
92 const float sliceWeight = targetWeights[i] + otherWeights[i];
93 const float completeness{totalTargetWeight > std::numeric_limits<float>::epsilon() ? targetWeights[i] / totalTargetWeight : 0.f};
94 const float purity{sliceWeight > std::numeric_limits<float>::epsilon() ? targetWeights[i] / sliceWeight : 0.f};
99 reducedSliceVarIndexMap.emplace(completeness, i);
104 reducedSliceVarIndexMap.emplace(purity, i);
108 std::vector<int> reducedSliceIndices{};
110 for (
const auto [cutVariable,
index] : reducedSliceVarIndexMap)
113 reducedSliceIndices.push_back(
index);
114 outputSliceVector.push_back(inputSliceVector[
index]);
std::string m_cutVariable
The variable to cut on ("purity" or "completeness") - default "completeness".
int m_maxSlices
The maximum number of slices to retain (0 to retain all) - default 0.
std::map< float, int, std::greater< float > > MetricSliceIndexMap
static bool SortByMomentum(const pandora::MCParticle *const pLhs, const pandora::MCParticle *const pRhs)
Sort mc particles by their momentum.
float m_threshold
The minimum cut threshold to retain a slice (< 0 for no threshold) - default -1.
static const pandora::MCParticle * GetParentMCParticle(const pandora::MCParticle *const pMCParticle)
Get the parent mc particle.
virtual bool IsTarget(const pandora::MCParticle *const mcParticle) const =0
Template method to determine if an MC particle matches the target criteria for slice selection...
Dft::FloatVector FloatVector