22 m_fastScoreCheck(true),
23 m_fastScoreOnly(false),
25 m_kernelEstimateSigma(0.048f),
27 m_maxHitVertexDisplacement1D(100.f),
28 m_minFastScoreFraction(0.8f),
29 m_fastHistogramNPhiBins(200),
30 m_fastHistogramPhiMin(-1.1f * M_PI),
31 m_fastHistogramPhiMax(+1.1f * M_PI),
44 std::cout <<
"----> Running Algorithm Tool: " << this->
GetInstanceName() <<
", " << this->
GetType() << std::endl;
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));
88 for (
const KernelEstimate::ContributionList::value_type &contribution : kernelEstimateU.
GetContributionList())
89 histogramU.
Fill(contribution.first, contribution.second);
91 for (
const KernelEstimate::ContributionList::value_type &contribution : kernelEstimateV.
GetContributionList())
92 histogramV.
Fill(contribution.first, contribution.second);
94 for (
const KernelEstimate::ContributionList::value_type &contribution : kernelEstimateW.
GetContributionList())
95 histogramW.
Fill(contribution.first, contribution.second);
103 float figureOfMerit(0.f);
105 for (
int xBin = 0; xBin < histogramU.
GetNBinsX(); ++xBin)
110 figureOfMerit += binContentU * binContentU + binContentV * binContentV + binContentW * binContentW;
113 return figureOfMerit;
124 for (
const KernelEstimate::ContributionList::value_type &contribution : kernelEstimateU.
GetContributionList())
125 histogramU.
Fill(contribution.first, contribution.second);
127 for (
const KernelEstimate::ContributionList::value_type &contribution : kernelEstimateV.
GetContributionList())
128 histogramV.
Fill(contribution.first, contribution.second);
130 for (
const KernelEstimate::ContributionList::value_type &contribution : kernelEstimateW.
GetContributionList())
131 histogramW.
Fill(contribution.first, contribution.second);
133 float figureOfMerit(0.f);
135 for (
int xBin = 0; xBin < histogramU.
GetNBinsX(); ++xBin)
137 const float binCenter(histogramU.
GetXLow() + (
static_cast<float>(xBin) + 0.5f) * histogramU.
GetXBinWidth());
143 return figureOfMerit;
150 float figureOfMerit(0.f);
152 for (
const KernelEstimate::ContributionList::value_type &contribution : kernelEstimateU.
GetContributionList())
153 figureOfMerit += contribution.second * kernelEstimateU.
Sample(contribution.first);
155 for (
const KernelEstimate::ContributionList::value_type &contribution : kernelEstimateV.
GetContributionList())
156 figureOfMerit += contribution.second * kernelEstimateV.
Sample(contribution.first);
158 for (
const KernelEstimate::ContributionList::value_type &contribution : kernelEstimateW.
GetContributionList())
159 figureOfMerit += contribution.second * kernelEstimateW.
Sample(contribution.first);
161 return figureOfMerit;
173 kdTree.
search(searchRegionHits, found);
175 for (
const auto &hit : found)
177 const CartesianVector displacement(hit.data->GetPositionVector() - vertexPosition2D);
180 if (magnitude < std::numeric_limits<float>::epsilon())
184 float weight(1.f / (std::sqrt(magnitude + std::fabs(
m_kappa))));
200 const float ONE_QTR_PI(0.25f * M_PI);
201 const float THR_QTR_PI(0.75f * M_PI);
203 const float abs_y(std::max(std::fabs(y), std::numeric_limits<float>::epsilon()));
204 const float abs_x(std::fabs(x));
206 const float r((x < 0.f) ? (x + abs_y) / (abs_y + abs_x) : (abs_x - abs_y) / (abs_x + abs_y));
207 const float angle(((x < 0.f) ? THR_QTR_PI : ONE_QTR_PI) + (0.1963f * r * r - 0.9817f) * r);
209 return ((y < 0.f) ? -angle : angle);
218 ContributionList::const_iterator lowerIter(contributionList.lower_bound(x - 3.f *
m_sigma));
219 ContributionList::const_iterator upperIter(contributionList.upper_bound(x + 3.f *
m_sigma));
222 const float gaussConstant(1.f / std::sqrt(2.f * M_PI *
m_sigma *
m_sigma));
224 for (ContributionList::const_iterator iter = lowerIter; iter != upperIter; ++iter)
226 const float deltaSigma((x - iter->first) /
m_sigma);
227 const float gaussian(gaussConstant * std::exp(-0.5f * deltaSigma * deltaSigma));
228 sample += iter->second * gaussian;
238 m_contributionList.insert(ContributionList::value_type(x, weight));
273 return STATUS_CODE_SUCCESS;
Header file for the kd tree linker algo template class.
Header file for the cluster helper class.
Header file for the geometry helper class.
#define PANDORA_RETURN_RESULT_IF_AND_IF(StatusCode1, StatusCode2, Operator, Command)
static const pandora::PandoraSettings * GetSettings(const pandora::Algorithm &algorithm)
Get the pandora settings instance.
Box structure used to define 2D field. It's used in KDTree building step to divide the detector space...
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...
static pandora::CartesianVector ProjectPosition(const pandora::Pandora &pandora, const pandora::CartesianVector &position3D, const pandora::HitType view)
Project 3D position into a given 2D view.
MvaTypes::MvaFeatureVector MvaFeatureVector
const float m_sigma
The assigned width.
const ContributionList & GetContributionList() const
Get the contribution list.
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.
float Sample(const float x) const
Sample the parameterised distribution at a specified x coordinate.
bool m_fullScore
Whether to use the full kernel density estimation score, as opposed to the midway score.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read the algorithm settings.
bool m_enableFolding
Whether to enable folding of -pi -> +pi phi distribution into 0 -> +pi region only.
bool m_fastScoreOnly
Whether to use the fast histogram based score only.
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_maxHitVertexDisplacement1D
Max hit-vertex displacement in any one dimension for contribution to kernel estimation.
float m_fastHistogramPhiMin
Min value for fast score histograms.
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 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.
float m_fastHistogramPhiMax
Max value for fast score histograms.
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 ...
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...
bool m_fastScoreCheck
Whether to use the fast histogram based score to selectively avoid calling full or midway scores.
float m_kappa
Hit-deweighting offset, of form: weight = 1 / sqrt(distance + kappa), units cm.
float m_kernelEstimateSigma
The Gaussian width to use for kernel estimation.
unsigned int m_fastHistogramNPhiBins
Number of bins to use for fast score histograms.
RPhiFeatureTool()
Default constructor.
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.
float m_minFastScoreFraction
Fast score must be at least this fraction of best fast score to calculate full score.
VertexSelectionBaseAlgorithm class.
std::map< pandora::HitType, const SlidingFitDataList > SlidingFitDataListMap
Map of sliding fit data lists for passing to tools.
std::map< pandora::HitType, const pandora::ClusterList & > ClusterListMap
Map array of cluster lists for passing to tools.
std::map< pandora::HitType, const std::reference_wrapper< HitKDTree2D > > KDTreeMap
Map array of hit kd trees for passing to tools.
std::vector< HitKDNode2D > HitKDNode2DList
std::map< pandora::HitType, const ShowerClusterList > ShowerClusterListMap
Map of shower cluster lists for passing to tools.
float GetX() const
Get the cartesian x coordinate.
float GetZ() const
Get the cartesian z coordinate.
float GetMagnitude() const
Get the magnitude.
int GetNBinsX() const
Get the number of x bins.
float GetCumulativeSum() const
Get the cumulative sum of bin entries in the histogram (ignores overflow and underflow bins)
void Fill(const float valueX, const float weight=1.f)
Add an entry to the histogram.
float GetXBinWidth() const
Get the x bin width.
float GetBinContent(const int binX) const
Get the content of a specified bin.
float GetXLow() const
Get the min binned x value.
void Scale(const float scaleFactor)
Scale contents of all histogram bins by a specified factor.
bool ShouldDisplayAlgorithmInfo() const
Whether to display algorithm information during processing.
const std::string & GetType() const
Get the type.
const Pandora & GetPandora() const
Get the associated pandora instance.
const std::string & GetInstanceName() const
Get the instance name.
const CartesianVector & GetPosition() const
Get the vertex position.
static StatusCode ReadValue(const TiXmlHandle &xmlHandle, const std::string &xmlElementName, T &t)
Read a value from an xml element.
KDTreeBox build_2d_kd_search_region(const pandora::CaloHit *const point, const float x_span, const float z_span)
build_2d_kd_search_region
HitType
Calorimeter hit type enum.
StatusCode
The StatusCode enum.