All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CheatTrack.h
Go to the documentation of this file.
1 /**
2  * @file larexamples/Algorithms/TotallyCheatTracks/CheatTrackData/CheatTrack.h
3  * @brief Pseudo-track data product for TotallyCheatTracks example.
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date December 26, 2017
6  * @version 10
7  * @ingroup TotallyCheatTracks
8  *
9  * This is a header-only library (no implementation file).
10  *
11  */
12 
13 #ifndef LAREXAMPLES_ALGORITHMS_TOTALLYCHEATTRACKS_CHEATTRACKDATA_CHEATTRACK_H
14 #define LAREXAMPLES_ALGORITHMS_TOTALLYCHEATTRACKS_CHEATTRACKDATA_CHEATTRACK_H
15 
16 
17 // LArSoft libraries
19 
20 // ROOT libraries
21 #include "TDatabasePDG.h"
22 
23 // C/C++ standard libraries
24 #include <ostream>
25 #include <string>
26 #include <utility> // std::move(), std::forward()
27 
28 
29 namespace lar {
30 
31  namespace example {
32  // BEGIN TotallyCheatTracks group ------------------------------------------
33  /// @ingroup TotallyCheatTracks
34  /// @{
35 
36  /**
37  * @brief Pseudo-track object for TotallyCheatTracks example.
38  *
39  * This class represents a reconstructed track via a trajectory in phase
40  * space (position plus momentum), sampled in many points, and in addition
41  * a particle identification code representing the type of the original
42  * particle.
43  *
44  * It is expected to be unrealistically precise for a reconstructed object,
45  * by being constructed from simulated "truth" information.
46  *
47  * This track object does _not_ implement the standard interface of a
48  * LArSoft track (`recob::Track`).
49  * It _can_ present a standard LArSoft `recob::Trajectory` though.
50  *
51  */
52  class CheatTrack {
53 
54  public:
55 
56  using PDGID_t = int; ///< Type of the particle ID.
57 
58  /// Value of a particle ID that denotes it as invalid.
59  static constexpr PDGID_t InvalidParticleID = 0;
60 
61  /// Default constructor, only for ROOT I/O (do not use it!).
62  CheatTrack() = default;
63 
64  /**
65  * @brief Constructor from trajectory (stolen) and particle ID.
66  * @param traj the reconstructed trajectory of the track
67  * @param pid particle ID, in PDG standard
68  *
69  * The trajectory in `traj` is moved into this object, and it will not be
70  * valid in the caller scope any more.
71  */
73  : fTraj(std::move(traj))
74  , fPDGID(pid)
75  {}
76 
77 
78  /// Returns the trajectory of this track.
79  recob::Trajectory const& trajectory() const { return fTraj; }
80 
81  // --- BEGIN access to data ----------------------------------------------
82  /// @{
83  /// @name Access to data
84 
85  /// Returns the initial momentum of the particle [MeV]
86  double momentum() const { return trajectory().StartMomentum(); }
87 
88  /// Returns the particle ID, in PDG standard.
89  PDGID_t particleId() const { return fPDGID; }
90 
91  /// Returns whether the particle ID is valid.
92  bool hasParticleId() const { return particleId() != InvalidParticleID; }
93 
94  /// @}
95  // --- END access to data ------------------------------------------------
96 
97  // --- BEGIN printing data -----------------------------------------------
98  /// @{
99  /// @name Printing data
100 
101  /// Default verbosity level.
102  static constexpr unsigned int DefaultDumpVerbosity = 1U;
103 
104  /// Maximum verbosity level.
105  static constexpr unsigned int MaxDumpVerbosity
107 
108  //@{
109  /**
110  * @brief Prints the content of this object into an output stream.
111  * @tparam Stream type of the output text stream
112  * @param out the output text stream
113  * @param verbosity the amount of information printed
114  * (_default: `DefaultDumpVerbosity`_)
115  * @param indent indentation string for all output except the first line
116  * (_default: none_)
117  * @param firstIndent indentation string for the first line
118  * (_default: as `indent`_)
119  *
120  * Verbosity level is the same as the one of `recob::Trajectory::Dump()`.
121  * In addition, the momentum and particle ID are always printed.
122  *
123  */
124  template <typename Stream>
125  void dump(
126  Stream&& out, unsigned int verbosity,
127  std::string indent, std::string firstIndent
128  ) const;
129  template <typename Stream>
130  void dump(
131  Stream&& out, unsigned int verbosity = DefaultDumpVerbosity,
132  std::string indent = ""
133  ) const
134  { dump(std::forward<Stream>(out), verbosity, indent, indent); }
135  //@}
136 
137  ///@}
138 
139  // --- END printing data -------------------------------------------------
140 
141  private:
142 
143  recob::Trajectory fTraj; ///< The trejectory of this track.
144  PDGID_t fPDGID = InvalidParticleID; ///< Particle ID in PDG standard.
145 
146  }; // class CheatTrack
147 
148 
149  /// Prints the content of the track into a text stream.
150  /// @related lar::example::CheatTrack
151  /// @ingroup TotallyCheatTracks
152  inline std::ostream& operator<<
153  (std::ostream& out, lar::example::CheatTrack const& track)
154  { track.dump(out); return out; }
155 
156  /// @}
157  // END TotallyCheatTracks group ------------------------------------------
158 
159  } // namespace example
160 
161 } // namespace lar
162 
163 
164 //------------------------------------------------------------------------------
165 //--- template implementation
166 //------------------------------------------------------------------------------
167 template <typename Stream>
169  Stream&& out, unsigned int verbosity,
170  std::string indent, std::string firstIndent
171  ) const
172 {
173 
174  // we could use ROOT's TDatabasePDG to get the name of the ID, but we'd rather
175  // not depend on ROOT here...
176  out << firstIndent
177  << "particle: ";
178  auto const* pPDGinfo = TDatabasePDG::Instance()->GetParticle(particleId());
179  if (pPDGinfo) out << pPDGinfo->GetName() << " (ID=" << particleId() << ")";
180  else out << "ID " << particleId();
181  out << "; momentum: " << momentum() << " GeV/c; ";
182  trajectory().Dump(std::forward<Stream>(out), verbosity, indent, "");
183 
184 } // lar::example::CheatTrack::dump()
185 
186 //------------------------------------------------------------------------------
187 
188 
189 #endif // LAREXAMPLES_ALGORITHMS_TOTALLYCHEATTRACKS_CHEATTRACKDATA_CHEATTRACK_H
CheatTrack(recob::Trajectory &&traj, PDGID_t pid)
Constructor from trajectory (stolen) and particle ID.
Definition: CheatTrack.h:72
static constexpr unsigned int DefaultDumpVerbosity
Default verbosity level.
Definition: CheatTrack.h:102
PDGID_t particleId() const
Returns the particle ID, in PDG standard.
Definition: CheatTrack.h:89
Data product for reconstructed trajectory in space.
CheatTrack()=default
Default constructor, only for ROOT I/O (do not use it!).
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
recob::Trajectory fTraj
The trejectory of this track.
Definition: CheatTrack.h:143
PDGID_t fPDGID
Particle ID in PDG standard.
Definition: CheatTrack.h:144
bool hasParticleId() const
Returns whether the particle ID is valid.
Definition: CheatTrack.h:92
process_name use argoneut_mc_hitfinder track
double StartMomentum() const
Computes and returns the modulus of momentum at the first point [GeV/c].
Definition: Trajectory.h:397
Pseudo-track object for TotallyCheatTracks example.
Definition: CheatTrack.h:52
static constexpr PDGID_t InvalidParticleID
Value of a particle ID that denotes it as invalid.
Definition: CheatTrack.h:59
int PDGID_t
Type of the particle ID.
Definition: CheatTrack.h:56
void dump(Stream &&out, unsigned int verbosity=DefaultDumpVerbosity, std::string indent="") const
Definition: CheatTrack.h:130
double momentum() const
Returns the initial momentum of the particle [MeV].
Definition: CheatTrack.h:86
static constexpr unsigned int MaxDumpVerbosity
Maximum verbosity level.
Definition: CheatTrack.h:106
recob::Trajectory const & trajectory() const
Returns the trajectory of this track.
Definition: CheatTrack.h:79
static constexpr unsigned int MaxDumpVerbosity
Largest verbosity level supported by Dump().
Definition: Trajectory.h:662
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:168
A trajectory in space reconstructed from hits.
Definition: Trajectory.h:67
void Dump(Stream &&out, unsigned int verbosity, std::string indent, std::string indentFirst) const
Prints trajectory content into a stream.
bnb BNB Stream