LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
lar_content::CheatingPfoCreationAlgorithm Class Reference

CheatingPfoCreationAlgorithm class. More...

#include "CheatingPfoCreationAlgorithm.h"

Inheritance diagram for lar_content::CheatingPfoCreationAlgorithm:

Public Member Functions

 CheatingPfoCreationAlgorithm ()
 Default constructor. More...
 

Private Types

typedef std::unordered_map< const pandora::MCParticle *, pandora::ClusterList > MCParticleToClusterListMap
 
typedef std::map< pandora::HitType, unsigned int > HitTypeMap
 
typedef std::set< int > ParticleIdList
 

Private Member Functions

pandora::StatusCode Run ()
 
pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle)
 
void GetMCParticleToClusterListMap (const pandora::ClusterList *const pClusterList, const LArMCParticleHelper::MCRelationMap &mcPrimaryMap, MCParticleToClusterListMap &mcParticleToClusterListMap) const
 Get a map relating mc particles to a list of daughter clusters. More...
 
void CreatePfos (const MCParticleToClusterListMap &mcParticleToClusterListMap) const
 Create pfos corresponding to the details in a provided mc particle to cluster list map. More...
 
unsigned int GetNHitTypesAboveThreshold (const pandora::ClusterList &clusterList, const unsigned int nHitsThreshold) const
 Get the number of hit types containing more than a specified number of hits. More...
 

Private Attributes

pandora::StringVector m_inputClusterListNames
 The names of the input cluster lists. More...
 
std::string m_outputPfoListName
 The output pfo list name. More...
 
std::string m_outputVertexListName
 The output vertex list name. More...
 
bool m_collapseToPrimaryMCParticles
 Whether to collapse mc particle hierarchies to primary particles. More...
 
std::string m_mcParticleListName
 The mc particle list name. More...
 
bool m_useOnlyAvailableClusters
 Whether to consider unavailable clusters when identifying cheated pfos. More...
 
bool m_addVertices
 Whether to add the start vertex to the cheated pfo. More...
 
bool m_replaceCurrentVertexList
 Whether to replace current vertex list. More...
 
unsigned int m_minGoodHitTypes
 The min number of good hit types in the clusters collected for a given mc particle. More...
 
unsigned int m_nHitsForGoodHitType
 The min number of hits of a particular hit type in order to declare the hit type is good. More...
 
ParticleIdList m_particleIdList
 The list of particle ids to consider for pfo creation; will consider all ids if empty. More...
 

Detailed Description

Member Typedef Documentation

typedef std::map<pandora::HitType, unsigned int> lar_content::CheatingPfoCreationAlgorithm::HitTypeMap
private

Definition at line 64 of file CheatingPfoCreationAlgorithm.h.

typedef std::unordered_map<const pandora::MCParticle*, pandora::ClusterList> lar_content::CheatingPfoCreationAlgorithm::MCParticleToClusterListMap
private

Definition at line 35 of file CheatingPfoCreationAlgorithm.h.

Definition at line 65 of file CheatingPfoCreationAlgorithm.h.

Constructor & Destructor Documentation

lar_content::CheatingPfoCreationAlgorithm::CheatingPfoCreationAlgorithm ( )

Default constructor.

Definition at line 20 of file CheatingPfoCreationAlgorithm.cc.

20  :
23  m_addVertices(true),
27 {
28 }
unsigned int m_minGoodHitTypes
The min number of good hit types in the clusters collected for a given mc particle.
unsigned int m_nHitsForGoodHitType
The min number of hits of a particular hit type in order to declare the hit type is good...
bool m_addVertices
Whether to add the start vertex to the cheated pfo.
bool m_useOnlyAvailableClusters
Whether to consider unavailable clusters when identifying cheated pfos.
bool m_collapseToPrimaryMCParticles
Whether to collapse mc particle hierarchies to primary particles.
bool m_replaceCurrentVertexList
Whether to replace current vertex list.

Member Function Documentation

void lar_content::CheatingPfoCreationAlgorithm::CreatePfos ( const MCParticleToClusterListMap mcParticleToClusterListMap) const
private

