All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ShowerTrackHitDirection_tool.cc
Go to the documentation of this file.
1 //############################################################################
2 //### Name: ShowerTrackHitDirection ###
3 //### Author: Dominic Barker ###
4 //### Date: 13.05.19 ###
5 //### Description: Tool for finding the shower direction using the ###
6 //### initial track the average direction of the initial hits ###
7 //############################################################################
8 
9 //Framework Includes
10 #include "art/Utilities/ToolMacros.h"
11 
12 //LArSoft Includes
14 
18 
19 namespace ShowerRecoTools {
20 
22 
23  public:
24  ShowerTrackHitDirection(const fhicl::ParameterSet& pset);
25 
26  //Calculate the shower direction from the initial track hits.
27  int CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
28  art::Event& Event,
29  reco::shower::ShowerElementHolder& ShowerEleHolder) override;
30 
31  private:
32  //fcl
33  int fVerbose;
34  bool fUsePandoraVertex; //Direction from point defined as (Position of Hit - Vertex)
35  //rather than (Position of Hit - Track Start Point)
36  art::InputTag fHitModuleLabel;
37  art::InputTag fPFParticleLabel;
38 
43  };
44 
45  ShowerTrackHitDirection::ShowerTrackHitDirection(const fhicl::ParameterSet& pset)
46  : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
47  , fVerbose(pset.get<int>("Verbose"))
48  , fUsePandoraVertex(pset.get<bool>("UsePandoraVertex"))
49  , fHitModuleLabel(pset.get<art::InputTag>("HitModuleLabel"))
50  , fPFParticleLabel(pset.get<art::InputTag>("PFParticleLabel"))
51  , fInitialTrackHitsInputLabel(pset.get<std::string>("InitialTrackHitsInputLabel"))
52  , fShowerStartPositionInputLabel(pset.get<std::string>("ShowerStartPositionInputLabel"))
53  , fInitialTrackInputLabel(pset.get<std::string>("InitialTrackInputLabel"))
54  , fShowerDirectionOutputLabel(pset.get<std::string>("ShowerDirectionOutputLabel"))
55  {}
56 
57  int
58  ShowerTrackHitDirection::CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
59  art::Event& Event,
60  reco::shower::ShowerElementHolder& ShowerEleHolder)
61  {
62 
63  //Check the Track Hits has been defined
64  if (!ShowerEleHolder.CheckElement(fInitialTrackHitsInputLabel)) {
65  if (fVerbose)
66  mf::LogError("ShowerTrackHitDirection") << "Initial track hits not set" << std::endl;
67  return 0;
68  }
69 
70  //Check the start position is set.
72  if (fVerbose)
73  mf::LogError("ShowerTrackHitDirection")
74  << "Start position not set, returning " << std::endl;
75  return 0;
76  }
77 
78  //Get the start poistion
79  TVector3 StartPosition = {-999, -999, -99};
80  if (fUsePandoraVertex) {
81  ShowerEleHolder.GetElement(fShowerStartPositionInputLabel, StartPosition);
82  }
83  else {
84  //Check the Tracks has been defined
85  if (!ShowerEleHolder.CheckElement(fInitialTrackInputLabel)) {
86  if (fVerbose)
87  mf::LogError("ShowerTrackHitDirection") << "Initial track not set" << std::endl;
88  return 0;
89  }
90  recob::Track InitialTrack;
91  ShowerEleHolder.GetElement(fInitialTrackInputLabel, InitialTrack);
92  geo::Point_t Start_point = InitialTrack.Start();
93  StartPosition = {Start_point.X(), Start_point.Y(), Start_point.Z()};
94  }
95 
96  //Get the spacepoints associated to hits
97  auto const hitHandle = Event.getValidHandle<std::vector<recob::Hit>>(fHitModuleLabel);
98 
99  //Get the spacepoint handle. We need to do this in 3D.
100  const art::FindManyP<recob::SpacePoint>& fmsp =
101  ShowerEleHolder.GetFindManyP<recob::SpacePoint>(hitHandle, Event, fPFParticleLabel);
102 
103  //Get the initial track hits.
104  std::vector<art::Ptr<recob::Hit>> InitialTrackHits;
105  ShowerEleHolder.GetElement(fInitialTrackHitsInputLabel, InitialTrackHits);
106 
107  //Calculate the mean direction and the the standard deviation
108  float sumX = 0, sumX2 = 0;
109  float sumY = 0, sumY2 = 0;
110  float sumZ = 0, sumZ2 = 0;
111 
112  //Get the spacepoints associated to the track hit
113  std::vector<art::Ptr<recob::SpacePoint>> intitaltrack_sp;
114  for (auto const hit : InitialTrackHits) {
115  std::vector<art::Ptr<recob::SpacePoint>> sps = fmsp.at(hit.key());
116  for (auto const sp : sps) {
117  intitaltrack_sp.push_back(sp);
118 
119  //Get the direction relative to the start positon
120  TVector3 pos = IShowerTool::GetLArPandoraShowerAlg().SpacePointPosition(sp) - StartPosition;
121  if (pos.Mag() == 0) { continue; }
122 
123  sumX = pos.X();
124  sumX2 += pos.X() * pos.X();
125  sumY = pos.Y();
126  sumY2 += pos.Y() * pos.Y();
127  sumZ = pos.Z();
128  sumZ2 += pos.Z() * pos.Z();
129  }
130  }
131 
132  float NumSps = intitaltrack_sp.size();
133  TVector3 Mean = {sumX / NumSps, sumY / NumSps, sumZ / NumSps};
134  Mean = Mean.Unit();
135 
136  float RMSX = 999;
137  float RMSY = 999;
138  float RMSZ = 999;
139  if (sumX2 / NumSps - ((sumX / NumSps) * ((sumX / NumSps))) > 0) {
140  RMSX = std::sqrt(sumX2 / NumSps - ((sumX / NumSps) * ((sumX / NumSps))));
141  }
142  if (sumY2 / NumSps - ((sumY / NumSps) * ((sumY / NumSps))) > 0) {
143  RMSY = std::sqrt(sumY2 / NumSps - ((sumY / NumSps) * ((sumY / NumSps))));
144  }
145  if (sumZ2 / NumSps - ((sumZ / NumSps) * ((sumZ / NumSps))) > 0) {
146  RMSZ = std::sqrt(sumZ2 / NumSps - ((sumZ / NumSps) * ((sumZ / NumSps))));
147  }
148 
149  //Loop over the spacepoints and remove ones the relative direction is not within one sigma.
150  TVector3 Direction_Mean = {0, 0, 0};
151  int N = 0;
152  for (auto const sp : intitaltrack_sp) {
153  TVector3 Direction =
155  if ((std::abs((Direction - Mean).X()) < 1 * RMSX) &&
156  (std::abs((Direction - Mean).Y()) < 1 * RMSY) &&
157  (std::abs((Direction - Mean).Z()) < 1 * RMSZ)) {
158  if (Direction.Mag() == 0) { continue; }
159  ++N;
160  Direction_Mean += Direction;
161  }
162  }
163 
164  if (N > 0) {
165  //Take the mean value
166  TVector3 Direction = Direction_Mean.Unit();
167  ShowerEleHolder.SetElement(Direction, fShowerDirectionOutputLabel);
168  }
169  else {
170  if (fVerbose)
171  mf::LogError("ShowerTrackHitDirection")
172  << "None of the points are within 1 sigma" << std::endl;
173  return 1;
174  }
175  return 0;
176  }
177 }
178 
179 DEFINE_ART_CLASS_TOOL(ShowerRecoTools::ShowerTrackHitDirection)
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
Declaration of signal hit object.
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
static constexpr bool
const art::FindManyP< T1 > & GetFindManyP(const art::ValidHandle< std::vector< T2 > > &handle, const art::Event &evt, const art::InputTag &moduleTag)
process_name hit
Definition: cheaterreco.fcl:51
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
ShowerTrackHitDirection(const fhicl::ParameterSet &pset)
process_name largeant stream1 can override from command line with o or output physics producers generator N
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
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