9 #include "Pandora/AlgorithmHeaders.h" 21 RPhiFeatureTool::RPhiFeatureTool() :
22 m_fastScoreCheck(true),
23 m_fastScoreOnly(false),
25 m_kernelEstimateSigma(0.048
f),
27 m_maxHitVertexDisplacement1D(100.
f),
28 m_minFastScoreFraction(0.8
f),
29 m_fastHistogramNPhiBins(200),
30 m_fastHistogramPhiMin(-1.1
f * M_PI),
31 m_fastHistogramPhiMax(+1.1
f * M_PI),
41 const float beamDeweightingScore,
float &bestFastScore)
43 if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
44 std::cout <<
"----> Running Algorithm Tool: " << this->GetInstanceName() <<
", " << this->GetType() << std::endl;
50 this->
FillKernelEstimate(pVertex, TPC_VIEW_U, kdTreeMap.at(TPC_VIEW_U), kernelEstimateU);
51 this->
FillKernelEstimate(pVertex, TPC_VIEW_V, kdTreeMap.at(TPC_VIEW_V), kernelEstimateV);
52 this->
FillKernelEstimate(pVertex, TPC_VIEW_W, kdTreeMap.at(TPC_VIEW_W), kernelEstimateW);
54 const float expBeamDeweightingScore = std::exp(beamDeweightingScore);
58 const float fastScore(this->
GetFastScore(kernelEstimateU, kernelEstimateV, kernelEstimateW));
62 featureVector.push_back(fastScore);
68 featureVector.push_back(0.);
72 if (expBeamDeweightingScore * fastScore > bestFastScore)
73 bestFastScore = expBeamDeweightingScore * fastScore;
77 this->
GetMidwayScore(kernelEstimateU, kernelEstimateV, kernelEstimateW));
89 for (
const KernelEstimate::ContributionList::value_type &contribution : kernelEstimateU.
GetContributionList())
90 histogramU.Fill(contribution.first, contribution.second);
92 for (
const KernelEstimate::ContributionList::value_type &contribution : kernelEstimateV.
GetContributionList())
93 histogramV.Fill(contribution.first, contribution.second);
95 for (
const KernelEstimate::ContributionList::value_type &contribution : kernelEstimateW.
GetContributionList())
96 histogramW.Fill(contribution.first, contribution.second);
99 histogramU.Scale(1.
f/histogramU.GetCumulativeSum());
100 histogramV.Scale(1.
f/histogramV.GetCumulativeSum());
101 histogramW.Scale(1.
f/histogramW.GetCumulativeSum());
104 float figureOfMerit(0.
f);
106 for (
int xBin = 0; xBin < histogramU.GetNBinsX(); ++xBin)
108 const float binContentU(histogramU.GetBinContent(xBin));
109 const float binContentV(histogramV.GetBinContent(xBin));
110 const float binContentW(histogramW.GetBinContent(xBin));
111 figureOfMerit += binContentU * binContentU + binContentV * binContentV + binContentW * binContentW;
114 return figureOfMerit;
126 for (
const KernelEstimate::ContributionList::value_type &contribution : kernelEstimateU.
GetContributionList())
127 histogramU.Fill(contribution.first, contribution.second);
129 for (
const KernelEstimate::ContributionList::value_type &contribution : kernelEstimateV.
GetContributionList())
130 histogramV.Fill(contribution.first, contribution.second);
132 for (
const KernelEstimate::ContributionList::value_type &contribution : kernelEstimateW.
GetContributionList())
133 histogramW.Fill(contribution.first, contribution.second);
135 float figureOfMerit(0.
f);
137 for (
int xBin = 0; xBin < histogramU.GetNBinsX(); ++xBin)
139 const float binCenter(histogramU.GetXLow() + (
static_cast<float>(xBin) + 0.5
f) * histogramU.GetXBinWidth());
140 figureOfMerit += histogramU.GetBinContent(xBin) * kernelEstimateU.
Sample(binCenter);
141 figureOfMerit += histogramV.GetBinContent(xBin) * kernelEstimateV.
Sample(binCenter);
142 figureOfMerit += histogramW.GetBinContent(xBin) * kernelEstimateW.
Sample(binCenter);
145 return figureOfMerit;
153 float figureOfMerit(0.
f);
155 for (
const KernelEstimate::ContributionList::value_type &contribution : kernelEstimateU.
GetContributionList())
156 figureOfMerit += contribution.second * kernelEstimateU.
Sample(contribution.first);
158 for (
const KernelEstimate::ContributionList::value_type &contribution : kernelEstimateV.
GetContributionList())
159 figureOfMerit += contribution.second * kernelEstimateV.
Sample(contribution.first);
161 for (
const KernelEstimate::ContributionList::value_type &contribution : kernelEstimateW.
GetContributionList())
162 figureOfMerit += contribution.second * kernelEstimateW.
Sample(contribution.first);
164 return figureOfMerit;
176 kdTree.
search(searchRegionHits, found);
178 for (
const auto &
hit : found)
180 const CartesianVector displacement(
hit.data->GetPositionVector() - vertexPosition2D);
181 const float magnitude(displacement.GetMagnitude());
183 if (magnitude < std::numeric_limits<float>::epsilon())
186 float phi(this->
atan2Fast(displacement.GetZ(), displacement.GetX()));
203 const float ONE_QTR_PI(0.25
f * M_PI);
204 const float THR_QTR_PI(0.75
f * M_PI);
206 const float abs_y(
std::max(std::fabs(y), std::numeric_limits<float>::epsilon()));
207 const float abs_x(std::fabs(x));
209 const float r((x < 0.
f) ? (x + abs_y) / (abs_y + abs_x) : (abs_x - abs_y) / (abs_x + abs_y));
210 const float angle(((x < 0.
f) ? THR_QTR_PI : ONE_QTR_PI) + (0.1963
f * r * r - 0.9817
f) * r);
212 return ((y < 0.
f) ? -angle : angle);
225 const float gaussConstant(1.
f / std::sqrt(2.
f * M_PI * m_sigma * m_sigma));
229 const float deltaSigma((x - iter->first) / m_sigma);
230 const float gaussian(gaussConstant * std::exp(-0.5
f * deltaSigma * deltaSigma));
231 sample += iter->second * gaussian;
241 m_contributionList.insert(ContributionList::value_type(x, weight));
248 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
251 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
254 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
257 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
260 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
263 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
266 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
269 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
272 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
275 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
278 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
281 return STATUS_CODE_SUCCESS;
bool m_fastScoreCheck
Whether to use the fast histogram based score to selectively avoid calling full or midway scores...
Header file for the kd tree linker algo template class.
MvaTypes::MvaFeatureVector MvaFeatureVector
void Run(LArMvaHelper::MvaFeatureVector &featureVector, const VertexSelectionBaseAlgorithm *const pAlgorithm, const pandora::Vertex *const pVertex, const VertexSelectionBaseAlgorithm::SlidingFitDataListMap &, const VertexSelectionBaseAlgorithm::ClusterListMap &, const VertexSelectionBaseAlgorithm::KDTreeMap &kdTreeMap, const VertexSelectionBaseAlgorithm::ShowerClusterListMap &, const float beamDeweightingScore, float &bestFastScore)
Run the tool.
unsigned int m_fastHistogramNPhiBins
Number of bins to use for fast score histograms.
Class that implements the KDTree partition of 2D space and a closest point search algorithm...
Box structure used to define 2D field. It's used in KDTree building step to divide the detector space...
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
float m_fastHistogramPhiMin
Min value for fast score histograms.
static pandora::CartesianVector ProjectPosition(const pandora::Pandora &pandora, const pandora::CartesianVector &position3D, const pandora::HitType view)
Project 3D position into a given 2D view.
float m_kappa
Hit-deweighting offset, of form: weight = 1 / sqrt(distance + kappa), units cm.
bool m_fastScoreOnly
Whether to use the fast histogram based score only.
const ContributionList & GetContributionList() const
Get the contribution list.
float m_minFastScoreFraction
Fast score must be at least this fraction of best fast score to calculate full score.
float atan2Fast(const float y, const float x) const
Fast estimate of std::atan2 function. Rather coarse (max |error| > 0.01) but should suffice for this ...
Header file for the geometry helper class.
std::vector< HitKDNode2D > HitKDNode2DList
void search(const KDTreeBoxT< DIM > &searchBox, std::vector< KDTreeNodeInfoT< DATA, DIM > > &resRecHitList)
Search in the KDTree for all points that would be contained in the given searchbox The founded points...
std::map< pandora::HitType, const ShowerClusterList > ShowerClusterListMap
Map of shower cluster lists for passing to tools.
float GetFastScore(const KernelEstimate &kernelEstimateU, const KernelEstimate &kernelEstimateV, const KernelEstimate &kernelEstimateW) const
Get the score for a trio of kernel estimations, using fast histogram approach.
Header file for the cluster helper class.
float Sample(const float x) const
Sample the parameterised distribution at a specified x coordinate.
float m_maxHitVertexDisplacement1D
Max hit-vertex displacement in any one dimension for contribution to kernel estimation.
float GetFullScore(const KernelEstimate &kernelEstimateU, const KernelEstimate &kernelEstimateV, const KernelEstimate &kernelEstimateW) const
Get the score for a trio of kernel estimations, using kernel density estimation and full hit-by-hit s...
float m_fastHistogramPhiMax
Max value for fast score histograms.
bool m_fullScore
Whether to use the full kernel density estimation score, as opposed to the midway score...
std::map< pandora::HitType, const pandora::ClusterList & > ClusterListMap
Map array of cluster lists for passing to tools.
float m_kernelEstimateSigma
The Gaussian width to use for kernel estimation.
VertexSelectionBaseAlgorithm class.
bool m_enableFolding
Whether to enable folding of -pi -> +pi phi distribution into 0 -> +pi region only.
Detector simulation of raw signals on wires.
std::map< pandora::HitType, const SlidingFitDataList > SlidingFitDataListMap
Map of sliding fit data lists for passing to tools.
float GetMidwayScore(const KernelEstimate &kernelEstimateU, const KernelEstimate &kernelEstimateV, const KernelEstimate &kernelEstimateW) const
Get the score for a trio of kernel estimations, using kernel density estimation but with reduced (bin...
void FillKernelEstimate(const pandora::Vertex *const pVertex, const pandora::HitType hitType, VertexSelectionBaseAlgorithm::HitKDTree2D &kdTree, KernelEstimate &kernelEstimate) const
Use hits in clusters (in the provided kd tree) to fill a provided kernel estimate with hit-vertex rel...
void AddContribution(const float x, const float weight)
Add a contribution to the distribution.
std::multimap< float, float > ContributionList
Map from x coord to weight, ATTN avoid map.find, etc. with float key.
std::map< pandora::HitType, const std::reference_wrapper< HitKDTree2D > > KDTreeMap
Map array of hit kd trees for passing to tools.
KDTreeBox build_2d_kd_search_region(const pandora::CaloHit *const point, const float x_span, const float z_span)
build_2d_kd_search_region