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
14 
15 namespace ShowerRecoTools {
16 
18 
19  public:
21 
22  //Generic Direction Finder
23  int CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
25  reco::shower::ShowerElementHolder& ShowerEleHolder) override;
26 
27  private:
28  float fPercentile;
29 
31  int fVerbose;
36  };
37 
39  : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
40  , fPercentile(pset.get<float>("Percentile"))
41  , fPFParticleLabel(pset.get<art::InputTag>("PFParticleLabel"))
42  , fVerbose(pset.get<int>("Verbose"))
43  , fShowerStartPositionInputLabel(pset.get<std::string>("ShowerStartPositionInputLabel"))
44  , fShowerDirectionInputLabel(pset.get<std::string>("ShowerDirectionInputLabel"))
45  , fShowerLengthOutputLabel(pset.get<std::string>("ShowerLengthOutputLabel"))
46  , fShowerOpeningAngleOutputLabel(pset.get<std::string>("ShowerOpeningAngleOutputLabel"))
47  {}
48 
49  int
51  art::Event& Event,
52  reco::shower::ShowerElementHolder& ShowerEleHolder)
53  {
54 
55  //Get the start position
56  if (!ShowerEleHolder.CheckElement(fShowerStartPositionInputLabel)) {
57  if (fVerbose)
58  mf::LogError("ShowerLengthPercentile") << "Start position not set, returning " << std::endl;
59  return 1;
60  }
61  //Only consider hits in the same tpcs as the vertex.
62  TVector3 ShowerStartPosition = {-999, -999, -999};
63  ShowerEleHolder.GetElement(fShowerStartPositionInputLabel, ShowerStartPosition);
64 
65  // Get the assocated pfParicle Handle
66  auto const pfpHandle = Event.getValidHandle<std::vector<recob::PFParticle>>(fPFParticleLabel);
67 
68  // Get the spacepoint - PFParticle assn
69  const art::FindManyP<recob::SpacePoint>& fmspp =
70  ShowerEleHolder.GetFindManyP<recob::SpacePoint>(pfpHandle, Event, fPFParticleLabel);
71 
72  // Get the SpacePoints
73  std::vector<art::Ptr<recob::SpacePoint>> spacePoints = fmspp.at(pfparticle.key());
74  if (spacePoints.empty()) {
75  if (fVerbose)
76  mf::LogError("ShowerLengthPercentile") << "No Spacepoints, returning" << std::endl;
77  return 1;
78  }
79 
80  if (!ShowerEleHolder.CheckElement(fShowerDirectionInputLabel)) {
81  if (fVerbose)
82  mf::LogError("ShowerLengthPercentile") << "Direction not set, returning " << std::endl;
83  return 1;
84  }
85 
86  TVector3 ShowerDirection = {-999, -999, -999};
87  ShowerEleHolder.GetElement(fShowerDirectionInputLabel, ShowerDirection);
88 
89  //Order the spacepoints
91  spacePoints, ShowerStartPosition, ShowerDirection);
92 
93  //Find the length as the value that contains % of the hits
94  int lengthIter = fPercentile * spacePoints.size();
95 
96  //Find the length
98  spacePoints[lengthIter], ShowerStartPosition, ShowerDirection);
99  double ShowerMaxProjection = IShowerTool::GetLArPandoraShowerAlg().SpacePointProjection(
100  spacePoints[spacePoints.size() - 1], ShowerStartPosition, ShowerDirection);
101 
102  double ShowerLengthError = ShowerMaxProjection - ShowerLength;
103 
104  //Order the spacepoints in perpendicular
106  spacePoints, ShowerStartPosition, ShowerDirection);
107 
108  //Find the length as the value that contains % of the hits
109  int perpIter = fPercentile * spacePoints.size();
110 
111  //Find the width of the shower
113  spacePoints[perpIter], ShowerStartPosition, ShowerDirection);
114  // double ShowerMaxWidth = IShowerTool::GetLArPandoraShowerAlg().SpacePointPerpendicular(
115  // spacePoints[spacePoints.size() -1], ShowerStartPosition, ShowerDirection);
116 
117  double ShowerAngle = std::atan(ShowerWidth / ShowerLength);
118  double ShowerAngleError = -999; //TODO: Do properly
119 
120  // Fill the shower element holder
121  ShowerEleHolder.SetElement(ShowerLength, ShowerLengthError, fShowerLengthOutputLabel);
122  ShowerEleHolder.SetElement(ShowerAngle, ShowerAngleError, fShowerOpeningAngleOutputLabel);
123 
124  return 0;
125  }
126 }
127 
void OrderShowerSpacePointsPerpendicular(std::vector< art::Ptr< recob::SpacePoint >> &showersps, TVector3 const &vertex, TVector3 const &direction) const
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
std::string string
Definition: nybbler.cc:12
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)
STL namespace.
const art::FindManyP< T1 > & GetFindManyP(const art::ValidHandle< std::vector< T2 > > &handle, const art::Event &evt, const art::InputTag &moduleTag)
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
ShowerLengthPercentile(const fhicl::ParameterSet &pset)
int CalculateElement(const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder) override
key_type key() const noexcept
Definition: Ptr.h:216
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
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:87
Definition: types.h:32
double SpacePointPerpendicular(art::Ptr< recob::SpacePoint > const &sp, TVector3 const &vertex, TVector3 const &direction) const
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
QTextStream & endl(QTextStream &s)