CMS 3D CMS Logo

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()) {
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(
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 }
tauImpactParameter::TrackHelixVertexFitter::cov_
TMatrixTSym< double > cov_
Definition: TrackHelixVertexFitter.h:78
tauImpactParameter::TrackHelixVertexFitter::nVal_
int nVal_
Definition: TrackHelixVertexFitter.h:80
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
tauImpactParameter::TrackHelixVertexFitter::kappa0
Definition: TrackHelixVertexFitter.h:27
tauImpactParameter::LorentzVectorParticle
Definition: LorentzVectorParticle.h:17
funct::false
false
Definition: Factorize.h:29
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
TrackHelixVertexFitter.h
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
np
int np
Definition: AMPTWrapper.h:43
tauImpactParameter::TrackHelixVertexFitter::computeMotherLorentzVectorPar
static TVectorT< double > computeMotherLorentzVectorPar(const TVectorT< double > &inpar)
Definition: TrackHelixVertexFitter.cc:234
tauImpactParameter::TrackHelixVertexFitter::particles_
std::vector< TrackParticle > particles_
Definition: TrackHelixVertexFitter.h:76
tauImpactParameter::LorentzVectorParticle::py
Definition: LorentzVectorParticle.h:24
tauImpactParameter
Definition: Chi2VertexFitter.h:14
tauImpactParameter::TrackHelixVertexFitter::val_
TVectorT< double > val_
Definition: TrackHelixVertexFitter.h:77
tauImpactParameter::TrackHelixVertexFitter::NFreeVertexPar
Definition: TrackHelixVertexFitter.h:26
tauImpactParameter::TrackHelixVertexFitter::getVertex
virtual TVector3 getVertex()
Definition: TrackHelixVertexFitter.cc:143
tauImpactParameter::TrackHelixVertexFitter::x0
Definition: TrackHelixVertexFitter.h:26
tauImpactParameter::TrackHelixVertexFitter::parcov_
TMatrixTSym< double > parcov_
Definition: TrackHelixVertexFitter.h:59
tauImpactParameter::TrackHelixVertexFitter::isConfigured_
bool isConfigured_
Definition: TrackHelixVertexFitter.h:57
tauImpactParameter::ErrorMatrixPropagator::propagateError
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)
Definition: ErrorMatrixPropagator.cc:12
findQualityFiles.v
v
Definition: findQualityFiles.py:179
tauImpactParameter::TrackHelixVertexFitter::cov_inv_
TMatrixTSym< double > cov_inv_
Definition: TrackHelixVertexFitter.h:79
tauImpactParameter::TrackHelixVertexFitter::updateChisquare
virtual double updateChisquare(const TVectorT< double > &inpar)
Definition: TrackHelixVertexFitter.cc:68
tauImpactParameter::TrackHelixVertexFitter::phi0
Definition: TrackHelixVertexFitter.h:27
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
ecalTrigSettings_cff.particles
particles
Definition: ecalTrigSettings_cff.py:11
tauImpactParameter::TrackHelixVertexFitter::NExtraPar
Definition: TrackHelixVertexFitter.h:28
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
tauImpactParameter::TrackHelixVertexFitter::nPar_
int nPar_
Definition: TrackHelixVertexFitter.h:80
alignCSCRings.s
s
Definition: alignCSCRings.py:92
tauImpactParameter::TrackHelixVertexFitter::computeLorentzVectorPar
static TVectorT< double > computeLorentzVectorPar(const TVectorT< double > &inpar)
Definition: TrackHelixVertexFitter.cc:213
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
tauImpactParameter::TrackHelixVertexFitter::BField0
Definition: TrackHelixVertexFitter.h:28
tauImpactParameter::TrackParticle::kappa
Definition: TrackParticle.h:17
tauImpactParameter::TrackHelixVertexFitter::getRefitTracks
virtual std::vector< TrackParticle > getRefitTracks()
Definition: TrackHelixVertexFitter.cc:75
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
tauImpactParameter::TrackHelixVertexFitter::lambda0
Definition: TrackHelixVertexFitter.h:27
dqmdumpme.k
k
Definition: dqmdumpme.py:60
tauImpactParameter::TrackHelixVertexFitter::parSizeInfo
static void parSizeInfo(const TVectorT< double > &inpar, int &np, int &parsize, bool hasextras=false)
Definition: TrackHelixVertexFitter.cc:290
b
double b
Definition: hdecay.h:118
tauImpactParameter::TrackHelixVertexFitter::freeParName
virtual TString freeParName(int Par)
Definition: TrackHelixVertexFitter.cc:265
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
tauImpactParameter::TrackHelixVertexFitter::getVertexError
virtual TMatrixTSym< double > getVertexError()
Definition: TrackHelixVertexFitter.cc:147
tauImpactParameter::LorentzVectorParticle::m
Definition: LorentzVectorParticle.h:26
tauImpactParameter::LorentzVectorParticle::NLorentzandVertexPar
Definition: LorentzVectorParticle.h:27
tauImpactParameter::TrackHelixVertexFitter::computePar
static TVectorT< double > computePar(const TVectorT< double > &inpar)
Definition: TrackHelixVertexFitter.cc:188
tauImpactParameter::TrackParticle::lambda
Definition: TrackParticle.h:17
tauImpactParameter::LorentzVectorParticle::pz
Definition: LorentzVectorParticle.h:25
tauImpactParameter::TrackHelixVertexFitter::measuredValueIndex
static int measuredValueIndex(int TrackPar, int Particle)
Definition: TrackHelixVertexFitter.h:68
funct::tan
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
tauImpactParameter::TrackParticle
Definition: TrackParticle.h:15
tauImpactParameter::TrackHelixVertexFitter::NFreeTrackPar
Definition: TrackHelixVertexFitter.h:27
tauImpactParameter::LorentzVectorParticle::px
Definition: LorentzVectorParticle.h:23
tauImpactParameter::TrackHelixVertexFitter::ndf_
double ndf_
Definition: TrackHelixVertexFitter.h:61
EgammaValidation_cff.pdgId
pdgId
Definition: EgammaValidation_cff.py:118
tauImpactParameter::TrackHelixVertexFitter::computeTrackPar
static TVectorT< double > computeTrackPar(const TVectorT< double > &inpar, int p=0)
Definition: TrackHelixVertexFitter.cc:200
tauImpactParameter::TrackHelixVertexFitter::freeParIndex
static int freeParIndex(int Par, int Particle)
Definition: TrackHelixVertexFitter.h:69
tauImpactParameter::TrackHelixVertexFitter::MassOffSet
Definition: TrackHelixVertexFitter.h:28
tauImpactParameter::TrackParticle::NHelixPar
Definition: TrackParticle.h:17
TtFullHadDaughter::B
static const std::string B
Definition: TtFullHadronicEvent.h:9
tauImpactParameter::TrackHelixVertexFitter::~TrackHelixVertexFitter
virtual ~TrackHelixVertexFitter()
Definition: TrackHelixVertexFitter.cc:66
tauImpactParameter::TrackHelixVertexFitter::computedxydz
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)
Definition: TrackHelixVertexFitter.cc:157
tauImpactParameter::TrackHelixVertexFitter::nParticles_
int nParticles_
Definition: TrackHelixVertexFitter.h:80
tauImpactParameter::LorentzVectorParticle::vx
Definition: LorentzVectorParticle.h:20
PVValHelper::dxy
Definition: PVValidationHelpers.h:48
Calorimetry_cff.bField
bField
Definition: Calorimetry_cff.py:284
PVValHelper::dz
Definition: PVValidationHelpers.h:51
tauImpactParameter::TrackHelixVertexFitter::getRefitLorentzVectorParticles
std::vector< LorentzVectorParticle > getRefitLorentzVectorParticles()
Definition: TrackHelixVertexFitter.cc:99
tauImpactParameter::TrackHelixVertexFitter::getMother
LorentzVectorParticle getMother(int pdgid)
Definition: TrackHelixVertexFitter.cc:121
tauImpactParameter::TrackHelixVertexFitter::TrackHelixVertexFitter
TrackHelixVertexFitter(const std::vector< TrackParticle > &particles, const TVector3 &vguess)
Definition: TrackHelixVertexFitter.cc:13
LV
math::XYZTLorentzVectorD LV
Definition: HLTTauDQMPlotter.h:15
tauImpactParameter::LorentzVectorParticle::vy
Definition: LorentzVectorParticle.h:21
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
HLT_FULL_cff.massHypothesis
massHypothesis
Definition: HLT_FULL_cff.py:32657
tauImpactParameter::TrackParticle::phi
Definition: TrackParticle.h:17
tauImpactParameter::TrackHelixVertexFitter::par_
TVectorT< double > par_
Definition: TrackHelixVertexFitter.h:58
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
tauImpactParameter::TrackHelixVertexFitter::y0
Definition: TrackHelixVertexFitter.h:26
Pi
const double Pi
Definition: CosmicMuonParameters.h:18
tauImpactParameter::TrackParticle::dxy
Definition: TrackParticle.h:17
tauImpactParameter::TrackHelixVertexFitter::z0
Definition: TrackHelixVertexFitter.h:26
kappa
static const G4double kappa
Definition: UrbanMscModel93.cc:35
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
tauImpactParameter::TrackParticle::dz
Definition: TrackParticle.h:17
EgammaValidation_cff.pdgid
pdgid
Definition: EgammaValidation_cff.py:30
tauImpactParameter::LorentzVectorParticle::vz
Definition: LorentzVectorParticle.h:22
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443