LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
LArTwoDSlidingShowerFitResult.cc
Go to the documentation of this file.
1 
9 #include "Objects/Cluster.h"
10 
12 
14 
15 #include <algorithm>
16 #include <cmath>
17 #include <limits>
18 
19 using namespace pandora;
20 
21 namespace lar_content
22 {
23 
24 template <typename T>
25 TwoDSlidingShowerFitResult::TwoDSlidingShowerFitResult(const T *const pT, const unsigned int slidingFitWindow, const float slidingFitLayerPitch,
26  const float showerEdgeMultiplier) :
27  m_showerFitResult(TwoDSlidingFitResult(pT, slidingFitWindow, slidingFitLayerPitch)),
28  m_negativeEdgeFitResult(TwoDSlidingShowerFitResult::LArTwoDShowerEdgeFit(pT, m_showerFitResult, NEGATIVE_SHOWER_EDGE, showerEdgeMultiplier)),
29  m_positiveEdgeFitResult(TwoDSlidingShowerFitResult::LArTwoDShowerEdgeFit(pT, m_showerFitResult, POSITIVE_SHOWER_EDGE, showerEdgeMultiplier))
30 {
31 }
32 
33 //------------------------------------------------------------------------------------------------------------------------------------------
34 
35 void TwoDSlidingShowerFitResult::GetShowerEdges(const float x, const bool widenIfAmbiguity, FloatVector &edgePositions) const
36 {
37  edgePositions.clear();
38  CartesianPointVector fitPositionVector;
39  PANDORA_THROW_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, this->GetNegativeEdgeFitResult().GetGlobalFitPositionListAtX(x, fitPositionVector));
40  PANDORA_THROW_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, this->GetPositiveEdgeFitResult().GetGlobalFitPositionListAtX(x, fitPositionVector));
41 
42  if (fitPositionVector.size() < 2)
43  {
44  float minXn(0.f), maxXn(0.f), minXp(0.f), maxXp(0.f);
45  this->GetNegativeEdgeFitResult().GetMinAndMaxX(minXn, maxXn);
46  this->GetPositiveEdgeFitResult().GetMinAndMaxX(minXp, maxXp);
47  const float minX(std::min(minXn, minXp)), maxX(std::max(maxXn, maxXp));
48 
49  if ((x < minX) || (x > maxX))
50  return;
51 
52  float minZn(0.f), maxZn(0.f), minZp(0.f), maxZp(0.f);
53  this->GetNegativeEdgeFitResult().GetMinAndMaxZ(minZn, maxZn);
54  this->GetPositiveEdgeFitResult().GetMinAndMaxZ(minZp, maxZp);
55  const float minZ(std::min(minZn, minZp)), maxZ(std::max(maxZn, maxZp));
56 
57  if (!widenIfAmbiguity)
58  {
59  return;
60  }
61  else if (fitPositionVector.empty())
62  {
63  fitPositionVector.push_back(CartesianVector(x, 0.f, minZ));
64  fitPositionVector.push_back(CartesianVector(x, 0.f, maxZ));
65  }
66  else if (1 == fitPositionVector.size())
67  {
68  // ATTN Could improve sophistication of choice of second bounding edge
69  const float existingEdge(fitPositionVector.front().GetZ());
70  const float secondEdge((std::fabs(existingEdge - minZ) < std::fabs(existingEdge - maxZ)) ? minZ : maxZ);
71  fitPositionVector.push_back(CartesianVector(x, 0.f, secondEdge));
72  }
73  }
74 
75  FloatVector localEdgePositions;
76  for (const CartesianVector &fitPosition : fitPositionVector)
77  localEdgePositions.push_back(fitPosition.GetZ());
78 
79  if (localEdgePositions.size() < 2)
80  throw StatusCodeException(STATUS_CODE_FAILURE);
81 
82  std::sort(localEdgePositions.begin(), localEdgePositions.end());
83  edgePositions.push_back(localEdgePositions.front());
84  edgePositions.push_back(localEdgePositions.back());
85 }
86 
87 //------------------------------------------------------------------------------------------------------------------------------------------
88 
89 TwoDSlidingFitResult TwoDSlidingShowerFitResult::LArTwoDShowerEdgeFit(const Cluster *const pCluster, const TwoDSlidingFitResult &fullShowerFit,
90  const ShowerEdge showerEdge, const float showerEdgeMultiplier)
91 {
92  CartesianPointVector pointVector;
93  LArClusterHelper::GetCoordinateVector(pCluster, pointVector);
94  return TwoDSlidingShowerFitResult::LArTwoDShowerEdgeFit(&pointVector, fullShowerFit, showerEdge, showerEdgeMultiplier);
95 }
96 
97 //------------------------------------------------------------------------------------------------------------------------------------------
98 
99 TwoDSlidingFitResult TwoDSlidingShowerFitResult::LArTwoDShowerEdgeFit(const CartesianPointVector *const pPointVector,
100  const TwoDSlidingFitResult &fullShowerFit, const ShowerEdge showerEdge, const float showerEdgeMultiplier)
101 {
102  // Examine all possible fit contributions
103  FitCoordinateMap fitCoordinateMap;
104 
105  for (const CartesianVector &hitPosition : *pPointVector)
106  {
107  float rL(0.f), rT(0.f);
108  fullShowerFit.GetLocalPosition(hitPosition, rL, rT);
109  rT *= showerEdgeMultiplier;
110 
111  CartesianVector fullShowerFitPosition(0.f, 0.f, 0.f);
112  if (STATUS_CODE_SUCCESS != fullShowerFit.GetGlobalFitPosition(rL, fullShowerFitPosition))
113  continue;
114 
115  float rLFit(0.f), rTFit(0.f);
116  fullShowerFit.GetLocalPosition(fullShowerFitPosition, rLFit, rTFit);
117 
118  const float rTDiff(rT - rTFit);
119  if (((POSITIVE_SHOWER_EDGE == showerEdge) && (rTDiff < 0.f)) || ((NEGATIVE_SHOWER_EDGE == showerEdge) && (rTDiff > 0.f)))
120  rT = rTFit;
121 
122  const int layer(fullShowerFit.GetLayer(rL));
123  fitCoordinateMap[layer].push_back(FitCoordinate(rL, rT));
124  }
125 
126  // Select fit contributions representing relevant shower edge
127  LayerFitContributionMap layerFitContributionMap;
128 
129  for (const FitCoordinateMap::value_type &mapEntry : fitCoordinateMap)
130  {
131  // ATTN Could modify this hit selection, e.g. add inertia to edge positions
132  bool bestFitCoordinateFound(false);
133  FitCoordinate bestFitCoordinate = (POSITIVE_SHOWER_EDGE == showerEdge) ?
136 
137  for (const FitCoordinate &fitCoordinate : mapEntry.second)
138  {
139  if (((POSITIVE_SHOWER_EDGE == showerEdge) && (fitCoordinate.second > bestFitCoordinate.second)) ||
140  ((NEGATIVE_SHOWER_EDGE == showerEdge) && (fitCoordinate.second < bestFitCoordinate.second)))
141  {
142  bestFitCoordinate = fitCoordinate;
143  bestFitCoordinateFound = true;
144  }
145  }
146 
147  if (bestFitCoordinateFound)
148  layerFitContributionMap[mapEntry.first].AddPoint(bestFitCoordinate.first, bestFitCoordinate.second);
149  }
150 
151  return TwoDSlidingFitResult(fullShowerFit.GetLayerFitHalfWindow(), fullShowerFit.GetLayerPitch(), fullShowerFit.GetAxisIntercept(),
152  fullShowerFit.GetAxisDirection(), fullShowerFit.GetOrthoDirection(), layerFitContributionMap);
153 }
154 
155 //------------------------------------------------------------------------------------------------------------------------------------------
156 //------------------------------------------------------------------------------------------------------------------------------------------
157 
158 template TwoDSlidingShowerFitResult::TwoDSlidingShowerFitResult(const pandora::Cluster *const, const unsigned int, const float, const float);
159 template TwoDSlidingShowerFitResult::TwoDSlidingShowerFitResult(const pandora::CartesianPointVector *const, const unsigned int, const float, const float);
160 
161 } // namespace lar_content
Float_t x
Definition: compare.C:6
unsigned int GetLayerFitHalfWindow() const
Get the layer fit half window.
Header file for the lar two dimensional sliding shower fit result class.
ShowerEdge
ShowerEdge enum.
void GetMinAndMaxX(float &minX, float &maxX) const
Get the minimum and maximum x coordinates associated with the sliding fit.
std::map< int, FitCoordinateList > FitCoordinateMap
static TwoDSlidingFitResult LArTwoDShowerEdgeFit(const pandora::Cluster *const pCluster, const TwoDSlidingFitResult &fullShowerFit, const ShowerEdge showerEdge, const float showerEdgeMultiplier)
Perform two dimensional sliding fit to shower edge, using specified primary axis. ...
const pandora::CartesianVector & GetAxisDirection() const
Get the axis direction vector.
std::map< int, LayerFitContribution > LayerFitContributionMap
const pandora::CartesianVector & GetAxisIntercept() const
Get the axis intercept position.
TFile f
Definition: plotHisto.C:6
void GetMinAndMaxZ(float &minZ, float &maxZ) const
Get the minimum and maximum z coordinates associated with the sliding fit.
Int_t max
Definition: plot.C:27
Header file for the cluster helper class.
pandora::StatusCode GetGlobalFitPosition(const float rL, pandora::CartesianVector &position) const
Get global fit position for a given longitudinal coordinate.
const pandora::CartesianVector & GetOrthoDirection() const
Get the orthogonal direction vector.
float GetLayerPitch() const
Get the layer pitch, units cm.
const TwoDSlidingFitResult & GetPositiveEdgeFitResult() const
Get the sliding fit result for the positive shower edge.
Int_t min
Definition: plot.C:26
const TwoDSlidingFitResult & GetNegativeEdgeFitResult() const
Get the sliding fit result for the negative shower edge.
static void GetCoordinateVector(const pandora::Cluster *const pCluster, pandora::CartesianPointVector &coordinateVector)
Get vector of hit coordinates from an input cluster.
TwoDSlidingShowerFitResult(const T *const pT, const unsigned int slidingFitWindow, const float slidingFitLayerPitch, const float showerEdgeMultiplier=1.f)
Constructor.
void GetLocalPosition(const pandora::CartesianVector &position, float &rL, float &rT) const
Get local sliding fit coordinates for a given global position.
int GetLayer(const float rL) const
Get layer number for given sliding linear fit longitudinal coordinate.
void GetShowerEdges(const float x, const bool widenIfAmbiguity, pandora::FloatVector &edgePositions) const
Get the most appropriate shower edges at a given x coordinate.