Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
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)
 
- Public Member Functions inherited from pma::PMAlgTrackingBase
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
 

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
 

Additional Inherited Members

- Protected Member Functions inherited from pma::PMAlgTrackingBase
 PMAlgTrackingBase (const std::vector< art::Ptr< recob::Hit >> &allhitlist, const pma::ProjectionMatchingAlg::Config &pmalgConfig, const pma::PMAlgVertexing::Config &pmvtxConfig)
 
 ~PMAlgTrackingBase ()
 
void guideEndpoints (detinfo::DetectorPropertiesData const &detProp, pma::TrkCandidateColl &tracks)
 
- Protected Attributes inherited from pma::PMAlgTrackingBase
pma::cryo_tpc_view_hitmap fHitMap
 
pma::ProjectionMatchingAlg fProjectionMatchingAlg
 
pma::PMAlgVertexing fPMAlgVertexing
 
pma::TrkCandidateColl fResult
 

Detailed Description

Definition at line 95 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 103 of file PMAlgTracking.cxx.

112  : PMAlgTrackingBase(allhitlist, pmalgConfig, pmvtxConfig)
113  , fTrackingOnlyPdg(pmalgFitterConfig.TrackingOnlyPdg())
114  , fTrackingSkipPdg(pmalgFitterConfig.TrackingSkipPdg())
115  , fRunVertexing(pmalgFitterConfig.RunVertexing())
116 {
117  mf::LogVerbatim("PMAlgFitter") << "Found " << allhitlist.size() << "hits in the event.";
118  mf::LogVerbatim("PMAlgFitter") << "Sort hits by clusters assigned to PFParticles...";
119 
120  fCluHits.resize(clusters.size());
121  for (size_t i = 0; i < pfparticles.size(); ++i) {
122  fPfpPdgCodes[i] = pfparticles[i].PdgCode();
123 
124  auto cv = clusFromPfps.at(i);
125  for (const auto& c : cv) {
126  fPfpClusters[i].push_back(c);
127  if (fCluHits[c.key()].empty()) {
128  auto hv = hitsFromClusters.at(c.key());
129  fCluHits[c.key()].reserve(hv.size());
130  for (auto const& h : hv)
131  fCluHits[c.key()].push_back(h);
132  }
133  }
134 
135  if (vtxFromPfps.isValid() && vtxFromPfps.at(i).size()) {
136  double xyz[3];
137  vtxFromPfps.at(i).front()->XYZ(xyz);
138  fPfpVtx[i] = pma::Vector3D(xyz[0], xyz[1], xyz[2]);
139  }
140  }
141 
142  mf::LogVerbatim("PMAlgFitter") << "...done, " << fCluHits.size() << " clusters from "
143  << fPfpClusters.size() << " pfparticles for 3D tracking.";
144 }
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:31
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 150 of file PMAlgTracking.cxx.

151 {
152  if (!fPfpClusters.empty() && !fCluHits.empty()) {
153  // build pm tracks
154  buildTracks(detProp);
155 
156  // add 3D ref.points for clean endpoints of wire-plae parallel tracks
157  guideEndpoints(detProp, fResult);
158 
159  if (fRunVertexing) fPMAlgVertexing.run(detProp, fResult);
160 
161  // build segment of shower
162  buildShowers(detProp);
163  }
164  else {
165  mf::LogWarning("PMAlgFitter") << "no clusters, no pfparticles";
166  return -1;
167  }
168 
169  return fResult.size();
170 }
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:92
pma::PMAlgVertexing fPMAlgVertexing
Definition: PMAlgTracking.h:90
void buildShowers(detinfo::DetectorPropertiesData const &detProp)
void pma::PMAlgFitter::buildShowers ( detinfo::DetectorPropertiesData const &  detProp)
private

Definition at line 231 of file PMAlgTracking.cxx.

