LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
PmaTrack3D.h
Go to the documentation of this file.
1 
17 #ifndef PmaTrack3D_h
18 #define PmaTrack3D_h
19 
20 #include "TVector2.h"
21 #include "TVector3.h"
22 
27 namespace detinfo {
28  class DetectorClocksData;
29  class DetectorPropertiesData;
30 }
31 
32 namespace pma {
33  class Segment3D;
34  class Track3D;
35 }
36 
37 #include <utility>
38 #include <vector>
39 
40 class pma::Track3D {
41 public:
42  enum ETrackEnd { kBegin = -1, kEnd = 1 };
43  enum EDirection { kForward = -1, kBackward = 1 };
44  enum ETag {
46  kTrackLike = 0,
47  kEmLike = 1,
48  kStopping = 2,
49  kCosmic = 4,
50 
51  kGeometry_YY = 0x000100,
52  kGeometry_YZ = 0x000200,
53  kGeometry_ZZ = 0x000300,
54  kGeometry_XX = 0x000400,
55  kGeometry_XY = 0x000500,
56  kGeometry_XZ = 0x000600,
57 
58  kGeometry_Y = 0x001000,
59  kGeometry_Z = 0x002000,
60  kGeometry_X = 0x003000,
61 
64  kBeamIncompatible = 0x030000
65  };
66  ETag GetTag() const noexcept { return fTag; }
67  bool HasTagFlag(ETag value) const noexcept { return (fTag & value); }
68  void SetTagFlag(ETag value) { fTag = (ETag)(fTag | value); }
69 
70  Track3D();
71  Track3D(const Track3D& src);
72  ~Track3D();
73 
74  bool Initialize(detinfo::DetectorPropertiesData const& detProp, float initEndSegW = 0.05F);
75 
76  pma::Hit3D* release_at(size_t index);
78  {
79  hit->fParent = this;
80  fHits.push_back(hit);
81  }
82  bool push_back(const detinfo::DetectorPropertiesData& detProp, const art::Ptr<recob::Hit>& hit);
83  bool erase(const art::Ptr<recob::Hit>& hit);
84 
85  pma::Hit3D* operator[](size_t index) { return fHits[index]; }
86  pma::Hit3D const* operator[](size_t index) const { return fHits[index]; }
87  pma::Hit3D const* front() const { return fHits.front(); }
88  pma::Hit3D const* back() const { return fHits.back(); }
89  size_t size() const { return fHits.size(); }
90 
91  int index_of(const pma::Hit3D* hit) const;
92  int index_of(const pma::Node3D* n) const;
93 
94  double Length(size_t step = 1) const { return Length(0, size() - 1, step); }
95  double Length(size_t start, size_t stop, size_t step = 1) const;
96 
97  double Dist2(const TVector2& p2d, unsigned int view, unsigned int tpc, unsigned int cryo) const;
98  double Dist2(const TVector3& p3d) const;
99 
101  pma::Vector3D GetDirection3D(size_t index) const;
102 
105  void AddHits(detinfo::DetectorPropertiesData const& detProp,
107 
109  void RemoveHits(const std::vector<art::Ptr<recob::Hit>>& hits);
110 
111  unsigned int NHits(unsigned int view) const;
112  unsigned int NEnabledHits(unsigned int view = geo::kUnknown) const;
113  bool HasTwoViews(size_t nmin = 1) const;
114 
115  std::vector<unsigned int> TPCs() const;
116  std::vector<unsigned int> Cryos() const;
117 
118  unsigned int FrontTPC() const { return fNodes.front()->TPC(); }
119  unsigned int FrontCryo() const { return fNodes.front()->Cryo(); }
120 
121  unsigned int BackTPC() const { return fNodes.back()->TPC(); }
122  unsigned int BackCryo() const { return fNodes.back()->Cryo(); }
123 
124  bool HasTPC(int tpc) const
125  {
126  for (auto n : fNodes)
127  if (n->TPC() == tpc) return true;
128  return false;
129  }
130 
135  std::pair<TVector2, TVector2> WireDriftRange(detinfo::DetectorPropertiesData const& detProp,
136  unsigned int view,
137  unsigned int tpc,
138  unsigned int cryo) const;
139 
144  bool Flip(const detinfo::DetectorPropertiesData& detProp, std::vector<pma::Track3D*>& allTracks);
145 
148  void Flip();
149 
151  bool CanFlip() const;
152 
153  void AutoFlip(pma::Track3D::EDirection dir, double thr = 0.0, unsigned int n = 0);
154  bool AutoFlip(detinfo::DetectorPropertiesData const& detProp,
155  std::vector<pma::Track3D*>& allTracks,
157  double thr = 0.0,
158  unsigned int n = 0);
159 
161  double TestHitsMse(detinfo::DetectorPropertiesData const& detProp,
163  bool normalized = true) const; // normalize to the number of hits
164 
166  unsigned int TestHits(detinfo::DetectorPropertiesData const& detProp,
168  double dist = 0.4) const; // max acceptable distance [cm]
169 
170  int NextHit(int index, unsigned int view = geo::kZ, bool inclDisabled = false) const;
171  int PrevHit(int index, unsigned int view = geo::kZ, bool inclDisabled = false) const;
172 
178  double HitDxByView(size_t index, unsigned int view) const;
179 
182 
208  double GetRawdEdxSequence(std::map<size_t, std::vector<double>>& dedx,
209  unsigned int view = geo::kZ,
210  unsigned int skip = 0,
211  bool inclDisabled = false) const;
212 
213  std::vector<float> DriftsOfWireIntersection(detinfo::DetectorPropertiesData const& detProp,
214  unsigned int wire,
215  unsigned int view) const;
216  size_t CompleteMissingWires(detinfo::DetectorPropertiesData const& detProp, unsigned int view);
217 
218  void AddRefPoint(const TVector3& p) { fAssignedPoints.push_back(new TVector3(p)); }
219  void AddRefPoint(double x, double y, double z)
220  {
221  fAssignedPoints.push_back(new TVector3(x, y, z));
222  }
223  bool HasRefPoint(TVector3* p) const;
224 
226  double GetMse(unsigned int view = geo::kUnknown) const;
227 
229  double GetObjFunction(float penaltyFactor = 1.0F) const;
230 
232  double Optimize(const detinfo::DetectorPropertiesData& detProp,
233  int nNodes = -1,
234  double eps = 0.01,
235  bool selAllHits = true,
236  bool setAllNodes = true,
237  size_t selSegHits = 0,
238  size_t selVtxHits = 0);
239 
240  void SortHitsInTree(bool skipFirst = false);
241  void MakeProjectionInTree(bool skipFirst = false);
242  bool UpdateParamsInTree(bool skipFirst, size_t& depth);
243  double GetObjFnInTree(bool skipFirst = false);
244  double TuneSinglePass(bool skipFirst = false);
245  double TuneFullTree(double eps = 0.001, double gmax = 50.0);
246 
249  void ApplyDriftShiftInTree(const detinfo::DetectorClocksData& clockData,
250  detinfo::DetectorPropertiesData const& detProp,
251  double dx,
252  bool skipFirst = false);
254  void SetT0FromDx(const detinfo::DetectorClocksData& clockData,
255  detinfo::DetectorPropertiesData const& detProp,
256  double dx);
257  double GetT0() const { return fT0; }
260  bool HasT0() const noexcept { return fT0Flag; }
261 
263  void CleanupTails();
264 
267  bool ShiftEndsToHits();
268 
269  std::vector<pma::Segment3D*> const& Segments() const noexcept { return fSegments; }
270 
271  pma::Segment3D* NextSegment(pma::Node3D* vtx) const;
272  pma::Segment3D* PrevSegment(pma::Node3D* vtx) const;
273 
274  std::vector<pma::Node3D*> const& Nodes() const noexcept { return fNodes; }
275  pma::Node3D* FirstElement() const { return fNodes.front(); }
276  pma::Node3D* LastElement() const { return fNodes.back(); }
277 
278  void AddNode(pma::Node3D* node);
280  TVector3 const& p3d,
281  unsigned int tpc,
282  unsigned int cryo)
283  {
284  double ds = fNodes.empty() ? 0 : fNodes.back()->GetDriftShift();
285  AddNode(new pma::Node3D(detProp, p3d, tpc, cryo, false, ds));
286  }
287  bool AddNode(detinfo::DetectorPropertiesData const& detProp);
288 
289  void InsertNode(detinfo::DetectorPropertiesData const& detProp,
290  TVector3 const& p3d,
291  size_t at_idx,
292  unsigned int tpc,
293  unsigned int cryo);
294  bool RemoveNode(size_t idx);
295 
296  pma::Track3D* Split(detinfo::DetectorPropertiesData const& detProp,
297  size_t idx,
298  bool try_start_at_idx = true);
299 
300  bool AttachTo(pma::Node3D* vStart, bool noFlip = false);
301  bool AttachBackTo(pma::Node3D* vStart);
302  bool IsAttachedTo(pma::Track3D const* trk) const;
303 
305  void ExtendWith(pma::Track3D* src);
306 
307  pma::Track3D* GetRoot();
308  bool GetBranches(std::vector<pma::Track3D const*>& branches, bool skipFirst = false) const;
309 
310  void MakeProjection();
311  void UpdateProjection();
312  void SortHits();
313 
314  unsigned int DisableSingleViewEnds();
315  bool SelectHits(float fraction = 1.0F);
316  bool SelectRndHits(size_t segmax, size_t vtxmax);
317  bool SelectAllHits();
318 
319  float GetEndSegWeight() const noexcept { return fEndSegWeight; }
320  void SetEndSegWeight(float value) noexcept { fEndSegWeight = value; }
321 
322  float GetPenalty() const noexcept { return fPenaltyFactor; }
323  void SetPenalty(float value) noexcept { fPenaltyFactor = value; }
324 
325  unsigned int GetMaxHitsPerSeg() const noexcept { return fMaxHitsPerSeg; }
326  void SetMaxHitsPerSeg(unsigned int value) noexcept { fMaxHitsPerSeg = value; }
327 
328 private:
329  void ClearNodes();
330  void MakeFastProjection();
331 
332  bool AttachToSameTPC(pma::Node3D* vStart);
333  bool AttachToOtherTPC(pma::Node3D* vStart);
334 
335  bool AttachBackToSameTPC(pma::Node3D* vStart);
336  bool AttachBackToOtherTPC(pma::Node3D* vStart);
337 
338  void InternalFlip(std::vector<pma::Track3D*>& toSort);
339 
340  void UpdateHitsRadius();
341  double AverageDist2() const;
342 
343  bool InitFromHits(detinfo::DetectorPropertiesData const& detProp,
344  int tpc,
345  int cryo,
346  float initEndSegW = 0.05F);
347  bool InitFromRefPoints(detinfo::DetectorPropertiesData const& detProp, int tpc, int cryo);
348  void InitFromMiddle(detinfo::DetectorPropertiesData const& detProp, int tpc, int cryo);
349 
350  pma::Track3D* GetNearestTrkInTree(const TVector3& p3d_cm, double& dist, bool skipFirst = false);
351  pma::Track3D* GetNearestTrkInTree(const TVector2& p2d_cm,
352  unsigned int view,
353  unsigned int tpc,
354  unsigned int cryo,
355  double& dist,
356  bool skipFirst = false);
357  void ReassignHitsInTree(pma::Track3D* plRoot = nullptr);
358 
364  double HitDxByView(size_t index,
365  unsigned int view,
367  bool secondDir = false) const;
368 
373  bool GetUnconstrainedProj3D(detinfo::DetectorPropertiesData const& detProp,
375  TVector3& p3d,
376  double& dist2) const;
377 
378  void DeleteSegments();
379  void RebuildSegments();
380  bool SwapVertices(size_t v0, size_t v1);
381  bool UpdateParams();
382 
383  bool CheckEndSegment(pma::Track3D::ETrackEnd endCode);
384 
385  std::vector<pma::Hit3D*> fHits;
386 
387  std::vector<TVector3*> fAssignedPoints;
388 
389  pma::Element3D* GetNearestElement(const TVector2& p2d,
390  unsigned int view,
391  int tpc = -1,
392  bool skipFrontVtx = false,
393  bool skipBackVtx = false) const;
394  pma::Element3D* GetNearestElement(const TVector3& p3d) const;
395 
396  std::vector<pma::Node3D*> fNodes;
397  std::vector<pma::Segment3D*> fSegments;
398 
399  unsigned int fMaxHitsPerSeg{70};
400  float fPenaltyFactor{1.0F};
401  float fMaxSegStopFactor{8.0F};
402 
403  unsigned int fSegStopValue{2};
404  unsigned int fMinSegStop{2};
405  unsigned int fMaxSegStop{2};
406 
407  float fSegStopFactor{0.2F};
408  float fPenaltyValue{0.1F};
409  float fEndSegWeight{0.05F};
410  float fHitsRadius{1.0F};
411 
412  double fT0{};
413  bool fT0Flag{false};
414 
416 };
417 
418 #endif
Float_t x
Definition: compare.C:6
float Length(const PFPStruct &pfp)
Definition: PFPUtils.cxx:3269
bool HasTPC(int tpc) const
Definition: PmaTrack3D.h:124
void SetTagFlag(ETag value)
Definition: PmaTrack3D.h:68
void AddNode(detinfo::DetectorPropertiesData const &detProp, TVector3 const &p3d, unsigned int tpc, unsigned int cryo)
Definition: PmaTrack3D.h:279
pma::Track3D * fParent
Definition: PmaHit3D.h:109
double Dist2(const TVector2 &v1, const TVector2 &v2)
Definition: Utilities.cxx:39
void AddHits(TCSlice &slc, Trajectory &tj, unsigned short ipt, bool &sigOK)
Definition: StepUtils.cxx:1113
pma::Hit3D * operator[](size_t index)
Definition: PmaTrack3D.h:85
Unknown view.
Definition: geo_types.h:142
Float_t y
Definition: compare.C:6
pma::Hit3D const * front() const
Definition: PmaTrack3D.h:87
void Initialize()
Definition: errprop.cc:100
Double_t z
Definition: plot.C:276
Planes which measure Z direction.
Definition: geo_types.h:138
Implementation of the Projection Matching Algorithm.
void AddRefPoint(double x, double y, double z)
Definition: PmaTrack3D.h:219
std::vector< pma::Segment3D * > fSegments
Definition: PmaTrack3D.h:397
unsigned int BackTPC() const
Definition: PmaTrack3D.h:121
float GetPenalty() const noexcept
Definition: PmaTrack3D.h:322
bool SortHits(HitLoc const &h1, HitLoc const &h2)
recob::tracking::Vector_t Vector3D
Definition: Utilities.h:34
void AddRefPoint(const TVector3 &p)
Definition: PmaTrack3D.h:218
int TPC(void) const
TPC index or -1 if out of any TPC.
Definition: PmaElement3D.h:35
unsigned int BackCryo() const
Definition: PmaTrack3D.h:122
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
Cosmic ray background.
unsigned int GetMaxHitsPerSeg() const noexcept
Definition: PmaTrack3D.h:325
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
void SetMaxHitsPerSeg(unsigned int value) noexcept
Definition: PmaTrack3D.h:326
double GetT0() const
Definition: PmaTrack3D.h:257
float GetEndSegWeight() const noexcept
Definition: PmaTrack3D.h:319
void hits()
Definition: readHits.C:15
pma::Node3D * FirstElement() const
Definition: PmaTrack3D.h:275
pma::Node3D * LastElement() const
Definition: PmaTrack3D.h:276
bool HasTagFlag(ETag value) const noexcept
Definition: PmaTrack3D.h:67
void SetEndSegWeight(float value) noexcept
Definition: PmaTrack3D.h:320
std::vector< pma::Segment3D * > const & Segments() const noexcept
Definition: PmaTrack3D.h:269
Implementation of the Projection Matching Algorithm.
unsigned int FrontTPC() const
Definition: PmaTrack3D.h:118
unsigned int FrontCryo() const
Definition: PmaTrack3D.h:119
General LArSoft Utilities.
ETag GetTag() const noexcept
Definition: PmaTrack3D.h:66
Definition of data types for geometry description.
double value
Definition: spectrum.C:18
std::vector< pma::Node3D * > fNodes
Definition: PmaTrack3D.h:396
Detector simulation of raw signals on wires.
void push_back(pma::Hit3D *hit)
Definition: PmaTrack3D.h:77
Implementation of the Projection Matching Algorithm.
double Length(size_t step=1) const
Definition: PmaTrack3D.h:94
Contains all timing reference information for the detector.
TDirectory * dir
Definition: macro.C:5
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
std::vector< TVector3 * > fAssignedPoints
Definition: PmaTrack3D.h:387
bool HasT0() const noexcept
Definition: PmaTrack3D.h:260
pma::Hit3D const * back() const
Definition: PmaTrack3D.h:88
void SetPenalty(float value) noexcept
Definition: PmaTrack3D.h:323
Char_t n[5]
pma::Hit3D const * operator[](size_t index) const
Definition: PmaTrack3D.h:86
std::vector< pma::Node3D * > const & Nodes() const noexcept
Definition: PmaTrack3D.h:274
size_t size() const
Definition: PmaTrack3D.h:89
std::vector< pma::Hit3D * > fHits
Definition: PmaTrack3D.h:385