62 #include "reportingUtils.hpp"
63 #include "reportingUtilsRoot.hpp"
69 class TFitResult :
public TObject {
74 TFitResult(
const TFitResult& result);
75 TFitResult(
const TFitBin& fitBin);
76 virtual ~TFitResult();
79 void fill(
const unsigned int nmbEvents,
80 const unsigned int normNmbEvents,
81 const double massBinCenter,
82 const double logLikelihood,
84 const std::vector<std::complex<double> >& prodAmps,
85 const std::vector<std::string>& prodAmpNames,
86 const TMatrixT<double>& fitParCovMatrix,
87 const std::vector<std::pair<int, int> >& fitParCovMatrixIndices,
90 double massBinCenter()
const {
return _massBinCenter; }
91 double logLikelihood()
const {
return _logLikelihood; }
92 double evidence ()
const ;
93 unsigned int rank ()
const {
return _rank; }
94 unsigned int nmbEvents ()
const {
return _nmbEvents; }
95 unsigned int normNmbEvents()
const {
return _normNmbEvents; }
96 unsigned int nmbWaves ()
const {
return _waveNames.size(); }
97 unsigned int nmbProdAmps ()
const {
return _prodAmps.size(); }
99 TString waveName (
const unsigned int waveIndex)
const {
return _waveNames[waveIndex]; }
100 TString prodAmpName (
const unsigned int prodAmpIndex)
const {
return _prodAmpNames[prodAmpIndex]; }
102 double fitParameter (
const std::string& parName)
const;
104 double fitParameterCov(
const unsigned int parIndexA,
105 const unsigned int parIndexB)
const {
return _fitParCovMatrix[parIndexA][parIndexB]; }
106 inline void fitParameters (
double* parArray)
const;
109 std::complex<double> prodAmp (
const unsigned int prodAmpIndex)
const {
return std::complex<double>(_prodAmps[prodAmpIndex].Re(), _prodAmps[prodAmpIndex].Im()); }
110 inline TMatrixT<double> prodAmpCov(
const unsigned int prodAmpIndex)
const;
112 TMatrixT<double> prodAmpCov(
const std::vector<unsigned int>& prodAmpIndices)
const;
114 inline TMatrixT<double> prodAmpCov(
const std::vector<std::pair<unsigned int, unsigned int> >& prodAmpIndexPairs)
const;
116 inline TMatrixT<double> prodAmpCov(
const std::vector<unsigned int>& prodAmpIndicesA,
117 const std::vector<unsigned int>& prodAmpIndicesB)
const;
118 bool covMatrixValid()
const {
return _hasErrors; }
121 inline std::complex<double> normIntegral(
const unsigned int waveIndexA,
122 const unsigned int waveIndexB)
const;
125 std::complex<double> spinDensityMatrixElem (
const unsigned int waveIndexA,
126 const unsigned int waveIndexB)
const;
128 TMatrixT<double> spinDensityMatrixElemCov(
const unsigned int waveIndexA,
129 const unsigned int waveIndexB)
const;
132 double intensity (
const unsigned int waveIndex)
const {
return spinDensityMatrixElem(waveIndex, waveIndex).real(); }
134 double intensityErr(
const unsigned int waveIndex)
const {
return sqrt(spinDensityMatrixElemCov(waveIndex, waveIndex)[0][0]); }
135 double intensity (
const char* waveNamePattern)
const;
136 double intensityErr(
const char* waveNamePattern)
const;
137 double intensity ()
const {
return intensity(
""); }
138 double intensityErr()
const {
return intensityErr(
""); }
140 double phase (
const unsigned int waveIndexA,
141 const unsigned int waveIndexB)
const;
142 double phaseErr (
const unsigned int waveIndexA,
143 const unsigned int waveIndexB)
const;
144 double coherence (
const unsigned int waveIndexA,
145 const unsigned int waveIndexB)
const;
146 double coherenceErr(
const unsigned int waveIndexA,
147 const unsigned int waveIndexB)
const;
148 double overlap (
const unsigned int waveIndexA,
149 const unsigned int waveIndexB)
const;
150 double overlapErr (
const unsigned int waveIndexA,
151 const unsigned int waveIndexB)
const;
154 const std::vector<TComplex>& prodAmps ()
const {
return _prodAmps; }
155 const std::vector<std::string>& prodAmpNames ()
const {
return _prodAmpNames; }
156 const std::vector<std::string>& waveNames ()
const {
return _waveNames; }
157 const TMatrixT<Double_t>& fitParCovMatrix ()
const {
return _fitParCovMatrix; }
158 const std::vector<std::pair<Int_t, Int_t> >& fitParCovIndices ()
const {
return _fitParCovMatrixIndices; }
159 const TCMatrix& normIntegralMatrix()
const {
return _normIntegral; }
160 const std::map<Int_t, Int_t>& normIntIndexMap ()
const {
return _normIntIndexMap; }
162 inline std::ostream& printProdAmpNames(std::ostream& out = std::cout)
const;
163 inline std::ostream& printWaveNames (std::ostream& out = std::cout)
const;
164 inline std::ostream& printProdAmps (std::ostream& out = std::cout)
const;
165 inline std::ostream& printWaves (std::ostream& out = std::cout)
const;
167 virtual inline std::ostream& print(std::ostream& out = std::cout)
const;
168 friend std::ostream&
operator << (std::ostream& out,
169 const TFitResult& fitResult) {
return fitResult.print(out); }
174 UInt_t _normNmbEvents;
178 std::vector<TComplex> _prodAmps;
179 std::vector<std::string> _prodAmpNames;
180 std::vector<std::string> _waveNames;
182 TMatrixT<Double_t> _fitParCovMatrix;
183 std::vector<std::pair<Int_t, Int_t> > _fitParCovMatrixIndices;
185 std::map<Int_t, Int_t> _normIntIndexMap;
190 inline static TMatrixT<double> matrixRepr(
const std::complex<double>& c);
192 inline int rankOfProdAmp(
const unsigned int prodAmpIndex)
const;
194 std::complex<double> normIntegralForProdAmp(
const unsigned int prodAmpIndexA,
195 const unsigned int prodAmpIndexB)
const;
197 inline std::vector<unsigned int> waveIndicesMatchingPattern (
const std::string& waveNamePattern)
const;
198 inline std::vector<unsigned int> prodAmpIndicesMatchingPattern(
const std::string& ampNamePattern )
const;
199 std::vector<unsigned int> prodAmpIndicesForWave (
const unsigned int waveIndex)
const
200 {
return prodAmpIndicesMatchingPattern(_waveNames[waveIndex]); }
201 inline std::vector<std::pair<unsigned int, unsigned int> > prodAmpIndexPairsForWaves(
const unsigned int waveIndexA,
202 const unsigned int waveIndexB)
const;
204 inline double realValVariance(
const unsigned int waveIndexA,
205 const unsigned int waveIndexB,
206 const TMatrixT<double>& jacobian)
const;
209 TString wavetitle(
int i)
const
211 const TString ampName = _prodAmpNames[
i];
212 if (ampName.Contains(
"V_"))
213 return ampName(2, 1000);
215 return ampName(3, 1000);
221 ClassDef(TFitResult,1)
229 TFitResult::fitParameters(
double* parArray)
const
231 unsigned int countPar = 0;
232 for (
unsigned int i = 0; i < nmbProdAmps(); ++
i) {
233 parArray[countPar++] = prodAmp(i).real();
235 if (_fitParCovMatrixIndices[i].second >= 0)
236 parArray[countPar++] = prodAmp(i).imag();
244 TFitResult::prodAmpCov(
const unsigned int prodAmpIndex)
const {
246 const int i = _fitParCovMatrixIndices[prodAmpIndex].first;
247 const int j = _fitParCovMatrixIndices[prodAmpIndex].second;
248 TMatrixT<double> cov(2, 2);
249 cov[0][0] = _fitParCovMatrix[
i][
i];
251 cov[0][1] = _fitParCovMatrix[
i][j];
252 cov[1][0] = _fitParCovMatrix[j][
i];
253 cov[1][1] = _fitParCovMatrix[j][j];
266 TFitResult::prodAmpCov(
const std::vector<std::pair<unsigned int, unsigned int> >& prodAmpIndexPairs)
const
268 std::vector<unsigned int> prodAmpIndices;
270 for (
unsigned int i = 0; i < prodAmpIndexPairs.size(); ++
i)
271 prodAmpIndices.push_back(prodAmpIndexPairs[i].first);
273 for (
unsigned int i = 0; i < prodAmpIndexPairs.size(); ++
i)
274 prodAmpIndices.push_back(prodAmpIndexPairs[i].second);
275 return prodAmpCov(prodAmpIndices);
286 TFitResult::prodAmpCov(
const std::vector<unsigned int>& prodAmpIndicesA,
287 const std::vector<unsigned int>& prodAmpIndicesB)
const
289 std::vector<unsigned int> prodAmpIndices;
291 prodAmpIndices.assign(prodAmpIndicesA.begin(), prodAmpIndicesA.end());
293 prodAmpIndices.insert(prodAmpIndices.end(), prodAmpIndicesB.begin(), prodAmpIndicesB.end());
294 return prodAmpCov(prodAmpIndices);
301 TFitResult::normIntegral(
const unsigned int waveIndexA,
302 const unsigned int waveIndexB)
const
304 const TComplex norm = _normIntegral(waveIndexA, waveIndexB);
305 return std::complex<double>(norm.Re(), norm.Im());
312 TFitResult::printProdAmpNames(std::ostream& out)
const
314 out <<
" Production amplitude names:" << std::endl;
315 for (
unsigned int i = 0; i < nmbProdAmps(); ++
i)
316 out <<
" " << std::setw(3) << i <<
" " << _prodAmpNames[
i] << std::endl;
324 TFitResult::printWaveNames(std::ostream& out)
const
326 out <<
" Wave names:" << std::endl;
327 for (
unsigned int i = 0; i < nmbWaves(); ++
i)
328 out <<
" " << std::setw(3) << i <<
" " << _waveNames[
i] << std::endl;
336 TFitResult::printProdAmps(std::ostream& out)
const
338 out <<
"Production amplitudes:" << std::endl;
339 for (
unsigned int i = 0; i < nmbProdAmps(); ++
i) {
340 out <<
" " << std::setw(3) << i <<
" " << _prodAmpNames[
i] <<
" = " << prodAmp(i)
341 <<
", cov = " << prodAmpCov(i) << std::endl;
350 TFitResult::printWaves(std::ostream& out)
const
352 out <<
"Waves:" << std::endl;
353 for (
unsigned int i = 0; i < nmbWaves(); ++
i) {
354 out <<
" " << std::setw(3) << i <<
" " << _waveNames[
i] <<
" = " << intensity(i)
355 <<
" +- " << intensityErr(i) << std::endl;
364 TFitResult::print(std::ostream& out)
const
366 out <<
"TFitResult dump:" << std::endl
367 <<
" number of events .................... " << _nmbEvents << std::endl
368 <<
" number of events to normalize to .... " << _normNmbEvents << std::endl
369 <<
" center value of mass bin ............ " << _massBinCenter << std::endl
370 <<
" log(likelihood) at maximum .......... " << _logLikelihood << std::endl
371 <<
" rank of fit ......................... " << _rank << std::endl
372 <<
" bin has a valid covariance matrix ... " << _hasErrors << std::endl;
375 out <<
" covariance matrix:" << std::endl << _fitParCovMatrix << std::endl;
376 out <<
" covariance matrix indices:" << std::endl;
377 for (
unsigned int i = 0; i < _fitParCovMatrixIndices.size(); ++
i)
378 out <<
" index " << std::setw(3) << i <<
" = (" << std::setw(3) << _fitParCovMatrixIndices[
i].first
379 <<
", " << std::setw(3) << _fitParCovMatrixIndices[
i].second <<
")" << std::endl;
380 out <<
" normalization integral (w/o acceptance):" << std::endl << _normIntegral << std::endl;
381 out <<
" map of production amplitude indices to indices in normalization integral:" << std::endl;
382 for (std::map<Int_t, Int_t>::const_iterator i = _normIntIndexMap.begin(); i != _normIntIndexMap.end(); ++
i)
383 out <<
" prod. amp [" << std::setw(3) << i->first <<
"] "
384 <<
"-> norm. int. [" << std::setw(3) << i->second <<
"]" << std::endl;
396 TFitResult::matrixRepr(
const std::complex<double>& c)
398 TMatrixT<double> m(2, 2);
399 m[0][0] = m[1][1] = c.real();
409 TFitResult::rankOfProdAmp(
const unsigned int prodAmpIndex)
const
411 const TString ampName = _prodAmpNames[prodAmpIndex];
412 if (ampName.Contains(
"flat"))
416 return TString(ampName(1, 1)).Atoi();
422 std::vector<unsigned int>
423 TFitResult::waveIndicesMatchingPattern(
const std::string& waveNamePattern)
const
425 std::vector<unsigned int> waveIndices;
426 for (
unsigned int waveIndex = 0; waveIndex < nmbWaves(); ++waveIndex)
427 if (waveName(waveIndex).Contains(waveNamePattern))
428 waveIndices.push_back(waveIndex);
435 std::vector<unsigned int>
436 TFitResult::prodAmpIndicesMatchingPattern(
const std::string& ampNamePattern)
const
438 std::vector<unsigned int> prodAmpIndices;
439 for (
unsigned int prodAmpIndex = 0; prodAmpIndex < nmbProdAmps(); ++prodAmpIndex)
440 if (prodAmpName(prodAmpIndex).Contains(ampNamePattern))
441 prodAmpIndices.push_back(prodAmpIndex);
442 return prodAmpIndices;
448 std::vector<std::pair<unsigned int, unsigned int> >
449 TFitResult::prodAmpIndexPairsForWaves(
const unsigned int waveIndexA,
450 const unsigned int waveIndexB)
const
452 std::vector<std::pair<unsigned int, unsigned int> > prodAmpIndexPairs;
453 const std::vector<unsigned int> prodAmpIndicesA = prodAmpIndicesForWave(waveIndexA);
454 const std::vector<unsigned int> prodAmpIndicesB = prodAmpIndicesForWave(waveIndexB);
455 for (
unsigned int countAmpA = 0; countAmpA < prodAmpIndicesA.size(); ++countAmpA) {
456 const unsigned int ampIndexA = prodAmpIndicesA[countAmpA];
457 const int ampRankA = rankOfProdAmp(ampIndexA);
460 for (
unsigned int countAmpB = 0; countAmpB < prodAmpIndicesB.size(); ++countAmpB)
461 if (rankOfProdAmp(prodAmpIndicesB[countAmpB]) == ampRankA) {
462 ampIndexB = prodAmpIndicesB[countAmpB];
466 prodAmpIndexPairs.push_back(std::make_pair(ampIndexA, (
unsigned int)ampIndexB));
468 return prodAmpIndexPairs;
475 TFitResult::realValVariance(
const unsigned int waveIndexA,
476 const unsigned int waveIndexB,
477 const TMatrixT<double>& jacobian)
const
481 const TMatrixT<double> spinDensCov = spinDensityMatrixElemCov(waveIndexA, waveIndexB);
482 const TMatrixT<double> jacobianT(TMatrixT<double>::kTransposed, jacobian);
483 const TMatrixT<double> spinDensCovJT = spinDensCov * jacobianT;
484 const TMatrixT<double> cov = jacobian * spinDensCovJT;
489 #endif // USE_TFITRESULT
492 #endif // TFITRESULT_HH