232 {
233  bool skipPdg = true;
234  if (!fTrackingSkipPdg.empty() && (fTrackingSkipPdg.front() == 0)) skipPdg = false;
235 
236  bool selectPdg = true;
237  if (!fTrackingOnlyPdg.empty() && (fTrackingOnlyPdg.front() == 0)) selectPdg = false;
238 
239  for (const auto& pfpCluEntry : fPfpClusters) {
240  int pfPartIdx = pfpCluEntry.first;
241  int pdg = fPfpPdgCodes[pfPartIdx];
242 
243  if (pdg != 11) continue;
244  if (skipPdg && has(fTrackingSkipPdg, pdg)) continue;
245  if (selectPdg && !has(fTrackingOnlyPdg, pdg)) continue;
246 
247  mf::LogVerbatim("PMAlgFitter") << "Process clusters from PFP:" << pfPartIdx << ", pdg:" << pdg;
248 
249  std::vector<art::Ptr<recob::Hit>> allHits;
250 
251  pma::TrkCandidate candidate;
252  std::unordered_map<geo::View_t, size_t> clu_count;
253  for (const auto& c : pfpCluEntry.second) {
254  if (c->NHits() == 0) { continue; }
255 
256  candidate.Clusters().push_back(c.key());
257  clu_count[c->View()]++;
258 
259  allHits.reserve(allHits.size() + fCluHits.at(c.key()).size());
260  for (const auto& h : fCluHits.at(c.key()))
261  allHits.push_back(h);
262  }
263  if (clu_count.size() > 1) // try building only if there are clusters from multiple views
264  {
265  candidate.SetKey(pfpCluEntry.first);
266 
267  mf::LogVerbatim("PMAlgFitter") << "building..."
268  << ", pdg:" << pdg;
269 
270  auto search = fPfpVtx.find(pfPartIdx);
271  if (search != fPfpVtx.end()) {
272  candidate.SetTrack(fProjectionMatchingAlg.buildShowerSeg(detProp, allHits, search->second));
273 
274  if (candidate.IsValid() && candidate.Track()->HasTwoViews() &&
275  (candidate.Track()->Nodes().size() > 1) && !std::isnan(candidate.Track()->Length())) {
276  fResult.push_back(candidate);
277  }
278  else {
279  candidate.DeleteTrack();
280  }
281  }
282  }
283  }
284 }
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:92
std::vector< int > fTrackingOnlyPdg
std::map< int, int > fPfpPdgCodes
std::vector< int > fTrackingSkipPdg
pma::ProjectionMatchingAlg fProjectionMatchingAlg
Definition: PMAlgTracking.h:89
Definition: search.py:1
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:442
double Length(size_t step=1) const
Definition: PmaTrack3D.h:117
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:335
pma::TrkCandidateColl fResult
Definition: PMAlgTracking.h:92
pma::Track3D * Track() const
void push_back(const TrkCandidate &trk)
void pma::PMAlgFitter::buildTracks ( detinfo::DetectorPropertiesData const &  detProp)
private

Definition at line 175 of file PMAlgTracking.cxx.

176 {
177  bool skipPdg = true;
178  if (!fTrackingSkipPdg.empty() && (fTrackingSkipPdg.front() == 0)) skipPdg = false;
179 
180  bool selectPdg = true;
181  if (!fTrackingOnlyPdg.empty() && (fTrackingOnlyPdg.front() == 0)) selectPdg = false;
182 
183  for (const auto& pfpCluEntry : fPfpClusters) {
184  int pfPartIdx = pfpCluEntry.first;
185  int pdg = fPfpPdgCodes[pfPartIdx];
186 
187  //if (pdg == 11) continue;
188  if (skipPdg && has(fTrackingSkipPdg, pdg)) continue;
189  if (selectPdg && !has(fTrackingOnlyPdg, pdg)) continue;
190 
191  mf::LogVerbatim("PMAlgFitter") << "Process clusters from PFP:" << pfPartIdx << ", pdg:" << pdg;
192 
193  std::vector<art::Ptr<recob::Hit>> allHits;
194 
195  pma::TrkCandidate candidate;
196  std::unordered_map<geo::View_t, size_t> clu_count;
197  for (const auto& c : pfpCluEntry.second) {
198  if (c->NHits() == 0) { continue; }
199 
200  candidate.Clusters().push_back(c.key());
201  clu_count[c->View()]++;
202 
203  allHits.reserve(allHits.size() + fCluHits.at(c.key()).size());
204  for (const auto& h : fCluHits.at(c.key())) {
205  allHits.push_back(h);
206  }
207  }
208  if (clu_count.size() > 1) // try building only if there are clusters from multiple views
209  {
210  candidate.SetKey(pfpCluEntry.first);
211 
212  candidate.SetTrack(fProjectionMatchingAlg.buildMultiTPCTrack(detProp, allHits));
213 
214  if (candidate.IsValid() && candidate.Track()->HasTwoViews() &&
215  (candidate.Track()->Nodes().size() > 1)) {
216  if (!std::isnan(candidate.Track()->Length())) { fResult.push_back(candidate); }
217  else {
218  mf::LogError("PMAlgFitter") << "Trajectory fit lenght is nan.";
219  candidate.DeleteTrack();
220  }
221  }
222  else {
223  candidate.DeleteTrack();
224  }
225  }
226  }
227 }
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:92
std::vector< int > fTrackingOnlyPdg
std::map< int, int > fPfpPdgCodes
std::vector< int > fTrackingSkipPdg
pma::ProjectionMatchingAlg fProjectionMatchingAlg
Definition: PMAlgTracking.h:89
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:442
double Length(size_t step=1) const
Definition: PmaTrack3D.h:117
const std::vector< size_t > & Clusters() const
std::vector< pma::Node3D * > const & Nodes() const noexcept
Definition: PmaTrack3D.h:335
pma::TrkCandidateColl fResult
Definition: PMAlgTracking.h:92
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
bool pma::PMAlgFitter::has ( const std::vector< int > &  v,
int  i 
) const
inlineprivate

Definition at line 134 of file PMAlgTracking.h.

135  {
136  for (auto c : v) {
137  if (c == i) return true;
138  }
139  return false;
140  }

Member Data Documentation

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

Definition at line 142 of file PMAlgTracking.h.

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

Definition at line 143 of file PMAlgTracking.h.

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

Definition at line 145 of file PMAlgTracking.h.

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

Definition at line 144 of file PMAlgTracking.h.

bool pma::PMAlgFitter::fRunVertexing
private

Definition at line 152 of file PMAlgTracking.h.

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

Definition at line 148 of file PMAlgTracking.h.

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

Definition at line 150 of file PMAlgTracking.h.


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