LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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
20 
21 namespace ShowerRecoTools {
22 
24 
25  public:
27 
28  //Calculate the start position
29  int CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
30  art::Event& Event,
31  reco::shower::ShowerElementHolder& ShowerEleHolder) override;
32 
33  private:
34  //fcl parameters
36  int fVerbose;
39  };
40 
42  : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
43  , fPFParticleLabel(pset.get<art::InputTag>("PFParticleLabel"))
44  , fVerbose(pset.get<int>("Verbose"))
45  , fShowerStartPositionOutputLabel(pset.get<std::string>("ShowerStartPositionOutputLabel"))
46  , fShowerDirectionInputLabel(pset.get<std::string>("ShowerDirectionInputLabel"))
47  {}
48 
50  const art::Ptr<recob::PFParticle>& pfparticle,
51  art::Event& Event,
52  reco::shower::ShowerElementHolder& ShowerEleHolder)
53  {
54 
55  // Get the assocated pfParicle vertex PFParticles
56  auto const pfpHandle = Event.getValidHandle<std::vector<recob::PFParticle>>(fPFParticleLabel);
57 
59  ShowerEleHolder.GetFindManyP<recob::Vertex>(pfpHandle, Event, fPFParticleLabel);
60  // art::FindManyP<recob::Vertex> fmv(pfpHandle, Event, fPFParticleLabel);
61  if (!fmv.isValid()) {
62  throw cet::exception("ShowerPFPVertexStartPosition")
63  << "Vertex and PF particle association is somehow not valid. Stopping";
64  }
65 
66  std::vector<art::Ptr<recob::Vertex>> vtx_cand;
67  try {
68  vtx_cand = fmv.at(pfparticle.key());
69  }
70  catch (...) {
71  if (fVerbose)
72  mf::LogError("ShowerPFPVertexStartPosition") << "PFP-Vertex assan not set, returning";
73  return 1;
74  }
75  //If there is more than one then fail becuase I don't think that this can be the case
76  if (vtx_cand.size() != 1) {
77  if (fVerbose)
78  mf::LogError("ShowerPFPVertexStartPosition")
79  << "Wrong number of vertices: " << vtx_cand.size() << ", returning";
80  return 1;
81  }
82 
83  //If there is only one vertex good news we just say that is the start of the shower.
84  if (vtx_cand.size() == 1) {
85  art::Ptr<recob::Vertex> StartPositionVertex = vtx_cand[0];
86  auto ShowerStartPosition(StartPositionVertex->position());
87  geo::Point_t ShowerStartPositionErr = {-999, -999, -999};
88  ShowerEleHolder.SetElement(
89  ShowerStartPosition, ShowerStartPositionErr, fShowerStartPositionOutputLabel);
90  return 0;
91  }
92 
93  //If we there have none then use the direction to find the neutrino vertex
94  if (ShowerEleHolder.CheckElement(fShowerDirectionInputLabel)) {
95 
96  geo::Vector_t ShowerDirection = {-999, -999, -999};
97  ShowerEleHolder.GetElement(fShowerDirectionInputLabel, ShowerDirection);
98 
100  ShowerEleHolder.GetFindManyP<recob::SpacePoint>(pfpHandle, Event, fPFParticleLabel);
101 
102  //Get the spacepoints handle and the hit assoication
103  auto const spHandle = Event.getValidHandle<std::vector<recob::SpacePoint>>(fPFParticleLabel);
104  const art::FindManyP<recob::Hit>& fmh =
105  ShowerEleHolder.GetFindManyP<recob::Hit>(spHandle, Event, fPFParticleLabel);
106 
107  //Get the spacepoints
108  std::vector<art::Ptr<recob::SpacePoint>> spacePoints_pfp = fmspp.at(pfparticle.key());
109 
110  //Cannot continue if we have no spacepoints
111  if (spacePoints_pfp.empty()) { return 0; }
112 
113  //Get the Shower Center
114  auto const clockData =
116  auto const detProp =
118 
120  clockData, detProp, spacePoints_pfp, fmh);
121 
122  //Order the Hits from the shower centre. The most negative will be the start position.
124  spacePoints_pfp, ShowerCentre, ShowerDirection);
125 
126  //Set the start position.
127  auto ShowerStartPosition = spacePoints_pfp[0]->position();
128 
129  geo::Point_t ShowerStartPositionErr = {-999, -999, -999};
130  ShowerEleHolder.SetElement(
131  ShowerStartPosition, ShowerStartPositionErr, fShowerStartPositionOutputLabel);
132 
133  return 0;
134  }
135 
136  if (fVerbose)
137  mf::LogWarning("ShowerPFPVertexStartPosition")
138  << "Start Position has not been set yet. If you are not calculating the start position "
139  "again then maybe you should stop";
140  return 0;
141  }
142 
143 }
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:160
Declaration of signal hit object.
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
STL namespace.
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
parameter set interface
key_type key() const noexcept
Definition: Ptr.h:166
bool CheckElement(const std::string &Name) const
int GetElement(const std::string &Name, T &Element) const
const shower::LArPandoraShowerAlg & GetLArPandoraShowerAlg() const
Definition: IShowerTool.h:82
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:180
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
geo::Point_t ShowerCentre(std::vector< art::Ptr< recob::SpacePoint >> const &showersps) const
void OrderShowerSpacePoints(std::vector< art::Ptr< recob::SpacePoint >> &showersps, geo::Point_t const &vertex, geo::Vector_t const &direction) const
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Definition: MVAAlg.h:12
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:46
const art::FindManyP< T1 > & GetFindManyP(const art::ValidHandle< std::vector< T2 >> &handle, const art::Event &evt, const art::InputTag &moduleTag)
const Point_t & position() const
Return vertex 3D position.
Definition: Vertex.h:64
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33