Create pfos corresponding to the details in a provided mc particle to cluster list map.

Parameters
mcParticleToClusterListMapthe mc particle to cluster list map

Definition at line 100 of file CheatingPfoCreationAlgorithm.cc.

References GetNHitTypesAboveThreshold(), m_addVertices, m_minGoodHitTypes, m_nHitsForGoodHitType, m_outputPfoListName, m_outputVertexListName, m_replaceCurrentVertexList, and lar_content::LArMCParticleHelper::SortByMomentum().

Referenced by Run().

101 {
102  if (mcParticleToClusterListMap.empty())
103  return;
104 
105  const PfoList *pPfoList(nullptr); std::string pfoListName;
106  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::CreateTemporaryListAndSetCurrent(*this, pPfoList, pfoListName));
107 
108  const VertexList *pVertexList(nullptr); std::string vertexListName;
109  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::CreateTemporaryListAndSetCurrent(*this, pVertexList, vertexListName));
110 
111  MCParticleVector mcParticleVector;
112  for (const auto &mapEntry : mcParticleToClusterListMap) mcParticleVector.push_back(mapEntry.first);
113  std::sort(mcParticleVector.begin(), mcParticleVector.end(), LArMCParticleHelper::SortByMomentum);
114 
115  for (const MCParticle *const pMCParticle : mcParticleVector)
116  {
117  const ClusterList &clusterList(mcParticleToClusterListMap.at(pMCParticle));
118 
119  if (clusterList.empty())
120  continue;
121 
123  continue;
124 
125  try
126  {
127  PandoraContentApi::ParticleFlowObject::Parameters pfoParameters;
128  pfoParameters.m_particleId = pMCParticle->GetParticleId();
129  pfoParameters.m_charge = PdgTable::GetParticleCharge(pfoParameters.m_particleId.Get());
130  pfoParameters.m_mass = PdgTable::GetParticleMass(pfoParameters.m_particleId.Get());
131  pfoParameters.m_energy = pMCParticle->GetEnergy();
132  pfoParameters.m_momentum = pMCParticle->GetMomentum();
133  pfoParameters.m_clusterList.insert(pfoParameters.m_clusterList.end(), clusterList.begin(), clusterList.end());
134 
135  const ParticleFlowObject *pPfo(nullptr);
136  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::Create(*this, pfoParameters, pPfo));
137 
138  if (m_addVertices)
139  {
140  PandoraContentApi::Vertex::Parameters parameters;
141  parameters.m_position = pMCParticle->GetVertex();
142  parameters.m_vertexLabel = VERTEX_START;
143  parameters.m_vertexType = VERTEX_3D;
144 
145  const Vertex *pVertex(nullptr);
146  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Vertex::Create(*this, parameters, pVertex));
147  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::AddToPfo<Vertex>(*this, pPfo, pVertex));
148  }
149  }
150  catch (const StatusCodeException &)
151  {
152  std::cout << "CheatingPfoCreationAlgorithm: Could not create PFO for MCParticle with pdg code " << pMCParticle->GetParticleId() << std::endl;
153  }
154  }
155 
156  if (!pPfoList->empty())
157  {
158  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList<Pfo>(*this, m_outputPfoListName));
159  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ReplaceCurrentList<Pfo>(*this, m_outputPfoListName));
160  }
161 
162  if (!pVertexList->empty())
163  {
164  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList<Vertex>(*this, m_outputVertexListName));
165 
167  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ReplaceCurrentList<Vertex>(*this, m_outputVertexListName));
168  }
169 }
std::string m_outputVertexListName
The output vertex list name.
unsigned int m_minGoodHitTypes
The min number of good hit types in the clusters collected for a given mc particle.
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
static bool SortByMomentum(const pandora::MCParticle *const pLhs, const pandora::MCParticle *const pRhs)
Sort mc particles by their momentum.
std::string m_outputPfoListName
The output pfo list name.
unsigned int m_nHitsForGoodHitType
The min number of hits of a particular hit type in order to declare the hit type is good...
bool m_addVertices
Whether to add the start vertex to the cheated pfo.
unsigned int GetNHitTypesAboveThreshold(const pandora::ClusterList &clusterList, const unsigned int nHitsThreshold) const
Get the number of hit types containing more than a specified number of hits.
bool m_replaceCurrentVertexList
Whether to replace current vertex list.
std::list< Vertex > VertexList
Definition: DCEL.h:178
void lar_content::CheatingPfoCreationAlgorithm::GetMCParticleToClusterListMap ( const pandora::ClusterList *const  pClusterList,
const LArMCParticleHelper::MCRelationMap mcPrimaryMap,
MCParticleToClusterListMap mcParticleToClusterListMap 
) const
private

