All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CheatingBeamParticleIdTool.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArCheating/CheatingBeamParticleIdTool.cc
3  *
4  * @brief Implementation of the cheating beam particle id tool class.
5  *
6  * $Log: $
7  */
8 
9 #include "Pandora/AlgorithmHeaders.h"
10 
12 
15 
16 using namespace pandora;
17 
18 namespace lar_content
19 {
20 
21 CheatingBeamParticleIdTool::CheatingBeamParticleIdTool() : m_minWeightFraction(0.5f)
22 {
23 }
24 
25 //------------------------------------------------------------------------------------------------------------------------------------------
26 
27 void CheatingBeamParticleIdTool::SelectOutputPfos(const pandora::Algorithm *const /*pAlgorithm*/,
28  const SliceHypotheses &testBeamSliceHypotheses, const SliceHypotheses &crSliceHypotheses, PfoList &selectedPfos)
29 {
30  if (testBeamSliceHypotheses.size() != crSliceHypotheses.size())
31  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
32 
33  for (unsigned int sliceIndex = 0, nSlices = testBeamSliceHypotheses.size(); sliceIndex < nSlices; ++sliceIndex)
34  {
35  float beamParticleWeight(0.f), totalWeight(0.f);
36  const PfoList &testBeamPfoList(testBeamSliceHypotheses.at(sliceIndex));
37 
38  for (const Pfo *const pTestBeamPfo : testBeamPfoList)
39  {
40  if (!LArPfoHelper::IsTestBeam(pTestBeamPfo))
41  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
42 
43  PfoList downstreamPfos;
44  LArPfoHelper::GetAllDownstreamPfos(pTestBeamPfo, downstreamPfos);
45 
46  float thisBeamParticleWeight(0.f), thisTotalWeight(0.f);
47  CheatingSliceIdBaseTool::GetTargetParticleWeight(&downstreamPfos, thisBeamParticleWeight, thisTotalWeight, LArMCParticleHelper::IsBeamParticle);
48 
49  beamParticleWeight += thisBeamParticleWeight;
50  totalWeight += thisTotalWeight;
51  }
52 
53  const float beamWeightFraction(totalWeight < std::numeric_limits<float>::epsilon() ? 0.f : beamParticleWeight / totalWeight);
54 
55  if (beamWeightFraction > m_minWeightFraction)
56  {
57  const PfoList &sliceOutput(testBeamSliceHypotheses.at(sliceIndex));
58  selectedPfos.insert(selectedPfos.end(), sliceOutput.begin(), sliceOutput.end());
59  }
60  else
61  {
62  const PfoList &sliceOutput(crSliceHypotheses.at(sliceIndex));
63  selectedPfos.insert(selectedPfos.end(), sliceOutput.begin(), sliceOutput.end());
64  }
65  }
66 }
67 
68 //------------------------------------------------------------------------------------------------------------------------------------------
69 
70 StatusCode CheatingBeamParticleIdTool::ReadSettings(const TiXmlHandle xmlHandle)
71 {
72  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "MinimumWeightFraction", m_minWeightFraction));
73 
74  return STATUS_CODE_SUCCESS;
75 }
76 
77 } // namespace lar_content
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Header file for the pfo helper class.
void SelectOutputPfos(const pandora::Algorithm *const pAlgorithm, const SliceHypotheses &nuSliceHypotheses, const SliceHypotheses &crSliceHypotheses, pandora::PfoList &selectedPfos)
Select which reconstruction hypotheses to use; neutrino outcomes or cosmic-ray muon outcomes for each...
Header file for the cheating beam particle id tool class.
static bool IsTestBeam(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a test beam particle.
Header file for the lar monte carlo particle helper helper class.
static bool IsBeamParticle(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary beam MCParticle.
std::vector< pandora::PfoList > SliceHypotheses
float m_minWeightFraction
The minimum weight fraction for identifying a slice as a beam particle.
static void GetTargetParticleWeight(const pandora::PfoList *const pPfoList, float &targetParticleWeight, float &totalWeight, std::function< bool(const pandora::MCParticle *const)> fCriteria)
Get the target particle weight in a list of pfos.
required by fuzzyCluster table::sbnd_g4_services gaushitTruthMatch pandora
Definition: reco_sbnd.fcl:182
static void GetAllDownstreamPfos(const pandora::PfoList &inputPfoList, pandora::PfoList &outputPfoList)
Get a flat list of all pfos, recursively, of all daughters associated with those pfos in an input lis...