All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
10 #include "art/Utilities/ToolMacros.h"
11 
12 //LArSoft Includes
20 
21 namespace ShowerRecoTools {
22 
24 
25  public:
26  ShowerPFPVertexStartPosition(const fhicl::ParameterSet& pset);
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
35  art::InputTag fPFParticleLabel;
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 
49  int
50  ShowerPFPVertexStartPosition::CalculateElement(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 
58  const art::FindManyP<recob::Vertex>& fmv =
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  double xyz[3] = {-999, -999, -999};
87  StartPositionVertex->XYZ(xyz);
88  TVector3 ShowerStartPosition = {xyz[0], xyz[1], xyz[2]};
89  TVector3 ShowerStartPositionErr = {-999, -999, -999};
90  ShowerEleHolder.SetElement(
91  ShowerStartPosition, ShowerStartPositionErr, fShowerStartPositionOutputLabel);
92  return 0;
93  }
94 
95  //If we there have none then use the direction to find the neutrino vertex
96  if (ShowerEleHolder.CheckElement(fShowerDirectionInputLabel)) {
97 
98  TVector3 ShowerDirection = {-999, -999, -999};
99  ShowerEleHolder.GetElement(fShowerDirectionInputLabel, ShowerDirection);
100 
101  const art::FindManyP<recob::SpacePoint>& fmspp =
102  ShowerEleHolder.GetFindManyP<recob::SpacePoint>(pfpHandle, Event, fPFParticleLabel);
103 
104  //Get the spacepoints handle and the hit assoication
105  auto const spHandle = Event.getValidHandle<std::vector<recob::SpacePoint>>(fPFParticleLabel);
106  const art::FindManyP<recob::Hit>& fmh =
107  ShowerEleHolder.GetFindManyP<recob::Hit>(spHandle, Event, fPFParticleLabel);
108 
109  //Get the spacepoints
110  std::vector<art::Ptr<recob::SpacePoint>> spacePoints_pfp = fmspp.at(pfparticle.key());
111 
112  //Cannot continue if we have no spacepoints
113  if (spacePoints_pfp.empty()) { return 0; }
114 
115  //Get the Shower Center
116  auto const clockData =
117  art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(Event);
118  auto const detProp =
119  art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(Event, clockData);
120 
121  TVector3 ShowerCentre = IShowerTool::GetLArPandoraShowerAlg().ShowerCentre(
122  clockData, detProp, spacePoints_pfp, fmh);
123 
124  //Order the Hits from the shower centre. The most negative will be the start position.
126  spacePoints_pfp, ShowerCentre, ShowerDirection);
127 
128  //Set the start position.
129  TVector3 ShowerStartPosition =
131 
132  TVector3 ShowerStartPositionErr = {-999, -999, -999};
133  ShowerEleHolder.SetElement(
134  ShowerStartPosition, ShowerStartPositionErr, fShowerStartPositionOutputLabel);
135 
136  return 0;
137  }
138 
139  if (fVerbose)
140  mf::LogWarning("ShowerPFPVertexStartPosition")
141  << "Start Position has not been set yet. If you are not calculating the start position "
142  "again then maybe you should stop";
143  return 0;
144  }
145 
146 }
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
void OrderShowerSpacePoints(std::vector< art::Ptr< recob::SpacePoint >> &showersps, TVector3 const &vertex, TVector3 const &direction) const
Declaration of signal hit object.
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
const art::FindManyP< T1 > & GetFindManyP(const art::ValidHandle< std::vector< T2 > > &handle, const art::Event &evt, const art::InputTag &moduleTag)
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
bool CheckElement(const std::string &Name) const
int GetElement(const std::string &Name, T &Element) const
const shower::LArPandoraShowerAlg & GetLArPandoraShowerAlg() const
Definition: IShowerTool.h:88
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 detProp
TVector3 SpacePointPosition(art::Ptr< recob::SpacePoint > const &sp) const