24 m_nMaxMatrixToolRepeats(1000),
25 m_downsampleFactor(5),
27 m_nPermutations(1000),
28 m_localMatchingScoreThreshold(0.99f),
29 m_maxDotProduct(0.998f),
30 m_minOverallMatchingScore(0.1f),
31 m_minOverallLocallyMatchedFraction(0.1f),
32 m_randomNumberGenerator(static_cast<std::mt19937::result_type>(0))
47 this->
GetMatchingControl().GetOverlapMatrix().SetOverlapResult(pCluster1, pCluster2, overlapResult);
55 UIntSet daughterVolumeIntersection;
58 if (daughterVolumeIntersection.empty())
59 return STATUS_CODE_NOT_FOUND;
62 return STATUS_CODE_NOT_FOUND;
64 float xMin1(0.f), xMax1(0.f), xMin2(0.f), xMax2(0.f);
69 if (twoViewXOverlap.
GetXSpan0() < std::numeric_limits<float>::epsilon() || twoViewXOverlap.
GetXSpan1() < std::numeric_limits<float>::epsilon())
73 return STATUS_CODE_NOT_FOUND;
77 float zMin1(0.f), zMax1(0.f);
78 float zMin2(0.f), zMax2(0.f);
81 const CartesianVector boundingBoxMin1(xOverlapMin, 0.f, zMin1), boundingBoxMax1(xOverlapMax, 0.f, zMax1);
82 const CartesianVector boundingBoxMin2(xOverlapMin, 0.f, zMin2), boundingBoxMax2(xOverlapMax, 0.f, zMax2);
88 if (
m_minSamples > std::min(overlapHits1.size(), overlapHits2.size()))
89 return STATUS_CODE_NOT_FOUND;
93 const unsigned int nSamples(
98 inputData1.emplace_back(pCaloHit->GetPositionVector().GetX(), pCaloHit->GetInputEnergy());
102 inputData2.emplace_back(pCaloHit->GetPositionVector().GetX(), pCaloHit->GetInputEnergy());
108 for (
unsigned int iSample = 0; iSample < nSamples; ++iSample)
110 resamplingPointsX.emplace_back(
111 (xOverlapMin + (xOverlapMax - xOverlapMin) *
static_cast<float>(iSample + 1) /
static_cast<float>(nSamples + 1)));
117 const float correlation(
123 const float matchingScore(1.f - pvalue);
125 return STATUS_CODE_NOT_FOUND;
129 const int nComparisons(
static_cast<int>(resampledDiscreteProbabilityVector1.
GetSize()) - (
static_cast<int>(
m_minSamples) - 1));
130 if (1 > nComparisons)
133 const float locallyMatchedFraction(
static_cast<float>(nLocallyMatchedSamplingPoints) /
static_cast<float>(nComparisons));
135 return STATUS_CODE_NOT_FOUND;
138 matchingScore,
m_downsampleFactor, nComparisons, nLocallyMatchedSamplingPoints, correlation, twoViewXOverlap);
140 return STATUS_CODE_SUCCESS;
148 if (discreteProbabilityVector1.
GetSize() != discreteProbabilityVector2.
GetSize() ||
149 0 == discreteProbabilityVector1.
GetSize() * discreteProbabilityVector2.
GetSize())
150 throw STATUS_CODE_INVALID_PARAMETER;
153 throw STATUS_CODE_INVALID_PARAMETER;
156 unsigned int nMatchedComparisons(0);
158 for (
unsigned int iValue = 0; iValue < discreteProbabilityVector1.
GetSize(); ++iValue)
160 localValues1.emplace_back(discreteProbabilityVector1.
GetProbability(iValue));
161 localValues2.emplace_back(discreteProbabilityVector2.
GetProbability(iValue));
164 float localPValue(0);
172 std::cout <<
"TwoViewTransverseTracksAlgorithm: failed to calculate correlation coefficient p-value for these numbers" << std::endl;
174 std::cout <<
"----view 0: ";
175 for (
unsigned int iElement = 0; iElement < localValues1.size(); ++iElement)
176 std::cout << localValues1.at(iElement) <<
" ";
177 std::cout << std::endl;
178 std::cout <<
"----view 1: ";
179 for (
unsigned int iElement = 0; iElement < localValues2.size(); ++iElement)
180 std::cout << localValues2.at(iElement) <<
" ";
181 std::cout << std::endl;
185 nMatchedComparisons++;
187 localValues1.erase(localValues1.begin());
188 localValues2.erase(localValues2.begin());
191 return nMatchedComparisons;
215 unsigned int repeatCounter(0);
218 if ((*iter)->Run(
this, this->GetMatchingControl().GetOverlapMatrix()))
239 for (AlgorithmToolVector::const_iterator iter = algorithmToolVector.begin(), iterEnd = algorithmToolVector.end(); iter != iterEnd; ++iter)
243 if (!pTransverseMatrixTool)
244 return STATUS_CODE_INVALID_PARAMETER;
Header file for the cluster helper class.
Header file for the discrete probability helper class.
Header file for the geometry helper class.
Header file for the principal curve analysis helper class.
#define PANDORA_THROW_RESULT_IF_AND_IF(StatusCode1, StatusCode2, Operator, Command)
#define PANDORA_RETURN_RESULT_IF_AND_IF(StatusCode1, StatusCode2, Operator, Command)
#define PANDORA_RETURN_RESULT_IF(StatusCode1, Operator, Command)
Header file for the two view transverse tracks algorithm class.
DiscreteProbabilityVector class.
pandora::FloatVector ResamplingPoints
float GetProbability(const unsigned int index) const
Get the probability value of the element in the vector.
unsigned int GetSize() const
Get the size of the probability vector.
InputData< float, float > AllFloatInputData
static void GetCoordinateVector(const pandora::Cluster *const pCluster, pandora::CartesianPointVector &coordinateVector)
Get vector of hit coordinates from an input cluster.
static void GetCaloHitListInBoundingBox(const pandora::Cluster *const pCluster, const pandora::CartesianVector &lowerBound, const pandora::CartesianVector &upperBound, pandora::CaloHitList &caloHitList)
Get list of Calo hits from an input cluster that are contained in a bounding box. The hits are sorted...
static float CalculateCorrelationCoefficientPValueFromPermutationTest(const T &t1, const T &t2, std::mt19937 &randomNumberGenerator, const unsigned int nPermutations)
Calculate P value for measured correlation coefficient between two datasets via a permutation test.
static float CalculateCorrelationCoefficient(const T &t1, const T &t2)
Calculate the correlation coefficient between two datasets.
static void GetCommonDaughterVolumes(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, UIntSet &intersect)
Return the set of common daughter volumes between two 2D clusters.
std::vector< pandora::CartesianVector > EigenVectors
static void RunPca(const T &t, pandora::CartesianVector ¢roid, EigenValues &outputEigenValues, EigenVectors &outputEigenVectors)
Run principal component analysis using input calo hits (TPC_VIEW_U,V,W or TPC_3D; all treated as 3D p...
MatchingType & GetMatchingControl()
Get the matching control.
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
bool IsInitialized() const
Whether the track overlap result has been initialized.
TransverseMatrixTool class.
TwoViewTransverseOverlapResult class.
void ExamineOverlapContainer()
Examine contents of overlap container, collect together best-matching 2D particles and modify cluster...
float GetPrimaryAxisDotDriftAxis(const pandora::Cluster *const pCluster)
Get the dot product between the cluster's primary axis and the drift axis.
void CalculateOverlapResult(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const pandora::Cluster *const)
Calculate cluster overlap result and store in container.
unsigned int CalculateNumberOfLocallyMatchingSamplingPoints(const DiscreteProbabilityVector &discreteProbabilityVector1, const DiscreteProbabilityVector &discreteProbabilityVector2, std::mt19937 &randomNumberGenerator)
Calculates the number of the sliding windows that contains charge bins that locally match.
TwoViewTransverseTracksAlgorithm()
Default constructor.
unsigned int m_nPermutations
The number of permutations for calculating p-values.
std::set< unsigned int > UIntSet
float m_minOverallMatchingScore
M The maximum allowed cluster primary qxis Dot drift axis to fill the overlap result.
unsigned int m_minSamples
The minimum number of samples needed for comparing charges.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read the algorithm settings.
float m_localMatchingScoreThreshold
The minimum score to classify a local region as matching.
unsigned int m_downsampleFactor
The downsampling (hit merging) applied to hits in the overlap region.
float m_minOverallLocallyMatchedFraction
The minimum required lcoally matched fraction to fill the overlap result.
unsigned int m_nMaxMatrixToolRepeats
The maximum number of repeat loops over matrix tools.
std::mt19937 m_randomNumberGenerator
The random number generator.
MatrixToolVector m_algorithmToolVector
The algorithm tool vector.
float GetTwoViewXOverlapMin() const
Get the x overlap max X value.
float GetXSpan1() const
Get the x span in the view 1.
float GetXSpan0() const
Get the x span in the view 0.
float GetTwoViewXOverlapSpan() const
Get the x overlap span.
float GetTwoViewXOverlapMax() const
Get the x overlap min X value.
float GetDotProduct(const CartesianVector &rhs) const
Get the dot product of the cartesian vector with a second cartesian vector.
const OrderedCaloHitList & GetOrderedCaloHitList() const
Get the ordered calo hit list.
void GetClusterSpanX(float &xmin, float &xmax) const
Get minimum and maximum X positions of the calo hits in this cluster.
void GetClusterSpanZ(const float xmin, const float xmax, float &zmin, float &zmax) const
Get upper and lower Z positions of the calo hits in a cluster in range xmin to xmax.
unsigned int size() const
Returns the number of elements in the container.
StatusCodeException class.
static StatusCode ReadValue(const TiXmlHandle &xmlHandle, const std::string &xmlElementName, T &t)
Read a value from an xml element.
static StatusCode ProcessAlgorithmToolList(const Algorithm &algorithm, const TiXmlHandle &xmlHandle, const std::string &listName, AlgorithmToolVector &algorithmToolVector)
Process a list of algorithms tools in an xml file.
std::vector< CartesianVector > CartesianPointVector
std::vector< AlgorithmTool * > AlgorithmToolVector
MANAGED_CONTAINER< const CaloHit * > CaloHitList
std::vector< float > FloatVector
StatusCode
The StatusCode enum.