HitCreationBaseTool.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArThreeDReco/LArHitCreation/HitCreationBaseTool.cc
3  *
4  * @brief Implementation of the hit creation base tool.
5  *
6  * $Log: $
7  */
8 
9 #include "Pandora/AlgorithmHeaders.h"
10 
12 
14 
15 using namespace pandora;
16 
17 namespace lar_content
18 {
19 
20 HitCreationBaseTool::HitCreationBaseTool() : m_sigmaX2(1.), m_chiSquaredCut(1.)
21 {
22 }
23 
24 //------------------------------------------------------------------------------------------------------------------------------------------
25 
27 {
28 }
29 
30 //------------------------------------------------------------------------------------------------------------------------------------------
31 
32 void HitCreationBaseTool::GetBestPosition3D(const HitType hitType1, const HitType hitType2, const CartesianPointVector &fitPositionList1,
33  const CartesianPointVector &fitPositionList2, ProtoHit &protoHit) const
34 {
35  if (fitPositionList1.empty() && fitPositionList2.empty())
36  {
37  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
38  }
39  else if (fitPositionList1.empty())
40  {
41  if (fitPositionList2.size() != 1)
42  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
43 
44  this->GetBestPosition3D(hitType2, fitPositionList2.front(), protoHit);
45  }
46  else if (fitPositionList2.empty())
47  {
48  if (fitPositionList1.size() != 1)
49  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
50 
51  this->GetBestPosition3D(hitType1, fitPositionList1.front(), protoHit);
52  }
53  else
54  {
55  for (const CartesianVector &fitPosition1 : fitPositionList1)
56  {
57  for (const CartesianVector &fitPosition2 : fitPositionList2)
58  {
59  ProtoHit thisProtoHit(protoHit.GetParentCaloHit2D());
60  this->GetBestPosition3D(hitType1, hitType2, fitPosition1, fitPosition2, thisProtoHit);
61 
62  if (!protoHit.IsPositionSet() || (thisProtoHit.GetChi2() < protoHit.GetChi2()))
63  protoHit = thisProtoHit;
64  }
65  }
66  }
67 
68  // TODO Add additional chi-squared at edge of detector
69 }
70 
71 //------------------------------------------------------------------------------------------------------------------------------------------
72 
73 void HitCreationBaseTool::GetBestPosition3D(const HitType hitType1, const HitType hitType2, const CartesianVector &fitPosition1,
74  const CartesianVector &fitPosition2, ProtoHit &protoHit) const
75 {
76  // TODO Input better uncertainties into this method (sigmaHit, sigmaFit, sigmaX)
77  const CaloHit *const pCaloHit2D(protoHit.GetParentCaloHit2D());
78  const HitType hitType(pCaloHit2D->GetHitType());
79 
80  const double sigmaFit(LArGeometryHelper::GetSigmaUVW(this->GetPandora()));
81  const double sigmaHit(sigmaFit);
82 
83  CartesianVector position3D(0.f, 0.f, 0.f);
84  double chi2(std::numeric_limits<double>::max());
85 
86  const double u((TPC_VIEW_U == hitType) ? pCaloHit2D->GetPositionVector().GetZ()
87  : (TPC_VIEW_U == hitType1) ? fitPosition1.GetZ() : fitPosition2.GetZ());
88  const double v((TPC_VIEW_V == hitType) ? pCaloHit2D->GetPositionVector().GetZ()
89  : (TPC_VIEW_V == hitType1) ? fitPosition1.GetZ() : fitPosition2.GetZ());
90  const double w((TPC_VIEW_W == hitType) ? pCaloHit2D->GetPositionVector().GetZ()
91  : (TPC_VIEW_W == hitType1) ? fitPosition1.GetZ() : fitPosition2.GetZ());
92 
93  const double sigmaU((TPC_VIEW_U == hitType) ? sigmaHit : sigmaFit);
94  const double sigmaV((TPC_VIEW_V == hitType) ? sigmaHit : sigmaFit);
95  const double sigmaW((TPC_VIEW_W == hitType) ? sigmaHit : sigmaFit);
96 
98  this->GetPandora().GetPlugins()->GetLArTransformationPlugin()->GetMinChiSquaredYZ(u, v, w, sigmaU, sigmaV, sigmaW, bestY, bestZ, chi2);
99  position3D.SetValues(pCaloHit2D->GetPositionVector().GetX(), static_cast<float>(bestY), static_cast<float>(bestZ));
100 
101  const double deltaX1(pCaloHit2D->GetPositionVector().GetX() - fitPosition1.GetX());
102  const double deltaX2(pCaloHit2D->GetPositionVector().GetX() - fitPosition2.GetX());
103  const double chi2X(((deltaX1 * deltaX1) / m_sigmaX2) + ((deltaX2 * deltaX2) / m_sigmaX2));
104 
105  protoHit.SetPosition3D(position3D, chi2 + chi2X);
106  protoHit.AddTrajectorySample(TrajectorySample(fitPosition1, hitType1, sigmaFit));
107  protoHit.AddTrajectorySample(TrajectorySample(fitPosition2, hitType2, sigmaFit));
108 }
109 
110 //------------------------------------------------------------------------------------------------------------------------------------------
111 
112 void HitCreationBaseTool::GetBestPosition3D(const HitType hitType, const CartesianVector &fitPosition, ProtoHit &protoHit) const
113 {
114  // TODO Input better uncertainties into this method (sigmaHit, sigmaFit, sigmaX)
115  const CaloHit *const pCaloHit2D(protoHit.GetParentCaloHit2D());
116  const double sigmaFit(LArGeometryHelper::GetSigmaUVW(this->GetPandora()));
117 
118  if (pCaloHit2D->GetHitType() == hitType)
119  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
120 
121  CartesianVector position3D(0.f, 0.f, 0.f);
122  float chi2(std::numeric_limits<float>::max());
124  this->GetPandora(), pCaloHit2D->GetHitType(), hitType, pCaloHit2D->GetPositionVector(), fitPosition, position3D, chi2);
125 
126  // ATTN Replace chi2 from LArGeometryHelper for consistency with three-view treatment (purely a measure of delta x)
127  const double deltaX(pCaloHit2D->GetPositionVector().GetX() - fitPosition.GetX());
128  const double chi2X((deltaX * deltaX) / m_sigmaX2);
129 
130  protoHit.SetPosition3D(position3D, chi2X);
131  protoHit.AddTrajectorySample(TrajectorySample(fitPosition, hitType, sigmaFit));
132 }
133 
134 //------------------------------------------------------------------------------------------------------------------------------------------
135 
136 StatusCode HitCreationBaseTool::ReadSettings(const pandora::TiXmlHandle xmlHandle)
137 {
138  double sigmaX(std::sqrt(m_sigmaX2));
139 
140  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SigmaX", sigmaX));
141 
142  m_sigmaX2 = sigmaX * sigmaX;
143 
144  if (m_sigmaX2 < std::numeric_limits<double>::epsilon())
145  {
146  std::cout << "HitCreationBaseTool - Invalid parameter, SigmaX: " << sigmaX << std::endl;
147  return STATUS_CODE_INVALID_PARAMETER;
148  }
149 
150  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "ChiSquaredCut", m_chiSquaredCut));
151 
152  return STATUS_CODE_SUCCESS;
153 }
154 
155 } // namespace lar_content
Proto hits are temporary constructs to be used during iterative 3D hit procedure. ...
static float GetSigmaUVW(const pandora::Pandora &pandora, const float maxSigmaDiscrepancy=0.01)
Find the sigmaUVW value for the detector geometry.
static void MergeTwoPositions3D(const pandora::Pandora &pandora, const pandora::HitType view1, const pandora::HitType view2, const pandora::CartesianVector &position1, const pandora::CartesianVector &position2, pandora::CartesianVector &position3D, float &chiSquared)
Merge 2D positions from two views to give unified 3D position.
double m_sigmaX2
The sigmaX squared value, for calculation of chi2 deltaX term.
enum cvn::HType HitType
const pandora::CaloHit * GetParentCaloHit2D() const
Get the address of the parent 2D calo hit.
ThreeDHitCreationAlgorithm::TrajectorySample TrajectorySample
bool IsPositionSet() const
Whether the proto hit position is set.
double m_chiSquaredCut
The chi squared cut (accept only values below the cut value)
void AddTrajectorySample(const TrajectorySample &trajectorySample)
Add a trajectory sample.
Header file for the geometry helper class.
double GetChi2() const
Get the chi squared value.
Header file for the hit creation base tool.
virtual void GetBestPosition3D(const pandora::HitType hitType1, const pandora::HitType hitType2, const pandora::CartesianPointVector &fitPositionList1, const pandora::CartesianPointVector &fitPositionList2, ProtoHit &protoHit) const
Get the three dimensional position using a provided two dimensional calo hit and candidate fit positi...
static int max(int a, int b)
virtual ~HitCreationBaseTool()
Destructor.
void SetPosition3D(const pandora::CartesianVector &position3D, const double chi2)
Set position 3D.
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
QTextStream & endl(QTextStream &s)