All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
16 
17 namespace 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:
30  float fPercentile;
31 
32  art::InputTag fPFParticleLabel;
33  int fVerbose;
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
52  ShowerLengthPercentile::CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
53  art::Event& Event,
54  reco::shower::ShowerElementHolder& ShowerEleHolder)
55  {
56 
57  //Get the start position
58  if (!ShowerEleHolder.CheckElement(fShowerStartPositionInputLabel)) {
59  if (fVerbose)
60  mf::LogError("ShowerLengthPercentile") << "Start position not set, returning " << std::endl;
61  return 1;
62  }
63  //Only consider hits in the same tpcs as the vertex.
64  TVector3 ShowerStartPosition = {-999, -999, -999};
65  ShowerEleHolder.GetElement(fShowerStartPositionInputLabel, ShowerStartPosition);
66 
67  // Get the assocated pfParicle Handle
68  auto const pfpHandle = Event.getValidHandle<std::vector<recob::PFParticle>>(fPFParticleLabel);
69 
70  // Get the spacepoint - PFParticle assn
71  const art::FindManyP<recob::SpacePoint>& fmspp =
72  ShowerEleHolder.GetFindManyP<recob::SpacePoint>(pfpHandle, Event, fPFParticleLabel);
73 
74  // Get the SpacePoints
75  std::vector<art::Ptr<recob::SpacePoint>> spacePoints = fmspp.at(pfparticle.key());
76  if (spacePoints.empty()) {
77  if (fVerbose)
78  mf::LogError("ShowerLengthPercentile") << "No Spacepoints, returning" << std::endl;
79  return 1;
80  }
81 
82  if (!ShowerEleHolder.CheckElement(fShowerDirectionInputLabel)) {
83  if (fVerbose)
84  mf::LogError("ShowerLengthPercentile") << "Direction not set, returning " << std::endl;
85  return 1;
86  }
87 
88  TVector3 ShowerDirection = {-999, -999, -999};
89  ShowerEleHolder.GetElement(fShowerDirectionInputLabel, ShowerDirection);
90 
91  //Order the spacepoints
93  spacePoints, ShowerStartPosition, ShowerDirection);
94 
95  //Find the length as the value that contains % of the hits
96  int lengthIter = fPercentile * spacePoints.size();
97 
98  //Find the length
100  spacePoints[lengthIter], ShowerStartPosition, ShowerDirection);
101  double ShowerMaxProjection = IShowerTool::GetLArPandoraShowerAlg().SpacePointProjection(
102  spacePoints[spacePoints.size() - 1], ShowerStartPosition, ShowerDirection);
103 
104  double ShowerLengthError = ShowerMaxProjection - ShowerLength;
105 
106  //Order the spacepoints in perpendicular
108  spacePoints, ShowerStartPosition, ShowerDirection);
109 
110  //Find the length as the value that contains % of the hits
111  int perpIter = fPercentile * spacePoints.size();
112 
113  //Find the width of the shower
115  spacePoints[perpIter], ShowerStartPosition, ShowerDirection);
116  // double ShowerMaxWidth = IShowerTool::GetLArPandoraShowerAlg().SpacePointPerpendicular(
117  // spacePoints[spacePoints.size() -1], ShowerStartPosition, ShowerDirection);
118 
119  double ShowerAngle = std::atan(ShowerWidth / ShowerLength);
120  double ShowerAngleError = -999; //TODO: Do properly
121 
122  // Fill the shower element holder
123  ShowerEleHolder.SetElement(ShowerLength, ShowerLengthError, fShowerLengthOutputLabel);
124  ShowerEleHolder.SetElement(ShowerAngle, ShowerAngleError, fShowerOpeningAngleOutputLabel);
125 
126  return 0;
127  }
128 }
129 
130 DEFINE_ART_CLASS_TOOL(ShowerRecoTools::ShowerLengthPercentile)
void OrderShowerSpacePointsPerpendicular(std::vector< art::Ptr< recob::SpacePoint >> &showersps, TVector3 const &vertex, TVector3 const &direction) const
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
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)
ShowerLengthPercentile(const fhicl::ParameterSet &pset)
int CalculateElement(const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder) override
bool CheckElement(const std::string &Name) const
double SpacePointProjection(art::Ptr< recob::SpacePoint > const &sp, TVector3 const &vertex, TVector3 const &direction) const
int GetElement(const std::string &Name, T &Element) const
const shower::LArPandoraShowerAlg & GetLArPandoraShowerAlg() const
Definition: IShowerTool.h:88
double SpacePointPerpendicular(art::Ptr< recob::SpacePoint > const &sp, TVector3 const &vertex, TVector3 const &direction) const