LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
LArPandoraShowerCreation_module.cc
Go to the documentation of this file.
1 
10 
11 #include "fhiclcpp/ParameterSet.h"
12 
17 
19 
21 
22 #include <memory>
23 
24 namespace lar_pandora
25 {
26 
28 {
29 public:
30  explicit LArPandoraShowerCreation(fhicl::ParameterSet const &pset);
31 
36 
37  void produce(art::Event &evt) override;
38 
39 private:
46  recob::Shower BuildShower(const lar_content::LArShowerPCA &larShowerPCA, const pandora::CartesianVector &vertexPosition) const;
47 
53  recob::PCAxis BuildPCAxis(const lar_content::LArShowerPCA &larShowerPCA) const;
54 
55  std::string m_pfParticleLabel;
57 
58  // TODO When implementation lived in LArPandoraOutput, it contained key building blocks for calculation of shower energies per plane.
59  // Now functionality has moved to separate module, will require reimplementation (was deeply embedded in LArPandoraOutput structure).
60  // const calo::LinearEnergyAlg *m_pShowerEnergyAlg; ///< The address of the shower energy algorithm
61 };
62 
64 
65 } // namespace lar_pandora
66 
67 //------------------------------------------------------------------------------------------------------------------------------------------
68 // implementation follows
69 
73 
75 
77 
79 
81 
87 
89 
91 
93 
94 #include <iostream>
95 
96 namespace lar_pandora
97 {
98 
100  m_pfParticleLabel(pset.get<std::string>("PFParticleLabel")),
101  m_useAllParticles(pset.get<bool>("UseAllParticles", false))
102 {
103  produces< std::vector<recob::Shower> >();
104  produces< std::vector<recob::PCAxis> >();
105  produces< art::Assns<recob::PFParticle, recob::Shower> >();
106  produces< art::Assns<recob::PFParticle, recob::PCAxis> >();
107  produces< art::Assns<recob::Shower, recob::Hit> >();
108  produces< art::Assns<recob::Shower, recob::PCAxis> >();
109 }
110 
111 //------------------------------------------------------------------------------------------------------------------------------------------
112 
114 {
115  std::unique_ptr< std::vector<recob::Shower> > outputShowers( new std::vector<recob::Shower> );
116  std::unique_ptr< std::vector<recob::PCAxis> > outputPCAxes( new std::vector<recob::PCAxis> );
117  std::unique_ptr< art::Assns<recob::PFParticle, recob::Shower> > outputParticlesToShowers( new art::Assns<recob::PFParticle, recob::Shower> );
118  std::unique_ptr< art::Assns<recob::PFParticle, recob::PCAxis> > outputParticlesToPCAxes( new art::Assns<recob::PFParticle, recob::PCAxis> );
119  std::unique_ptr< art::Assns<recob::Shower, recob::Hit> > outputShowersToHits( new art::Assns<recob::Shower, recob::Hit> );
120  std::unique_ptr< art::Assns<recob::Shower, recob::PCAxis> > outputShowersToPCAxes( new art::Assns<recob::Shower, recob::PCAxis> );
121 
122  const art::PtrMaker<recob::Shower> makeShowerPtr(evt, *this);
123  const art::PtrMaker<recob::PCAxis> makePCAxisPtr(evt, *this);
124 
125  // Organise inputs
126  PFParticleVector pfParticleVector, extraPfParticleVector;
127  PFParticlesToSpacePoints pfParticlesToSpacePoints;
128  PFParticlesToClusters pfParticlesToClusters;
129  LArPandoraHelper::CollectPFParticles(evt, m_pfParticleLabel, pfParticleVector, pfParticlesToSpacePoints);
130  LArPandoraHelper::CollectPFParticles(evt, m_pfParticleLabel, extraPfParticleVector, pfParticlesToClusters);
131 
132  VertexVector vertexVector;
133  PFParticlesToVertices pfParticlesToVertices;
134  LArPandoraHelper::CollectVertices(evt, m_pfParticleLabel, vertexVector, pfParticlesToVertices);
135 
136  for (const art::Ptr<recob::PFParticle> pPFParticle : pfParticleVector)
137  {
138  // Select shower-like pfparticles
139  if (!m_useAllParticles && !LArPandoraHelper::IsShower(pPFParticle))
140  continue;
141 
142  // Obtain associated spacepoints
143  PFParticlesToSpacePoints::const_iterator particleToSpacePointIter(pfParticlesToSpacePoints.find(pPFParticle));
144 
145  if (pfParticlesToSpacePoints.end() == particleToSpacePointIter)
146  {
147  mf::LogDebug("LArPandoraShowerCreation") << "No spacepoints associated to particle ";
148  continue;
149  }
150 
151  // Obtain associated clusters
152  PFParticlesToClusters::const_iterator particleToClustersIter(pfParticlesToClusters.find(pPFParticle));
153 
154  if (pfParticlesToClusters.end() == particleToClustersIter)
155  {
156  mf::LogDebug("LArPandoraShowerCreation") << "No clusters associated to particle ";
157  continue;
158  }
159 
160  // Obtain associated vertex
161  PFParticlesToVertices::const_iterator particleToVertexIter(pfParticlesToVertices.find(pPFParticle));
162 
163  if ((pfParticlesToVertices.end() == particleToVertexIter) || (1 != particleToVertexIter->second.size()))
164  {
165  mf::LogDebug("LArPandoraShowerCreation") << "Unexpected number of vertices for particle ";
166  continue;
167  }
168 
169  // Copy information into expected pandora form
170  pandora::CartesianPointVector cartesianPointVector;
171  for (const art::Ptr<recob::SpacePoint> spacePoint : particleToSpacePointIter->second)
172  cartesianPointVector.emplace_back(pandora::CartesianVector(spacePoint->XYZ()[0], spacePoint->XYZ()[1], spacePoint->XYZ()[2]));
173 
174  double vertexXYZ[3] = {0., 0., 0.};
175  particleToVertexIter->second.front()->XYZ(vertexXYZ);
176  const pandora::CartesianVector vertexPosition(vertexXYZ[0], vertexXYZ[1], vertexXYZ[2]);
177 
178  // Call pandora "fast" shower fitter
179  try
180  {
181  // Ensure successful creation of all structures before placing results in output containers
182  const lar_content::LArShowerPCA larShowerPCA(lar_content::LArPfoHelper::GetPrincipalComponents(cartesianPointVector, vertexPosition));
183  const recob::Shower shower(LArPandoraShowerCreation::BuildShower(larShowerPCA, vertexPosition));
184  const recob::PCAxis pcAxis(LArPandoraShowerCreation::BuildPCAxis(larShowerPCA));
185  outputShowers->emplace_back(shower);
186  outputPCAxes->emplace_back(pcAxis);
187  }
188  catch (const pandora::StatusCodeException &)
189  {
190  mf::LogDebug("LArPandoraShowerCreation") << "Unable to extract shower pca";
191  continue;
192  }
193 
194  // Output objects
195  art::Ptr<recob::Shower> pShower(makeShowerPtr(outputShowers->size() - 1));
196  art::Ptr<recob::PCAxis> pPCAxis(makePCAxisPtr(outputPCAxes->size() - 1));
197 
198  HitVector hitsInParticle;
199  LArPandoraHelper::GetAssociatedHits(evt, m_pfParticleLabel, particleToClustersIter->second, hitsInParticle);
200 
201  // Output associations, after output objects are in place
202  util::CreateAssn(*this, evt, pShower, pPFParticle, *(outputParticlesToShowers.get()));
203  util::CreateAssn(*this, evt, pPCAxis, pPFParticle, *(outputParticlesToPCAxes.get()));
204  util::CreateAssn(*this, evt, *(outputShowers.get()), hitsInParticle, *(outputShowersToHits.get()));
205  util::CreateAssn(*this, evt, pPCAxis, pShower, *(outputShowersToPCAxes.get()));
206  }
207 
208  mf::LogDebug("LArPandora") << " Number of new showers: " << outputShowers->size() << std::endl;
209  mf::LogDebug("LArPandora") << " Number of new pcaxes: " << outputPCAxes->size() << std::endl;
210 
211  evt.put(std::move(outputShowers));
212  evt.put(std::move(outputPCAxes));
213  evt.put(std::move(outputParticlesToShowers));
214  evt.put(std::move(outputParticlesToPCAxes));
215  evt.put(std::move(outputShowersToHits));
216  evt.put(std::move(outputShowersToPCAxes));
217 }
218 
219 //------------------------------------------------------------------------------------------------------------------------------------------
220 
221 recob::Shower LArPandoraShowerCreation::BuildShower(const lar_content::LArShowerPCA &larShowerPCA, const pandora::CartesianVector &vertexPosition) const
222 {
223  const pandora::CartesianVector &showerLength(larShowerPCA.GetAxisLengths());
224  const pandora::CartesianVector &showerDirection(larShowerPCA.GetPrimaryAxis());
225 
226  const float length(showerLength.GetX());
227  const float openingAngle(larShowerPCA.GetPrimaryLength() > 0.f ? std::atan(larShowerPCA.GetSecondaryLength() / larShowerPCA.GetPrimaryLength()) : 0.f);
228  const TVector3 direction(showerDirection.GetX(), showerDirection.GetY(), showerDirection.GetZ());
229  const TVector3 vertex(vertexPosition.GetX(), vertexPosition.GetY(), vertexPosition.GetZ());
230 
231  // TODO
232  const TVector3 directionErr;
233  const TVector3 vertexErr;
234  const std::vector<double> totalEnergyErr;
235  const std::vector<double> dEdx;
236  const std::vector<double> dEdxErr;
237  const std::vector<double> totalEnergy;
238  const int bestplane(0);
239 
240  return recob::Shower(direction, directionErr, vertex, vertexErr, totalEnergy, totalEnergyErr, dEdx, dEdxErr, bestplane, util::kBogusI, length, openingAngle);
241 }
242 
243 //------------------------------------------------------------------------------------------------------------------------------------------
244 
246 {
247  const pandora::CartesianVector &showerCentroid(larShowerPCA.GetCentroid());
248  const pandora::CartesianVector &showerDirection(larShowerPCA.GetPrimaryAxis());
249  const pandora::CartesianVector &showerSecondaryVector(larShowerPCA.GetSecondaryAxis());
250  const pandora::CartesianVector &showerTertiaryVector(larShowerPCA.GetTertiaryAxis());
251  const pandora::CartesianVector &showerEigenValues(larShowerPCA.GetEigenValues());
252 
253  const bool svdOK(true);
254  const double eigenValues[3] = {showerEigenValues.GetX(), showerEigenValues.GetY(), showerEigenValues.GetZ()};
255  const double avePosition[3] = {showerCentroid.GetX(), showerCentroid.GetY(), showerCentroid.GetZ()};
256 
257  std::vector< std::vector<double> > eigenVecs = {
258  { showerDirection.GetX(), showerDirection.GetY(), showerDirection.GetZ() },
259  { showerSecondaryVector.GetX(), showerSecondaryVector.GetY(), showerSecondaryVector.GetZ() },
260  { showerTertiaryVector.GetX(), showerTertiaryVector.GetY(), showerTertiaryVector.GetZ() }
261  };
262 
263  // TODO
264  const int numHitsUsed(100);
265  const double aveHitDoca(0.);
266  const size_t iD(util::kBogusI);
267 
268  return recob::PCAxis(svdOK, numHitsUsed, eigenValues, eigenVecs, avePosition, aveHitDoca, iD);
269 }
270 
271 } // namespace lar_pandora
static LArShowerPCA GetPrincipalComponents(const pandora::CartesianPointVector &pointVector, const pandora::CartesianVector &vertexPosition)
Perform PCA analysis on a set of 3D points and return results.
Header file for the pfo helper class.
recob::PCAxis BuildPCAxis(const lar_content::LArShowerPCA &larShowerPCA) const
Build a recob::PCAxis object.
std::map< art::Ptr< recob::PFParticle >, ClusterVector > PFParticlesToClusters
Algorithm(s) calculating energy.
LArPandoraShowerCreation & operator=(LArPandoraShowerCreation const &)=delete
const pandora::CartesianVector & GetCentroid() const
Return centroid.
bool m_useAllParticles
Build a recob::Track for every recob::PFParticle.
float GetPrimaryLength() const
Return primary length.
std::vector< art::Ptr< recob::PFParticle > > PFParticleVector
Header file for lar pfo objects.
Declaration of signal hit object.
recob::Shower BuildShower(const lar_content::LArShowerPCA &larShowerPCA, const pandora::CartesianVector &vertexPosition) const
Build a recob::Shower object.
static bool IsShower(const art::Ptr< recob::PFParticle > particle)
Determine whether a particle has been reconstructed as shower-like.
STL namespace.
constexpr int kBogusI
obviously bogus integer value
TFile f
Definition: plotHisto.C:6
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
std::string m_pfParticleLabel
The pf particle label.
LArPandoraShowerCreation(fhicl::ParameterSet const &pset)
intermediate_table::const_iterator const_iterator
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
const pandora::CartesianVector & GetEigenValues() const
Return vector of eigenvalues.
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.
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
Definition: SpacePoint.h:65
const pandora::CartesianVector & GetAxisLengths() const
Return vector of lengths.
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
Utility object to perform functions of association.
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
const pandora::CartesianVector & GetSecondaryAxis() const
Return secondary axis.
std::map< art::Ptr< recob::PFParticle >, SpacePointVector > PFParticlesToSpacePoints
const pandora::CartesianVector & GetTertiaryAxis() const
Return tertiary axis.
LArShowerPCA class.
TCEvent evt
Definition: DataStructs.cxx:5
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.
std::vector< art::Ptr< recob::Vertex > > VertexVector
vertex reconstruction