MINT2
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
FitAmpPairCovariance Class Reference

#include <FitAmpPairCovariance.h>

Public Member Functions

 FitAmpPairCovariance (const FitAmpPairList *myList)
 
 FitAmpPairCovariance (const FitAmpPairCovariance &other)
 
 FitAmpPairCovariance (const FitAmpPairCovariance &other, const FitAmpPairList *newList)
 
virtual ~FitAmpPairCovariance ()
 
bool add (const FitAmpPairCovariance &other)
 
bool reset ()
 
bool addLastEventFromList ()
 
bool calculateAll ()
 
double getFractionVariance (int i)
 
double getFractionError (int i)
 
double getFractionSumVariance ()
 
double getFractionSumError ()
 
double getIntegralVariance ()
 
double getIntegralError ()
 
unsigned int size () const
 
bool isValid () const
 
bool save (const std::string &asSubdirOf=".") const
 
bool retrieve (const std::string &fromDirectory=".")
 
int Nevents () const
 
FitAmpPairCovarianceoperator+= (const FitAmpPairCovariance &other)
 
FitAmpPairCovariance operator+ (const FitAmpPairCovariance &other) const
 

Private Member Functions

std::string realName (int listPosition) const
 
std::string imagName (int listPosition) const
 
int indexReal (int listPosition) const
 
int indexImag (int listPosition) const
 
int listPositionFromIndex (int idx) const
 
bool make_dN_by_d2N ()
 
bool make_dFraction_by_dN ()
 
bool make_dFractionSum_by_dFraction ()
 
bool make_dIntegral_by_dN ()
 
bool resize ()
 
unsigned int maxSize () const
 
bool make2NCovariance ()
 
bool makeNCovariance ()
 
bool makeFractionCovariance ()
 
bool makeFractionSumCovariance ()
 
bool makeIntegralCovariance ()
 
bool clearAll ()
 
bool makeDirectory (const std::string &asSubdirOf=".") const
 
std::string dirName (const std::string &asSubdirOf=".") const
 
std::string matrix_x_fname (const std::string &asSubdirOf=".") const
 
std::string matrix_xy_fname (const std::string &asSubdirOf=".") const
 
bool save_sum_x (const std::string &inDirectory) const
 
bool save_sum_xy (const std::string &inDirectory) const
 
bool retrieve_sum_x (const std::string &inDirectory)
 
bool retrieve_sum_xy (const std::string &inDirectory)
 
bool isCompatibleWith (const FitAmpPairCovariance &other) const
 

Private Attributes

const FitAmpPairList_myList
 
unsigned int _Nevents
 
unsigned int _size
 
bool _needToRecalculate
 
TMatrixT< float > _sum_x
 
TMatrixTSym< float > _sum_xy
 
TMatrixTSym< float > _cov2N
 
TMatrixTSym< float > _corr2N
 
TMatrixTSym< float > _cov
 
TMatrixTSym< float > _corr
 
TMatrixTSym< float > _fractionCov
 
TMatrixTSym< float > _fractionSumCov
 
TMatrixTSym< float > _integralCov
 
TMatrixT< float > _dN_by_d2N
 
TMatrixT< float > _dFraction_by_dN
 
TMatrixT< float > _dFractionSum_by_dFraction
 
TMatrixT< float > _dIntegral_by_dN
 

Static Private Attributes

static unsigned int _maxSize = 1500
 

Detailed Description

Definition at line 11 of file FitAmpPairCovariance.h.

Constructor & Destructor Documentation

◆ FitAmpPairCovariance() [1/3]

FitAmpPairCovariance::FitAmpPairCovariance ( const FitAmpPairList myList)

Definition at line 18 of file FitAmpPairCovariance.cpp.

19  : _myList(myList)
20  , _Nevents(0)
21  , _size()
22  , _needToRecalculate(true)
23  , _sum_x(1, 1)
24  , _sum_xy(1)
25  , _cov2N(2)
26  , _corr2N(2)
27  , _cov(1)
28  , _corr(1)
29  , _fractionCov(1)
30  , _fractionSumCov(1)
31  , _integralCov(1)
32  , _dN_by_d2N(1, 2)
33  , _dFraction_by_dN(1, 1)
35  , _dIntegral_by_dN(1, 1)
36 {
37  if(0 != _myList && _myList->size() >=1) resize();
38 }
TMatrixT< float > _sum_x
TMatrixTSym< float > _fractionCov
TMatrixTSym< float > _cov2N
const FitAmpPairList * _myList
TMatrixTSym< float > _fractionSumCov
TMatrixT< float > _dFractionSum_by_dFraction
TMatrixTSym< float > _sum_xy
TMatrixT< float > _dFraction_by_dN
unsigned int size() const
TMatrixTSym< float > _corr2N
TMatrixT< float > _dN_by_d2N
TMatrixTSym< float > _integralCov
TMatrixT< float > _dIntegral_by_dN
TMatrixTSym< float > _cov
TMatrixTSym< float > _corr

◆ FitAmpPairCovariance() [2/3]

FitAmpPairCovariance::FitAmpPairCovariance ( const FitAmpPairCovariance other)

Definition at line 39 of file FitAmpPairCovariance.cpp.

40  : _myList(other._myList)
41  , _Nevents(other._Nevents)
42  , _size(other._size)
43  , _needToRecalculate(true)
44  , _sum_x(other._sum_x)
45  , _sum_xy(other._sum_xy)
46  , _cov2N(other._cov2N)
47  , _corr2N(other._corr2N)
48  , _cov(other._cov)
49  , _corr(other._corr)
50  , _fractionCov(other._fractionCov)
52  , _integralCov(other._integralCov)
53  , _dN_by_d2N(other._dN_by_d2N)
57 {
58 }
TMatrixT< float > _sum_x
TMatrixTSym< float > _fractionCov
TMatrixTSym< float > _cov2N
const FitAmpPairList * _myList
TMatrixTSym< float > _fractionSumCov
TMatrixT< float > _dFractionSum_by_dFraction
TMatrixTSym< float > _sum_xy
TMatrixT< float > _dFraction_by_dN
TMatrixTSym< float > _corr2N
TMatrixT< float > _dN_by_d2N
TMatrixTSym< float > _integralCov
TMatrixT< float > _dIntegral_by_dN
TMatrixTSym< float > _cov
TMatrixTSym< float > _corr

◆ FitAmpPairCovariance() [3/3]

FitAmpPairCovariance::FitAmpPairCovariance ( const FitAmpPairCovariance other,
const FitAmpPairList newList 
)

Definition at line 59 of file FitAmpPairCovariance.cpp.

61  : _myList(newList)
62  , _Nevents(other._Nevents)
63  , _size(other._size)
64  , _needToRecalculate(true)
65  , _sum_x(other._sum_x)
66  , _sum_xy(other._sum_xy)
67  , _cov2N(other._cov2N)
68  , _corr2N(other._corr2N)
69  , _cov(other._cov)
70  , _corr(other._corr)
71  , _fractionCov(other._fractionCov)
73  , _integralCov(other._integralCov)
74  , _dN_by_d2N(other._dN_by_d2N)
78 {
79 }
TMatrixT< float > _sum_x
TMatrixTSym< float > _fractionCov
TMatrixTSym< float > _cov2N
const FitAmpPairList * _myList
TMatrixTSym< float > _fractionSumCov
TMatrixT< float > _dFractionSum_by_dFraction
TMatrixTSym< float > _sum_xy
TMatrixT< float > _dFraction_by_dN
TMatrixTSym< float > _corr2N
TMatrixT< float > _dN_by_d2N
TMatrixTSym< float > _integralCov
TMatrixT< float > _dIntegral_by_dN
TMatrixTSym< float > _cov
TMatrixTSym< float > _corr

◆ ~FitAmpPairCovariance()

FitAmpPairCovariance::~FitAmpPairCovariance ( )
virtual

Definition at line 81 of file FitAmpPairCovariance.cpp.

81  {
82  clearAll();
83 }

Member Function Documentation

◆ add()

bool FitAmpPairCovariance::add ( const FitAmpPairCovariance other)

Definition at line 99 of file FitAmpPairCovariance.cpp.

99  {
100  if(0 == _myList || 0 == other._myList) {
101  cout << "WARNING in FitAmpPairCovariance::add: "
102  << "trying to add incompatible FitAmpPairCovariances"
103  << "\n\t _myListPtr = " << _myList << " other's: " << other._myList
104  << endl;
105  return false;
106  }
107  if(! isCompatibleWith(other)){
108  cout << "WARNING in FitAmpPairCovariance::add: "
109  << "trying to add incompatible FitAmpPairCovariances"
110  << endl;
111  return false;
112  }
113  _needToRecalculate = true;
114  _Nevents += other._Nevents;
115  _sum_x += other._sum_x;
116  _sum_xy += other._sum_xy;
117 
118  return true;
119 }
TMatrixT< float > _sum_x
const FitAmpPairList * _myList
TMatrixTSym< float > _sum_xy
bool isCompatibleWith(const FitAmpPairCovariance &other) const

◆ addLastEventFromList()

bool FitAmpPairCovariance::addLastEventFromList ( )

Definition at line 177 of file FitAmpPairCovariance.cpp.

177  {
178  bool dbThis=false;
179  if(size() != _myList->size()) {
180  if(dbThis) cout << "FitAmpPairCovariance::addLastEventFromList() size() "
181  << size() << " == " << _myList->size() << endl;
182  if(! resize()) return false;
183  }
184  _needToRecalculate = true;
185  _Nevents++;
186  if(dbThis)cout << "FitAmpPairCovariance::addLastEventFromList()"
187  << " adding event to cov matrix." << endl;
188 
189  if(! isValid()) return false;
190  for(unsigned int i=0; i < _myList->size(); i++){
191  if(dbThis) cout << " i= " << i << endl;
192  double re_i = _myList->at(i).lastEntry().real();
193  double im_i = _myList->at(i).lastEntry().imag();
194  _sum_x(indexReal(i), 0) += re_i;
195  _sum_x(indexImag(i), 0) += im_i;
196 
197  for(unsigned int j=0; j < _myList->size(); j++){
198  double re_j = _myList->at(j).lastEntry().real();
199  double im_j = _myList->at(j).lastEntry().imag();
200 
201  _sum_xy(indexReal(i), indexReal(j)) += re_i * re_j;
202  _sum_xy(indexReal(i), indexImag(j)) += re_i * im_j;
203  _sum_xy(indexImag(i), indexReal(j)) += im_i * re_j;
204  _sum_xy(indexImag(i), indexImag(j)) += im_i * im_j;
205  }
206  }
207  return true;
208 }
int indexImag(int listPosition) const
TMatrixT< float > _sum_x
std::complex< double > lastEntry() const
Definition: FitAmpPair.cpp:443
int indexReal(int listPosition) const
const FitAmpPairList * _myList
T & at(unsigned int i)
TMatrixTSym< float > _sum_xy
unsigned int size() const
unsigned int size() const

◆ calculateAll()

bool FitAmpPairCovariance::calculateAll ( )

Definition at line 210 of file FitAmpPairCovariance.cpp.

210  {
211  bool dbThis=false;
212  if(! isValid()) return false;
213  bool sc=true;
214  if(dbThis) cout << "FitAmpPairCovariance::calculateAll"
215  << " making dN_by_d2N" << endl;
216  sc &= make_dN_by_d2N();
217 
218  if(dbThis) cout << "FitAmpPairCovariance::calculateAll"
219  << " making dFraction_by_dN" << endl;
220  sc &= make_dFraction_by_dN();
221 
222  if(dbThis) cout << "FitAmpPairCovariance::calculateAll"
223  << " making dFractionSum_by_dFraction" << endl;
225 
226  if(dbThis) cout << "FitAmpPairCovariance::calculateAll"
227  << " making dIntegral_by_dN" << endl;
228  sc &= make_dIntegral_by_dN();
229 
230  if(dbThis) cout << "FitAmpPairCovariance::calculateAll"
231  << " making 2NCovariance" << endl;
232  sc &= make2NCovariance();
233  if(dbThis) cout << "FitAmpPairCovariance::calculateAll"
234  << " making NCovariance" << endl;
235  sc &= makeNCovariance();
236  if(dbThis) cout << "FitAmpPairCovariance::calculateAll"
237  << " making FractionCovariance" << endl;
238  sc &= makeFractionCovariance();
239  if(dbThis) cout << "FitAmpPairCovariance::calculateAll"
240  << " making FractionSumCovariance" << endl;
242  if(dbThis) cout << "FitAmpPairCovariance::calculateAll"
243  << " making IntegralCovariance" << endl;
244  sc &= makeIntegralCovariance();
245 
246 
247 
248  //_needToRecalculate=false;
249  return sc;
250 }

