CMS 3D CMS Logo

TFitParticleCart.cc
Go to the documentation of this file.
1 // Classname: TFitParticleCart
2 // Author: Jan E. Sundermann, Verena Klose (TU Dresden)
3 
4 
5 //________________________________________________________________
6 //
7 // TFitParticleCart::
8 // --------------------
9 //
10 // Particle with cartesian 4vector parametrization and free mass
11 // [four free parameters (px, py, pz, d) with initial values
12 // (px, py, pz, 1)]
13 //
14 // p = px*u1 + py*u2 + pz*u3
15 // E = Sqrt( |p|^2 + d^2*m^2 )
16 //
17 
18 #include <iostream>
21 #include "TMath.h"
22 
23 
24 //----------------
25 // Constructor --
26 //----------------
28  :TAbsFitParticle()
29 {
30  init(0, 0);
31 }
32 
34  :TAbsFitParticle( fitParticle.GetName(), fitParticle.GetTitle() )
35 {
36 
37  _nPar = fitParticle._nPar;
38  _u1 = fitParticle._u1;
39  _u2 = fitParticle._u2;
40  _u3 = fitParticle._u3;
41  _covMatrix.ResizeTo( fitParticle._covMatrix );
42  _covMatrix = fitParticle._covMatrix;
43  _iniparameters.ResizeTo( fitParticle._iniparameters );
44  _iniparameters = fitParticle._iniparameters;
45  _parameters.ResizeTo( fitParticle._parameters );
46  _parameters = fitParticle._parameters;
47  _pini = fitParticle._pini;
48  _pcurr = fitParticle._pcurr;
49 
50 }
51 
52 TFitParticleCart::TFitParticleCart(TLorentzVector* pini, const TMatrixD* theCovMatrix)
53  :TAbsFitParticle()
54 {
55  init(pini, theCovMatrix);
56 }
57 
58 TFitParticleCart::TFitParticleCart(const TString &name, const TString &title,
59  TLorentzVector* pini, const TMatrixD* theCovMatrix)
60  :TAbsFitParticle(name, title)
61 {
62  init(pini, theCovMatrix);
63 }
64 
65 TAbsFitParticle* TFitParticleCart::clone( const TString& newname ) const {
66  // Returns a copy of itself
67 
68  TAbsFitParticle* myclone = new TFitParticleCart( *this );
69  if ( newname.Length() > 0 ) myclone->SetName(newname);
70  return myclone;
71 
72 }
73 
74 //--------------
75 // Destructor --
76 //--------------
78 
79 }
80 
81 //--------------
82 // Operations --
83 //--------------
84 void TFitParticleCart::init(TLorentzVector* pini, const TMatrixD* theCovMatrix ) {
85 
86  _nPar = 4;
87  setIni4Vec(pini);
88  setCovMatrix(theCovMatrix);
89 
90 }
91 
92 TLorentzVector* TFitParticleCart::calc4Vec( const TMatrixD* params ) {
93  // Calculates a 4vector corresponding to the given
94  // parameter values
95 
96  if (params == 0) {
97  return 0;
98  }
99 
100  if ( params->GetNcols() != 1 || params->GetNrows() !=_nPar ) {
101  edm::LogError ("WrongMatrixSize")
102  << GetName() << "::calc4Vec - Parameter matrix has wrong size.";
103  return 0;
104  }
105 
106  Double_t X = (*params)(0,0);
107  Double_t Y = (*params)(1,0);
108  Double_t Z = (*params)(2,0);
109  Double_t E = TMath::Sqrt( X*X + Y*Y + Z*Z + (*params)(3,0)*(*params)(3,0)*_pini.M2() );
110 
111  TLorentzVector* vec = new TLorentzVector( X, Y, Z, E );
112  return vec;
113 
114 }
115 
116 void TFitParticleCart::setIni4Vec(const TLorentzVector* pini) {
117  // Set the initial 4vector. Will also set the
118  // inital parameter values
119 
120  if (pini == 0) {
121 
122  _u1.SetXYZ(0., 0., 0.);
123  _u3.SetXYZ(0., 0., 0.);
124  _u2.SetXYZ(0., 0., 0.);
125  _pini.SetXYZT(0., 0., 0., 0.);
126  _pcurr = _pini;
127 
128  _iniparameters.ResizeTo(_nPar,1);
129  _iniparameters(0,0)=0;
130  _iniparameters(1,0)=0;
131  _iniparameters(2,0)=0;
132  _iniparameters(3,0)=0.;
133 
134  _parameters.ResizeTo(_nPar,1);
135  _parameters(0,0)=0.;
136  _parameters(1,0)=0.;
137  _parameters(2,0)=0.;
138  _parameters(3,0)=0.;
139 
140  } else {
141 
142  _pini = (*pini);
143  _pcurr = _pini;
144 
145  _u1.SetXYZ( 1., 0., 0. );
146  _u2.SetXYZ( 0., 1., 0. );
147  _u3.SetXYZ( 0., 0., 1. );
148 
149  _iniparameters.ResizeTo(_nPar,1);
150  _iniparameters(0,0)=_pini.X();
151  _iniparameters(1,0)=_pini.Y();
152  _iniparameters(2,0)=_pini.Z();
153  _iniparameters(3,0)=1.;
154  _parameters.ResizeTo(_nPar,1);
156 
157  }
158 
159 }
160 
162  // returns derivative dP/dy with P=(p,E) and y=(px, py, pz, d)
163  // the free parameters of the fit. The columns of the matrix contain
164  // (dP/dpx, dP/dpy, ...).
165 
166  TMatrixD* DerivativeMatrix = new TMatrixD(4,4);
167  (*DerivativeMatrix) *= 0.;
168 
169  //1st column: dP/dx
170  (*DerivativeMatrix)(0,0)=1.;
171  (*DerivativeMatrix)(1,0)=0.;
172  (*DerivativeMatrix)(2,0)=0.;
173  (*DerivativeMatrix)(3,0)=0.;
174 
175  //2nd column: dP/dy
176  (*DerivativeMatrix)(0,1)=0;
177  (*DerivativeMatrix)(1,1)=1;
178  (*DerivativeMatrix)(2,1)=0;
179  (*DerivativeMatrix)(3,1)=0.;
180 
181  //3rd column: dP/dz
182  (*DerivativeMatrix)(0,2)=0.;
183  (*DerivativeMatrix)(1,2)=0.;
184  (*DerivativeMatrix)(2,2)=1.;
185  (*DerivativeMatrix)(3,2)=0.;
186 
187  //4th column: dP/dm
188  (*DerivativeMatrix)(0,3)=0.;
189  (*DerivativeMatrix)(1,3)=0.;
190  (*DerivativeMatrix)(2,3)=0.;
191  (*DerivativeMatrix)(3,3)=_pini.M()*_pini.M()*_parameters(3,0)/_pcurr.E();
192 
193  return DerivativeMatrix;
194 }
195 
196 TMatrixD* TFitParticleCart::transform(const TLorentzVector& vec) {
197  // Returns the parameters corresponding to the given
198  // 4vector
199 
200  TMatrixD* tparams = new TMatrixD( _nPar, 1 );
201  (*tparams)(0,0) = vec.X();
202  (*tparams)(1,0) = vec.Y();
203  (*tparams)(2,0) = vec.Z();
204  (*tparams)(3,0) = vec.M()/_pini.M();
205 
206  return tparams;
207 
208 }
virtual ~TFitParticleCart()
#define X(str)
Definition: MuonsGrabber.cc:48
TLorentzVector _pini
virtual TAbsFitParticle * clone(const TString &newname=TString("")) const
TMatrixD _parameters
TLorentzVector _pcurr
virtual void setCovMatrix(const TMatrixD *theCovMatrix)
virtual void setIni4Vec(const TLorentzVector *pini)
virtual TLorentzVector * calc4Vec(const TMatrixD *params)
virtual TMatrixD * transform(const TLorentzVector &vec)
virtual TMatrixD * getDerivative()
void init(TLorentzVector *pini, const TMatrixD *theCovMatrix)
TMatrixD _iniparameters