CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TrackHelixVertexFitter.cc
Go to the documentation of this file.
1 /* From SimpleFits Package
2  * Designed an written by
3  * author: Ian M. Nugent
4  * Humboldt Foundations
5  */
8 #include "TDecompBK.h"
9 #include <iostream>
10 
11 using namespace tauImpactParameter;
12 
13 TrackHelixVertexFitter::TrackHelixVertexFitter(const std::vector<TrackParticle>& particles, const TVector3& vguess)
14  : isFit_(false),
15  isConfigured_(false),
16  nParticles_(particles.size()),
17  nPar_((NFreeTrackPar - NFreeVertexPar) * particles.size() + NFreeVertexPar),
18  nVal_(TrackParticle::NHelixPar * particles.size()) {
19  particles_ = particles;
20  par_.ResizeTo(nPar_);
21  parcov_.ResizeTo(nPar_, nPar_);
22  val_.ResizeTo(nVal_);
23  cov_.ResizeTo(nVal_, nVal_);
24  for (unsigned int p = 0; p < particles.size(); p++) {
25  for (unsigned int j = 0; j < TrackParticle::NHelixPar; j++) {
26  val_(measuredValueIndex(j, p)) = particles[p].parameter(j);
27  for (unsigned int k = 0; k < TrackParticle::NHelixPar; k++) {
28  cov_(measuredValueIndex(j, p), measuredValueIndex(k, p)) = particles[p].covariance(j, k);
29  }
30  }
31  }
32  TDecompBK Inverter(cov_);
33  double det = cov_.Determinant();
34  if (!Inverter.Decompose()) {
35  edm::LogWarning("TrackHelixVertexFitter::TrackHelixVertexFitter")
36  << "Fit failed: unable to invert SYM gain matrix " << det << " \n"
37  << std::endl;
38  return;
39  }
40 
41  cov_inv_.ResizeTo(nVal_, nVal_);
42  cov_inv_ = Inverter.Invert();
43  ndf_ = nVal_ - nPar_;
44  // Set Initial conditions within reason
45  par_(x0) = vguess.X();
46  parcov_(x0, x0) = 1.0;
47  par_(y0) = vguess.Y();
48  parcov_(y0, y0) = 1.0;
49  par_(z0) = vguess.Z();
50  parcov_(z0, z0) = 1.0;
51  for (unsigned int p = 0; p < particles_.size(); p++) {
55 
62  }
63  isConfigured_ = true;
64 }
65 
67 
68 double TrackHelixVertexFitter::updateChisquare(const TVectorT<double>& inpar) {
69  TVectorT<double> vprime = computePar(inpar);
70  TVectorT<double> dalpha = vprime - val_;
71  double c2 = dalpha * (cov_inv_ * dalpha);
72  return c2;
73 }
74 
75 std::vector<TrackParticle> TrackHelixVertexFitter::getRefitTracks() {
76  std::vector<TrackParticle> refitParticles;
77  for (unsigned int p = 0; p < particles_.size(); p++) {
78  TVectorT<double> FreePar(NFreeTrackPar);
79  TMatrixTSym<double> FreeParCov(NFreeTrackPar);
80  for (int i = 0; i < FreeParCov.GetNrows(); i++) {
81  FreePar(i) = par_(freeParIndex(i, p));
82  for (int j = 0; j < FreeParCov.GetNrows(); j++) {
83  FreeParCov(i, j) = parcov_(freeParIndex(i, p), freeParIndex(j, p));
84  }
85  }
86  TVectorT<double> TrackPar = computePar(FreePar);
87  TMatrixTSym<double> TrackCov =
89  refitParticles.push_back(TrackParticle(TrackPar,
90  TrackCov,
91  particles_[p].pdgId(),
92  particles_[p].mass(),
93  particles_[p].charge(),
94  particles_[p].bField()));
95  }
96  return refitParticles;
97 }
98 
99 std::vector<LorentzVectorParticle> TrackHelixVertexFitter::getRefitLorentzVectorParticles() {
100  std::vector<LorentzVectorParticle> refitParticles;
101  for (unsigned int p = 0; p < particles_.size(); p++) {
102  TVectorT<double> FreePar(NFreeTrackPar + NExtraPar + MassOffSet);
103  TMatrixTSym<double> FreeParCov(NFreeTrackPar + NExtraPar + MassOffSet);
104  for (int i = 0; i < NFreeTrackPar; i++) {
105  FreePar(i) = par_(freeParIndex(i, p));
106  for (int j = 0; j < NFreeTrackPar; j++) {
107  FreeParCov(i, j) = parcov_(freeParIndex(i, p), freeParIndex(j, p));
108  }
109  }
110  FreePar(NFreeTrackPar + MassOffSet) = particles_[p].mass();
111  FreePar(NFreeTrackPar + BField0) = particles_[p].bField();
112  TVectorT<double> LVPar = computeLorentzVectorPar(FreePar);
113  TMatrixTSym<double> LVCov =
115  refitParticles.push_back(
116  LorentzVectorParticle(LVPar, LVCov, particles_[p].pdgId(), particles_[p].charge(), particles_[p].bField()));
117  }
118  return refitParticles;
119 }
120 
122  double c(0), b(0);
123  TVectorT<double> FreePar(par_.GetNrows() + NExtraPar + particles_.size());
124  TMatrixTSym<double> FreeParCov(par_.GetNrows() + NExtraPar + particles_.size());
125  for (int i = 0; i < par_.GetNrows(); i++) {
126  FreePar(i) = par_(i);
127  for (int j = 0; j < par_.GetNrows(); j++) {
128  FreeParCov(i, j) = parcov_(i, j);
129  }
130  }
131  for (unsigned int p = 0; p < particles_.size(); p++) {
132  b = particles_[p].bField();
133  c += particles_[p].charge();
134  FreePar(par_.GetNrows() + MassOffSet + p) = particles_[p].mass();
135  }
136  FreePar(par_.GetNrows() + BField0) = b;
137  TVectorT<double> mpar = computeMotherLorentzVectorPar(FreePar);
138  TMatrixTSym<double> mcov = ErrorMatrixPropagator::propagateError(
140  return LorentzVectorParticle(mpar, mcov, pdgid, c, b);
141 }
142 
144  return TVector3(par_(freeParIndex(x0, 0)), par_(freeParIndex(y0, 0)), par_(freeParIndex(z0, 0)));
145 }
146 
148  TMatrixTSym<double> c(NFreeVertexPar);
149  for (unsigned int i = 0; i < NFreeVertexPar; i++) {
150  for (unsigned int j = 0; j < NFreeVertexPar; j++) {
152  }
153  }
154  return c;
155 }
156 
157 void TrackHelixVertexFitter::computedxydz(const TVectorT<double>& inpar,
158  int p,
159  double& kappa,
160  double& lam,
161  double& phi,
162  double& x,
163  double& y,
164  double& z,
165  double& s,
166  double& dxy,
167  double& dz) {
168  kappa = inpar(freeParIndex(kappa0, p));
169  lam = inpar(freeParIndex(lambda0, p));
170  phi = inpar(freeParIndex(phi0, p));
171  x = inpar(freeParIndex(x0, p));
172  y = inpar(freeParIndex(y0, p));
173  z = inpar(freeParIndex(z0, p));
174  double v = (2.0 * kappa * (x * cos(phi) + y * sin(phi)));
175  double arcsinv = 0;
176  if (v >= 1.0) {
177  arcsinv = TMath::Pi() / 2;
178  } else if (v <= -1.0) {
179  arcsinv = -TMath::Pi() / 2;
180  } else {
181  arcsinv = asin(v);
182  }
183  s = 1.0 / (2.0 * kappa) * arcsinv;
184  dxy = y * cos(phi) - x * sin(phi) - (1 / kappa) * sin(kappa * s) * sin(kappa * s);
185  dz = z - s * tan(lam);
186 }
187 
188 TVectorT<double> TrackHelixVertexFitter::computePar(const TVectorT<double>& inpar) {
189  int nparticles = (inpar.GetNrows() - NFreeVertexPar) / (NFreeTrackPar - NFreeVertexPar);
190  TVectorT<double> helices(nparticles * TrackParticle::NHelixPar);
191  for (int p = 0; p < nparticles; p++) {
192  TVectorT<double> TrackPar = computeTrackPar(inpar, p);
193  for (int i = 0; i < TrackParticle::NHelixPar; i++) {
194  helices(measuredValueIndex(i, p)) = TrackPar(i);
195  }
196  }
197  return helices;
198 }
199 
200 TVectorT<double> TrackHelixVertexFitter::computeTrackPar(const TVectorT<double>& inpar, int p) {
201  TVectorT<double> helix(TrackParticle::NHelixPar);
202  // copy parameters that are 1 to 1
203  double kappa, lam, phi, x, y, z, s, dxy, dz;
204  TrackHelixVertexFitter::computedxydz(inpar, p, kappa, lam, phi, x, y, z, s, dxy, dz);
205  helix(TrackParticle::kappa) = kappa;
206  helix(TrackParticle::lambda) = lam;
207  helix(TrackParticle::phi) = phi;
208  helix(TrackParticle::dxy) = dxy;
209  helix(TrackParticle::dz) = dz;
210  return helix;
211 }
212 
213 TVectorT<double> TrackHelixVertexFitter::computeLorentzVectorPar(const TVectorT<double>& inpar) {
214  int np(0), parsize(0);
215  parSizeInfo(inpar, np, parsize, true);
216  double B = inpar(parsize + BField0);
217  double massHypothesis = inpar(parsize + MassOffSet);
219  double kappa, lam, phi, x, y, z, s, dxy, dz;
220  int p = 0;
221  TrackHelixVertexFitter::computedxydz(inpar, p, kappa, lam, phi, x, y, z, s, dxy, dz);
222  double phi1 = 2 * s * kappa + phi;
223  double bOverK = B * (1.0 / fabs(kappa));
224  LV(LorentzVectorParticle::px) = bOverK * cos(phi1);
225  LV(LorentzVectorParticle::py) = bOverK * sin(phi1);
226  LV(LorentzVectorParticle::pz) = bOverK * tan(lam);
231  return LV;
232 }
233 
234 TVectorT<double> TrackHelixVertexFitter::computeMotherLorentzVectorPar(const TVectorT<double>& inpar) {
235  TVectorT<double> mother(LorentzVectorParticle::NLorentzandVertexPar);
236  double E(0);
237  int np(0), parsize(0);
238  parSizeInfo(inpar, np, parsize, true);
239  for (int p = 0; p < np; p++) {
240  TVectorT<double> particlepar(NFreeTrackPar + NExtraPar + MassOffSet);
241  for (int i = 0; i < NFreeTrackPar; i++) {
242  particlepar(i) = inpar(freeParIndex(i, p));
243  }
244  particlepar(NFreeTrackPar + BField0) = inpar(parsize + BField0);
245  particlepar(NFreeTrackPar + MassOffSet) = inpar(parsize + MassOffSet + p);
246  TVectorT<double> daughter = TrackHelixVertexFitter::computeLorentzVectorPar(particlepar);
253  E += sqrt((daughter(LorentzVectorParticle::px) * daughter(LorentzVectorParticle::px) +
256  daughter(LorentzVectorParticle::m) * daughter(LorentzVectorParticle::m)));
257  }
258  double P2 = (mother(LorentzVectorParticle::px) * mother(LorentzVectorParticle::px) +
261  mother(LorentzVectorParticle::m) = (E * E - P2) / sqrt(fabs(E * E - P2));
262  return mother;
263 }
264 
266  int p(0);
267  if (Par == x0)
268  return "x0";
269  if (Par == y0)
270  return "y0";
271  if (Par == z0)
272  return "z0";
273  for (p = 0; p < nParticles_; p++) {
274  if ((Par - NFreeVertexPar) < (p + 1) * (NFreeTrackPar - NFreeVertexPar))
275  break;
276  }
277  TString n;
278  int index = Par - p * (NFreeTrackPar - NFreeVertexPar);
279  if (index == kappa0)
280  n = "kappa0";
281  if (index == lambda0)
282  n = "lambda0";
283  if (index == phi0)
284  n = "phi0";
285  n += "_particle";
286  n += p;
287  return n;
288 }
289 
290 void TrackHelixVertexFitter::parSizeInfo(const TVectorT<double>& inpar, int& np, int& parsize, bool hasextras) {
291  if (hasextras)
292  np = (inpar.GetNrows() - NFreeVertexPar - NExtraPar) / (NFreeTrackPar + MassOffSet - NFreeVertexPar);
293  else
294  np = (inpar.GetNrows() - NFreeVertexPar) / (NFreeTrackPar - NFreeVertexPar);
295  parsize = np * (NFreeTrackPar - NFreeVertexPar) + NFreeVertexPar;
296 }
const double Pi
const edm::EventSetup & c
tuple massHypothesis
math::XYZTLorentzVectorD LV
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
static TVectorT< double > computeMotherLorentzVectorPar(const TVectorT< double > &inpar)
virtual double updateChisquare(const TVectorT< double > &inpar)
virtual std::vector< TrackParticle > getRefitTracks()
int np
Definition: AMPTWrapper.h:43
static TVectorT< double > computePar(const TVectorT< double > &inpar)
T sqrt(T t)
Definition: SSEVec.h:19
static TVectorT< double > computeLorentzVectorPar(const TVectorT< double > &inpar)
static void parSizeInfo(const TVectorT< double > &inpar, int &np, int &parsize, bool hasextras=false)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
static const std::string B
static int measuredValueIndex(int TrackPar, int Particle)
virtual TMatrixTSym< double > getVertexError()
std::vector< LorentzVectorParticle > getRefitLorentzVectorParticles()
TrackHelixVertexFitter(const std::vector< TrackParticle > &particles, const TVector3 &vguess)
static TVectorT< double > computeTrackPar(const TVectorT< double > &inpar, int p=0)
static int freeParIndex(int Par, int Particle)
double b
Definition: hdecay.h:118
static void computedxydz(const TVectorT< double > &inpar, int particle, double &kappa, double &lam, double &phi, double &x, double &y, double &z, double &s, double &dxy, double &dz)
Log< level::Warning, false > LogWarning
tuple size
Write out results.
static TMatrixTSym< double > propagateError(std::function< TVectorT< double >(const TVectorT< double > &)> f, const TVectorT< double > &inPar, TMatrixTSym< double > &inCov, double epsilon=0.001, double errorEpsilonRatio=1000)