Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
ShowerLengthPercentile_tool.cc
Go to the documentation of this file.
1//############################################################################
2//### Name: ShowerLengthPercentile ###
3//### Author: Dominic Barker ###
4//### Date: 13.05.19 ###
5//### Description: Simple code to calculate the lenght such that a given % ###
6//### of the hits are within the length. ###
7//############################################################################
8
9//Framework Includes
10#include "art/Utilities/ToolMacros.h"
11
12//LArSoft Includes
13#include "lardataobj/RecoBase/PFParticle.h"
14#include "lardataobj/RecoBase/SpacePoint.h"
16
17namespace ShowerRecoTools {
18
20
21 public:
22 ShowerLengthPercentile(const fhicl::ParameterSet& pset);
23
24 //Generic Direction Finder
25 int CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
26 art::Event& Event,
27 reco::shower::ShowerElementHolder& ShowerEleHolder) override;
28
29 private:
31
32 art::InputTag fPFParticleLabel;
38 };
39
40 ShowerLengthPercentile::ShowerLengthPercentile(const fhicl::ParameterSet& pset)
41 : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
42 , fPercentile(pset.get<float>("Percentile"))
43 , fPFParticleLabel(pset.get<art::InputTag>("PFParticleLabel"))
44 , fVerbose(pset.get<int>("Verbose"))
45 , fShowerStartPositionInputLabel(pset.get<std::string>("ShowerStartPositionInputLabel"))
46 , fShowerDirectionInputLabel(pset.get<std::string>("ShowerDirectionInputLabel"))
47 , fShowerLengthOutputLabel(pset.get<std::string>("ShowerLengthOutputLabel"))
48 , fShowerOpeningAngleOutputLabel(pset.get<std::string>("ShowerOpeningAngleOutputLabel"))
49 {}
50
51 int ShowerLengthPercentile::CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
52 art::Event& Event,
53 reco::shower::ShowerElementHolder& ShowerEleHolder)
54 {
55
56 //Get the start position
57 if (!ShowerEleHolder.CheckElement(fShowerStartPositionInputLabel)) {
58 if (fVerbose)
59 mf::LogError("ShowerLengthPercentile") << "Start position not set, returning " << std::endl;
60 return 1;
61 }
62 //Only consider hits in the same tpcs as the vertex.
63 geo::Point_t ShowerStartPosition = {-999, -999, -999};
64 ShowerEleHolder.GetElement(fShowerStartPositionInputLabel, ShowerStartPosition);
65
66 // Get the assocated pfParicle Handle
67 auto const pfpHandle = Event.getValidHandle<std::vector<recob::PFParticle>>(fPFParticleLabel);
68
69 // Get the spacepoint - PFParticle assn
70 const art::FindManyP<recob::SpacePoint>& fmspp =
71 ShowerEleHolder.GetFindManyP<recob::SpacePoint>(pfpHandle, Event, fPFParticleLabel);
72
73 // Get the SpacePoints
74 std::vector<art::Ptr<recob::SpacePoint>> spacePoints = fmspp.at(pfparticle.key());
75 if (spacePoints.empty()) {
76 if (fVerbose)
77 mf::LogError("ShowerLengthPercentile") << "No Spacepoints, returning" << std::endl;
78 return 1;
79 }
80
81 if (!ShowerEleHolder.CheckElement(fShowerDirectionInputLabel)) {
82 if (fVerbose)
83 mf::LogError("ShowerLengthPercentile") << "Direction not set, returning " << std::endl;
84 return 1;
85 }
86
87 geo::Vector_t ShowerDirection = {-999, -999, -999};
88 ShowerEleHolder.GetElement(fShowerDirectionInputLabel, ShowerDirection);
89
90 //Order the spacepoints
92 spacePoints, ShowerStartPosition, ShowerDirection);
93
94 //Find the length as the value that contains % of the hits
95 int lengthIter = fPercentile * spacePoints.size();
96
97 //Find the length
99 spacePoints[lengthIter], ShowerStartPosition, ShowerDirection);
100 double ShowerMaxProjection = IShowerTool::GetLArPandoraShowerAlg().SpacePointProjection(
101 spacePoints[spacePoints.size() - 1], ShowerStartPosition, ShowerDirection);
102
103 double ShowerLengthError = ShowerMaxProjection - ShowerLength;
104
105 //Order the spacepoints in perpendicular
107 spacePoints, ShowerStartPosition, ShowerDirection);
108
109 //Find the length as the value that contains % of the hits
110 int perpIter = fPercentile * spacePoints.size();
111
112 //Find the width of the shower
114 spacePoints[perpIter], ShowerStartPosition, ShowerDirection);
115 // double ShowerMaxWidth = IShowerTool::GetLArPandoraShowerAlg().SpacePointPerpendicular(
116 // spacePoints[spacePoints.size() -1], ShowerStartPosition, ShowerDirection);
117
118 double ShowerAngle = std::atan(ShowerWidth / ShowerLength);
119 double ShowerAngleError = -999; //TODO: Do properly
120
121 // Fill the shower element holder
122 ShowerEleHolder.SetElement(ShowerLength, ShowerLengthError, fShowerLengthOutputLabel);
123 ShowerEleHolder.SetElement(ShowerAngle, ShowerAngleError, fShowerOpeningAngleOutputLabel);
124
125 return 0;
126 }
127}
128
129DEFINE_ART_CLASS_TOOL(ShowerRecoTools::ShowerLengthPercentile)
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
ShowerLengthPercentile(const fhicl::ParameterSet &pset)
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
void OrderShowerSpacePointsPerpendicular(std::vector< art::Ptr< recob::SpacePoint > > &showersps, geo::Point_t const &vertex, geo::Vector_t const &direction) const
double SpacePointPerpendicular(art::Ptr< recob::SpacePoint > const &sp, geo::Point_t const &vertex, geo::Vector_t const &direction) const
double SpacePointProjection(art::Ptr< recob::SpacePoint > const &sp, geo::Point_t const &vertex, geo::Vector_t const &direction) const