ROOTPWA
TPWALikelihoodC.h
Go to the documentation of this file.
1 
2 //
3 // Copyright 2009 Sebastian Neubert
4 //
5 // This file is part of rootpwa
6 //
7 // rootpwa is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // rootpwa is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with rootpwa. If not, see <http://www.gnu.org/licenses/>.
19 //
21 //-----------------------------------------------------------
22 // File and Version Information:
23 // $Id$
24 //
25 // Description:
26 // Likelihood function Object to use with ROOT minimizers
27 // Supports Constraint amplitudes!
28 //
29 // Author List:
30 // Sebastian Neubert TUM (original author)
31 //
32 //
33 //-----------------------------------------------------------
34 
35 #ifndef TPWALIKELIHOODC_HH
36 #define TPWALIKELIHOODC_HH
37 
38 // Base Class Headers ----------------
39 
40 
41 // Collaborating Class Headers -------
42 #include <vector>
43 #include <string>
44 #include <complex>
45 
46 
47 #include "TString.h"
48 #include "TMatrixD.h"
49 #include "Math/IFunction.h"
50 
51 #include "integral.h"
52 #include "matrix.h"
53 #include "TPWAAmp.h"
54 
55 
56 // Collaborating Class Declarations --
57 class TString;
58 class TCMatrix;
59 
61 
62 
63 class TPWALikelihoodC : public ROOT::Math::IGradientFunctionMultiDim {
64 public:
65 
66  // Constructors/Destructors ---------
69  TPWALikelihoodC* Clone() const {return new TPWALikelihoodC(*this);}
70  // Accessors -----------------------
71 
72  unsigned int NDim() const;
73  std::string parname(unsigned int i)const {return _parnames.at(i);}
74  const std::vector<std::string>& wavetitles() const {return _wavenames;}
75  double parthreshold(unsigned int i) const {return _parthresholds[i];}
76  double dLcache(unsigned int i) const {return _dLcache[i];}
77  unsigned int ncalls() const {return _ncalls;}
78  double Ltime() const {return _Ltime;}
79  double Ntime() const {return _Ntime;}
80  unsigned int nevents() const {return _nevents;}
81  const integral& normInt()const {return _I;}
82 
83 
84  // Modifiers -----------------------
85  //void SetRank(unsigned int rank);
86  void UseNormalizedAmps(bool flag=true){_useNorm=flag;}
87  // Set wavelist filename:
88  void Init(const TString& wavelist, unsigned int rank,
89  const TString& norm, const TString& acceptance,
90  int scaleevents, const TString constraints="");
91  void SetQuiet(bool flag=true){_quiet=flag;}
92 
93 
94  // Operations ----------------------
95  // Load Amplitudes into memory
96  void LoadAmplitudes();
97  //void LoadIntegrals(const TString& norm, const TString& acceptance);
98  void getIntCMatrix(TCMatrix& integr,
99  TCMatrix& acceptance);
100 
101  // convert parameter array into amplitudes:
102  void partoamp(const double* x) const;
103  void amptopar(double* x) const;
104  // Note: amps which do not exist in higher ranks are NOT built!
105 // convert parameters error matrix into error matrix of amplitudes
106  void buildCAmps(const double* x,
107  std::vector<std::complex<double> >& V,
108  std::vector<std::pair<int,int> >& indices,
109  std::vector<std::string>& names,
110  const TMatrixD& errpar,
111  TMatrixD& erramp,
112  bool withFlat=false);
113 
114 
115 
116  virtual double DoEval(const double*) const;
117  virtual double DoDerivative(const double*, unsigned int) const;
118 
119  // Calculate Function f and Derivatives df in one go
120  virtual void FdF(const double* x, double& f, double* df) const;
121  void Print() const ;
122 private:
123 
124  // Private Data Members ------------
125  unsigned int _rank;
126  unsigned int _dim;
127  unsigned int _nposrefl; // number of positive reflectivity waves
128  unsigned int _nnegrefl; // number of negative reflectivity waves
129  unsigned int _nevents;
130  unsigned int _nwaves;
131  mutable unsigned int _ncalls;
132  mutable double _Ltime; // total time spent calculating L
133  mutable double _Ntime; // total time spent calculating Normalization
134 
135  bool _quiet;
136  bool _useNorm; // use normalized amplitudes
137 
138  // production amplitude vectors per rank
139  std::vector<std::vector<TPWAAmp>*> _V; // production amplitudes
140  mutable TPWAAmp _Vflat; // amplitude for flat wave
141  unsigned int _NumNullConstraints; // number of null constraint waves
142  std::vector<std::string> _wavenames;
143  std::vector<std::string> _parnames;
144  std::vector<int> _reflect; // reflectivity of parameter
145  std::vector<double> _thresholds; // mass threshold for a wave
146  std::vector<double> _parthresholds; // mass threshold for a parameter
147  std::vector<unsigned int> _wmap; // map: waveindex -> id in normalization integral
148  std::vector<unsigned int> _accmap; // map: waveindex -> id in accpetance integral
149  mutable std::vector<double> _parcache; // parameter cache for derivative calc.
150  mutable std::vector<double> _dLcache; // cache for derivatives
151 
152  // derivative with resp to real/imaginary part resp.
153  // the dL are NOT well defined complex numbers!
154  mutable std::vector<std::vector<std::complex<double> >* > _dL; // complex derivatives
155  // derivative contribution of single event:
156  mutable std::vector<std::vector<std::complex<double> >* > _dl; // contribution of each event
157  // normalization contribution of derivative:
158  mutable std::vector<std::vector<std::complex<double> >* > _dLN;
159 
160 
161  // data cache:
162  std::vector<std::vector<std::complex<double> >* > _data;
163 
164  // normalization integrals
167 
169  mutable matrix<std::complex<double> > _accmat; // has to be mutable because
170  // of matrix accessor
171  // declaration not const
172 
173  // Private Methods -----------------
174  void ClearCache();
175  int geteps(TString wavename);
176  // add constraints return number of constraints that have been added
177  // used in Init
178  unsigned int addConstraints(TString ConstraintsFile);
179 
180 };
181 
182 #endif
183 
184 //--------------------------------------------------------------
185 // $Log$
186 //--------------------------------------------------------------