LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
CheatingNeutrinoDaughterVerticesAlgorithm.cc
Go to the documentation of this file.
1 
9 #include "Pandora/AlgorithmHeaders.h"
10 
12 
14 
15 using namespace pandora;
16 
17 namespace lar_content
18 {
19 
20 CheatingNeutrinoDaughterVerticesAlgorithm::CheatingNeutrinoDaughterVerticesAlgorithm() :
21  m_collapseToPrimaryMCParticles(false)
22 {
23 }
24 
25 //------------------------------------------------------------------------------------------------------------------------------------------
26 
28 {
29  const PfoList *pPfoList(nullptr);
30  PANDORA_THROW_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=, PandoraContentApi::GetList(*this, m_neutrinoListName, pPfoList));
31 
32  if (!pPfoList)
33  {
34  if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
35  std::cout << "CheatingNeutrinoDaughterVerticesAlgorithm: pfo list unavailable." << std::endl;
36 
37  return STATUS_CODE_SUCCESS;
38  }
39 
41  this->GetMCPrimaryMap(mcPrimaryMap);
42 
43  PfoList neutrinoPfos;
44  LArPfoHelper::GetRecoNeutrinos(pPfoList, neutrinoPfos);
45 
46  this->ProcessRecoNeutrinos(neutrinoPfos, mcPrimaryMap);
47 
48  return STATUS_CODE_SUCCESS;
49 }
50 
51 //------------------------------------------------------------------------------------------------------------------------------------------
52 
54 {
56  {
57  const MCParticleList *pMCParticleList(nullptr);
58  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*this, m_mcParticleListName, pMCParticleList));
59 
60  LArMCParticleHelper::GetMCPrimaryMap(pMCParticleList, mcPrimaryMap);
61  }
62 }
63 
64 //------------------------------------------------------------------------------------------------------------------------------------------
65 
67  const LArMCParticleHelper::MCRelationMap &mcPrimaryMap) const
68 {
69  for (const ParticleFlowObject *const pNeutrinoPfo : neutrinoPfos)
70  {
71  PfoList daughterPfos;
72  LArPfoHelper::GetAllDownstreamPfos(pNeutrinoPfo, daughterPfos);
73 
74  PfoList::iterator neutrinoIter(std::find(daughterPfos.begin(), daughterPfos.end(), pNeutrinoPfo));
75 
76  if (daughterPfos.end() != neutrinoIter)
77  daughterPfos.erase(neutrinoIter);
78 
79  for (const ParticleFlowObject *const pDaughterPfo : daughterPfos)
80  {
81  try
82  {
83  this->ProcessDaughterPfo(pDaughterPfo, mcPrimaryMap);
84  }
85  catch (const StatusCodeException &) {}
86  }
87  }
88 }
89 
90 //------------------------------------------------------------------------------------------------------------------------------------------
91 
92 void CheatingNeutrinoDaughterVerticesAlgorithm::ProcessDaughterPfo(const ParticleFlowObject *const pDaughterPfo,
93  const LArMCParticleHelper::MCRelationMap &mcPrimaryMap) const
94 {
95  const MCParticle *pMCParticle(LArMCParticleHelper::GetMainMCParticle(pDaughterPfo));
96 
98  {
99  LArMCParticleHelper::MCRelationMap::const_iterator primaryIter = mcPrimaryMap.find(pMCParticle);
100 
101  if (mcPrimaryMap.end() == primaryIter)
102  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
103 
104  pMCParticle = primaryIter->second;
105  }
106 
107  const VertexList *pVertexList(nullptr); std::string vertexListName;
108  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::CreateTemporaryListAndSetCurrent(*this, pVertexList, vertexListName));
109 
110  PandoraContentApi::Vertex::Parameters parameters;
111  parameters.m_position = pMCParticle->GetVertex();
112  parameters.m_vertexLabel = VERTEX_INTERACTION;
113  parameters.m_vertexType = VERTEX_3D;
114 
115  const Vertex *pVertex(nullptr);
116  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Vertex::Create(*this, parameters, pVertex));
117 
118  if (!pVertexList->empty())
119  {
120  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList<Vertex>(*this, m_vertexListName));
121  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::AddToPfo<Vertex>(*this, pDaughterPfo, pVertex));
122  }
123 }
124 
125 //------------------------------------------------------------------------------------------------------------------------------------------
126 
127 StatusCode CheatingNeutrinoDaughterVerticesAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
128 {
129  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
130  "CollapseToPrimaryMCParticles", m_collapseToPrimaryMCParticles));
131 
133  {
134  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
135  "MCParticleListName", m_mcParticleListName));
136  }
137 
138  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
139  "NeutrinoPfoListName", m_neutrinoListName));
140 
141  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
142  "OutputVertexListName", m_vertexListName));
143 
144  return STATUS_CODE_SUCCESS;
145 }
146 
147 } // namespace lar_content
std::string m_mcParticleListName
The mc particle list name, required if want to collapse mc particle hierarchy.
Header file for the pfo helper class.
std::string m_vertexListName
The name of the output cosmic-ray vertex list.
intermediate_table::iterator iterator
static void GetRecoNeutrinos(const pandora::PfoList *const pPfoList, pandora::PfoList &recoNeutrinos)
Get neutrino pfos from an input pfo list.
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...
void GetMCPrimaryMap(LArMCParticleHelper::MCRelationMap &mcPrimaryMap) const
Get the mapping from mc particle to primary, only required if collapsed mc particle hierarchy specifi...
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
intermediate_table::const_iterator const_iterator
Header file for the cheating neutrino daughter vertices algorithm class.
void ProcessRecoNeutrinos(const pandora::PfoList &neutrinoPfos, const LArMCParticleHelper::MCRelationMap &mcPrimaryMap) const
Process the list of reconstructed neutrinos.
void ProcessDaughterPfo(const pandora::ParticleFlowObject *const pDaughterPfo, const LArMCParticleHelper::MCRelationMap &mcPrimaryMap) const
Process a daughter pfo.
bool m_collapseToPrimaryMCParticles
Whether to collapse mc particle hierarchies to primary particles.
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...
std::unordered_map< const pandora::MCParticle *, const pandora::MCParticle * > MCRelationMap
std::list< Vertex > VertexList
Definition: DCEL.h:178