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