All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ShowerTrackTrajPointDirection_tool.cc
Go to the documentation of this file.
1 //############################################################################
2 //### Name: ShowerTrackTrajPointDirection ###
3 //### Author: Dominic Barker ###
4 //### Date: 13.05.19 ###
5 //### Description: Tool for finding the shower direction using the ###
6 //### first trajectory of the initial track ###
7 //############################################################################
8 
9 //Framework Includes
10 #include "art/Utilities/ToolMacros.h"
11 
12 //LArSoft Includes
14 
16 
17 namespace ShowerRecoTools {
18 
20 
21  public:
22  ShowerTrackTrajPointDirection(const fhicl::ParameterSet& pset);
23 
24  //Calculate the direction from the inital track
25  int CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
26  art::Event& Event,
27  reco::shower::ShowerElementHolder& ShowerEleHolder) override;
28 
29  private:
30  //fcl
31  int fVerbose;
32  bool fUsePandoraVertex; //Direction from point defined as
33  //(Position of traj point - Vertex) rather than
34  //(Position of traj point - Track Start Point).
35  bool fUsePositonInfo; //Don't use the direction At point rather than definition
36  //above.
37  //((Position of traj point + 1) - (Position of traj point).
38  int fTrajPoint; //Trajectory point to get the direction from.
39 
43  };
44 
46  : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
47  , fVerbose(pset.get<int>("Verbose"))
48  , fUsePandoraVertex(pset.get<bool>("UsePandoraVertex"))
49  , fUsePositonInfo(pset.get<bool>("UsePositonInfo"))
50  , fTrajPoint(pset.get<int>("TrajPoint"))
51  , fInitialTrackInputLabel(pset.get<std::string>("InitialTrackInputLabel"))
52  , fShowerStartPositionInputLabel(pset.get<std::string>("ShowerStartPositionInputLabel"))
53  , fShowerDirectionOutputLabel(pset.get<std::string>("ShowerDirectionOutputLabel"))
54  {}
55 
56  int
58  const art::Ptr<recob::PFParticle>& pfparticle,
59  art::Event& Event,
60  reco::shower::ShowerElementHolder& ShowerEleHolder)
61  {
62 
63  //Check the Track has been defined
64  if (!ShowerEleHolder.CheckElement(fInitialTrackInputLabel)) {
65  if (fVerbose)
66  mf::LogError("ShowerTrackTrajPointDirection") << "Initial track not set" << std::endl;
67  return 1;
68  }
69  recob::Track InitialTrack;
70  ShowerEleHolder.GetElement(fInitialTrackInputLabel, InitialTrack);
71 
72  if ((int)InitialTrack.NumberTrajectoryPoints() - 1 < fTrajPoint) {
73  if (fVerbose)
74  mf::LogError("ShowerTrackTrajPointDirection")
75  << "Less that fTrajPoint trajectory points, bailing." << std::endl;
76  fTrajPoint = InitialTrack.NumberTrajectoryPoints() - 1;
77  }
78 
79  //ignore bogus info.
80  auto flags = InitialTrack.FlagsAtPoint(fTrajPoint);
82  if (fVerbose)
83  mf::LogError("ShowerTrackTrajPointDirection")
84  << "Bogus trajectory point bailing." << std::endl;
85  return 1;
86  }
87 
88  geo::Vector_t Direction_vec;
89  //Get the difference between the point and the start position.
90  if (fUsePositonInfo) {
91  //Get the start position.
92  geo::Point_t StartPosition;
93  if (fUsePandoraVertex) {
94  //Check the Track has been defined
95  if (!ShowerEleHolder.CheckElement(fShowerStartPositionInputLabel)) {
96  if (fVerbose)
97  mf::LogError("ShowerTrackTrajPointDirection")
98  << "Shower start position not set" << std::endl;
99  return 1;
100  }
101  TVector3 StartPosition_vec = {-999, -999, -999};
102  ShowerEleHolder.GetElement(fShowerStartPositionInputLabel, StartPosition_vec);
103  StartPosition.SetCoordinates(
104  StartPosition_vec.X(), StartPosition_vec.Y(), StartPosition_vec.Z());
105  }
106  else {
107  StartPosition = InitialTrack.Start();
108  }
109  //Get the specific trajectory point and look and and the direction from the start position
110  geo::Point_t TrajPosition = InitialTrack.LocationAtPoint(fTrajPoint);
111  Direction_vec = (TrajPosition - StartPosition).Unit();
112  }
113  else {
114  //Use the direction of the trajection at tat point;
115  Direction_vec = InitialTrack.DirectionAtPoint(fTrajPoint);
116  }
117 
118  TVector3 Direction = {Direction_vec.X(), Direction_vec.Y(), Direction_vec.Z()};
119  TVector3 DirectionErr = {-999, -999, -999};
120  ShowerEleHolder.SetElement(Direction, DirectionErr, fShowerDirectionOutputLabel);
121  return 0;
122  }
123 }
124 
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:164
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
static constexpr Flag_t NoPoint
The trajectory point is not defined.
Point_t const & LocationAtPoint(size_t i) const
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
static constexpr bool
Point_t const & Start() const
Access to track position at different points.
bool CheckElement(const std::string &Name) const
int GetElement(const std::string &Name, T &Element) const
Provides recob::Track data product.
int CalculateElement(const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder) override
PointFlags_t const & FlagsAtPoint(size_t i) const
Vector_t DirectionAtPoint(size_t i) const
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:184
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a &quot;fitted&quot; track: