Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
dt::Cand Class Reference

Calculation and representation of a straight line passing through several "segment" windows. More...

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-12-03/DiscreteTracker/Cand.h"

Public Member Functions

 Cand (geo::View_t view, bool up)
 
void AddChunk (const Chunk &chunk, Direction dir)
 Simply store the chunk in the list. Need to call AddSeg too. More...
 
void PopFirstChunk ()
 
void PopLastChunk ()
 
bool operator< (const Cand &rhs) const
 
void EstimateStraightLine (double &z1, double &y1, double &z2, double &y2) const
 
double MinGradient () const
 
double MaxGradient () const
 
double EstimateGradient () const
 
geo::View_t View () const
 
unsigned int NChunks () const
 
unsigned int NDeadChunks () const
 
int NHitPlanes () const
 
const ChunkFirstChunk () const
 
const ChunkLastChunk () const
 
const ChunkExtremalChunk (Direction dir) const
 
bool IsExtremalChunkComplete (Direction dir) const
 
void MarkExtremalChunkShower (Direction dir)
 
bool IsAllShower () const
 
const SegmentFirstSeg () const
 
const SegmentLastSeg () const
 
const SegmentExtremalSeg (Direction dir) const
 
bool Up () const
 
art::PtrVector< rb::CellHitAllHits () const
 
rb::Track ToTrack () const
 
std::list< ChunkAllChunks () const
 Sorted in plane order. More...
 
unsigned int FirstPlane () const
 
unsigned int LastPlane () const
 
unsigned int ExtremalPlane (Direction dir) const
 
bool TryAddSeg (const Segment &seg, Direction dir, bool check=true)
 Appends seg to fSegs and updates internal state reflecting limits on the possible straight lines. If the new seg is impossible to accomodate, returns false and guarantees not to change any state. More...
 
bool TryAddSegOutOfOrder (const Segment &seg)
 
void PopFirstSeg ()
 
void PopLastSeg ()
 
int NSegs () const
 
void TrimFront ()
 
void TrimBack ()
 
void ShortenOne (Direction dir)
 
Cand MaybeFlip (bool &ok) const
 
bool FindChunk (int plane, Chunk &chunk) const
 
bool operator== (const Cand &rhs) const
 

Protected Member Functions

void MinMaxLines (const Segment &segi, const Segment &segj, double &mmax, double &mmin, double &cmax, double &cmin) const
 Helper for TryAddSeg. More...
 
void MinMaxLines (const SubSeg &segi, const SubSeg &segj, double &mmax, double &mmin, double &cmax, double &cmin) const
 
void PopSegHelper (const Segment &segi, Direction end)
 
double ClosestToEndCell (bool left) const
 Z position. More...
 
double MAvg () const
 
double CAvg () const
 

Protected Attributes

geo::View_t fView
 
bool fUp
 
double fAllMMax
 
double fAllMMin
 
double fAllCMax
 
double fAllCMin
 
int fNChunks
 
int fNDeadChunks
 
std::list< SegmentfSegs
 
std::list< ChunkfChunks
 
bool fAllHitsDirty
 
art::PtrVector< rb::CellHitfAllHits
 Always access via AllHits. More...
 

Detailed Description

Calculation and representation of a straight line passing through several "segment" windows.

Definition at line 25 of file Cand.h.

Constructor & Destructor Documentation

dt::Cand::Cand ( geo::View_t  view,
bool  up 
)

Definition at line 26 of file Cand.cxx.

27  : fView(view), fUp(up),
28  fAllMMax(+1e10), fAllMMin(-1e10),
29  fAllCMax(+1e10), fAllCMin(-1e10),
30  fNChunks(0), fNDeadChunks(0),
31  fAllHitsDirty(true)
32  {
33  }
bool fUp
Definition: Cand.h:117
int fNDeadChunks
Definition: Cand.h:121
geo::View_t fView
Definition: Cand.h:115
double fAllMMax
Definition: Cand.h:119
double fAllCMax
Definition: Cand.h:119
int fNChunks
Definition: Cand.h:121
double fAllMMin
Definition: Cand.h:119
double fAllCMin
Definition: Cand.h:119
bool fAllHitsDirty
Definition: Cand.h:126

Member Function Documentation

void dt::Cand::AddChunk ( const Chunk chunk,
Direction  dir 
)

Simply store the chunk in the list. Need to call AddSeg too.

Definition at line 36 of file Cand.cxx.

References ana::assert(), fAllHitsDirty, fChunks, fNChunks, fNDeadChunks, fUp, dt::Chunk::HasHits(), dt::kDownstream, and dt::Chunk::Up().

Referenced by dt::DiscreteTracker::BestSeed(), MaybeFlip(), and dt::DiscreteTracker::TryExtendCandOne().

37  {
38  fAllHitsDirty = true;
39 
40  if(chunk.HasHits())
41  ++fNChunks;
42  else
43  ++fNDeadChunks;
44  assert(chunk.Up() == fUp);
45 
46  if(dir == kDownstream)
47  fChunks.push_back(chunk);
48  else
49  fChunks.push_front(chunk);
50  }
bool fUp
Definition: Cand.h:117
int fNDeadChunks
Definition: Cand.h:121
int fNChunks
Definition: Cand.h:121
TDirectory * dir
Definition: macro.C:5
assert(nhit_max >=nhit_nbins)
bool fAllHitsDirty
Definition: Cand.h:126
std::list< Chunk > fChunks
Definition: Cand.h:124
std::list<Chunk> dt::Cand::AllChunks ( ) const
inline

Sorted in plane order.

Definition at line 65 of file Cand.h.

65 {return fChunks;}
std::list< Chunk > fChunks
Definition: Cand.h:124
art::PtrVector< rb::CellHit > dt::Cand::AllHits ( ) const

Definition at line 424 of file Cand.cxx.

