CMS 3D CMS Logo

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