LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
pma::PMAlgFitter Class Reference

#include "PMAlgTracking.h"

Inheritance diagram for pma::PMAlgFitter:
pma::PMAlgTrackingBase

Classes

struct  Config
 

Public Member Functions

 PMAlgFitter (const std::vector< art::Ptr< recob::Hit > > &allhitlist, const std::vector< recob::Cluster > &clusters, const std::vector< recob::PFParticle > &pfparticles, const art::FindManyP< recob::Hit > &hitsFromClusters, const art::FindManyP< recob::Cluster > &clusFromPfps, const art::FindManyP< recob::Vertex > &vtxFromPfps, const pma::ProjectionMatchingAlg::Config &pmalgConfig, const pma::PMAlgFitter::Config &pmalgFitterConfig, const pma::PMAlgVertexing::Config &pmvtxConfig)
 
int build (void)
 
const pma::TrkCandidateCollresult (void)
 
std::vector< std::pair< TVector3, std::vector< std::pair< size_t, bool > > > > getVertices (bool onlyBranching=false) const
 
std::vector< std::pair< TVector3, size_t > > getKinks (void) const
 

Protected Member Functions

void guideEndpoints (pma::TrkCandidateColl &tracks)
 

Protected Attributes

pma::cryo_tpc_view_hitmap fHitMap
 
pma::ProjectionMatchingAlg fProjectionMatchingAlg
 
pma::PMAlgVertexing fPMAlgVertexing
 
pma::TrkCandidateColl fResult
 

Private Member Functions

void buildTracks (void)
 
void buildShowers (void)
 
bool has (const std::vector< int > &v, int i) const
 

Private Attributes

std::vector< std::vector< art::Ptr< recob::Hit > > > fCluHits
 
std::map< int, std::vector< art::Ptr< recob::Cluster > > > fPfpClusters
 
std::map< int, pma::Vector3DfPfpVtx
 
std::map< int, int > fPfpPdgCodes
 
std::vector< int > fTrackingOnlyPdg
 
std::vector< int > fTrackingSkipPdg
 
bool fRunVertexing
 

Detailed Description

Definition at line 86 of file PMAlgTracking.h.

Constructor & Destructor Documentation

pma::PMAlgFitter::PMAlgFitter ( const std::vector< art::Ptr< recob::Hit > > &  allhitlist,
const std::vector< recob::Cluster > &  clusters,
const std::vector< recob::PFParticle > &  pfparticles,
const art::FindManyP< recob::Hit > &  hitsFromClusters,
const art::FindManyP< recob::Cluster > &  clusFromPfps,
const art::FindManyP< recob::Vertex > &  vtxFromPfps,
const pma::ProjectionMatchingAlg::Config pmalgConfig,
const pma::PMAlgFitter::Config pmalgFitterConfig,
const pma::PMAlgVertexing::Config pmvtxConfig 
)

Definition at line 94 of file PMAlgTracking.cxx.

References fCluHits, fPfpClusters, fPfpPdgCodes, and fPfpVtx.

