Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
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
13#include "lardata/DetectorInfoServices/DetectorClocksService.h"
14#include "lardata/DetectorInfoServices/DetectorPropertiesService.h"
15#include "lardataobj/RecoBase/Hit.h"
16#include "lardataobj/RecoBase/PFParticle.h"
17#include "lardataobj/RecoBase/SpacePoint.h"
18#include "lardataobj/RecoBase/Vertex.h"
20
21namespace 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;
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
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 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
99 const art::FindManyP<recob::SpacePoint>& fmspp =
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 =
115 art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(Event);
116 auto const detProp =
117 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(Event, clockData);
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}
const shower::LArPandoraShowerAlg & GetLArPandoraShowerAlg() const
Definition IShowerTool.h:82
int CalculateElement(const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder) override
int GetElement(const std::string &Name, T &Element) const
const art::FindManyP< T1 > & GetFindManyP(const art::ValidHandle< std::vector< T2 > > &handle, const art::Event &evt, const art::InputTag &moduleTag)
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
bool CheckElement(const std::string &Name) const
void OrderShowerSpacePoints(std::vector< art::Ptr< recob::SpacePoint > > &showersps, geo::Point_t const &vertex, geo::Vector_t const &direction) const
geo::Point_t ShowerCentre(std::vector< art::Ptr< recob::SpacePoint > > const &showersps) const