ROOTPWA
TCovEllipse.cc
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 // Implementation of class TCovEllipse
27 // see TCovEllipse.hh for details
28 //
29 // Environment:
30 // Software developed for the PANDA Detector at FAIR.
31 //
32 // Author List:
33 // Sebastian Neubert TUM (original author)
34 //
35 //
36 //-----------------------------------------------------------
37 
38 // Panda Headers ----------------------
39 
40 // This Class' Header ------------------
41 #include "TCovEllipse.h"
42 
43 // C/C++ Headers ----------------------
44 #include <iostream>
45 
46 // Collaborating Class Headers --------
47 #include "TMath.h"
48 
49 // Class Member definitions -----------
51 
53  : TEllipse(), _sig(1)
54 {
55  SetFillStyle(0);
56 }
57 
58 TCovEllipse::TCovEllipse(const TMatrixT<double>& cov,
59  double x0, double y0,
60  int i, int j)
61  : TEllipse(),_cov(cov), _x0(x0), _y0(y0), _i(i), _j(j)
62 {
63  recalc();
64  SetFillStyle(0);
65 }
66 
67 void
68 TCovEllipse::setCov(const TMatrixT<double>& cov)
69 {
70  _cov=cov;
71  recalc();
72 }
73 
74 void
75 TCovEllipse::setMean(double x, double y)
76 {
77  SetX1(x);
78  SetY1(y);
79 }
80 
81 void
83 {
84  double sig1=sqrt(_cov[_i][_i]);
85  double sig2=sqrt(_cov[_j][_j]);
86  double rho=_cov[_i][_j]/(sig1*sig2);
87  double theta=0;
88  if(_cov[_i][_i]!=_cov[_j][_j]){
89  double term=2.*rho*sig1*sig2/(_cov[_i][_i]-_cov[_j][_j]);
90  theta=TMath::ATan(term)*0.5;
91  }
92  //std::cout<<theta<<std::endl;
93  double num=_cov[_i][_i]*_cov[_j][_j]*(1-rho*rho);
94  double mixed=2*rho*sig1*sig2*sin(theta)*cos(theta);
95  double sin2=sin(theta)*sin(theta);
96  double cos2=cos(theta)*cos(theta);
97  double p12_=_cov[_j][_j]*cos2-mixed+_cov[_i][_i]*sin2;
98  double p22_=_cov[_j][_j]*sin2+mixed+_cov[_i][_i]*cos2;
99  double p1=sqrt(num/p12_);
100  double p2=sqrt(num/p22_);
101  SetTheta(theta*57.2958);
102  SetR1(p1);
103  SetR2(p2);
104  SetX1(_x0);
105  SetY1(_y0);
106 }