◆ clearAll()

bool FitAmpPairCovariance::clearAll ( )
private

Definition at line 573 of file FitAmpPairCovariance.cpp.

573  {
574  _Nevents=0;
575  _needToRecalculate=true;
576  resize();
577  if(0 != this->size()){
578  _sum_x *= 0;
579  _sum_xy *= 0;
580  }
581  return 0;
582 }
TMatrixT< float > _sum_x
TMatrixTSym< float > _sum_xy
unsigned int size() const

◆ dirName()

std::string FitAmpPairCovariance::dirName ( const std::string &  asSubdirOf = ".") const
private

Definition at line 625 of file FitAmpPairCovariance.cpp.

625  {
626  return asSubdirOf +"/" + "FitAmpPairCovariance";
627 }

◆ getFractionError()

double FitAmpPairCovariance::getFractionError ( int  i)

Definition at line 501 of file FitAmpPairCovariance.cpp.

501  {
502  double V = getFractionVariance(i);
503  if(V < 0){
504  cout << "ERROR in FitAmpPairCovariance::getFractionError"
505  << " variance is " << V << " which is < 0."
506  << " will return -9999."
507  << endl;
508  return -9999.0;
509  }
510  return sqrt(V);
511 }

◆ getFractionSumError()

double FitAmpPairCovariance::getFractionSumError ( )

Definition at line 518 of file FitAmpPairCovariance.cpp.

518  {
519  double V = getFractionSumVariance();
520  if(V < 0){
521  cout << "ERROR in FitAmpPairCovariance::getFractionSumError"
522  << " variance is " << V << " which is < 0."
523  << " will return 0."
524  << endl;
525  return 0;
526  }
527  return sqrt(V);
528 }

◆ getFractionSumVariance()

double FitAmpPairCovariance::getFractionSumVariance ( )

Definition at line 513 of file FitAmpPairCovariance.cpp.

513  {
515  return _fractionSumCov(0,0);
516 }
TMatrixTSym< float > _fractionSumCov

◆ getFractionVariance()

double FitAmpPairCovariance::getFractionVariance ( int  i)

Definition at line 495 of file FitAmpPairCovariance.cpp.

495  {
497  if(i < 0 || i >= _fractionCov.GetNcols()) return -9999.0;
498  if(i < 0 || i >= _fractionCov.GetNrows()) return -9999.0;
499  return _fractionCov(i, i);
500 }
TMatrixTSym< float > _fractionCov

◆ getIntegralError()

double FitAmpPairCovariance::getIntegralError ( )

Definition at line 537 of file FitAmpPairCovariance.cpp.

537  {
538  double V = getIntegralVariance();
539  if(V < 0){
540  cout << "ERROR in FitAmpPairCovariance::getFractionError"
541  << " variance is " << V << " which is < 0."
542  << " will return -9999."
543  << endl;
544  return -9999.0;
545  }
546  return sqrt(V);
547 }

◆ getIntegralVariance()

double FitAmpPairCovariance::getIntegralVariance ( )

Definition at line 530 of file FitAmpPairCovariance.cpp.

530  {
531  bool dbThis=false;
532  if(dbThis) cout << "need to recalculate ? " << _needToRecalculate << endl;
534  if(_integralCov.GetNcols() < 1 || _integralCov.GetNrows() < 1) return -9999.0;
535  return _integralCov(0,0);
536 }
TMatrixTSym< float > _integralCov

◆ imagName()

std::string FitAmpPairCovariance::imagName ( int  listPosition) const
private

Definition at line 173 of file FitAmpPairCovariance.cpp.

173  {
174  return _myList->at(listPosition).name() + "_imag";
175 }
const FitAmpPairList * _myList
T & at(unsigned int i)
const std::string & name() const
Definition: FitAmpPair.cpp:605

◆ indexImag()

int FitAmpPairCovariance::indexImag ( int  listPosition) const
inlineprivate

Definition at line 36 of file FitAmpPairCovariance.h.

36 {return 2*listPosition + 1;}

◆ indexReal()

int FitAmpPairCovariance::indexReal ( int  listPosition) const
inlineprivate

Definition at line 35 of file FitAmpPairCovariance.h.

35 {return 2*listPosition;}

◆ isCompatibleWith()

bool FitAmpPairCovariance::isCompatibleWith ( const FitAmpPairCovariance other) const
private

Definition at line 84 of file FitAmpPairCovariance.cpp.

85  {
86  if(0 == _myList && 0 == other._myList) return true;
87  if(0 == _myList || 0 == other._myList) return false;
88  if(_myList->size() != other._myList->size()) return false;
89 
90  if(! _myList->isCompatibleWith(*(other._myList))) return false;
91 
92  // the following check should be redundant:
93  for(unsigned int i=0; i < this->size(); i++){
94  if(realName(i) != other.realName(i)) return false;
95  if(imagName(i) != other.imagName(i)) return false;
96  }
97  return true;
98 }
std::string realName(int listPosition) const
std::string imagName(int listPosition) const
bool isCompatibleWith(const FitAmpPairList &other) const
const FitAmpPairList * _myList
unsigned int size() const
unsigned int size() const

◆ isValid()

bool FitAmpPairCovariance::isValid ( ) const

Definition at line 549 of file FitAmpPairCovariance.cpp.

549  {
550  bool dbThis=false;
551  static int numWarnings=0;
552  const static int maxWarnings=10;
553  if(dbThis){
554  cout << " FitAmpPairCovariance::isValid() with: "
555  << size() << " == " << _sum_x.GetNcols() << " ? " << endl;
556  }
557  if(size() > maxSize()){
558  if(numWarnings < 10){
559  cout << "WARNING: FitAmpPairCovariance::isValid returns false"
560  << " because size (" << size() << ") is too big"
561  << endl;
562  cout << " Will print this " << maxWarnings
563  << " times (" << numWarnings << ")." << endl;
564  }
565  numWarnings++;
566  return false;
567  }
568  if(size() <= 0)return false;
569  //if((unsigned int) _sum_x.GetNcols() != 2*size()) return false;
570  return true;
571 }
TMatrixT< float > _sum_x
unsigned int maxSize() const
unsigned int size() const

