LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
lar_content::ThreeDLinearFitFeatureTool Class Referenceabstract

LinearFitFeatureTool class for the calculation of variables related to sliding linear fit. More...

#include "TrackShowerIdFeatureTool.h"

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

Public Types

typedef std::vector< MvaFeatureTool< Ts... > * > FeatureToolVector
 

Public Member Functions

 ThreeDLinearFitFeatureTool ()
 Default constructor. More...
 
void Run (LArMvaHelper::MvaFeatureVector &featureVector, const pandora::Algorithm *const pAlgorithm, const pandora::ParticleFlowObject *const pInputPfo)
 
virtual void Run (MvaTypes::MvaFeatureVector &featureVector, Ts...args)=0
 Run the algorithm tool. More...
 

Private Member Functions

pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle)
 
void CalculateVariablesSlidingLinearFit (const pandora::Cluster *const pCluster, float &straightLineLengthLarge, float &diffWithStraigthLineMean, 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

LinearFitFeatureTool class for the calculation of variables related to sliding linear fit.

Definition at line 123 of file TrackShowerIdFeatureTool.h.

Member Typedef Documentation

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

Definition at line 30 of file LArMvaHelper.h.

Constructor & Destructor Documentation

lar_content::ThreeDLinearFitFeatureTool::ThreeDLinearFitFeatureTool ( )

Default constructor.

Definition at line 253 of file TrackShowerIdFeatureTool.cc.

253  :
256 {
257 }
unsigned int m_slidingLinearFitWindowLarge
The sliding linear fit window - should be large, providing a simple linear fit.
unsigned int m_slidingLinearFitWindow
The sliding linear fit window.

Member Function Documentation

void lar_content::ThreeDLinearFitFeatureTool::CalculateVariablesSlidingLinearFit ( const pandora::Cluster *const  pCluster,
float &  straightLineLengthLarge,
float &  diffWithStraigthLineMean,
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 310 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, m_slidingLinearFitWindowLarge, max, and min.

Referenced by Run().

312 {
313  try
314  {
315  const TwoDSlidingFitResult slidingFitResult(pCluster, m_slidingLinearFitWindow, LArGeometryHelper::GetWireZPitch(this->GetPandora()));
316  const TwoDSlidingFitResult slidingFitResultLarge(pCluster, m_slidingLinearFitWindowLarge, LArGeometryHelper::GetWireZPitch(this->GetPandora()));
317 
318  if (slidingFitResult.GetLayerFitResultMap().empty())
319  throw StatusCodeException(STATUS_CODE_NOT_INITIALIZED);
320 
321  straightLineLengthLarge = (slidingFitResultLarge.GetGlobalMaxLayerPosition() - slidingFitResultLarge.GetGlobalMinLayerPosition()).GetMagnitude();
322  rmsSlidingLinearFit = 0.f;
323 
324  FloatVector diffWithStraightLineVector;
325  const HitType hitType(LArClusterHelper::GetClusterHitType(pCluster));
326  CartesianVector previousFitPosition(slidingFitResult.GetGlobalMinLayerPosition());
328 
329  for (const auto &mapEntry : slidingFitResult.GetLayerFitResultMap())
330  {
331  const LayerFitResult &layerFitResult(mapEntry.second);
332  rmsSlidingLinearFit += layerFitResult.GetRms();
333 
334  CartesianVector thisFitPosition(0.f, 0.f, 0.f);
335  slidingFitResult.GetGlobalPosition(layerFitResult.GetL(), layerFitResult.GetFitT(), thisFitPosition);
336 
337  LayerFitResultMap::const_iterator iterLarge = slidingFitResultLarge.GetLayerFitResultMap().find(slidingFitResultLarge.GetLayer(layerFitResult.GetL()));
338 
339  if (slidingFitResultLarge.GetLayerFitResultMap().end() == iterLarge)
340  throw StatusCodeException(STATUS_CODE_FAILURE);
341 
342  diffWithStraightLineVector.push_back(static_cast<float>(std::fabs(layerFitResult.GetFitT() - iterLarge->second.GetFitT())));
343 
344  const float thisGapLength((thisFitPosition - previousFitPosition).GetMagnitude());
345  const float minZ(std::min(thisFitPosition.GetZ(), previousFitPosition.GetZ()));
346  const float maxZ(std::max(thisFitPosition.GetZ(), previousFitPosition.GetZ()));
347 
348  if ((maxZ - minZ) > std::numeric_limits<float>::epsilon())
349  {
350  const float gapZ(LArGeometryHelper::CalculateGapDeltaZ(this->GetPandora(), minZ, maxZ, hitType));
351  const float correctedGapLength(thisGapLength * (1.f - gapZ / (maxZ - minZ)));
352 
353  if (correctedGapLength > maxFitGapLength)
354  maxFitGapLength = correctedGapLength;
355  }
356  else
357  {
358  maxFitGapLength = 0.f;
359  }
360 
361  dTdLMin = std::min(dTdLMin, static_cast<float>(layerFitResult.GetGradient()));
362  dTdLMax = std::max(dTdLMax, static_cast<float>(layerFitResult.GetGradient()));
363  previousFitPosition = thisFitPosition;
364  }
365 
366  if (diffWithStraightLineVector.empty())
367  throw StatusCodeException(STATUS_CODE_FAILURE);
368 
369  diffWithStraightLineMean = 0.f;
370 
371  for (const float diffWithStraightLine : diffWithStraightLineVector)
372  diffWithStraightLineMean += diffWithStraightLine;
373 
374  diffWithStraightLineMean /= static_cast<float>(diffWithStraightLineVector.size());
375 
376  }
377  catch (const StatusCodeException &)
378  {
379  straightLineLengthLarge = -1.f;
380  diffWithStraightLineMean = -1.f;
381  maxFitGapLength = -1.f;
382  rmsSlidingLinearFit = -1.f;
383  }
384 }
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...
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.
TFile f
Definition: plotHisto.C:6
Int_t max
Definition: plot.C:27
intermediate_table::const_iterator const_iterator
unsigned int m_slidingLinearFitWindowLarge
The sliding linear fit window - should be large, providing a simple linear fit.
Int_t min
Definition: plot.C:26
unsigned int m_slidingLinearFitWindow
The sliding linear fit window.
StatusCode lar_content::ThreeDLinearFitFeatureTool::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
private

Definition at line 388 of file TrackShowerIdFeatureTool.cc.

References m_slidingLinearFitWindow, and m_slidingLinearFitWindowLarge.

389 {
390  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
391  "SlidingLinearFitWindow", m_slidingLinearFitWindow));
392 
393  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
394  "SlidingLinearFitWindowLarge", m_slidingLinearFitWindowLarge));
395 
396  return STATUS_CODE_SUCCESS;
397 }
unsigned int m_slidingLinearFitWindowLarge
The sliding linear fit window - should be large, providing a simple linear fit.
unsigned int m_slidingLinearFitWindow
The sliding linear fit window.
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
void lar_content::ThreeDLinearFitFeatureTool::Run ( LArMvaHelper::MvaFeatureVector featureVector,
const pandora::Algorithm *const  pAlgorithm,
const pandora::ParticleFlowObject *const  pInputPfo 
)

