All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackHitsBaseTool.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArThreeDReco/LArHitCreation/TrackHitsBaseTool.cc
3  *
4  * @brief Implementation of the track hits base tool.
5  *
6  * $Log: $
7  */
8 
9 #include "Pandora/AlgorithmHeaders.h"
10 
14 
17 
18 using namespace pandora;
19 
20 namespace lar_content
21 {
22 
23 TrackHitsBaseTool::TrackHitsBaseTool() : m_minViews(2), m_slidingFitWindow(20)
24 {
25 }
26 
27 //------------------------------------------------------------------------------------------------------------------------------------------
28 
29 void TrackHitsBaseTool::Run(ThreeDHitCreationAlgorithm *const pAlgorithm, const ParticleFlowObject *const pPfo,
30  const CaloHitVector &inputTwoDHits, ProtoHitVector &protoHitVector)
31 {
32  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
33  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
34 
35  try
36  {
37  if (!LArPfoHelper::IsTrack(pPfo))
38  return;
39 
40  MatchedSlidingFitMap matchedSlidingFitMap;
41  this->BuildSlidingFitMap(pPfo, matchedSlidingFitMap);
42 
43  if (matchedSlidingFitMap.size() < 2)
44  return;
45 
46  this->GetTrackHits3D(inputTwoDHits, matchedSlidingFitMap, protoHitVector);
47  }
48  catch (StatusCodeException &)
49  {
50  }
51 }
52 
53 //------------------------------------------------------------------------------------------------------------------------------------------
54 
55 void TrackHitsBaseTool::BuildSlidingFitMap(const ParticleFlowObject *const pPfo, MatchedSlidingFitMap &matchedSlidingFitMap) const
56 {
57  const ClusterList &pfoClusterList(pPfo->GetClusterList());
58  const float slidingFitPitch(LArGeometryHelper::GetWireZPitch(this->GetPandora()));
59 
60  ClusterVector pfoClusterVector;
61  pfoClusterVector.insert(pfoClusterVector.end(), pfoClusterList.begin(), pfoClusterList.end());
62  std::sort(pfoClusterVector.begin(), pfoClusterVector.end(), LArClusterHelper::SortByNHits);
63 
64  for (const Cluster *const pCluster : pfoClusterVector)
65  {
66  const HitType hitType(LArClusterHelper::GetClusterHitType(pCluster));
67 
68  if (TPC_3D == hitType)
69  continue;
70 
71  if (matchedSlidingFitMap.end() != matchedSlidingFitMap.find(hitType))
72  continue;
73 
74  try
75  {
76  const TwoDSlidingFitResult slidingFitResult(pCluster, m_slidingFitWindow, slidingFitPitch);
77 
78  if (!matchedSlidingFitMap.insert(MatchedSlidingFitMap::value_type(hitType, slidingFitResult)).second)
79  throw StatusCodeException(STATUS_CODE_FAILURE);
80  }
81  catch (StatusCodeException &statusCodeException)
82  {
83  if (STATUS_CODE_FAILURE == statusCodeException.GetStatusCode())
84  throw statusCodeException;
85  }
86  }
87 }
88 
89 //------------------------------------------------------------------------------------------------------------------------------------------
90 
91 StatusCode TrackHitsBaseTool::ReadSettings(const TiXmlHandle xmlHandle)
92 {
93  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinViews", m_minViews));
94 
95  PANDORA_RETURN_RESULT_IF_AND_IF(
96  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SlidingFitWindow", m_slidingFitWindow));
97 
98  return HitCreationBaseTool::ReadSettings(xmlHandle);
99 }
100 
101 } // namespace lar_content
static bool SortByNHits(const pandora::Cluster *const pLhs, const pandora::Cluster *const pRhs)
Sort clusters by number of hits, then layer span, then inner layer, then position, then pulse-height.
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
virtual void BuildSlidingFitMap(const pandora::ParticleFlowObject *const pPfo, MatchedSlidingFitMap &matchedSlidingFitMap) const
Calculate sliding fit results for clusters from each view.
Header file for the pfo helper class.
virtual void GetTrackHits3D(const pandora::CaloHitVector &inputTwoDHits, const MatchedSlidingFitMap &matchedSlidingFitMap, ProtoHitVector &protoHitVector) const =0
Calculate 3D hits from an input list of 2D hits.
std::map< pandora::HitType, TwoDSlidingFitResult > MatchedSlidingFitMap
ThreeDHitCreationAlgorithm::ProtoHitVector ProtoHitVector
static pandora::HitType GetClusterHitType(const pandora::Cluster *const pCluster)
Get the hit type associated with a two dimensional cluster.
static bool IsTrack(const pandora::ParticleFlowObject *const pPfo)
Return track flag based on Pfo Particle ID.
static float GetWireZPitch(const pandora::Pandora &pandora, const float maxWirePitchDiscrepancy=0.01)
Return the wire pitch.
Header file for the three dimensional hit creation algorithm class.
Header file for the geometry helper class.
Header file for the cluster helper class.
Header file for the track hits base tool.
unsigned int m_slidingFitWindow
The layer window for the sliding linear fits.
required by fuzzyCluster table::sbnd_g4_services gaushitTruthMatch pandora
Definition: reco_sbnd.fcl:182
unsigned int m_minViews
The minimum number of views required for building hits.
ThreeDHitCreationAlgorithm::Algorithm class.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
virtual void Run(ThreeDHitCreationAlgorithm *const pAlgorithm, const pandora::ParticleFlowObject *const pPfo, const pandora::CaloHitVector &inputTwoDHits, ProtoHitVector &protoHitVector)
Run the algorithm tool.
BEGIN_PROLOG could also be cout