CMS 3D CMS Logo

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