All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PFParticle.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////
2 //
3 // \brief Definition of PFParticle object for LArSoft
4 //
5 // \author usher@slac.stanford.edu
6 //
7 ////////////////////////////////////////////////////////////////////////////
8 
9 #ifndef Recob_PFParticle_H
10 #define Recob_PFParticle_H
11 
12 #include <iosfwd>
13 #include <vector>
14 #include <limits>
15 
16 namespace recob {
17 
18  /**
19  * @brief Hierarchical representation of particle flow
20  *
21  * The "Particle Flow" Particle is an object connecting to others of the
22  * same type to define a hierarchy of a single parent generating multiple
23  * daughter particles.
24  *
25  * This structure was originally proposed to accommodate the information
26  * produced by Pandora. The PFParticle is a small entity that is expected
27  * to be associated with `recob::Track`, `recob::Cluster`, `recob::Hit`,
28  * `recob::Vertex` and also `recob::Seed` to describe all the reconstructed
29  * quantities related to it.
30  *
31  * The parentage relationships are expressed by indices in the collection
32  * all the particles belong to. This requires additional care when creating
33  * that collection, since each relation is defined in the particles with
34  * indices pointing to a collection that does not yet exist when the particle
35  * is created.
36  * The relation is expressed as one parent and many daughters. For "primary"
37  * particles, which have no parent, the special parent value
38  * `recob::PFParticle::kPFParticlePrimary` must be used.
39  *
40  * Note that the parentage relation can not be expressed as simple _art_
41  * associations, which can't express relations between two objects of the
42  * same type.
43  */
44  class PFParticle {
45 
46  public:
47 
48  PFParticle(); ///< Default constructor necessary for gccxml - not really for public use
49 
50  private:
51 
52  int fPdgCode; ///< A preliminary estimate of the PFParticle type using the PDG code
53  size_t fSelf; ///< Self reference
54  size_t fParent; ///< Index into PFParticle collection for parent
55  std::vector<size_t> fDaughters; ///< Vector of indices into PFParticle Collection for daughters
56 
57 
58  public:
59 
60  /// Define index to signify primary particle
61  static constexpr size_t kPFParticlePrimary = std::numeric_limits<size_t>::max();
62 
63  /// Primary constructor
64  PFParticle(int pdgCode, size_t self, size_t parent, const std::vector<size_t>& daughters);
65 
66  PFParticle(int pdgCode, size_t self, size_t parent, std::vector<size_t>&& daughters);
67 
68  /// Destructor definition
69  ~PFParticle() = default;
70 
71  /// Copy constructor (using defaults)
72  PFParticle(const PFParticle& other) = default;
73  PFParticle(PFParticle&& other) = default;
74 
75  /// Copy assignment operator (using defaults)
76  PFParticle& operator= (const PFParticle& other) = default;
77  PFParticle& operator= (PFParticle&& other) = default;
78 
79  /// @name Accessors
80  /// @{
81 
82  /// Return the type of particle as a PDG ID.
83  int PdgCode() const {return fPdgCode;}
84 
85  /// Returns whether the particle is the root of the flow.
87 
88  /// Returns the number of daughter particles flowing from this one.
89  int NumDaughters() const {return fDaughters.size();}
90 
91  /// Returns the index of this particle.
92  size_t Self() const {return fSelf;}
93 
94  /// Returns the index of the parent particle
95  /// (`PFParticle::kPFParticlePrimary` if primary).
96  size_t Parent() const {return fParent;}
97 
98  /**
99  * @brief Returns the ID of the specified daughter.
100  * @param idx index of the daughter to be queried (`0` to `NumDaughters()-1`)
101  * @return the ID of the specified daughter
102  * @throw std::out_of_range if the requested daughter does not exist
103  *
104  * The returned value describes the ID of the `idx`-th daughter of this
105  * PFParticle. Note that this is not the same as the index of that PFParticle
106  * in the data product or PFParticle collection.
107  *
108  * This function checks the validity of the index (`idx`). For unchecked access,
109  * use `Daughters()[idx]` instead.
110  */
111  size_t Daughter(size_t idx) const {return Daughters().at(idx);}
112 
113  /// Returns the collection of daughter particles.
114  const std::vector<size_t>& Daughters() const {return fDaughters;}
115 
116  /// @}
117 
118  friend std::ostream& operator << (std::ostream& o, const PFParticle& c);
119  friend bool operator < (const PFParticle& a, const PFParticle& b);
120 
121  }; // class PFParticle
122 } // namespace recob
123 
124 #endif //Recob_PFParticle_H
const std::vector< size_t > & Daughters() const
Returns the collection of daughter particles.
Definition: PFParticle.h:114
int NumDaughters() const
Returns the number of daughter particles flowing from this one.
Definition: PFParticle.h:89
size_t Self() const
Returns the index of this particle.
Definition: PFParticle.h:92
static constexpr size_t kPFParticlePrimary
Define index to signify primary particle.
Definition: PFParticle.h:61
std::vector< size_t > fDaughters
Vector of indices into PFParticle Collection for daughters.
Definition: PFParticle.h:55
int PdgCode() const
Return the type of particle as a PDG ID.
Definition: PFParticle.h:83
process_name gaushit a
int fPdgCode
A preliminary estimate of the PFParticle type using the PDG code.
Definition: PFParticle.h:52
size_t Parent() const
Definition: PFParticle.h:96
bool IsPrimary() const
Returns whether the particle is the root of the flow.
Definition: PFParticle.h:86
friend std::ostream & operator<<(std::ostream &o, const PFParticle &c)
Definition: PFParticle.cxx:38
PFParticle & operator=(const PFParticle &other)=default
Copy assignment operator (using defaults)
Hierarchical representation of particle flow.
Definition: PFParticle.h:44
friend bool operator<(const PFParticle &a, const PFParticle &b)
Definition: PFParticle.cxx:50
~PFParticle()=default
Destructor definition.
size_t fSelf
Self reference.
Definition: PFParticle.h:53
PFParticle()
Default constructor necessary for gccxml - not really for public use.
Definition: PFParticle.cxx:17
size_t fParent
Index into PFParticle collection for parent.
Definition: PFParticle.h:54
size_t Daughter(size_t idx) const
Returns the ID of the specified daughter.
Definition: PFParticle.h:111