CMS 3D CMS Logo

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