LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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 
15 
17 
20 
21 #include "Pandora/PandoraInternal.h"
22 
23 namespace art {class EDProducer;}
24 namespace pandora {class Pandora;}
25 
26 //------------------------------------------------------------------------------------------------------------------------------------------
27 
28 namespace lar_pandora
29 {
30 
32 {
33 public:
34  typedef std::vector<size_t> IdVector;
35  typedef std::map<size_t, IdVector> IdToIdVectorMap;
36  typedef std::map<const pandora::CaloHit *, art::Ptr<recob::Hit> > CaloHitToArtHitMap;
37 
38  typedef std::unique_ptr< std::vector<recob::PFParticle> > PFParticleCollection;
39  typedef std::unique_ptr< std::vector<recob::Vertex> > VertexCollection;
40  typedef std::unique_ptr< std::vector<recob::Cluster> > ClusterCollection;
41  typedef std::unique_ptr< std::vector<recob::SpacePoint> > SpacePointCollection;
42  typedef std::unique_ptr< std::vector<anab::T0> > T0Collection;
43  typedef std::unique_ptr< std::vector<larpandoraobj::PFParticleMetadata> > PFParticleMetadataCollection;
44  typedef std::unique_ptr< std::vector<recob::Slice> > SliceCollection;
45 
46  typedef std::unique_ptr< art::Assns<recob::PFParticle, larpandoraobj::PFParticleMetadata> > PFParticleToMetadataCollection;
47  typedef std::unique_ptr< art::Assns<recob::PFParticle, recob::SpacePoint> > PFParticleToSpacePointCollection;
48  typedef std::unique_ptr< art::Assns<recob::PFParticle, recob::Cluster> > PFParticleToClusterCollection;
49  typedef std::unique_ptr< art::Assns<recob::PFParticle, recob::Vertex> > PFParticleToVertexCollection;
50  typedef std::unique_ptr< art::Assns<recob::PFParticle, anab::T0> > PFParticleToT0Collection;
51  typedef std::unique_ptr< art::Assns<recob::PFParticle, recob::Slice> > PFParticleToSliceCollection;
52 
53  typedef std::unique_ptr< art::Assns<recob::Cluster, recob::Hit> > ClusterToHitCollection;
54  typedef std::unique_ptr< art::Assns<recob::SpacePoint, recob::Hit> > SpacePointToHitCollection;
55  typedef std::unique_ptr< art::Assns<recob::Slice, recob::Hit> > SliceToHitCollection;
56 
60  class Settings
61  {
62  public:
66  Settings();
67 
71  void Validate() const;
72 
73  const pandora::Pandora *m_pPrimaryPandora;
79  std::string m_hitfinderModuleLabel;
80  };
81 
89  static void ProduceArtOutput(const Settings &settings, const IdToHitMap &idToHitMap, art::Event &evt);
90 
91 private:
101  static bool GetPandoraInstance(const pandora::Pandora *const pPrimaryPandora, const std::string &name,
102  const pandora::Pandora *&pPandoraInstance);
103 
110  static void GetPandoraSlices(const pandora::Pandora *const pPrimaryPandora, pandora::PfoVector &slicePfos);
111 
119  static bool IsClearCosmic(const pandora::ParticleFlowObject *const pPfo);
120 
128  static bool IsFromSlice(const pandora::ParticleFlowObject *const pPfo);
129 
137  static unsigned int GetSliceIndex(const pandora::ParticleFlowObject *const pPfo);
138 
146  static pandora::PfoVector CollectPfos(const pandora::Pandora *const pPrimaryPandora);
147 
155  static pandora::PfoVector CollectAllPfoOutcomes(const pandora::Pandora *const pPrimaryPandora);
156 
163  static void CollectPfos(const pandora::PfoList &parentPfoList, pandora::PfoVector &pfoVector);
164 
174  static pandora::VertexVector CollectVertices(const pandora::PfoVector &pfoVector, IdToIdVectorMap &pfoToVerticesMap);
175 
185  static pandora::ClusterList CollectClusters(const pandora::PfoVector &pfoVector, IdToIdVectorMap &pfoToClustersMap);
186 
193  static void Collect3DHits(const pandora::ParticleFlowObject *const pPfo, pandora::CaloHitVector &caloHits);
194 
204  static pandora::CaloHitList Collect3DHits(const pandora::PfoVector &pfoVector, IdToIdVectorMap &pfoToThreeDHitsMap);
205 
214  template <typename T>
215  static size_t GetId(const T *const pT, const std::list<const T*> &tList);
216 
225  template <typename T>
226  static size_t GetId(const T *const pT, const std::vector<const T*> &tVector);
227 
236  static void GetPandoraToArtHitMap(const pandora::ClusterList &clusterList, const pandora::CaloHitList &threeDHitList,
237  const IdToHitMap &idToHitMap, CaloHitToArtHitMap &pandoraHitToArtHitMap);
238 
245  static art::Ptr<recob::Hit> GetHit(const IdToHitMap &idToHitMap, const pandora::CaloHit *const pCaloHit);
246 
253  static void BuildVertices(const pandora::VertexVector &vertexVector, VertexCollection &outputVertices);
254 
266  static void BuildSpacePoints(const art::Event &event, const art::EDProducer *const pProducer, const std::string &instanceLabel,
267  const pandora::CaloHitList &threeDHitList, const CaloHitToArtHitMap &pandoraHitToArtHitMap, SpacePointCollection &outputSpacePoints,
268  SpacePointToHitCollection &outputSpacePointsToHits);
269 
284  static void BuildClusters(const art::Event &event, const art::EDProducer *const pProducer, const std::string &instanceLabel,
285  const pandora::ClusterList &clusterList, const CaloHitToArtHitMap &pandoraHitToArtHitMap, const IdToIdVectorMap &pfoToClustersMap,
286  ClusterCollection &outputClusters, ClusterToHitCollection &outputClustersToHits, IdToIdVectorMap &pfoToArtClustersMap);
287 
303  static void BuildPFParticles(const art::Event &event, const art::EDProducer *const pProducer, const std::string &instanceLabel,
304  const pandora::PfoVector &pfoVector, const IdToIdVectorMap &pfoToVerticesMap, const IdToIdVectorMap &pfoToThreeDHitsMap,
305  const IdToIdVectorMap &pfoToArtClustersMap, PFParticleCollection &outputParticles,
306  PFParticleToVertexCollection &outputParticlesToVertices, PFParticleToSpacePointCollection &outputParticlesToSpacePoints,
307  PFParticleToClusterCollection &outputParticlesToClusters);
308 
318  static void BuildParticleMetadata(const art::Event &event, const art::EDProducer *const pProducer, const std::string &instanceLabel,
319  const pandora::PfoVector &pfoVector, PFParticleMetadataCollection &outputParticleMetadata,
320  PFParticleToMetadataCollection &outputParticlesToMetadata);
321 
336  static void BuildSlices(const Settings &settings, const pandora::Pandora *const pPrimaryPandora, const art::Event &event,
337  const art::EDProducer *const pProducer, const std::string &instanceLabel, const pandora::PfoVector &pfoVector,
338  const IdToHitMap &idToHitMap, SliceCollection &outputSlices, PFParticleToSliceCollection &outputParticlesToSlices,
339  SliceToHitCollection &outputSlicesToHits);
340 
346  static unsigned int BuildDummySlice(SliceCollection &outputSlices);
347 
361  static void CopyAllHitsToSingleSlice(const Settings &settings, const art::Event &event, const art::EDProducer *const pProducer,
362  const std::string &instanceLabel, const pandora::PfoVector &pfoVector, const IdToHitMap &idToHitMap, SliceCollection &outputSlices,
363  PFParticleToSliceCollection &outputParticlesToSlices, SliceToHitCollection &outputSlicesToHits);
364 
376  static unsigned int BuildSlice(const pandora::ParticleFlowObject *const pParentPfo, const art::Event &event,
377  const art::EDProducer *const pProducer, const std::string &instanceLabel, const IdToHitMap &idToHitMap, SliceCollection &outputSlices,
378  SliceToHitCollection &outputSlicesToHits);
379 
391  static void BuildT0s(const art::Event &event, const art::EDProducer *const pProducer, const std::string &instanceLabel,
392  const pandora::PfoVector &pfoVector, T0Collection &outputT0s, const CaloHitToArtHitMap &pandoraHitToArtHitMap,
393  PFParticleToT0Collection &outputParticlesToT0s);
394 
403  static recob::Vertex BuildVertex(const pandora::Vertex *const pVertex, const size_t vertexId);
404 
413  static recob::SpacePoint BuildSpacePoint(const pandora::CaloHit *const pCaloHit, const size_t spacePointId);
414 
421  static void GetHitsInCluster(const pandora::Cluster *const pCluster, pandora::CaloHitVector &sortedHits);
422 
435  static std::vector<recob::Cluster> BuildClusters(const pandora::Cluster *const pCluster, const pandora::ClusterList &clusterList,
436  const CaloHitToArtHitMap &pandoraHitToArtHitMap, IdToIdVectorMap &pandoraClusterToArtClustersMap, std::vector<HitVector> &hitVectors,
437  size_t &nextId, cluster::ClusterParamsAlgBase &algo);
438 
452  static recob::Cluster BuildCluster(const size_t id, const HitVector &hitVector, const HitList &isolatedHits,
454 
464  static recob::PFParticle BuildPFParticle(const pandora::ParticleFlowObject *const pPfo, const size_t pfoId, const pandora::PfoVector &pfoVector);
465 
477  static bool BuildT0(const pandora::ParticleFlowObject *const pPfo, const pandora::PfoVector &pfoVector, size_t &nextId,
478  const CaloHitToArtHitMap &pandoraHitToArtHitMap, anab::T0 &t0);
479 
488  static double CalculateT0(const art::Ptr<recob::Hit> hit, const pandora::CaloHit *const pCaloHit);
489 
499  template <typename A, typename B>
500  static void AddAssociation(const art::Event &event, const art::EDProducer *const pProducer, const std::string &instanceLabel,
501  const size_t idA, const size_t idB, std::unique_ptr< art::Assns<A, B> > &association);
502 
512  template <typename A, typename B>
513  static void AddAssociation(const art::Event &event, const art::EDProducer *const pProducer, const std::string &instanceLabel,
514  const size_t idA, const IdToIdVectorMap &aToBMap, std::unique_ptr< art::Assns<A, B> > &association);
515 
525  template <typename A, typename B>
526  static void AddAssociation(const art::Event &event, const art::EDProducer *const pProducer, const std::string &instanceLabel,
527  const size_t idA, const std::vector< art::Ptr<B> > &bVector, std::unique_ptr< art::Assns<A, B> > &association);
528 };
529 
530 //------------------------------------------------------------------------------------------------------------------------------------------
531 
532 template <typename T>
533 inline size_t LArPandoraOutput::GetId(const T *const pT, const std::list<const T*> &tList)
534 {
535  typename std::list<const T*>::const_iterator it(std::find(tList.begin(), tList.end(), pT));
536 
537  if (it == tList.end())
538  throw cet::exception("LArPandora") << " LArPandoraOutput::GetId --- can't find the id of supplied object";
539 
540  return static_cast<size_t>(std::distance(tList.begin(), it));
541 }
542 
543 //------------------------------------------------------------------------------------------------------------------------------------------
544 
545 template <typename T>
546 inline size_t LArPandoraOutput::GetId(const T *const pT, const std::vector<const T*> &tVector)
547 {
548  typename std::vector<const T*>::const_iterator it(std::find(tVector.begin(), tVector.end(), pT));
549 
550  if (it == tVector.end())
551  throw cet::exception("LArPandora") << " LArPandoraOutput::GetId --- can't find the id of supplied object";
552 
553  return static_cast<size_t>(std::distance(tVector.begin(), it));
554 }
555 
556 //------------------------------------------------------------------------------------------------------------------------------------------
557 
558 template <typename A, typename B>
559 inline void LArPandoraOutput::AddAssociation(const art::Event &event, const art::EDProducer *const pProducer,
560  const std::string &instanceLabel, const size_t idA, const size_t idB, std::unique_ptr< art::Assns<A, B> > &association)
561 {
562  const art::PtrMaker<A> makePtrA(event, *pProducer, instanceLabel);
563  art::Ptr<A> pA(makePtrA(idA));
564 
565  const art::PtrMaker<B> makePtrB(event, *pProducer, instanceLabel);
566  art::Ptr<B> pB(makePtrB(idB));
567 
568  association->addSingle(pA, pB);
569 }
570 
571 //------------------------------------------------------------------------------------------------------------------------------------------
572 
573 template <typename A, typename B>
574 inline void LArPandoraOutput::AddAssociation(const art::Event &event, const art::EDProducer *const pProducer,
575  const std::string &instanceLabel, const size_t idA, const IdToIdVectorMap &aToBMap, std::unique_ptr< art::Assns<A, B> > &association)
576 {
577  IdToIdVectorMap::const_iterator it(aToBMap.find(idA));
578  if (it == aToBMap.end())
579  throw cet::exception("LArPandora") << " LArPandoraOutput::AddAssociation --- id doesn't exists in the assocaition map";
580 
581  const art::PtrMaker<A> makePtrA(event, *pProducer, instanceLabel);
582  art::Ptr<A> pA(makePtrA(idA));
583 
584  const art::PtrMaker<B> makePtrB(event, *pProducer, instanceLabel);
585  for (const size_t idB : it->second)
586  {
587  art::Ptr<B> pB(makePtrB(idB));
588  association->addSingle(pA, pB);
589  }
590 }
591 
592 //------------------------------------------------------------------------------------------------------------------------------------------
593 
594 template <typename A, typename B>
595 inline void LArPandoraOutput::AddAssociation(const art::Event &event, const art::EDProducer *const pProducer,
596  const std::string &instanceLabel, const size_t idA, const std::vector< art::Ptr<B> > &bVector,
597  std::unique_ptr< art::Assns<A, B> > &association)
598 {
599  const art::PtrMaker<A> makePtrA(event, *pProducer, instanceLabel);
600  art::Ptr<A> pA(makePtrA(idA));
601 
602  for (const art::Ptr<B> &pB : bVector)
603  association->addSingle(pA, pB);
604 }
605 
606 } // namespace lar_pandora
607 
608 #endif // LAR_PANDORA_OUTPUT_H
code to link reconstructed objects back to the MC truth information
std::unique_ptr< art::Assns< recob::PFParticle, anab::T0 > > PFParticleToT0Collection
Interface class for LArPandora producer modules, which reconstruct recob::PFParticles from recob::Hit...
std::unique_ptr< std::vector< recob::Cluster > > ClusterCollection
const pandora::Pandora * m_pPrimaryPandora
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:71
std::map< int, art::Ptr< recob::Hit > > IdToHitMap
Definition: ILArPandora.h:20
bool m_isNeutrinoRecoOnlyNoSlicing
If we are running the neutrino reconstruction only with no slicing.
Definition: T0.h:19
std::map< const pandora::CaloHit *, art::Ptr< recob::Hit > > CaloHitToArtHitMap
std::unique_ptr< std::vector< recob::SpacePoint > > SpacePointCollection
Definition of vertex object for LArSoft.
Definition: Vertex.h:35
std::unique_ptr< std::vector< recob::Slice > > SliceCollection
std::string m_hitfinderModuleLabel
The hit finder module label.
Algorithm collection class computing cluster parameters.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
std::vector< size_t > IdVector
std::unique_ptr< art::Assns< recob::SpacePoint, recob::Hit > > SpacePointToHitCollection
intermediate_table::const_iterator const_iterator
std::unique_ptr< art::Assns< recob::PFParticle, recob::Slice > > PFParticleToSliceCollection
std::unique_ptr< std::vector< recob::Vertex > > VertexCollection
std::unique_ptr< std::vector< larpandoraobj::PFParticleMetadata > > PFParticleMetadataCollection
std::unique_ptr< std::vector< recob::PFParticle > > PFParticleCollection
Declaration of cluster object.
std::unique_ptr< art::Assns< recob::PFParticle, larpandoraobj::PFParticleMetadata > > PFParticleToMetadataCollection
std::vector< art::Ptr< recob::Hit > > HitVector
Detector simulation of raw signals on wires.
std::unique_ptr< art::Assns< recob::PFParticle, recob::Vertex > > PFParticleToVertexCollection
Hierarchical representation of particle flow.
Definition: PFParticle.h:44
Utility object to perform functions of association.
std::unique_ptr< std::vector< anab::T0 > > T0Collection
std::unique_ptr< art::Assns< recob::PFParticle, recob::Cluster > > PFParticleToClusterCollection
Interface for a algorithm class computing cluster parameters.
bool m_shouldProduceAllOutcomes
If all outcomes should be produced in separate collections (choose false if you only require the cons...
std::pair< unsigned short, unsigned short > GetSliceIndex(std::string typeName, int uID)
Definition: Utils.cxx:4496
HLT enums.
std::unique_ptr< art::Assns< recob::Slice, recob::Hit > > SliceToHitCollection
std::unique_ptr< art::Assns< recob::PFParticle, recob::SpacePoint > > PFParticleToSpacePointCollection
TCEvent evt
Definition: DataStructs.cxx:5
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.
std::vector< art::Ptr< recob::Vertex > > VertexVector