LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
PmaTrack3D.h
Go to the documentation of this file.
1 
17 #ifndef PmaTrack3D_h
18 #define PmaTrack3D_h
19 
23 
24 namespace pma
25 {
26  class Track3D;
27 }
28 
30 {
31 public:
32  enum ETrackEnd { kBegin = -1, kEnd = 1 };
33  enum EDirection { kForward = -1, kBackward = 1 };
34  enum ETag
35  {
36  kNotTagged = 0, kTrackLike = 0, kEmLike = 1, kStopping = 2, kCosmic = 4,
37 
38  kGeometry_YY = 0x000100,
39  kGeometry_YZ = 0x000200,
40  kGeometry_ZZ = 0x000300,
41  kGeometry_XX = 0x000400,
42  kGeometry_XY = 0x000500,
43  kGeometry_XZ = 0x000600,
44 
45  kGeometry_Y = 0x001000,
46  kGeometry_Z = 0x002000,
47  kGeometry_X = 0x003000,
48 
51  kBeamIncompatible = 0x030000
52  };
53  ETag GetTag(void) const { return fTag; }
54  bool HasTagFlag(ETag value) const { return (fTag & value); }
55  void SetTagFlag(ETag value) { fTag = (ETag)(fTag | value); }
56  void SetTag(ETag value) { fTag = value; }
57 
58 
59  Track3D(void);
60  Track3D(const Track3D& src);
61  ~Track3D(void);
62 
63  bool Initialize(float initEndSegW = 0.05F);
64 
65  pma::Hit3D* release_at(size_t index);
66  void push_back(pma::Hit3D* hit) { hit->fParent = this; fHits.push_back(hit); }
67  bool push_back(const art::Ptr< recob::Hit > & hit);
68  bool erase(const art::Ptr< recob::Hit > & hit);
69 
70  pma::Hit3D* & operator [] (size_t index) { return fHits[index]; }
71  pma::Hit3D* const & operator [] (size_t index) const { return fHits[index]; }
72  pma::Hit3D* & front() { return fHits.front(); }
73  pma::Hit3D* const & front() const { return fHits.front(); }
74  pma::Hit3D* & back() { return fHits.back(); }
75  pma::Hit3D* const & back() const { return fHits.back(); }
76  size_t size() const { return fHits.size(); }
77 
78  int index_of(const pma::Hit3D* hit) const;
79  int index_of(const pma::Node3D* n) const;
80 
81  double Length(size_t step = 1) const { return Length(0, size() - 1, step); }
82  double Length(size_t start, size_t stop, size_t step = 1) const;
83 
84  double Dist2(const TVector2& p2d, unsigned int view, unsigned int tpc, unsigned int cryo) const;
85  double Dist2(const TVector3& p3d) const;
86 
88  pma::Vector3D GetDirection3D(size_t index) const;
89 
93 
96 
97  unsigned int NHits(unsigned int view) const;
98  unsigned int NEnabledHits(unsigned int view = geo::kUnknown) const;
99  bool HasTwoViews(size_t nmin = 1) const;
100 
101  std::vector< unsigned int > TPCs(void) const;
102  std::vector< unsigned int > Cryos(void) const;
103 
104  unsigned int FrontTPC(void) const { return fNodes.front()->TPC(); }
105  unsigned int FrontCryo(void) const { return fNodes.front()->Cryo(); }
106 
107  unsigned int BackTPC(void) const { return fNodes.back()->TPC(); }
108  unsigned int BackCryo(void) const { return fNodes.back()->Cryo(); }
109 
110  bool HasTPC(int tpc) const
111  {
112  for (auto n : fNodes) if (n->TPC() == tpc) return true;
113  return false;
114  }
115 
119  std::pair< TVector2, TVector2 > WireDriftRange(unsigned int view, unsigned int tpc, unsigned int cryo) const;
120 
125  bool Flip(std::vector< pma::Track3D* >& allTracks);
126 
129  void Flip(void);
130 
132  bool CanFlip(void) const;
133 
134  void AutoFlip(pma::Track3D::EDirection dir, double thr = 0.0, unsigned int n = 0);
135  bool AutoFlip(std::vector< pma::Track3D* >& allTracks, pma::Track3D::EDirection dir, double thr = 0.0, unsigned int n = 0);
136 
139  bool normalized = true) const; // normalize to the number of hits
140 
142  unsigned int TestHits(const std::vector< art::Ptr<recob::Hit> >& hits,
143  double dist = 0.4) const; // max acceptable distance [cm]
144 
145  int NextHit(int index, unsigned int view = geo::kZ, bool inclDisabled = false) const;
146  int PrevHit(int index, unsigned int view = geo::kZ, bool inclDisabled = false) const;
147 
153  double HitDxByView(size_t index, unsigned int view) const;
154 
157 
183  double GetRawdEdxSequence(std::map< size_t, std::vector<double> >& dedx, unsigned int view = geo::kZ,
184  unsigned int skip = 0, bool inclDisabled = false) const;
185 
186  std::vector<float> DriftsOfWireIntersection(unsigned int wire, unsigned int view) const;
187  size_t CompleteMissingWires(unsigned int view);
188 
189  void AddRefPoint(const TVector3& p) { fAssignedPoints.push_back(new TVector3(p)); }
190  void AddRefPoint(double x, double y, double z) { fAssignedPoints.push_back(new TVector3(x, y, z)); }
191  bool HasRefPoint(TVector3* p) const;
192 
194  double GetMse(unsigned int view = geo::kUnknown) const;
195 
197  double GetObjFunction(float penaltyFactor = 1.0F) const;
198 
200  double Optimize(int nNodes = -1, double eps = 0.01,
201  bool selAllHits = true, bool setAllNodes = true,
202  size_t selSegHits = 0, size_t selVtxHits = 0);
203 
204  void SortHitsInTree(bool skipFirst = false);
205  void MakeProjectionInTree(bool skipFirst = false);
206  bool UpdateParamsInTree(bool skipFirst = false);
207  double GetObjFnInTree(bool skipFirst = false);
208  double TuneSinglePass(bool skipFirst = false);
209  double TuneFullTree(double eps = 0.001, double gmax = 50.0);
210 
212  void ApplyDriftShiftInTree(double dx, bool skipFirst = false);
214  void SetT0FromDx(double dx);
215  double GetT0(void) const { return fT0; }
218  bool HasT0(void) const {return fT0Flag; }
219 
221  void CleanupTails(void);
222 
225  bool ShiftEndsToHits(void);
226 
227  std::vector< pma::Segment3D* > const & Segments(void) const { return fSegments; }
228 
231 
232  std::vector< pma::Node3D* > const & Nodes(void) const { return fNodes; }
233  pma::Node3D* FirstElement(void) const { return fNodes.front(); }
234  pma::Node3D* LastElement(void) const { return fNodes.back(); }
235 
236  void AddNode(pma::Node3D* node);
237  void AddNode(TVector3 const & p3d, unsigned int tpc, unsigned int cryo)
238  {
239  double ds = fNodes.empty() ? 0 : fNodes.back()->GetDriftShift();
240  AddNode(new pma::Node3D(p3d, tpc, cryo, false, ds));
241  }
242  bool AddNode(void);
243 
244  void InsertNode(
245  TVector3 const & p3d, size_t at_idx,
246  unsigned int tpc, unsigned int cryo);
247  bool RemoveNode(size_t idx);
248 
249  pma::Track3D* Split(size_t idx, bool try_start_at_idx = true);
250 
251  bool AttachTo(pma::Node3D* vStart, bool noFlip = false);
252  bool AttachBackTo(pma::Node3D* vStart);
253  bool IsAttachedTo(pma::Track3D const * trk) const;
254 
256  void ExtendWith(pma::Track3D* src);
257 
258  pma::Track3D* GetRoot(void);
259  bool GetBranches(std::vector< pma::Track3D const * >& branches, bool skipFirst = false) const;
260 
261  void MakeProjection(void);
262  void UpdateProjection(void);
263  void SortHits(void);
264 
265  unsigned int DisableSingleViewEnds(void);
266  bool SelectHits(float fraction = 1.0F);
267  bool SelectRndHits(size_t segmax, size_t vtxmax);
268  bool SelectAllHits(void);
269 
270  float GetEndSegWeight(void) const { return fEndSegWeight; }
272 
273  float GetPenalty(void) const { return fPenaltyFactor; }
275 
276  unsigned int GetMaxHitsPerSeg(void) const { return fMaxHitsPerSeg; }
277  void SetMaxHitsPerSeg(unsigned int value) { fMaxHitsPerSeg = value; }
278 
279 private:
280  void ClearNodes(void);
281  void MakeFastProjection(void);
282 
283  bool AttachToSameTPC(pma::Node3D* vStart);
284  bool AttachToOtherTPC(pma::Node3D* vStart);
285 
286  bool AttachBackToSameTPC(pma::Node3D* vStart);
287  bool AttachBackToOtherTPC(pma::Node3D* vStart);
288 
289  void InternalFlip(std::vector< pma::Track3D* >& toSort);
290 
291  void UpdateHitsRadius(void);
292  double AverageDist2(void) const;
293 
294  bool InitFromHits(int tpc, int cryo, float initEndSegW = 0.05F);
295  bool InitFromRefPoints(int tpc, int cryo);
296  void InitFromMiddle(int tpc, int cryo);
297 
298  pma::Track3D* GetNearestTrkInTree(const TVector3& p3d_cm, double& dist, bool skipFirst = false);
299  pma::Track3D* GetNearestTrkInTree(const TVector2& p2d_cm,
300  unsigned int view, unsigned int tpc, unsigned int cryo,
301  double& dist, bool skipFirst = false);
302  void ReassignHitsInTree(pma::Track3D* plRoot = 0);
303 
307  double HitDxByView(size_t index, unsigned int view, Track3D::EDirection dir, bool secondDir = false) const;
308 
313  bool GetUnconstrainedProj3D(art::Ptr<recob::Hit> hit, TVector3& p3d, double& dist2) const;
314 
315  void DeleteSegments(void);
316  void RebuildSegments(void);
317  bool SwapVertices(size_t v0, size_t v1);
318  bool UpdateParams(void);
319 
321 
322  std::vector< pma::Hit3D* > fHits;
323 
324  std::vector< TVector3* > fAssignedPoints;
325 
326  pma::Element3D* GetNearestElement(const TVector2& p2d, unsigned int view, int tpc = -1,
327  bool skipFrontVtx = false, bool skipBackVtx = false) const;
328  pma::Element3D* GetNearestElement(const TVector3& p3d) const;
329 
330  std::vector< pma::Node3D* > fNodes;
331  std::vector< pma::Segment3D* > fSegments;
332 
333  unsigned int fMaxHitsPerSeg;
336 
337  unsigned int fSegStopValue;
338  unsigned int fMinSegStop;
339  unsigned int fMaxSegStop;
340 
344  float fHitsRadius;
345 
346  double fT0;
347  bool fT0Flag;
348 
350 };
351 
352 #endif
353 
Float_t x
Definition: compare.C:6
unsigned int TestHits(const std::vector< art::Ptr< recob::Hit > > &hits, double dist=0.4) const
Count close 2D hits.
Definition: PmaTrack3D.cxx:811
bool SelectHits(float fraction=1.0F)
std::vector< pma::Segment3D * > fSegments
Definition: PmaTrack3D.h:331
bool HasTagFlag(ETag value) const
Definition: PmaTrack3D.h:54
pma::Node3D * LastElement(void) const
Definition: PmaTrack3D.h:234
std::vector< unsigned int > TPCs(void) const
Definition: PmaTrack3D.cxx:437
void AutoFlip(pma::Track3D::EDirection dir, double thr=0.0, unsigned int n=0)
Definition: PmaTrack3D.cxx:630
void CleanupTails(void)
Cut out tails with no hits assigned.
bool InitFromHits(int tpc, int cryo, float initEndSegW=0.05F)
Definition: PmaTrack3D.cxx:126
bool HasTPC(int tpc) const
Definition: PmaTrack3D.h:110
std::vector< float > DriftsOfWireIntersection(unsigned int wire, unsigned int view) const
double GetMse(unsigned int view=geo::kUnknown) const
MSE of hits weighted with hit amplidudes and wire plane coefficients.
bool HasT0(void) const
Definition: PmaTrack3D.h:218
void SortHitsInTree(bool skipFirst=false)
bool AttachTo(pma::Node3D *vStart, bool noFlip=false)
void UpdateProjection(void)
void SetTagFlag(ETag value)
Definition: PmaTrack3D.h:55
double Dist2(const TVector2 &p2d, unsigned int view, unsigned int tpc, unsigned int cryo) const
void InsertNode(TVector3 const &p3d, size_t at_idx, unsigned int tpc, unsigned int cryo)
bool IsAttachedTo(pma::Track3D const *trk) const
pma::Track3D * fParent
Definition: PmaHit3D.h:106
unsigned int FrontTPC(void) const
Definition: PmaTrack3D.h:104
unsigned int BackTPC(void) const
Definition: PmaTrack3D.h:107
int PrevHit(int index, unsigned int view=geo::kZ, bool inclDisabled=false) const
Definition: PmaTrack3D.cxx:877
Unknown view.
Definition: geo_types.h:83
float GetPenalty(void) const
Definition: PmaTrack3D.h:273
Float_t y
Definition: compare.C:6
Implementation of the Projection Matching Algorithm.
Double_t z
Definition: plot.C:279
std::vector< pma::Node3D * > const & Nodes(void) const
Definition: PmaTrack3D.h:232
int index_of(const pma::Hit3D *hit) const
Definition: PmaTrack3D.cxx:333
bool AttachBackToSameTPC(pma::Node3D *vStart)
bool AddNode(void)
bool GetBranches(std::vector< pma::Track3D const * > &branches, bool skipFirst=false) const
bool AttachToOtherTPC(pma::Node3D *vStart)
bool CheckEndSegment(pma::Track3D::ETrackEnd endCode)
double GetObjFunction(float penaltyFactor=1.0F) const
Objective function optimized in track reconstruction.
void AddNode(TVector3 const &p3d, unsigned int tpc, unsigned int cryo)
Definition: PmaTrack3D.h:237
bool GetUnconstrainedProj3D(art::Ptr< recob::Hit > hit, TVector3 &p3d, double &dist2) const
Planes which measure Z direction.
Definition: geo_types.h:79
float GetEndSegWeight(void) const
Definition: PmaTrack3D.h:270
Implementation of the Projection Matching Algorithm.
void AddRefPoint(double x, double y, double z)
Definition: PmaTrack3D.h:190
void DeleteSegments(void)
pma::Track3D * Split(size_t idx, bool try_start_at_idx=true)
bool UpdateParams(void)
bool AttachBackToOtherTPC(pma::Node3D *vStart)
float fPenaltyValue
Definition: PmaTrack3D.h:342
std::vector< pma::Segment3D * > const & Segments(void) const
Definition: PmaTrack3D.h:227
void RemoveHits(const std::vector< art::Ptr< recob::Hit > > &hits)
Remove hits; removes also hit->node/seg assignments.
Definition: PmaTrack3D.cxx:399
recob::tracking::Vector_t Vector3D
Definition: Utilities.h:29
double TuneFullTree(double eps=0.001, double gmax=50.0)
pma::Vector3D GetDirection3D(size_t index) const
Get trajectory direction at given hit index.
Definition: PmaTrack3D.cxx:373
double TuneSinglePass(bool skipFirst=false)
float fEndSegWeight
Definition: PmaTrack3D.h:343
pma::Hit3D *& operator[](size_t index)
Definition: PmaTrack3D.h:70
double GetT0(void) const
Definition: PmaTrack3D.h:215
void AddRefPoint(const TVector3 &p)
Definition: PmaTrack3D.h:189
void SetTag(ETag value)
Definition: PmaTrack3D.h:56
double AverageDist2(void) const
unsigned int NEnabledHits(unsigned int view=geo::kUnknown) const
Definition: PmaTrack3D.cxx:416
int TPC(void) const
TPC index or -1 if out of any TPC.
Definition: PmaElement3D.h:31
bool ShiftEndsToHits(void)
~Track3D(void)
Definition: PmaTrack3D.cxx:74
unsigned int fMaxHitsPerSeg
Definition: PmaTrack3D.h:333
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
std::pair< TVector2, TVector2 > WireDriftRange(unsigned int view, unsigned int tpc, unsigned int cryo) const
Definition: PmaTrack3D.cxx:469
unsigned int fSegStopValue
Definition: PmaTrack3D.h:337
void ExtendWith(pma::Track3D *src)
Extend the track with everything from src, delete the src;.
void hits()
Definition: readHits.C:15
pma::Hit3D * release_at(size_t index)
Definition: PmaTrack3D.cxx:340
unsigned int NHits(unsigned int view) const
Definition: PmaTrack3D.cxx:406
pma::Hit3D *const & back() const
Definition: PmaTrack3D.h:75
void SetMaxHitsPerSeg(unsigned int value)
Definition: PmaTrack3D.h:277
void MakeFastProjection(void)
void InitFromMiddle(int tpc, int cryo)
Definition: PmaTrack3D.cxx:299
double fT0
Definition: PmaTrack3D.h:346
void SetPenalty(float value)
Definition: PmaTrack3D.h:274
unsigned int BackCryo(void) const
Definition: PmaTrack3D.h:108
bool HasRefPoint(TVector3 *p) const
void SetEndSegWeight(float value)
Definition: PmaTrack3D.h:271
bool CanFlip(void) const
Check if the track can be flipped without breaking any other track.
Definition: PmaTrack3D.cxx:615
size_t CompleteMissingWires(unsigned int view)
pma::Hit3D *& back()
Definition: PmaTrack3D.h:74
double Optimize(int nNodes=-1, double eps=0.01, bool selAllHits=true, bool setAllNodes=true, size_t selSegHits=0, size_t selVtxHits=0)
Main optimization method.
Implementation of the Projection Matching Algorithm.
unsigned int GetMaxHitsPerSeg(void) const
Definition: PmaTrack3D.h:276
pma::Hit3D *const & front() const
Definition: PmaTrack3D.h:73
void UpdateHitsRadius(void)
float fPenaltyFactor
Definition: PmaTrack3D.h:334
double GetObjFnInTree(bool skipFirst=false)
void InternalFlip(std::vector< pma::Track3D * > &toSort)
Definition: PmaTrack3D.cxx:565
bool erase(const art::Ptr< recob::Hit > &hit)
Definition: PmaTrack3D.cxx:359
bool AttachToSameTPC(pma::Node3D *vStart)
unsigned int FrontCryo(void) const
Definition: PmaTrack3D.h:105
std::vector< unsigned int > Cryos(void) const
Definition: PmaTrack3D.cxx:453
void RebuildSegments(void)
Detector simulation of raw signals on wires.
bool SelectRndHits(size_t segmax, size_t vtxmax)
double TestHitsMse(const std::vector< art::Ptr< recob::Hit > > &hits, bool normalized=true) const
MSE of 2D hits.
Definition: PmaTrack3D.cxx:788
unsigned int DisableSingleViewEnds(void)
void ClearNodes(void)
Definition: PmaTrack3D.cxx:120
void push_back(pma::Hit3D *hit)
Definition: PmaTrack3D.h:66
bool HasTwoViews(size_t nmin=1) const
Definition: PmaTrack3D.cxx:428
void MakeProjectionInTree(bool skipFirst=false)
pma::Track3D * GetRoot(void)
std::string value(boost::any const &)
double Length(size_t step=1) const
Definition: PmaTrack3D.h:81
bool UpdateParamsInTree(bool skipFirst=false)
TDirectory * dir
Definition: macro.C:5
pma::Segment3D * PrevSegment(pma::Node3D *vtx) const
Definition: PmaTrack3D.cxx:980
bool RemoveNode(size_t idx)
void ReassignHitsInTree(pma::Track3D *plRoot=0)
bool Initialize(float initEndSegW=0.05F)
Definition: PmaTrack3D.cxx:84
float fSegStopFactor
Definition: PmaTrack3D.h:341
int NextHit(int index, unsigned int view=geo::kZ, bool inclDisabled=false) const
Definition: PmaTrack3D.cxx:861
void MakeProjection(void)
void SetT0FromDx(double dx)
Function to convert dx into dT0.
double GetRawdEdxSequence(std::map< size_t, std::vector< double > > &dedx, unsigned int view=geo::kZ, unsigned int skip=0, bool inclDisabled=false) const
Definition: PmaTrack3D.cxx:990
std::vector< pma::Node3D * > fNodes
Definition: PmaTrack3D.h:330
double HitDxByView(size_t index, unsigned int view) const
Definition: PmaTrack3D.cxx:952
Char_t n[5]
bool SwapVertices(size_t v0, size_t v1)
ETag GetTag(void) const
Definition: PmaTrack3D.h:53
pma::Track3D * GetNearestTrkInTree(const TVector3 &p3d_cm, double &dist, bool skipFirst=false)
void SortHits(void)
float fMaxSegStopFactor
Definition: PmaTrack3D.h:335
unsigned int fMinSegStop
Definition: PmaTrack3D.h:338
float fHitsRadius
Definition: PmaTrack3D.h:344
size_t size() const
Definition: PmaTrack3D.h:76
pma::Hit3D *& front()
Definition: PmaTrack3D.h:72
std::vector< pma::Hit3D * > fHits
Definition: PmaTrack3D.h:322
bool AttachBackTo(pma::Node3D *vStart)
unsigned int fMaxSegStop
Definition: PmaTrack3D.h:339
pma::Node3D * FirstElement(void) const
Definition: PmaTrack3D.h:233
pma::Element3D * GetNearestElement(const TVector2 &p2d, unsigned int view, int tpc=-1, bool skipFrontVtx=false, bool skipBackVtx=false) const
pma::Segment3D * NextSegment(pma::Node3D *vtx) const
Definition: PmaTrack3D.cxx:966
void ApplyDriftShiftInTree(double dx, bool skipFirst=false)
Adjust track tree position in the drift direction (when T0 is being corrected).
bool SelectAllHits(void)
void Flip(void)
Definition: PmaTrack3D.cxx:596
std::vector< TVector3 * > fAssignedPoints
Definition: PmaTrack3D.h:324
void AddHits(const std::vector< art::Ptr< recob::Hit > > &hits)
Definition: PmaTrack3D.cxx:393
bool InitFromRefPoints(int tpc, int cryo)
Definition: PmaTrack3D.cxx:215