TransverseTrackHitsBaseTool.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArThreeDReco/LArHitCreation/TransverseTrackHitsBaseTool.cc
3  *
4  * @brief Implementation of the transverse track hits base tool.
5  *
6  * $Log: $
7  */
8 
9 #include "Pandora/AlgorithmHeaders.h"
10 
13 
15 
16 using namespace pandora;
17 
18 namespace lar_content
19 {
20 
21 void TransverseTrackHitsBaseTool::GetTrackHits3D(
22  const CaloHitVector &inputTwoDHits, const MatchedSlidingFitMap &matchedSlidingFitMap, ProtoHitVector &protoHitVector) const
23 {
24  for (const CaloHit *const pCaloHit2D : inputTwoDHits)
25  {
26  try
27  {
28  ProtoHit protoHit(pCaloHit2D);
29  this->GetTransverseTrackHit3D(matchedSlidingFitMap, protoHit);
30  this->AddTransverseChi2(matchedSlidingFitMap, protoHit);
31 
32  if (protoHit.IsPositionSet() && (protoHit.GetChi2() < m_chiSquaredCut))
33  protoHitVector.push_back(protoHit);
34  }
35  catch (StatusCodeException &)
36  {
37  }
38  }
39 }
40 
41 //------------------------------------------------------------------------------------------------------------------------------------------
42 
43 void TransverseTrackHitsBaseTool::AddTransverseChi2(const MatchedSlidingFitMap &matchedSlidingFitMap, ProtoHit &protoHit) const
44 {
45  // TODO Develop a proper treatment of the |dz/dx| * sigmaX uncertainty
46  double chiSquared(protoHit.GetChi2());
47  const HitType inputHitType(protoHit.GetParentCaloHit2D()->GetHitType());
48  const CartesianVector &inputPosition3D(protoHit.GetPosition3D());
49 
50  for (const MatchedSlidingFitMap::value_type &mapEntry : matchedSlidingFitMap)
51  {
52  if (mapEntry.first == inputHitType)
53  continue;
54 
55  const CartesianVector inputPosition2D(LArGeometryHelper::ProjectPosition(this->GetPandora(), inputPosition3D, mapEntry.first));
56  chiSquared += this->GetTransverseChi2(inputPosition2D, mapEntry.second);
57  }
58 
59  protoHit.SetPosition3D(inputPosition3D, chiSquared);
60 }
61 
62 //------------------------------------------------------------------------------------------------------------------------------------------
63 
64 double TransverseTrackHitsBaseTool::GetTransverseChi2(const CartesianVector &position2D, const TwoDSlidingFitResult &fitResult) const
65 {
66  const float minLayerX(fitResult.GetGlobalMinLayerPosition().GetX());
67  const float maxLayerX(fitResult.GetGlobalMaxLayerPosition().GetX());
68 
69  const float minX(std::min(minLayerX, maxLayerX));
70  const float maxX(std::max(minLayerX, maxLayerX));
71 
72  if (((position2D.GetX() - minX) > -std::numeric_limits<float>::epsilon()) && ((position2D.GetX() - maxX) < +std::numeric_limits<float>::epsilon()))
73  return 0.;
74 
75  const float minLayerDistanceSquared((position2D - fitResult.GetGlobalMinLayerPosition()).GetMagnitudeSquared());
76  const float maxLayerDistanceSquared((position2D - fitResult.GetGlobalMaxLayerPosition()).GetMagnitudeSquared());
77 
78  double px(0.), pz(0.);
79 
80  if (minLayerDistanceSquared < maxLayerDistanceSquared)
81  {
82  px = fitResult.GetGlobalMinLayerDirection().GetX();
83  pz = fitResult.GetGlobalMinLayerDirection().GetZ();
84  }
85  else if (maxLayerDistanceSquared < minLayerDistanceSquared)
86  {
87  px = fitResult.GetGlobalMaxLayerDirection().GetX();
88  pz = fitResult.GetGlobalMaxLayerDirection().GetZ();
89  }
90 
91  if (std::fabs(px) > std::numeric_limits<double>::epsilon())
92  {
93  return (0.5 * (pz * pz) / (px * px)); // TODO: Figure out the appropriate scale factor
94  }
95 
96  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
97 }
98 
99 } // namespace lar_content
Header file for the transverse track hits base tool.
Proto hits are temporary constructs to be used during iterative 3D hit procedure. ...
std::map< pandora::HitType, TwoDSlidingFitResult > MatchedSlidingFitMap
enum cvn::HType HitType
const pandora::CaloHit * GetParentCaloHit2D() const
Get the address of the parent 2D calo hit.
ThreeDHitCreationAlgorithm::ProtoHitVector ProtoHitVector
bool IsPositionSet() const
Whether the proto hit position is set.
pandora::CartesianVector GetGlobalMinLayerDirection() const
Get global direction corresponding to the fit result in minimum fit layer.
const pandora::CartesianVector & GetPosition3D() const
Get the output 3D position.
Header file for the three dimensional hit creation algorithm class.
Header file for the geometry helper class.
double GetChi2() const
Get the chi squared value.
pandora::CartesianVector GetGlobalMinLayerPosition() const
Get global position corresponding to the fit result in minimum fit layer.
static int max(int a, int b)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
pandora::CartesianVector GetGlobalMaxLayerDirection() const
Get global direction corresponding to the fit result in maximum fit layer.
void SetPosition3D(const pandora::CartesianVector &position3D, const double chi2)
Set position 3D.
pandora::CartesianVector GetGlobalMaxLayerPosition() const
Get global position corresponding to the fit result in maximum fit layer.