Definition at line 261 of file TrackShowerIdFeatureTool.cc.

References CalculateVariablesSlidingLinearFit(), f, lar_content::LArPfoHelper::GetThreeDLengthSquared(), and lar_content::LArPfoHelper::GetTwoDClusterList().

263 {
264  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
265  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
266 
267  ClusterList clusterList;
268  LArPfoHelper::GetTwoDClusterList(pInputPfo, clusterList);
269  float diffWithStraightLineMean(0.f), maxFitGapLength(0.f), rmsSlidingLinearFit(0.f);
270  LArMvaHelper::MvaFeature length, diff, gap, rms;
271  unsigned int nClustersUsed(0);
272 
273  for (const Cluster *const pCluster : clusterList)
274  {
275  float straightLineLengthLargeCluster(-1.f), diffWithStraightLineMeanCluster(-1.f), maxFitGapLengthCluster(-1.f), rmsSlidingLinearFitCluster(-1.f);
276 
277  this->CalculateVariablesSlidingLinearFit(pCluster, straightLineLengthLargeCluster, diffWithStraightLineMeanCluster, maxFitGapLengthCluster, rmsSlidingLinearFitCluster);
278 
279  if (straightLineLengthLargeCluster > std::numeric_limits<float>::epsilon())
280  {
281  diffWithStraightLineMeanCluster /= straightLineLengthLargeCluster;
282  maxFitGapLengthCluster /= straightLineLengthLargeCluster;
283  rmsSlidingLinearFitCluster /= straightLineLengthLargeCluster;
284 
285  diffWithStraightLineMean += diffWithStraightLineMeanCluster;
286  maxFitGapLength += maxFitGapLengthCluster;
287  rmsSlidingLinearFit += rmsSlidingLinearFitCluster;
288 
289  ++nClustersUsed;
290  }
291  }
292 
293  if (nClustersUsed > 0)
294  {
295  const float nClusters(static_cast<float>(nClustersUsed));
296  length = std::sqrt(LArPfoHelper::GetThreeDLengthSquared(pInputPfo));
297  diff = diffWithStraightLineMean / nClusters;
298  gap = maxFitGapLength / nClusters;
299  rms = rmsSlidingLinearFit / nClusters;
300  }
301 
302  featureVector.push_back(length);
303  featureVector.push_back(diff);
304  featureVector.push_back(gap);
305  featureVector.push_back(rms);
306 }
static void GetTwoDClusterList(const pandora::ParticleFlowObject *const pPfo, pandora::ClusterList &clusterList)
Get the list of 2D clusters from an input pfo.
Definition: LArPfoHelper.cc:97
static float GetThreeDLengthSquared(const pandora::ParticleFlowObject *const pPfo)
Calculate length of Pfo using 3D clusters.
void CalculateVariablesSlidingLinearFit(const pandora::Cluster *const pCluster, float &straightLineLengthLarge, float &diffWithStraigthLineMean, float &maxFitGapLength, float &rmsSlidingLinearFit) const
Calculation of several variables related to sliding linear fit.
MvaTypes::MvaFeature MvaFeature
Definition: LArMvaHelper.h:57
TFile f
Definition: plotHisto.C:6

Member Data Documentation

unsigned int lar_content::ThreeDLinearFitFeatureTool::m_slidingLinearFitWindow
private

The sliding linear fit window.

Definition at line 150 of file TrackShowerIdFeatureTool.h.

Referenced by CalculateVariablesSlidingLinearFit(), and ReadSettings().

unsigned int lar_content::ThreeDLinearFitFeatureTool::m_slidingLinearFitWindowLarge
private

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

Definition at line 151 of file TrackShowerIdFeatureTool.h.

Referenced by CalculateVariablesSlidingLinearFit(), and ReadSettings().


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