References CAvg(), art::PtrVector< T >::clear(), fAllHits, fAllHitsDirty, fChunks, FirstSeg(), fNChunks, fSegs, it, LastChunk(), LastSeg(), dt::Segment::left, m, MAvg(), dt::Chunk::Plane(), art::PtrVector< T >::push_back(), and art::PtrVector< T >::size().

Referenced by ClosestToEndCell(), operator<(), and dt::DiscreteTracker::TryExtendChainOne().

425  {
426  if(!fAllHitsDirty) return fAllHits;
427  fAllHitsDirty = false;
428 
429  fAllHits.clear();
430  if(fSegs.size() <= 1) return fAllHits;
431  if(fNChunks == 0) return fAllHits;
432 
433  for(std::list<Chunk>::const_iterator it = fChunks.begin(); it != fChunks.end(); ++it){
434  art::PtrVector<rb::CellHit> chunkHits = it->AllHits();
435 
436  // Unless it's the type of chunk you have to do by dead-reckoning the
437  // track.
438  if(it->IsShowerChunk() ||
439  (it == fChunks.begin() && !FirstSeg().left) ||
440  (it->Plane() == LastChunk().Plane() && LastSeg().left)){
441 
442  chunkHits = it->HitsOnLine(MAvg(), CAvg());
443  }
444 
445  for(unsigned int m = 0; m < chunkHits.size(); ++m)
446  fAllHits.push_back(chunkHits[m]);
447  } // end for it
448 
449  return fAllHits;
450  }
double CAvg() const
Definition: Cand.h:113
int Plane() const
Definition: Chunk.h:23
set< int >::iterator it
std::list< Segment > fSegs
Definition: Cand.h:123
bool left
Definition: Segment.h:41
const Segment & LastSeg() const
Definition: Cand.cxx:371
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:441
const Segment & FirstSeg() const
Definition: Cand.cxx:365
size_type size() const
Definition: PtrVector.h:308
const Chunk & LastChunk() const
Definition: Cand.cxx:359
int fNChunks
Definition: Cand.h:121
double MAvg() const
Definition: Cand.h:112
bool fAllHitsDirty
Definition: Cand.h:126
void clear()
Definition: PtrVector.h:537
std::list< Chunk > fChunks
Definition: Cand.h:124
art::PtrVector< rb::CellHit > fAllHits
Always access via AllHits.
Definition: Cand.h:128
double dt::Cand::CAvg ( ) const
inlineprotected

Definition at line 113 of file Cand.h.

Referenced by AllHits(), ClosestToEndCell(), and EstimateStraightLine().

113 {return (fAllCMin+fAllCMax)/2;}
double fAllCMax
Definition: Cand.h:119
double fAllCMin
Definition: Cand.h:119
double dt::Cand::ClosestToEndCell ( bool  left) const
protected

Z position.

Definition at line 469 of file Cand.cxx.

References AllHits(), CAvg(), geo::PlaneGeo::Cell(), geo::ClosestApproach(), dir, Dot(), fView, geom(), geo::CellGeo::GetCenter(), CLHEP::L, MAvg(), getGoodRuns4SAM::n, geo::GeometryBase::Plane(), art::PtrVector< T >::size(), and febshutoff_auto::start.

Referenced by EstimateStraightLine().

470  {
471  double bestL = left ? +1e10 : -1e10;
472  double bestZ = -1e10;
473 
475 
476  const art::PtrVector<rb::CellHit> allhits = AllHits();
477  for(unsigned int n = 0; n < allhits.size(); ++n){
478  const geo::CellGeo* geocell = geom->Plane(allhits[n]->Plane())->Cell(allhits[n]->Cell());
479  double xyz[3];
480  geocell->GetCenter(xyz);
481  // y-view by convention
482  xyz[1] = xyz[fView];
483  xyz[0] = 0;
484 
485  const TVector3 orig(0, CAvg(), 0);
486  const TVector3 dir(0, MAvg(), 1);
487 
488  TVector3 start;
489  geo::ClosestApproach(TVector3(xyz), orig, dir, start);
490 
491  // Distance along the line
492  const double L = (start-orig).Dot(dir);
493 
494  if((left && L < bestL) ||
495  (!left && L > bestL)){
496  bestL = L;
497  bestZ = start.Z();
498  }
499  } // end for n
500 
501  // TODO
502  // assert(bestZ > -1e10);
503  return bestZ;
504  }
double CAvg() const
Definition: Cand.h:113
void GetCenter(double *xyz, double localz=0.0) const
Definition: CellGeo.cxx:159
float Dot(const Proxy &v) const
const CellGeo * Cell(int icell) const
Definition: PlaneGeo.h:48
const PlaneGeo * Plane(unsigned int i) const
geo::View_t fView
Definition: Cand.h:115
static constexpr double L
art::PtrVector< rb::CellHit > AllHits() const
Definition: Cand.cxx:424
size_type size() const
Definition: PtrVector.h:308
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:104
double ClosestApproach(const double point[], const double intercept[], const double slopes[], double closest[])
Find the distance of closest approach between point and line.
Definition: Geo.cxx:222
TDirectory * dir
Definition: macro.C:5
double MAvg() const
Definition: Cand.h:112
void geom(int which=0)
Definition: geom.C:163
Encapsulate the cell geometry.
Definition: CellGeo.h:25
double dt::Cand::EstimateGradient ( ) const
inline

Definition at line 38 of file Cand.h.

38 {return MAvg();}
double MAvg() const
Definition: Cand.h:112
void dt::Cand::EstimateStraightLine ( double &  z1,
double &  y1,
double &  z2,
double &  y2 
) const

Definition at line 284 of file Cand.cxx.

References a, ana::assert(), b, CAvg(), ClosestToEndCell(), FirstChunk(), fSegs, geom(), geo::kPLANE_NOT_FOUND, LastChunk(), MAvg(), and dt::Chunk::Plane().

Referenced by ToTrack().

