LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
LArPandoraOutput.h
Go to the documentation of this file.
1 
7 #ifndef LAR_PANDORA_OUTPUT_H
8 #define LAR_PANDORA_OUTPUT_H
9 
12 
13 namespace recob {
14  class Cluster;
15  class PFParticleMetadata;
16 }
17 
18 namespace cluster {
19  class ClusterParamsAlgBase;
20 }
21 
24 
32 
33 #include "Api/PandoraApi.h"
34 
35 namespace util {
36  class GeometryUtilities;
37 }
38 
39 #include <map>
40 #include <vector>
41 
42 //------------------------------------------------------------------------------------------------------------------------------------------
43 
44 namespace lar_pandora {
45 
47  public:
48  typedef std::vector<size_t> IdVector;
49  typedef std::map<size_t, IdVector> IdToIdVectorMap;
50  typedef std::map<const pandora::CaloHit*, art::Ptr<recob::Hit>> CaloHitToArtHitMap;
51 
52  typedef std::unique_ptr<std::vector<recob::PFParticle>> PFParticleCollection;
53  typedef std::unique_ptr<std::vector<recob::Vertex>> VertexCollection;
54  typedef std::unique_ptr<std::vector<recob::Cluster>> ClusterCollection;
55  typedef std::unique_ptr<std::vector<recob::SpacePoint>> SpacePointCollection;
56  typedef std::unique_ptr<std::vector<anab::T0>> T0Collection;
57  typedef std::unique_ptr<std::vector<larpandoraobj::PFParticleMetadata>>
59  typedef std::unique_ptr<std::vector<recob::Slice>> SliceCollection;
60 
61  typedef std::unique_ptr<art::Assns<recob::PFParticle, larpandoraobj::PFParticleMetadata>>
63  typedef std::unique_ptr<art::Assns<recob::PFParticle, recob::SpacePoint>>
65  typedef std::unique_ptr<art::Assns<recob::PFParticle, recob::Cluster>>
67  typedef std::unique_ptr<art::Assns<recob::PFParticle, recob::Vertex>>
69  typedef std::unique_ptr<art::Assns<recob::PFParticle, anab::T0>> PFParticleToT0Collection;
70  typedef std::unique_ptr<art::Assns<recob::PFParticle, recob::Slice>>
72 
73  typedef std::unique_ptr<art::Assns<recob::Cluster, recob::Hit>> ClusterToHitCollection;
74  typedef std::unique_ptr<art::Assns<recob::SpacePoint, recob::Hit>> SpacePointToHitCollection;
75  typedef std::unique_ptr<art::Assns<recob::Slice, recob::Hit>> SliceToHitCollection;
76 
80  class Settings {
81  public:
85  Settings();
86 
90  void Validate() const;
91 
92  const pandora::Pandora* m_pPrimaryPandora;
94  bool
96  bool
99  bool
101  std::string
103  bool
106  };
107 
115  static void ProduceArtOutput(const Settings& settings,
116  const IdToHitMap& idToHitMap,
117  art::Event& evt);
118 
128  static bool GetPandoraInstance(const pandora::Pandora* const pPrimaryPandora,
129  const std::string& name,
130  const pandora::Pandora*& pPandoraInstance);
131 
138  static void GetPandoraSlices(const pandora::Pandora* const pPrimaryPandora,
139  pandora::PfoVector& slicePfos);
140 
148  static bool IsClearCosmic(const pandora::ParticleFlowObject* const pPfo);
149 
157  static bool IsFromSlice(const pandora::ParticleFlowObject* const pPfo);
158 
166  static unsigned int GetSliceIndex(const pandora::ParticleFlowObject* const pPfo);
167 
175  static pandora::PfoVector CollectPfos(const pandora::Pandora* const pPrimaryPandora);
176 
184  static pandora::PfoVector CollectAllPfoOutcomes(const pandora::Pandora* const pPrimaryPandora);
185 
192  static void CollectPfos(const pandora::PfoList& parentPfoList, pandora::PfoVector& pfoVector);
193 
204  static pandora::VertexVector CollectVertices(
205  const pandora::PfoVector& pfoVector,
206  IdToIdVectorMap& pfoToVerticesMap,
207  std::function<const pandora::Vertex* const(const pandora::ParticleFlowObject* const)>
208  fCriteria);
209 
219  static pandora::ClusterList CollectClusters(const pandora::PfoVector& pfoVector,
220  IdToIdVectorMap& pfoToClustersMap);
221 
228  static void Collect3DHits(const pandora::ParticleFlowObject* const pPfo,
229  pandora::CaloHitVector& caloHits);
230 
240  static pandora::CaloHitList Collect3DHits(const pandora::PfoVector& pfoVector,
241  IdToIdVectorMap& pfoToThreeDHitsMap);
242 
251  template <typename T>
252  static size_t GetId(const T* const pT, const std::list<const T*>& tList);
253 
262  template <typename T>
263  static size_t GetId(const T* const pT, const std::vector<const T*>& tVector);
264 
273  static void GetPandoraToArtHitMap(const pandora::ClusterList& clusterList,
274  const pandora::CaloHitList& threeDHitList,
275  const IdToHitMap& idToHitMap,
276  CaloHitToArtHitMap& pandoraHitToArtHitMap);
277 
284  static art::Ptr<recob::Hit> GetHit(const IdToHitMap& idToHitMap,
285  const pandora::CaloHit* const pCaloHit);
286 
293  static void BuildVertices(const pandora::VertexVector& vertexVector,
294  VertexCollection& outputVertices);
295 
306  static void BuildSpacePoints(const art::Event& event,
307  const std::string& instanceLabel,
308  const pandora::CaloHitList& threeDHitList,
309  const CaloHitToArtHitMap& pandoraHitToArtHitMap,
310  SpacePointCollection& outputSpacePoints,
311  SpacePointToHitCollection& outputSpacePointsToHits);
312 
326  static void BuildClusters(const art::Event& event,
327  const std::string& instanceLabel,
328  const pandora::ClusterList& clusterList,
329  const CaloHitToArtHitMap& pandoraHitToArtHitMap,
330  const IdToIdVectorMap& pfoToClustersMap,
331  ClusterCollection& outputClusters,
332  ClusterToHitCollection& outputClustersToHits,
333  IdToIdVectorMap& pfoToArtClustersMap);
334 
349  static void BuildPFParticles(const art::Event& event,
350  const std::string& instanceLabel,
351  const pandora::PfoVector& pfoVector,
352  const IdToIdVectorMap& pfoToVerticesMap,
353  const IdToIdVectorMap& pfoToThreeDHitsMap,
354  const IdToIdVectorMap& pfoToArtClustersMap,
355  PFParticleCollection& outputParticles,
356  PFParticleToVertexCollection& outputParticlesToVertices,
357  PFParticleToSpacePointCollection& outputParticlesToSpacePoints,
358  PFParticleToClusterCollection& outputParticlesToClusters);
359 
369  static void AssociateAdditionalVertices(
370  const art::Event& event,
371  const std::string& instanceLabel,
372  const pandora::PfoVector& pfoVector,
373  const IdToIdVectorMap& pfoToVerticesMap,
374  PFParticleToVertexCollection& outputParticlesToVertices);
375 
384  static void BuildParticleMetadata(const art::Event& event,
385  const std::string& instanceLabel,
386  const pandora::PfoVector& pfoVector,
387  PFParticleMetadataCollection& outputParticleMetadata,
388  PFParticleToMetadataCollection& outputParticlesToMetadata);
389 
403  static void BuildSlices(const Settings& settings,
404  const pandora::Pandora* const pPrimaryPandora,
405  const art::Event& event,
406  const std::string& instanceLabel,
407  const pandora::PfoVector& pfoVector,
408  const IdToHitMap& idToHitMap,
409  SliceCollection& outputSlices,
410  PFParticleToSliceCollection& outputParticlesToSlices,
411  SliceToHitCollection& outputSlicesToHits);
412 
418  static unsigned int BuildDummySlice(SliceCollection& outputSlices);
419 
432  static void CopyAllHitsToSingleSlice(const Settings& settings,
433  const art::Event& event,
434  const std::string& instanceLabel,
435  const pandora::PfoVector& pfoVector,
436  const IdToHitMap& idToHitMap,
437  SliceCollection& outputSlices,
438  PFParticleToSliceCollection& outputParticlesToSlices,
439  SliceToHitCollection& outputSlicesToHits);
440 
451  static unsigned int BuildSlice(const pandora::ParticleFlowObject* const pParentPfo,
452  const art::Event& event,
453  const std::string& instanceLabel,
454  const IdToHitMap& idToHitMap,
455  SliceCollection& outputSlices,
456  SliceToHitCollection& outputSlicesToHits);
457 
468  static void BuildT0s(const art::Event& event,
469  const std::string& instanceLabel,
470  const pandora::PfoVector& pfoVector,
471  T0Collection& outputT0s,
472  PFParticleToT0Collection& outputParticlesToT0s);
473 
482  static recob::Vertex BuildVertex(const pandora::Vertex* const pVertex, const size_t vertexId);
483 
492  static recob::SpacePoint BuildSpacePoint(const pandora::CaloHit* const pCaloHit,
493  const size_t spacePointId);
494 
501  static void GetHitsInCluster(const pandora::Cluster* const pCluster,
502  pandora::CaloHitVector& sortedHits);
503 
516  static std::vector<recob::Cluster> BuildClusters(
517  util::GeometryUtilities const& gser,
518  const pandora::Cluster* const pCluster,
519  const pandora::ClusterList& clusterList,
520  const CaloHitToArtHitMap& pandoraHitToArtHitMap,
521  IdToIdVectorMap& pandoraClusterToArtClustersMap,
522  std::vector<HitVector>& hitVectors,
523  size_t& nextId,
525 
539  static recob::Cluster BuildCluster(util::GeometryUtilities const& gser,
540  const size_t id,
541  const HitVector& hitVector,
542  const HitList& isolatedHits,
544 
554  static recob::PFParticle BuildPFParticle(const pandora::ParticleFlowObject* const pPfo,
555  const size_t pfoId,
556  const pandora::PfoVector& pfoVector);
557 
569  static bool BuildT0(const art::Event& event,
570  const pandora::ParticleFlowObject* const pPfo,
571  const pandora::PfoVector& pfoVector,
572  size_t& nextId,
573  anab::T0& t0);
574 
583  template <typename A, typename B>
584  static void AddAssociation(const art::Event& event,
585  const std::string& instanceLabel,
586  const size_t idA,
587  const size_t idB,
588  std::unique_ptr<art::Assns<A, B>>& association);
589 
598  template <typename A, typename B>
599  static void AddAssociation(const art::Event& event,
600  const std::string& instanceLabel,
601  const size_t idA,
602  const IdToIdVectorMap& aToBMap,
603  std::unique_ptr<art::Assns<A, B>>& association);
604 
613  template <typename A, typename B>
614  static void AddAssociation(const art::Event& event,
615  const std::string& instanceLabel,
616  const size_t idA,
617  const std::vector<art::Ptr<B>>& bVector,
618  std::unique_ptr<art::Assns<A, B>>& association);
619  };
620 
621  //------------------------------------------------------------------------------------------------------------------------------------------
622 
623  template <typename T>
624  inline size_t LArPandoraOutput::GetId(const T* const pT, const std::list<const T*>& tList)
625  {
626  typename std::list<const T*>::const_iterator it(std::find(tList.begin(), tList.end(), pT));
627 
628  if (it == tList.end())
629  throw cet::exception("LArPandora")
630  << " LArPandoraOutput::GetId --- can't find the id of supplied object";
631 
632  return static_cast<size_t>(std::distance(tList.begin(), it));
633  }
634 
635  //------------------------------------------------------------------------------------------------------------------------------------------
636 
637  template <typename T>
638  inline size_t LArPandoraOutput::GetId(const T* const pT, const std::vector<const T*>& tVector)
639  {
641  std::find(tVector.begin(), tVector.end(), pT));
642 
643  if (it == tVector.end())
644  throw cet::exception("LArPandora")
645  << " LArPandoraOutput::GetId --- can't find the id of supplied object";
646 
647  return static_cast<size_t>(std::distance(tVector.begin(), it));
648  }
649 
650  //------------------------------------------------------------------------------------------------------------------------------------------
651 
652  template <typename A, typename B>
653  inline void LArPandoraOutput::AddAssociation(const art::Event& event,
654  const std::string& instanceLabel,
655  const size_t idA,
656  const size_t idB,
657  std::unique_ptr<art::Assns<A, B>>& association)
658  {
659  const art::PtrMaker<A> makePtrA(event, instanceLabel);
660  art::Ptr<A> pA(makePtrA(idA));
661 
662  const art::PtrMaker<B> makePtrB(event, instanceLabel);
663  art::Ptr<B> pB(makePtrB(idB));
664 
665  association->addSingle(pA, pB);
666  }
667 
668  //------------------------------------------------------------------------------------------------------------------------------------------
669 
670  template <typename A, typename B>
671  inline void LArPandoraOutput::AddAssociation(const art::Event& event,
672  const std::string& instanceLabel,
673  const size_t idA,
674  const IdToIdVectorMap& aToBMap,
675  std::unique_ptr<art::Assns<A, B>>& association)
676  {
677  IdToIdVectorMap::const_iterator it(aToBMap.find(idA));
678  if (it == aToBMap.end())
679  throw cet::exception("LArPandora")
680  << " LArPandoraOutput::AddAssociation --- id doesn't exists in the assocaition map";
681 
682  const art::PtrMaker<A> makePtrA(event, instanceLabel);
683  art::Ptr<A> pA(makePtrA(idA));
684 
685  const art::PtrMaker<B> makePtrB(event, instanceLabel);
686  for (const size_t idB : it->second) {
687  art::Ptr<B> pB(makePtrB(idB));
688  association->addSingle(pA, pB);
689  }
690  }
691 
692  //------------------------------------------------------------------------------------------------------------------------------------------
693 
694  template <typename A, typename B>
695  inline void LArPandoraOutput::AddAssociation(const art::Event& event,
696  const std::string& instanceLabel,
697  const size_t idA,
698  const std::vector<art::Ptr<B>>& bVector,
699  std::unique_ptr<art::Assns<A, B>>& association)
700  {
701  const art::PtrMaker<A> makePtrA(event, instanceLabel);
702  art::Ptr<A> pA(makePtrA(idA));
703 
704  for (const art::Ptr<B>& pB : bVector)
705  association->addSingle(pA, pB);
706  }
707 
708 } // namespace lar_pandora
709 
710 #endif // LAR_PANDORA_OUTPUT_H
code to link reconstructed objects back to the MC truth information
std::map< int, art::Ptr< recob::Hit > > IdToHitMap
Definition: ILArPandora.h:24
Interface class for LArPandora producer modules, which reconstruct recob::PFParticles from recob::Hit...
Namespace for general, non-LArSoft-specific utilities.
Definition: PIDAAlg.h:26
const pandora::Pandora * m_pPrimaryPandora
Reconstruction base classes.
std::unique_ptr< std::vector< larpandoraobj::PFParticleMetadata > > PFParticleMetadataCollection
std::unique_ptr< art::Assns< recob::PFParticle, recob::Slice > > PFParticleToSliceCollection
std::unique_ptr< std::vector< recob::Slice > > SliceCollection
std::unique_ptr< std::vector< recob::PFParticle > > PFParticleCollection
std::string m_testBeamInteractionVerticesInstanceLabel
The label for the test beam interaction vertices.
std::unique_ptr< std::vector< recob::Vertex > > VertexCollection
std::string m_allOutcomesInstanceLabel
The label for the instance producing all outcomes.
std::map< size_t, IdVector > IdToIdVectorMap
Set of hits with a 2D structure.
Definition: Cluster.h:69
std::unique_ptr< art::Assns< recob::PFParticle, larpandoraobj::PFParticleMetadata > > PFParticleToMetadataCollection
intermediate_table::const_iterator const_iterator
bool m_isNeutrinoRecoOnlyNoSlicing
If we are running the neutrino reconstruction only with no slicing.
Definition: T0.h:16
Cluster finding and building.
Definition of vertex object for LArSoft.
Definition: Vertex.h:35
std::unique_ptr< art::Assns< recob::PFParticle, recob::Cluster > > PFParticleToClusterCollection
std::string m_hitfinderModuleLabel
The hit finder module label.
Algorithm collection class computing cluster parameters.
std::unique_ptr< art::Assns< recob::Slice, recob::Hit > > SliceToHitCollection
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
std::vector< size_t > IdVector
std::unique_ptr< art::Assns< recob::PFParticle, anab::T0 > > PFParticleToT0Collection
std::unique_ptr< art::Assns< recob::SpacePoint, recob::Hit > > SpacePointToHitCollection
std::unique_ptr< std::vector< recob::Cluster > > ClusterCollection
std::map< const pandora::CaloHit *, art::Ptr< recob::Hit > > CaloHitToArtHitMap
std::unique_ptr< art::Assns< recob::PFParticle, recob::Vertex > > PFParticleToVertexCollection
Declaration of cluster object.
bool m_shouldProduceTestBeamInteractionVertices
Whether to write the test beam interaction vertices in a separate collection.
std::unique_ptr< art::Assns< recob::PFParticle, recob::SpacePoint > > PFParticleToSpacePointCollection
std::vector< art::Ptr< recob::Hit > > HitVector
Hierarchical representation of particle flow.
Definition: PFParticle.h:44
Utility object to perform functions of association.
std::unique_ptr< std::vector< anab::T0 > > T0Collection
bool m_shouldProduceAllOutcomes
If all outcomes should be produced in separate collections (choose false if you only require the cons...
bool m_shouldProduceSlices
Whether to produce output slices e.g. may not want to do this if only (re)processing single slices...
std::pair< unsigned short, unsigned short > GetSliceIndex(std::string typeName, int uID)
Definition: Utils.cxx:4939
std::vector< art::Ptr< recob::Vertex > > VertexVector
boost::graph_traits< ModuleGraph >::vertex_descriptor Vertex
Definition: ModuleGraph.h:25
std::unique_ptr< std::vector< recob::SpacePoint > > SpacePointCollection
TCEvent evt
Definition: DataStructs.cxx:8
std::set< art::Ptr< recob::Hit > > HitList
helper function for LArPandoraInterface producer module
std::unique_ptr< art::Assns< recob::Cluster, recob::Hit > > ClusterToHitCollection
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
Event finding and building.