TrackShowerSeparationAlg.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: TrackShowerSeparationAlg
3 // File: TrackShowerSeparationAlg.h
4 // Author: Mike Wallbank (m.wallbank@sheffield.ac.uk), November 2015
5 //
6 // Track/shower separation class.
7 // Provides methods for removing hits associated with track-like
8 // objects.
9 // To be run after track reconstruction, before shower reconstruction.
10 ////////////////////////////////////////////////////////////////////////
11 
12 #ifndef TrackShowerSeparationAlg_hxx
13 #define TrackShowerSeparationAlg_hxx
14 
15 // Framework
17 #include "canvas/Persistency/Common/FindManyP.h"
18 namespace fhicl { class ParameterSet; }
19 
20 // larsoft
24 
25 // ROOT
26 #include "TMath.h"
27 #include "TVector3.h"
28 
29 namespace shower {
30  class TrackShowerSeparationAlg;
31  class ReconTrack;
32 }
33 
35  public:
36 
37  ReconTrack(int id) {
38  fID = id;
39  fTrack = false;
40  fShower = false;
41  fShowerTrack = false;
42  fShowerCone = false;
43  }
44 
45  // Setters
46  void SetVertex(TVector3 vertex) { fVertex = vertex; }
47  void SetEnd(TVector3 end) { fEnd = end; }
48  void SetLength(double length) { fLength = length; }
49  void SetVertexDir(TVector3 vertexDir) { fVertexDir = vertexDir; }
50  void SetDirection(TVector3 direction) { fDirection = direction; }
51  void SetHits(std::vector<art::Ptr<recob::Hit> > hits) { fHits = hits; }
52  void SetSpacePoints(std::vector<art::Ptr<recob::SpacePoint> > spacePoints) { fSpacePoints = spacePoints; }
53 
54  void AddForwardTrack(int track) { if (std::find(fForwardConeTracks.begin(), fForwardConeTracks.end(), track) == fForwardConeTracks.end()) fForwardConeTracks.push_back(track); }
55  void AddBackwardTrack(int track) { if (std::find(fBackwardConeTracks.begin(), fBackwardConeTracks.end(), track) == fBackwardConeTracks.end()) fBackwardConeTracks.push_back(track); }
56  void AddShowerTrack(int track) { fShowerTracks.push_back(track); }
57 
58  void AddForwardSpacePoint(int spacePoint) { fForwardSpacePoints.push_back(spacePoint); }
59  void AddBackwardSpacePoint(int spacePoint) { fBackwardSpacePoints.push_back(spacePoint); }
60  void AddCylinderSpacePoint(int spacePoint) { fCylinderSpacePoints.push_back(spacePoint); }
61  void AddSphereSpacePoint(int spacePoint) { fSphereSpacePoints.push_back(spacePoint); }
62  void AddIsolationSpacePoint(int spacePoint, double distance) { fIsolationSpacePoints[spacePoint] = distance; }
63 
64  // Getters
65  int ID() const { return fID; }
66  TVector3 Vertex() const { return fVertex; }
67  TVector3 End() const { return fEnd; }
68  double Length() const { return fLength; }
69  TVector3 VertexDirection() const { return fVertexDir; }
70  TVector3 Direction() const { return fDirection; }
71  const std::vector<art::Ptr<recob::Hit> >& Hits() const { return fHits; }
72  const std::vector<art::Ptr<recob::SpacePoint> >& SpacePoints() const { return fSpacePoints; }
73 
74  void FlipTrack() {
75  TVector3 tmp = fEnd;
76  fEnd = fVertex;
77  fVertex = tmp;
78  fDirection *= -1;
79  }
80 
81  void MakeShower() {
82  if (fTrack)
83  this->MakeShowerTrack();
84  else
85  this->MakeShowerCone();
86  }
87  void MakeShowerTrack() {
88  fShower = true;
89  fShowerTrack = true;
90  fShowerCone = false;
91  fTrack = false;
92  }
93  void MakeShowerCone() {
94  fShower = true;
95  fShowerCone = true;
96  fShowerTrack = false;
97  fTrack = false;
98  }
99  void MakeTrack() {
100  fTrack = true;
101  fShower = false;
102  fShowerTrack = false;
103  fShowerCone = false;
104  }
105 
106  bool IsShower() const { return fShower; }
107  bool IsShowerTrack() const { return fShowerTrack; }
108  bool IsShowerCone() const { return fShowerCone; }
109  bool IsTrack() const { return fTrack; }
110  bool IsUndetermined() const { return !fTrack and !fShower; }
111 
112  int TrackConeSize() const { return (int)fForwardConeTracks.size() - (int)fBackwardConeTracks.size(); }
113  bool ShowerTrackCandidate() const { return TrackConeSize() > 5; }
114  const std::vector<int>& ShowerTracks() const { return fShowerTracks; }
115  const std::vector<int>& ForwardConeTracks() const { return fForwardConeTracks; }
116 
117  int ConeSize() const { return (int)fForwardSpacePoints.size() - (int)fBackwardSpacePoints.size(); }
118  int ForwardSpacePoints() const { return fForwardSpacePoints.size(); }
119  int NumCylinderSpacePoints() const { return fCylinderSpacePoints.size(); }
120  double CylinderSpacePointRatio() const { return (double)fCylinderSpacePoints.size()/(double)fSpacePoints.size(); }
121  int NumSphereSpacePoints() const { return fSphereSpacePoints.size(); }
122  double SphereSpacePointDensity(double scale) const { return (double)fSphereSpacePoints.size()/(4*TMath::Pi()*TMath::Power((scale*fLength/2.),3)/3.); }
123  double IsolationSpacePointDistance() const { std::vector<double> distances;
124  std::transform(fIsolationSpacePoints.begin(), fIsolationSpacePoints.end(), std::back_inserter(distances), [](const std::pair<int,double>& p){return p.second;});
125  return TMath::Mean(distances.begin(), distances.end()); }
126 
127  private:
128 
129  int fID;
130  TVector3 fVertex;
131  TVector3 fEnd;
132  double fLength;
133  TVector3 fVertexDir;
134  TVector3 fDirection;
135  std::vector<art::Ptr<recob::Hit> > fHits;
136  std::vector<art::Ptr<recob::SpacePoint> > fSpacePoints;
137 
138  std::vector<int> fForwardConeTracks;
139  std::vector<int> fBackwardConeTracks;
140  std::vector<int> fShowerTracks;
141 
142  std::vector<int> fForwardSpacePoints;
143  std::vector<int> fBackwardSpacePoints;
144  std::vector<int> fCylinderSpacePoints;
145  std::vector<int> fSphereSpacePoints;
146  std::map<int,double> fIsolationSpacePoints;
147 
148  bool fShower;
151  bool fTrack;
152 
153 };
154 
156  public:
157 
159 
160  /// Read in configurable parameters from provided parameter set
161  void reconfigure(fhicl::ParameterSet const& pset);
162 
163  std::vector<art::Ptr<recob::Hit> > SelectShowerHits(int event,
164  const std::vector<art::Ptr<recob::Hit> >& hits,
166  const std::vector<art::Ptr<recob::SpacePoint> >& spacePoints,
167  const art::FindManyP<recob::Hit>& fmht,
168  const art::FindManyP<recob::Track>& fmth,
169  const art::FindManyP<recob::SpacePoint>& fmspt,
170  const art::FindManyP<recob::Track>& fmtsp) const;
171 
172  private:
173 
174  ///
175  std::vector<int> InitialTrackLikeSegment(std::map<int,std::unique_ptr<ReconTrack> >& reconTracks) const;
176 
177  ///
178  TVector3 Gradient(const std::vector<TVector3>& points, const std::unique_ptr<TVector3>& dir) const;
179 
180  ///
181  TVector3 Gradient(const art::Ptr<recob::Track>& track) const;
182 
183  ///
184  TVector3 Gradient(const std::vector<art::Ptr<recob::SpacePoint> >& spacePoints) const;
185 
186  /// Projects the 3D point given along the line defined by the specified direction
187  /// Coordinate system is assumed to be centred at the origin unless a difference point is specified
188  TVector3 ProjPoint(const TVector3& point, const TVector3& direction, const TVector3& origin = TVector3(0,0,0)) const;
189 
190  /// Return 3D point of this space point
191  TVector3 SpacePointPos(const art::Ptr<recob::SpacePoint>& spacePoint) const;
192 
193  ///
194  double SpacePointsRMS(const std::vector<art::Ptr<recob::SpacePoint> >& spacePoints) const;
195 
196  // Parameters
197  int fDebug;
198 
199  // Properties
200  double fConeAngle;
202 
203  // Cuts
205  double fCylinderCut;
207 
208 };
209 
210 #endif
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
void SetDirection(TVector3 direction)
const std::vector< art::Ptr< recob::SpacePoint > > & SpacePoints() const
void SetEnd(TVector3 end)
const std::vector< int > & ForwardConeTracks() const
double CylinderSpacePointRatio() const
const std::vector< int > & ShowerTracks() const
void AddForwardSpacePoint(int spacePoint)
void SetLength(double length)
void AddBackwardTrack(int track)
double IsolationSpacePointDistance() const
struct vector vector
std::map< int, double > fIsolationSpacePoints
void SetSpacePoints(std::vector< art::Ptr< recob::SpacePoint > > spacePoints)
void AddForwardTrack(int track)
string dir
std::vector< int > fBackwardSpacePoints
void SetVertex(TVector3 vertex)
virtual void reconfigure(fhicl::ParameterSet const &pset)
std::vector< int > fForwardConeTracks
std::vector< art::Ptr< recob::SpacePoint > > fSpacePoints
const std::vector< art::Ptr< recob::Hit > > & Hits() const
p
Definition: test.py:223
std::vector< int > fSphereSpacePoints
string tmp
Definition: languages.py:63
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
void SetVertexDir(TVector3 vertexDir)
Definition: tracks.py:1
void AddCylinderSpacePoint(int spacePoint)
Declaration of signal hit object.
std::vector< int > fShowerTracks
std::vector< int > fForwardSpacePoints
TVector3 VertexDirection() const
double SphereSpacePointDensity(double scale) const
std::vector< art::Ptr< recob::Hit > > fHits
Provides recob::Track data product.
void AddSphereSpacePoint(int spacePoint)
void AddIsolationSpacePoint(int spacePoint, double distance)
void SetHits(std::vector< art::Ptr< recob::Hit > > hits)
TVector3 Direction() const
void AddShowerTrack(int track)
void AddBackwardSpacePoint(int spacePoint)
std::vector< int > fCylinderSpacePoints
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:227
Event finding and building.
std::vector< int > fBackwardConeTracks
static TemplateFilterFactory::AutoRegister< FilterLength > fLength("length")
vertex reconstruction