◆ listPositionFromIndex()

int FitAmpPairCovariance::listPositionFromIndex ( int  idx) const
inlineprivate

Definition at line 37 of file FitAmpPairCovariance.h.

37 {return idx/2;}

◆ make2NCovariance()

bool FitAmpPairCovariance::make2NCovariance ( )
private

Definition at line 349 of file FitAmpPairCovariance.cpp.

349  {
350  bool dbThis=false;
351  if(dbThis) cout << "making 2N covariance" << endl;
352 
353  double dN = _myList->numEvents();
354  TMatrixT<float> mean_x(_myList->size()*2, 1);
355  TMatrixTSym<float> mean_xy(_myList->size()*2);
356 
357  mean_x = _sum_x;
358  mean_x *= 1./dN;
359 
360  mean_xy = _sum_xy;
361  mean_xy *= 1./dN;
362 
363  for(unsigned int i=0; i < _myList->size()*2; i++){
364  for(unsigned int j=0; j < _myList->size()*2; j++){
365  _cov2N(i, j) = (mean_xy(i,j) - mean_x(i,0)*mean_x(j,0));
366  // above: cov of the distribution
367  // now: .. of the mean
368  _cov2N(i, j) /= dN;
369  // now taking into account other factors that I muliply the result
370  // with.
371  int il = listPositionFromIndex(i);
372  int jl = listPositionFromIndex(j);
373  double sfden = _myList->at(il).weightSum() * _myList->at(jl).weightSum();
374  if(sfden > 0){
375  _cov2N(i, j) *= dN*dN/sfden;
376  }
377  }
378  }
379  for(unsigned int i=0; i < _myList->size()*2; i++){
380  for(unsigned int j=0; j < _myList->size()*2; j++){
381  double den = _cov2N(i,i)*_cov2N(j,j);
382  if(den > 0){
383  _corr2N(i,j) = _cov2N(i,j)/sqrt(den);
384  }
385  }
386  }
387 
388  if(dbThis){
389  cout << "After " << _Nevents << "events" << endl;
390  cout << "mean matrix" << endl;
391  mean_x.Print();
392  cout << "Covariance Matrix 2N" << endl;
393  _cov2N.Print();
394  cout << "Correlation Matrix 2N" << endl;
395  _corr2N.Print();
396  }
397  return true;
398 
399 }
TMatrixT< float > _sum_x
TMatrixTSym< float > _cov2N
int listPositionFromIndex(int idx) const
const FitAmpPairList * _myList
double weightSum() const
Definition: FitAmpPair.cpp:480
T & at(unsigned int i)
TMatrixTSym< float > _sum_xy
unsigned int size() const
TMatrixTSym< float > _corr2N
virtual int numEvents() const

◆ make_dFraction_by_dN()

bool FitAmpPairCovariance::make_dFraction_by_dN ( )
private

Definition at line 278 of file FitAmpPairCovariance.cpp.

278  {
279  bool dbThis=false;
280  if(dbThis) cout << "FitAmpPairCovariance::make_dFraction_by_dN() called"
281  << endl;
282  /*
283  We are calculating trafo matrix for the following trafo:
284 
285  f_a = a/(a + b + c...)
286 
287 
288  diagonal terms:
289 
290  d(f_a)/d(a) = 1/(a + b + c +...) - a/(a + b + c ...)^2
291 
292  off-diagonal terms:
293 
294  d(f_a)/d(b) = -a/(a + b + c ...)^2
295  */
296 
297  double integ = _myList->integral();
298  double integ2 = integ*integ;
299  for(unsigned int i=0; i < _myList->size(); i++){
300  double num = _myList->at(i).integral();
301  for(unsigned int j=0; j < _myList->size(); j++){
302  _dFraction_by_dN(i, j) = -num/integ2;
303  }
304  _dFraction_by_dN(i, i) += 1.0/integ;
305  }
306  return true;
307 }
double integral() const
Definition: FitAmpPair.cpp:476
const FitAmpPairList * _myList
T & at(unsigned int i)
virtual double integral() const
TMatrixT< float > _dFraction_by_dN
unsigned int size() const

◆ make_dFractionSum_by_dFraction()

bool FitAmpPairCovariance::make_dFractionSum_by_dFraction ( )
private

Definition at line 326 of file FitAmpPairCovariance.cpp.

326  {
327  bool dbThis=false;
328  if(dbThis) cout << "FitAmpPairCovariance::make_dFractionSum_by_dFraction()"
329  << " called" << endl;
330  /*
331  We are calculating trafo matrix for the trafo to the sum
332  of all terms entering the fraction calculation, this
333  excludes the terms for interference effect.
334 
335  It's just ones (those included) and zeros (for those not included)
336  */
337 
338  for(unsigned int i=0; i < _myList->size(); i++){
339  if(_myList->at(i).isSingleAmp()){
340  _dFractionSum_by_dFraction(0, i) = 1.0;
341  }else{
342  _dFractionSum_by_dFraction(0, i) = 0.0;
343  }
344  }
345  return true;
346 }
const FitAmpPairList * _myList
TMatrixT< float > _dFractionSum_by_dFraction
T & at(unsigned int i)
unsigned int size() const
bool isSingleAmp() const
Definition: FitAmpPair.cpp:590

◆ make_dIntegral_by_dN()

bool FitAmpPairCovariance::make_dIntegral_by_dN ( )
private

Definition at line 309 of file FitAmpPairCovariance.cpp.

309  {
310  bool dbThis=false;
311  if(dbThis) cout << "FitAmpPairCovariance::make_dIntegral_by_dN() called"
312  << endl;
313  /*
314  We are calculating trafo matrix for the following trafo:
315 
316  sum = a + b + c...
317 
318  */
319 
320  for(unsigned int i=0; i < _myList->size(); i++){
321  _dIntegral_by_dN(0, i) = 1;
322  }
323  return true;
324 }
const FitAmpPairList * _myList
unsigned int size() const
TMatrixT< float > _dIntegral_by_dN

