110 std::unique_ptr<std::vector<recob::Shower>> outputShowers(
new std::vector<recob::Shower>);
111 std::unique_ptr<std::vector<recob::PCAxis>> outputPCAxes(
new std::vector<recob::PCAxis>);
112 std::unique_ptr<art::Assns<recob::PFParticle, recob::Shower>> outputParticlesToShowers(
114 std::unique_ptr<art::Assns<recob::PFParticle, recob::PCAxis>> outputParticlesToPCAxes(
116 std::unique_ptr<art::Assns<recob::Shower, recob::Hit>> outputShowersToHits(
118 std::unique_ptr<art::Assns<recob::Shower, recob::PCAxis>> outputShowersToPCAxes(
124 int showerCounter(0);
145 pfParticlesToSpacePoints.find(pPFParticle));
147 if (pfParticlesToSpacePoints.end() == particleToSpacePointIter) {
148 mf::LogDebug(
"LArPandoraShowerCreation") <<
"No spacepoints associated to particle ";
154 pfParticlesToClusters.find(pPFParticle));
156 if (pfParticlesToClusters.end() == particleToClustersIter) {
157 mf::LogDebug(
"LArPandoraShowerCreation") <<
"No clusters associated to particle ";
163 pfParticlesToVertices.find(pPFParticle));
165 if ((pfParticlesToVertices.end() == particleToVertexIter) ||
166 (1 != particleToVertexIter->second.size())) {
167 mf::LogDebug(
"LArPandoraShowerCreation") <<
"Unexpected number of vertices for particle ";
172 pandora::CartesianPointVector cartesianPointVector;
174 cartesianPointVector.emplace_back(pandora::CartesianVector(
175 spacePoint->
XYZ()[0], spacePoint->
XYZ()[1], spacePoint->
XYZ()[2]));
177 double vertexXYZ[3] = {0., 0., 0.};
178 particleToVertexIter->second.front()->XYZ(vertexXYZ);
179 const pandora::CartesianVector vertexPosition(vertexXYZ[0], vertexXYZ[1], vertexXYZ[2]);
188 const pandora::CartesianVector& centroid(initialLArShowerPCA.GetCentroid());
189 const pandora::CartesianVector& primaryAxis(initialLArShowerPCA.GetPrimaryAxis());
190 const pandora::CartesianVector& secondaryAxis(initialLArShowerPCA.GetSecondaryAxis());
191 const pandora::CartesianVector& tertiaryAxis(initialLArShowerPCA.GetTertiaryAxis());
192 const pandora::CartesianVector& eigenvalues(initialLArShowerPCA.GetEigenValues());
195 const pandora::CartesianVector projectedVertexPosition(
197 primaryAxis.GetUnitVector() * (centroid - vertexPosition).GetDotProduct(primaryAxis));
200 const float testProjection(primaryAxis.GetDotProduct(projectedVertexPosition - centroid));
201 const float directionScaleFactor(
202 (testProjection > std::numeric_limits<float>::epsilon()) ? -1.
f : 1.
f);
205 primaryAxis * directionScaleFactor,
206 secondaryAxis * directionScaleFactor,
207 tertiaryAxis * directionScaleFactor,
210 showerCounter++, larShowerPCA, projectedVertexPosition));
212 outputShowers->emplace_back(
shower);
213 outputPCAxes->emplace_back(pcAxis);
215 catch (
const pandora::StatusCodeException&) {
216 mf::LogDebug(
"LArPandoraShowerCreation") <<
"Unable to extract shower pca";
229 util::CreateAssn(evt, pShower, pPFParticle, *(outputParticlesToShowers.get()));
230 util::CreateAssn(evt, pPCAxis, pPFParticle, *(outputParticlesToPCAxes.get()));
231 util::CreateAssn(evt, *(outputShowers.get()), hitsInParticle, *(outputShowersToHits.get()));
235 mf::LogDebug(
"LArPandora") <<
" Number of new showers: " << outputShowers->size()
237 mf::LogDebug(
"LArPandora") <<
" Number of new pcaxes: " << outputPCAxes->size() << std::endl;
239 evt.
put(std::move(outputShowers));
240 evt.
put(std::move(outputPCAxes));
241 evt.
put(std::move(outputParticlesToShowers));
242 evt.
put(std::move(outputParticlesToPCAxes));
243 evt.
put(std::move(outputShowersToHits));
244 evt.
put(std::move(outputShowersToPCAxes));
static LArShowerPCA GetPrincipalComponents(const pandora::CartesianPointVector &pointVector, const pandora::CartesianVector &vertexPosition)
Perform PCA analysis on a set of 3D points and return results.
recob::PCAxis BuildPCAxis(const lar_content::LArShowerPCA &larShowerPCA) const
Build a recob::PCAxis object.
std::map< art::Ptr< recob::PFParticle >, ClusterVector > PFParticlesToClusters
bool m_useAllParticles
Build a recob::Track for every recob::PFParticle.
static bool IsShower(const art::Ptr< recob::PFParticle > particle)
Determine whether a particle has been reconstructed as shower-like.
recob::Shower BuildShower(const int id, const lar_content::LArShowerPCA &larShowerPCA, const pandora::CartesianVector &vertexPosition) const
Build a recob::Shower object.
std::map< art::Ptr< recob::PFParticle >, VertexVector > PFParticlesToVertices
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
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.
std::string m_pfParticleLabel
The pf particle label.
std::vector< art::Ptr< recob::PFParticle > > PFParticleVector
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.
const Double32_t * XYZ() const
std::map< art::Ptr< recob::PFParticle >, SpacePointVector > PFParticlesToSpacePoints
static void CollectPFParticles(const art::Event &evt, const std::string &label, PFParticleVector &particleVector)
Collect the reconstructed PFParticles from the ART event record.
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
std::vector< art::Ptr< recob::Hit > > HitVector
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
std::vector< art::Ptr< recob::Vertex > > VertexVector