9 #include "Pandora/AlgorithmHeaders.h" 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]);
124 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"MaxSlices",
m_maxSlices));
125 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"Threshold",
m_threshold));
127 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"CutVariable",
m_cutVariable));
131 std::cout <<
"CheatingSliceSelectionTool::ReadSettings: Unknown cut variable \'" <<
m_cutVariable <<
"\'" <<
std::endl;
132 return STATUS_CODE_INVALID_PARAMETER;
135 return STATUS_CODE_SUCCESS;
void SelectSlices(const pandora::Algorithm *const pAlgorithm, const SliceVector &inputSliceVector, SliceVector &outputSliceVector)
Select which slice(s) to use.
std::string m_cutVariable
The variable to cut on ("purity" or "completeness") - default "completeness".
std::vector< pandora::CaloHitList > SliceVector
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.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Header file for the lar monte carlo particle helper helper class.
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
QTextStream & endl(QTextStream &s)