102  :
103  PMAlgTrackingBase(allhitlist, pmalgConfig, pmvtxConfig),
104  fTrackingOnlyPdg(pmalgFitterConfig.TrackingOnlyPdg()),
105  fTrackingSkipPdg(pmalgFitterConfig.TrackingSkipPdg()),
106  fRunVertexing(pmalgFitterConfig.RunVertexing())
107 {
108  mf::LogVerbatim("PMAlgFitter") << "Found " << allhitlist.size() << "hits in the event.";
109  mf::LogVerbatim("PMAlgFitter") << "Sort hits by clusters assigned to PFParticles...";
110 
111  fCluHits.resize(clusters.size());
112  for (size_t i = 0; i < pfparticles.size(); ++i)
113  {
114  fPfpPdgCodes[i] = pfparticles[i].PdgCode();
115 
116  auto cv = clusFromPfps.at(i);
117  for (const auto & c : cv)
118  {
119  fPfpClusters[i].push_back(c);
120  if (fCluHits[c.key()].empty())
121  {
122  auto hv = hitsFromClusters.at(c.key());
123  fCluHits[c.key()].reserve(hv.size());
124  for (auto const & h : hv) fCluHits[c.key()].push_back(h);
125  }
126  }
127 
128  if (vtxFromPfps.isValid() && vtxFromPfps.at(i).size())
129  {
130  double xyz[3];
131  vtxFromPfps.at(i).front()->XYZ(xyz);
132  fPfpVtx[i] = pma::Vector3D(xyz[0], xyz[1], xyz[2]);
133  }
134  }
135 
136  mf::LogVerbatim("PMAlgFitter") << "...done, "
137  << fCluHits.size() << " clusters from "
138  << fPfpClusters.size() << " pfparticles for 3D tracking.";
139 }
std::vector< std::vector< art::Ptr< recob::Hit > > > fCluHits
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
fhicl::Sequence< int > TrackingSkipPdg
Definition: PMAlgTracking.h:99
fhicl::Sequence< int > TrackingOnlyPdg
Definition: PMAlgTracking.h:94
recob::tracking::Vector_t Vector3D
Definition: Utilities.h:29
std::map< int, pma::Vector3D > fPfpVtx
std::vector< int > fTrackingOnlyPdg
fhicl::Atom< bool > RunVertexing
std::vector< int > fTrackingSkipPdg
std::map< int, int > fPfpPdgCodes
PMAlgTrackingBase(const std::vector< art::Ptr< recob::Hit > > &allhitlist, const pma::ProjectionMatchingAlg::Config &pmalgConfig, const pma::PMAlgVertexing::Config &pmvtxConfig)
std::map< int, std::vector< art::Ptr< recob::Cluster > > > fPfpClusters

Member Function Documentation

int pma::PMAlgFitter::build ( void  )

Definition at line 144 of file PMAlgTracking.cxx.

References buildShowers(), buildTracks(), fCluHits, fPfpClusters, pma::PMAlgTrackingBase::fPMAlgVertexing, pma::PMAlgTrackingBase::fResult, fRunVertexing, pma::PMAlgTrackingBase::guideEndpoints(), pma::PMAlgVertexing::run(), and pma::TrkCandidateColl::size().

145 {
146  if (!fPfpClusters.empty() && !fCluHits.empty())
147  {
148  // build pm tracks
149  buildTracks();
150 
151  // add 3D ref.points for clean endpoints of wire-plae parallel tracks
153 
155 
156  // build segment of shower
157  buildShowers();
158  }
159  else
160  {
161  mf::LogWarning("PMAlgFitter") << "no clusters, no pfparticles";
162  return -1;
163  }
164 
165  return fResult.size();
166 }
std::vector< std::vector< art::Ptr< recob::Hit > > > fCluHits
void buildTracks(void)
size_t size(void) const
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
void guideEndpoints(pma::TrkCandidateColl &tracks)
void buildShowers(void)
pma::TrkCandidateColl fResult
Definition: PMAlgTracking.h:82
size_t run(pma::TrkCandidateColl &trk_input)
pma::PMAlgVertexing fPMAlgVertexing
Definition: PMAlgTracking.h:80
std::map< int, std::vector< art::Ptr< recob::Cluster > > > fPfpClusters
void pma::PMAlgFitter::buildShowers ( void  )
private

Definition at line 229 of file PMAlgTracking.cxx.

References pma::ProjectionMatchingAlg::buildShowerSeg(), pma::TrkCandidate::Clusters(), pma::TrkCandidate::DeleteTrack(), fCluHits, fPfpClusters, fPfpPdgCodes, fPfpVtx, pma::PMAlgTrackingBase::fProjectionMatchingAlg, pma::PMAlgTrackingBase::fResult, fTrackingOnlyPdg, fTrackingSkipPdg, has(), pma::Track3D::HasTwoViews(), pma::TrkCandidate::IsValid(), pma::Track3D::Length(), pma::Track3D::Nodes(), pma::TrkCandidateColl::push_back(), pma::TrkCandidate::SetKey(), pma::TrkCandidate::SetTrack(), and pma::TrkCandidate::Track().

Referenced by build().

