CMS 3D CMS Logo

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