All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PointCharge.h
Go to the documentation of this file.
1 /**
2  * @file lardataobj/RecoBase/PointCharge.h
3  * @brief Information about charge reconstructed in the active volume.
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date December 20, 2017
6  *
7  *
8  */
9 
10 #ifndef LARDATAOBJ_RECOBASE_CHARGE_H
11 #define LARDATAOBJ_RECOBASE_CHARGE_H
12 
13 // C/C++ standard libraries
14 #include <limits>
15 #include <string>
16 #include <utility> // std::forward()
17 #include <iosfwd> // std::ostream
18 
19 
20 namespace recob {
21 
22  /**
23  * @brief Charge reconstructed in the active volume.
24  *
25  * The reconstructed charge value is in arbitrary units in that it's hard to
26  * precisely define the normalization, which ends up being
27  * algorithm-dependent. As such, the charge from this object is expected to
28  * require a specific calibration.
29  *
30  */
31  class PointCharge {
32 
33  public:
34 
35  using Charge_t = float; ///< Type for the amount of reconstructed charge.
36 
37  /// Value used for default-constructed ("invalid") charge.
38  static constexpr Charge_t InvalidCharge
39  = std::numeric_limits<Charge_t>::lowest();
40 
41 
42  //--- BEGIN Constructors ---------------------------------------------------
43  /// @{
44  /// @name Constructors
45 
46  /// Default constructor (for ROOT only).
48 
49  /**
50  * @brief Constructor: sets all the data.
51  * @param charge reconstructed charge (used unchanged)
52  *
53  */
54  constexpr PointCharge(Charge_t charge): fCharge(charge) {}
55 
56  /// @}
57  //--- END Constructors -----------------------------------------------------
58 
59 
60  //--- BEGIN Accessors ------------------------------------------------------
61  /// @{
62  /// @name Access to the information
63 
64  /// Returns the stored value of the reconstructed charge.
65  constexpr Charge_t charge() const { return fCharge; }
66 
67  /// @}
68  //--- END Accessors --------------------------------------------------------
69 
70 
71  //--- BEGIN Status ---------------------------------------------------------
72  /// @{
73  /// @name Object status and data validity
74 
75  /// Returns whether the reconstructed charge value is valid.
76  constexpr bool hasCharge() const { return charge() != InvalidCharge; }
77 
78  /// @}
79  //--- END Status -----------------------------------------------------------
80 
81 
82  //--- BEGIN Printing operations --------------------------------------------
83  /// @{
84  /// @name Printing operations
85 
86  /// Default verbosity for dumping operations.
87  static constexpr unsigned int DefaultVerbosity = 1U;
88 
89  /// Maximum available verbosity for dumping operations.
90  static constexpr unsigned int MaxVerbosity = 1U;
91 
92  /**
93  * @brief Dump the content of this object into an output stream.
94  * @tparam Stream type of stream to write into
95  * @param out output stream
96  * @param verbosity the level of detail of dumped information, to be between
97  * `0` and `MaxVerbosity` _(default: `DefaultVerbosity`)_
98  * @param indent all lines except the first are prepended this string
99  * _(default: none)_
100  * @param firstIndent the first output line is prepended this string
101  * _(default: same as `indent`)_
102  *
103  * The output starts on the current line, with `firstIndent` as indentation.
104  * No end-of-line is inserted at the end of the output.
105  */
106  template <typename Stream>
107  void dump(
108  Stream&& out, unsigned int verbosity,
109  std::string indent, std::string firstIndent
110  ) const;
111 
112  // variants for the implementation of default values
113  template <typename Stream>
114  void dump
115  (Stream&& out, unsigned int verbosity, std::string indent = "") const
116  { dump(std::forward<Stream>(out), verbosity, indent, indent); }
117  template <typename Stream>
118  void dump(Stream&& out, std::string indent, std::string firstIndent) const
119  { dump(std::forward<Stream>(out), DefaultVerbosity, indent, firstIndent); }
120  template <typename Stream>
121  void dump(Stream&& out, std::string indent = "") const
122  { dump(std::forward<Stream>(out), indent, indent); }
123 
124  /// @}
125  //--- END Printing operations ----------------------------------------------
126 
127  private:
128  float fCharge; ///< Reconstructed charge.
129 
130  }; // class PointCharge
131 
132 
133  /// Dumps the content of a `recob::PointCharge` object into an output stream.
134  inline std::ostream& operator<<
135  (std::ostream& out, recob::PointCharge const& charge)
136  { charge.dump(out); return out; }
137 
138 
139 } // namespace recob
140 
141 
142 
143 //------------------------------------------------------------------------------
144 //--- template implementation
145 //---
146 template <typename Stream>
148  Stream&& out, unsigned int verbosity,
149  std::string indent, std::string firstIndent
150  ) const
151 {
152  if (verbosity <= 0U) return;
153 
154  //----------------------------------------------------------------------------
155  out << firstIndent
156  << "charge: ";
157  if (hasCharge()) out << charge();
158  else out << "none";
159 
160 // if (verbosity <= 1U) return;
161  //----------------------------------------------------------------------------
162  // if the following check fails,
163  // consistency between `dump()` and `MaxVerbosity` needs to be restored
164  static_assert(MaxVerbosity == 1U, "Please update the code!");
165 
166 } // recob::PointCharge::dump()
167 
168 
169 //------------------------------------------------------------------------------
170 
171 #endif // LARDATAOBJ_RECOBASE_CHARGE_H
constexpr PointCharge(Charge_t charge)
Constructor: sets all the data.
Definition: PointCharge.h:54
static constexpr Charge_t InvalidCharge
Value used for default-constructed (&quot;invalid&quot;) charge.
Definition: PointCharge.h:39
void dump(Stream &&out, unsigned int verbosity, std::string indent, std::string firstIndent) const
Dump the content of this object into an output stream.
Definition: PointCharge.h:147
void dump(Stream &&out, std::string indent="") const
Definition: PointCharge.h:121
constexpr PointCharge()
Default constructor (for ROOT only).
Definition: PointCharge.h:47
constexpr bool hasCharge() const
Returns whether the reconstructed charge value is valid.
Definition: PointCharge.h:76
static constexpr unsigned int DefaultVerbosity
Default verbosity for dumping operations.
Definition: PointCharge.h:87
float fCharge
Reconstructed charge.
Definition: PointCharge.h:128
static constexpr unsigned int MaxVerbosity
Maximum available verbosity for dumping operations.
Definition: PointCharge.h:90
float Charge_t
Type for the amount of reconstructed charge.
Definition: PointCharge.h:35
void dump(Stream &&out, std::string indent, std::string firstIndent) const
Definition: PointCharge.h:118
constexpr Charge_t charge() const
Returns the stored value of the reconstructed charge.
Definition: PointCharge.h:65
bnb BNB Stream
Charge reconstructed in the active volume.
Definition: PointCharge.h:31