9 #include "Pandora/AlgorithmHeaders.h"
20 HitCreationBaseTool::HitCreationBaseTool() : m_sigmaX2(1.), m_chiSquaredCut(1.)
33 const CartesianPointVector &fitPositionList2, ProtoHit &protoHit)
const
35 if (fitPositionList1.empty() && fitPositionList2.empty())
37 throw StatusCodeException(STATUS_CODE_NOT_FOUND);
39 else if (fitPositionList1.empty())
41 if (fitPositionList2.size() != 1)
42 throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
46 else if (fitPositionList2.empty())
48 if (fitPositionList1.size() != 1)
49 throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
55 for (
const CartesianVector &fitPosition1 : fitPositionList1)
57 for (
const CartesianVector &fitPosition2 : fitPositionList2)
59 ProtoHit thisProtoHit(protoHit.GetParentCaloHit2D());
60 this->
GetBestPosition3D(hitType1, hitType2, fitPosition1, fitPosition2, thisProtoHit);
62 if (!protoHit.IsPositionSet() || (thisProtoHit.GetChi2() < protoHit.GetChi2()))
63 protoHit = thisProtoHit;
74 const CartesianVector &fitPosition2, ProtoHit &protoHit)
const
77 const CaloHit *
const pCaloHit2D(protoHit.GetParentCaloHit2D());
78 const HitType hitType(pCaloHit2D->GetHitType());
81 const double sigmaHit(sigmaFit);
83 CartesianVector position3D(0.f, 0.f, 0.f);
84 double chi2(std::numeric_limits<double>::max());
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());
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);
97 double bestY(std::numeric_limits<double>::max()), bestZ(std::numeric_limits<double>::max());
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));
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));
105 protoHit.SetPosition3D(position3D, chi2 + chi2X);
106 protoHit.AddTrajectorySample(
TrajectorySample(fitPosition1, hitType1, sigmaFit));
107 protoHit.AddTrajectorySample(
TrajectorySample(fitPosition2, hitType2, sigmaFit));
115 const CaloHit *
const pCaloHit2D(protoHit.GetParentCaloHit2D());
118 if (pCaloHit2D->GetHitType() == hitType)
119 throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
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);
127 const double deltaX(pCaloHit2D->GetPositionVector().GetX() - fitPosition.GetX());
128 const double chi2X((deltaX * deltaX) /
m_sigmaX2);
130 protoHit.SetPosition3D(position3D, chi2X);
131 protoHit.AddTrajectorySample(
TrajectorySample(fitPosition, hitType, sigmaFit));
140 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"SigmaX", sigmaX));
144 if (
m_sigmaX2 < std::numeric_limits<double>::epsilon())
146 std::cout <<
"HitCreationBaseTool - Invalid parameter, SigmaX: " << sigmaX << std::endl;
147 return STATUS_CODE_INVALID_PARAMETER;
150 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"ChiSquaredCut",
m_chiSquaredCut));
152 return STATUS_CODE_SUCCESS;
ThreeDHitCreationAlgorithm::ProtoHit ProtoHit
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.
ThreeDHitCreationAlgorithm::TrajectorySample TrajectorySample
double m_chiSquaredCut
The chi squared cut (accept only values below the cut value)
Header file for the geometry helper class.
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...
required by fuzzyCluster table::sbnd_g4_services gaushitTruthMatch pandora
virtual ~HitCreationBaseTool()
Destructor.
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
BEGIN_PROLOG could also be cout