All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LArPandoraOutput.h
Go to the documentation of this file.
1 /**
2  * @file larpandora/LArPandoraInterface/LArPandoraOutput.h
3  *
4  * @brief Helper functions for processing outputs from pandora
5  *
6  */
7 #ifndef LAR_PANDORA_OUTPUT_H
8 #define LAR_PANDORA_OUTPUT_H
9 
10 #include "art/Persistency/Common/PtrMaker.h"
12 
13 namespace recob {
14  class Cluster;
15  class PFParticleMetadata;
16 }
17 
18 namespace cluster { class ClusterParamsAlgBase; }
19 
22 
30 
31 #include "Api/PandoraApi.h"
32 
33 namespace util {
34  class GeometryUtilities;
35 }
36 
37 #include <map>
38 #include <vector>
39 
40 //------------------------------------------------------------------------------------------------------------------------------------------
41 
42 namespace lar_pandora {
43 
45  public:
46  typedef std::vector<size_t> IdVector;
47  typedef std::map<size_t, IdVector> IdToIdVectorMap;
48  typedef std::map<const pandora::CaloHit*, art::Ptr<recob::Hit>> CaloHitToArtHitMap;
49 
50  typedef std::unique_ptr<std::vector<recob::PFParticle>> PFParticleCollection;
51  typedef std::unique_ptr<std::vector<recob::Vertex>> VertexCollection;
52  typedef std::unique_ptr<std::vector<recob::Cluster>> ClusterCollection;
53  typedef std::unique_ptr<std::vector<recob::SpacePoint>> SpacePointCollection;
54  typedef std::unique_ptr<std::vector<anab::T0>> T0Collection;
55  typedef std::unique_ptr<std::vector<larpandoraobj::PFParticleMetadata>>
57  typedef std::unique_ptr<std::vector<recob::Slice>> SliceCollection;
58 
59  typedef std::unique_ptr<art::Assns<recob::PFParticle, larpandoraobj::PFParticleMetadata>>
61  typedef std::unique_ptr<art::Assns<recob::PFParticle, recob::SpacePoint>>
63  typedef std::unique_ptr<art::Assns<recob::PFParticle, recob::Cluster>>
65  typedef std::unique_ptr<art::Assns<recob::PFParticle, recob::Vertex>>
67  typedef std::unique_ptr<art::Assns<recob::PFParticle, anab::T0>> PFParticleToT0Collection;
68  typedef std::unique_ptr<art::Assns<recob::PFParticle, recob::Slice>>
70 
71  typedef std::unique_ptr<art::Assns<recob::Cluster, recob::Hit>> ClusterToHitCollection;
72  typedef std::unique_ptr<art::Assns<recob::SpacePoint, recob::Hit>> SpacePointToHitCollection;
73  typedef std::unique_ptr<art::Assns<recob::Slice, recob::Hit>> SliceToHitCollection;
74 
75  /**
76  * @brief Settings class
77  */
78  class Settings {
79  public:
80  /**
81  * @brief Default constructor
82  */
83  Settings();
84 
85  /**
86  * @brief Check the parameters and throw an exception if they are not valid
87  */
88  void Validate() const;
89 
90  const pandora::Pandora* m_pPrimaryPandora; ///<
92  bool
93  m_shouldProduceSlices; ///< Whether to produce output slices e.g. may not want to do this if only (re)processing single slices
94  bool
95  m_shouldProduceAllOutcomes; ///< If all outcomes should be produced in separate collections (choose false if you only require the consolidated output)
96  std::string m_allOutcomesInstanceLabel; ///< The label for the instance producing all outcomes
97  bool
98  m_shouldProduceTestBeamInteractionVertices; ///< Whether to write the test beam interaction vertices in a separate collection
99  std::string
100  m_testBeamInteractionVerticesInstanceLabel; ///< The label for the test beam interaction vertices
101  bool
102  m_isNeutrinoRecoOnlyNoSlicing; ///< If we are running the neutrino reconstruction only with no slicing
103  std::string m_hitfinderModuleLabel; ///< The hit finder module label
104  };
105 
106  /**
107  * @brief Convert the Pandora PFOs into ART clusters and write into ART event
108  *
109  * @param settings the settings
110  * @param idToHitMap the mapping from Pandora hit ID to ART hit
111  * @param evt the ART event
112  */
113  static void ProduceArtOutput(const Settings& settings,
114  const IdToHitMap& idToHitMap,
115  art::Event& evt);
116 
117  /**
118  * @brief Get the address of a pandora instance with a given name
119  *
120  * @param pPrimaryPandora the primary pandora instance
121  * @param name the name of the instance to collect
122  * @param pPandoraInstance the output address of the pandora instance requested
123  *
124  * @return if the pandora instance could be found
125  */
126  static bool GetPandoraInstance(const pandora::Pandora* const pPrimaryPandora,
127  const std::string& name,
128  const pandora::Pandora*& pPandoraInstance);
129 
130  /**
131  * @brief Get the slice pfos - one pfo per slice
132  *
133  * @param pPrimaryPandora the primary pandora instance
134  * @param slicePfos the output vector of slice pfos
135  */
136  static void GetPandoraSlices(const pandora::Pandora* const pPrimaryPandora,
137  pandora::PfoVector& slicePfos);
138 
139  /**
140  * @brief Check if the input pfo is an unambiguous cosmic ray
141  *
142  * @param pPfo the input pfo
143  *
144  * @return if the input pfo is a clear cosmic ray
145  */
146  static bool IsClearCosmic(const pandora::ParticleFlowObject* const pPfo);
147 
148  /**
149  * @brief Check if the input pfo is from a slice
150  *
151  * @param pPfo the input pfo
152  *
153  * @return if the input pfo is from a slice
154  */
155  static bool IsFromSlice(const pandora::ParticleFlowObject* const pPfo);
156 
157  /**
158  * @brief Get the index of the slice from which this pfo was produced
159  *
160  * @param pPfo the input pfo
161  *
162  * @return the slice index
163  */
164  static unsigned int GetSliceIndex(const pandora::ParticleFlowObject* const pPfo);
165 
166  /**
167  * @brief Collect the current pfos (including all downstream pfos) from the master pandora instance
168  *
169  * @param pPrimaryPandora address of master pandora instance
170  *
171  * @return a sorted list of all pfos to convert to ART PFParticles
172  */
173  static pandora::PfoVector CollectPfos(const pandora::Pandora* const pPrimaryPandora);
174 
175  /**
176  * @brief Collect the pfos (including all downstream pfos) from the master and daughter pandora instances
177  *
178  * @param pPrimaryPandora address of master pandora instance
179  *
180  * @return a sorted list of all pfos to convert to ART PFParticles
181  */
182  static pandora::PfoVector CollectAllPfoOutcomes(const pandora::Pandora* const pPrimaryPandora);
183 
184  /**
185  * @brief Collect a sorted list of all downstream pfos of an input list of parent
186  *
187  * @param parentPfoList the input list of parent pfos
188  * @param pfoVector the sorted output list of all downstream pfos
189  */
190  static void CollectPfos(const pandora::PfoList& parentPfoList, pandora::PfoVector& pfoVector);
191 
192  /**
193  * @brief Collect all vertices contained in the input pfo list
194  * Order is guaranteed provided pfoVector is ordered
195  *
196  * @param pfoVector the input list of pfos
197  * @param pfoToVerticesMap the output mapping from pfo ID to vertex IDs (zero or one)
198  * @param fCriteria function to extract vertex from pfo
199  *
200  * @return the list of vertices collected
201  */
203  const pandora::PfoVector& pfoVector,
204  IdToIdVectorMap& pfoToVerticesMap,
205  std::function<const pandora::Vertex* const(const pandora::ParticleFlowObject* const)>
206  fCriteria);
207 
208  /**
209  * @brief Collect a sorted list of all 2D clusters contained in the input pfo list
210  * Order is guaranteed provided pfoVector is ordered
211  *
212  * @param pfoVector the input list of pfos
213  * @param pfoToClustersMap the output mapping from pfo ID to cluster IDs
214  *
215  * @return the list of clusters collected
216  */
217  static pandora::ClusterList CollectClusters(const pandora::PfoVector& pfoVector,
218  IdToIdVectorMap& pfoToClustersMap);
219 
220  /**
221  * @brief Collect a sorted vector of all 3D hits in the input pfo
222  *
223  * @param pPfo the input pfo
224  * @param caloHits the sorted output vector of 3D hits
225  */
226  static void Collect3DHits(const pandora::ParticleFlowObject* const pPfo,
227  pandora::CaloHitVector& caloHits);
228 
229  /**
230  * @brief Collect a sorted list of all 3D hits contained in the input pfo list
231  * Order is guaranteed provided pfoVector is ordered
232  *
233  * @param pfoVector the input list of pfos
234  * @param pfoToThreeDHitsMap the output mapping from pfo ID to 3D hit IDs
235  *
236  * @return the list of 3D hits collected
237  */
238  static pandora::CaloHitList Collect3DHits(const pandora::PfoVector& pfoVector,
239  IdToIdVectorMap& pfoToThreeDHitsMap);
240 
241  /**
242  * @brief Find the index of an input object in an input list. Throw an exception if it doesn't exist
243  *
244  * @param pT the input object for which the ID should be found
245  * @param tList a list of objects of type pT to query
246  *
247  * @return the ID of the input object
248  */
249  template <typename T>
250  static size_t GetId(const T* const pT, const std::list<const T*>& tList);
251 
252  /**
253  * @brief Find the index of an input object in an input vector. Throw an exception if it doesn't exist
254  *
255  * @param pT the input object for which the ID should be found
256  * @param tVector a list of objects of type pT to query
257  *
258  * @return the ID of the input object
259  */
260  template <typename T>
261  static size_t GetId(const T* const pT, const std::vector<const T*>& tVector);
262 
263  /**
264  * @brief Collect all 2D and 3D hits that were used / produced in the reconstruction and map them to their corresponding ART hit
265  *
266  * @param clusterList input list of all 2D clusters to be output
267  * @param threeDHitList input list of all 3D hits to be output (as spacepoints)
268  * @param idToHitMap input mapping from pandora hit ID to ART hit
269  * @param pandoraHitToArtHitMap output mapping from pandora hit to ART hit
270  */
271  static void GetPandoraToArtHitMap(const pandora::ClusterList& clusterList,
272  const pandora::CaloHitList& threeDHitList,
273  const IdToHitMap& idToHitMap,
274  CaloHitToArtHitMap& pandoraHitToArtHitMap);
275 
276  /**
277  * @brief Look up ART hit from an input Pandora hit
278  *
279  * @param idToHitMap the mapping between Pandora and ART hits
280  * @param pCaloHit the input Pandora hit (2D)
281  */
282  static art::Ptr<recob::Hit> GetHit(const IdToHitMap& idToHitMap,
283  const pandora::CaloHit* const pCaloHit);
284 
285  /**
286  * @brief Convert pandora vertices to ART vertices and add them to the output vector
287  *
288  * @param vertexVector the input list of pandora vertices
289  * @param outputVertices the output vector of ART vertices
290  */
291  static void BuildVertices(const pandora::VertexVector& vertexVector,
292  VertexCollection& outputVertices);
293 
294  /**
295  * @brief Convert pandora 3D hits to ART spacepoints and add them to the output vector
296  * Create the associations between spacepoints and hits
297  *
298  * @param event the art event
299  * @param threeDHitList the input list of 3D hits to convert
300  * @param pandoraHitToArtHitMap the input mapping from pandora hits to ART hits
301  * @param outputSpacePoints the output vector of spacepoints
302  * @param outputSpacePointsToHits the output associations between spacepoints and hits
303  */
304  static void BuildSpacePoints(const art::Event& event,
305  const std::string& instanceLabel,
306  const pandora::CaloHitList& threeDHitList,
307  const CaloHitToArtHitMap& pandoraHitToArtHitMap,
308  SpacePointCollection& outputSpacePoints,
309  SpacePointToHitCollection& outputSpacePointsToHits);
310 
311  /**
312  * @brief Convert pandora 2D clusters to ART clusters and add them to the output vector
313  * Create the associations between clusters and hits.
314  * For multiple drift volumes, each pandora cluster can correspond to multiple ART clusters.
315  *
316  * @param event the art event
317  * @param clusterList the input list of 2D pandora clusters to convert
318  * @param pandoraHitToArtHitMap the input mapping from pandora hits to ART hits
319  * @param pfoToClustersMap the input mapping from pfo ID to cluster IDs
320  * @param outputClusters the output vector of clusters
321  * @param outputClustersToHits the output associations between clusters and hits
322  * @param pfoToArtClustersMap the output mapping from pfo ID to art cluster ID
323  */
324  static void BuildClusters(const art::Event& event,
325  const std::string& instanceLabel,
326  const pandora::ClusterList& clusterList,
327  const CaloHitToArtHitMap& pandoraHitToArtHitMap,
328  const IdToIdVectorMap& pfoToClustersMap,
329  ClusterCollection& outputClusters,
330  ClusterToHitCollection& outputClustersToHits,
331  IdToIdVectorMap& pfoToArtClustersMap);
332 
333  /**
334  * @brief Convert between pfos and PFParticles and add them to the output vector
335  * Create the associations between PFParticle and vertices, spacepoints and clusters
336  *
337  * @param event the art event
338  * @param pfoVector the input list of pfos to convert
339  * @param pfoToVerticesMap the input mapping from pfo ID to vertex IDs
340  * @param pfoToThreeDHitsMap the input mapping from pfo ID to 3D hit IDs
341  * @param pfoToArtClustersMap the input mapping from pfo ID to ART cluster IDs
342  * @param outputParticle the output vector of PFParticles
343  * @param outputParticlesToVertices the output associations between PFParticles and vertices
344  * @param outputParticlesToSpacePoints the output associations between PFParticles and spacepoints
345  * @param outputParticlesToClusters the output associations between PFParticles and clusters
346  */
347  static void BuildPFParticles(const art::Event& event,
348  const std::string& instanceLabel,
349  const pandora::PfoVector& pfoVector,
350  const IdToIdVectorMap& pfoToVerticesMap,
351  const IdToIdVectorMap& pfoToThreeDHitsMap,
352  const IdToIdVectorMap& pfoToArtClustersMap,
353  PFParticleCollection& outputParticles,
354  PFParticleToVertexCollection& outputParticlesToVertices,
355  PFParticleToSpacePointCollection& outputParticlesToSpacePoints,
356  PFParticleToClusterCollection& outputParticlesToClusters);
357 
358  /**
359  * @brief Convert Create the associations between pre-existing PFParticle and additional vertices
360  *
361  * @param event the art event
362  * @param instanceLabel instance label
363  * @param pfoVector the input list of pfos to convert
364  * @param pfoToVerticesMap the input mapping from pfo ID to vertex IDs
365  * @param outputParticlesToVertices the output associations between PFParticles and vertices
366  */
367  static void AssociateAdditionalVertices(
368  const art::Event& event,
369  const std::string& instanceLabel,
370  const pandora::PfoVector& pfoVector,
371  const IdToIdVectorMap& pfoToVerticesMap,
372  PFParticleToVertexCollection& outputParticlesToVertices);
373 
374  /**
375  * @brief Build metadata objects from a list of input pfos
376  *
377  * @param event the art event
378  * @param pfoVector the input list of pfos
379  * @param outputParticleMetadata the output vector of PFParticleMetadata
380  * @param outputParticlesToMetadata the output associations between PFParticles and metadata
381  */
382  static void BuildParticleMetadata(const art::Event& event,
383  const std::string& instanceLabel,
384  const pandora::PfoVector& pfoVector,
385  PFParticleMetadataCollection& outputParticleMetadata,
386  PFParticleToMetadataCollection& outputParticlesToMetadata);
387 
388  /**
389  * @brief Build slices - collections of hits which each describe a single particle hierarchy
390  *
391  * @param settings the settings
392  * @param pPrimaryPandora the primary pandora instance
393  * @param event the art event
394  * @param instanceLabel the label for the collections to be produced
395  * @param pfoVector the input vector of all pfos to be output
396  * @param idToHitMap input mapping from pandora hit ID to ART hit
397  * @param outputSlices the output collection of slices to populate
398  * @param outputParticlesToSlices the output association from particles to slices
399  * @param outputSlicesToHits the output association from slices to hits
400  */
401  static void BuildSlices(const Settings& settings,
402  const pandora::Pandora* const pPrimaryPandora,
403  const art::Event& event,
404  const std::string& instanceLabel,
405  const pandora::PfoVector& pfoVector,
406  const IdToHitMap& idToHitMap,
407  SliceCollection& outputSlices,
408  PFParticleToSliceCollection& outputParticlesToSlices,
409  SliceToHitCollection& outputSlicesToHits);
410 
411  /**
412  * @brief Build a new slice object with dummy information
413  *
414  * @param outputSlices the output collection of slices to populate
415  */
416  static unsigned int BuildDummySlice(SliceCollection& outputSlices);
417 
418  /**
419  * @brief Ouput a single slice containing all of the input hits
420  *
421  * @param settings the settings
422  * @param event the art event
423  * @param instanceLabel the label for the collections to be produced
424  * @param pfoVector the input vector of all pfos to be output
425  * @param idToHitMap input mapping from pandora hit ID to ART hit
426  * @param outputSlices the output collection of slices to populate
427  * @param outputParticlesToSlices the output association from particles to slices
428  * @param outputSlicesToHits the output association from slices to hits
429  */
430  static void CopyAllHitsToSingleSlice(const Settings& settings,
431  const art::Event& event,
432  const std::string& instanceLabel,
433  const pandora::PfoVector& pfoVector,
434  const IdToHitMap& idToHitMap,
435  SliceCollection& outputSlices,
436  PFParticleToSliceCollection& outputParticlesToSlices,
437  SliceToHitCollection& outputSlicesToHits);
438 
439  /**
440  * @brief Build a new slice object from a PFO, this can be a top-level parent in a hierarchy or a "slice PFO" from the slicing instance
441  *
442  * @param pParentPfo the parent pfo from which to build the slice
443  * @param event the art event
444  * @param instanceLabel the label for the collections to be produced
445  * @param idToHitMap input mapping from pandora hit ID to ART hit
446  * @param outputSlices the output collection of slices to populate
447  * @param outputSlicesToHits the output association from slices to hits
448  */
449  static unsigned int BuildSlice(const pandora::ParticleFlowObject* const pParentPfo,
450  const art::Event& event,
451  const std::string& instanceLabel,
452  const IdToHitMap& idToHitMap,
453  SliceCollection& outputSlices,
454  SliceToHitCollection& outputSlicesToHits);
455 
456  /**
457  * @brief Calculate the T0 of each pfos and add them to the output vector
458  * Create the associations between PFParticle and T0s
459  *
460  * @param event the art event
461  * @param instanceLabel the label for the collections to be produced
462  * @param pfoVector the input list of pfos
463  * @param outputT0s the output vector of T0s
464  * @param outputParticlesToT0s the output associations between PFParticles and T0s
465  */
466  static void BuildT0s(const art::Event& event,
467  const std::string& instanceLabel,
468  const pandora::PfoVector& pfoVector,
469  T0Collection& outputT0s,
470  PFParticleToT0Collection& outputParticlesToT0s);
471 
472  /**
473  * @brief Convert from a pandora vertex to an ART vertex
474  *
475  * @param pVertex the input vertex
476  * @param vertexId the id of the vertex to produce
477  *
478  * @param the ART vertex
479  */
480  static recob::Vertex BuildVertex(const pandora::Vertex* const pVertex, const size_t vertexId);
481 
482  /**
483  * @brief Convert from a pandora 3D hit to an ART spacepoint
484  *
485  * @param pCaloHit the input hit
486  * @param spacePointId the id of the space-point to produce
487  *
488  * @param the ART spacepoint
489  */
490  static recob::SpacePoint BuildSpacePoint(const pandora::CaloHit* const pCaloHit,
491  const size_t spacePointId);
492 
493  /**
494  * @brief Collect a sorted list of all 2D hits in a cluster
495  *
496  * @param pCluster the input cluster
497  * @param sortedHits the output vector of sorted 2D hits
498  */
499  static void GetHitsInCluster(const pandora::Cluster* const pCluster,
500  pandora::CaloHitVector& sortedHits);
501 
502  /**
503  * @brief Convert from a pandora 2D cluster to a vector of ART clusters (produce multiple if the cluster is split over drift volumes)
504  *
505  * @param pCluster the input cluster
506  * @param clusterList the input list of clusters
507  * @param pandoraHitToArtHitMap the input mapping from pandora hits to ART hits
508  * @param pandoraClusterToArtClustersMap output mapping from pandora cluster ID to art cluster IDs
509  * @param hitVectors the output vectors of hits for each cluster produced used to produce associations
510  * @param algo algorithm set to fill cluster members
511  *
512  * @param the vector of ART clusters
513  */
514  static std::vector<recob::Cluster> BuildClusters(
515  util::GeometryUtilities const& gser,
516  const pandora::Cluster* const pCluster,
517  const pandora::ClusterList& clusterList,
518  const CaloHitToArtHitMap& pandoraHitToArtHitMap,
519  IdToIdVectorMap& pandoraClusterToArtClustersMap,
520  std::vector<HitVector>& hitVectors,
521  size_t& nextId,
523 
524  /**
525  * @brief Build an ART cluster from an input vector of ART hits
526  *
527  * @param id the id code for the cluster
528  * @param hitVector the input vector of hits
529  * @param isolatedHits the input list of isolated hits
530  * @param algo algorithm set to fill cluster members
531  *
532  * @return the ART cluster
533  *
534  * If you don't know which algorithm to pick, StandardClusterParamsAlg is a good default.
535  * The hits that are isolated (that is, present in isolatedHits) are not fed to the cluster parameter algorithms.
536  */
538  const size_t id,
539  const HitVector& hitVector,
540  const HitList& isolatedHits,
542 
543  /**
544  * @brief Convert from a pfo to and ART PFParticle
545  *
546  * @param pPfo the input pfo to convert
547  * @param pfoId the id of the pfo to produce
548  * @param pfoVector the input list of pfos
549  *
550  * @param the ART PFParticle
551  */
552  static recob::PFParticle BuildPFParticle(const pandora::ParticleFlowObject* const pPfo,
553  const size_t pfoId,
554  const pandora::PfoVector& pfoVector);
555 
556  /**
557  * @brief If required, build a T0 for the input pfo
558  *
559  * @param event the ART event
560  * @param pPfo the input pfo
561  * @param pfoVector the input list of pfos
562  * @param nextId the ID of the T0 - will be incremented if the t0 was produced
563  * @param t0 the output T0
564  *
565  * @return if a T0 was produced (calculated from the stitching hit shift distance)
566  */
567  static bool BuildT0(const art::Event& event,
568  const pandora::ParticleFlowObject* const pPfo,
569  const pandora::PfoVector& pfoVector,
570  size_t& nextId,
571  anab::T0& t0);
572 
573  /**
574  * @brief Add an association between objects with two given ids
575  *
576  * @param event the ART event
577  * @param idA the id of an object of type A
578  * @param idB the id of an object of type B to associate to the first object
579  * @param association the output association to update
580  */
581  template <typename A, typename B>
582  static void AddAssociation(const art::Event& event,
583  const std::string& instanceLabel,
584  const size_t idA,
585  const size_t idB,
586  std::unique_ptr<art::Assns<A, B>>& association);
587 
588  /**
589  * @brief Add associations between input objects
590  *
591  * @param event the ART event
592  * @param idA the id of an object of type A
593  * @param aToBMap the input mapping from IDs of objects of type A to IDs of objects of type B to associate
594  * @param association the output association to update
595  */
596  template <typename A, typename B>
597  static void AddAssociation(const art::Event& event,
598  const std::string& instanceLabel,
599  const size_t idA,
600  const IdToIdVectorMap& aToBMap,
601  std::unique_ptr<art::Assns<A, B>>& association);
602 
603  /**
604  * @brief Add associations between input objects
605  *
606  * @param event the ART event
607  * @param idA the id of an object of type A
608  * @param bVector the input vector of IDs of objects of type B to associate
609  * @param association the output association to update
610  */
611  template <typename A, typename B>
612  static void AddAssociation(const art::Event& event,
613  const std::string& instanceLabel,
614  const size_t idA,
615  const std::vector<art::Ptr<B>>& bVector,
616  std::unique_ptr<art::Assns<A, B>>& association);
617  };
618 
619  //------------------------------------------------------------------------------------------------------------------------------------------
620 
621  template <typename T>
622  inline size_t
623  LArPandoraOutput::GetId(const T* const pT, const std::list<const T*>& tList)
624  {
625  typename std::list<const T*>::const_iterator it(std::find(tList.begin(), tList.end(), pT));
626 
627  if (it == tList.end())
628  throw cet::exception("LArPandora")
629  << " LArPandoraOutput::GetId --- can't find the id of supplied object";
630 
631  return static_cast<size_t>(std::distance(tList.begin(), it));
632  }
633 
634  //------------------------------------------------------------------------------------------------------------------------------------------
635 
636  template <typename T>
637  inline size_t
638  LArPandoraOutput::GetId(const T* const pT, const std::vector<const T*>& tVector)
639  {
640  typename std::vector<const T*>::const_iterator it(
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
654  LArPandoraOutput::AddAssociation(const art::Event& event,
655  const std::string& instanceLabel,
656  const size_t idA,
657  const size_t idB,
658  std::unique_ptr<art::Assns<A, B>>& association)
659  {
660  const art::PtrMaker<A> makePtrA(event, instanceLabel);
661  art::Ptr<A> pA(makePtrA(idA));
662 
663  const art::PtrMaker<B> makePtrB(event, instanceLabel);
664  art::Ptr<B> pB(makePtrB(idB));
665 
666  association->addSingle(pA, pB);
667  }
668 
669  //------------------------------------------------------------------------------------------------------------------------------------------
670 
671  template <typename A, typename B>
672  inline void
673  LArPandoraOutput::AddAssociation(const art::Event& event,
674  const std::string& instanceLabel,
675  const size_t idA,
676  const IdToIdVectorMap& aToBMap,
677  std::unique_ptr<art::Assns<A, B>>& association)
678  {
679  IdToIdVectorMap::const_iterator it(aToBMap.find(idA));
680  if (it == aToBMap.end())
681  throw cet::exception("LArPandora")
682  << " LArPandoraOutput::AddAssociation --- id doesn't exists in the assocaition map";
683 
684  const art::PtrMaker<A> makePtrA(event, instanceLabel);
685  art::Ptr<A> pA(makePtrA(idA));
686 
687  const art::PtrMaker<B> makePtrB(event, instanceLabel);
688  for (const size_t idB : it->second) {
689  art::Ptr<B> pB(makePtrB(idB));
690  association->addSingle(pA, pB);
691  }
692  }
693 
694  //------------------------------------------------------------------------------------------------------------------------------------------
695 
696  template <typename A, typename B>
697  inline void
698  LArPandoraOutput::AddAssociation(const art::Event& event,
699  const std::string& instanceLabel,
700  const size_t idA,
701  const std::vector<art::Ptr<B>>& bVector,
702  std::unique_ptr<art::Assns<A, B>>& association)
703  {
704  const art::PtrMaker<A> makePtrA(event, instanceLabel);
705  art::Ptr<A> pA(makePtrA(idA));
706 
707  for (const art::Ptr<B>& pB : bVector)
708  association->addSingle(pA, pB);
709  }
710 
711 } // namespace lar_pandora
712 
713 #endif // LAR_PANDORA_OUTPUT_H
static pandora::VertexVector CollectVertices(const pandora::PfoVector &pfoVector, IdToIdVectorMap &pfoToVerticesMap, std::function< const pandora::Vertex *const (const pandora::ParticleFlowObject *const)> fCriteria)
Collect all vertices contained in the input pfo list Order is guaranteed provided pfoVector is ordere...
static recob::SpacePoint BuildSpacePoint(const pandora::CaloHit *const pCaloHit, const size_t spacePointId)
Convert from a pandora 3D hit to an ART spacepoint.
Interface class for LArPandora producer modules, which reconstruct recob::PFParticles from recob::Hit...
void Validate() const
Check the parameters and throw an exception if they are not valid.
static void GetPandoraSlices(const pandora::Pandora *const pPrimaryPandora, pandora::PfoVector &slicePfos)
Get the slice pfos - one pfo per slice.
static recob::Cluster BuildCluster(util::GeometryUtilities const &gser, const size_t id, const HitVector &hitVector, const HitList &isolatedHits, cluster::ClusterParamsAlgBase &algo)
Build an ART cluster from an input vector of ART hits.
const pandora::Pandora * m_pPrimaryPandora
static bool GetPandoraInstance(const pandora::Pandora *const pPrimaryPandora, const std::string &name, const pandora::Pandora *&pPandoraInstance)
Get the address of a pandora instance with a given name.
std::unique_ptr< std::vector< larpandoraobj::PFParticleMetadata > > PFParticleMetadataCollection
process_name cluster
Definition: cheaterreco.fcl:51
static void GetPandoraToArtHitMap(const pandora::ClusterList &clusterList, const pandora::CaloHitList &threeDHitList, const IdToHitMap &idToHitMap, CaloHitToArtHitMap &pandoraHitToArtHitMap)
Collect all 2D and 3D hits that were used / produced in the reconstruction and map them to their corr...
std::unique_ptr< art::Assns< recob::PFParticle, recob::Slice > > PFParticleToSliceCollection
static void BuildClusters(const art::Event &event, const std::string &instanceLabel, const pandora::ClusterList &clusterList, const CaloHitToArtHitMap &pandoraHitToArtHitMap, const IdToIdVectorMap &pfoToClustersMap, ClusterCollection &outputClusters, ClusterToHitCollection &outputClustersToHits, IdToIdVectorMap &pfoToArtClustersMap)
Convert pandora 2D clusters to ART clusters and add them to the output vector Create the associations...
static void BuildSpacePoints(const art::Event &event, const std::string &instanceLabel, const pandora::CaloHitList &threeDHitList, const CaloHitToArtHitMap &pandoraHitToArtHitMap, SpacePointCollection &outputSpacePoints, SpacePointToHitCollection &outputSpacePointsToHits)
Convert pandora 3D hits to ART spacepoints and add them to the output vector Create the associations ...
static unsigned int BuildSlice(const pandora::ParticleFlowObject *const pParentPfo, const art::Event &event, const std::string &instanceLabel, const IdToHitMap &idToHitMap, SliceCollection &outputSlices, SliceToHitCollection &outputSlicesToHits)
Build a new slice object from a PFO, this can be a top-level parent in a hierarchy or a &quot;slice PFO&quot; f...
std::unique_ptr< std::vector< recob::Slice > > SliceCollection
std::unique_ptr< std::vector< recob::PFParticle > > PFParticleCollection
static unsigned int BuildDummySlice(SliceCollection &outputSlices)
Build a new slice object with dummy information.
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
static void GetHitsInCluster(const pandora::Cluster *const pCluster, pandora::CaloHitVector &sortedHits)
Collect a sorted list of all 2D hits in a cluster.
Set of hits with a 2D structure.
Definition: Cluster.h:71
std::unique_ptr< art::Assns< recob::PFParticle, larpandoraobj::PFParticleMetadata > > PFParticleToMetadataCollection
std::map< int, art::Ptr< recob::Hit > > IdToHitMap
Definition: ILArPandora.h:21
static art::Ptr< recob::Hit > GetHit(const IdToHitMap &idToHitMap, const pandora::CaloHit *const pCaloHit)
Look up ART hit from an input Pandora hit.
bool m_isNeutrinoRecoOnlyNoSlicing
If we are running the neutrino reconstruction only with no slicing.
static size_t GetId(const T *const pT, const std::list< const T * > &tList)
Find the index of an input object in an input list. Throw an exception if it doesn&#39;t exist...
Definition: T0.h:16
static bool IsFromSlice(const pandora::ParticleFlowObject *const pPfo)
Check if the input pfo is from a slice.
Definition of vertex object for LArSoft.
Definition: Vertex.h:35
static recob::Vertex BuildVertex(const pandora::Vertex *const pVertex, const size_t vertexId)
Convert from a pandora vertex to an ART vertex.
std::unique_ptr< art::Assns< recob::PFParticle, recob::Cluster > > PFParticleToClusterCollection
static void AssociateAdditionalVertices(const art::Event &event, const std::string &instanceLabel, const pandora::PfoVector &pfoVector, const IdToIdVectorMap &pfoToVerticesMap, PFParticleToVertexCollection &outputParticlesToVertices)
Convert Create the associations between pre-existing PFParticle and additional vertices.
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:265
std::vector< size_t > IdVector
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
static unsigned int GetSliceIndex(const pandora::ParticleFlowObject *const pPfo)
Get the index of the slice from which this pfo was produced.
std::unique_ptr< art::Assns< recob::PFParticle, anab::T0 > > PFParticleToT0Collection
static void BuildVertices(const pandora::VertexVector &vertexVector, VertexCollection &outputVertices)
Convert pandora vertices to ART vertices and add them to the output vector.
static bool BuildT0(const art::Event &event, const pandora::ParticleFlowObject *const pPfo, const pandora::PfoVector &pfoVector, size_t &nextId, anab::T0 &t0)
If required, build a T0 for the input pfo.
std::unique_ptr< art::Assns< recob::SpacePoint, recob::Hit > > SpacePointToHitCollection
static pandora::PfoVector CollectPfos(const pandora::Pandora *const pPrimaryPandora)
Collect the current pfos (including all downstream pfos) from the master pandora instance.
static bool IsClearCosmic(const pandora::ParticleFlowObject *const pPfo)
Check if the input pfo is an unambiguous cosmic ray.
static void ProduceArtOutput(const Settings &settings, const IdToHitMap &idToHitMap, art::Event &evt)
Convert the Pandora PFOs into ART clusters and write into ART event.
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.
static pandora::ClusterList CollectClusters(const pandora::PfoVector &pfoVector, IdToIdVectorMap &pfoToClustersMap)
Collect a sorted list of all 2D clusters contained in the input pfo list Order is guaranteed provided...
static void Collect3DHits(const pandora::ParticleFlowObject *const pPfo, pandora::CaloHitVector &caloHits)
Collect a sorted vector of all 3D hits in the input pfo.
static void BuildT0s(const art::Event &event, const std::string &instanceLabel, const pandora::PfoVector &pfoVector, T0Collection &outputT0s, PFParticleToT0Collection &outputParticlesToT0s)
Calculate the T0 of each pfos and add them to the output vector Create the associations between PFPar...
bool m_shouldProduceTestBeamInteractionVertices
Whether to write the test beam interaction vertices in a separate collection.
static recob::PFParticle BuildPFParticle(const pandora::ParticleFlowObject *const pPfo, const size_t pfoId, const pandora::PfoVector &pfoVector)
Convert from a pfo to and ART PFParticle.
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
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...
static void BuildSlices(const Settings &settings, const pandora::Pandora *const pPrimaryPandora, const art::Event &event, const std::string &instanceLabel, const pandora::PfoVector &pfoVector, const IdToHitMap &idToHitMap, SliceCollection &outputSlices, PFParticleToSliceCollection &outputParticlesToSlices, SliceToHitCollection &outputSlicesToHits)
Build slices - collections of hits which each describe a single particle hierarchy.
static void CopyAllHitsToSingleSlice(const Settings &settings, const art::Event &event, const std::string &instanceLabel, const pandora::PfoVector &pfoVector, const IdToHitMap &idToHitMap, SliceCollection &outputSlices, PFParticleToSliceCollection &outputParticlesToSlices, SliceToHitCollection &outputSlicesToHits)
Ouput a single slice containing all of the input hits.
then echo fcl name
static void BuildPFParticles(const art::Event &event, const std::string &instanceLabel, const pandora::PfoVector &pfoVector, const IdToIdVectorMap &pfoToVerticesMap, const IdToIdVectorMap &pfoToThreeDHitsMap, const IdToIdVectorMap &pfoToArtClustersMap, PFParticleCollection &outputParticles, PFParticleToVertexCollection &outputParticlesToVertices, PFParticleToSpacePointCollection &outputParticlesToSpacePoints, PFParticleToClusterCollection &outputParticlesToClusters)
Convert between pfos and PFParticles and add them to the output vector Create the associations betwee...
static void BuildParticleMetadata(const art::Event &event, const std::string &instanceLabel, const pandora::PfoVector &pfoVector, PFParticleMetadataCollection &outputParticleMetadata, PFParticleToMetadataCollection &outputParticlesToMetadata)
Build metadata objects from a list of input pfos.
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
static pandora::PfoVector CollectAllPfoOutcomes(const pandora::Pandora *const pPrimaryPandora)
Collect the pfos (including all downstream pfos) from the master and daughter pandora instances...
static void AddAssociation(const art::Event &event, const std::string &instanceLabel, const size_t idA, const size_t idB, std::unique_ptr< art::Assns< A, B >> &association)
Add an association between objects with two given ids.
std::array< float, 2 > VertexVector(const recob::Vertex &vert, const geo::PlaneID &plane, const geo::GeometryCore *geo, const detinfo::DetectorPropertiesData &dprop)
std::unique_ptr< art::Assns< recob::Cluster, recob::Hit > > ClusterToHitCollection