◆ make_dN_by_d2N()

bool FitAmpPairCovariance::make_dN_by_d2N ( )
private

Definition at line 251 of file FitAmpPairCovariance.cpp.

251  {
252  bool dbThis=false;
253  if(dbThis) cout << "FitAmpPairCovariance::make_dN_by_d2N() called" << endl;
254 
255  /*
256  each FitAmpPair is evaluated as the real part of
257  the product of two complex numbers.
258  The product of fit parameters: oneOrTwo * (x_1 + iy_1)*(x_2 - iy_2)
259  The integral: a + ib
260  So we want to transfrom from (a, b) to c = xa - yb.
261 
262  Here we do the covariance due to the statistical uncertainty
263  in the MC integration, not the uncertainy in the fit parameters x,y.
264 
265  So we calculate d(c) by d(a,b) = (x, -y)
266  */
267  for(unsigned int i=0; i < _myList->size(); i++){
268  complex<double> fpv =
269  _myList->at(i).fitParValue()
270  * (double)(_myList->at(i).oneOrTwo());
271 
272  _dN_by_d2N(i, indexReal(i)) = fpv.real();
273  _dN_by_d2N(i, indexImag(i)) = - fpv.imag();
274  }
275  return true;
276 }
int indexImag(int listPosition) const
std::complex< double > fitParValue() const
Definition: FitAmpPair.h:58
int indexReal(int listPosition) const
int oneOrTwo() const
Definition: FitAmpPair.h:65
const FitAmpPairList * _myList
T & at(unsigned int i)
unsigned int size() const
TMatrixT< float > _dN_by_d2N

◆ makeDirectory()

bool FitAmpPairCovariance::makeDirectory ( const std::string &  asSubdirOf = ".") const
private

Definition at line 590 of file FitAmpPairCovariance.cpp.

590  {
591  /*
592  A mode is created from or'd permission bit masks defined
593  in <sys/stat.h>:
594  #define S_IRWXU 0000700 RWX mask for owner
595  #define S_IRUSR 0000400 R for owner
596  #define S_IWUSR 0000200 W for owner
597  #define S_IXUSR 0000100 X for owner
598 
599  #define S_IRWXG 0000070 RWX mask for group
600  #define S_IRGRP 0000040 R for group
601  #define S_IWGRP 0000020 W for group
602  #define S_IXGRP 0000010 X for group
603 
604  #define S_IRWXO 0000007 RWX mask for other
605  #define S_IROTH 0000004 R for other
606  #define S_IWOTH 0000002 W for other
607  #define S_IXOTH 0000001 X for other
608 
609  #define S_ISUID 0004000 set user id on execution
610  #define S_ISGID 0002000 set group id on execution
611  #define S_ISVTX 0001000 save swapped text even after use
612  */
613 
614  mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO
615  | S_ISUID | S_ISGID;
616  // see above for meaning. I want everybody to be allowed to read/write/exec.
617  // Not sure about the last two bits.
618 
619  int zeroForSuccess = 0;
620  zeroForSuccess |= mkdir( (asSubdirOf ).c_str(), mode );
621  zeroForSuccess |= mkdir( (dirName(asSubdirOf) ).c_str(), mode );
622  return (0 == zeroForSuccess);
623 }
std::string dirName(const std::string &asSubdirOf=".") const

◆ makeFractionCovariance()

bool FitAmpPairCovariance::makeFractionCovariance ( )
private

Definition at line 441 of file FitAmpPairCovariance.cpp.

441  {
442  bool dbThis=false;
443 
444  TMatrixT<float> dFraction_by_dN_Transpose(size(), size());
445  dFraction_by_dN_Transpose.Transpose(_dFraction_by_dN);
446 
448  dFraction_by_dN_Transpose);
449 
450  if(dbThis){
451  cout << "Correlation Matrix Fractions" << endl;
452  _fractionCov.Print();
453  }
454 
455  return true;
456 }
TMatrixTSym< float > _fractionCov
TMatrixTSym< T > makeTMatrixTSym(const TMatrixT< T > &m)
Definition: Utils.h:45
unsigned int size() const
TMatrixT< float > _dFraction_by_dN
TMatrixTSym< float > _cov

◆ makeFractionSumCovariance()

bool FitAmpPairCovariance::makeFractionSumCovariance ( )
private

Definition at line 457 of file FitAmpPairCovariance.cpp.

457  {
458  bool dbThis=false;
459 
460  TMatrixT<float> dFractionSum_by_dFraction_Transpose(size(), 1);
461  dFractionSum_by_dFraction_Transpose.Transpose(_dFractionSum_by_dFraction);
462 
464  _fractionCov *
465  dFractionSum_by_dFraction_Transpose);
466 
467  if(dbThis){
468  cout << "After " << _Nevents << "events" << endl;
469  cout << "Covariance Matrix for FractionSum" << endl;
470  _fractionSumCov.Print();
471  }
472 
473  return true;
474 }
TMatrixTSym< float > _fractionCov
TMatrixTSym< T > makeTMatrixTSym(const TMatrixT< T > &m)
Definition: Utils.h:45
TMatrixTSym< float > _fractionSumCov
TMatrixT< float > _dFractionSum_by_dFraction
unsigned int size() const

◆ makeIntegralCovariance()

bool FitAmpPairCovariance::makeIntegralCovariance ( )
private

Definition at line 476 of file FitAmpPairCovariance.cpp.

476  {
477  bool dbThis=false;
478 
479  TMatrixT<float> dIntegral_by_dN_Transpose(size(), 1);
480  dIntegral_by_dN_Transpose.Transpose(_dIntegral_by_dN);
481 
483  _cov
484  * dIntegral_by_dN_Transpose);
485 
486  if(dbThis){
487  cout << "Correlation Matrix Integral" << endl;
488  _fractionCov.Print();
489  }
490 
491  return true;
492 }
TMatrixTSym< float > _fractionCov
TMatrixTSym< T > makeTMatrixTSym(const TMatrixT< T > &m)
Definition: Utils.h:45
unsigned int size() const
TMatrixTSym< float > _integralCov
TMatrixT< float > _dIntegral_by_dN
TMatrixTSym< float > _cov