230 {
231  bool skipPdg = true;
232  if (!fTrackingSkipPdg.empty() && (fTrackingSkipPdg.front() == 0))
233  skipPdg = false;
234 
235  bool selectPdg = true;
236  if (!fTrackingOnlyPdg.empty() && (fTrackingOnlyPdg.front() == 0))
237  selectPdg = false;
238 
239  for (const auto & pfpCluEntry : fPfpClusters)
240  {
241  int pfPartIdx = pfpCluEntry.first;
242  int pdg = fPfpPdgCodes[pfPartIdx];
243 
244  if (pdg != 11) continue;
245  if (skipPdg && has(fTrackingSkipPdg, pdg)) continue;
246  if (selectPdg && !has(fTrackingOnlyPdg, pdg)) continue;
247 
248  mf::LogVerbatim("PMAlgFitter") << "Process clusters from PFP:" << pfPartIdx << ", pdg:" << pdg;
249 
250  std::vector< art::Ptr<recob::Hit> > allHits;
251 
252  pma::TrkCandidate candidate;
253  std::unordered_map<geo::View_t, size_t> clu_count;
254  for (const auto & c : pfpCluEntry.second)
255  {
256  if (c->NHits() == 0) { continue; }
257 
258  candidate.Clusters().push_back(c.key());
259  clu_count[c->View()]++;
260 
261  allHits.reserve(allHits.size() + fCluHits.at(c.key()).size());
262  for (const auto & h : fCluHits.at(c.key()))
263  allHits.push_back(h);
264  }
265  if (clu_count.size() > 1) // try building only if there are clusters from multiple views
266  {
267  candidate.SetKey(pfpCluEntry.first);
268 
269  mf::LogVerbatim("PMAlgFitter") << "building..." << ", pdg:" << pdg;
270 
271  auto search = fPfpVtx.find(pfPartIdx);
272  if (search != fPfpVtx.end())
273  {
274  candidate.SetTrack(fProjectionMatchingAlg.buildShowerSeg(allHits, search->second));
275 
276  if (candidate.IsValid()
277  && candidate.Track()->HasTwoViews()
278  && (candidate.Track()->Nodes().size() > 1)
279  && !std::isnan(candidate.Track()->Length()))
280  {
281  fResult.push_back(candidate);
282  }
283  else { candidate.DeleteTrack(); }
284  }
285  }
286  }
287 }
pma::Track3D * buildShowerSeg(const std::vector< art::Ptr< recob::Hit > > &hits, const pma::Vector3D &vtx) const
Build a shower segment from sets of hits and attached to the provided vertex.
const std::vector< size_t > & Clusters(void) const
std::vector< std::vector< art::Ptr< recob::Hit > > > fCluHits
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
void SetKey(int key)
Set key of an external object associated to this track candidate.
std::vector< pma::Node3D * > const & Nodes(void) const
Definition: PmaTrack3D.h:232
void SetTrack(pma::Track3D *trk)
std::map< int, pma::Vector3D > fPfpVtx
bool IsValid(void) const
std::vector< int > fTrackingOnlyPdg
std::vector< int > fTrackingSkipPdg
pma::ProjectionMatchingAlg fProjectionMatchingAlg
Definition: PMAlgTracking.h:79
std::map< int, int > fPfpPdgCodes
bool has(const std::vector< int > &v, int i) const
bool HasTwoViews(size_t nmin=1) const
Definition: PmaTrack3D.cxx:428
double Length(size_t step=1) const
Definition: PmaTrack3D.h:81
pma::TrkCandidateColl fResult
Definition: PMAlgTracking.h:82
void push_back(const TrkCandidate &trk)
pma::Track3D * Track(void) const
std::map< int, std::vector< art::Ptr< recob::Cluster > > > fPfpClusters
void pma::PMAlgFitter::buildTracks ( void  )
private

Definition at line 170 of file PMAlgTracking.cxx.

References pma::ProjectionMatchingAlg::buildMultiTPCTrack(), pma::TrkCandidate::Clusters(), pma::TrkCandidate::DeleteTrack(), fCluHits, fPfpClusters, fPfpPdgCodes, pma::PMAlgTrackingBase::fProjectionMatchingAlg, pma::PMAlgTrackingBase::fResult, fTrackingOnlyPdg, fTrackingSkipPdg, has(), pma::Track3D::HasTwoViews(), pma::TrkCandidate::IsValid(), pma::Track3D::Length(), pma::Track3D::Nodes(), pma::TrkCandidateColl::push_back(), pma::TrkCandidate::SetKey(), pma::TrkCandidate::SetTrack(), and pma::TrkCandidate::Track().

