LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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 (detinfo::DetectorPropertiesData const &detProp)
 
const pma::TrkCandidateCollresult ()
 
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 () const
 

Protected Member Functions

void guideEndpoints (detinfo::DetectorPropertiesData const &detProp, 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 (detinfo::DetectorPropertiesData const &detProp)
 
void buildShowers (detinfo::DetectorPropertiesData const &detProp)
 
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 96 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 101 of file PMAlgTracking.cxx.

References fCluHits, fPfpClusters, fPfpPdgCodes, and fPfpVtx.

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

Member Function Documentation

int pma::PMAlgFitter::build ( detinfo::DetectorPropertiesData const &  detProp)

Definition at line 147 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().

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

Definition at line 226 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(), util::size(), and pma::TrkCandidate::Track().

Referenced by build().

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

Definition at line 171 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(), util::size(), and pma::TrkCandidate::Track().

Referenced by build().

172 {
173  bool skipPdg = true;
174  if (!fTrackingSkipPdg.empty() && (fTrackingSkipPdg.front() == 0)) skipPdg = false;
175 
176  bool selectPdg = true;
177  if (!fTrackingOnlyPdg.empty() && (fTrackingOnlyPdg.front() == 0)) selectPdg = false;
178 
179  for (const auto& pfpCluEntry : fPfpClusters) {
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  if (c->NHits() == 0) { continue; }
195 
196  candidate.Clusters().push_back(c.key());
197  clu_count[c->View()]++;
198 
199  allHits.reserve(allHits.size() + fCluHits.at(c.key()).size());
200  for (const auto& h : fCluHits.at(c.key())) {
201  allHits.push_back(h);
202  }
203  }
204  if (clu_count.size() > 1) // try building only if there are clusters from multiple views
205  {
206  candidate.SetKey(pfpCluEntry.first);
207 
208  candidate.SetTrack(fProjectionMatchingAlg.buildMultiTPCTrack(detProp, allHits));
209 
210  if (candidate.IsValid() && candidate.Track()->HasTwoViews() &&
211  (candidate.Track()->Nodes().size() > 1)) {
212  if (!std::isnan(candidate.Track()->Length())) { fResult.push_back(candidate); }
213  else {
214  mf::LogError("PMAlgFitter") << "Trajectory fit lenght is nan.";
215  candidate.DeleteTrack();
216  }
217  }
218  else {
219  candidate.DeleteTrack();
220  }
221  }
222  }
223 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
bool IsValid() const
void SetKey(int key)
Set key of an external object associated to this track candidate.
void SetTrack(pma::Track3D *trk)
std::map< int, std::vector< art::Ptr< recob::Cluster > > > fPfpClusters
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
std::vector< int > fTrackingOnlyPdg
std::map< int, int > fPfpPdgCodes
std::vector< int > fTrackingSkipPdg
pma::ProjectionMatchingAlg fProjectionMatchingAlg
Definition: PMAlgTracking.h:90
bool has(const std::vector< int > &v, int i) const
std::vector< std::vector< art::Ptr< recob::Hit > > > fCluHits
bool HasTwoViews(size_t nmin=1) const
Definition: PmaTrack3D.cxx:439
double Length(size_t step=1) const
Definition: PmaTrack3D.h:94
const std::vector< size_t > & Clusters() const
std::vector< pma::Node3D * > const & Nodes() const noexcept
Definition: PmaTrack3D.h:274
pma::TrkCandidateColl fResult
Definition: PMAlgTracking.h:93
pma::Track3D * Track() const
void push_back(const TrkCandidate &trk)
pma::Track3D * buildMultiTPCTrack(const detinfo::DetectorPropertiesData &clockData, const std::vector< art::Ptr< recob::Hit >> &hits) const
std::vector<std::pair<TVector3, size_t> > pma::PMAlgTrackingBase::getKinks ( ) const
inlineinherited

Definition at line 74 of file PMAlgTracking.h.

References lar::dump::vector().

75  {
77  }
std::vector< std::pair< TVector3, size_t > > getKinks(const pma::TrkCandidateColl &tracks) const
pma::TrkCandidateColl fResult
Definition: PMAlgTracking.h:93
pma::PMAlgVertexing fPMAlgVertexing
Definition: PMAlgTracking.h:91
std::vector<std::pair<TVector3, std::vector<std::pair<size_t, bool> > > > pma::PMAlgTrackingBase::getVertices ( bool  onlyBranching = false) const
inlineinherited

Definition at line 68 of file PMAlgTracking.h.

70  {
71  return fPMAlgVertexing.getVertices(fResult, onlyBranching);
72  }
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:93
pma::PMAlgVertexing fPMAlgVertexing
Definition: PMAlgTracking.h:91
void pma::PMAlgTrackingBase::guideEndpoints ( detinfo::DetectorPropertiesData const &  detProp,
pma::TrkCandidateColl tracks 
)
protectedinherited

Definition at line 79 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(), and pma::PMAlgTracker::build().

81 {
82  for (auto const& t : tracks.tracks()) {
83  auto& trk = *(t.Track());
84 
85  unsigned int tpc = trk.FrontTPC(), cryo = trk.FrontCryo();
86  if ((tpc == trk.BackTPC()) && (cryo == trk.BackCryo())) {
87  fProjectionMatchingAlg.guideEndpoints(detProp, trk, fHitMap[cryo][tpc]);
88  }
89  else {
91  detProp, trk, pma::Track3D::kBegin, fHitMap[trk.FrontCryo()][trk.FrontTPC()]);
93  detProp, trk, pma::Track3D::kEnd, fHitMap[trk.BackCryo()][trk.BackTPC()]);
94  }
95  }
96 }
pma::ProjectionMatchingAlg fProjectionMatchingAlg
Definition: PMAlgTracking.h:90
void guideEndpoints(const detinfo::DetectorPropertiesData &clockData, pma::Track3D &trk, const std::map< unsigned int, std::vector< art::Ptr< recob::Hit >>> &hits) const
std::vector< TrkCandidate > const & tracks() const
pma::cryo_tpc_view_hitmap fHitMap
Definition: PMAlgTracking.h:88
bool pma::PMAlgFitter::has ( const std::vector< int > &  v,
int  i 
) const
inlineprivate

Definition at line 134 of file PMAlgTracking.h.

Referenced by buildShowers(), and buildTracks().

135  {
136  for (auto c : v) {
137  if (c == i) return true;
138  }
139  return false;
140  }
const pma::TrkCandidateColl& pma::PMAlgTrackingBase::result ( )
inlineinherited

Member Data Documentation

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

Definition at line 142 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 143 of file PMAlgTracking.h.

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

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

Definition at line 145 of file PMAlgTracking.h.

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

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

Definition at line 144 of file PMAlgTracking.h.

Referenced by buildShowers(), and PMAlgFitter().

pma::PMAlgVertexing pma::PMAlgTrackingBase::fPMAlgVertexing
protectedinherited

Definition at line 91 of file PMAlgTracking.h.

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

bool pma::PMAlgFitter::fRunVertexing
private

Definition at line 152 of file PMAlgTracking.h.

Referenced by build().

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

Definition at line 148 of file PMAlgTracking.h.

Referenced by buildShowers(), and buildTracks().

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

Definition at line 150 of file PMAlgTracking.h.

Referenced by buildShowers(), and buildTracks().


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