85 Name(
"ProjectionMatchingAlg")
93 Name(
"PMAlgVertexing")
97 Name(
"PMAlgCosmicTagging")
101 Name(
"PMAlgStitching")
105 Name(
"SaveOnlyBranchingVtx"),
106 Comment(
"use true to save only vertices interconnecting many tracks, otherwise vertex is added to the front of each track")
110 Name(
"SavePmaNodes"),
111 Comment(
"save track nodes (only for algorithm development purposes)")
115 Name(
"HitModuleLabel"),
116 Comment(
"tag of unclustered hits, which were used to validate tracks")
120 Name(
"WireModuleLabel"),
121 Comment(
"tag of recob::Wire producer.")
125 Name(
"ClusterModuleLabel"),
126 Comment(
"tag of cluster collection, these clusters are used for track building")
130 Name(
"EmClusterModuleLabel"),
131 Comment(
"EM-like clusters, will be excluded from tracking if provided")
204 produces< std::vector<recob::Track> >();
205 produces< std::vector<recob::SpacePoint> >();
206 produces< std::vector<recob::Vertex> >();
207 produces< std::vector<recob::Vertex> >(
kKinksName);
208 produces< std::vector<recob::Vertex> >(
kNodesName);
209 produces< std::vector<anab::T0> >();
210 produces< std::vector<anab::CosmicTag> >();
212 produces< art::Assns<recob::Track, recob::Hit> >();
213 produces< art::Assns<recob::Track, recob::Hit, recob::TrackHitMeta> >();
215 produces< art::Assns<recob::Track, recob::SpacePoint> >();
216 produces< art::Assns<recob::SpacePoint, recob::Hit> >();
217 produces< art::Assns<recob::Vertex, recob::Track> >();
218 produces< art::Assns<recob::Track, recob::Vertex> >(
kKinksName);
219 produces< art::Assns<recob::Track, anab::T0> >();
220 produces< art::Assns<recob::Track, anab::CosmicTag> >();
222 produces< std::vector<recob::PFParticle> >();
223 produces< art::Assns<recob::PFParticle, recob::Cluster> >();
224 produces< art::Assns<recob::PFParticle, recob::Vertex> >();
225 produces< art::Assns<recob::PFParticle, recob::Track> >();
232 std::ostringstream ss1; ss1 <<
"adc_plane_" << p ;
233 fAdcInPassingPoints.push_back( tfs->
make<TH1F>((ss1.str() +
"_passing").c_str(),
"max adc around the point on track", 100., 0., 5.) );
234 fAdcInRejectedPoints.push_back( tfs->
make<TH1F>((ss1.str() +
"_rejected").c_str(),
"max adc around spurious point ", 100., 0., 5.) );
249 int trkLikeIdx = hitResults->getIndex(
"track");
250 int emLikeIdx = hitResults->getIndex(
"em");
251 if ((trkLikeIdx < 0) || (emLikeIdx < 0))
253 throw cet::exception(
"PMAlgTrackMaker") <<
"No em/track labeled columns in MVA data products." << std::endl;
256 size_t nh[3] = { 0, 0, 0 };
257 for (
size_t hidx = 0; hidx < trk.
size(); ++hidx) { ++nh[trk[hidx]->View2D()]; }
259 size_t best_view = 2;
260 if ((nh[0] >= nh[1]) && (nh[0] > 1.25 * nh[2])) best_view = 0;
261 if ((nh[1] >= nh[0]) && (nh[1] > 1.25 * nh[2])) best_view = 1;
263 std::vector< art::Ptr<recob::Hit> > trkHitPtrList;
264 trkHitPtrList.reserve(nh[best_view]);
265 for (
size_t hidx = 0; hidx < trk.
size(); ++hidx)
267 if (trk[hidx]->View2D() == best_view) { trkHitPtrList.emplace_back(trk[hidx]->Hit2DPtr()); }
269 auto vout = hitResults->getOutput(trkHitPtrList);
270 double trk_like = -1, trk_or_em = vout[trkLikeIdx] + vout[emLikeIdx];
273 trk_like = vout[trkLikeIdx] / trk_or_em;
287 if (!cluResults) {
return false; }
289 int trkLikeIdx = cluResults->getIndex(
"track");
290 int emLikeIdx = cluResults->getIndex(
"em");
291 if ((trkLikeIdx < 0) || (emLikeIdx < 0)) {
return false; }
294 const auto & cnnOuts = cluResults->outputs();
295 std::vector< float > trackLike(cnnOuts.size());
296 for (
size_t i = 0; i < cnnOuts.size(); ++i)
298 double trkOrEm = cnnOuts[i][trkLikeIdx] + cnnOuts[i][emLikeIdx];
299 if (trkOrEm > 0) { trackLike[i] = cnnOuts[i][trkLikeIdx] / trkOrEm; }
300 else { trackLike[i] = 0; }
302 pmalgTracker.
init(hitsFromClusters, trackLike);
308 std::vector<anab::CosmicTagID_t> anabTags;
327 auto tracks = std::make_unique< std::vector< recob::Track > >();
328 auto allsp = std::make_unique< std::vector< recob::SpacePoint > >();
329 auto vtxs = std::make_unique< std::vector< recob::Vertex > >();
330 auto kinks = std::make_unique< std::vector< recob::Vertex > >();
331 auto nodes = std::make_unique< std::vector< recob::Vertex > >();
332 auto t0s = std::make_unique< std::vector< anab::T0 > >();
333 auto cosmicTags = std::make_unique< std::vector< anab::CosmicTag > >();
335 auto trk2hit_oldway = std::make_unique< art::Assns< recob::Track, recob::Hit > >();
336 auto trk2hit = std::make_unique< art::Assns< recob::Track, recob::Hit, recob::TrackHitMeta > >();
338 auto trk2sp = std::make_unique< art::Assns< recob::Track, recob::SpacePoint > >();
339 auto trk2t0 = std::make_unique< art::Assns< recob::Track, anab::T0 > >();
340 auto trk2ct = std::make_unique< art::Assns< recob::Track, anab::CosmicTag > >();
342 auto sp2hit = std::make_unique< art::Assns< recob::SpacePoint, recob::Hit > >();
343 auto vtx2trk = std::make_unique< art::Assns< recob::Vertex, recob::Track > >();
344 auto trk2kink = std::make_unique< art::Assns< recob::Track, recob::Vertex > >();
346 auto pfps = std::make_unique< std::vector< recob::PFParticle > >();
348 auto pfp2clu = std::make_unique< art::Assns<recob::PFParticle, recob::Cluster> >();
349 auto pfp2vtx = std::make_unique< art::Assns<recob::PFParticle, recob::Vertex> >();
350 auto pfp2trk = std::make_unique< art::Assns< recob::PFParticle, recob::Track > >();
356 std::vector< art::Ptr<recob::Hit> > allhitlist;
364 size_t mvaLength = 0;
372 pmalgTracker.init(hitsFromClusters, hitsFromEmParts);
377 if (init<4>(evt, pmalgTracker) ) { mvaLength = 4; }
378 else if (init<3>(evt, pmalgTracker)) { mvaLength = 3; }
379 else if (init<2>(evt, pmalgTracker)) { mvaLength = 2; }
382 throw cet::exception(
"PMAlgTrackMaker") <<
"No EM/track MVA data products." << std::endl;
389 pmalgTracker.init(hitsFromClusters);
394 int retCode = pmalgTracker.build();
403 else if (retCode == 1)
mf::LogVerbatim(
"Summary") << retCode <<
" track ready";
409 auto const & result = pmalgTracker.result();
412 size_t spStart = 0, spEnd = 0;
413 double sp_pos[3], sp_err[6];
414 for (
size_t i = 0; i < 3; ++i) sp_pos[i] = 0.0;
415 for (
size_t i = 0; i < 6; ++i) sp_err[i] = 1.0;
424 tracks->reserve(result.size());
425 for (
size_t trkIndex = 0; trkIndex < result.size(); ++trkIndex)
439 if (trk->
size()<2)
continue;
442 if (mvaLength == 4) pdg = getPdgFromCnnOnHits<4>(evt, *(result[trkIndex].Track()));
443 else if (mvaLength == 3) pdg = getPdgFromCnnOnHits<3>(evt, *(result[trkIndex].Track()));
444 else if (mvaLength == 2) pdg = getPdgFromCnnOnHits<2>(evt, *(result[trkIndex].Track()));
449 auto const trkPtr = make_trkptr(tracks->size() - 1);
454 t0s->push_back(
anab::T0(trk->
GetT0(), 0, 3, tracks->back().ID()));
456 auto const t0Ptr = make_t0ptr(t0s->size() - 1);
457 trk2t0->addSingle(trkPtr, t0Ptr);
463 std::vector<float> trkEnd0;
464 std::vector<float> trkEnd1;
469 for(
int i = 0; i < 3; ++i){
474 shift = trk->
Nodes()[0]->GetDriftShift();
476 trkEnd0.push_back(trk->
Nodes()[0]->Point3D()[i] - shift);
477 trkEnd1.push_back(trk->
Nodes()[trk->
Nodes().size()-1]->Point3D()[i] - shift);
482 for (
const auto t : tags)
484 cosmicTags->emplace_back(trkEnd0, trkEnd1, 1, t);
485 auto const cosmicPtr = make_ctptr(cosmicTags->size()-1);
486 trk2ct->addSingle(trkPtr,cosmicPtr);
491 for (
size_t h = 0, cnt = 0; h < trk->
size(); h++)
497 trk2hit->addSingle(trkPtr, h3d->
Hit2DPtr(), metadata);
498 trk2hit_oldway->addSingle(trkPtr, h3d->
Hit2DPtr());
502 spStart = allsp->
size();
504 for (
size_t h = 0; h < trk->
size(); ++h)
509 double hx = h3d->
Point3D().X();
510 double hy = h3d->
Point3D().Y();
511 double hz = h3d->
Point3D().Z();
514 (std::fabs(sp_pos[0] - hx) > 1.0
e-5) ||
515 (std::fabs(sp_pos[1] - hy) > 1.0
e-5) ||
516 (std::fabs(sp_pos[2] - hz) > 1.0
e-5))
523 sp_pos[0] = hx; sp_pos[1] = hy; sp_pos[2] = hz;
533 spEnd = allsp->size();
535 if (spEnd > spStart)
util::CreateAssn(*
this, evt, *tracks, *allsp, *trk2sp, spStart, spEnd);
539 auto ksel = pmalgTracker.getKinks();
540 std::map< size_t, art::Ptr<recob::Vertex> > frontVtxs;
545 for (
auto const & v : vsel)
547 xyz[0] = v.first.X(); xyz[1] = v.first.Y(); xyz[2] = v.first.Z();
549 <<
" vtx:" << xyz[0] <<
":" << xyz[1] <<
":" << xyz[2]
550 <<
" (" << v.second.size() <<
" tracks)";
552 size_t vidx = vtxs->size();
555 auto const vptr = make_vtxptr(vidx);
556 if (!v.second.empty())
558 for (
const auto & vEntry : v.second)
560 size_t tidx = vEntry.first;
561 bool isFront = vEntry.second;
563 if (isFront) frontVtxs[tidx] = vptr;
565 auto const tptr = make_trkptr(tidx);
566 vtx2trk->addSingle(vptr, tptr);
569 else mf::LogWarning(
"PMAlgTrackMaker") <<
"No tracks found at this vertex.";
573 for (
auto const & k : ksel)
575 xyz[0] = k.first.X(); xyz[1] = k.first.Y(); xyz[2] = k.first.Z();
576 mf::LogVerbatim(
"Summary") <<
" kink:" << xyz[0] <<
":" << xyz[1] <<
":" << xyz[2];
578 size_t kidx = kinks->size();
579 size_t tidx = k.second;
583 auto const tptr = make_trkptr(tidx);
584 auto const kptr = make_kinkptr(kidx);
585 trk2kink->addSingle(tptr, kptr);
593 for (
size_t t = 0; t < result.size(); ++t)
595 auto const &
trk = *(result[t].Track());
596 for (
auto const * node :
trk.Nodes())
598 xyz[0] = node->Point3D().X(); xyz[1] = node->Point3D().Y(); xyz[2] = node->Point3D().Z();
604 for (
size_t t = 0; t < result.size(); ++t)
607 if (result[t].Parent() >= 0) parentIdx = (
size_t)result[t].Parent();
609 std::vector< size_t > daughterIdxs;
610 for (
size_t idx : result[t].Daughters()) { daughterIdxs.push_back(idx); }
612 size_t pfpidx = pfps->size();
613 pfps->emplace_back((*tracks)[t].ParticleId(), pfpidx, parentIdx, daughterIdxs);
615 auto const pfpptr = make_pfpptr(pfpidx);
616 auto const tptr = make_trkptr(t);
617 pfp2trk->addSingle(pfpptr, tptr);
623 if (!vptr.
isNull()) pfp2vtx->addSingle(pfpptr, vptr);
624 else mf::LogWarning(
"PMAlgTrackMaker") <<
"Front vertex for PFParticle is missing.";
627 mf::LogVerbatim(
"Summary") << pfps->size() <<
" PFParticles created for reconstructed tracks.";
628 mf::LogVerbatim(
"Summary") <<
"Adding " << result.parents().size() <<
" primary PFParticles.";
629 for (
size_t t = 0; t < result.parents().size(); ++t)
631 std::vector< size_t > daughterIdxs;
632 for (
size_t idx : result.parents()[t].Daughters()) { daughterIdxs.push_back(idx); }
634 size_t pfpidx = pfps->size();
636 pfps->emplace_back(0, pfpidx, parentIdx, daughterIdxs);
641 auto const pfpptr = make_pfpptr(pfpidx);
643 if (!vptr.
isNull()) pfp2vtx->addSingle(pfpptr, vptr);
644 else mf::LogWarning(
"PMAlgTrackMaker") <<
"Front vertex for PFParticle is missing.";
647 mf::LogVerbatim(
"Summary") << pfps->size() <<
" PFParticles created in total.";
652 evt.
put(std::move(tracks));
653 evt.
put(std::move(allsp));
654 evt.
put(std::move(vtxs));
657 evt.
put(std::move(t0s));
658 evt.
put(std::move(cosmicTags));
660 evt.
put(std::move(trk2hit_oldway));
661 evt.
put(std::move(trk2hit));
662 evt.
put(std::move(trk2sp));
663 evt.
put(std::move(trk2t0));
664 evt.
put(std::move(trk2ct));
666 evt.
put(std::move(sp2hit));
667 evt.
put(std::move(vtx2trk));
670 evt.
put(std::move(pfps));
671 evt.
put(std::move(pfp2clu));
672 evt.
put(std::move(pfp2vtx));
673 evt.
put(std::move(pfp2trk));
PMAlgTrackMaker & operator=(PMAlgTrackMaker const &)=delete
bool SelectHits(float fraction=1.0F)
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
bool HasPlane(unsigned int iplane) const
Returns whether a plane with index iplane is present in this TPC.
bool HasTagFlag(ETag value) const
static const std::string kKinksName
void produce(art::Event &e) override
recob::Track convertFrom(const pma::Track3D &src, unsigned int tidx, int pdg=0)
fhicl::Atom< art::InputTag > EmClusterModuleLabel
unsigned int FrontTPC(void) const
static constexpr size_t kPFParticlePrimary
Define index to signify primary particle.
bool IsEnabled(void) const
Declaration of signal hit object.
fhicl::Atom< art::InputTag > HitModuleLabel
fhicl::Table< pma::PMAlgVertexing::Config > PMAlgVertexing
Planes which measure X direction.
fhicl::Table< pma::PMAlgCosmicTagger::Config > PMAlgCosmicTagging
std::vector< pma::Node3D * > const & Nodes(void) const
fhicl::Atom< bool > SavePmaNodes
fhicl::Table< pma::ProjectionMatchingAlg::Config > ProjectionMatchingAlg
fhicl::Atom< std::string > Validation
fhicl::Atom< art::InputTag > ClusterModuleLabel
Planes which measure Z direction.
fhicl::Atom< art::InputTag > WireModuleLabel
fhicl::Atom< bool > RunVertexing
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
art::Ptr< recob::Hit > const & Hit2DPtr(void) const
Definition of vertex object for LArSoft.
Planes which measure Y direction.
std::vector< anab::CosmicTagID_t > getCosmicTag(const pma::Track3D::ETag pmaTag) const
geo::GeometryCore const * fGeom
ProductID put(std::unique_ptr< PROD > &&product)
pma::PMAlgStitching::Config fPmaStitchConfig
unsigned int MaxPlanes() const
Returns the largest number of planes among all TPCs in this detector.
std::vector< TH1F * > fAdcInRejectedPoints
#define DEFINE_ART_MODULE(klass)
pma::ProjectionMatchingAlg::Config fPmaConfig
void push_back(Ptr< U > const &p)
pma::PMAlgVertexing::Config fPmaVtxConfig
int getPdgFromCnnOnHits(const art::Event &evt, const pma::Track3D &trk) const
art::InputTag fCluModuleLabel
size_t CompleteMissingWires(unsigned int view)
bool CreateAssn(PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
Creates a single one-to-one association.
pma::PMAlgCosmicTagger::Config fPmaTaggingConfig
Description of geometry of one entire detector.
Declaration of cluster object.
Provides recob::Track data product.
unsigned int FrontCryo(void) const
art::InputTag fHitModuleLabel
Encapsulate the geometry of a wire.
TVector3 const & Point3D(void) const
T * make(ARGS...args) const
fhicl::Atom< float > TrackLikeThreshold
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane.
void init(const art::FindManyP< recob::Hit > &hitsFromClusters)
fhicl::Table< pma::PMAlgTracker::Config > PMAlgTracking
bool init(const art::Event &evt, pma::PMAlgTracker &pmalgTracker) const
art::InputTag fEmModuleLabel
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
fhicl::Table< pma::PMAlgStitching::Config > PMAlgStitching
art::InputTag fWireModuleLabel
double GetRawdEdxSequence(std::map< size_t, std::vector< double > > &dedx, unsigned int view=geo::kZ, unsigned int skip=0, bool inclDisabled=false) const
std::vector< TH1F * > fAdcInPassingPoints
bool fSaveOnlyBranchingVtx
TPCGeo const & TPC(unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified TPC.
std::map< size_t, std::vector< double > > dedx_map
pma::PMAlgTracker::Config fPmaTrackerConfig
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Namespace collecting geometry-related classes utilities.
PMAlgTrackMaker(Parameters const &config)
static std::unique_ptr< MVAReader > create(const art::Event &evt, const art::InputTag &tag)
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
Encapsulate the construction of a single detector plane.
fhicl::Atom< bool > SaveOnlyBranchingVtx
static const std::string kNodesName