Get a map relating mc particles to a list of daughter clusters.

Parameters
pClusterListaddress of a cluster list
mcPrimaryMapthe mapping between mc particles and their parents
mcParticleToClusterListMapto receive the populated mc particle to cluster list map

Definition at line 67 of file CheatingPfoCreationAlgorithm.cc.

References m_collapseToPrimaryMCParticles, m_particleIdList, and m_useOnlyAvailableClusters.

Referenced by Run().

69 {
70  for (const Cluster *const pCluster : *pClusterList)
71  {
72  try
73  {
74  if (m_useOnlyAvailableClusters && !PandoraContentApi::IsAvailable(*this, pCluster))
75  continue;
76 
77  const MCParticle *pMCParticle(MCParticleHelper::GetMainMCParticle(pCluster));
78 
80  {
81  LArMCParticleHelper::MCRelationMap::const_iterator primaryIter = mcPrimaryMap.find(pMCParticle);
82 
83  if (mcPrimaryMap.end() == primaryIter)
84  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
85 
86  pMCParticle = primaryIter->second;
87  }
88 
89  if (!m_particleIdList.empty() && !m_particleIdList.count(pMCParticle->GetParticleId()))
90  continue;
91 
92  mcParticleToClusterListMap[pMCParticle].push_back(pCluster);
93  }
94  catch (const StatusCodeException &) {}
95  }
96 }
intermediate_table::const_iterator const_iterator
bool m_useOnlyAvailableClusters
Whether to consider unavailable clusters when identifying cheated pfos.
ParticleIdList m_particleIdList
The list of particle ids to consider for pfo creation; will consider all ids if empty.
bool m_collapseToPrimaryMCParticles
Whether to collapse mc particle hierarchies to primary particles.
unsigned int lar_content::CheatingPfoCreationAlgorithm::GetNHitTypesAboveThreshold ( const pandora::ClusterList &  clusterList,
const unsigned int  nHitsThreshold 
) const
private

Get the number of hit types containing more than a specified number of hits.

Parameters
clusterListthe cluster list, consider all hits in clusters in this list
nHitsThresholdthe threshold number of hits of a specified hit type
Returns
the number of good hit types

Definition at line 173 of file CheatingPfoCreationAlgorithm.cc.

References lar_content::LArClusterHelper::GetClusterHitType().

Referenced by CreatePfos().

174 {
175  HitTypeMap hitTypeMap;
176 
177  for (const Cluster *const pCluster : clusterList)
178  {
179  hitTypeMap[LArClusterHelper::GetClusterHitType(pCluster)] += pCluster->GetNCaloHits();
180  }
181 
182  unsigned int nGoodViews(0);
183 
184  for (const HitTypeMap::value_type &mapEntry : hitTypeMap)
185  {
186  if (mapEntry.second > nHitsThreshold)
187  ++nGoodViews;
188  }
189 
190  return nGoodViews;
191 }
static pandora::HitType GetClusterHitType(const pandora::Cluster *const pCluster)
Get the hit type associated with a two dimensional cluster.
std::map< pandora::HitType, unsigned int > HitTypeMap
StatusCode lar_content::CheatingPfoCreationAlgorithm::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
private

Definition at line 195 of file CheatingPfoCreationAlgorithm.cc.