Referenced by build().

171 {
172  bool skipPdg = true;
173  if (!fTrackingSkipPdg.empty() && (fTrackingSkipPdg.front() == 0)) skipPdg = false;
174 
175  bool selectPdg = true;
176  if (!fTrackingOnlyPdg.empty() && (fTrackingOnlyPdg.front() == 0)) selectPdg = false;
177 
178  for (const auto & pfpCluEntry : fPfpClusters)
179  {
180  int pfPartIdx = pfpCluEntry.first;
181  int pdg = fPfpPdgCodes[pfPartIdx];
182 
183  //if (pdg == 11) continue;
184  if (skipPdg && has(fTrackingSkipPdg, pdg)) continue;
185  if (selectPdg && !has(fTrackingOnlyPdg, pdg)) continue;
186 
187  mf::LogVerbatim("PMAlgFitter") << "Process clusters from PFP:" << pfPartIdx << ", pdg:" << pdg;
188 
189  std::vector< art::Ptr<recob::Hit> > allHits;
190 
191  pma::TrkCandidate candidate;
192  std::unordered_map<geo::View_t, size_t> clu_count;
193  for (const auto & c : pfpCluEntry.second)
194  {
195  if (c->NHits() == 0) { continue; }
196 
197  candidate.Clusters().push_back(c.key());
198  clu_count[c->View()]++;
199 
200  allHits.reserve(allHits.size() + fCluHits.at(c.key()).size());
201  for (const auto & h : fCluHits.at(c.key()))
202  {
203  allHits.push_back(h);
204  }
205  }
206  if (clu_count.size() > 1) // try building only if there are clusters from multiple views
207  {
208  candidate.SetKey(pfpCluEntry.first);
209 
211 
212  if (candidate.IsValid() &&
213  candidate.Track()->HasTwoViews() &&
214  (candidate.Track()->Nodes().size() > 1))
215  {
216  if (!std::isnan(candidate.Track()->Length())) { fResult.push_back(candidate); }
217  else
218  {
219  mf::LogError("PMAlgFitter") << "Trajectory fit lenght is nan.";
220  candidate.DeleteTrack();
221  }
222  }
223  else { candidate.DeleteTrack(); }
224  }
225  }
226 }
const std::vector< size_t > & Clusters(void) const
std::vector< std::vector< art::Ptr< recob::Hit > > > fCluHits
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
void SetKey(int key)
Set key of an external object associated to this track candidate.
std::vector< pma::Node3D * > const & Nodes(void) const
Definition: PmaTrack3D.h:232
void SetTrack(pma::Track3D *trk)
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
pma::Track3D * buildMultiTPCTrack(const std::vector< art::Ptr< recob::Hit > > &hits) const
as far as hits origin from at least two wire planes.
bool IsValid(void) const
std::vector< int > fTrackingOnlyPdg
std::vector< int > fTrackingSkipPdg
pma::ProjectionMatchingAlg fProjectionMatchingAlg
Definition: PMAlgTracking.h:79
std::map< int, int > fPfpPdgCodes
bool has(const std::vector< int > &v, int i) const
bool HasTwoViews(size_t nmin=1) const
Definition: PmaTrack3D.cxx:428
double Length(size_t step=1) const
Definition: PmaTrack3D.h:81
pma::TrkCandidateColl fResult
Definition: PMAlgTracking.h:82
void push_back(const TrkCandidate &trk)
pma::Track3D * Track(void) const
std::map< int, std::vector< art::Ptr< recob::Cluster > > > fPfpClusters
std::vector< std::pair< TVector3, size_t > > pma::PMAlgTrackingBase::getKinks ( void  ) const
inlineinherited
std::vector< std::pair< TVector3, std::vector< std::pair< size_t, bool > > > > pma::PMAlgTrackingBase::getVertices ( bool  onlyBranching = false) const
inlineinherited

Definition at line 62 of file PMAlgTracking.h.

