CMS 3D CMS Logo

TwoBodyDecayTrajectory.cc
Go to the documentation of this file.
2 
9 
11 
13 
16  const MagneticField* magField,
17  const reco::BeamSpot& beamSpot,
21  recHits.first.size() + recHits.second.size(),
22  (config.materialEffects >= breakPoints) ? 2 * (recHits.first.size() + recHits.second.size()) - 4 : 0,
23  (config.materialEffects >= breakPoints) ? 2 * (recHits.first.size() + recHits.second.size()) - 3 : 1),
24  materialEffects_(config.materialEffects),
25  propDir_(config.propDir),
26  useRefittedState_(config.useRefittedState),
27  constructTsosWithErrors_(config.constructTsosWithErrors)
28 
29 {
30  if (config.hitsAreReverse) {
31  TransientTrackingRecHit::ConstRecHitContainer::const_reverse_iterator itRecHits;
32  ConstRecHitCollection fwdRecHits;
33 
34  fwdRecHits.first.reserve(recHits.first.size());
35  for (itRecHits = recHits.first.rbegin(); itRecHits != recHits.first.rend(); ++itRecHits) {
36  fwdRecHits.first.push_back(*itRecHits);
37  }
38 
39  fwdRecHits.second.reserve(recHits.second.size());
40  for (itRecHits = recHits.second.rbegin(); itRecHits != recHits.second.rend(); ++itRecHits) {
41  fwdRecHits.second.push_back(*itRecHits);
42  }
43 
44  theValidityFlag = this->construct(tsos, fwdRecHits, magField, beamSpot);
45  } else {
46  theValidityFlag = this->construct(tsos, recHits, magField, beamSpot);
47  }
48 }
49 
51  : ReferenceTrajectoryBase(0, 0, 0, 0),
56 
59  const MagneticField* field,
60  const reco::BeamSpot& beamSpot) {
63  double mass = state.particleMass();
64 
65  //
66  // first track
67  //
68 
69  // construct a trajectory (hits should be already in correct order)
71  config.useBeamSpot = false;
72  config.hitsAreReverse = false;
73 
74  ReferenceTrajectory trajectory1(tsos.first, recHits.first, field, beamSpot, config);
75 
76  // check if construction of trajectory was successful
77  if (!trajectory1.isValid())
78  return false;
79 
80  //
81  // second track
82  //
83 
84  ReferenceTrajectory trajectory2(tsos.second, recHits.second, field, beamSpot, config);
85 
86  if (!trajectory2.isValid())
87  return false;
88 
89  //
90  // combine both tracks
91  //
92  unsigned int nLocal = deriv.first.num_row();
93  unsigned int nTbd = deriv.first.num_col();
94 
95  if (materialEffects_ >= localGBL) {
96  // GBL trajectory inputs
97  // convert to Eigen::MatrixXd
98  Eigen::MatrixXd tbdToLocal1{nLocal, nTbd};
99  for (unsigned int row = 0; row < nLocal; ++row) {
100  for (unsigned int col = 0; col < nTbd; ++col) {
101  tbdToLocal1(row, col) = deriv.first[row][col];
102  }
103  }
104  // add first body
105  theGblInput.push_back(
106  std::make_pair(trajectory1.gblInput().front().first, trajectory1.gblInput().front().second * tbdToLocal1));
107  // convert to Eigen::MatrixXd
108  Eigen::MatrixXd tbdToLocal2{nLocal, nTbd};
109  for (unsigned int row = 0; row < nLocal; ++row) {
110  for (unsigned int col = 0; col < nTbd; ++col) {
111  tbdToLocal2(row, col) = deriv.second[row][col];
112  }
113  }
114  // add second body
115  theGblInput.push_back(
116  std::make_pair(trajectory2.gblInput().front().first, trajectory2.gblInput().front().second * tbdToLocal2));
117  // add virtual mass measurement
118  theGblExtDerivatives.resize(1, nTbd);
119  theGblExtDerivatives.setZero();
121  theGblExtMeasurements.resize(1);
123  theGblExtPrecisions.resize(1);
124  theGblExtPrecisions(0) = 1.0 / (state.primaryWidth() * state.primaryWidth());
125  // nominal field
126  theNomField = trajectory1.nominalField();
127  } else {
128  unsigned int nHitMeas1 = trajectory1.numberOfHitMeas();
129  unsigned int nVirtualMeas1 = trajectory1.numberOfVirtualMeas();
130  unsigned int nPar1 = trajectory1.numberOfPar();
131  unsigned int nVirtualPar1 = trajectory1.numberOfVirtualPar();
132 
133  // derivatives of the trajectory w.r.t. to the decay parameters
134  AlgebraicMatrix fullDeriv1 = trajectory1.derivatives().sub(1, nHitMeas1 + nVirtualMeas1, 1, nLocal) *
135  trajectory1.localToTrajectory() * deriv.first;
136 
137  unsigned int nHitMeas2 = trajectory2.numberOfHitMeas();
138  unsigned int nVirtualMeas2 = trajectory2.numberOfVirtualMeas();
139  unsigned int nPar2 = trajectory2.numberOfPar();
140  unsigned int nVirtualPar2 = trajectory2.numberOfVirtualPar();
141 
142  AlgebraicMatrix fullDeriv2 = trajectory2.derivatives().sub(1, nHitMeas2 + nVirtualMeas2, 1, nLocal) *
143  trajectory2.localToTrajectory() * deriv.second;
144 
145  theNumberOfRecHits.first = recHits.first.size();
146  theNumberOfRecHits.second = recHits.second.size();
147 
148  theNumberOfHits = trajectory1.numberOfHits() + trajectory2.numberOfHits();
149  theNumberOfPars = nPar1 + nPar2;
150  theNumberOfVirtualPars = nVirtualPar1 + nVirtualPar2;
151  theNumberOfVirtualMeas = nVirtualMeas1 + nVirtualMeas2 + 1; // add virtual mass measurement
152 
153  // hit measurements from trajectory 1
154  int rowOffset = 1;
155  int colOffset = 1;
156  theDerivatives.sub(rowOffset, colOffset, fullDeriv1.sub(1, nHitMeas1, 1, nTbd));
157  colOffset += nTbd;
158  theDerivatives.sub(
159  rowOffset, colOffset, trajectory1.derivatives().sub(1, nHitMeas1, nLocal + 1, nPar1 + nVirtualPar1));
160  // hit measurements from trajectory 2
161  rowOffset += nHitMeas1;
162  colOffset = 1;
163  theDerivatives.sub(rowOffset, colOffset, fullDeriv2.sub(1, nHitMeas2, 1, nTbd));
164  colOffset += (nPar1 + nVirtualPar1 + nTbd - nLocal);
165  theDerivatives.sub(
166  rowOffset, colOffset, trajectory2.derivatives().sub(1, nHitMeas2, nLocal + 1, nPar2 + nVirtualPar2));
167  // MS measurements from trajectory 1
168  rowOffset += nHitMeas2;
169  colOffset = 1;
170  theDerivatives.sub(rowOffset, colOffset, fullDeriv1.sub(nHitMeas1 + 1, nHitMeas1 + nVirtualMeas1, 1, nTbd));
171  colOffset += nTbd;
172  theDerivatives.sub(
173  rowOffset,
174  colOffset,
175  trajectory1.derivatives().sub(nHitMeas1 + 1, nHitMeas1 + nVirtualMeas1, nLocal + 1, nPar1 + nVirtualPar1));
176  // MS measurements from trajectory 2
177  rowOffset += nVirtualMeas1;
178  colOffset = 1;
179  theDerivatives.sub(rowOffset, colOffset, fullDeriv2.sub(nHitMeas2 + 1, nHitMeas2 + nVirtualMeas2, 1, nTbd));
180  colOffset += (nPar1 + nVirtualPar1 + nTbd - nLocal);
181  theDerivatives.sub(
182  rowOffset,
183  colOffset,
184  trajectory2.derivatives().sub(nHitMeas2 + 1, nHitMeas2 + nVirtualMeas2, nLocal + 1, nPar2 + nVirtualPar2));
185 
186  theMeasurements.sub(1, trajectory1.measurements().sub(1, nHitMeas1));
187  theMeasurements.sub(nHitMeas1 + 1, trajectory2.measurements().sub(1, nHitMeas2));
188  theMeasurements.sub(nHitMeas1 + nHitMeas2 + 1,
189  trajectory1.measurements().sub(nHitMeas1 + 1, nHitMeas1 + nVirtualMeas1));
190  theMeasurements.sub(nHitMeas1 + nHitMeas2 + nVirtualMeas1 + 1,
191  trajectory2.measurements().sub(nHitMeas2 + 1, nHitMeas2 + nVirtualMeas2));
192 
193  theMeasurementsCov.sub(1, trajectory1.measurementErrors().sub(1, nHitMeas1));
194  theMeasurementsCov.sub(nHitMeas1 + 1, trajectory2.measurementErrors().sub(1, nHitMeas2));
195  theMeasurementsCov.sub(nHitMeas1 + nHitMeas2 + 1,
196  trajectory1.measurementErrors().sub(nHitMeas1 + 1, nHitMeas1 + nVirtualMeas1));
197  theMeasurementsCov.sub(nHitMeas1 + nHitMeas2 + nVirtualMeas1 + 1,
198  trajectory2.measurementErrors().sub(nHitMeas2 + 1, nHitMeas2 + nVirtualMeas2));
199 
200  theTrajectoryPositions.sub(1, trajectory1.trajectoryPositions());
201  theTrajectoryPositions.sub(nHitMeas1 + 1, trajectory2.trajectoryPositions());
202 
204  state.decayParameters().covariance().similarity(theDerivatives.sub(1, nHitMeas1 + nHitMeas2, 1, 9));
205 
207 
208  // add virtual mass measurement
209  rowOffset += nVirtualMeas2;
210  int indMass = rowOffset - 1;
212  theMeasurementsCov[indMass][indMass] = state.primaryWidth() * state.primaryWidth();
214  }
215 
216  theRecHits.insert(theRecHits.end(), recHits.first.begin(), recHits.first.end());
217  theRecHits.insert(theRecHits.end(), recHits.second.begin(), recHits.second.end());
218 
220  constructTsosVecWithErrors(trajectory1, trajectory2, field);
221  } else {
222  theTsosVec.insert(theTsosVec.end(), trajectory1.trajectoryStates().begin(), trajectory1.trajectoryStates().end());
223 
224  theTsosVec.insert(theTsosVec.end(), trajectory2.trajectoryStates().begin(), trajectory2.trajectoryStates().end());
225  }
226 
227  return true;
228 }
229 
231  const ReferenceTrajectory& traj2,
232  const MagneticField* field) {
233  int iTsos = 0;
234 
235  std::vector<TrajectoryStateOnSurface>::const_iterator itTsos;
236 
237  for (itTsos = traj1.trajectoryStates().begin(); itTsos != traj1.trajectoryStates().end(); itTsos++) {
238  constructSingleTsosWithErrors(*itTsos, iTsos, field);
239  iTsos++;
240  }
241 
242  for (itTsos = traj2.trajectoryStates().begin(); itTsos != traj2.trajectoryStates().end(); itTsos++) {
243  constructSingleTsosWithErrors(*itTsos, iTsos, field);
244  iTsos++;
245  }
246 }
247 
249  int iTsos,
250  const MagneticField* field) {
251  AlgebraicSymMatrix55 localErrors;
252  const double coeff = 1e-2;
253 
254  double invP = tsos.localParameters().signedInverseMomentum();
256 
257  // rough estimate for the errors of q/p, dx/dz and dy/dz, assuming that
258  // sigma(px) = sigma(py) = sigma(pz) = coeff*p.
259  float dpinv = coeff * (fabs(p.x()) + fabs(p.y()) + fabs(p.z())) * invP * invP;
260  float dxdir = coeff * (fabs(p.x()) + fabs(p.z())) / p.z() / p.z();
261  float dydir = coeff * (fabs(p.y()) + fabs(p.z())) / p.z() / p.z();
262  localErrors[0][0] = dpinv * dpinv;
263  localErrors[1][1] = dxdir * dxdir;
264  localErrors[2][2] = dydir * dydir;
265 
266  // exact values for the errors on local x and y
267  localErrors[3][3] = theTrajectoryPositionCov[nMeasPerHit * iTsos][nMeasPerHit * iTsos];
268  localErrors[3][4] = theTrajectoryPositionCov[nMeasPerHit * iTsos][nMeasPerHit * iTsos + 1];
269  localErrors[4][4] = theTrajectoryPositionCov[nMeasPerHit * iTsos + 1][nMeasPerHit * iTsos + 1];
270 
271  // construct tsos with local errors
273  tsos.localParameters(), LocalTrajectoryError(localErrors), tsos.surface(), field, tsos.surfaceSide());
274 }
size
Write out results.
unsigned int numberOfHits() const
std::pair< int, int > theNumberOfRecHits
const LocalTrajectoryParameters & localParameters() const
bool construct(const TwoBodyDecayTrajectoryState &state, const ConstRecHitCollection &recHits, const MagneticField *field, const reco::BeamSpot &beamSpot)
const AlgebraicVector & parameters(void) const
Get decay parameters.
void constructSingleTsosWithErrors(const TrajectoryStateOnSurface &tsos, int iTsos, const MagneticField *field)
unsigned int numberOfHitMeas() const
const TransientTrackingRecHit::ConstRecHitContainer & recHits() const
T y() const
Definition: PV3DBase.h:60
unsigned int numberOfVirtualPar() const
Definition: config.py:1
const PropagationDirection propDir_
const TsosContainer & trajectoryStates(bool useRefittedState=true) const
const AlgebraicSymMatrix & measurementErrors() const
float signedInverseMomentum() const
Signed inverse momentum q/p (zero for neutrals).
U second(std::pair< T, U > const &p)
config
Definition: looper.py:291
AlgebraicSymMatrix theTrajectoryPositionCov
std::vector< std::pair< std::vector< gbl::GblPoint >, Eigen::MatrixXd > > theGblInput
const AlgebraicMatrix & derivatives() const
const SurfaceType & surface() const
const Derivatives & derivatives(void) const
CLHEP::HepMatrix AlgebraicMatrix
SurfaceSide surfaceSide() const
Position relative to material, defined relative to momentum vector.
T z() const
Definition: PV3DBase.h:61
const MaterialEffects materialEffects_
LocalVector momentum() const
Momentum vector in the local frame.
TransientTrackingRecHit::ConstRecHitContainer theRecHits
const AlgebraicMatrix & localToTrajectory() const
AlgebraicSymMatrix theMeasurementsCov
const TwoBodyDecayParameters & decayParameters(void) const
unsigned int numberOfPar() const
std::pair< TrajectoryStateOnSurface, TrajectoryStateOnSurface > TsosContainer
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
std::vector< std::pair< std::vector< gbl::GblPoint >, Eigen::MatrixXd > > & gblInput()
void constructTsosVecWithErrors(const ReferenceTrajectory &traj1, const ReferenceTrajectory &traj2, const MagneticField *field)
const AlgebraicSymMatrix & covariance(void) const
Get error matrix.
unsigned int numberOfVirtualMeas() const
std::pair< AlgebraicMatrix, AlgebraicMatrix > Derivatives
const AlgebraicVector & measurements() const
col
Definition: cuy.py:1010
std::vector< TrajectoryStateOnSurface > theTsosVec
const AlgebraicVector & trajectoryPositions() const
uint32_t dimension(pat::CandKinResolution::Parametrization parametrization)
Returns the number of free parameters in a parametrization (3 or 4)
T x() const
Definition: PV3DBase.h:59
std::pair< ConstRecHitContainer, ConstRecHitContainer > ConstRecHitCollection
const std::vector< TrajectoryStateOnSurface > & trajectoryStates() const