test
CMS 3D CMS Logo

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