All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PCAxisDumpers.h
Go to the documentation of this file.
1 /**
2  * @file PCAxisDumpers.h
3  * @brief Functions dumping principal component axis objects
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date December 18th, 2015
6  * @see PCAxisDumpers.cc DumpPCAxis_module.cc
7  */
8 
9 #ifndef LARDATA_RECOBASE_DUMPERS_PCAXISDUMPERS_H
10 #define LARDATA_RECOBASE_DUMPERS_PCAXISDUMPERS_H 1
11 
12 // LArSoft libraries
14 
15 // C/C++ standard libraries
16 #include <string>
17 #include <iomanip>
18 #include <type_traits> // std::decay<>
19 
20 
21 // --- for the implementation ---
22 // LArSoft libraries
24 
25 
26 namespace recob {
27  namespace dumper {
28 
29  /// Dumps the content of the specified PCA axis (indentation info in nl)
30  /// @tparam Stream the type of the output stream
31  /// @tparam NewLineRef NewLine reference type (to get a universal reference)
32  template <typename Stream, typename NewLineRef>
34  <std::is_same<recob::dumper::NewLine<std::decay_t<Stream>>, std::decay_t<NewLineRef>>::value>
36  (Stream&& out, recob::PCAxis const& pca, NewLineRef&& nl);
37 
38  /** ************************************************************************
39  * @brief Dumps the content of the specified PCA axis into a stream
40  * @tparam Stream the type of output stream
41  * @param out the output stream
42  * @param pca the principal component axis to be dumped
43  * @param indent indentation string (none by default)
44  * @param indentFirst whether to indent the first line (yes by default)
45  *
46  * Insertion operators are required that insert into Stream basic types.
47  *
48  * This function does not insert a end-of-line after its output.
49  */
50  template <typename Stream>
51  void DumpPCAxis(Stream&& out, recob::PCAxis const& pca,
52  std::string indent = "",
53  bool indentFirst = true
54  )
55  {
56  DumpPCAxis(
57  std::forward<Stream>(out), pca, makeNewLine(out, indent, !indentFirst)
58  );
59  }
60 
61 
62  } // namespace dumper
63 } // namespace lar
64 
65 
66 //==============================================================================
67 //=== template implementation
68 //===
69 //------------------------------------------------------------------------------
70 //--- recob::dumper::DumpPCAxis
71 //---
72 template <typename Stream, typename NewLineRef>
74  <std::is_same<recob::dumper::NewLine<std::decay_t<Stream>>, std::decay_t<NewLineRef>>::value>
76  (Stream&& out, recob::PCAxis const& pca, NewLineRef&& nl)
77 {
78 
79  if (!pca.getSvdOK()) {
80  nl() << "<not valid>";
81  return;
82  }
83 
84  nl() << std::setiosflags(std::ios::fixed) << std::setprecision(2)
85  << " ID " << pca.getID()
86  << " run on " << pca.getNumHitsUsed() << " space points";
87  nl()
88  << " - center position: " << std::setw(6) << pca.getAvePosition()[0]
89  << ", " << pca.getAvePosition()[1]
90  << ", " << pca.getAvePosition()[2];
91  nl()
92  << " - eigen values: " << std::setw(8) << std::right
93  << pca.getEigenValues()[0] << ", "
94  << pca.getEigenValues()[1] << ", " << pca.getEigenValues()[2];
95  nl()
96  << " - average doca: " << pca.getAveHitDoca();
97  nl()
98  << " - principle axis: "
99  << std::setw(7) << std::setprecision(4) << pca.getEigenVectors()[0][0]
100  << ", " << pca.getEigenVectors()[0][1]
101  << ", " << pca.getEigenVectors()[0][2];
102  nl()
103  << " - second axis: "
104  << std::setw(7) << std::setprecision(4) << pca.getEigenVectors()[1][0]
105  << ", " << pca.getEigenVectors()[1][1]
106  << ", " << pca.getEigenVectors()[1][2];
107  nl()
108  << " - third axis: "
109  << std::setw(7) << std::setprecision(4) << pca.getEigenVectors()[2][0]
110  << ", " << pca.getEigenVectors()[2][1]
111  << ", " << pca.getEigenVectors()[2][2];
112 
113 } // recob::dumper::DumpPCAxis()
114 
115 //------------------------------------------------------------------------------
116 
117 #endif // LARDATA_RECOBASE_DUMPERS_PCAXISDUMPERS_H
118 
double getAveHitDoca() const
Definition: PCAxis.h:68
const EigenVectors & getEigenVectors() const
Definition: PCAxis.h:66
const double * getEigenValues() const
Definition: PCAxis.h:65
std::enable_if_t< std::is_same< recob::dumper::NewLine< std::decay_t< Stream > >, std::decay_t< NewLineRef > >::value > DumpPCAxis(Stream &&out, recob::PCAxis const &pca, NewLineRef &&nl)
Definition: PCAxisDumpers.h:76
walls no right
Definition: selectors.fcl:105
int getNumHitsUsed() const
Definition: PCAxis.h:64
size_t getID() const
Definition: PCAxis.h:69
Simple class managing a repetitive output task.
typename std::enable_if< B, T >::type enable_if_t
Definition: json.hpp:2191
const double * getAvePosition() const
Definition: PCAxis.h:67
NewLine< Stream > makeNewLine(Stream &stream, std::string indent, bool followLine=false)
Convenience function to create a temporary NewLine.
Definition: NewLine.h:146
temporary value
bnb BNB Stream
bool getSvdOK() const
Definition: PCAxis.h:63