LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
CosmicRayShowerMatchingAlgorithm.cc
Go to the documentation of this file.
1 
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  LArClusterHelper::GetClusterSpanX(pCluster1, xMin1, xMax1);
48  LArClusterHelper::GetClusterSpanX(pCluster2, 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 
64 bool CosmicRayShowerMatchingAlgorithm::CheckMatchedClusters3D(const Cluster *const pCluster1, const Cluster *const pCluster2,
65  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  LArClusterHelper::GetClusterSpanX(pCluster1, xMin1, xMax1);
78  LArClusterHelper::GetClusterSpanX(pCluster2, xMin2, xMax2);
79  LArClusterHelper::GetClusterSpanX(pCluster3, 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) clusterList.push_back(particle.m_pClusterU);
115  if (particle.m_pClusterV) clusterList.push_back(particle.m_pClusterV);
116  if (particle.m_pClusterW) clusterList.push_back(particle.m_pClusterW);
117 
118  // TODO Correct these placeholder parameters
119  pfoParameters.m_particleId = E_MINUS; // SHOWER
120  pfoParameters.m_charge = PdgTable::GetParticleCharge(pfoParameters.m_particleId.Get());
121  pfoParameters.m_mass = PdgTable::GetParticleMass(pfoParameters.m_particleId.Get());
122  pfoParameters.m_energy = 0.f;
123  pfoParameters.m_momentum = CartesianVector(0.f, 0.f, 0.f);
124  pfoParameters.m_clusterList = clusterList;
125 }
126 
127 //------------------------------------------------------------------------------------------------------------------------------------------
128 
129 StatusCode CosmicRayShowerMatchingAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
130 {
131  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
132  "MinCaloHitsPerCluster", m_minCaloHitsPerCluster));
133 
134  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
135  "MinXOverlap", m_minXOverlap));
136 
137  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
138  "MinXOverlapFraction", m_minXOverlapFraction));
139 
140  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
141  "PseudoChi2Cut", m_pseudoChi2Cut));
142 
144 }
145 
146 } // namespace lar_content
bool MatchClusters(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2) const
Match a pair of clusters from two views.
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.
TFile f
Definition: plotHisto.C:6
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.
Int_t max
Definition: plot.C:27
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).
float m_pseudoChi2Cut
The selection cut on the matched chi2.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
Int_t min
Definition: plot.C:26
float m_minXOverlap
requirement on minimum X overlap for associated clusters
static void GetClusterSpanX(const pandora::Cluster *const pCluster, float &xmin, float &xmax)
Get minimum and maximum X positions of the calo hits in a cluster.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
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