BAT  0.9.4
The Bayesian analysis toolkit
 All Classes Namespaces Functions Variables Enumerations
BCMVCombination.h
1 /*
2  * Copyright (C) 2007-2014, the BAT core developer team
3  * All rights reserved.
4  *
5  * For the licensing terms see doc/COPYING.
6  * For documentation see http://mpp.mpg.de/bat
7  */
8 
9 // ---------------------------------------------------------
10 
11 #ifndef __BCMVCOMBINATION__H
12 #define __BCMVCOMBINATION__H
13 
14 #include "../../BAT/BCModel.h"
15 
16 #include <TMath.h>
17 #include <TMatrixDEigen.h>
18 #include <TMatrixT.h>
19 #include <TVectorT.h>
20 
21 class BCMVCMeasurement;
22 class BCMVCUncertainty;
23 class BCMVCObservable;
24 
25 // ---------------------------------------------------------
26 class BCMVCombination : public BCModel
27 {
28 
29  public:
30 
31  // Constructor
33 
34  // Destructor
35  ~BCMVCombination();
36 
37  // Add a parameter
38  // name: the name of the parameter
39  // min: the minimum value of the parameter
40  // max: the maximum value of the parameter
41  void AddObservable(std::string name, double min, double max);
42 
43  // Add a source of systematic uncertainty
44  // name: the name of the uncertainty
45  void AddUncertainty(std::string name);
46 
47  // Add a measurement
48  // name: the name of the measurement
49  // observable: the name of the observable
50  // central: the central value of the measurement
51  // uncertainties the uncertainties
52  void AddMeasurement(std::string name, std::string observable, double value, std::vector<double> uncertainties);
53 
54  // getters
55 
56  // return the number of observables
57  int GetNObservables()
58  { return fNObservables; };
59 
60  // return the number of uncertainties
61  int GetNUncertainties()
62  { return int(fUncertainties.size()); };
63 
64  // return the number of measurements
65  int GetNMeasurements()
66  { return int(fMeasurements.size()); };
67 
68  // return the number of measurements
69  int GetNActiveMeasurements();
70 
71  // return a specific uncertainty
72  BCMVCUncertainty* GetUncertainty(int index)
73  { return fUncertainties.at(index); }
74 
75  // return a specific measurement
76  BCMVCMeasurement* GetMeasurement(int index)
77  { return fMeasurements.at(index); }
78 
79  // return the total covariance matrix
80  TMatrixD GetCovarianceMatrix()
81  { return fCovarianceMatrix; };
82 
83  // return the BLUE weights
84  TMatrixD GetBLUEWeights()
85  { return fBLUEWeights; };
86 
87  // return the BLUE central values
88  TVectorD GetBLUECentralValues()
89  { return fBLUECentral; };
90 
91  // return the BLUE uncertainties
92  TVectorD GetBLUEUncertainties()
93  { return fBLUEUncertainties; };
94 
95  // return the BLUE uncertainties for a certain source of
96  // uncertainty
97  // index: the index of the uncertainty source
98  TVectorD GetBLUEUncertainties(int index)
99  { return fBLUEUncertaintiesPerSource.at(index); };
100 
101  // return the BLUE covariance matrix
102  TMatrixD GetBLUECovarianceMatrix()
103  { return fBLUECovarianceMatrix; };
104 
105  // return the BLUE covariance matrix for a certain source of
106  // uncertainty
107  // index: the index of the uncertainty source
108  TMatrixD GetBLUECovarianceMatrix(int index)
109  { return fBLUECovarianceMatrices.at(index); };
110 
111  // return the BLUE correlation matrix for a certain source of
112  // uncertainty
113  // index: the index of the uncertainty source
114  TMatrixD GetBLUECorrelationMatrix(int index)
115  { return fBLUECorrelationMatrices.at(index); };
116 
117  // return the BLUE correlation matrix
118  TMatrixD GetBLUECorrelationMatrix()
119  { return fBLUECorrelationMatrix; };
120 
121  // return the vector of observables
122  std::vector<int> GetVectorObservable()
123  { return fVectorObservable; };
124 
125  // return the vector of measurements
126  TVectorD GetVectorMeasurements()
127  { return fVectorMeasurements; };
128 
129  // return the index of the measurements
130  int GetIndexMeasurement(std::string measurement, std::string observable);
131 
132  // return the index of the uncertainty
133  int GetIndexUncertainty(std::string name);
134 
135  // return the index of the observable
136  int GetIndexObservable(std::string name);
137 
138  // misc
139 
140  // read input file
141  int ReadInput(std::string filename);
142 
143  // calculate the correlation matrix for a particular uncertainty
144  void CalculateCorrelationMatrix(int index);
145 
146  // calculate the total covariance matrix
147  void CalculateCovarianceMatrix(std::vector<double> nuisance = std::vector<double>(0));
148 
149  // calculate helper vectors
150  void CalculateHelperVectors();
151 
152  // check for positive definiteness of the covariance matrix
153  bool PositiveDefinite();
154 
155  // calculate BLUE
156  void CalculateBLUE();
157 
158  // calculate all necessary matrices
159  void PrepareAnalysis();
160 
161  // output
162 
163  // print summary to screen
164  void PrintBLUEResults(std::string filename);
165 
166  void PrintMatrix(TMatrixT<double> &matrix, std::string name="matrix");
167 
168  void PrintVector(TVectorD &vector, std::string name="vector");
169 
170  // BAT methods
171 
172  double LogLikelihood(const std::vector<double> &parameters);
173 
174  protected:
175 
177  int index_uncertainty;
178  int index_measurement1;
179  int index_measurement2;
180  int index_rhoparameter;
181  double pre;
182  };
183 
184  // the names of the uncertainties
185  std::vector<BCMVCUncertainty*> fUncertainties;
186 
187  // the measurements
188  std::vector<BCMVCMeasurement*> fMeasurements;
189 
190  // the total covariance matrix
191  TMatrixD fCovarianceMatrix;
192 
193  // the inverse of the covariance matrix
194  TMatrixD fInvCovarianceMatrix;
195 
196  // the determinant of the covariance matrix
197  double fDetCovariance;
198 
199  // helper: the vector of measurements
200  TVectorD fVectorMeasurements;
201 
202  // helper: the vector of active measurements
203  TVectorD fVectorActiveMeasurements;
204 
205  // the vector of the index of the observables being measured
206  std::vector<int> fVectorObservable;
207 
208  // the vector of the index of the observables being measured if active
209  std::vector<int> fVectorActiveObservable;
210 
211  // the BLUE matrix
212  TMatrixD fBLUEWeights;
213 
214  // the BLUE central values
215  TVectorD fBLUECentral;
216 
217  // the BLUE uncertainties
218  TVectorD fBLUEUncertainties;
219 
220  // the BLUE uncertainties per source
221  std::vector<TVectorD> fBLUEUncertaintiesPerSource;
222 
223  // the BLUE covariance matrix
224  TMatrixD fBLUECovarianceMatrix;
225 
226  // the BLUE covariance matrices for all uncertainties
227  std::vector<TMatrixD> fBLUECovarianceMatrices;
228 
229  // the BLUE covariance matrices for all uncertainties
230  std::vector<TMatrixD> fBLUECorrelationMatrices;
231 
232  // the BLUE correlation matrix
233  TMatrixD fBLUECorrelationMatrix;
234 
235  // number of observables
236  int fNObservables;
237 
238  // number of nuisance parameters for correlations
239  int fNNuisanceCorrelation;
240 
241  // nuisance parameters
242  std::vector<NuisanceParameter> fNuisanceCorrelation;
243 
244  // the observables
245  std::vector<BCMVCObservable*> fObservables;
246 
247 };
248 // ---------------------------------------------------------
249 
250 #endif
251 
The base class for all user-defined models.
Definition: BCModel.h:50
double LogLikelihood(const std::vector< double > &parameters)