npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
AbsSparseUnfoldND.hh
Go to the documentation of this file.
1 #ifndef EMSUNFOLD_ABSSPARSEUNFOLDND_HH_
2 #define EMSUNFOLD_ABSSPARSEUNFOLDND_HH_
3 
4 /*!
5 // \file AbsSparseUnfoldND.hh
6 //
7 // \brief Interface definition for multivariate unfolding algorithms that
8 // use sparse matrices
9 //
10 // Author: I. Volobouev
11 //
12 // July 2014
13 */
14 
16 
17 #include "Eigen/Core"
18 
19 namespace emsunfold {
20  template<class Matrix>
22  {
23  public:
24  typedef Matrix response_matrix_type;
25  typedef Eigen::DiagonalMatrix<double,Eigen::Dynamic> input_covariance_type;
26  typedef Matrix output_covariance_type;
28 
29  AbsSparseUnfoldND(const response_matrix_type& responseMatrix,
30  const npstat::ArrayShape& unfoldedShape,
31  const npstat::ArrayShape& observedShape);
32 
33  AbsSparseUnfoldND(const response_matrix_type& responseMatrix,
34  const unsigned* unfoldedShape, unsigned unfoldedDim,
35  const unsigned* observedShape, unsigned observedDim);
36 
37  inline virtual ~AbsSparseUnfoldND() {}
38 
39  inline const response_matrix_type& responseMatrix() const
40  {return responseMatrix_;}
41 
42  inline const npstat::ArrayND<double>& efficiency() const
43  {return efficiency_;}
44 
45  /** Set the initial approximation to the unfolded solution */
47 
48  /** Clear the initial approximation to the unfolded solution */
49  virtual void clearInitialApproximation();
50 
51  /** Return the initial approximation to the unfolded solution */
53 
54  /**
55  // Set the smoothing filter used. The filter will not be copied.
56  // The user must ensure that the filter exists while this object
57  // is in use.
58  */
59  virtual void setFilter(const filter_type* f);
60 
61  /** Retrieve the smoothing filter used */
62  virtual const filter_type* getFilter(
63  bool throwIfNull = false) const;
64 
65  /** Switch between using filtering or convolution */
66  inline virtual void useConvolutions(const bool b) {useConvolutions_=b;}
67 
68  /** Check if the filter should use "filter" or "convolve" method */
69  inline bool usingConvolutions() const {return useConvolutions_;}
70 
71  /** Shape of the expected observed input */
73  {return observedShape_;}
74 
75  /** Shape of the expected unfolded output */
77  {return unfoldedShape_;}
78 
79  /**
80  // Method to be implemented by derived classes. The covariance
81  // matrix of observations should assume linear ordering of the
82  // observed data, per ordering by the "ArrayND" class. If the
83  // "observationCovarianceMatrix" pointer is NULL, the matrix
84  // should be constructed internally, assuming Poisson statistics.
85  // The "unfoldedCovarianceMatrix" pointer can be NULL as well in
86  // which case the corresponding matrix should not be calculated.
87  // If it is not NULL, the resulting matrix should be pruned.
88  //
89  // This function should return "true" on success, "false" on failure.
90  */
91  virtual bool unfold(
92  const npstat::ArrayND<double>& observed,
93  const input_covariance_type* observationCovarianceMatrix,
94  npstat::ArrayND<double>* unfolded,
95  output_covariance_type* unfoldedCovarianceMatrix) = 0;
96 
97  //@{
98  /**
99  // This function will throw the "std::invalid_argument" exception if
100  // the dimensions are incompatible with those of the response matrix
101  */
103  void validateUnfoldedShape(const npstat::ArrayShape& uShape) const;
104  void validateObservedShape(const npstat::ArrayND<double>& o) const;
105  void validateObservedShape(const npstat::ArrayShape& oShape) const;
106  //@}
107 
108  protected:
109  // Build uniform initial approximation to the unfolded solution.
110  // This is useful if the initial approximation was not set explicitly.
111  void buildUniformInitialApproximation(const npstat::ArrayND<double>& o,
112  npstat::ArrayND<double>* r) const;
113  private:
114  // Disable copy and assignment because using the same
115  // filter by two different objects of this type is not
116  // necessarily cool
119  AbsSparseUnfoldND& operator=(const AbsSparseUnfoldND&);
120 
121  void initialize();
122 
123  response_matrix_type responseMatrix_;
124  const npstat::ArrayShape unfoldedShape_;
125  const npstat::ArrayShape observedShape_;
126  npstat::ArrayND<double> efficiency_;
127  npstat::ArrayND<double> initialApproximation_;
128  const filter_type* filt_;
129  bool useConvolutions_;
130  };
131 }
132 
133 #include "npstat/emsunfold/AbsSparseUnfoldND.icc"
134 
135 #endif // EMSUNFOLD_ABSSPARSEUNFOLDND_HH_
Interface for smoothing filters representable by sparse matrices.
Definition: AbsSparseUnfoldND.hh:22
virtual void setInitialApproximation(const npstat::ArrayND< double > &a)
virtual bool unfold(const npstat::ArrayND< double > &observed, const input_covariance_type *observationCovarianceMatrix, npstat::ArrayND< double > *unfolded, output_covariance_type *unfoldedCovarianceMatrix)=0
virtual void clearInitialApproximation()
npstat::ArrayShape getObservedShape() const
Definition: AbsSparseUnfoldND.hh:72
virtual void setFilter(const filter_type *f)
npstat::ArrayShape getUnfoldedShape() const
Definition: AbsSparseUnfoldND.hh:76
virtual const filter_type * getFilter(bool throwIfNull=false) const
virtual const npstat::ArrayND< double > & getInitialApproximation() const
void validateUnfoldedShape(const npstat::ArrayND< double > &u) const
virtual void useConvolutions(const bool b)
Definition: AbsSparseUnfoldND.hh:66
bool usingConvolutions() const
Definition: AbsSparseUnfoldND.hh:69
Definition: AbsSparseUnfoldingFilterND.hh:27
Definition: AbsSparseUnfoldingFilterND.hh:25
std::vector< unsigned > ArrayShape
Definition: ArrayShape.hh:21