ShowerPFPVertexStartPosition_tool.cc
Go to the documentation of this file.
1 //############################################################################
2 //### Name: ShowerPFPVertexStartPosition ###
3 //### Author: Dominic Barker (dominic.barker@sheffield.ac.uk ###
4 //### Date: 13.05.19 ###
5 //### Description: Tool for finding the start poistion ###
6 //### methods. ###
7 //############################################################################
8 
9 //Framework Includes
11 
12 //LArSoft Includes
15 
16 namespace ShowerRecoTools {
17 
19 
20  public:
22 
23  //Calculate the start position
24  int CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
26  reco::shower::ShowerElementHolder& ShowerEleHolder) override;
27 
28  private:
29  //fcl parameters
31  int fVerbose;
34  };
35 
37  : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
38  , fPFParticleLabel(pset.get<art::InputTag>("PFParticleLabel"))
39  , fVerbose(pset.get<int>("Verbose"))
40  , fShowerStartPositionOutputLabel(pset.get<std::string>("ShowerStartPositionOutputLabel"))
41  , fShowerDirectionInputLabel(pset.get<std::string>("ShowerDirectionInputLabel"))
42  {}
43 
44  int
46  art::Event& Event,
47  reco::shower::ShowerElementHolder& ShowerEleHolder)
48  {
49 
50  // Get the assocated pfParicle vertex PFParticles
51  auto const pfpHandle = Event.getValidHandle<std::vector<recob::PFParticle>>(fPFParticleLabel);
52 
53  const art::FindManyP<recob::Vertex>& fmv =
54  ShowerEleHolder.GetFindManyP<recob::Vertex>(pfpHandle, Event, fPFParticleLabel);
55  // art::FindManyP<recob::Vertex> fmv(pfpHandle, Event, fPFParticleLabel);
56  if (!fmv.isValid()) {
57  throw cet::exception("ShowerPFPVertexStartPosition")
58  << "Vertex and PF particle association is somehow not valid. Stopping";
59  }
60 
61  std::vector<art::Ptr<recob::Vertex>> vtx_cand;
62  try {
63  vtx_cand = fmv.at(pfparticle.key());
64  }
65  catch (...) {
66  if (fVerbose)
67  mf::LogError("ShowerPFPVertexStartPosition") << "PFP-Vertex assan not set, returning";
68  return 1;
69  }
70  //If there is more than one then fail becuase I don't think that this can be the case
71  if (vtx_cand.size() != 1) {
72  if (fVerbose)
73  mf::LogError("ShowerPFPVertexStartPosition")
74  << "Wrong number of vertices: " << vtx_cand.size() << ", returning";
75  return 1;
76  }
77 
78  //If there is only one vertex good news we just say that is the start of the shower.
79  if (vtx_cand.size() == 1) {
80  art::Ptr<recob::Vertex> StartPositionVertex = vtx_cand[0];
81  double xyz[3] = {-999, -999, -999};
82  StartPositionVertex->XYZ(xyz);
83  TVector3 ShowerStartPosition = {xyz[0], xyz[1], xyz[2]};
84  TVector3 ShowerStartPositionErr = {-999, -999, -999};
85  ShowerEleHolder.SetElement(
86  ShowerStartPosition, ShowerStartPositionErr, fShowerStartPositionOutputLabel);
87  return 0;
88  }
89 
90  //If we there have none then use the direction to find the neutrino vertex
91  if (ShowerEleHolder.CheckElement(fShowerDirectionInputLabel)) {
92 
93  TVector3 ShowerDirection = {-999, -999, -999};
94  ShowerEleHolder.GetElement(fShowerDirectionInputLabel, ShowerDirection);
95 
96  const art::FindManyP<recob::SpacePoint>& fmspp =
97  ShowerEleHolder.GetFindManyP<recob::SpacePoint>(pfpHandle, Event, fPFParticleLabel);
98 
99  //Get the spacepoints handle and the hit assoication
100  auto const spHandle = Event.getValidHandle<std::vector<recob::SpacePoint>>(fPFParticleLabel);
101  const art::FindManyP<recob::Hit>& fmh =
102  ShowerEleHolder.GetFindManyP<recob::Hit>(spHandle, Event, fPFParticleLabel);
103 
104  //Get the spacepoints
105  std::vector<art::Ptr<recob::SpacePoint>> spacePoints_pfp = fmspp.at(pfparticle.key());
106 
107  //Cannot continue if we have no spacepoints
108  if (spacePoints_pfp.empty()) { return 0; }
109 
110  //Get the Shower Center
111  auto const clockData =
113  auto const detProp =
115 
116  TVector3 ShowerCentre = IShowerTool::GetLArPandoraShowerAlg().ShowerCentre(
117  clockData, detProp, spacePoints_pfp, fmh);
118 
119  //Order the Hits from the shower centre. The most negative will be the start position.
121  spacePoints_pfp, ShowerCentre, ShowerDirection);
122 
123  //Set the start position.
124  TVector3 ShowerStartPosition =
126 
127  TVector3 ShowerStartPositionErr = {-999, -999, -999};
128  ShowerEleHolder.SetElement(
129  ShowerStartPosition, ShowerStartPositionErr, fShowerStartPositionOutputLabel);
130 
131  return 0;
132  }
133 
134  if (fVerbose)
135  mf::LogWarning("ShowerPFPVertexStartPosition")
136  << "Start Position has not been set yet. If you are not calculating the start position "
137  "again then maybe you should stop";
138  return 0;
139  }
140 
141 }
void XYZ(double *xyz) const
Legacy method to access vertex position, preserved to avoid breaking code. Please try to use Vertex::...
Definition: Vertex.cxx:36
#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)
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
Definition of vertex object for LArSoft.
Definition: Vertex.h:35
int CalculateElement(const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder) override
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
int GetElement(const std::string &Name, T &Element) const
const shower::LArPandoraShowerAlg & GetLArPandoraShowerAlg() const
Definition: IShowerTool.h:87
Definition: types.h:32
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
TVector3 ShowerCentre(std::vector< art::Ptr< recob::SpacePoint >> const &showersps) 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
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
TVector3 SpacePointPosition(art::Ptr< recob::SpacePoint > const &sp) const