LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
CheatTrack.h
Go to the documentation of this file.
1 
13 #ifndef LAREXAMPLES_ALGORITHMS_TOTALLYCHEATTRACKS_CHEATTRACKDATA_CHEATTRACK_H
14 #define LAREXAMPLES_ALGORITHMS_TOTALLYCHEATTRACKS_CHEATTRACKDATA_CHEATTRACK_H
15 
16 // LArSoft libraries
18 
19 // ROOT libraries
20 #include "TDatabasePDG.h"
21 
22 // C/C++ standard libraries
23 #include <ostream>
24 #include <string>
25 #include <utility> // std::move(), std::forward()
26 
27 namespace lar {
28 
29  namespace example {
30  // BEGIN TotallyCheatTracks group ------------------------------------------
33 
50  class CheatTrack {
51 
52  public:
53  using PDGID_t = int;
54 
56  static constexpr PDGID_t InvalidParticleID = 0;
57 
59  CheatTrack() = default;
60 
69  CheatTrack(recob::Trajectory&& traj, PDGID_t pid) : fTraj(std::move(traj)), fPDGID(pid) {}
70 
72  recob::Trajectory const& trajectory() const { return fTraj; }
73 
74  // --- BEGIN access to data ----------------------------------------------
77 
79  double momentum() const { return trajectory().StartMomentum(); }
80 
82  PDGID_t particleId() const { return fPDGID; }
83 
85  bool hasParticleId() const { return particleId() != InvalidParticleID; }
86 
88  // --- END access to data ------------------------------------------------
89 
90  // --- BEGIN printing data -----------------------------------------------
93 
95  static constexpr unsigned int DefaultDumpVerbosity = 1U;
96 
98  static constexpr unsigned int MaxDumpVerbosity = recob::Trajectory::MaxDumpVerbosity;
99 
101 
116  template <typename Stream>
117  void dump(Stream&& out,
118  unsigned int verbosity,
119  std::string indent,
120  std::string firstIndent) const;
121  template <typename Stream>
122  void dump(Stream&& out,
123  unsigned int verbosity = DefaultDumpVerbosity,
124  std::string indent = "") const
125  {
126  dump(std::forward<Stream>(out), verbosity, indent, indent);
127  }
129 
131 
132  // --- END printing data -------------------------------------------------
133 
134  private:
137 
138  }; // class CheatTrack
139 
143  inline std::ostream& operator<<(std::ostream& out, lar::example::CheatTrack const& track)
144  {
145  track.dump(out);
146  return out;
147  }
148 
150  // END TotallyCheatTracks group ------------------------------------------
151 
152  } // namespace example
153 
154 } // namespace lar
155 
156 //------------------------------------------------------------------------------
157 //--- template implementation
158 //------------------------------------------------------------------------------
159 template <typename Stream>
161  unsigned int verbosity,
162  std::string indent,
163  std::string firstIndent) const
164 {
165 
166  // we could use ROOT's TDatabasePDG to get the name of the ID, but we'd rather
167  // not depend on ROOT here...
168  out << firstIndent << "particle: ";
169  auto const* pPDGinfo = TDatabasePDG::Instance()->GetParticle(particleId());
170  if (pPDGinfo)
171  out << pPDGinfo->GetName() << " (ID=" << particleId() << ")";
172  else
173  out << "ID " << particleId();
174  out << "; momentum: " << momentum() << " GeV/c; ";
175  trajectory().Dump(std::forward<Stream>(out), verbosity, indent, "");
176 
177 } // lar::example::CheatTrack::dump()
178 
179 //------------------------------------------------------------------------------
180 
181 #endif // LAREXAMPLES_ALGORITHMS_TOTALLYCHEATTRACKS_CHEATTRACKDATA_CHEATTRACK_H
CheatTrack(recob::Trajectory &&traj, PDGID_t pid)
Constructor from trajectory (stolen) and particle ID.
Definition: CheatTrack.h:69
static constexpr unsigned int DefaultDumpVerbosity
Default verbosity level.
Definition: CheatTrack.h:95
PDGID_t particleId() const
Returns the particle ID, in PDG standard.
Definition: CheatTrack.h:82
Data product for reconstructed trajectory in space.
CheatTrack()=default
Default constructor, only for ROOT I/O (do not use it!).
recob::Trajectory fTraj
The trejectory of this track.
Definition: CheatTrack.h:135
PDGID_t fPDGID
Particle ID in PDG standard.
Definition: CheatTrack.h:136
bool hasParticleId() const
Returns whether the particle ID is valid.
Definition: CheatTrack.h:85
STL namespace.
double StartMomentum() const
Computes and returns the modulus of momentum at the first point [GeV/c].
Definition: Trajectory.h:363
Pseudo-track object for TotallyCheatTracks example.
Definition: CheatTrack.h:50
static constexpr PDGID_t InvalidParticleID
Value of a particle ID that denotes it as invalid.
Definition: CheatTrack.h:56
int PDGID_t
Type of the particle ID.
Definition: CheatTrack.h:53
void dump(Stream &&out, unsigned int verbosity=DefaultDumpVerbosity, std::string indent="") const
Default verbosity level.
Definition: CheatTrack.h:122
std::string indent(std::size_t const i)
double momentum() const
Returns the initial momentum of the particle [MeV].
Definition: CheatTrack.h:79
static constexpr unsigned int MaxDumpVerbosity
Maximum verbosity level.
Definition: CheatTrack.h:98
recob::Trajectory const & trajectory() const
Returns the trajectory of this track.
Definition: CheatTrack.h:72
static constexpr unsigned int MaxDumpVerbosity
Largest verbosity level supported by Dump().
Definition: Trajectory.h:681
void dump(Stream &&out, unsigned int verbosity, std::string indent, std::string firstIndent) const
Prints the content of this object into an output stream.
Definition: CheatTrack.h:160
A trajectory in space reconstructed from hits.
Definition: Trajectory.h:66
LArSoft-specific namespace.
void Dump(Stream &&out, unsigned int verbosity, std::string indent, std::string indentFirst) const
Prints trajectory content into a stream.
Float_t track
Definition: plot.C:35
std::ostream & operator<<(std::ostream &out, lar::example::CheatTrack const &track)
Definition: CheatTrack.h:143