9 #include "Pandora/AlgorithmHeaders.h" 21 CheatingNeutrinoCreationAlgorithm::CheatingNeutrinoCreationAlgorithm() :
22 m_collapseToPrimaryMCParticles(false),
23 m_vertexTolerance(0.5
f)
34 for (
const MCParticle *
const pMCNeutrino : mcNeutrinoVector)
36 const ParticleFlowObject *pNeutrinoPfo(
nullptr);
40 return STATUS_CODE_FAILURE;
49 return STATUS_CODE_SUCCESS;
56 const MCParticleList *pMCParticleList(
nullptr);
57 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*
this,
m_mcParticleListName, pMCParticleList));
62 for (
const MCParticle *
const pMCNeutrino : allMCNeutrinoVector)
65 mcNeutrinoVector.push_back(pMCNeutrino);
73 pNeutrinoPfo =
nullptr;
75 PandoraContentApi::ParticleFlowObject::Parameters pfoParameters;
76 pfoParameters.m_particleId = pMCNeutrino->GetParticleId();
77 pfoParameters.m_charge = PdgTable::GetParticleCharge(pfoParameters.m_particleId.Get());
78 pfoParameters.m_mass = PdgTable::GetParticleMass(pfoParameters.m_particleId.Get());
79 pfoParameters.m_energy = pMCNeutrino->GetEnergy();
80 pfoParameters.m_momentum = pMCNeutrino->GetMomentum();
82 std::string neutrinoPfoListName;
83 const PfoList *pNeutrinoPfoList(
nullptr);
84 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::CreateTemporaryListAndSetCurrent(*
this, pNeutrinoPfoList, neutrinoPfoListName));
85 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::Create(*
this, pfoParameters, pNeutrinoPfo));
87 if (!pNeutrinoPfoList || pNeutrinoPfoList->empty())
88 throw StatusCodeException(STATUS_CODE_FAILURE);
90 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList<Pfo>(*
this,
m_neutrinoPfoListName));
91 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ReplaceCurrentList<Pfo>(*
this,
m_neutrinoPfoListName));
99 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*
this, pVertexList));
101 const Vertex *pNeutrinoVertex(
nullptr);
104 for (
const Vertex *
const pVertex : *pVertexList)
106 const float distance((pVertex->GetPosition() - pMCNeutrino->GetEndpoint()).GetMagnitude());
108 if (distance < closestVertexDistance)
110 pNeutrinoVertex = pVertex;
111 closestVertexDistance = distance;
115 if (!pNeutrinoVertex || (VERTEX_3D != pNeutrinoVertex->GetVertexType()) || ((pNeutrinoVertex->GetPosition() - pMCNeutrino->GetEndpoint()).GetMagnitude() >
m_vertexTolerance))
116 throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
118 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::AddToPfo(*
this, pNeutrinoPfo, pNeutrinoVertex));
129 const MCParticleList *pMCParticleList(
nullptr);
130 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*
this,
m_mcParticleListName, pMCParticleList));
137 const PfoList *pDaughterPfoList(
nullptr);
139 if (STATUS_CODE_SUCCESS != PandoraContentApi::GetList(*
this, daughterPfoListName, pDaughterPfoList))
141 if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
142 std::cout <<
"CheatingNeutrinoCreationAlgorithm: pfo list " << daughterPfoListName <<
" unavailable." << std::endl;
147 for (
const ParticleFlowObject *
const pDaughterPfo : *pDaughterPfoList)
155 if (mcPrimaryMap.end() == primaryIter)
156 throw StatusCodeException(STATUS_CODE_NOT_FOUND);
158 pMCParticle = primaryIter->second;
161 if (!mcParticleToPfoMap.insert(MCParticleToPfoMap::value_type(pMCParticle, pDaughterPfo)).second)
162 throw StatusCodeException(STATUS_CODE_OUT_OF_RANGE);
172 for (
const MCParticle *
const pDaughterMCParticle : pParentMCParticle->GetDaughterList())
176 if (mcParticleToPfoMap.end() == mapIter)
182 const ParticleFlowObject *
const pDaughterPfo(mapIter->second);
183 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SetPfoParentDaughterRelationship(*
this, pParentPfo, pDaughterPfo));
192 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
195 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
198 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
201 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
204 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadVectorOfValues(xmlHandle,
207 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
210 return STATUS_CODE_SUCCESS;
Header file for the pfo helper class.
std::string m_neutrinoPfoListName
The name of the neutrino pfo list.
float m_vertexTolerance
Tolerance, 3d displacement, allowed between reco neutrino vertex and mc neutrino endpoint.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
static void GetMCPrimaryMap(const pandora::MCParticleList *const pMCParticleList, MCRelationMap &mcPrimaryMap)
Get mapping from individual mc particles (in a provided list) and their primary parent mc particles...
static const pandora::MCParticle * GetMainMCParticle(const pandora::ParticleFlowObject *const pPfo)
Find the mc particle making the largest contribution to 2D clusters in a specified pfo...
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
std::unordered_map< const pandora::MCParticle *, const pandora::ParticleFlowObject * > MCParticleToPfoMap
std::string m_mcParticleListName
The name of the three d mc particle list name.
void CreatePfoHierarchy(const pandora::MCParticle *const pParentMCParticle, const pandora::ParticleFlowObject *const pParentPfo, const MCParticleToPfoMap &mcParticleToPfoMap) const
Use information from mc particles and the mc particle to pfo map to fully-reconstruct the daughter pf...
Header file for the lar monte carlo particle helper helper class.
pandora::StatusCode Run()
pandora::StringVector m_daughterPfoListNames
The list of daughter pfo list names.
void GetMCParticleToDaughterPfoMap(MCParticleToPfoMap &mcParticleToPfoMap) const
Extract candidate daughter pfos from external lists and populate a map from main mc particle (or prim...
static void GetTrueNeutrinos(const pandora::MCParticleList *const pMCParticleList, pandora::MCParticleVector &trueNeutrinos)
Get neutrino MC particles from an input MC particle list.
Header file for the cheating neutrino creation algorithm class.
std::string m_vertexListName
The name of the neutrino vertex list.
bool m_collapseToPrimaryMCParticles
Whether to collapse mc particle hierarchies to primary particles.
void GetMCNeutrinoVector(pandora::MCParticleVector &mcNeutrinoVector) const
Get the mc neutrino vector.
std::unordered_map< const pandora::MCParticle *, const pandora::MCParticle * > MCRelationMap
void AddNeutrinoVertex(const pandora::MCParticle *const pMCNeutrino, const pandora::ParticleFlowObject *const pNeutrinoPfo) const
Extract reconstructed vertex from external list, check its position agrees with mc neutrino...
std::list< Vertex > VertexList
static bool IsNeutrino(const pandora::MCParticle *const pMCParticle)
Whether a mc particle is a neutrino or antineutrino.
void CreateAndSaveNeutrinoPfo(const pandora::MCParticle *const pMCNeutrino, const pandora::ParticleFlowObject *&pNeutrinoPfo) const
Create and save a neutrino pfo with properties dictated by the mc neutrino.