npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
AbsUnfoldND.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_ABSUNFOLDND_HH_
2 #define NPSTAT_ABSUNFOLDND_HH_
3 
4 /*!
5 // \file AbsUnfoldND.hh
6 //
7 // \brief Interface definition for multivariate unfolding algorithms
8 //
9 // Author: I. Volobouev
10 //
11 // June 2014
12 */
13 
16 
17 namespace npstat {
19  {
20  public:
25 
26  explicit AbsUnfoldND(const ResponseMatrix& responseMatrix);
27 
28  inline virtual ~AbsUnfoldND() {}
29 
30  inline const ResponseMatrix& responseMatrix() const
31  {return responseMatrix_;}
32 
33  inline const ArrayND<double>& efficiency() const
34  {return efficiency_;}
35 
36  /** Set the initial approximation to the unfolded solution */
37  virtual void setInitialApproximation(const ArrayND<double>& approx);
38 
39  /** Clear the initial approximation to the unfolded solution */
40  virtual void clearInitialApproximation();
41 
42  /** Return the initial approximation to the unfolded solution */
43  virtual const ArrayND<double>& getInitialApproximation() const;
44 
45  /**
46  // Set the smoothing filter used. The filter will not be copied.
47  // The user must ensure that the filter exists while this object
48  // is in use.
49  */
50  virtual void setFilter(const AbsUnfoldingFilterND* f);
51 
52  /** Retrieve the smoothing filter used */
54  bool throwIfNull = false) const;
55 
56  /** Switch between using filtering or convolution */
57  inline virtual void useConvolutions(const bool b) {useConvolutions_=b;}
58 
59  /** Check if the filter should use "filter" or "convolve" method */
60  inline bool usingConvolutions() const {return useConvolutions_;}
61 
62  /** Shape of the expected observed input */
64  {return responseMatrix_.observedShape();}
65 
66  /** Shape of the expected unfolded output */
68  {return responseMatrix_.shape();}
69 
70  /**
71  // Method to be implemented by derived classes. The covariance
72  // matrix of observations should assume linear ordering of the
73  // observed data, per ordering by the "ArrayND" class. If the
74  // "observationCovarianceMatrix" pointer is NULL, the matrix
75  // should be constructed internally, assuming Poisson or multinomial
76  // statistics. The "unfoldedCovarianceMatrix" pointer can be NULL
77  // as well in which case the corresponding matrix should not be
78  // calculated. This function should return "true" on success,
79  // "false" on failure.
80  */
81  virtual bool unfold(const ArrayND<double>& observed,
82  const Matrix<double>* observationCovarianceMatrix,
83  ArrayND<double>* unfolded,
84  Matrix<double>* unfoldedCovarianceMatrix) = 0;
85  //@{
86  /**
87  // This function will throw the "std::invalid_argument" exception if
88  // the dimensions are incompatible with those of the response matrix
89  */
90  void validateUnfoldedShape(const ArrayND<double>& unfolded) const;
91  void validateUnfoldedShape(const ArrayShape& unfoldedShape) const;
92  void validateObservedShape(const ArrayND<double>& observed) const;
93  void validateObservedShape(const ArrayShape& observedShape) const;
94  //@}
95 
96  /** L1 distance between two unnormalized distributions */
97  static double probDelta(const ArrayND<double>& prev,
98  const ArrayND<double>& next);
99  protected:
100  // Build uniform initial approximation to the unfolded solution.
101  // This is useful if the initial approximation was not set explicitly.
102  void buildUniformInitialApproximation(const ArrayND<double>& observed,
103  ArrayND<double>* result) const;
104  private:
105  // Disable copy and assignment because using the same
106  // filter by two different objects of this type is not
107  // necessarily cool
108  AbsUnfoldND();
109  AbsUnfoldND(const AbsUnfoldND&);
110  AbsUnfoldND& operator=(const AbsUnfoldND&);
111 
112  const ResponseMatrix responseMatrix_;
113  ArrayND<double> efficiency_;
114  ArrayND<double> initialApproximation_;
115  const AbsUnfoldingFilterND* filt_;
116  bool useConvolutions_;
117 
118 #ifdef SWIG
119  public:
120  inline ArrayND<double>* unfold2(const ArrayND<double>& observed,
121  Matrix<double>* unfoldedCovMat)
122  {
123  assert(unfoldedCovMat);
124  ArrayND<double>* result = new ArrayND<double>();
125  this->unfold(observed, 0, result, unfoldedCovMat);
126  return result;
127  }
128 
129  inline ArrayND<double>* unfold2(const ArrayND<double>& observed,
130  const Matrix<double>& observationCovMat,
131  Matrix<double>* unfoldedCovMat)
132  {
133  assert(unfoldedCovMat);
134  ArrayND<double>* result = new ArrayND<double>();
135  this->unfold(observed, &observationCovMat, result, unfoldedCovMat);
136  return result;
137  }
138 
139  inline ArrayND<double>* unfoldNoCov(const ArrayND<double>& observed)
140  {
141  ArrayND<double>* result = new ArrayND<double>();
142  this->unfold(observed, 0, result, 0);
143  return result;
144  }
145 
146  inline ArrayND<double>* unfoldNoCov(const ArrayND<double>& observed,
147  const Matrix<double>& observationCovMat)
148  {
149  ArrayND<double>* result = new ArrayND<double>();
150  this->unfold(observed, &observationCovMat, result, 0);
151  return result;
152  }
153 
154  inline ArrayND<double>* fold(const ArrayND<double>& unfolded) const
155  {
156  ArrayND<double>* result = new ArrayND<double>();
157  responseMatrix_.timesVector(unfolded, result);
158  return result;
159  }
160 #endif // SWIG
161  };
162 }
163 
164 #endif // NPSTAT_ABSUNFOLDND_HH_
Interface for smoothing filters used in multivariate unfolding problems.
Efficient response matrix representation for multidimensional unfolding.
Definition: AbsUnfoldND.hh:19
virtual const AbsUnfoldingFilterND * getFilter(bool throwIfNull=false) const
virtual bool unfold(const ArrayND< double > &observed, const Matrix< double > *observationCovarianceMatrix, ArrayND< double > *unfolded, Matrix< double > *unfoldedCovarianceMatrix)=0
static double probDelta(const ArrayND< double > &prev, const ArrayND< double > &next)
void validateUnfoldedShape(const ArrayND< double > &unfolded) const
virtual void useConvolutions(const bool b)
Definition: AbsUnfoldND.hh:57
virtual const ArrayND< double > & getInitialApproximation() const
virtual void setInitialApproximation(const ArrayND< double > &approx)
ArrayShape getUnfoldedShape() const
Definition: AbsUnfoldND.hh:67
bool usingConvolutions() const
Definition: AbsUnfoldND.hh:60
virtual void clearInitialApproximation()
ArrayShape getObservedShape() const
Definition: AbsUnfoldND.hh:63
virtual void setFilter(const AbsUnfoldingFilterND *f)
Definition: AbsUnfoldingFilterND.hh:28
ArrayShape shape() const
Definition: ResponseMatrix.hh:23
Definition: AbsArrayProjector.hh:14
std::vector< unsigned > ArrayShape
Definition: ArrayShape.hh:21