Shower3DCylinderTrackHitFinder_tool.cc
Go to the documentation of this file.
1 //############################################################################
2 //### Name: Shower3DCylinderTrackHitFinder ###
3 //### Author: Ed Tyley ###
4 //### Date: 14.06.19 ###
5 //### Description: Tool for finding the initial shower track using 3D ###
6 //### spacepoints within a cylinder along the shower ###
7 //### direction. fcl parameters define cylinder dimensions ###
8 //############################################################################
9 
10 //Framework Includes
12 
13 //LArSoft Includes
16 
17 namespace ShowerRecoTools {
18 
20  public:
22 
23  //Generic Track Finder
24  int CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
26  reco::shower::ShowerElementHolder& ShowerEleHolder) override;
27 
28  private:
29  std::vector<art::Ptr<recob::SpacePoint>> FindTrackSpacePoints(
31  TVector3& showerStartPosition,
32  TVector3& showerDirection);
33 
34  //Fcl paramters
35  float fMaxProjectionDist; //Maximum projection along shower direction.
36  float fMaxPerpendicularDist; //Maximum perpendicular distance, radius of cylinder
37  bool fForwardHitsOnly; //Only take hits downstream of shower vertex
38  //(projection>0)
39 
41  int fVerbose;
42 
47  };
48 
50  : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
51  , fMaxProjectionDist(pset.get<float>("MaxProjectionDist"))
52  , fMaxPerpendicularDist(pset.get<float>("MaxPerpendicularDist"))
53  , fForwardHitsOnly(pset.get<bool>("ForwardHitsOnly"))
54  , fPFParticleLabel(pset.get<art::InputTag>("PFParticleLabel"))
55  , fVerbose(pset.get<int>("Verbose"))
56  , fShowerStartPositionInputLabel(pset.get<std::string>("ShowerStartPositionInputLabel"))
57  , fInitialTrackHitsOutputLabel(pset.get<std::string>("InitialTrackHitsOutputLabel"))
59  pset.get<std::string>("InitialTrackSpacePointsOutputLabel"))
60  , fShowerDirectionInputLabel(pset.get<std::string>("ShowerDirectionInputLabel"))
61  {}
62 
63  int
65  const art::Ptr<recob::PFParticle>& pfparticle,
66  art::Event& Event,
67  reco::shower::ShowerElementHolder& ShowerEleHolder)
68  {
69 
70  //This is all based on the shower vertex being known. If it is not lets not do the track
71  if (!ShowerEleHolder.CheckElement(fShowerStartPositionInputLabel)) {
72  if (fVerbose)
73  mf::LogError("Shower3DCylinderTrackHitFinder")
74  << "Start position not set, returning " << std::endl;
75  return 1;
76  }
77  if (!ShowerEleHolder.CheckElement("ShowerDirection")) {
78  if (fVerbose)
79  mf::LogError("Shower3DCylinderTrackHitFinder")
80  << "Direction not set, returning " << std::endl;
81  return 1;
82  }
83 
84  TVector3 ShowerStartPosition = {-999, -999, -999};
85  ShowerEleHolder.GetElement(fShowerStartPositionInputLabel, ShowerStartPosition);
86 
87  TVector3 ShowerDirection = {-999, -999, -999};
88  ShowerEleHolder.GetElement(fShowerDirectionInputLabel, ShowerDirection);
89 
90  // Get the assocated pfParicle Handle
91  auto const pfpHandle = Event.getValidHandle<std::vector<recob::PFParticle>>(fPFParticleLabel);
92 
93  // Get the spacepoint - PFParticle assn
94  const art::FindManyP<recob::SpacePoint>& fmspp =
95  ShowerEleHolder.GetFindManyP<recob::SpacePoint>(pfpHandle, Event, fPFParticleLabel);
96 
97  // Get the spacepoints
98  auto const spHandle = Event.getValidHandle<std::vector<recob::SpacePoint>>(fPFParticleLabel);
99 
100  // Get the hits associated with the space points
101  const art::FindManyP<recob::Hit>& fmhsp =
102  ShowerEleHolder.GetFindManyP<recob::Hit>(spHandle, Event, fPFParticleLabel);
103 
104  // Get the SpacePoints
105  std::vector<art::Ptr<recob::SpacePoint>> spacePoints = fmspp.at(pfparticle.key());
106 
107  //We cannot progress with no spacepoints.
108  if (spacePoints.empty()) {
109  if (fVerbose)
110  mf::LogError("Shower3DCylinderTrackHitFinder")
111  << "No space points, returning " << std::endl;
112  return 1;
113  }
114 
115  // Order the spacepoints
117  spacePoints, ShowerStartPosition, ShowerDirection);
118 
119  // Get only the space points from the track
120  std::vector<art::Ptr<recob::SpacePoint>> trackSpacePoints;
121  trackSpacePoints = FindTrackSpacePoints(spacePoints, ShowerStartPosition, ShowerDirection);
122 
123  // Get the hits associated to the space points and seperate them by planes
124  std::vector<art::Ptr<recob::Hit>> trackHits;
125  for (auto const& spacePoint : trackSpacePoints) {
126  const art::Ptr<recob::Hit> hit = fmhsp.at(spacePoint.key()).front();
127  // const art::Ptr<recob::Hit> hit = fohsp.at(spacePoint.key());
128  trackHits.push_back(hit);
129  }
130 
131  ShowerEleHolder.SetElement(trackHits, fInitialTrackHitsOutputLabel);
132  ShowerEleHolder.SetElement(trackSpacePoints, fInitialTrackSpacePointsOutputLabel);
133 
134  return 0;
135  }
136 
137  std::vector<art::Ptr<recob::SpacePoint>>
140  TVector3& showerStartPosition,
141  TVector3& showerDirection)
142  {
143 
144  // Make a vector to hold the output space points
145  std::vector<art::Ptr<recob::SpacePoint>> trackSpacePoints;
146 
147  for (const auto& spacePoint : spacePoints) {
148  // Calculate the projection along direction and perpendicular distance
149  // from "axis" of shower TODO: change alg to return a pair for efficiency
151  spacePoint, showerStartPosition, showerDirection);
153  spacePoint, showerStartPosition, showerDirection, proj);
154 
155  if (fForwardHitsOnly && proj < 0) continue;
156 
158  trackSpacePoints.push_back(spacePoint);
159  }
160  return trackSpacePoints;
161  }
162 
163 }
164 
std::vector< art::Ptr< recob::SpacePoint > > FindTrackSpacePoints(std::vector< art::Ptr< recob::SpacePoint >> &spacePoints, TVector3 &showerStartPosition, TVector3 &showerDirection)
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
std::string string
Definition: nybbler.cc:12
void OrderShowerSpacePoints(std::vector< art::Ptr< recob::SpacePoint >> &showersps, TVector3 const &vertex, TVector3 const &direction) const
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
struct vector vector
STL namespace.
const art::FindManyP< T1 > & GetFindManyP(const art::ValidHandle< std::vector< T2 > > &handle, const art::Event &evt, const art::InputTag &moduleTag)
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
int CalculateElement(const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder) override
T abs(T value)
key_type key() const noexcept
Definition: Ptr.h:216
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
bool CheckElement(const std::string &Name) const
double SpacePointProjection(art::Ptr< recob::SpacePoint > const &sp, TVector3 const &vertex, TVector3 const &direction) const
int GetElement(const std::string &Name, T &Element) const
Detector simulation of raw signals on wires.
const shower::LArPandoraShowerAlg & GetLArPandoraShowerAlg() const
Definition: IShowerTool.h:87
Definition: types.h:32
double SpacePointPerpendicular(art::Ptr< recob::SpacePoint > const &sp, TVector3 const &vertex, TVector3 const &direction) const
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
int bool
Definition: qglobal.h:345
QTextStream & endl(QTextStream &s)