npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
ResponseMatrix.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_RESPONSEMATRIX_HH_
2 #define NPSTAT_RESPONSEMATRIX_HH_
3 
4 /*!
5 // \file ResponseMatrix.hh
6 //
7 // \brief Efficient response matrix representation for multidimensional unfolding
8 //
9 // Author: I. Volobouev
10 //
11 // June 2014
12 */
13 
14 #include <vector>
15 #include <utility>
16 
17 #include "npstat/nm/ArrayND.hh"
18 #include "npstat/nm/Matrix.hh"
19 
20 namespace npstat {
22  public ArrayND<std::pair<std::vector<unsigned long>, std::vector<double> > >
23  {
24  public:
25  typedef ArrayND<std::pair<std::vector<unsigned long>, std::vector<double> > > Base;
26 
27  inline ResponseMatrix() : Base() {}
28 
29  inline virtual ~ResponseMatrix() {}
30 
31  ResponseMatrix(const ArrayShape& unfoldedShape,
32  const ArrayShape& observedShape);
33 
34  ResponseMatrix(const ArrayShape& unfoldedShape,
35  const ArrayShape& observedShape,
36  const Matrix<double>& denseMatrix);
37 
38  ResponseMatrix(const unsigned* unfoldedShape, unsigned unfoldedDim,
39  const unsigned* observedShape, unsigned observedDim);
40 
41  ResponseMatrix(const unsigned* unfoldedShape, unsigned unfoldedDim,
42  const unsigned* observedShape, unsigned observedDim,
43  const Matrix<double>& denseMatrix);
44 
45  void shrinkToFit() const;
46 
47  inline const ArrayShape& observedShape() const {return toShape_;}
48 
49  unsigned long observedLength() const;
50 
51  bool isValid() const;
52 
53  void timesVector(const ArrayND<double>& a,
54  ArrayND<double>* result) const;
55 
56  void rowMultiply(const ArrayND<double>& a,
57  ArrayND<double>* result) const;
58 
59  ResponseMatrix T() const;
60 
61  bool operator==(const ResponseMatrix& r) const;
62 
63  inline bool operator!=(const ResponseMatrix& r) const
64  {return !(*this == r);}
65 
66  Matrix<double> denseMatrix() const;
67 
68  /** Efficiency is calculated without bounds checking */
69  double linearEfficiency(unsigned long index) const;
70 
71  //@{
72  /** Method related to "geners" I/O */
73  inline gs::ClassId classId() const {return gs::ClassId(*this);}
74  bool write(std::ostream& of) const;
75  //@}
76 
77  static inline const char* classname() {return "npstat::ResponseMatrix";}
78  static inline unsigned version() {return 1;}
79  static void restore(const gs::ClassId& id, std::istream& in,
80  ResponseMatrix* array);
81  private:
82  void sparsify(const Matrix<double>& dense);
83 
84  ArrayShape toShape_;
85  };
86 }
87 
88 #endif // NPSTAT_RESPONSEMATRIX_HH_
Arbitrary-dimensional array template.
Template matrix class.
Definition: ArrayND.hh:93
Definition: ResponseMatrix.hh:23
double linearEfficiency(unsigned long index) const
gs::ClassId classId() const
Definition: ResponseMatrix.hh:73
Definition: AbsArrayProjector.hh:14
std::vector< unsigned > ArrayShape
Definition: ArrayShape.hh:21