106 std::unique_ptr< std::vector<recob::Track> > outputTracks(
new std::vector<recob::Track> );
114 const unsigned int nWirePlanes(theGeometry->
MaxPlanes());
117 throw cet::exception(
"LArPandoraTrackCreation") <<
" LArPandoraTrackCreation::produce --- More than three wire planes present ";
119 if ((0 == theGeometry->
Ncryostats()) || (0 == theGeometry->
NTPC(0)))
120 throw cet::exception(
"LArPandoraTrackCreation") <<
" LArPandoraTrackCreation::produce --- unable to access first tpc in first cryostat ";
122 std::unordered_set<geo::_plane_proj> planeSet;
123 for (
unsigned int iPlane = 0; iPlane < nWirePlanes; ++iPlane)
124 (
void) planeSet.insert(theGeometry->
TPC(0, 0).
Plane(iPlane).
View());
126 if ((nWirePlanes != planeSet.size()) || !planeSet.count(
geo::kU) || !planeSet.count(
geo::kV) || (planeSet.count(
geo::kW) && planeSet.count(
geo::kY)))
127 throw cet::exception(
"LArPandoraTrackCreation") <<
" LArPandoraTrackCreation::produce --- expect to find u and v views; if there is one further view, it must be w or y ";
129 const bool useYPlane((nWirePlanes > 2) && planeSet.count(
geo::kY));
158 if (pfParticlesToSpacePoints.end() == particleToSpacePointIter)
160 mf::LogDebug(
"LArPandoraTrackCreation") <<
"No spacepoints associated to particle ";
167 if (pfParticlesToClusters.end() == particleToClustersIter)
169 mf::LogDebug(
"LArPandoraShowerCreation") <<
"No clusters associated to particle ";
176 if ((pfParticlesToVertices.end() == particleToVertexIter) || (1 != particleToVertexIter->second.size()))
178 mf::LogDebug(
"LArPandoraTrackCreation") <<
"Unexpected number of vertices for particle ";
183 pandora::CartesianPointVector cartesianPointVector;
185 cartesianPointVector.emplace_back(pandora::CartesianVector(spacePoint->
XYZ()[0], spacePoint->
XYZ()[1], spacePoint->
XYZ()[2]));
187 double vertexXYZ[3] = {0., 0., 0.};
188 particleToVertexIter->second.front()->XYZ(vertexXYZ);
189 const pandora::CartesianVector vertexPosition(vertexXYZ[0], vertexXYZ[1], vertexXYZ[2]);
198 catch (
const pandora::StatusCodeException &)
200 mf::LogDebug(
"LArPandoraTrackCreation") <<
"Unable to extract sliding fit trajectory";
206 mf::LogDebug(
"LArPandoraTrackCreation") <<
"Insufficient input trajectory points to build track: " << trackStateVector.size();
210 HitVector hitsFromSpacePoints, hitsFromClusters, hitsInParticle;
216 for (
unsigned int hitIndex = 0; hitIndex < hitsFromSpacePoints.size(); hitIndex++)
218 hitsInParticle.push_back(hitsFromSpacePoints.at(hitIndex));
219 (void) hitsInParticleSet.insert(hitsFromSpacePoints.at(hitIndex));
222 for (
unsigned int hitIndex = 0; hitIndex < hitsFromClusters.size(); hitIndex++)
224 if (hitsInParticleSet.count(hitsFromClusters.at(hitIndex)) == 0)
225 hitsInParticle.push_back(hitsFromClusters.at(hitIndex));
229 if (trackStateVector.size()>hitsFromSpacePoints.size())
231 throw cet::exception(
"LArPandoraTrackCreation") <<
"trackStateVector.size() is greater than hitsFromSpacePoints.size()";
233 const unsigned int nInvalidPoints = hitsInParticle.size()-trackStateVector.size();
234 for (
unsigned int i=0;i<nInvalidPoints;++i) {
244 util::CreateAssn(*
this, evt, pTrack, pPFParticle, *(outputParticlesToTracks.get()));
245 util::CreateAssn(*
this, evt, *(outputTracks.get()), hitsInParticle, *(outputTracksToHits.get()));
248 for (
unsigned int hitIndex = 0; hitIndex < hitsInParticle.size(); hitIndex++)
253 outputTracksToHitsWithMeta->addSingle(pTrack, pHit, metadata);
257 mf::LogDebug(
"LArPandoraTrackCreation") <<
"Number of new tracks: " << outputTracks->size() << std::endl;
259 evt.
put(std::move(outputTracks));
260 evt.
put(std::move(outputTracksToHits));
261 evt.
put(std::move(outputTracksToHitsWithMeta));
262 evt.
put(std::move(outputParticlesToTracks));
std::map< art::Ptr< recob::PFParticle >, ClusterVector > PFParticlesToClusters
std::vector< art::Ptr< recob::PFParticle > > PFParticleVector
static void GetSlidingFitTrajectory(const pandora::CartesianPointVector &pointVector, const pandora::CartesianVector &vertexPosition, const unsigned int layerWindow, const float layerPitch, LArTrackStateVector &trackStateVector, pandora::IntVector *const pIndexVector=nullptr)
Apply 3D sliding fit to a set of 3D points and return track trajectory.
std::vector< int > IntVector
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
geo::Length_t WirePitch(geo::PlaneID const &planeid) const
Returns the distance between two consecutive wires.
Planes which measure Y direction.
unsigned int m_slidingFitHalfWindow
The sliding fit half window.
ProductID put(std::unique_ptr< PROD > &&product)
std::unordered_set< art::Ptr< recob::Hit > > HitSet
View_t View() const
Which coordinate does this plane measure.
unsigned int MaxPlanes() const
Returns the largest number of planes among all TPCs in this detector.
static void GetAssociatedHits(const art::Event &evt, const std::string &label, const std::vector< art::Ptr< T > > &inputVector, HitVector &associatedHits, const pandora::IntVector *const indexVector=nullptr)
Get all hits associated with input clusters.
bool m_useAllParticles
Build a recob::Track for every recob::PFParticle.
std::string m_pfParticleLabel
The pf particle label.
static void CollectVertices(const art::Event &evt, const std::string &label, VertexVector &vertexVector, PFParticlesToVertices &particlesToVertices)
Collect the reconstructed PFParticles and associated Vertices from the ART event record.
std::map< art::Ptr< recob::PFParticle >, VertexVector > PFParticlesToVertices
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.
const Double32_t * XYZ() const
static void CollectPFParticles(const art::Event &evt, const std::string &label, PFParticleVector &particleVector)
Collect the reconstructed PFParticles from the ART event record.
std::vector< art::Ptr< recob::Hit > > HitVector
unsigned int NTPC(unsigned int cstat=0) const
Returns the total number of TPCs in the specified cryostat.
constexpr float kBogusF
obviously bogus float value
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
static bool IsTrack(const art::Ptr< recob::PFParticle > particle)
Determine whether a particle has been reconstructed as track-like.
recob::Track BuildTrack(const int id, const lar_content::LArTrackStateVector &trackStateVector) const
Build a recob::Track object.
TPCGeo const & TPC(unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified TPC.
std::map< art::Ptr< recob::PFParticle >, SpacePointVector > PFParticlesToSpacePoints
std::vector< LArTrackState > LArTrackStateVector
unsigned int m_minTrajectoryPoints
The minimum number of trajectory points.
Planes which measure W (third view for Bo, MicroBooNE, etc).
PlaneGeo const & Plane(geo::View_t view) const
Return the plane in the tpc with View_t view.
cet::coded_exception< error, detail::translate > exception
std::vector< art::Ptr< recob::Vertex > > VertexVector