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(
113 new art::Assns<recob::PFParticle, recob::Shower>);
114 std::unique_ptr<art::Assns<recob::PFParticle, recob::PCAxis>> outputParticlesToPCAxes(
115 new art::Assns<recob::PFParticle, recob::PCAxis>);
116 std::unique_ptr<art::Assns<recob::Shower, recob::Hit>> outputShowersToHits(
117 new art::Assns<recob::Shower, recob::Hit>);
118 std::unique_ptr<art::Assns<recob::Shower, recob::PCAxis>> outputShowersToPCAxes(
119 new art::Assns<recob::Shower, recob::PCAxis>);
121 const art::PtrMaker<recob::Shower> makeShowerPtr(evt);
122 const art::PtrMaker<recob::PCAxis> makePCAxisPtr(evt);
124 int showerCounter(0);
139 for (
const art::Ptr<recob::PFParticle> pPFParticle : pfParticleVector) {
144 PFParticlesToSpacePoints::const_iterator particleToSpacePointIter(
145 pfParticlesToSpacePoints.find(pPFParticle));
147 if (pfParticlesToSpacePoints.end() == particleToSpacePointIter) {
148 mf::LogDebug(
"LArPandoraShowerCreation") <<
"No spacepoints associated to particle ";
153 PFParticlesToClusters::const_iterator particleToClustersIter(
154 pfParticlesToClusters.find(pPFParticle));
156 if (pfParticlesToClusters.end() == particleToClustersIter) {
157 mf::LogDebug(
"LArPandoraShowerCreation") <<
"No clusters associated to particle ";
162 PFParticlesToVertices::const_iterator particleToVertexIter(
163 pfParticlesToVertices.find(pPFParticle));
165 if ((pfParticlesToVertices.end() == particleToVertexIter) ||
166 (1 != particleToVertexIter->second.size())) {
167 mf::LogDebug(
"LArPandoraShowerCreation") <<
"Unexpected number of vertices for particle ";
173 for (
const art::Ptr<recob::SpacePoint> spacePoint : particleToSpacePointIter->second)
175 spacePoint->XYZ()[0], spacePoint->XYZ()[1], spacePoint->XYZ()[2]));
177 double vertexXYZ[3] = {0., 0., 0.};
178 particleToVertexIter->second.front()->XYZ(vertexXYZ);
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);
216 mf::LogDebug(
"LArPandoraShowerCreation") <<
"Unable to extract shower pca";
221 art::Ptr<recob::Shower> pShower(makeShowerPtr(outputShowers->size() - 1));
222 art::Ptr<recob::PCAxis> pPCAxis(makePCAxisPtr(outputPCAxes->size() - 1));
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()));
232 util::CreateAssn(evt, pPCAxis, pShower, *(outputShowersToPCAxes.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));
300 const bool svdOK(
true);
301 const double eigenValues[3] = {
302 showerEigenValues.
GetX(),
303 showerEigenValues.
GetY(),
304 showerEigenValues.
GetZ()};
305 const double avePosition[3] = {showerCentroid.
GetX(),
306 showerCentroid.
GetY(),
307 showerCentroid.
GetZ()};
309 std::vector<std::vector<double>> eigenVecs = {
311 {showerDirection.
GetX(), showerDirection.
GetY(), showerDirection.
GetZ()},
312 {showerSecondaryVector.
GetX(), showerSecondaryVector.
GetY(), showerSecondaryVector.
GetZ()},
313 {showerTertiaryVector.
GetX(), showerTertiaryVector.
GetY(), showerTertiaryVector.
GetZ()}};
316 const int numHitsUsed(100);
317 const double aveHitDoca(0.);
318 const size_t iD(util::kBogusI);
320 return recob::PCAxis(svdOK, numHitsUsed, eigenValues, eigenVecs, avePosition, aveHitDoca, iD);
static LArShowerPCA GetPrincipalComponents(const pandora::CartesianPointVector &pointVector, const pandora::CartesianVector &vertexPosition)
Perform PCA analysis on a set of 3D points and return results.
const pandora::CartesianVector & GetPrimaryAxis() const
Return primary axis.
const pandora::CartesianVector & GetTertiaryAxis() const
Return tertiary axis.
const pandora::CartesianVector & GetEigenValues() const
Return vector of eigenvalues.
const pandora::CartesianVector & GetAxisLengths() const
Return vector of lengths.
const pandora::CartesianVector & GetCentroid() const
Return centroid.
const pandora::CartesianVector & GetSecondaryAxis() const
Return secondary axis.