LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
lar_content::TwoDLinearFitFeatureTool Class Referenceabstract

TwoDLinearFitFeatureTool class for the calculation of variables related to 2d sliding linear fit. More...

#include "TrackShowerIdFeatureTool.h"

Inheritance diagram for lar_content::TwoDLinearFitFeatureTool:
lar_content::MvaFeatureTool< Ts >

Public Types

typedef std::vector< MvaFeatureTool< Ts... > * > FeatureToolVector
 
typedef std::map< std::string, MvaFeatureTool< Ts... > * > FeatureToolMap
 

Public Member Functions

 TwoDLinearFitFeatureTool ()
 Default constructor. More...
 
void Run (LArMvaHelper::MvaFeatureVector &featureVector, const pandora::Algorithm *const pAlgorithm, const pandora::Cluster *const pCluster)
 
void Run (LArMvaHelper::MvaFeatureMap &featureMap, pandora::StringVector &featureOrder, const std::string &featureToolName, const pandora::Algorithm *const pAlgorithm, const pandora::Cluster *const pCluster)
 
virtual void Run (MvaTypes::MvaFeatureVector &featureVector, Ts...args)=0
 Run the algorithm tool. More...
 
virtual void Run (MvaTypes::MvaFeatureMap &featureMap, pandora::StringVector &featureOrder, const std::string &featureToolName, Ts...)
 

Private Member Functions

pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle)
 
void CalculateVariablesSlidingLinearFit (const pandora::Cluster *const pCluster, float &straightLineLengthLarge, float &diffWithStraigthLineMean, float &diffWithStraightLineSigma, float &dTdLWidth, float &maxFitGapLength, float &rmsSlidingLinearFit) const
 Calculation of several variables related to sliding linear fit. More...
 

Private Attributes

unsigned int m_slidingLinearFitWindow
 The sliding linear fit window. More...
 
unsigned int m_slidingLinearFitWindowLarge
 The sliding linear fit window - should be large, providing a simple linear fit. More...
 

Detailed Description

TwoDLinearFitFeatureTool class for the calculation of variables related to 2d sliding linear fit.

Definition at line 60 of file TrackShowerIdFeatureTool.h.

Member Typedef Documentation

template<typename... Ts>
typedef std::map<std::string, MvaFeatureTool<Ts...> *> lar_content::MvaFeatureTool< Ts >::FeatureToolMap
inherited

Definition at line 37 of file LArMvaHelper.h.

template<typename... Ts>
typedef std::vector<MvaFeatureTool<Ts...> *> lar_content::MvaFeatureTool< Ts >::FeatureToolVector
inherited

Definition at line 36 of file LArMvaHelper.h.

Constructor & Destructor Documentation

lar_content::TwoDLinearFitFeatureTool::TwoDLinearFitFeatureTool ( )

Default constructor.

Definition at line 90 of file TrackShowerIdFeatureTool.cc.

90  :
93 {
94 }
unsigned int m_slidingLinearFitWindow
The sliding linear fit window.
unsigned int m_slidingLinearFitWindowLarge
The sliding linear fit window - should be large, providing a simple linear fit.

Member Function Documentation

void lar_content::TwoDLinearFitFeatureTool::CalculateVariablesSlidingLinearFit ( const pandora::Cluster *const  pCluster,
float &  straightLineLengthLarge,
float &  diffWithStraigthLineMean,
float &  diffWithStraightLineSigma,
float &  dTdLWidth,
float &  maxFitGapLength,
float &  rmsSlidingLinearFit 
) const
private

Calculation of several variables related to sliding linear fit.

Parameters
pClusterthe cluster we are characterizing
straightLineLengthLargeto receive to length reported by the straight line fit
diffWithStraigthLineMeanto receive the difference with straight line mean variable
diffWithStraightLineSigmato receive the difference with straight line sigma variable
dTdLWidthto receive the dTdL width variable
maxFitGapLengthto receive the max fit gap length variable
rmsSlidingLinearFitto receive the RMS from the linear fit

Definition at line 161 of file TrackShowerIdFeatureTool.cc.

References lar_content::LArGeometryHelper::CalculateGapDeltaZ(), f, lar_content::LArClusterHelper::GetClusterHitType(), lar_content::LayerFitResult::GetFitT(), lar_content::TwoDSlidingFitResult::GetGlobalMaxLayerPosition(), lar_content::TwoDSlidingFitResult::GetGlobalMinLayerPosition(), lar_content::TwoDSlidingFitResult::GetGlobalPosition(), lar_content::LayerFitResult::GetGradient(), lar_content::LayerFitResult::GetL(), lar_content::TwoDSlidingFitResult::GetLayer(), lar_content::TwoDSlidingFitResult::GetLayerFitResultMap(), lar_content::LayerFitResult::GetRms(), lar_content::LArGeometryHelper::GetWireZPitch(), m_slidingLinearFitWindow, and m_slidingLinearFitWindowLarge.

Referenced by Run().