References pma::PMAlgTrackingBase::fPMAlgVertexing, pma::PMAlgTrackingBase::fResult, and pma::PMAlgVertexing::getVertices().

63  { return fPMAlgVertexing.getVertices(fResult, onlyBranching); }
std::vector< std::pair< TVector3, std::vector< std::pair< size_t, bool > > > > getVertices(const pma::TrkCandidateColl &tracks, bool onlyBranching=false) const
pma::TrkCandidateColl fResult
Definition: PMAlgTracking.h:82
pma::PMAlgVertexing fPMAlgVertexing
Definition: PMAlgTracking.h:80
void pma::PMAlgTrackingBase::guideEndpoints ( pma::TrkCandidateColl tracks)
protectedinherited

Definition at line 70 of file PMAlgTracking.cxx.

References pma::PMAlgTrackingBase::fHitMap, pma::PMAlgTrackingBase::fProjectionMatchingAlg, pma::ProjectionMatchingAlg::guideEndpoints(), pma::Track3D::kBegin, pma::Track3D::kEnd, and pma::TrkCandidateColl::tracks().

Referenced by build(), pma::PMAlgTracker::build(), and pma::PMAlgTrackingBase::getKinks().

71 {
72  for (auto const & t : tracks.tracks())
73  {
74  auto & trk = *(t.Track());
75 
76  unsigned int tpc = trk.FrontTPC(), cryo = trk.FrontCryo();
77  if ((tpc == trk.BackTPC()) && (cryo == trk.BackCryo()))
78  {
80  }
81  else
82  {
84  fHitMap[trk.FrontCryo()][trk.FrontTPC()]);
86  fHitMap[trk.BackCryo()][trk.BackTPC()]);
87  }
88  }
89 }
void guideEndpoints(pma::Track3D &trk, const std::map< unsigned int, std::vector< art::Ptr< recob::Hit > > > &hits) const
Add 3D reference points to clean endpoints of a track (both need to be in the same TPC)...
std::vector< TrkCandidate > const & tracks(void) const
pma::ProjectionMatchingAlg fProjectionMatchingAlg
Definition: PMAlgTracking.h:79
pma::cryo_tpc_view_hitmap fHitMap
Definition: PMAlgTracking.h:77
bool pma::PMAlgFitter::has ( const std::vector< int > &  v,
int  i 
) const
inlineprivate

Definition at line 127 of file PMAlgTracking.h.

Referenced by buildShowers(), and buildTracks().

128  {
129  for (auto c : v) { if (c == i) return true; }
130  return false;
131  }

Member Data Documentation

std::vector< std::vector< art::Ptr<recob::Hit> > > pma::PMAlgFitter::fCluHits
private

Definition at line 133 of file PMAlgTracking.h.

Referenced by build(), buildShowers(), buildTracks(), and PMAlgFitter().

pma::cryo_tpc_view_hitmap pma::PMAlgTrackingBase::fHitMap
protectedinherited
std::map< int, std::vector< art::Ptr<recob::Cluster> > > pma::PMAlgFitter::fPfpClusters
private

Definition at line 134 of file PMAlgTracking.h.

Referenced by build(), buildShowers(), buildTracks(), and PMAlgFitter().

std::map< int, int > pma::PMAlgFitter::fPfpPdgCodes
private

Definition at line 136 of file PMAlgTracking.h.

Referenced by buildShowers(), buildTracks(), and PMAlgFitter().

std::map< int, pma::Vector3D > pma::PMAlgFitter::fPfpVtx
private

Definition at line 135 of file PMAlgTracking.h.

Referenced by buildShowers(), and PMAlgFitter().

pma::PMAlgVertexing pma::PMAlgTrackingBase::fPMAlgVertexing
protectedinherited
bool pma::PMAlgFitter::fRunVertexing
private

Definition at line 141 of file PMAlgTracking.h.

Referenced by build().

std::vector<int> pma::PMAlgFitter::fTrackingOnlyPdg
private

Definition at line 139 of file PMAlgTracking.h.

Referenced by buildShowers(), and buildTracks().

std::vector<int> pma::PMAlgFitter::fTrackingSkipPdg
private

Definition at line 140 of file PMAlgTracking.h.

Referenced by buildShowers(), and buildTracks().


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