286  {
287  assert(fSegs.size() > 1);
288 
290 
291  // Best guess is starting halfway to the previous plane and ending halfway
292  // to the next.
293  const int firstPlane = FirstChunk().Plane();
294  const int prevPlane = fSegs.front().left ? geom->NextPlaneInView(firstPlane, -1) : firstPlane;
295 
296  const int lastPlane = LastChunk().Plane();
297  const int nextPlane = fSegs.back().left ? lastPlane : geom->NextPlaneInView(lastPlane, +1);
298 
299  if(prevPlane != geo::kPLANE_NOT_FOUND){
300  double a[3], b[3];
301  geom->Plane(prevPlane)->Cell(0)->GetCenter(a);
302  geom->Plane(firstPlane)->Cell(0)->GetCenter(b);
303  z1 = (a[2]+b[2])/2;
304  }
305  else{
306  z1 = fSegs.front().zL;
307  }
308 
309  if(nextPlane != geo::kPLANE_NOT_FOUND){
310  double a[3], b[3];
311  geom->Plane(lastPlane)->Cell(0)->GetCenter(a);
312  geom->Plane(nextPlane)->Cell(0)->GetCenter(b);
313  z2 = (a[2]+b[2])/2;
314  }
315  else{
316  z2 = fSegs.back().zR;
317  }
318 
319  // Except if the first or last chunk is partial, in which case our best
320  // guess is nearest the centre of the first or last cell.
321  if(!fSegs.front().left){
322  const double newz1 = ClosestToEndCell(true);
323  if(newz1 < fSegs.front().zL) z1 = newz1;
324  } // end if
325 
326 
327  if(fSegs.back().left){
328  const double newz2 = ClosestToEndCell(false);
329  if(newz2 > fSegs.back().zR) z2 = newz2;
330  }
331 
332  const double cavg = CAvg();
333  const double mavg = MAvg();
334 
335  y1 = cavg+mavg*z1;
336  y2 = cavg+mavg*z2;
337 
338  assert(z2 >= z1);
339  }
double CAvg() const
Definition: Cand.h:113
int Plane() const
Definition: Chunk.h:23
Float_t y1[n_points_granero]
Definition: compare.C:5
std::list< Segment > fSegs
Definition: Cand.h:123
double ClosestToEndCell(bool left) const
Z position.
Definition: Cand.cxx:469
const Chunk & FirstChunk() const
Definition: Cand.cxx:353
const double a
const Chunk & LastChunk() const
Definition: Cand.cxx:359
double MAvg() const
Definition: Cand.h:112
void geom(int which=0)
Definition: geom.C:163
const hit & b
Definition: hits.cxx:21
assert(nhit_max >=nhit_nbins)
const Chunk& dt::Cand::ExtremalChunk ( Direction  dir) const
inline

Definition at line 46 of file Cand.h.

References dt::kUpstream.

Referenced by dt::DiscreteTracker::TryExtendCand().

47  {
48  if(dir == kUpstream) return FirstChunk();
49  return LastChunk();
50  }
const Chunk & FirstChunk() const
Definition: Cand.cxx:353
const Chunk & LastChunk() const
Definition: Cand.cxx:359
TDirectory * dir
Definition: macro.C:5
unsigned int dt::Cand::ExtremalPlane ( Direction  dir) const
inline

Definition at line 68 of file Cand.h.

References dt::kUpstream.

Referenced by dt::Chain::ExtremalPlane(), dt::DiscreteTracker::PossibleNextSegs(), and dt::DiscreteTracker::SpliceChains().

69  {
70  if(dir == kUpstream) return FirstPlane();
71  return LastPlane();
72  }
unsigned int FirstPlane() const
Definition: Cand.h:66
unsigned int LastPlane() const
Definition: Cand.h:67
TDirectory * dir
Definition: macro.C:5
const Segment& dt::Cand::ExtremalSeg ( Direction  dir) const
inline

Definition at line 56 of file Cand.h.

References dt::kUpstream.

Referenced by TryAddSeg().

57  {
58  if(dir == kUpstream) return FirstSeg();
59  return LastSeg();
60  }
const Segment & LastSeg() const
Definition: Cand.cxx:371
const Segment & FirstSeg() const
Definition: Cand.cxx:365
TDirectory * dir
Definition: macro.C:5
bool dt::Cand::FindChunk ( int  plane,
Chunk chunk 
) const

Definition at line 575 of file Cand.cxx.

References fChunks, it, and NDAPDHVSetting::plane.

576  {
577  for(std::list<Chunk>::const_iterator it = fChunks.begin(); it != fChunks.end(); ++it){
578  if(it->Plane() == plane){
579  chunk = *it;
580  return true;
581  }
582  }
583  return false;
584  }
set< int >::iterator it
std::list< Chunk > fChunks
Definition: Cand.h:124
const Chunk & dt::Cand::FirstChunk ( ) const

Definition at line 353 of file Cand.cxx.

References fChunks.

Referenced by EstimateStraightLine(), dt::Chain::FirstChunk(), dt::Chain::FirstPlane(), operator<(), dt::DiscreteTracker::PossibleNextSegs(), and dt::Chain::ToTrack().

354  {
355  return fChunks.front();
356  }
std::list< Chunk > fChunks
Definition: Cand.h:124
unsigned int dt::Cand::FirstPlane ( ) const
inline

Definition at line 66 of file Cand.h.

References dt::Segment::plane.

Referenced by dt::DiscreteTracker::PossibleNextSegs().

66 {return FirstSeg().plane;}
const Segment & FirstSeg() const
Definition: Cand.cxx:365
int plane
Definition: Segment.h:42
const Segment & dt::Cand::FirstSeg ( ) const

Definition at line 365 of file Cand.cxx.

References fSegs.

Referenced by AllHits(), dt::Chain::FirstSeg(), IsExtremalChunkComplete(), dt::DiscreteTracker::PossibleNextSegs(), and ShortenOne().

366  {
367  return fSegs.front();
368  }
std::list< Segment > fSegs
Definition: Cand.h:123
bool dt::Cand::IsAllShower ( ) const

Definition at line 415 of file Cand.cxx.

References fChunks, and it.

Referenced by dt::DiscreteTracker::TryExtendChainOne().

416  {
417  for(std::list<Chunk>::const_iterator it = fChunks.begin(); it != fChunks.end(); ++it){
418  if(!it->IsShowerChunk()) return false;
419  }
420  return true;
421  }
set< int >::iterator it
std::list< Chunk > fChunks
Definition: Cand.h:124
bool dt::Cand::IsExtremalChunkComplete ( Direction  dir) const

Definition at line 377 of file Cand.cxx.

References FirstSeg(), dt::kUpstream, LastSeg(), and dt::Segment::left.

Referenced by MarkExtremalChunkShower(), and dt::DiscreteTracker::TryExtendCand().

378  {
379  if(dir == kUpstream) return FirstSeg().left;
380  return !LastSeg().left;
381  }
bool left
Definition: Segment.h:41
const Segment & LastSeg() const
Definition: Cand.cxx:371
const Segment & FirstSeg() const
Definition: Cand.cxx:365
TDirectory * dir
Definition: macro.C:5
const Chunk & dt::Cand::LastChunk ( ) const

Definition at line 359 of file Cand.cxx.

References fChunks.

Referenced by AllHits(), EstimateStraightLine(), dt::Chain::LastChunk(), dt::Chain::LastPlane(), and dt::DiscreteTracker::PossibleNextSegs().

360  {
361  return fChunks.back();
362  }
std::list< Chunk > fChunks
Definition: Cand.h:124
unsigned int dt::Cand::LastPlane ( ) const
inline

Definition at line 67 of file Cand.h.

References dt::Segment::plane.

Referenced by dt::DiscreteTracker::PossibleNextSegs().

67 {return LastSeg().plane;}
const Segment & LastSeg() const
Definition: Cand.cxx:371
int plane
Definition: Segment.h:42
const Segment & dt::Cand::LastSeg ( ) const

Definition at line 371 of file Cand.cxx.

References fSegs.

Referenced by AllHits(), IsExtremalChunkComplete(), dt::Chain::LastSeg(), dt::DiscreteTracker::PossibleNextSegs(), and ShortenOne().

372  {
373  return fSegs.back();
374  }
std::list< Segment > fSegs
Definition: Cand.h:123
void dt::Cand::MarkExtremalChunkShower ( Direction  dir)

Definition at line 384 of file Cand.cxx.

References ana::assert(), fChunks, IsExtremalChunkComplete(), dt::kDownstream, dt::kUpstream, PopFirstSeg(), PopLastSeg(), and TryAddSeg().

Referenced by dt::DiscreteTracker::TryExtendCand().

385  {
386  const bool complete = IsExtremalChunkComplete(dir);
387 
388  if(dir == kUpstream){
389  fChunks.begin()->SetShowerChunk();
390  if(complete) PopFirstSeg();
391  PopFirstSeg();
392  const std::pair<Segment, Segment> segs = fChunks.begin()->GetSegs();
393  bool ok = TryAddSeg(segs.second, kUpstream);
394  assert(ok);
395  if(complete){
396  ok = TryAddSeg(segs.first, kUpstream);
397  assert(ok);
398  }
399  }
400  else{
401  fChunks.rbegin()->SetShowerChunk();
402  if(complete) PopLastSeg();
403  PopLastSeg();
404  const std::pair<Segment, Segment> segs = fChunks.rbegin()->GetSegs();
405  bool ok = TryAddSeg(segs.first, kDownstream);
406  assert(ok);
407  if(complete){
408  ok = TryAddSeg(segs.second, kDownstream);
409  assert(ok);
410  }
411  }
412  }
void PopLastSeg()
Definition: Cand.cxx:223
void PopFirstSeg()
Definition: Cand.cxx:212
bool IsExtremalChunkComplete(Direction dir) const
Definition: Cand.cxx:377
bool TryAddSeg(const Segment &seg, Direction dir, bool check=true)
Appends seg to fSegs and updates internal state reflecting limits on the possible straight lines...
Definition: Cand.cxx:150
TDirectory * dir
Definition: macro.C:5
assert(nhit_max >=nhit_nbins)
std::list< Chunk > fChunks
Definition: Cand.h:124
double dt::Cand::MAvg ( ) const
inlineprotected

Definition at line 112 of file Cand.h.

Referenced by AllHits(), ClosestToEndCell(), and EstimateStraightLine().

112 {return (fAllMMin+fAllMMax)/2;}
double fAllMMax
Definition: Cand.h:119
double fAllMMin
Definition: Cand.h:119
double dt::Cand::MaxGradient ( ) const
inline

Definition at line 37 of file Cand.h.

Referenced by dt::DiscreteTracker::DotScore().

37 {return fAllMMax;}
double fAllMMax
Definition: Cand.h:119
Cand dt::Cand::MaybeFlip ( bool &  ok) const

Definition at line 547 of file Cand.cxx.

References AddChunk(), make_associated_cosmic_defs::chunk, fChunks, fSegs, fUp, fView, dt::Chunk::GetSegs(), it, dt::kDownstream, runNovaSAM::ret, dt::Chunk::SetUp(), and TryAddSeg().

Referenced by dt::DiscreteTracker::DotScore(), and dt::DiscreteTracker::TryExtendCand().

548  {
549  Cand ret(fView, !fUp);
550 
551  for(std::list<Chunk>::const_iterator it = fChunks.begin(); it != fChunks.end(); ++it){
552  Chunk chunk = *it;
553  chunk.SetUp(!fUp);
554  ret.AddChunk(chunk, kDownstream);
555 
556  const std::pair<Segment, Segment> segs = chunk.GetSegs();
557 
558  // Add first seg unless it's the very first and we don't have it
559  if(it != fChunks.begin() || fSegs.front().left){
560  ok = ret.TryAddSeg(segs.first, kDownstream);
561  if(!ok) return ret;
562  }
563 
564  // Add second seg unless it's the last and we don't have it
565  if(ret.fSegs.size() < fSegs.size()){
566  ok = ret.TryAddSeg(segs.second, kDownstream);
567  if(!ok) return ret;
568  }
569  }
570 
571  return ret;
572  }
bool fUp
Definition: Cand.h:117
set< int >::iterator it
Cand(geo::View_t view, bool up)
Definition: Cand.cxx:26
std::list< Segment > fSegs
Definition: Cand.h:123
geo::View_t fView
Definition: Cand.h:115
std::list< Chunk > fChunks
Definition: Cand.h:124
double dt::Cand::MinGradient ( ) const
inline

Definition at line 36 of file Cand.h.

Referenced by dt::DiscreteTracker::DotScore().

36 {return fAllMMin;}
double fAllMMin
Definition: Cand.h:119
void dt::Cand::MinMaxLines ( const Segment segi,
const Segment segj,
double &  mmax,
double &  mmin,
double &  cmax,
double &  cmin 
) const
protected

Helper for TryAddSeg.

Definition at line 127 of file Cand.cxx.

References cmax, dz, dt::Segment::GetSubSeg(), dt::kDownstream, dt::kUpstream, and dt::Segment::zL.

Referenced by PopSegHelper(), and TryAddSeg().

130  {
131  const double dz = segj.zL-segi.zL;
132 
133  if(dz < 0){
134  MinMaxLines(segj, segi, mmax, mmin, cmax, cmin);
135  return;
136  }
137 
138  mmax = +1e10;
139  mmin = -1e10;
140  cmax = +1e10;
141  cmin = -1e10;
142 
143  MinMaxLines(segi.GetSubSeg(kUpstream), segj.GetSubSeg(kUpstream), mmax, mmin, cmax, cmin);
144  MinMaxLines(segi.GetSubSeg(kUpstream), segj.GetSubSeg(kDownstream), mmax, mmin, cmax, cmin);
145  MinMaxLines(segi.GetSubSeg(kDownstream), segj.GetSubSeg(kUpstream), mmax, mmin, cmax, cmin);
146  MinMaxLines(segi.GetSubSeg(kDownstream), segj.GetSubSeg(kDownstream), mmax, mmin, cmax, cmin);
147  }
const int cmax
Definition: cellShifts.C:14
double dz[NP][NC]
void MinMaxLines(const Segment &segi, const Segment &segj, double &mmax, double &mmin, double &cmax, double &cmin) const
Helper for TryAddSeg.
Definition: Cand.cxx:127
void dt::Cand::MinMaxLines ( const SubSeg segi,
const SubSeg segj,
double &  mmax,
double &  mmin,
double &  cmax,
double &  cmin 
) const
protected

Definition at line 110 of file Cand.cxx.

References ana::assert(), dz, std::max(), std::min(), dt::SubSeg::y0, dt::SubSeg::y1, and dt::SubSeg::z.

113  {
114  const double dz = segj.z-segi.z;
115 
116  // Got sorted at some earlier stage
117  assert(dz > 0);
118 
119  mmax = std::min(mmax, (segj.y1-segi.y0)/dz);
120  mmin = std::max(mmin, (segj.y0-segi.y1)/dz);
121 
122  cmax = std::min(cmax, segi.y1-segi.z*(segj.y0-segi.y1)/dz);
123  cmin = std::max(cmin, segi.y0-segi.z*(segj.y1-segi.y0)/dz);
124  }
T max(const caf::Proxy< T > &a, T b)
const int cmax
Definition: cellShifts.C:14
double dz[NP][NC]
assert(nhit_max >=nhit_nbins)
T min(const caf::Proxy< T > &a, T b)
unsigned int dt::Cand::NChunks ( ) const
inline

Definition at line 41 of file Cand.h.

Referenced by dt::Chain::Add(), dt::Chain::AddFront(), and dt::DiscreteTracker::TryExtendChainOne().

41 {return fNChunks;}
int fNChunks
Definition: Cand.h:121
unsigned int dt::Cand::NDeadChunks ( ) const
inline

Definition at line 42 of file Cand.h.

42 {return fNDeadChunks;}
int fNDeadChunks
Definition: Cand.h:121
int dt::Cand::NHitPlanes ( ) const

Definition at line 342 of file Cand.cxx.

References fChunks, it, and runNovaSAM::ret.

Referenced by operator<().

343  {
344  int ret = 0;
345  for(std::list<Chunk>::const_iterator it = fChunks.begin(); it != fChunks.end(); ++it){
346  if(!it->AllDead()) ++ret;
347  }
348 
349  return ret;
350  }
set< int >::iterator it
std::list< Chunk > fChunks
Definition: Cand.h:124
int dt::Cand::NSegs ( ) const
inline
bool dt::Cand::operator< ( const Cand rhs) const

Definition at line 80 of file Cand.cxx.

References AllHits(), FirstChunk(), fNDeadChunks, fSegs, NHitPlanes(), dt::Chunk::Plane(), and art::PtrVector< T >::size().

81  {
82  // This is sufficient to sort them, but can't be used for a map or set
83  // Possibly shouldn't include it as an operator then...
84 
85  if(NHitPlanes() < rhs.NHitPlanes()) return true;
86  if(NHitPlanes() > rhs.NHitPlanes()) return false;
87 
88  if(fSegs.size() < rhs.fSegs.size()) return true;
89  if(fSegs.size() > rhs.fSegs.size()) return false;
90 
91  // Having more dead is a _bad_ thing. Select the ones without
92  // preferentially
93  if(fNDeadChunks > rhs.fNDeadChunks) return true;
94  if(fNDeadChunks < rhs.fNDeadChunks) return false;
95 
96  // if(fChunks.size() < rhs.fChunks.size()) return true;
97  // if(fChunks.size() > rhs.fChunks.size()) return false;
98 
99  // Even if these are only destined to be singleton chunks, need to give the
100  // biggest ones back first because we'll stop looking for new chains when
101  // we see small ones.
102  if(AllHits().size() < rhs.AllHits().size()) return true;
103  if(AllHits().size() > rhs.AllHits().size()) return false;
104 
105  // Arbitrary, but removes dependence on order FindCands emits things
106  return FirstChunk().Plane() < rhs.FirstChunk().Plane();
107  }
int Plane() const
Definition: Chunk.h:23
std::list< Segment > fSegs
Definition: Cand.h:123
int NHitPlanes() const
Definition: Cand.cxx:342
const Chunk & FirstChunk() const
Definition: Cand.cxx:353
int fNDeadChunks
Definition: Cand.h:121
art::PtrVector< rb::CellHit > AllHits() const
Definition: Cand.cxx:424
size_type size() const
Definition: PtrVector.h:308
bool dt::Cand::operator== ( const Cand rhs) const

Definition at line 587 of file Cand.cxx.

References fSegs, fUp, and fView.

588  {
589  if(fView != rhs.fView) return false;
590  if(fUp != rhs.fUp) return false;
591 
592  return fSegs == rhs.fSegs;
593  }
bool fUp
Definition: Cand.h:117
std::list< Segment > fSegs
Definition: Cand.h:123
geo::View_t fView
Definition: Cand.h:115
void dt::Cand::PopFirstChunk ( )

Definition at line 53 of file Cand.cxx.

References fAllHitsDirty, fChunks, fNChunks, and fNDeadChunks.

Referenced by ShortenOne().

54  {
55 
56  if(fChunks.front().HasHits())
57  --fNChunks;
58  else
59  --fNDeadChunks;
60 
61  fChunks.pop_front();
62 
63  fAllHitsDirty = true;
64  }
int fNDeadChunks
Definition: Cand.h:121
int fNChunks
Definition: Cand.h:121
bool fAllHitsDirty
Definition: Cand.h:126
std::list< Chunk > fChunks
Definition: Cand.h:124
void dt::Cand::PopFirstSeg ( )

Definition at line 212 of file Cand.cxx.

References ana::assert(), fSegs, dt::kUpstream, and PopSegHelper().

Referenced by MarkExtremalChunkShower(), and ShortenOne().

213  {
214  assert(fSegs.size() > 1);
215 
216  const Segment segi = fSegs.front();
217  fSegs.pop_front();
218 
219  PopSegHelper(segi, kUpstream);
220  }
void PopSegHelper(const Segment &segi, Direction end)
Definition: Cand.cxx:234
std::list< Segment > fSegs
Definition: Cand.h:123
assert(nhit_max >=nhit_nbins)
void dt::Cand::PopLastChunk ( )

Definition at line 67 of file Cand.cxx.

References fAllHitsDirty, fChunks, fNChunks, and fNDeadChunks.

Referenced by ShortenOne().

68  {
69  if(fChunks.back().HasHits())
70  --fNChunks;
71  else
72  --fNDeadChunks;
73 
74  fChunks.pop_back();
75 
76  fAllHitsDirty = true;
77  }
int fNDeadChunks
Definition: Cand.h:121
int fNChunks
Definition: Cand.h:121
bool fAllHitsDirty
Definition: Cand.h:126
std::list< Chunk > fChunks
Definition: Cand.h:124
void dt::Cand::PopLastSeg ( )

Definition at line 223 of file Cand.cxx.

References ana::assert(), fSegs, dt::kDownstream, and PopSegHelper().

Referenced by MarkExtremalChunkShower(), and ShortenOne().

224  {
225  assert(fSegs.size() > 1);
226 
227  const Segment segi = fSegs.back();
228  fSegs.pop_back();
229 
230  PopSegHelper(segi, kDownstream);
231  }
void PopSegHelper(const Segment &segi, Direction end)
Definition: Cand.cxx:234
std::list< Segment > fSegs
Definition: Cand.h:123
assert(nhit_max >=nhit_nbins)
void dt::Cand::PopSegHelper ( const Segment segi,
Direction  end 
)
protected

Definition at line 234 of file Cand.cxx.

References ana::assert(), cmax, e, fAllCMax, fAllCMin, fAllMMax, fAllMMin, fSegs, it, dt::kDownstream, MinMaxLines(), and TryAddSeg().

Referenced by PopFirstSeg(), and PopLastSeg().

235  {
236  if(fSegs.size() == 1){
237  fAllMMax = +1e10;
238  fAllMMin = -1e10;
239  fAllCMax = +1e10;
240  fAllCMin = -1e10;
241  return;
242  }
243 
244  // Work out if this seg was responsible for any of the strongest
245  // constraints.
246  bool needRecalc = false;
247  for(std::list<Segment>::iterator it = fSegs.begin(); it != fSegs.end(); ++it){
248  const Segment& segj = *it;
249 
250  double mmax, mmin, cmax, cmin;
251  MinMaxLines((end == kDownstream) ? segj : segi,
252  (end == kDownstream) ? segi : segj,
253  mmax, mmin, cmax, cmin);
254 
255  if(mmax-1e-6 < fAllMMax ||
256  mmin+1e-6 > fAllMMin ||
257  cmax-1e-6 < fAllCMax ||
258  cmin+1e-6 > fAllCMin){
259  needRecalc = true;
260  break;
261  }
262  }
263 
264  if(!needRecalc) return;
265 
266  // If this seg was important, need to recalculate the whole lot to find the
267  // 2nd most stringent. To avoid this we'd have to store more information in
268  // the object.
269  std::list<Segment> segs = fSegs;
270  fSegs.clear();
271 
272  fAllMMax = +1e10;
273  fAllMMin = -1e10;
274  fAllCMax = +1e10;
275  fAllCMin = -1e10;
276 
277  for(std::list<Segment>::iterator it = segs.begin(); it != segs.end(); ++it){
278  const bool ok = TryAddSeg(*it, kDownstream);
279  assert(ok);
280  }
281  }
set< int >::iterator it
const int cmax
Definition: cellShifts.C:14
std::list< Segment > fSegs
Definition: Cand.h:123
double fAllMMax
Definition: Cand.h:119
double fAllCMax
Definition: Cand.h:119
bool TryAddSeg(const Segment &seg, Direction dir, bool check=true)
Appends seg to fSegs and updates internal state reflecting limits on the possible straight lines...
Definition: Cand.cxx:150
void MinMaxLines(const Segment &segi, const Segment &segj, double &mmax, double &mmin, double &cmax, double &cmin) const
Helper for TryAddSeg.
Definition: Cand.cxx:127
double fAllMMin
Definition: Cand.h:119
double fAllCMin
Definition: Cand.h:119
assert(nhit_max >=nhit_nbins)
Float_t e
Definition: plot.C:35
void dt::Cand::ShortenOne ( Direction  dir)

Definition at line 533 of file Cand.cxx.

References FirstSeg(), dt::kDownstream, LastSeg(), art::left(), PopFirstChunk(), PopFirstSeg(), PopLastChunk(), and PopLastSeg().

Referenced by dt::DiscreteTracker::TryExtendChainOne().

534  {
535  if(dir == kDownstream){
536  if(!FirstSeg().left) PopFirstChunk();
537  PopFirstSeg();
538  }
539  else{
540  if(LastSeg().left) PopLastChunk();
541  PopLastSeg();
542  }
543  }
const Segment & LastSeg() const
Definition: Cand.cxx:371
void PopLastSeg()
Definition: Cand.cxx:223
void PopFirstSeg()
Definition: Cand.cxx:212
const Segment & FirstSeg() const
Definition: Cand.cxx:365
void PopFirstChunk()
Definition: Cand.cxx:53
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:104
TDirectory * dir
Definition: macro.C:5
void PopLastChunk()
Definition: Cand.cxx:67
rb::Track dt::Cand::ToTrack ( ) const

Definition at line 453 of file Cand.cxx.

References rb::Cluster::Add(), rb::Track::AppendTrajectoryPoint(), EstimateStraightLine(), fChunks, fView, it, runNovaSAM::ret, y1, and submit_syst::y2.

Referenced by dt::DiscreteTracker::RecoOneTrack().

454  {
455  double z1, y1, z2, y2;
456  EstimateStraightLine(z1, y1, z2, y2);
458  fView, y1, z1, y2-y1, z2-z1);
459  ret.AppendTrajectoryPoint(y2, z2);
460  for(std::list<Chunk>::const_iterator it = fChunks.begin(); it != fChunks.end(); ++it){
461  ret.Add(it->AllHits());
462  }
463  // TODO: this can happen sometimes, figure out when and why
464  // assert(ret.NCell() > 0);
465  return ret;
466  }
set< int >::iterator it
Float_t y1[n_points_granero]
Definition: compare.C:5
A rb::Prong with full reconstructed trajectory.
Definition: Track.h:20
void EstimateStraightLine(double &z1, double &y1, double &z2, double &y2) const
Definition: Cand.cxx:284
geo::View_t fView
Definition: Cand.h:115
std::list< Chunk > fChunks
Definition: Cand.h:124
void dt::Cand::TrimBack ( )

Definition at line 520 of file Cand.cxx.

References fAllHitsDirty, fChunks, fSegs, and NDAPDHVSetting::plane.

521  {
522  fAllHitsDirty = true;
523 
524  while(!fChunks.empty()){
525  if(!fChunks.back().AllDead()) return;
526  const int plane = fChunks.back().Plane();
527  fChunks.pop_back();
528  while(fSegs.back().plane == plane) fSegs.pop_back();
529  }
530  }
std::list< Segment > fSegs
Definition: Cand.h:123
bool fAllHitsDirty
Definition: Cand.h:126
std::list< Chunk > fChunks
Definition: Cand.h:124
void dt::Cand::TrimFront ( )

Definition at line 507 of file Cand.cxx.

References fAllHitsDirty, fChunks, fSegs, and NDAPDHVSetting::plane.

508  {
509  fAllHitsDirty = true;
510 
511  while(!fChunks.empty()){
512  if(!fChunks.front().AllDead()) return;
513  const int plane = fChunks.front().Plane();
514  fChunks.pop_front();
515  while(fSegs.front().plane == plane) fSegs.pop_front();
516  }
517  }
std::list< Segment > fSegs
Definition: Cand.h:123
bool fAllHitsDirty
Definition: Cand.h:126
std::list< Chunk > fChunks
Definition: Cand.h:124
bool dt::Cand::TryAddSeg ( const Segment seg,
Direction  dir,
bool  check = true 
)

Appends seg to fSegs and updates internal state reflecting limits on the possible straight lines. If the new seg is impossible to accomodate, returns false and guarantees not to change any state.

Definition at line 150 of file Cand.cxx.

References ana::assert(), cmax, ExtremalSeg(), fAllCMax, fAllCMin, fAllHitsDirty, fAllMMax, fAllMMin, fSegs, fUp, it, dt::kDownstream, dt::Segment::left, std::max(), std::min(), and MinMaxLines().

Referenced by dt::DiscreteTracker::BestSeed(), MarkExtremalChunkShower(), MaybeFlip(), PopSegHelper(), TryAddSegOutOfOrder(), and dt::DiscreteTracker::TryExtendCandOne().

151  {
152  if(check){
153  // Must alternate sides
154  assert(fSegs.empty() || seg.left != ExtremalSeg(dir).left);
155  }
156 
157  double newAllMMax = fAllMMax;
158  double newAllMMin = fAllMMin;
159  double newAllCMax = fAllCMax;
160  double newAllCMin = fAllCMin;
161 
162  for(std::list<Segment>::iterator it = fSegs.begin(); it != fSegs.end(); ++it){
163  const Segment& segi = *it;
164  // In principle would have to loop over all j > i. But this happens every
165  // time we add a new seg, so only the last one is novel.
166  const Segment& segj = seg;
167 
168  double mmax, mmin, cmax, cmin;
169  MinMaxLines(segi, segj, mmax, mmin, cmax, cmin);
170  newAllMMax = std::min(mmax, newAllMMax);
171  newAllMMin = std::max(mmin, newAllMMin);
172  newAllCMax = std::min(cmax, newAllCMax);
173  newAllCMin = std::max(cmin, newAllCMin);
174 
175  if(newAllMMax <= newAllMMin ||
176  newAllCMax <= newAllCMin) return false;
177  } // end for it
178 
179  // TODO: I'm worried about the interaction of this with imperfect
180  // geometry/staggering, but it, or something like it, is necessary to
181  // prevent cands with the obviously "wrong" sense through one-cell chunks
182  if((fUp && newAllMMax < 0) || (!fUp && newAllMMin > 0)) return false;
183 
184  // Everything checks out, finalize the addition
185 
186  if(dir == kDownstream)
187  fSegs.push_back(seg);
188  else
189  fSegs.push_front(seg);
190 
191  fAllHitsDirty = true;
192 
193  fAllMMax = newAllMMax;
194  fAllMMin = newAllMMin;
195  fAllCMax = newAllCMax;
196  fAllCMin = newAllCMin;
197 
198  return true;
199  }
T max(const caf::Proxy< T > &a, T b)
bool fUp
Definition: Cand.h:117
set< int >::iterator it
const int cmax
Definition: cellShifts.C:14
std::list< Segment > fSegs
Definition: Cand.h:123
const Segment & ExtremalSeg(Direction dir) const
Definition: Cand.h:56
bool left
Definition: Segment.h:41
double fAllMMax
Definition: Cand.h:119
double fAllCMax
Definition: Cand.h:119
TDirectory * dir
Definition: macro.C:5
void MinMaxLines(const Segment &segi, const Segment &segj, double &mmax, double &mmin, double &cmax, double &cmin) const
Helper for TryAddSeg.
Definition: Cand.cxx:127
double fAllMMin
Definition: Cand.h:119
double fAllCMin
Definition: Cand.h:119
assert(nhit_max >=nhit_nbins)
bool fAllHitsDirty
Definition: Cand.h:126
T min(const caf::Proxy< T > &a, T b)
bool dt::Cand::TryAddSegOutOfOrder ( const Segment seg)

Definition at line 202 of file Cand.cxx.

References fSegs, dt::kDownstream, and TryAddSeg().

203  {
204  if(TryAddSeg(seg, kDownstream, false)){
205  fSegs.sort();
206  return true;
207  }
208  return false;
209  }
std::list< Segment > fSegs
Definition: Cand.h:123
bool TryAddSeg(const Segment &seg, Direction dir, bool check=true)
Appends seg to fSegs and updates internal state reflecting limits on the possible straight lines...
Definition: Cand.cxx:150
bool dt::Cand::Up ( ) const
inline

Definition at line 61 of file Cand.h.

Referenced by dt::DiscreteTracker::BestSeed(), and dt::DiscreteTracker::PossibleNextSegs().

61 {return fUp;}
bool fUp
Definition: Cand.h:117
geo::View_t dt::Cand::View ( ) const
inline
Returns
Number of segs in common, or -1 if requirements aren't met

Definition at line 40 of file Cand.h.

Referenced by dt::Chain::ToTrack().

40 {return fView;}
geo::View_t fView
Definition: Cand.h:115

Member Data Documentation

double dt::Cand::fAllCMax
protected

Definition at line 119 of file Cand.h.

Referenced by PopSegHelper(), and TryAddSeg().

double dt::Cand::fAllCMin
protected

Definition at line 119 of file Cand.h.

Referenced by PopSegHelper(), and TryAddSeg().

art::PtrVector<rb::CellHit> dt::Cand::fAllHits
mutableprotected

Always access via AllHits.

Definition at line 128 of file Cand.h.

Referenced by AllHits().

bool dt::Cand::fAllHitsDirty
mutableprotected

Definition at line 126 of file Cand.h.

Referenced by AddChunk(), AllHits(), PopFirstChunk(), PopLastChunk(), TrimBack(), TrimFront(), and TryAddSeg().

double dt::Cand::fAllMMax
protected

Definition at line 119 of file Cand.h.

Referenced by PopSegHelper(), and TryAddSeg().

double dt::Cand::fAllMMin
protected

Definition at line 119 of file Cand.h.

Referenced by PopSegHelper(), and TryAddSeg().

std::list<Chunk> dt::Cand::fChunks
protected
int dt::Cand::fNChunks
protected

Definition at line 121 of file Cand.h.

Referenced by AddChunk(), AllHits(), PopFirstChunk(), and PopLastChunk().

int dt::Cand::fNDeadChunks
protected

Definition at line 121 of file Cand.h.

Referenced by AddChunk(), operator<(), PopFirstChunk(), and PopLastChunk().

std::list<Segment> dt::Cand::fSegs
protected
bool dt::Cand::fUp
protected

Definition at line 117 of file Cand.h.

Referenced by AddChunk(), MaybeFlip(), operator==(), and TryAddSeg().

geo::View_t dt::Cand::fView
protected

Definition at line 115 of file Cand.h.

Referenced by ClosestToEndCell(), MaybeFlip(), operator==(), and ToTrack().


The documentation for this class was generated from the following files: