All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ShowerTrackSpacePointDirection_tool.cc
Go to the documentation of this file.
1 //############################################################################
2 //### Name: ShowerTrackSpacePointDirection ###
3 //### Author: Dominic Barker ###
4 //### Date: 13.05.19 ###
5 //### Description: Tool for finding the shower direction using the ###
6 //### the average direction of theinitial track spacepoints. ###
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  ShowerTrackSpacePointDirection(const fhicl::ParameterSet& pset);
23 
24  //Calculate the direction using the initial track spacepoints
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 SP - Vertex) rather than
34  //(Position of SP - Track Start Point).
35 
40  };
41 
43  : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
44  , fVerbose(pset.get<int>("Verbose"))
45  , fUsePandoraVertex(pset.get<bool>("UsePandoraVertex"))
46  , fInitialTrackSpacePointsInputLabel(pset.get<std::string>("InitialTrackSpacePointsInputLabel"))
47  , fShowerStartPositionInputLabel(pset.get<std::string>("ShowerStartPositionInputLabel"))
48  , fInitialTrackInputLabel(pset.get<std::string>("InitialTrackInputLabel"))
49  , fShowerDirectionOutputLabel(pset.get<std::string>("ShowerDirectionOutputLabel"))
50  {}
51 
52  int
54  const art::Ptr<recob::PFParticle>& pfparticle,
55  art::Event& Event,
56  reco::shower::ShowerElementHolder& ShowerEleHolder)
57  {
58 
59  //Check the Track Hits has been defined
60  if (!ShowerEleHolder.CheckElement(fInitialTrackSpacePointsInputLabel)) {
61  if (fVerbose)
62  mf::LogError("ShowerTrackSpacePointDirection")
63  << "Initial track spacepoints not set" << std::endl;
64  return 0;
65  }
66 
67  //Check the start position is set.
69  if (fVerbose)
70  mf::LogError("ShowerTrackSpacePointDirection")
71  << "Start position not set, returning " << std::endl;
72  return 0;
73  }
74 
75  //Get the start poistion
76  TVector3 StartPosition = {-999, -999, -999};
77  if (fUsePandoraVertex) {
78  ShowerEleHolder.GetElement(fShowerStartPositionInputLabel, StartPosition);
79  }
80  else {
81  //Check the Tracks has been defined
82  if (!ShowerEleHolder.CheckElement(fInitialTrackInputLabel)) {
83  if (fVerbose)
84  mf::LogError("ShowerTrackSpacePointDirection") << "Initial track not set" << std::endl;
85  return 0;
86  }
87  recob::Track InitialTrack;
88  ShowerEleHolder.GetElement(fInitialTrackInputLabel, InitialTrack);
89  geo::Point_t Start_point = InitialTrack.Start();
90  StartPosition = {Start_point.X(), Start_point.Y(), Start_point.Z()};
91  }
92 
93  //Get the initial track hits.
94  std::vector<art::Ptr<recob::SpacePoint>> intitaltrack_sp;
95  ShowerEleHolder.GetElement(fInitialTrackSpacePointsInputLabel, intitaltrack_sp);
96 
97  //Calculate the mean direction and the the standard deviation
98  float sumX = 0, sumX2 = 0;
99  float sumY = 0, sumY2 = 0;
100  float sumZ = 0, sumZ2 = 0;
101 
102  //Get the spacepoints associated to the track hit
103  for (auto const& sp : intitaltrack_sp) {
104 
105  //Get the direction relative to the start positon
106  TVector3 pos = IShowerTool::GetLArPandoraShowerAlg().SpacePointPosition(sp) - StartPosition;
107  if (pos.Mag() == 0) { continue; }
108 
109  sumX = pos.X();
110  sumX2 += pos.X() * pos.X();
111  sumY = pos.Y();
112  sumY2 += pos.Y() * pos.Y();
113  sumZ = pos.Z();
114  sumZ2 += pos.Z() * pos.Z();
115  }
116 
117  float NumSps = intitaltrack_sp.size();
118  TVector3 Mean = {sumX / NumSps, sumY / NumSps, sumZ / NumSps};
119  Mean = Mean.Unit();
120 
121  float RMSX = 999;
122  float RMSY = 999;
123  float RMSZ = 999;
124  if (sumX2 / NumSps - ((sumX / NumSps) * ((sumX / NumSps))) > 0) {
125  RMSX = std::sqrt(sumX2 / NumSps - ((sumX / NumSps) * ((sumX / NumSps))));
126  }
127  if (sumY2 / NumSps - ((sumY / NumSps) * ((sumY / NumSps))) > 0) {
128  RMSY = std::sqrt(sumY2 / NumSps - ((sumY / NumSps) * ((sumY / NumSps))));
129  }
130  if (sumZ2 / NumSps - ((sumZ / NumSps) * ((sumZ / NumSps))) > 0) {
131  RMSZ = std::sqrt(sumZ2 / NumSps - ((sumZ / NumSps) * ((sumZ / NumSps))));
132  }
133 
134  //Loop over the spacepoints and remove ones the relative direction is not within one sigma.
135  TVector3 Direction_Mean = {0, 0, 0};
136  int N = 0;
137  for (auto const sp : intitaltrack_sp) {
138  TVector3 Direction =
140  if ((std::abs((Direction - Mean).X()) < 1 * RMSX) &&
141  (std::abs((Direction - Mean).Y()) < 1 * RMSY) &&
142  (std::abs((Direction - Mean).Z()) < 1 * RMSZ)) {
143  if (Direction.Mag() == 0) { continue; }
144  ++N;
145  Direction_Mean += Direction;
146  }
147  }
148 
149  if (N > 0) {
150  //Take the mean value
151  TVector3 Direction = Direction_Mean.Unit();
152  ShowerEleHolder.SetElement(Direction, fShowerDirectionOutputLabel);
153  }
154  else {
155  if (fVerbose)
156  mf::LogError("ShowerTrackSpacePointDirection")
157  << "None of the points are within 1 sigma" << std::endl;
158  return 1;
159  }
160  return 0;
161  }
162 }
163 
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
static constexpr bool
then echo echo For and will not be changed by echo further linking echo echo B echo The symbol is in the uninitialized data multiple common symbols may appear with the echo same name If the symbol is defined the common echo symbols are treated as undefined references For more echo details on common see the discussion of warn common echo in *Note Linker see the discussion of warn common echo in *Note Linker such as a global int variable echo as opposed to a large global array echo echo I echo The symbol is an indirect reference to another symbol This echo is a GNU extension to the a out object file format which is echo rarely used echo echo N echo The symbol is a debugging symbol echo echo R echo The symbol is in a read only data section echo echo S echo The symbol is in an uninitialized data section for small echo objects echo echo T echo The symbol is in the the normal defined echo symbol is used with no error When a weak undefined symbol echo is linked and the symbol is not the value of the echo weak symbol becomes zero with no error echo echo W echo The symbol is a weak symbol that has not been specifically echo tagged as a weak object symbol When a weak defined symbol echo is linked with a normal defined the normal defined echo symbol is used with no error When a weak undefined symbol echo is linked and the symbol is not the value of the echo weak symbol becomes zero with no error echo echo echo The symbol is a stabs symbol in an a out object file In echo this the next values printed are the stabs other echo the stabs desc and the stab type Stabs symbols are echo used to hold debugging information For more echo see *Note or object file format specific echo echo For Mac OS X
T abs(T value)
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.
const shower::LArPandoraShowerAlg & GetLArPandoraShowerAlg() const
Definition: IShowerTool.h:88
process_name largeant stream1 can override from command line with o or output physics producers generator N
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
int CalculateElement(const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder) override
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a &quot;fitted&quot; track:
TVector3 SpacePointPosition(art::Ptr< recob::SpacePoint > const &sp) const