163 {
164  try
165  {
166  const TwoDSlidingFitResult slidingFitResult(pCluster, m_slidingLinearFitWindow, LArGeometryHelper::GetWireZPitch(this->GetPandora()));
167  const TwoDSlidingFitResult slidingFitResultLarge(
168  pCluster, m_slidingLinearFitWindowLarge, LArGeometryHelper::GetWireZPitch(this->GetPandora()));
169 
170  if (slidingFitResult.GetLayerFitResultMap().empty())
171  throw StatusCodeException(STATUS_CODE_NOT_INITIALIZED);
172 
173  straightLineLengthLarge =
174  (slidingFitResultLarge.GetGlobalMaxLayerPosition() - slidingFitResultLarge.GetGlobalMinLayerPosition()).GetMagnitude();
175  rmsSlidingLinearFit = 0.f;
176 
177  FloatVector diffWithStraightLineVector;
178  const HitType hitType(LArClusterHelper::GetClusterHitType(pCluster));
179  CartesianVector previousFitPosition(slidingFitResult.GetGlobalMinLayerPosition());
180  float dTdLMin(+std::numeric_limits<float>::max()), dTdLMax(-std::numeric_limits<float>::max());
181 
182  for (const auto &mapEntry : slidingFitResult.GetLayerFitResultMap())
183  {
184  const LayerFitResult &layerFitResult(mapEntry.second);
185  rmsSlidingLinearFit += layerFitResult.GetRms();
186 
187  CartesianVector thisFitPosition(0.f, 0.f, 0.f);
188  slidingFitResult.GetGlobalPosition(layerFitResult.GetL(), layerFitResult.GetFitT(), thisFitPosition);
189 
191  slidingFitResultLarge.GetLayerFitResultMap().find(slidingFitResultLarge.GetLayer(layerFitResult.GetL()));
192 
193  if (slidingFitResultLarge.GetLayerFitResultMap().end() == iterLarge)
194  throw StatusCodeException(STATUS_CODE_FAILURE);
195 
196  diffWithStraightLineVector.push_back(static_cast<float>(std::fabs(layerFitResult.GetFitT() - iterLarge->second.GetFitT())));
197 
198  const float thisGapLength((thisFitPosition - previousFitPosition).GetMagnitude());
199  const float minZ(std::min(thisFitPosition.GetZ(), previousFitPosition.GetZ()));
200  const float maxZ(std::max(thisFitPosition.GetZ(), previousFitPosition.GetZ()));
201 
202  if ((maxZ - minZ) > std::numeric_limits<float>::epsilon())
203  {
204  const float gapZ(LArGeometryHelper::CalculateGapDeltaZ(this->GetPandora(), minZ, maxZ, hitType));
205  const float correctedGapLength(thisGapLength * (1.f - gapZ / (maxZ - minZ)));
206 
207  if (correctedGapLength > maxFitGapLength)
208  maxFitGapLength = correctedGapLength;
209  }
210 
211  dTdLMin = std::min(dTdLMin, static_cast<float>(layerFitResult.GetGradient()));
212  dTdLMax = std::max(dTdLMax, static_cast<float>(layerFitResult.GetGradient()));
213  previousFitPosition = thisFitPosition;
214  }
215 
216  if (diffWithStraightLineVector.empty())
217  throw StatusCodeException(STATUS_CODE_FAILURE);
218 
219  diffWithStraightLineMean = 0.f;
220  diffWithStraightLineSigma = 0.f;
221 
222  for (const float diffWithStraightLine : diffWithStraightLineVector)
223  diffWithStraightLineMean += diffWithStraightLine;
224 
225  diffWithStraightLineMean /= static_cast<float>(diffWithStraightLineVector.size());
226 
227  for (const float diffWithStraightLine : diffWithStraightLineVector)
228  diffWithStraightLineSigma += (diffWithStraightLine - diffWithStraightLineMean) * (diffWithStraightLine - diffWithStraightLineMean);
229 
230  if (diffWithStraightLineSigma < 0.f)
231  throw StatusCodeException(STATUS_CODE_FAILURE);
232 
233  diffWithStraightLineSigma = std::sqrt(diffWithStraightLineSigma / static_cast<float>(diffWithStraightLineVector.size()));
234  dTdLWidth = dTdLMax - dTdLMin;
235  }
236  catch (const StatusCodeException &)
237  {
238  straightLineLengthLarge = -1.f;
239  diffWithStraightLineMean = -1.f;
240  diffWithStraightLineSigma = -1.f;
241  dTdLWidth = -1.f;
242  maxFitGapLength = -1.f;
243  rmsSlidingLinearFit = -1.f;
244  }
245 }
static float CalculateGapDeltaZ(const pandora::Pandora &pandora, const float minZ, const float maxZ, const pandora::HitType hitType)
Calculate the total distance within a given 2D region that is composed of detector gaps...
intermediate_table::const_iterator const_iterator
static pandora::HitType GetClusterHitType(const pandora::Cluster *const pCluster)
Get the hit type associated with a two dimensional cluster.
static float GetWireZPitch(const pandora::Pandora &pandora, const float maxWirePitchDiscrepancy=0.01)
Return the wire pitch.
unsigned int m_slidingLinearFitWindow
The sliding linear fit window.
TFile f
Definition: plotHisto.C:6
HitType
Definition: HitType.h:12
unsigned int m_slidingLinearFitWindowLarge
The sliding linear fit window - should be large, providing a simple linear fit.
StatusCode lar_content::TwoDLinearFitFeatureTool::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
private