◆ makeNCovariance()

bool FitAmpPairCovariance::makeNCovariance ( )
private

Definition at line 401 of file FitAmpPairCovariance.cpp.

401  {
402  bool dbThis=false;
403 
404  bool success = true;
405  // success &= make2NCovariance();
406  // success &= make_dN_by_d2N();
407 
408  TMatrixT<float> dN_by_d2N_Transpose(2*size(), size());
409  dN_by_d2N_Transpose.Transpose(_dN_by_d2N);
410  if(dbThis){
411  cout << "FitAmpPairCovariance::makeNCovariance()"
412  << " _dN_by_d2N(): "
413  << endl;
414  _dN_by_d2N.Print();
415  cout << "and its transpose:" << endl;
416  dN_by_d2N_Transpose.Print();
417  }
418 
419  _cov = makeTMatrixTSym(_dN_by_d2N * _cov2N * dN_by_d2N_Transpose);
420 
421  for(unsigned int i=0; i < _myList->size(); i++){
422  if(_cov(i, i) <= 0) continue;
423  for(unsigned int j=0; j < _myList->size(); j++){
424  double den = _cov(i,i)*_cov(j,j);
425  if(den > 0){
426  _corr(i,j) = _cov(i,j)/sqrt(den);
427  }
428  }
429  }
430 
431  if(dbThis){
432  cout << "After " << _Nevents << "events" << endl;
433  cout << "Covariance Matrix N" << endl;
434  _cov.Print();
435  cout << "Correlation Matrix N" << endl;
436  _corr.Print();
437  }
438  return success;
439 }
TMatrixTSym< float > _cov2N
TMatrixTSym< T > makeTMatrixTSym(const TMatrixT< T > &m)
Definition: Utils.h:45
const FitAmpPairList * _myList
unsigned int size() const
unsigned int size() const
TMatrixT< float > _dN_by_d2N
TMatrixTSym< float > _cov
TMatrixTSym< float > _corr

◆ matrix_x_fname()

std::string FitAmpPairCovariance::matrix_x_fname ( const std::string &  asSubdirOf = ".") const
private

Definition at line 628 of file FitAmpPairCovariance.cpp.

628  {
629  return dirName(asSubdirOf) + "/" + "matrix_x.txt";
630 }
std::string dirName(const std::string &asSubdirOf=".") const

◆ matrix_xy_fname()

std::string FitAmpPairCovariance::matrix_xy_fname ( const std::string &  asSubdirOf = ".") const
private

Definition at line 631 of file FitAmpPairCovariance.cpp.

631  {
632  return dirName(asSubdirOf) + "/" + "matrix_xy.txt";
633 }
std::string dirName(const std::string &asSubdirOf=".") const

◆ maxSize()

unsigned int FitAmpPairCovariance::maxSize ( ) const
inlineprivate

Definition at line 45 of file FitAmpPairCovariance.h.

45 {return _maxSize;}
static unsigned int _maxSize

◆ Nevents()

int FitAmpPairCovariance::Nevents ( ) const
inline

Definition at line 94 of file FitAmpPairCovariance.h.

94 {return _Nevents;}

◆ operator+()

FitAmpPairCovariance FitAmpPairCovariance::operator+ ( const FitAmpPairCovariance other) const

Definition at line 814 of file FitAmpPairCovariance.cpp.

814  {
815  FitAmpPairCovariance returnVal(*this);
816  return (returnVal += other);
817 }

◆ operator+=()

FitAmpPairCovariance & FitAmpPairCovariance::operator+= ( const FitAmpPairCovariance other)

Definition at line 810 of file FitAmpPairCovariance.cpp.

810  {
811  this->add(other);
812  return *this;
813 }
bool add(const FitAmpPairCovariance &other)

◆ realName()

std::string FitAmpPairCovariance::realName ( int  listPosition) const
private

Definition at line 170 of file FitAmpPairCovariance.cpp.

170  {
171  return _myList->at(listPosition).name() + "_real";
172 }
const FitAmpPairList * _myList
T & at(unsigned int i)
const std::string & name() const
Definition: FitAmpPair.cpp:605

◆ reset()

bool FitAmpPairCovariance::reset ( )

Definition at line 583 of file FitAmpPairCovariance.cpp.

583  {
584  clearAll();
585  resize();
586  return true;
587 }

◆ resize()

bool FitAmpPairCovariance::resize ( )
private

Definition at line 124 of file FitAmpPairCovariance.cpp.

124  {
125  bool dbThis=false;
126  if(dbThis){
127  cout << "FitAmpPairCovariance::resize()"
128  << " resizing from " << size()
129  << " to " << _myList->size()
130  << " with maxSize() = " << maxSize()
131  << endl;
132  }
133 
134  _needToRecalculate=true;
135 
136  _size = _myList->size();
137 
138  if(size() > maxSize()){
139  cout << "FitAmpPairCovariance::resize size() = " << size()
140  << " that's too big! won't do it!" << endl;
141  return false;
142  }
143 
144  _sum_x. ResizeTo(size()*2, 1);
145  _sum_xy.ResizeTo(size()*2, size()*2);
146  _cov2N. ResizeTo(size()*2, size()*2);
147  _corr2N.ResizeTo(size()*2, size()*2);
148 
149  _cov. ResizeTo(size(), size());
150  _corr. ResizeTo(size(), size());
151 
152  _fractionCov. ResizeTo(size(), size());
153  _fractionSumCov. ResizeTo(1,1);
154  _integralCov. ResizeTo(1,1);
155 
156  _dN_by_d2N. ResizeTo(size(), size()*2);
157  _dFraction_by_dN. ResizeTo(size(), size());
158 
159  _dFractionSum_by_dFraction.ResizeTo(1, size());
160 
161  _dIntegral_by_dN. ResizeTo(1, size());
162 
163  if(dbThis){
164  cout << "FitAmpPairCovariance::resize() to "
165  << size() << " done." << endl;
166  }
167  return true;
168 }
TMatrixT< float > _sum_x
TMatrixTSym< float > _fractionCov
TMatrixTSym< float > _cov2N
const FitAmpPairList * _myList
TMatrixTSym< float > _fractionSumCov
TMatrixT< float > _dFractionSum_by_dFraction
unsigned int maxSize() const
TMatrixTSym< float > _sum_xy
unsigned int size() const
TMatrixT< float > _dFraction_by_dN
unsigned int size() const
TMatrixTSym< float > _corr2N
TMatrixT< float > _dN_by_d2N
TMatrixTSym< float > _integralCov
TMatrixT< float > _dIntegral_by_dN
TMatrixTSym< float > _cov
TMatrixTSym< float > _corr

◆ retrieve()

bool FitAmpPairCovariance::retrieve ( const std::string &  fromDirectory = ".")

Definition at line 711 of file FitAmpPairCovariance.cpp.

711  {
712  if(! resize()) return false;
713  if(! retrieve_sum_x(inDirectory)) return false;
714  if(! retrieve_sum_xy(inDirectory)) return false;
715  _needToRecalculate=true;
716  return true;
717 }
bool retrieve_sum_xy(const std::string &inDirectory)
bool retrieve_sum_x(const std::string &inDirectory)

◆ retrieve_sum_x()

bool FitAmpPairCovariance::retrieve_sum_x ( const std::string &  inDirectory)
private

Definition at line 719 of file FitAmpPairCovariance.cpp.

719  {
720  bool dbThis=false;
721  if(size() > maxSize()) return false;
722  ifstream is(matrix_x_fname(inDirectory).c_str());
723  if(is.bad()) return false;
724 
725  if(dbThis) cout << "opened file: "
726  << "\n" << matrix_x_fname(inDirectory)
727  << endl;
728  std::string st1;
729  double val;
730  std::map<string, double> map_x;
731 
732  int counter=0;
733  while(is){
734  if(dbThis) cout << "reading " << counter << ". line" << endl;
735  if(0 == counter){
736  is >> st1 >> _Nevents;
737  if(dbThis){
738  cout << "just read " << st1 << " " << _Nevents << endl;
739  }
740  }else{
741  is >> st1 >> val;
742  map_x[st1] = val;
743  if(dbThis){
744  cout << "just read " << st1 << " " << val << endl;
745  }
746  }
747  counter++;
748  }
749  is.close();
750  if(dbThis)cout << "retrieve_sum_x, filling _sum_x for size "
751  << size() << endl;
752  for(unsigned int i=0; i < size(); i++){
753  _sum_x(indexReal(i), 0) = map_x[realName(i)];
754  _sum_x(indexImag(i), 0) = map_x[imagName(i)];
755  if(dbThis){
756  cout << "Tried to retrieve from map entry for " << realName(i)
757  << " \n got: " << map_x[realName(i)] << endl;
758  }
759 
760  }
761  if(dbThis){
762  cout << " did so, look at what I got for sum_x" << endl;
763  _sum_x.Print();
764  }
765  _needToRecalculate=true;
766  return true;
767 }
int indexImag(int listPosition) const
std::string realName(int listPosition) const
TMatrixT< float > _sum_x
std::string imagName(int listPosition) const
int indexReal(int listPosition) const
unsigned int maxSize() const
unsigned int size() const
std::string matrix_x_fname(const std::string &asSubdirOf=".") const

◆ retrieve_sum_xy()

bool FitAmpPairCovariance::retrieve_sum_xy ( const std::string &  inDirectory)
private

Definition at line 768 of file FitAmpPairCovariance.cpp.

768  {
769  bool dbThis=false;
770  if(size() > maxSize()) return false;
771  ifstream is(matrix_xy_fname(inDirectory).c_str());
772  if(is.bad()) return false;
773  if(dbThis) cout << "opened file: "
774  << "\n" << matrix_xy_fname(inDirectory)
775  << endl;
776  std::string st1, st2;
777  double val;
778  map< string, map<string, double> > map_xy;
779 
780  int counter=0;
781  while(is){
782  if(0 == counter){
783  is >> st1 >> _Nevents;
784  }else{
785  is >> st1 >> st2 >> val;
786  map_xy[st1][st2] = val;
787  if(dbThis) cout << "just read " << counter << ". line: "
788  << st1 << " " << st2 << " " << val << endl;
789  }
790  counter++;
791  }
792 
793  is.close();
794  for(unsigned int i=0; i < size(); i++){
795  for(unsigned int j=0; j < size(); j++){
796  _sum_xy(indexReal(i), indexReal(j)) = map_xy[realName(i)][realName(j)];
797  _sum_xy(indexReal(i), indexImag(j)) = map_xy[realName(i)][imagName(j)];
798  _sum_xy(indexImag(i), indexReal(j)) = map_xy[imagName(i)][realName(j)];
799  _sum_xy(indexImag(i), indexImag(j)) = map_xy[imagName(i)][imagName(j)];
800  }
801  }
802  if(dbThis){
803  cout << "got _sum_xy: " << endl;
804  _sum_xy.Print();
805  }
806  _needToRecalculate=true;
807  return true;
808 }
int indexImag(int listPosition) const
std::string realName(int listPosition) const
std::string imagName(int listPosition) const
int indexReal(int listPosition) const
unsigned int maxSize() const
TMatrixTSym< float > _sum_xy
unsigned int size() const
std::string matrix_xy_fname(const std::string &asSubdirOf=".") const

◆ save()

bool FitAmpPairCovariance::save ( const std::string &  asSubdirOf = ".") const

Definition at line 635 of file FitAmpPairCovariance.cpp.

635  {
636  bool dbThis=false;
637  if(! isValid()){
638  cout << "WARNING FitAmpPairCovariance::save(" << inDirectory <<")"
639  << " I'm not valid, I won't save anything." << endl;
640  return false;
641  }
642  if(dbThis){
643  cout << "saving FitAmpPairCovariance in " << inDirectory << "." << endl;
644  }
645  makeDirectory(inDirectory);
646  bool sc=true;
647  sc &= save_sum_x(inDirectory);
648  sc &= save_sum_xy(inDirectory);
649 
650  return true;
651 }
bool makeDirectory(const std::string &asSubdirOf=".") const
bool save_sum_xy(const std::string &inDirectory) const
bool save_sum_x(const std::string &inDirectory) const

◆ save_sum_x()

bool FitAmpPairCovariance::save_sum_x ( const std::string &  inDirectory) const
private

