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 "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;
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 }
Vector3DBase
Definition: Vector3DBase.h:8
PFGsfHelper.h
CollinearFitAtTM
Definition: CollinearFitAtTM.h:17
TrajectoryStateOnSurface.h
BeamSpotPI::parameters
parameters
Definition: BeamSpotPayloadInspectorHelper.h:30
mps_fire.i
i
Definition: mps_fire.py:428
GaussianSumUtilities1D::mode
const SingleGaussianState1D & mode() const
Definition: GaussianSumUtilities1D.cc:85
MessageLogger.h
MultiGaussianStateTransform.h
ESHandle.h
edm
HLT enums.
Definition: AlignableModifier.h:19
TrajectoryMeasurement::updatedState
TrajectoryStateOnSurface const & updatedState() const
Definition: TrajectoryMeasurement.h:184
LocalTrajectoryError::matrix
const AlgebraicSymMatrix55 & matrix() const
Definition: LocalTrajectoryError.h:60
GaussianSumUtilities1D.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
GlobalVector
Global3DVector GlobalVector
Definition: GlobalVector.h:10
SingleGaussianState1D::mean
double mean() const
parameter vector
Definition: SingleGaussianState1D.h:25
MultiGaussianState1D.h
GetComponents.h
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
PFGsfHelper::computeQpMode
void computeQpMode(const TrajectoryStateOnSurface tsos, AlgebraicVector5 &parameters, AlgebraicSymMatrix55 &covariance) const
Definition: PFGsfHelper.cc:134
GetComponents
Definition: GetComponents.h:4
Track.h
TrajectoryMeasurement::backwardPredictedState
TrajectoryStateOnSurface const & backwardPredictedState() const
Access to backward predicted state (from smoother)
Definition: TrajectoryMeasurement.h:179
Calorimetry_cff.dp
dp
Definition: Calorimetry_cff.py:158
SingleGaussianState1D::variance
double variance() const
variance
Definition: SingleGaussianState1D.h:27
TrajectoryMeasurement::forwardPredictedState
TrajectoryStateOnSurface const & forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
Definition: TrajectoryMeasurement.h:177
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
AlgebraicSymMatrix66
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > AlgebraicSymMatrix66
Definition: AlgebraicROOTObjects.h:24
PFCluster.h
MultiGaussianState1D
Definition: MultiGaussianState1D.h:12
LocalTrajectoryParameters::vector
AlgebraicVector5 vector() const
Definition: LocalTrajectoryParameters.h:120
Point3DBase< float, LocalTag >
PFGsfHelper::~PFGsfHelper
~PFGsfHelper()
Definition: PFGsfHelper.cc:121
TrajectoryStateOnSurface::localParameters
const LocalTrajectoryParameters & localParameters() const
Definition: TrajectoryStateOnSurface.h:73
PFGsfHelper::sigmafittedDP
double sigmafittedDP() const
Definition: PFGsfHelper.cc:131
PFGsfHelper::PFGsfHelper
PFGsfHelper(const TrajectoryMeasurement &)
Definition: PFGsfHelper.cc:32
LocalError
Definition: LocalError.h:12
SingleGaussianState1D
Definition: SingleGaussianState1D.h:10
PFGsfHelper::fittedDP
double fittedDP() const
Definition: PFGsfHelper.cc:130
CollinearFitAtTM::ResultMatrix
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > ResultMatrix
Definition: CollinearFitAtTM.h:25
AlgebraicVector5
ROOT::Math::SVector< double, 5 > AlgebraicVector5
Definition: AlgebraicROOTObjects.h:14
TrajectoryMeasurement::recHit
ConstRecHitPointer const & recHit() const
Definition: TrajectoryMeasurement.h:190
Trajectory.h
std
Definition: JetResolutionObject.h:76
makeMuonMisalignmentScenario.components
string components
Definition: makeMuonMisalignmentScenario.py:58
PFGsfHelper::computeP
GlobalVector computeP(bool ComputeMode) const
Definition: PFGsfHelper.cc:122
GaussianSumUtilities1D
Definition: GaussianSumUtilities1D.h:16
CollinearFitAtTM::fit
bool fit(const TrajectoryMeasurement &tm, ResultVector &parameters, ResultMatrix &covariance, double &chi2)
Fit for one TM. Return value "true" for success.
Definition: CollinearFitAtTM.cc:19
PFRecTrackFwd.h
fitChi2
static double fitChi2(const CachingVertex< 5 > &vtx)
Definition: GhostTrackVertexFinder.cc:638
MultiGaussianStateTransform::multiState1D
MultiGaussianState1D multiState1D(const std::vector< MultiGaussianState< N >::Vector > &, const std::vector< MultiGaussianState< N >::Matrix > &, const std::vector< double > &, unsigned int)
Definition: MultiGaussianStateTransform.cc:54
L1TRate_cfi.fitParameters
fitParameters
Offline oracleDB = cms.string("oracle://cms_orcon_adg/CMS_COND_31X_L1T"), # For offline pathCondDB = ...
Definition: L1TRate_cfi.py:69
PFGsfHelper::isValid
bool isValid() const
Definition: PFGsfHelper.cc:132
TrajectoryStateOnSurface::localError
const LocalTrajectoryError & localError() const
Definition: TrajectoryStateOnSurface.h:77
AlgebraicSymMatrix55
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
Definition: AlgebraicROOTObjects.h:23
TrajectoryMeasurement
Definition: TrajectoryMeasurement.h:25
CollinearFitAtTM::ResultVector
ROOT::Math::SVector< double, 6 > ResultVector
Definition: CollinearFitAtTM.h:24
CollinearFitAtTM.h
GaussianSumUtilities1D::modeIsValid
bool modeIsValid() const
mode status
Definition: GaussianSumUtilities1D.cc:79