All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LArVertexHelper.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArHelpers/LArVertexHelper.cc
3  *
4  * @brief Implementation of the vertex helper class.
5  *
6  * $Log: $
7  */
8 
9 #include "Geometry/LArTPC.h"
10 #include "Managers/GeometryManager.h"
11 
16 
17 #include <algorithm>
18 #include <limits>
19 
20 using namespace pandora;
21 
22 namespace lar_content
23 {
24 
25 LArVertexHelper::ClusterDirection LArVertexHelper::GetClusterDirectionInZ(
26  const Pandora &pandora, const Vertex *const pVertex, const Cluster *const pCluster, const float tanAngle, const float apexShift)
27 {
28  if ((VERTEX_3D != pVertex->GetVertexType()) || (tanAngle < std::numeric_limits<float>::epsilon()))
29  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
30 
31  const HitType hitType(LArClusterHelper::GetClusterHitType(pCluster));
32  const CartesianVector theVertex2D(LArGeometryHelper::ProjectPosition(pandora, pVertex->GetPosition(), hitType));
33 
34  try
35  {
36  const LArPointingCluster pointingCluster(pCluster);
37  const float length((pointingCluster.GetInnerVertex().GetPosition() - pointingCluster.GetOuterVertex().GetPosition()).GetMagnitude());
38  const bool innerIsAtLowerZ(pointingCluster.GetInnerVertex().GetPosition().GetZ() < pointingCluster.GetOuterVertex().GetPosition().GetZ());
39 
40  float rLInner(std::numeric_limits<float>::max()), rTInner(std::numeric_limits<float>::max());
41  float rLOuter(std::numeric_limits<float>::max()), rTOuter(std::numeric_limits<float>::max());
42  LArPointingClusterHelper::GetImpactParameters(pointingCluster.GetInnerVertex(), theVertex2D, rLInner, rTInner);
43  LArPointingClusterHelper::GetImpactParameters(pointingCluster.GetOuterVertex(), theVertex2D, rLOuter, rTOuter);
44 
45  const bool innerIsVertexAssociated(rLInner > (rTInner / tanAngle) - (length * apexShift));
46  const bool outerIsVertexAssociated(rLOuter > (rTInner / tanAngle) - (length * apexShift));
47 
48  if (innerIsVertexAssociated == outerIsVertexAssociated)
49  return DIRECTION_UNKNOWN;
50 
51  if ((innerIsVertexAssociated && innerIsAtLowerZ) || (outerIsVertexAssociated && !innerIsAtLowerZ))
52  return DIRECTION_FORWARD_IN_Z;
53 
54  if ((innerIsVertexAssociated && !innerIsAtLowerZ) || (outerIsVertexAssociated && innerIsAtLowerZ))
55  return DIRECTION_BACKWARD_IN_Z;
56  }
57  catch (StatusCodeException &)
58  {
59  return DIRECTION_UNKNOWN;
60  }
61 
62  throw StatusCodeException(STATUS_CODE_FAILURE);
63 }
64 
65 //-----------------------------------------------------------------------------------------------------------------------------------------
66 
67 bool LArVertexHelper::IsInFiducialVolume(const Pandora &pandora, const CartesianVector &vertex, const std::string &detector)
68 {
69  const LArTPCMap &larTPCMap(pandora.GetGeometry()->GetLArTPCMap());
70 
71  if (larTPCMap.empty())
72  {
73  std::cout << "LArVertexHelper::IsInFiducialVolume - LArTPC description not registered with Pandora as required " << std::endl;
74  throw StatusCodeException(STATUS_CODE_NOT_INITIALIZED);
75  }
76 
77  float tpcMinX{std::numeric_limits<float>::max()}, tpcMaxX{-std::numeric_limits<float>::max()};
78  float tpcMinY{std::numeric_limits<float>::max()}, tpcMaxY{-std::numeric_limits<float>::max()};
79  float tpcMinZ{std::numeric_limits<float>::max()}, tpcMaxZ{-std::numeric_limits<float>::max()};
80 
81  for (const auto &[volumeId, pLArTPC] : larTPCMap)
82  {
83  (void)volumeId;
84  const float centreX{pLArTPC->GetCenterX()}, halfWidthX{0.5f * pLArTPC->GetWidthX()};
85  const float centreY{pLArTPC->GetCenterY()}, halfWidthY{0.5f * pLArTPC->GetWidthY()};
86  const float centreZ{pLArTPC->GetCenterZ()}, halfWidthZ{0.5f * pLArTPC->GetWidthZ()};
87  tpcMinX = std::min(tpcMinX, centreX - halfWidthX);
88  tpcMaxX = std::max(tpcMaxX, centreX + halfWidthX);
89  tpcMinY = std::min(tpcMinY, centreY - halfWidthY);
90  tpcMaxY = std::max(tpcMaxY, centreY + halfWidthY);
91  tpcMinZ = std::min(tpcMinZ, centreZ - halfWidthZ);
92  tpcMaxZ = std::max(tpcMaxZ, centreZ + halfWidthZ);
93  }
94 
95  if (detector == "dune_fd_hd")
96  {
97  const float x{vertex.GetX()};
98  const float y{vertex.GetY()};
99  const float z{vertex.GetZ()};
100  return (tpcMinX + 50.f) < x && x < (tpcMaxX - 50.f) && (tpcMinY + 50.f) < y && y < (tpcMaxY - 50.f) && (tpcMinZ + 50.f) < z &&
101  z < (tpcMaxZ - 150.f);
102  }
103  else
104  {
105  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
106  }
107 }
108 
109 } // namespace lar_content
process_name vertex
Definition: cheaterreco.fcl:51
process_name opflash particleana ie ie ie z
process_name opflash particleana ie x
LArPointingCluster class.
Header file for the geometry helper class.
process_name opflash particleana ie ie y
Header file for the cluster helper class.
const Vertex & GetOuterVertex() const
Get the outer vertex.
const Vertex & GetInnerVertex() const
Get the inner vertex.
j template void())
Definition: json.hpp:3108
Header file for the vertex helper class.
required by fuzzyCluster table::sbnd_g4_services gaushitTruthMatch pandora
Definition: reco_sbnd.fcl:182
const pandora::CartesianVector & GetPosition() const
Get the vertex position.
BEGIN_PROLOG could also be cout