Definition at line 249 of file TrackShowerIdFeatureTool.cc.

References m_slidingLinearFitWindow, and m_slidingLinearFitWindowLarge.

250 {
251  PANDORA_RETURN_RESULT_IF_AND_IF(
252  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SlidingLinearFitWindow", m_slidingLinearFitWindow));
253 
254  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
255  XmlHelper::ReadValue(xmlHandle, "SlidingLinearFitWindowLarge", m_slidingLinearFitWindowLarge));
256 
257  return STATUS_CODE_SUCCESS;
258 }
unsigned int m_slidingLinearFitWindow
The sliding linear fit window.
unsigned int m_slidingLinearFitWindowLarge
The sliding linear fit window - should be large, providing a simple linear fit.
template<typename... Ts>
virtual void lar_content::MvaFeatureTool< Ts >::Run ( MvaTypes::MvaFeatureVector featureVector,
Ts...  args 
)
pure virtualinherited

Run the algorithm tool.

Parameters
featureVectorthe vector of features to append
argsarguments to pass to the tool
template<typename... Ts>
virtual void lar_content::MvaFeatureTool< Ts >::Run ( MvaTypes::MvaFeatureMap featureMap,
pandora::StringVector &  featureOrder,
const std::string &  featureToolName,
Ts...   
)
inlinevirtualinherited

Definition at line 51 of file LArMvaHelper.h.

52  {
53  (void)featureMap;
54  (void)featureOrder;
55  (void)featureToolName;
56  return;
57  };
void lar_content::TwoDLinearFitFeatureTool::Run ( LArMvaHelper::MvaFeatureVector featureVector,
const pandora::Algorithm *const  pAlgorithm,
const pandora::Cluster *const  pCluster 
)

Definition at line 98 of file TrackShowerIdFeatureTool.cc.

References CalculateVariablesSlidingLinearFit(), and f.

99 {
100  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
101  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
102 
103  float dTdLWidth(-1.f), straightLineLengthLarge(-1.f), diffWithStraightLineMean(-1.f), diffWithStraightLineSigma(-1.f),
104  maxFitGapLength(-1.f), rmsSlidingLinearFit(-1.f);
105  this->CalculateVariablesSlidingLinearFit(pCluster, straightLineLengthLarge, diffWithStraightLineMean, diffWithStraightLineSigma,
106  dTdLWidth, maxFitGapLength, rmsSlidingLinearFit);
107 
108  if (straightLineLengthLarge > std::numeric_limits<float>::epsilon())
109  {
110  diffWithStraightLineMean /= straightLineLengthLarge;
111  diffWithStraightLineSigma /= straightLineLengthLarge;
112  dTdLWidth /= straightLineLengthLarge;
113  maxFitGapLength /= straightLineLengthLarge;
114  rmsSlidingLinearFit /= straightLineLengthLarge;
115  }
116 
117  featureVector.push_back(straightLineLengthLarge);
118  featureVector.push_back(diffWithStraightLineMean);
119  featureVector.push_back(diffWithStraightLineSigma);
120  featureVector.push_back(dTdLWidth);
121  featureVector.push_back(maxFitGapLength);
122  featureVector.push_back(rmsSlidingLinearFit);
123 }
TFile f
Definition: plotHisto.C:6
void CalculateVariablesSlidingLinearFit(const pandora::Cluster *const pCluster, float &straightLineLengthLarge, float &diffWithStraigthLineMean, float &diffWithStraightLineSigma, float &dTdLWidth, float &maxFitGapLength, float &rmsSlidingLinearFit) const
Calculation of several variables related to sliding linear fit.
void lar_content::TwoDLinearFitFeatureTool::Run ( LArMvaHelper::MvaFeatureMap featureMap,
pandora::StringVector &  featureOrder,
const std::string &  featureToolName,
const pandora::Algorithm *const  pAlgorithm,
const pandora::Cluster *const  pCluster 
)

Member Data Documentation

unsigned int lar_content::TwoDLinearFitFeatureTool::m_slidingLinearFitWindow
private

The sliding linear fit window.

Definition at line 89 of file TrackShowerIdFeatureTool.h.

Referenced by CalculateVariablesSlidingLinearFit(), and ReadSettings().

unsigned int lar_content::TwoDLinearFitFeatureTool::m_slidingLinearFitWindowLarge
private

The sliding linear fit window - should be large, providing a simple linear fit.

Definition at line 90 of file TrackShowerIdFeatureTool.h.

Referenced by CalculateVariablesSlidingLinearFit(), and ReadSettings().


The documentation for this class was generated from the following files: