CosmicRayShowerMatchingAlgorithm.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArTwoDReco/LArCosmicRay/CosmicRayShowerMatchingAlgorithm.cc
3  *
4  * @brief Implementation of the cosmic ray splitting algorithm 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 CosmicRayShowerMatchingAlgorithm::CosmicRayShowerMatchingAlgorithm() :
22  m_minCaloHitsPerCluster(10),
23  m_minXOverlap(1.f),
24  m_minXOverlapFraction(0.5f),
25  m_pseudoChi2Cut(5.f)
26 {
27 }
28 
29 //------------------------------------------------------------------------------------------------------------------------------------------
30 
32 {
33  for (const Cluster *const pCluster : inputVector)
34  {
35  if (pCluster->GetNCaloHits() < m_minCaloHitsPerCluster)
36  continue;
37 
38  outputVector.push_back(pCluster);
39  }
40 }
41 
42 //------------------------------------------------------------------------------------------------------------------------------------------
43 
44 bool CosmicRayShowerMatchingAlgorithm::MatchClusters(const Cluster *const pCluster1, const Cluster *const pCluster2) const
45 {
46  float xMin1(0.f), xMax1(0.f), xMin2(0.f), xMax2(0.f);
47  pCluster1->GetClusterSpanX(xMin1, xMax1);
48  pCluster2->GetClusterSpanX(xMin2, xMax2);
49 
50  const float xOverlap(std::min(xMax1, xMax2) - std::max(xMin1, xMin2));
51  const float xSpan(std::max(xMax1, xMax2) - std::min(xMin1, xMin2));
52 
53  if (xSpan < std::numeric_limits<float>::epsilon())
54  return false;
55 
56  if (xOverlap > m_minXOverlap && xOverlap / xSpan > m_minXOverlapFraction)
57  return true;
58 
59  return false;
60 }
61 
62 //------------------------------------------------------------------------------------------------------------------------------------------
63 
65  const Cluster *const pCluster1, const Cluster *const pCluster2, const Cluster *const pCluster3) const
66 {
67  // Check that three clusters have a consistent 3D position
68  const HitType hitType1(LArClusterHelper::GetClusterHitType(pCluster1));
69  const HitType hitType2(LArClusterHelper::GetClusterHitType(pCluster2));
70  const HitType hitType3(LArClusterHelper::GetClusterHitType(pCluster3));
71 
72  if (hitType1 == hitType2 || hitType2 == hitType3 || hitType3 == hitType1)
73  throw StatusCodeException(STATUS_CODE_FAILURE);
74 
75  // Requirements on X matching
76  float xMin1(0.f), xMin2(0.f), xMin3(0.f), xMax1(0.f), xMax2(0.f), xMax3(0.f);
77  pCluster1->GetClusterSpanX(xMin1, xMax1);
78  pCluster2->GetClusterSpanX(xMin2, xMax2);
79  pCluster3->GetClusterSpanX(xMin3, xMax3);
80 
81  const float xMin(std::max(xMin1, std::max(xMin2, xMin3)));
82  const float xMax(std::min(xMax1, std::min(xMax2, xMax3)));
83  const float xOverlap(xMax - xMin);
84 
85  if (xOverlap < std::numeric_limits<float>::epsilon())
86  return false;
87 
89 
90  if ((STATUS_CODE_SUCCESS != LArClusterHelper::GetAverageZ(pCluster1, xMin, xMax, p1)) ||
91  (STATUS_CODE_SUCCESS != LArClusterHelper::GetAverageZ(pCluster2, xMin, xMax, p2)) ||
92  (STATUS_CODE_SUCCESS != LArClusterHelper::GetAverageZ(pCluster3, xMin, xMax, p3)))
93  {
94  return false;
95  }
96 
97  const float q3(LArGeometryHelper::MergeTwoPositions(this->GetPandora(), hitType1, hitType2, p1, p2));
98  const float q1(LArGeometryHelper::MergeTwoPositions(this->GetPandora(), hitType2, hitType3, p2, p3));
99  const float q2(LArGeometryHelper::MergeTwoPositions(this->GetPandora(), hitType3, hitType1, p3, p1));
100 
101  const float pseudoChi2(((q1 - p1) * (q1 - p1) + (q2 - p2) * (q2 - p2) + (q3 - p3) * (q3 - p3)) / 3.f);
102 
103  if (pseudoChi2 > m_pseudoChi2Cut)
104  return false;
105 
106  return true;
107 }
108 
109 //------------------------------------------------------------------------------------------------------------------------------------------
110 
111 void CosmicRayShowerMatchingAlgorithm::SetPfoParameters(const Particle &particle, PandoraContentApi::ParticleFlowObject::Parameters &pfoParameters) const
112 {
113  ClusterList clusterList;
114  if (particle.m_pClusterU)
115  clusterList.push_back(particle.m_pClusterU);
116  if (particle.m_pClusterV)
117  clusterList.push_back(particle.m_pClusterV);
118  if (particle.m_pClusterW)
119  clusterList.push_back(particle.m_pClusterW);
120 
121  // TODO Correct these placeholder parameters
122  pfoParameters.m_particleId = E_MINUS; // SHOWER
123  pfoParameters.m_charge = PdgTable::GetParticleCharge(pfoParameters.m_particleId.Get());
124  pfoParameters.m_mass = PdgTable::GetParticleMass(pfoParameters.m_particleId.Get());
125  pfoParameters.m_energy = 0.f;
126  pfoParameters.m_momentum = CartesianVector(0.f, 0.f, 0.f);
127  pfoParameters.m_clusterList = clusterList;
128 }
129 
130 //------------------------------------------------------------------------------------------------------------------------------------------
131 
132 StatusCode CosmicRayShowerMatchingAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
133 {
134  PANDORA_RETURN_RESULT_IF_AND_IF(
135  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinCaloHitsPerCluster", m_minCaloHitsPerCluster));
136 
137  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinXOverlap", m_minXOverlap));
138 
139  PANDORA_RETURN_RESULT_IF_AND_IF(
140  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinXOverlapFraction", m_minXOverlapFraction));
141 
142  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "PseudoChi2Cut", m_pseudoChi2Cut));
143 
145 }
146 
147 } // namespace lar_content
bool MatchClusters(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2) const
Match a pair of clusters from two views.
enum cvn::HType HitType
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
const pandora::Cluster * m_pClusterV
Address of cluster in V view.
static pandora::HitType GetClusterHitType(const pandora::Cluster *const pCluster)
Get the hit type associated with a two dimensional cluster.
static pandora::StatusCode GetAverageZ(const pandora::Cluster *const pCluster, const float xmin, const float xmax, float &averageZ)
Get average Z positions of the calo hits in a cluster in range xmin to xmax.
Header file for the cosmic ray shower matching algorithm class.
Header file for the geometry helper class.
bool CheckMatchedClusters3D(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const pandora::Cluster *const pCluster3) const
Check that three clusters have a consistent 3D position.
Header file for the cluster helper class.
const pandora::Cluster * m_pClusterW
Address of cluster in W view.
const pandora::Cluster * m_pClusterU
Address of cluster in U view.
static float MergeTwoPositions(const pandora::Pandora &pandora, const pandora::HitType view1, const pandora::HitType view2, const float position1, const float position2)
Merge two views (U,V) to give a third view (Z).
static int max(int a, int b)
float m_pseudoChi2Cut
The selection cut on the matched chi2.
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
float m_minXOverlap
requirement on minimum X overlap for associated clusters
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
std::vector< art::Ptr< recob::Cluster > > ClusterVector
void SelectCleanClusters(const pandora::ClusterVector &inputVector, pandora::ClusterVector &outputVector) const
Select a set of clusters judged to be clean.
float m_minCaloHitsPerCluster
minimum size of clusters for this algorithm
void SetPfoParameters(const Particle &particle, PandoraContentApi::ParticleFlowObject::Parameters &pfoParameters) const
Calculate Pfo properties from proto particle.
float m_minXOverlapFraction
requirement on minimum X overlap fraction for associated clusters