CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PFGsfHelper.cc
Go to the documentation of this file.
1 //
2 // -*- C++ -*-
3 // Package: PFTracking
4 // Class: PFGsfHelper
5 //
6 // Original Author: Daniele Benedetti
7 
9 
12 
16 
18 //#include "CommonTools/BaseParticlePropagator/interface/BaseParticlePropagator.h"
19 
21 // Add by Daniele
27 
28 using namespace std;
29 using namespace reco;
30 using namespace edm;
31 
33  /* LogInfo("PFGsfHelper")<<" PFGsfHelper built"; */
34 
35  // TrajectoryStateOnSurface theUpdateState = tm.forwardPredictedState();
36  theUpdateState = tm.updatedState();
37  theForwardState = tm.forwardPredictedState();
38  theBackwardState = tm.backwardPredictedState();
39 
40  Valid = true;
41  if (!theUpdateState.isValid() || !theForwardState.isValid() || !theBackwardState.isValid())
42  Valid = false;
43 
44  if (Valid) {
45  mode_Px = 0.;
46  mode_Py = 0.;
47  mode_Pz = 0.;
48  GetComponents comps(theUpdateState);
49  auto const& components = comps();
50  auto numb = components.size();
51  std::vector<SingleGaussianState1D> pxStates;
52  pxStates.reserve(numb);
53  std::vector<SingleGaussianState1D> pyStates;
54  pyStates.reserve(numb);
55  std::vector<SingleGaussianState1D> pzStates;
56  pzStates.reserve(numb);
57  for (auto ic = components.begin(); ic != components.end(); ++ic) {
58  GlobalVector momentum(ic->globalMomentum());
59  AlgebraicSymMatrix66 cov(ic->cartesianError().matrix());
60  pxStates.push_back(SingleGaussianState1D(momentum.x(), cov(3, 3), ic->weight()));
61  pyStates.push_back(SingleGaussianState1D(momentum.y(), cov(4, 4), ic->weight()));
62  pzStates.push_back(SingleGaussianState1D(momentum.z(), cov(5, 5), ic->weight()));
63  // cout<<"COMP "<<momentum<<endl;
64  }
65  MultiGaussianState1D pxState(pxStates);
66  MultiGaussianState1D pyState(pyStates);
67  MultiGaussianState1D pzState(pzStates);
68  GaussianSumUtilities1D pxUtils(pxState);
69  GaussianSumUtilities1D pyUtils(pyState);
70  GaussianSumUtilities1D pzUtils(pzState);
71  mode_Px = pxUtils.mode().mean();
72  mode_Py = pyUtils.mode().mean();
73  mode_Pz = pzUtils.mode().mean();
74 
75  dp = 0.;
76  sigmaDp = 0.;
77 
78  //
79  // prepare input parameter vectors and covariance matrices
80  //
81 
82  AlgebraicVector5 fwdPars = theForwardState.localParameters().vector();
83  AlgebraicSymMatrix55 fwdCov = theForwardState.localError().matrix();
84  computeQpMode(theForwardState, fwdPars, fwdCov);
85  AlgebraicVector5 bwdPars = theBackwardState.localParameters().vector();
86  AlgebraicSymMatrix55 bwdCov = theBackwardState.localError().matrix();
87  computeQpMode(theBackwardState, bwdPars, bwdCov);
88  LocalPoint hitPos(0., 0., 0.);
89  LocalError hitErr(-1., -1., -1.);
90  if (tm.recHit()->isValid()) {
91  hitPos = tm.recHit()->localPosition();
92  hitErr = tm.recHit()->localPositionError();
93  }
94 
95  CollinearFitAtTM collinearFit;
96  CollinearFitAtTM::ResultVector fitParameters;
97  CollinearFitAtTM::ResultMatrix fitCovariance;
98  double fitChi2;
99  bool CollFit = true;
100  if (!collinearFit.fit(fwdPars, fwdCov, bwdPars, bwdCov, hitPos, hitErr, fitParameters, fitCovariance, fitChi2))
101  CollFit = false;
102 
103  if (CollFit) {
104  double qpIn = fitParameters(0);
105  double sig2In = fitCovariance(0, 0);
106  double qpOut = fitParameters(1);
107  double sig2Out = fitCovariance(1, 1);
108  double corrInOut = fitCovariance(0, 1);
109  double pIn = 1. / fabs(qpIn);
110  double pOut = 1. / fabs(qpOut);
111  double sig2DeltaP = pIn / qpIn * pIn / qpIn * sig2In - 2 * pIn / qpIn * pOut / qpOut * corrInOut +
112  pOut / qpOut * pOut / qpOut * sig2Out;
113  // std::cout << "fitted delta p = " << pOut-pIn << " sigma = "
114  // << sqrt(sig2DeltaP) << std::endl;
115  dp = pOut - pIn;
116  sigmaDp = sqrt(sig2DeltaP);
117  }
118  }
119 }
120 
122 GlobalVector PFGsfHelper::computeP(bool ComputeMode) const {
123  GlobalVector gsfp;
124  if (ComputeMode)
125  gsfp = GlobalVector(mode_Px, mode_Py, mode_Pz);
126  else
127  gsfp = theUpdateState.globalMomentum();
128  return gsfp;
129 }
130 double PFGsfHelper::fittedDP() const { return dp; }
131 double PFGsfHelper::sigmafittedDP() const { return sigmaDp; }
132 bool PFGsfHelper::isValid() const { return Valid; }
133 
136  AlgebraicSymMatrix55& covariance) const {
137  //
138  // parameters and errors from combined state
139  //
140  parameters = tsos.localParameters().vector();
141  covariance = tsos.localError().matrix();
142  //
143  // mode for parameter 0 (q/p)
144  //
146  GaussianSumUtilities1D qpGS(qpState);
147  if (!qpGS.modeIsValid())
148  return;
149  double qp = qpGS.mode().mean();
150  double varQp = qpGS.mode().variance();
151  //
152  // replace q/p value and variance, rescale correlation terms
153  // (heuristic procedure - alternative would be mode in 5D ...)
154  //
155  double VarQpRatio = sqrt(varQp / covariance(0, 0));
156  parameters(0) = qp;
157  covariance(0, 0) = varQp;
158  for (int i = 1; i < 5; ++i)
159  covariance(i, 0) *= VarQpRatio;
160  // std::cout << "covariance " << VarQpRatio << " "
161  // << covariance(1,0) << " " << covariance(0,1) << std::endl;
162 }
void computeQpMode(const TrajectoryStateOnSurface tsos, AlgebraicVector5 &parameters, AlgebraicSymMatrix55 &covariance) const
Definition: PFGsfHelper.cc:134
ConstRecHitPointer const & recHit() const
const LocalTrajectoryParameters & localParameters() const
bool fit(const TrajectoryMeasurement &tm, ResultVector &parameters, ResultMatrix &covariance, double &chi2)
Fit for one TM. Return value &quot;true&quot; for success.
double sigmafittedDP() const
Definition: PFGsfHelper.cc:131
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > ResultMatrix
static double fitChi2(const CachingVertex< 5 > &vtx)
AlgebraicVector5 vector() const
MultiGaussianState1D multiState1D(const std::vector< MultiGaussianState< N >::Vector > &, const std::vector< MultiGaussianState< N >::Matrix > &, const std::vector< double > &, unsigned int)
double mean() const
parameter vector
T sqrt(T t)
Definition: SSEVec.h:19
double variance() const
variance
const SingleGaussianState1D & mode() const
ROOT::Math::SVector< double, 5 > AlgebraicVector5
const AlgebraicSymMatrix55 & matrix() const
ROOT::Math::SVector< double, 6 > ResultVector
const LocalTrajectoryError & localError() const
TrajectoryStateOnSurface const & forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > AlgebraicSymMatrix66
PFGsfHelper(const TrajectoryMeasurement &)
Definition: PFGsfHelper.cc:32
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
double fittedDP() const
Definition: PFGsfHelper.cc:130
bool isValid() const
Definition: PFGsfHelper.cc:132
TrajectoryStateOnSurface const & updatedState() const
GlobalVector computeP(bool ComputeMode) const
Definition: PFGsfHelper.cc:122
bool modeIsValid() const
mode status
TrajectoryStateOnSurface const & backwardPredictedState() const
Access to backward predicted state (from smoother)
Global3DVector GlobalVector
Definition: GlobalVector.h:10