29 unsigned int sliceCounter{0};
36 for (
const CaloHitList &sliceHits : inputSliceVector)
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};
48 if (hitMCParticleWeightMap.empty())
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;
64 thisTotalWeight += 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]);
131 std::cout <<
"CheatingSliceSelectionTool::ReadSettings: Unknown cut variable \'" <<
m_cutVariable <<
"\'" << std::endl;
132 return STATUS_CODE_INVALID_PARAMETER;
135 return STATUS_CODE_SUCCESS;
Header file for the lar monte carlo particle helper helper class.
static bool SortByMomentum(const pandora::MCParticle *const pLhs, const pandora::MCParticle *const pRhs)
Sort mc particles by their momentum.
static const pandora::MCParticle * GetParentMCParticle(const pandora::MCParticle *const pMCParticle)
Get the parent mc particle.
std::vector< pandora::CaloHitList > SliceVector