References m_addVertices, m_collapseToPrimaryMCParticles, m_inputClusterListNames, m_mcParticleListName, m_minGoodHitTypes, m_nHitsForGoodHitType, m_outputPfoListName, m_outputVertexListName, m_particleIdList, m_replaceCurrentVertexList, and m_useOnlyAvailableClusters.

196 {
197  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadVectorOfValues(xmlHandle,
198  "InputClusterListNames", m_inputClusterListNames));
199 
200  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
201  "OutputPfoListName", m_outputPfoListName));
202 
203  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
204  "CollapseToPrimaryMCParticles", m_collapseToPrimaryMCParticles));
205 
207  {
208  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
209  "MCParticleListName", m_mcParticleListName));
210  }
211 
212  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
213  "UseOnlyAvailableClusters", m_useOnlyAvailableClusters));
214 
215  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
216  "AddVertices", m_addVertices));
217 
218  if (m_addVertices)
219  {
220  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
221  "OutputVertexListName", m_outputVertexListName));
222 
223  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
224  "ReplaceCurrentVertexList", m_replaceCurrentVertexList));
225  }
226 
227  IntVector particleIdVector;
228  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadVectorOfValues(xmlHandle,
229  "ParticleIdList", particleIdVector));
230 
231  m_particleIdList.insert(particleIdVector.begin(), particleIdVector.end());
232 
233  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
234  "MinGoodHitTypes", m_minGoodHitTypes));
235 
236  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
237  "NHitsForGoodHitType", m_nHitsForGoodHitType));
238 
239  return STATUS_CODE_SUCCESS;
240 }
std::string m_mcParticleListName
The mc particle list name.
pandora::StringVector m_inputClusterListNames
The names of the input cluster lists.
std::string m_outputVertexListName
The output vertex list name.
unsigned int m_minGoodHitTypes
The min number of good hit types in the clusters collected for a given mc particle.
std::vector< int > IntVector
std::string m_outputPfoListName
The output pfo list name.
unsigned int m_nHitsForGoodHitType
The min number of hits of a particular hit type in order to declare the hit type is good...
bool m_addVertices
Whether to add the start vertex to the cheated pfo.
bool m_useOnlyAvailableClusters
Whether to consider unavailable clusters when identifying cheated pfos.
ParticleIdList m_particleIdList
The list of particle ids to consider for pfo creation; will consider all ids if empty.
bool m_collapseToPrimaryMCParticles
Whether to collapse mc particle hierarchies to primary particles.
bool m_replaceCurrentVertexList
Whether to replace current vertex list.
StatusCode lar_content::CheatingPfoCreationAlgorithm::Run ( )
private

Definition at line 32 of file CheatingPfoCreationAlgorithm.cc.

References CreatePfos(), GetMCParticleToClusterListMap(), lar_content::LArMCParticleHelper::GetMCPrimaryMap(), m_collapseToPrimaryMCParticles, m_inputClusterListNames, and m_mcParticleListName.

33 {
35 
37  {
38  const MCParticleList *pMCParticleList(nullptr);
39  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*this, m_mcParticleListName, pMCParticleList));
40 
41  LArMCParticleHelper::GetMCPrimaryMap(pMCParticleList, mcPrimaryMap);
42  }
43 
44  MCParticleToClusterListMap mcParticleToClusterListMap;
45 
46  for (const std::string &clusterListName : m_inputClusterListNames)
47  {
48  const ClusterList *pClusterList(nullptr);
49 
50  if (STATUS_CODE_SUCCESS != PandoraContentApi::GetList(*this, clusterListName, pClusterList))
51  {
52  if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
53  std::cout << "CheatingPfoCreationAlgorithm - Could not access cluster list with name " << clusterListName << std::endl;
54 
55  continue;
56  }
57 
58  this->GetMCParticleToClusterListMap(pClusterList, mcPrimaryMap, mcParticleToClusterListMap);
59  }
60 
61  this->CreatePfos(mcParticleToClusterListMap);
62  return STATUS_CODE_SUCCESS;
63 }
std::string m_mcParticleListName
The mc particle list name.
pandora::StringVector m_inputClusterListNames
The names of the input cluster lists.
std::unordered_map< const pandora::MCParticle *, pandora::ClusterList > MCParticleToClusterListMap
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...
void CreatePfos(const MCParticleToClusterListMap &mcParticleToClusterListMap) const
Create pfos corresponding to the details in a provided mc particle to cluster list map...
void GetMCParticleToClusterListMap(const pandora::ClusterList *const pClusterList, const LArMCParticleHelper::MCRelationMap &mcPrimaryMap, MCParticleToClusterListMap &mcParticleToClusterListMap) const
Get a map relating mc particles to a list of daughter clusters.
bool m_collapseToPrimaryMCParticles
Whether to collapse mc particle hierarchies to primary particles.
std::unordered_map< const pandora::MCParticle *, const pandora::MCParticle * > MCRelationMap

