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