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
11 
12 //LArSoft Includes
14 
15 namespace ShowerRecoTools {
16 
18 
19  public:
21 
22  //Calculate the direction from the inital track
23  int CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
25  reco::shower::ShowerElementHolder& ShowerEleHolder) override;
26 
27  private:
28  //fcl
29  int fVerbose;
30  bool fUsePandoraVertex; //Direction from point defined as
31  //(Position of traj point - Vertex) rather than
32  //(Position of traj point - Track Start Point).
33  bool fUsePositonInfo; //Don't use the direction At point rather than definition
34  //above.
35  //((Position of traj point + 1) - (Position of traj point).
36  int fTrajPoint; //Trajectory point to get the direction from.
37 
41  };
42 
44  : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
45  , fVerbose(pset.get<int>("Verbose"))
46  , fUsePandoraVertex(pset.get<bool>("UsePandoraVertex"))
47  , fUsePositonInfo(pset.get<bool>("UsePositonInfo"))
48  , fTrajPoint(pset.get<int>("TrajPoint"))
49  , fInitialTrackInputLabel(pset.get<std::string>("InitialTrackInputLabel"))
50  , fShowerStartPositionInputLabel(pset.get<std::string>("ShowerStartPositionInputLabel"))
51  , fShowerDirectionOutputLabel(pset.get<std::string>("ShowerDirectionOutputLabel"))
52  {}
53 
54  int
56  const art::Ptr<recob::PFParticle>& pfparticle,
57  art::Event& Event,
58  reco::shower::ShowerElementHolder& ShowerEleHolder)
59  {
60 
61  //Check the Track has been defined
62  if (!ShowerEleHolder.CheckElement(fInitialTrackInputLabel)) {
63  if (fVerbose)
64  mf::LogError("ShowerTrackTrajPointDirection") << "Initial track not set" << std::endl;
65  return 1;
66  }
67  recob::Track InitialTrack;
68  ShowerEleHolder.GetElement(fInitialTrackInputLabel, InitialTrack);
69 
70  if ((int)InitialTrack.NumberTrajectoryPoints() - 1 < fTrajPoint) {
71  if (fVerbose)
72  mf::LogError("ShowerTrackTrajPointDirection")
73  << "Less that fTrajPoint trajectory points, bailing." << std::endl;
74  fTrajPoint = InitialTrack.NumberTrajectoryPoints() - 1;
75  }
76 
77  //ignore bogus info.
78  auto flags = InitialTrack.FlagsAtPoint(fTrajPoint);
80  if (fVerbose)
81  mf::LogError("ShowerTrackTrajPointDirection")
82  << "Bogus trajectory point bailing." << std::endl;
83  return 1;
84  }
85 
86  geo::Vector_t Direction_vec;
87  //Get the difference between the point and the start position.
88  if (fUsePositonInfo) {
89  //Get the start position.
90  geo::Point_t StartPosition;
91  if (fUsePandoraVertex) {
92  //Check the Track has been defined
93  if (!ShowerEleHolder.CheckElement(fShowerStartPositionInputLabel)) {
94  if (fVerbose)
95  mf::LogError("ShowerTrackTrajPointDirection")
96  << "Shower start position not set" << std::endl;
97  return 1;
98  }
99  TVector3 StartPosition_vec = {-999, -999, -999};
100  ShowerEleHolder.GetElement(fShowerStartPositionInputLabel, StartPosition_vec);
101  StartPosition.SetCoordinates(
102  StartPosition_vec.X(), StartPosition_vec.Y(), StartPosition_vec.Z());
103  }
104  else {
105  StartPosition = InitialTrack.Start();
106  }
107  //Get the specific trajectory point and look and and the direction from the start position
108  geo::Point_t TrajPosition = InitialTrack.LocationAtPoint(fTrajPoint);
109  Direction_vec = (TrajPosition - StartPosition).Unit();
110  }
111  else {
112  //Use the direction of the trajection at tat point;
113  Direction_vec = InitialTrack.DirectionAtPoint(fTrajPoint);
114  }
115 
116  TVector3 Direction = {Direction_vec.X(), Direction_vec.Y(), Direction_vec.Z()};
117  TVector3 DirectionErr = {-999, -999, -999};
118  ShowerEleHolder.SetElement(Direction, DirectionErr, fShowerDirectionOutputLabel);
119  return 0;
120  }
121 }
122 
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
static constexpr Flag_t NoPoint
The trajectory point is not defined.
std::string string
Definition: nybbler.cc:12
Point_t const & LocationAtPoint(size_t i) const
Definition: Track.h:126
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.
Definition: Track.h:102
STL namespace.
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
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
Point_t const & Start() const
Access to track position at different points.
Definition: Track.h:123
bool CheckElement(const std::string &Name) const
int GetElement(const std::string &Name, T &Element) const
int CalculateElement(const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder) override
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
Definition: types.h:32
PointFlags_t const & FlagsAtPoint(size_t i) const
Definition: Track.h:118
Vector_t DirectionAtPoint(size_t i) const
Definition: Track.h:134
Direction
Definition: AssnsIter.h:13
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
int bool
Definition: qglobal.h:345
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:49
QTextStream & endl(QTextStream &s)