LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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
11 
12 //LArSoft Includes
16 
17 namespace ShowerRecoTools {
18 
20 
21  public:
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:
30  float fPercentile;
31 
33  int fVerbose;
38  };
39 
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 
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
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 
void OrderShowerSpacePointsPerpendicular(std::vector< art::Ptr< recob::SpacePoint >> &showersps, geo::Point_t const &vertex, geo::Vector_t const &direction) const
#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
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
STL namespace.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
ShowerLengthPercentile(const fhicl::ParameterSet &pset)
double SpacePointPerpendicular(art::Ptr< recob::SpacePoint > const &sp, geo::Point_t const &vertex, geo::Vector_t const &direction) const
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
double SpacePointProjection(art::Ptr< recob::SpacePoint > const &sp, geo::Point_t const &vertex, geo::Vector_t const &direction) 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
void OrderShowerSpacePoints(std::vector< art::Ptr< recob::SpacePoint >> &showersps, geo::Point_t const &vertex, geo::Vector_t const &direction) const
Definition: MVAAlg.h:12
const art::FindManyP< T1 > & GetFindManyP(const art::ValidHandle< std::vector< T2 >> &handle, const art::Event &evt, const art::InputTag &moduleTag)