Member Data Documentation

bool lar_content::CheatingPfoCreationAlgorithm::m_addVertices
private

Whether to add the start vertex to the cheated pfo.

Definition at line 75 of file CheatingPfoCreationAlgorithm.h.

Referenced by CreatePfos(), and ReadSettings().

bool lar_content::CheatingPfoCreationAlgorithm::m_collapseToPrimaryMCParticles
private

Whether to collapse mc particle hierarchies to primary particles.

Definition at line 71 of file CheatingPfoCreationAlgorithm.h.

Referenced by GetMCParticleToClusterListMap(), ReadSettings(), and Run().

pandora::StringVector lar_content::CheatingPfoCreationAlgorithm::m_inputClusterListNames
private

The names of the input cluster lists.

Definition at line 67 of file CheatingPfoCreationAlgorithm.h.

Referenced by ReadSettings(), and Run().

std::string lar_content::CheatingPfoCreationAlgorithm::m_mcParticleListName
private

The mc particle list name.

Definition at line 72 of file CheatingPfoCreationAlgorithm.h.

Referenced by ReadSettings(), and Run().

unsigned int lar_content::CheatingPfoCreationAlgorithm::m_minGoodHitTypes
private

The min number of good hit types in the clusters collected for a given mc particle.

Definition at line 77 of file CheatingPfoCreationAlgorithm.h.

Referenced by CreatePfos(), and ReadSettings().

unsigned int lar_content::CheatingPfoCreationAlgorithm::m_nHitsForGoodHitType
private

The min number of hits of a particular hit type in order to declare the hit type is good.

Definition at line 78 of file CheatingPfoCreationAlgorithm.h.

Referenced by CreatePfos(), and ReadSettings().

std::string lar_content::CheatingPfoCreationAlgorithm::m_outputPfoListName
private

The output pfo list name.

Definition at line 68 of file CheatingPfoCreationAlgorithm.h.

Referenced by CreatePfos(), and ReadSettings().

std::string lar_content::CheatingPfoCreationAlgorithm::m_outputVertexListName
private

The output vertex list name.

Definition at line 69 of file CheatingPfoCreationAlgorithm.h.

Referenced by CreatePfos(), and ReadSettings().

ParticleIdList lar_content::CheatingPfoCreationAlgorithm::m_particleIdList
private

The list of particle ids to consider for pfo creation; will consider all ids if empty.

Definition at line 79 of file CheatingPfoCreationAlgorithm.h.

Referenced by GetMCParticleToClusterListMap(), and ReadSettings().

bool lar_content::CheatingPfoCreationAlgorithm::m_replaceCurrentVertexList
private

Whether to replace current vertex list.

Definition at line 76 of file CheatingPfoCreationAlgorithm.h.

Referenced by CreatePfos(), and ReadSettings().

bool lar_content::CheatingPfoCreationAlgorithm::m_useOnlyAvailableClusters
private

Whether to consider unavailable clusters when identifying cheated pfos.

Definition at line 74 of file CheatingPfoCreationAlgorithm.h.

Referenced by GetMCParticleToClusterListMap(), and ReadSettings().


The documentation for this class was generated from the following files: