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

Collection of overlapping Cands forming a 2D track. More...

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-11-25/DiscreteTracker/Chain.h"

Public Member Functions

 Chain ()
 
 Chain (const Cand &c)
 
rb::Track ToTrack () const
 
std::vector< rb::TrackToDebugTracks () const
 
void Add (const Cand &c)
 
void Add (const Cand &c, Direction dir)
 
void AddFront (const Cand &c)
 
unsigned int FirstPlane () const
 
unsigned int LastPlane () const
 
unsigned int ExtremalPlane (Direction dir) const
 
unsigned int ExtremalHitPlane (Direction dir) const
 
unsigned int ExtentPlane () const
 
unsigned int NCands () const
 
const CandFirstCand () const
 
const CandLastCand () const
 
const CandExtremalCand (Direction dir) const
 
const ChunkFirstChunk () const
 
const ChunkLastChunk () const
 
const SegmentFirstSeg () const
 
const SegmentLastSeg () const
 
const SegmentExtremalSeg (Direction dir) const
 
art::PtrVector< rb::CellHitAllHits () const
 
std::vector< ChunkAllChunks () const
 
int NHitPlanes () const
 
void TrimEnds ()
 Remove Cands that add no actual hits. After building but before writing. More...
 
void Truncate (unsigned int plane, Direction end)
 
void Add (const Chain &c, Direction dir)
 
dt::View::ChunkMap AsChunkMap () const
 

Protected Attributes

std::list< CandfCands
 

Detailed Description

Collection of overlapping Cands forming a 2D track.

Definition at line 29 of file Chain.h.

Constructor & Destructor Documentation

dt::Chain::Chain ( )
inline

Definition at line 32 of file Chain.h.

References plot_validation_datamc::c, and dir.

32 {}
dt::Chain::Chain ( const Cand c)

Definition at line 23 of file Chain.cxx.

References Add().

24  {
25  Add(c);
26  }
void Add(const Cand &c)
Definition: Chain.cxx:142

Member Function Documentation

void dt::Chain::Add ( const Cand c)

Definition at line 142 of file Chain.cxx.

References ana::assert(), fCands, dt::Cand::NChunks(), and dt::Cand::NSegs().

Referenced by Add(), Chain(), dt::DiscreteTracker::ExtendChain(), and dt::DiscreteTracker::SpliceChains().

143  {
144  assert(c.NChunks() > 0);
145  assert(c.NSegs() > 1);
146  fCands.push_back(c);
147  }
assert(nhit_max >=nhit_nbins)
std::list< Cand > fCands
Definition: Chain.h:80
void dt::Chain::Add ( const Cand c,
Direction  dir 
)

Definition at line 150 of file Chain.cxx.

References Add(), AddFront(), and dt::kDownstream.

151  {
152  if(dir == kDownstream)
153  Add(c);
154  else
155  AddFront(c);
156  }
void AddFront(const Cand &c)
Definition: Chain.cxx:159
void Add(const Cand &c)
Definition: Chain.cxx:142
TDirectory * dir
Definition: macro.C:5
void dt::Chain::Add ( const Chain c,
Direction  dir 
)
inline

Definition at line 71 of file Chain.h.

References fCands, and dt::kDownstream.

72  {
73  if(dir == kDownstream)
74  fCands.insert(fCands.end(), c.fCands.begin(), c.fCands.end());
75  else
76  fCands.insert(fCands.begin(), c.fCands.begin(), c.fCands.end());
77  }
TDirectory * dir
Definition: macro.C:5
std::list< Cand > fCands
Definition: Chain.h:80
void dt::Chain::AddFront ( const Cand c)

Definition at line 159 of file Chain.cxx.

References ana::assert(), fCands, dt::Cand::NChunks(), and dt::Cand::NSegs().

Referenced by Add().

160  {
161  assert(c.NChunks() > 0);
162  assert(c.NSegs() > 1);
163  fCands.push_front(c);
164  }
assert(nhit_max >=nhit_nbins)
std::list< Cand > fCands
Definition: Chain.h:80
std::vector< Chunk > dt::Chain::AllChunks ( ) const

Definition at line 245 of file Chain.cxx.

References make_goodruns_defs::chunks, fCands, it, and runNovaSAM::ret.

Referenced by AsChunkMap(), dt::DiscreteTracker::CheckAndFixSparseChain(), ExtremalHitPlane(), NHitPlanes(), and Truncate().

246  {
247  // TODO: this doesn't take into account the possibility that chunks on the
248  // same plane don't entirely correspond (due to dead channels?)
249  std::map<unsigned int, Chunk> retMap;
250 
251  for(std::list<Cand>::const_iterator it = fCands.begin(); it != fCands.end(); ++it){
252  const std::list<Chunk> chunks = it->AllChunks();
253  for(std::list<Chunk>::const_iterator it = chunks.begin(); it != chunks.end(); ++it){
254  retMap[it->Plane()] = *it;
255  }
256  }
257 
258  // Come out sorted in plane order
259  std::vector<Chunk> ret;
260  for(std::map<unsigned int, Chunk>::iterator it = retMap.begin(); it != retMap.end(); ++it)
261  ret.push_back(it->second);
262  return ret;
263  }
set< int >::iterator it
std::list< Cand > fCands
Definition: Chain.h:80
art::PtrVector< rb::CellHit > dt::Chain::AllHits ( ) const

Definition at line 220 of file Chain.cxx.

References rb::HitMap::Add(), rb::CellHit::Cell(), rb::HitMap::CellExists(), fCands, hits(), it, rb::CellHit::Plane(), art::PtrVector< T >::push_back(), runNovaSAM::ret, and art::PtrVector< T >::size().

Referenced by dt::DiscreteTracker::CheckAndFixSparseChain(), dt::DiscreteTracker::RecoDiscrete(), dt::DiscreteTracker::SpliceChains(), ToTrack(), TrimEnds(), and Truncate().

221  {
223 
224  // To eliminate duplicates
225  rb::HitMap hmap;
226 
227  for(std::list<Cand>::const_iterator it = fCands.begin();
228  it != fCands.end(); ++it){
229  const art::PtrVector<rb::CellHit>& hits = it->AllHits();
230  for(unsigned int hitIdx = 0; hitIdx < hits.size(); ++hitIdx){
231  const art::Ptr<rb::CellHit> hit = hits[hitIdx];
232  if(!hmap.CellExists(hit->Plane(), hit->Cell())){
233  ret.push_back(hit);
234  }
235  hmap.Add(hit);
236  }
237  } // end for it
238 
239  // TODO
240  // assert(!ret.empty());
241  return ret;
242  }
set< int >::iterator it
unsigned short Plane() const
Definition: CellHit.h:39
Provides efficient lookup of CellHits by plane and cell number.
Definition: HitMap.h:22
unsigned short Cell() const
Definition: CellHit.h:40
void hits()
Definition: readHits.C:15
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:441
size_type size() const
Definition: PtrVector.h:308
Definition: structs.h:12
bool CellExists(unsigned int planeIdx, unsigned int cellIdx) const
Does the map contain any cell at this position?
Definition: HitMap.cxx:81
std::list< Cand > fCands
Definition: Chain.h:80
void Add(const art::Ptr< rb::CellHit > &chit)
Definition: HitMap.cxx:37
dt::View::ChunkMap dt::Chain::AsChunkMap ( ) const

Definition at line 337 of file Chain.cxx.

References AllChunks(), make_goodruns_defs::chunks, getGoodRuns4SAM::n, and runNovaSAM::ret.

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

338  {
340 
341  const std::vector<Chunk> chunks = AllChunks();
342  for(unsigned int n = 0; n < chunks.size(); ++n)
343  ret[chunks[n].Plane()].push_back(chunks[n]);
344 
345  return ret;
346  }
std::map< int, std::vector< Chunk > > ChunkMap
Definition: View.h:27
std::vector< Chunk > AllChunks() const
Definition: Chain.cxx:245
unsigned int dt::Chain::ExtentPlane ( ) const
inline

Definition at line 43 of file Chain.h.

Referenced by dt::compareByLength(), and ToTrack().

43 {return LastPlane()-FirstPlane();}
unsigned int FirstPlane() const
Definition: Chain.cxx:167
unsigned int LastPlane() const
Definition: Chain.cxx:173
const Cand& dt::Chain::ExtremalCand ( Direction  dir) const
inline

Definition at line 47 of file Chain.h.

References dt::kUpstream.

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

48  {
49  if(dir == kUpstream) return FirstCand();
50  return LastCand();
51  }
TDirectory * dir
Definition: macro.C:5
const Cand & FirstCand() const
Definition: Chain.h:45
const Cand & LastCand() const
Definition: Chain.h:46
unsigned int dt::Chain::ExtremalHitPlane ( Direction  dir) const

Definition at line 185 of file Chain.cxx.

References AllChunks(), make_goodruns_defs::chunks, dt::kUpstream, and site_stats_from_log::reverse.

186  {
187  std::vector<Chunk> chunks = AllChunks();
188  if(dir == kUpstream) std::reverse(chunks.begin(), chunks.end());
189 
190  while(!chunks.empty() && chunks.back().AllDead()) chunks.pop_back();
191 
192  return chunks.back().Plane();
193  }
std::vector< Chunk > AllChunks() const
Definition: Chain.cxx:245
TDirectory * dir
Definition: macro.C:5
unsigned int dt::Chain::ExtremalPlane ( Direction  dir) const

Definition at line 179 of file Chain.cxx.

References ExtremalCand(), and dt::Cand::ExtremalPlane().

Referenced by dt::DiscreteTracker::CheckAndFixSparseChain(), and dt::DiscreteTracker::SpliceChains().

180  {
182  }
unsigned int ExtremalPlane(Direction dir) const
Definition: Cand.h:68
TDirectory * dir
Definition: macro.C:5
const Cand & ExtremalCand(Direction dir) const
Definition: Chain.h:47
const Segment& dt::Chain::ExtremalSeg ( Direction  dir) const
inline

Definition at line 56 of file Chain.h.

References febshutoff_auto::end, dt::kUpstream, and NDAPDHVSetting::plane.

57  {
58  if(dir == kUpstream) return FirstSeg();
59  return LastSeg();
60  }
const Segment & FirstSeg() const
Definition: Chain.cxx:208
const Segment & LastSeg() const
Definition: Chain.cxx:214
TDirectory * dir
Definition: macro.C:5
const Cand& dt::Chain::FirstCand ( ) const
inline

Definition at line 45 of file Chain.h.

Referenced by FirstChunk(), FirstPlane(), FirstSeg(), dt::DiscreteTracker::RecoDiscrete(), dt::DiscreteTracker::SpliceIsSane(), ToTrack(), and Truncate().

45 {return fCands.front();}
std::list< Cand > fCands
Definition: Chain.h:80
const Chunk & dt::Chain::FirstChunk ( ) const

Definition at line 196 of file Chain.cxx.

References FirstCand(), and dt::Cand::FirstChunk().

197  {
198  return FirstCand().FirstChunk();
199  }
const Chunk & FirstChunk() const
Definition: Cand.cxx:353
const Cand & FirstCand() const
Definition: Chain.h:45
unsigned int dt::Chain::FirstPlane ( ) const

Definition at line 167 of file Chain.cxx.

References FirstCand(), dt::Cand::FirstChunk(), and dt::Chunk::Plane().

Referenced by dt::compareByStart(), dt::DiscreteTracker::SpliceChains(), dt::DiscreteTracker::SpliceIsSane(), and Truncate().

168  {
169  return FirstCand().FirstChunk().Plane();
170  }
int Plane() const
Definition: Chunk.h:23
const Chunk & FirstChunk() const
Definition: Cand.cxx:353
const Cand & FirstCand() const
Definition: Chain.h:45
const Segment & dt::Chain::FirstSeg ( ) const

Definition at line 208 of file Chain.cxx.

References FirstCand(), and dt::Cand::FirstSeg().

Referenced by Truncate().

209  {
210  return FirstCand().FirstSeg();
211  }
const Segment & FirstSeg() const
Definition: Cand.cxx:365
const Cand & FirstCand() const
Definition: Chain.h:45
const Cand& dt::Chain::LastCand ( ) const
inline

Definition at line 46 of file Chain.h.

Referenced by LastChunk(), LastPlane(), LastSeg(), dt::DiscreteTracker::RecoDiscrete(), dt::DiscreteTracker::SpliceIsSane(), and Truncate().

46 {return fCands.back();}
std::list< Cand > fCands
Definition: Chain.h:80
const Chunk & dt::Chain::LastChunk ( ) const

Definition at line 202 of file Chain.cxx.

References LastCand(), and dt::Cand::LastChunk().

203  {
204  return LastCand().LastChunk();
205  }
const Chunk & LastChunk() const
Definition: Cand.cxx:359
const Cand & LastCand() const
Definition: Chain.h:46
unsigned int dt::Chain::LastPlane ( ) const

Definition at line 173 of file Chain.cxx.

References LastCand(), dt::Cand::LastChunk(), and dt::Chunk::Plane().

Referenced by dt::compareByEnd(), dt::DiscreteTracker::SpliceChains(), dt::DiscreteTracker::SpliceIsSane(), and Truncate().

174  {
175  return LastCand().LastChunk().Plane();
176  }
int Plane() const
Definition: Chunk.h:23
const Chunk & LastChunk() const
Definition: Cand.cxx:359
const Cand & LastCand() const
Definition: Chain.h:46
const Segment & dt::Chain::LastSeg ( ) const

Definition at line 214 of file Chain.cxx.

References LastCand(), and dt::Cand::LastSeg().

Referenced by Truncate().

215  {
216  return LastCand().LastSeg();
217  }
const Segment & LastSeg() const
Definition: Cand.cxx:371
const Cand & LastCand() const
Definition: Chain.h:46
unsigned int dt::Chain::NCands ( ) const
inline

Definition at line 44 of file Chain.h.

44 {return fCands.size();}
std::list< Cand > fCands
Definition: Chain.h:80
int dt::Chain::NHitPlanes ( ) const

Definition at line 266 of file Chain.cxx.

References AllChunks(), make_goodruns_defs::chunks, getGoodRuns4SAM::n, and runNovaSAM::ret.

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

267  {
268  std::vector<Chunk> chunks = AllChunks();
269  int ret = 0;
270  for(unsigned int n = 0; n < chunks.size(); ++n)
271  if(!chunks[n].AllDead()) ++ret;
272 
273  return ret;
274  }
std::vector< Chunk > AllChunks() const
Definition: Chain.cxx:245
std::vector< rb::Track > dt::Chain::ToDebugTracks ( ) const

Definition at line 129 of file Chain.cxx.

References fCands, and runNovaSAM::ret.

130  {
131  std::vector<rb::Track> ret;
132 
133  for(std::list<Cand>::const_iterator candIt = fCands.begin();
134  candIt != fCands.end(); ++candIt){
135  ret.push_back(candIt->ToTrack());
136  }
137 
138  return ret;
139  }
std::list< Cand > fCands
Definition: Chain.h:80
rb::Track dt::Chain::ToTrack ( ) const

Definition at line 29 of file Chain.cxx.

References AllHits(), rb::Track::AppendTrajectoryPoint(), ana::assert(), dt::Chunk::BottomHitCell(), make_associated_cosmic_defs::chunk, geo::GeometryBase::DetLength(), dir, dz, e, allTimeWatchdog::endl, ExtentPlane(), fCands, FirstCand(), dt::Cand::FirstChunk(), geom(), makeTrainCVSamples::int, std::max(), std::min(), getGoodRuns4SAM::n, PandAna.Demos.pi0_spectra::p0, plot_validation_datamc::p1, dt::Chunk::Plane(), geo::GeometryBase::Plane(), gen_flatrecord::size, fillBadChanDBTables::step, dt::Chunk::TopHitCell(), make_root_from_grid_output::tr, POTSpillRate::view, dt::Cand::View(), ana::weight, y1, submit_syst::y2, test::z, and Z.

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

30  {
32 
33  // Special case for vertical cands (who'll otherwise estimate themselves
34  // arbitrarily at a slope depending if they're marked "up" or "down").
35  if(ExtentPlane() == 0 && AllHits().size() > 1){
36  const Chunk& chunk = FirstCand().FirstChunk();
37  double xyz0[3];
38  geom->Plane(chunk.Plane())->Cell(chunk.TopHitCell())->GetCenter(xyz0);
39  double xyz1[3];
40  geom->Plane(chunk.Plane())->Cell(chunk.BottomHitCell())->GetCenter(xyz1);
41 
44  xyz0[view], xyz0[2],
45  xyz1[view]-xyz0[view], xyz1[2]-xyz0[2]);
46 
47  tr.AppendTrajectoryPoint(xyz1[view], xyz1[2]);
48  return tr;
49  }
50 
51  // The algorithm is to take the weighted average of the y-positions of all
52  // relevant candidates at each z-position. (Convention is that the non-z
53  // coordinate is called "y").
54 
55  // Estimate the start and end points of all the component cands upfront
56  std::vector<TVector3> p0s, p1s;
57  for(std::list<Cand>::const_iterator candIt = fCands.begin();
58  candIt != fCands.end(); ++candIt){
59  double z1, y1, z2, y2;
60  candIt->EstimateStraightLine(z1, y1, z2, y2);
61  p0s.push_back(TVector3(0, y1, z1));
62  p1s.push_back(TVector3(0, y2, z2));
63  }
64 
65  std::vector<TVector3> pts;
66 
67  // TODO, figure out where -1e10 Z's come from
68  const double minZ = std::max(0., p0s[0].Z());
69  const double maxZ = std::min(p1s.back().Z(), geom->DetLength());
70 
71  const double kZStep = 5; // cm
72  const int stepMax = int((maxZ-minZ)/kZStep);
73 
74  for(int step = 0; step <= stepMax; ++step){
75  const double z = minZ+(double(step)/stepMax)*(maxZ-minZ);
76 
77  TVector3 meanp;
78  double totweight = 0;
79 
80  for(unsigned int pIdx = 0; pIdx < p0s.size(); ++pIdx){
81  const TVector3& p0 = p0s[pIdx];
82  const TVector3& p1 = p1s[pIdx];
83  const double dz = p1.Z()-p0.Z();
84 
85  const TVector3 p = p0*((p1.Z()-z)/dz) + p1*((z-p0.Z())/dz);
86 
87  // Give more weight to cands near their centres
88  double weight = (z-p0.Z())/dz;
89  if(weight > 0.5) weight = 1-weight;
90  weight += 1e-3; // Avoid zeros at very ends
91  if(weight < 0) continue;
92 
93  meanp += p*weight;
94  totweight += weight;
95  }
96 
97  // This can happen when two cands are connected because they intersect at
98  // a shallow angle inside a large dead region. There's probably a neater
99  // way to illustrate this in the trajectory, but it's rare, so this will
100  // do.
101  if(totweight == 0) continue; // No cands cover this range
102 
103  meanp *= 1/totweight;
104 
105  pts.push_back(meanp);
106  } // end for step
107 
108  // TODO
109  // assert(pts.size() >= 2);
110  assert(!pts.empty());
111  if(pts.size() == 1){
112  mf::LogWarning("DiscreteTracker") << "Only one trajectory point. Fabricating a second one." << std::endl;
113  pts.push_back(pts[0]+TVector3(0, 0, 1));
114  }
115 
116  const TVector3 dir = pts[1]-pts[0];
117 
118  rb::Track tr(AllHits(),
119  fCands.begin()->View(),
120  pts[0].Y(), pts[0].Z(), dir.Y(), dir.Z());
121 
122  for(unsigned int n = 1; n < pts.size(); ++n)
123  tr.AppendTrajectoryPoint(pts[n].Y(), pts[n].Z());
124 
125  return tr;
126  }
T max(const caf::Proxy< T > &a, T b)
Float_t y1[n_points_granero]
Definition: compare.C:5
const Var weight
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
const char * p
Definition: xmltok.h:285
double DetLength() const
geo::View_t View() const
Definition: Cand.h:40
A rb::Prong with full reconstructed trajectory.
Definition: Track.h:20
const Chunk & FirstChunk() const
Definition: Cand.cxx:353
const PlaneGeo * Plane(unsigned int i) const
Float_t Z
Definition: plot.C:38
double dz[NP][NC]
Definition: View.py:1
z
Definition: test.py:28
art::PtrVector< rb::CellHit > AllHits() const
Definition: Chain.cxx:220
TDirectory * dir
Definition: macro.C:5
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
void geom(int which=0)
Definition: geom.C:163
assert(nhit_max >=nhit_nbins)
unsigned int ExtentPlane() const
Definition: Chain.h:43
const Cand & FirstCand() const
Definition: Chain.h:45
T min(const caf::Proxy< T > &a, T b)
Float_t e
Definition: plot.C:35
std::list< Cand > fCands
Definition: Chain.h:80
void dt::Chain::TrimEnds ( )

Remove Cands that add no actual hits. After building but before writing.

Definition at line 277 of file Chain.cxx.

References AllHits(), ana::assert(), fCands, and art::PtrVector< T >::size().

Referenced by dt::DiscreteTracker::RecoDiscrete(), and Truncate().

278  {
279  const unsigned int origSize = AllHits().size();
280 
281  assert(origSize > 0);
282 
283  while(true){
284  const Cand cand = fCands.front();
285  fCands.pop_front();
286  if(fCands.empty() || AllHits().size() < origSize){
287  fCands.push_front(cand);
288  break;
289  }
290  }
291 
292  while(true){
293  const Cand cand = fCands.back();
294  fCands.pop_back();
295  if(fCands.empty() || AllHits().size() < origSize){
296  fCands.push_back(cand);
297  break;
298  }
299  }
300 
301  fCands.front().TrimFront();
302  fCands.back().TrimBack();
303  }
size_type size() const
Definition: PtrVector.h:308
art::PtrVector< rb::CellHit > AllHits() const
Definition: Chain.cxx:220
assert(nhit_max >=nhit_nbins)
std::list< Cand > fCands
Definition: Chain.h:80
void dt::Chain::Truncate ( unsigned int  plane,
Direction  end 
)

Definition at line 306 of file Chain.cxx.

References AllChunks(), AllHits(), fCands, FirstCand(), FirstPlane(), FirstSeg(), dt::kUpstream, LastCand(), LastPlane(), LastSeg(), and TrimEnds().

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

307  {
308  if(end == kUpstream){
309  while(FirstPlane() < plane){
310  fCands.begin()->PopFirstChunk();
311  if(FirstCand().AllChunks().empty()) fCands.pop_front();
312  }
313  while(FirstSeg().plane < int(plane)){
314  if(fCands.begin()->NSegs() > 1)
315  fCands.begin()->PopFirstSeg();
316  else
317  fCands.pop_front();
318  }
319  }
320  else{
321  while(LastPlane() > plane){
322  fCands.rbegin()->PopLastChunk();
323  if(LastCand().AllChunks().empty()) fCands.pop_back();
324  }
325  while(LastSeg().plane > int(plane)){
326  if(fCands.rbegin()->NSegs() > 1)
327  fCands.rbegin()->PopLastSeg();
328  else
329  fCands.pop_back();
330  }
331  }
332 
333  if(!AllHits().empty()) TrimEnds();
334  }
const Segment & FirstSeg() const
Definition: Chain.cxx:208
unsigned int FirstPlane() const
Definition: Chain.cxx:167
unsigned int LastPlane() const
Definition: Chain.cxx:173
std::vector< Chunk > AllChunks() const
Definition: Chain.cxx:245
const Segment & LastSeg() const
Definition: Chain.cxx:214
art::PtrVector< rb::CellHit > AllHits() const
Definition: Chain.cxx:220
void TrimEnds()
Remove Cands that add no actual hits. After building but before writing.
Definition: Chain.cxx:277
const Cand & FirstCand() const
Definition: Chain.h:45
const Cand & LastCand() const
Definition: Chain.h:46
std::list< Cand > fCands
Definition: Chain.h:80

Member Data Documentation

std::list<Cand> dt::Chain::fCands
protected

Definition at line 80 of file Chain.h.

Referenced by Add(), AddFront(), AllChunks(), AllHits(), ToDebugTracks(), ToTrack(), TrimEnds(), and Truncate().


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