All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EMShowerAlg.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////
2 // Implementation of the EMShower algorithm
3 //
4 // Forms EM showers from clusters and associated tracks.
5 // Also provides methods for finding the vertex and further
6 // properties of the shower.
7 //
8 // Mike Wallbank (m.wallbank@sheffield.ac.uk), September 2015
9 ////////////////////////////////////////////////////////////////////
10 
11 #ifndef EMShowerAlg_hxx
12 #define EMShowerAlg_hxx
13 
14 // framework
15 #include "art/Framework/Services/Registry/ServiceHandle.h"
16 #include "canvas/Persistency/Common/FindManyP.h"
17 #include "canvas/Persistency/Common/Ptr.h"
18 #include "canvas/Persistency/Common/PtrVector.h"
19 namespace fhicl {
20  class ParameterSet;
21 }
22 
23 // larsoft
38 
39 // C++
40 #include <map>
41 #include <memory>
42 #include <string>
43 #include <vector>
44 
45 // ROOT
46 #include "RtypesCore.h"
47 #include "TVector2.h"
48 #include "TVector3.h"
49 
50 namespace detinfo {
51  class DetectorClocksData;
52  class DetectorPropertiesData;
53 }
54 
55 namespace shower {
56  class EMShowerAlg;
57  struct HitPosition;
58 }
59 
61 public:
62  EMShowerAlg(fhicl::ParameterSet const& pset, int debug = 0);
63 
64  /// Map associated tracks and clusters together given their associated hits
65  void AssociateClustersAndTracks(std::vector<art::Ptr<recob::Cluster>> const& clusters,
66  art::FindManyP<recob::Hit> const& fmh,
67  art::FindManyP<recob::Track> const& fmt,
68  std::map<int, std::vector<int>>& clusterToTracks,
69  std::map<int, std::vector<int>>& trackToClusters) const;
70 
71  /// Map associated tracks and clusters together given their associated hits, whilst ignoring certain clusters
72  void AssociateClustersAndTracks(std::vector<art::Ptr<recob::Cluster>> const& clusters,
73  art::FindManyP<recob::Hit> const& fmh,
74  art::FindManyP<recob::Track> const& fmt,
75  std::vector<int> const& clustersToIgnore,
76  std::map<int, std::vector<int>>& clusterToTracks,
77  std::map<int, std::vector<int>>& trackToClusters) const;
78 
79  /// Takes the initial showers found and tries to resolve issues where one bad view ruins the event
80  std::vector<int> CheckShowerPlanes(std::vector<std::vector<int>> const& initialShowers,
81  std::vector<art::Ptr<recob::Cluster>> const& clusters,
82  art::FindManyP<recob::Hit> const& fmh) const;
83 
84  /// Constructs a recob::Track from sets of hits in two views. Intended to be used to construct the initial first part of a shower.
85  /// All PMA methods taken from the pma tracking algorithm (R. Sulej and D. Stefan).
86  /// This implementation also orients the track in the correct direction if a map of shower centres (units [cm]) in each view is provided.
87  std::unique_ptr<recob::Track> ConstructTrack(
89  std::vector<art::Ptr<recob::Hit>> const& track1,
90  std::vector<art::Ptr<recob::Hit>> const& track2,
91  std::map<int, TVector2> const& showerCentreMap) const;
92 
93  /// Constructs a recob::Track from sets of hits in two views. Intended to be used to construct the initial first part of a shower.
94  /// All methods taken from the pma tracking algorithm (R. Sulej and D. Stefan).
95  std::unique_ptr<recob::Track> ConstructTrack(
96  detinfo::DetectorPropertiesData const& detProp,
97  std::vector<art::Ptr<recob::Hit>> const& track1,
98  std::vector<art::Ptr<recob::Hit>> const& track2) const;
99 
100  /// Finds the initial track-like part of the shower and the hits in all views
101  /// associated with it
103  std::map<int, std::vector<art::Ptr<recob::Hit>>> const& hits,
104  std::unique_ptr<recob::Track>& initialTrack,
105  std::map<int, std::vector<art::Ptr<recob::Hit>>>& initialTrackHits,
106  int plane) const;
107 
108  /// Makes showers given a map between tracks and all clusters associated with them
109  std::vector<std::vector<int>> FindShowers(
110  std::map<int, std::vector<int>> const& trackToClusters) const;
111 
112  /// Makes a recob::Shower object given the hits in the shower and the initial track-like part
114  detinfo::DetectorClocksData const& clockData,
115  detinfo::DetectorPropertiesData const& detProp,
116  art::PtrVector<recob::Hit> const& hits,
117  std::unique_ptr<recob::Track> const& initialTrack,
118  std::map<int, std::vector<art::Ptr<recob::Hit>>> const& initialTrackHits) const;
119 
120  /// <Tingjun to document>
122  detinfo::DetectorPropertiesData const& detProp,
123  art::PtrVector<recob::Hit> const& hits,
124  art::Ptr<recob::Vertex> const& vertex,
125  int& iok) const;
126 
127  /// Makes space points from the shower hits in each plane
128  std::vector<recob::SpacePoint> MakeSpacePoints(
129  detinfo::DetectorPropertiesData const& detProp,
130  std::map<int, std::vector<art::Ptr<recob::Hit>>> const& hits,
131  std::vector<std::vector<art::Ptr<recob::Hit>>>& hitAssns) const;
132 
133  /// Takes the hits associated with a shower and orders them so they follow the direction of the shower
134  std::map<int, std::vector<art::Ptr<recob::Hit>>> OrderShowerHits(
135  detinfo::DetectorPropertiesData const& detProp,
136  art::PtrVector<recob::Hit> const& shower,
137  int plane) const;
138 
139  /// <Tingjun to document>
140  void FindInitialTrackHits(std::vector<art::Ptr<recob::Hit>> const& showerHits,
141  art::Ptr<recob::Vertex> const& vertex,
142  std::vector<art::Ptr<recob::Hit>>& trackHits) const;
143 
144  /// <Tingjun to document>
145  Int_t WeightedFit(const Int_t n,
146  const Double_t* x,
147  const Double_t* y,
148  const Double_t* w,
149  Double_t* parm) const;
150 
151  /// <Tingjun to document>
152  bool isCleanShower(std::vector<art::Ptr<recob::Hit>> const& hits) const;
153 
154  int fDebug;
155 
156 private:
157  /// Checks the hits across the views in a given shower to determine if there
158  /// is one in the incorrect TPC
159  void CheckIsolatedHits_(std::map<int, std::vector<art::Ptr<recob::Hit>>>& showerHitsMap) const;
160 
161  /// Takes the shower hits in all views and ensure the ordering is consistent
162  /// Returns bool, indicating whether or not everything makes sense!
163  bool CheckShowerHits_(
164  detinfo::DetectorPropertiesData const& detProp,
165  std::map<int, std::vector<art::Ptr<recob::Hit>>> const& showerHitsMap) const;
166 
167  /// Constructs a 3D point (in [cm]) to represent the hits given in two views
168  TVector3 Construct3DPoint_(detinfo::DetectorPropertiesData const& detProp,
169  art::Ptr<recob::Hit> const& hit1,
170  art::Ptr<recob::Hit> const& hit2) const;
171 
172  /// Finds dE/dx for the track given a set of hits
173  double FinddEdx_(detinfo::DetectorClocksData const& clockData,
174  detinfo::DetectorPropertiesData const& detProp,
175  std::vector<art::Ptr<recob::Hit>> const& trackHits,
176  std::unique_ptr<recob::Track> const& track) const;
177 
178  /// Orders hits along the best fit line through the charge-weighted centre of
179  /// the hits. Orders along the line perpendicular to the least squares line if
180  /// perpendicular is set to true.
181  std::vector<art::Ptr<recob::Hit>> FindOrderOfHits_(detinfo::DetectorPropertiesData const& detProp,
182  std::vector<art::Ptr<recob::Hit>> const& hits,
183  bool perpendicular = false) const;
184 
185  /// Takes a map of the shower hits on each plane (ordered from what has been
186  /// decided to be the start) Returns a map of the initial track-like part of
187  /// the shower on each plane
188  std::map<int, std::vector<art::Ptr<recob::Hit>>> FindShowerStart_(
189  std::map<int, std::vector<art::Ptr<recob::Hit>>> const& orderedShowerMap) const;
190 
191  /// Takes all the shower hits, ready ordered, and returns information to help
192  /// with the orientation of the shower in each view Returns map of most likely
193  /// permutations of reorientation Starts at 0,0,0 (i.e. don't need to reorient
194  /// any plane) and ends with 1,1,1 (i.e. every plane needs reorienting) Every
195  /// permutation inbetween represent increasing less likely changes to satisfy
196  /// the correct orientation criteria
197  std::map<int, std::map<int, bool>> GetPlanePermutations_(
198  const detinfo::DetectorPropertiesData& detProp,
199  const std::map<int, std::vector<art::Ptr<recob::Hit>>>& showerHitsMap) const;
200 
201  /// Find the global wire position
202  double GlobalWire_(const geo::WireID& wireID) const;
203 
204  /// Return the coordinates of this hit in global wire/tick space
205  TVector2 HitCoordinates_(recob::Hit const& hit) const;
206 
207  /// Return the coordinates of this hit in units of cm
208  TVector2 HitPosition_(detinfo::DetectorPropertiesData const& detProp,
209  recob::Hit const& hit) const;
210 
211  /// Return the coordinates of this hit in units of cm
212  TVector2 HitPosition_(detinfo::DetectorPropertiesData const& detProp,
213  TVector2 const& pos,
214  geo::PlaneID planeID) const;
215 
216  /// Takes initial track hits from multiple views and forms a track object
217  /// which best represents the start of the shower
218  std::unique_ptr<recob::Track> MakeInitialTrack_(
219  detinfo::DetectorPropertiesData const& detProp,
220  std::map<int, std::vector<art::Ptr<recob::Hit>>> const& initialHitsMap,
221  std::map<int, std::vector<art::Ptr<recob::Hit>>> const& showerHitsMap) const;
222 
223  /// Takes the hits associated with a shower and orders then so they follow the
224  /// direction of the shower
226  std::vector<art::Ptr<recob::Hit>> const& shower,
227  std::vector<art::Ptr<recob::Hit>>& orderedShower,
228  art::Ptr<recob::Vertex> const& vertex) const;
229 
230  /// Projects a 3D point (units [cm]) onto a 2D plane
231  /// Returns 2D point (units [cm])
233  TVector3 const& point,
234  int plane,
235  int cryostat = 0) const;
236 
237  /// Determines the 'relative wire width', i.e. how spread a shower is across
238  /// wires of each plane relative to the others If a shower travels along the
239  /// wire directions in a particular view, it will have a smaller wire width in
240  /// that view Returns a map relating these widths to each plane
241  std::map<double, int> RelativeWireWidth_(
242  const std::map<int, std::vector<art::Ptr<recob::Hit>>>& showerHitsMap) const;
243 
244  /// Returns the charge-weighted shower center
245  TVector2 ShowerCenter_(detinfo::DetectorPropertiesData const& detProp,
246  std::vector<art::Ptr<recob::Hit>> const& showerHits) const;
247 
248  /// Returns a rough charge-weighted shower 'direction' given the hits in the
249  /// shower
250  TVector2 ShowerDirection_(detinfo::DetectorPropertiesData const& detProp,
251  const std::vector<art::Ptr<recob::Hit>>& showerHits) const;
252 
253  /// Returns the RMS of the hits from the central shower 'axis' along the
254  /// length of the shower
255  double ShowerHitRMS_(detinfo::DetectorPropertiesData const& detProp,
256  std::vector<art::Ptr<recob::Hit>> const& showerHits) const;
257 
258  /// Returns the gradient of the RMS vs shower segment graph
260  const std::vector<art::Ptr<recob::Hit>>& showerHits) const;
261 
262  /// Returns the plane which is determined to be the least likely to be correct
263  int WorstPlane_(const std::map<int, std::vector<art::Ptr<recob::Hit>>>& showerHitsMap) const;
264 
265  // Parameters
266  double const fMinTrackLength;
267  double const fdEdxTrackLength;
268  double const fSpacePointSize;
269 
270  // Parameters to fit wire vs time
271  unsigned int const fNfitpass;
272  std::vector<unsigned int> const fNfithits;
273  std::vector<double> const fToler;
274 
275  // Services used by this class
276  art::ServiceHandle<geo::Geometry const> fGeom;
277 
278  // Algs used by this class
282 
283  std::string const fDetector;
284 
285  // tmp
286  bool const fMakeGradientPlot;
289 };
290 
292  TVector2 WireTick;
293  TVector2 Cm;
294 };
295 
296 #endif
process_name vertex
Definition: cheaterreco.fcl:51
TVector2 HitPosition_(detinfo::DetectorPropertiesData const &detProp, recob::Hit const &hit) const
Return the coordinates of this hit in units of cm.
std::vector< recob::SpacePoint > MakeSpacePoints(detinfo::DetectorPropertiesData const &detProp, std::map< int, std::vector< art::Ptr< recob::Hit >>> const &hits, std::vector< std::vector< art::Ptr< recob::Hit >>> &hitAssns) const
Makes space points from the shower hits in each plane.
void FindInitialTrackHits(std::vector< art::Ptr< recob::Hit >> const &showerHits, art::Ptr< recob::Vertex > const &vertex, std::vector< art::Ptr< recob::Hit >> &trackHits) const
&lt;Tingjun to=&quot;&quot; document&gt;=&quot;&quot;&gt;
int WorstPlane_(const std::map< int, std::vector< art::Ptr< recob::Hit >>> &showerHitsMap) const
Returns the plane which is determined to be the least likely to be correct.
shower::ShowerEnergyAlg const fShowerEnergyAlg
Definition: EMShowerAlg.h:279
pma::ProjectionMatchingAlg const fProjectionMatchingAlg
Definition: EMShowerAlg.h:281
process_name opflash particleana ie x
recob::Shower MakeShower(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, art::PtrVector< recob::Hit > const &hits, std::unique_ptr< recob::Track > const &initialTrack, std::map< int, std::vector< art::Ptr< recob::Hit >>> const &initialTrackHits) const
Makes a recob::Shower object given the hits in the shower and the initial track-like part...
Declaration of signal hit object.
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
void AssociateClustersAndTracks(std::vector< art::Ptr< recob::Cluster >> const &clusters, art::FindManyP< recob::Hit > const &fmh, art::FindManyP< recob::Track > const &fmt, std::map< int, std::vector< int >> &clusterToTracks, std::map< int, std::vector< int >> &trackToClusters) const
Map associated tracks and clusters together given their associated hits.
Definition: EMShowerAlg.cxx:60
std::map< int, std::map< int, bool > > GetPlanePermutations_(const detinfo::DetectorPropertiesData &detProp, const std::map< int, std::vector< art::Ptr< recob::Hit >>> &showerHitsMap) const
double GlobalWire_(const geo::WireID &wireID) const
Find the global wire position.
process_name use argoneut_mc_hitfinder track
process_name hit
Definition: cheaterreco.fcl:51
double const fdEdxTrackLength
Definition: EMShowerAlg.h:267
unsigned int const fNfitpass
Definition: EMShowerAlg.h:271
TVector2 ShowerCenter_(detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit >> const &showerHits) const
Returns the charge-weighted shower center.
process_name shower
Definition: cheaterreco.fcl:51
std::vector< std::vector< int > > FindShowers(std::map< int, std::vector< int >> const &trackToClusters) const
Makes showers given a map between tracks and all clusters associated with them.
std::vector< double > const fToler
Definition: EMShowerAlg.h:273
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
Access the description of detector geometry.
bool const fMakeRMSGradientPlot
Definition: EMShowerAlg.h:287
void CheckIsolatedHits_(std::map< int, std::vector< art::Ptr< recob::Hit >>> &showerHitsMap) const
std::vector< unsigned int > const fNfithits
Definition: EMShowerAlg.h:272
Int_t WeightedFit(const Int_t n, const Double_t *x, const Double_t *y, const Double_t *w, Double_t *parm) const
&lt;Tingjun to=&quot;&quot; document&gt;=&quot;&quot;&gt;
TVector3 Construct3DPoint_(detinfo::DetectorPropertiesData const &detProp, art::Ptr< recob::Hit > const &hit1, art::Ptr< recob::Hit > const &hit2) const
Constructs a 3D point (in [cm]) to represent the hits given in two views.
process_name opflash particleana ie ie y
std::vector< int > CheckShowerPlanes(std::vector< std::vector< int >> const &initialShowers, std::vector< art::Ptr< recob::Cluster >> const &clusters, art::FindManyP< recob::Hit > const &fmh) const
Takes the initial showers found and tries to resolve issues where one bad view ruins the event...
std::unique_ptr< recob::Track > ConstructTrack(detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit >> const &track1, std::vector< art::Ptr< recob::Hit >> const &track2, std::map< int, TVector2 > const &showerCentreMap) const
std::map< int, std::vector< art::Ptr< recob::Hit > > > OrderShowerHits(detinfo::DetectorPropertiesData const &detProp, art::PtrVector< recob::Hit > const &shower, int plane) const
Takes the hits associated with a shower and orders them so they follow the direction of the shower...
double ShowerHitRMS_(detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit >> const &showerHits) const
double const fMinTrackLength
Definition: EMShowerAlg.h:266
Declaration of cluster object.
Definition of data types for geometry description.
bool isCleanShower(std::vector< art::Ptr< recob::Hit >> const &hits) const
&lt;Tingjun to=&quot;&quot; document&gt;=&quot;&quot;&gt;
Provides recob::Track data product.
bool const fMakeGradientPlot
Definition: EMShowerAlg.h:286
TVector2 Project3DPointOntoPlane_(detinfo::DetectorPropertiesData const &detProp, TVector3 const &point, int plane, int cryostat=0) const
EMShowerAlg(fhicl::ParameterSet const &pset, int debug=0)
Definition: EMShowerAlg.cxx:37
TVector2 ShowerDirection_(detinfo::DetectorPropertiesData const &detProp, const std::vector< art::Ptr< recob::Hit >> &showerHits) const
void FindInitialTrack(detinfo::DetectorPropertiesData const &detProp, std::map< int, std::vector< art::Ptr< recob::Hit >>> const &hits, std::unique_ptr< recob::Track > &initialTrack, std::map< int, std::vector< art::Ptr< recob::Hit >>> &initialTrackHits, int plane) const
bool CheckShowerHits_(detinfo::DetectorPropertiesData const &detProp, std::map< int, std::vector< art::Ptr< recob::Hit >>> const &showerHitsMap) const
void OrderShowerHits_(detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit >> const &shower, std::vector< art::Ptr< recob::Hit >> &orderedShower, art::Ptr< recob::Vertex > const &vertex) const
std::unique_ptr< recob::Track > MakeInitialTrack_(detinfo::DetectorPropertiesData const &detProp, std::map< int, std::vector< art::Ptr< recob::Hit >>> const &initialHitsMap, std::map< int, std::vector< art::Ptr< recob::Hit >>> const &showerHitsMap) const
double FinddEdx_(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit >> const &trackHits, std::unique_ptr< recob::Track > const &track) const
Finds dE/dx for the track given a set of hits.
Contains all timing reference information for the detector.
TVector2 HitCoordinates_(recob::Hit const &hit) const
Return the coordinates of this hit in global wire/tick space.
int const fNumShowerSegments
Definition: EMShowerAlg.h:288
calo::CalorimetryAlg const fCalorimetryAlg
Definition: EMShowerAlg.h:280
std::vector< art::Ptr< recob::Hit > > FindOrderOfHits_(detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit >> const &hits, bool perpendicular=false) const
double const fSpacePointSize
Definition: EMShowerAlg.h:268
std::map< double, int > RelativeWireWidth_(const std::map< int, std::vector< art::Ptr< recob::Hit >>> &showerHitsMap) const
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
art::ServiceHandle< geo::Geometry const > fGeom
Definition: EMShowerAlg.h:276
std::string const fDetector
Definition: EMShowerAlg.h:283
art framework interface to geometry description
auto const detProp
std::map< int, std::vector< art::Ptr< recob::Hit > > > FindShowerStart_(std::map< int, std::vector< art::Ptr< recob::Hit >>> const &orderedShowerMap) const
double ShowerHitRMSGradient_(detinfo::DetectorPropertiesData const &detProp, const std::vector< art::Ptr< recob::Hit >> &showerHits) const
Returns the gradient of the RMS vs shower segment graph.