7 #include "art/Framework/Core/EDProducer.h"
8 #include "art/Framework/Core/ModuleMacros.h"
9 #include "art/Framework/Principal/Event.h"
11 #include "fhiclcpp/ParameterSet.h"
22 namespace lar_pandora {
45 const pandora::CartesianVector& vertexPosition)
const;
65 #include "art/Framework/Principal/Handle.h"
66 #include "art/Framework/Principal/Run.h"
67 #include "art/Framework/Principal/SubRun.h"
69 #include "art/Persistency/Common/PtrMaker.h"
71 #include "canvas/Utilities/InputTag.h"
83 #include "messagefacility/MessageLogger/MessageLogger.h"
91 namespace lar_pandora {
95 , m_pfParticleLabel(pset.get<std::string>(
"PFParticleLabel"))
96 , m_useAllParticles(pset.get<
bool>(
"UseAllParticles",
false))
98 produces<std::vector<recob::Shower>>();
99 produces<std::vector<recob::PCAxis>>();
100 produces<art::Assns<recob::PFParticle, recob::Shower>>();
101 produces<art::Assns<recob::PFParticle, recob::PCAxis>>();
102 produces<art::Assns<recob::Shower, recob::Hit>>();
103 produces<art::Assns<recob::Shower, recob::PCAxis>>();
111 std::unique_ptr<std::vector<recob::Shower>> outputShowers(
new std::vector<recob::Shower>);
112 std::unique_ptr<std::vector<recob::PCAxis>> outputPCAxes(
new std::vector<recob::PCAxis>);
113 std::unique_ptr<art::Assns<recob::PFParticle, recob::Shower>> outputParticlesToShowers(
114 new art::Assns<recob::PFParticle, recob::Shower>);
115 std::unique_ptr<art::Assns<recob::PFParticle, recob::PCAxis>> outputParticlesToPCAxes(
116 new art::Assns<recob::PFParticle, recob::PCAxis>);
117 std::unique_ptr<art::Assns<recob::Shower, recob::Hit>> outputShowersToHits(
118 new art::Assns<recob::Shower, recob::Hit>);
119 std::unique_ptr<art::Assns<recob::Shower, recob::PCAxis>> outputShowersToPCAxes(
120 new art::Assns<recob::Shower, recob::PCAxis>);
122 const art::PtrMaker<recob::Shower> makeShowerPtr(evt);
123 const art::PtrMaker<recob::PCAxis> makePCAxisPtr(evt);
125 int showerCounter(0);
140 for (
const art::Ptr<recob::PFParticle> pPFParticle : pfParticleVector) {
145 PFParticlesToSpacePoints::const_iterator particleToSpacePointIter(
146 pfParticlesToSpacePoints.find(pPFParticle));
148 if (pfParticlesToSpacePoints.end() == particleToSpacePointIter) {
149 mf::LogDebug(
"LArPandoraShowerCreation") <<
"No spacepoints associated to particle ";
154 PFParticlesToClusters::const_iterator particleToClustersIter(
155 pfParticlesToClusters.find(pPFParticle));
157 if (pfParticlesToClusters.end() == particleToClustersIter) {
158 mf::LogDebug(
"LArPandoraShowerCreation") <<
"No clusters associated to particle ";
163 PFParticlesToVertices::const_iterator particleToVertexIter(
164 pfParticlesToVertices.find(pPFParticle));
166 if ((pfParticlesToVertices.end() == particleToVertexIter) ||
167 (1 != particleToVertexIter->second.size())) {
168 mf::LogDebug(
"LArPandoraShowerCreation") <<
"Unexpected number of vertices for particle ";
173 pandora::CartesianPointVector cartesianPointVector;
174 for (
const art::Ptr<recob::SpacePoint> spacePoint : particleToSpacePointIter->second)
175 cartesianPointVector.emplace_back(pandora::CartesianVector(
176 spacePoint->XYZ()[0], spacePoint->XYZ()[1], spacePoint->XYZ()[2]));
178 double vertexXYZ[3] = {0., 0., 0.};
179 particleToVertexIter->second.front()->XYZ(vertexXYZ);
180 const pandora::CartesianVector vertexPosition(vertexXYZ[0], vertexXYZ[1], vertexXYZ[2]);
189 const pandora::CartesianVector& centroid(initialLArShowerPCA.
GetCentroid());
190 const pandora::CartesianVector& primaryAxis(initialLArShowerPCA.
GetPrimaryAxis());
191 const pandora::CartesianVector& secondaryAxis(initialLArShowerPCA.
GetSecondaryAxis());
192 const pandora::CartesianVector& tertiaryAxis(initialLArShowerPCA.
GetTertiaryAxis());
193 const pandora::CartesianVector& eigenvalues(initialLArShowerPCA.
GetEigenValues());
196 const pandora::CartesianVector projectedVertexPosition(
198 primaryAxis.GetUnitVector() * (centroid - vertexPosition).GetDotProduct(primaryAxis));
201 const float testProjection(primaryAxis.GetDotProduct(projectedVertexPosition - centroid));
202 const float directionScaleFactor(
203 (testProjection > std::numeric_limits<float>::epsilon()) ? -1.f : 1.f);
206 primaryAxis * directionScaleFactor,
207 secondaryAxis * directionScaleFactor,
208 tertiaryAxis * directionScaleFactor,
211 showerCounter++, larShowerPCA, projectedVertexPosition));
213 outputShowers->emplace_back(shower);
214 outputPCAxes->emplace_back(pcAxis);
216 catch (
const pandora::StatusCodeException&) {
217 mf::LogDebug(
"LArPandoraShowerCreation") <<
"Unable to extract shower pca";
222 art::Ptr<recob::Shower> pShower(makeShowerPtr(outputShowers->size() - 1));
223 art::Ptr<recob::PCAxis> pPCAxis(makePCAxisPtr(outputPCAxes->size() - 1));
230 util::CreateAssn(*
this, evt, pShower, pPFParticle, *(outputParticlesToShowers.get()));
231 util::CreateAssn(*
this, evt, pPCAxis, pPFParticle, *(outputParticlesToPCAxes.get()));
233 *
this, evt, *(outputShowers.get()), hitsInParticle, *(outputShowersToHits.get()));
234 util::CreateAssn(*
this, evt, pPCAxis, pShower, *(outputShowersToPCAxes.get()));
237 mf::LogDebug(
"LArPandora") <<
" Number of new showers: " << outputShowers->size()
239 mf::LogDebug(
"LArPandora") <<
" Number of new pcaxes: " << outputPCAxes->size() << std::endl;
241 evt.put(std::move(outputShowers));
242 evt.put(std::move(outputPCAxes));
243 evt.put(std::move(outputParticlesToShowers));
244 evt.put(std::move(outputParticlesToPCAxes));
245 evt.put(std::move(outputShowersToHits));
246 evt.put(std::move(outputShowersToPCAxes));
254 const pandora::CartesianVector& vertexPosition)
const
256 const pandora::CartesianVector& showerLength(larShowerPCA.
GetAxisLengths());
257 const pandora::CartesianVector& showerDirection(larShowerPCA.
GetPrimaryAxis());
259 const float length(showerLength.GetX());
260 const float openingAngle(
264 const TVector3 direction(
265 showerDirection.GetX(), showerDirection.GetY(), showerDirection.GetZ());
266 const TVector3
vertex(vertexPosition.GetX(), vertexPosition.GetY(), vertexPosition.GetZ());
269 const TVector3 directionErr;
270 const TVector3 vertexErr;
271 const std::vector<double> totalEnergyErr;
272 const std::vector<double>
dEdx;
273 const std::vector<double> dEdxErr;
274 const std::vector<double> totalEnergy;
275 const int bestplane(0);
296 const pandora::CartesianVector& showerCentroid(larShowerPCA.
GetCentroid());
297 const pandora::CartesianVector& showerDirection(larShowerPCA.
GetPrimaryAxis());
298 const pandora::CartesianVector& showerSecondaryVector(larShowerPCA.
GetSecondaryAxis());
299 const pandora::CartesianVector& showerTertiaryVector(larShowerPCA.
GetTertiaryAxis());
300 const pandora::CartesianVector& showerEigenValues(larShowerPCA.
GetEigenValues());
302 const bool svdOK(
true);
303 const double eigenValues[3] = {
304 showerEigenValues.GetX(),
305 showerEigenValues.GetY(),
306 showerEigenValues.GetZ()};
307 const double avePosition[3] = {showerCentroid.GetX(),
308 showerCentroid.GetY(),
309 showerCentroid.GetZ()};
311 std::vector<std::vector<double>> eigenVecs = {
313 {showerDirection.GetX(), showerDirection.GetY(), showerDirection.GetZ()},
314 {showerSecondaryVector.GetX(), showerSecondaryVector.GetY(), showerSecondaryVector.GetZ()},
315 {showerTertiaryVector.GetX(), showerTertiaryVector.GetY(), showerTertiaryVector.GetZ()}};
318 const int numHitsUsed(100);
319 const double aveHitDoca(0.);
322 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.
void produce(art::Event &evt) override
Header file for the pfo helper class.
recob::PCAxis BuildPCAxis(const lar_content::LArShowerPCA &larShowerPCA) const
Build a recob::PCAxis object.
LArPandoraShowerCreation & operator=(LArPandoraShowerCreation const &)=delete
const pandora::CartesianVector & GetCentroid() const
Return centroid.
std::map< art::Ptr< recob::PFParticle >, ClusterVector > PFParticlesToClusters
bool m_useAllParticles
Build a recob::Track for every recob::PFParticle.
float GetPrimaryLength() const
Return primary length.
Header file for lar pfo objects.
Declaration of signal hit object.
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.
constexpr int kBogusI
obviously bogus integer value
std::map< art::Ptr< recob::PFParticle >, VertexVector > PFParticlesToVertices
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.
LArPandoraShowerCreation(fhicl::ParameterSet const &pset)
const pandora::CartesianVector & GetEigenValues() const
Return vector of eigenvalues.
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 pandora::CartesianVector & GetAxisLengths() const
Return vector of lengths.
std::map< art::Ptr< recob::PFParticle >, SpacePointVector > PFParticlesToSpacePoints
float dEdx(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const TCSlice &slc, TP3D &tp3d)
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
std::vector< art::Ptr< recob::Vertex > > VertexVector
const pandora::CartesianVector & GetSecondaryAxis() const
Return secondary axis.
const pandora::CartesianVector & GetTertiaryAxis() const
Return tertiary axis.
float GetSecondaryLength() const
Return secondary length.
helper function for LArPandoraInterface producer module
art framework interface to geometry description
const pandora::CartesianVector & GetPrimaryAxis() const
Return primary axis.