Definition at line 653 of file FitAmpPairCovariance.cpp.

653  {
654  bool dbThis=false;
655  if(! isValid()){
656  cout << "WARNING FitAmpPairCovariance::save_sum_x(" << inDirectory <<")"
657  << " I'm not valid, I won't save anything." << endl;
658  return false;
659  }
660  ofstream os(matrix_x_fname(inDirectory).c_str());
661  os << "N " << _Nevents << endl;
662  if(dbThis){
663  cout << "about to save: ";
664  _sum_x.Print();
665  }
666  for(unsigned int i=0; i < _myList->size(); i++){
667 
668  os << setprecision(20) << realName(i) << " "
669  << _sum_x(indexReal(i), 0) << endl;
670 
671  os << setprecision(20) << imagName(i) << " "
672  << _sum_x(indexImag(i), 0) << endl;
673  }
674  os.close();
675  return true;
676 }
int indexImag(int listPosition) const
std::string realName(int listPosition) const
TMatrixT< float > _sum_x
std::string imagName(int listPosition) const
int indexReal(int listPosition) const
const FitAmpPairList * _myList
unsigned int size() const
std::string matrix_x_fname(const std::string &asSubdirOf=".") const

◆ save_sum_xy()

bool FitAmpPairCovariance::save_sum_xy ( const std::string &  inDirectory) const
private

Definition at line 678 of file FitAmpPairCovariance.cpp.

678  {
679  bool dbThis=false;
680  if(! isValid()){
681  cout << "WARNING FitAmpPairCovariance::save_sum_xy(" << inDirectory <<")"
682  << " I'm not valid, I won't save anything." << endl;
683  return false;
684  }
685  ofstream os(matrix_xy_fname(inDirectory).c_str());
686  os << "N " << _Nevents << endl;
687  if(dbThis){
688  cout << "about to save: ";
689  _sum_xy.Print();
690  }
691  for(unsigned int i=0; i < _myList->size(); i++){
692  for(unsigned int j=0; j < _myList->size(); j++){
693 
694  os << setprecision(20)<< realName(i) << " " << realName(j) << " "
695  << _sum_xy(indexReal(i), indexReal(j)) << endl;
696 
697  os << setprecision(20)<< realName(i) << " " << imagName(j) << " "
698  << _sum_xy(indexReal(i), indexImag(j)) << endl;
699 
700  os << setprecision(20)<< imagName(i) << " " << realName(j) << " "
701  << _sum_xy(indexImag(i), indexReal(j)) << endl;
702 
703  os << setprecision(20)<< imagName(i) << " " << imagName(j) << " "
704  << _sum_xy(indexImag(i), indexImag(j)) << endl;
705  }
706  }
707  os.close();
708  return true;
709 }
int indexImag(int listPosition) const
std::string realName(int listPosition) const
std::string imagName(int listPosition) const
int indexReal(int listPosition) const
const FitAmpPairList * _myList
TMatrixTSym< float > _sum_xy
unsigned int size() const
std::string matrix_xy_fname(const std::string &asSubdirOf=".") const

◆ size()

unsigned int FitAmpPairCovariance::size ( ) const

Definition at line 121 of file FitAmpPairCovariance.cpp.

121  {
122  return _size;
123 }

Member Data Documentation

◆ _corr

TMatrixTSym<float> FitAmpPairCovariance::_corr
private

Definition at line 22 of file FitAmpPairCovariance.h.

◆ _corr2N

TMatrixTSym<float> FitAmpPairCovariance::_corr2N
private

Definition at line 22 of file FitAmpPairCovariance.h.

◆ _cov

TMatrixTSym<float> FitAmpPairCovariance::_cov
private

Definition at line 22 of file FitAmpPairCovariance.h.

◆ _cov2N

TMatrixTSym<float> FitAmpPairCovariance::_cov2N
private

Definition at line 22 of file FitAmpPairCovariance.h.

◆ _dFraction_by_dN

TMatrixT<float> FitAmpPairCovariance::_dFraction_by_dN
private

Definition at line 28 of file FitAmpPairCovariance.h.

◆ _dFractionSum_by_dFraction

TMatrixT<float> FitAmpPairCovariance::_dFractionSum_by_dFraction
private

Definition at line 29 of file FitAmpPairCovariance.h.

◆ _dIntegral_by_dN

TMatrixT<float> FitAmpPairCovariance::_dIntegral_by_dN
private

Definition at line 30 of file FitAmpPairCovariance.h.

◆ _dN_by_d2N

TMatrixT<float> FitAmpPairCovariance::_dN_by_d2N
private

Definition at line 27 of file FitAmpPairCovariance.h.

◆ _fractionCov

TMatrixTSym<float> FitAmpPairCovariance::_fractionCov
private

Definition at line 23 of file FitAmpPairCovariance.h.

◆ _fractionSumCov

TMatrixTSym<float> FitAmpPairCovariance::_fractionSumCov
private

Definition at line 24 of file FitAmpPairCovariance.h.

◆ _integralCov

TMatrixTSym<float> FitAmpPairCovariance::_integralCov
private

Definition at line 25 of file FitAmpPairCovariance.h.

◆ _maxSize

unsigned int FitAmpPairCovariance::_maxSize = 1500
staticprivate

Definition at line 12 of file FitAmpPairCovariance.h.

◆ _myList

const FitAmpPairList* FitAmpPairCovariance::_myList
private

Definition at line 14 of file FitAmpPairCovariance.h.

◆ _needToRecalculate

bool FitAmpPairCovariance::_needToRecalculate
private

Definition at line 17 of file FitAmpPairCovariance.h.

◆ _Nevents

unsigned int FitAmpPairCovariance::_Nevents
private

Definition at line 15 of file FitAmpPairCovariance.h.

◆ _size

unsigned int FitAmpPairCovariance::_size
private

Definition at line 16 of file FitAmpPairCovariance.h.

◆ _sum_x

TMatrixT<float> FitAmpPairCovariance::_sum_x
private

Definition at line 19 of file FitAmpPairCovariance.h.

◆ _sum_xy

TMatrixTSym<float> FitAmpPairCovariance::_sum_xy
private

Definition at line 20 of file FitAmpPairCovariance.h.


The documentation for this class was generated from the following files: