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,
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 {
47  }
48 }
49 
51  : ReferenceTrajectoryBase(0, 0, 0, 0),
52  materialEffects_(none),
53  propDir_(anyDirection),
54  useRefittedState_(false),
55  constructTsosWithErrors_(false) {}
56 
59  const MagneticField* field,
60  const reco::BeamSpot& beamSpot) {
62  const TwoBodyDecayTrajectoryState::Derivatives& deriv = state.derivatives();
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);
122  theGblExtMeasurements(0) = state.primaryMass() - state.decayParameters()[TwoBodyDecayParameters::mass];
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 
206  theParameters = state.decayParameters().parameters();
207 
208  // add virtual mass measurement
209  rowOffset += nVirtualMeas2;
210  int indMass = rowOffset - 1;
211  theMeasurements[indMass] = state.primaryMass() - state.decayParameters()[TwoBodyDecayParameters::mass];
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.
const AlgebraicMatrix & localToTrajectory() const
unsigned int numberOfPar() const
std::pair< int, int > theNumberOfRecHits
const AlgebraicSymMatrix & measurementErrors() const
SurfaceSide surfaceSide() const
Position relative to material, defined relative to momentum vector.
float signedInverseMomentum() const
Signed inverse momentum q/p (zero for neutrals).
bool construct(const TwoBodyDecayTrajectoryState &state, const ConstRecHitCollection &recHits, const MagneticField *field, const reco::BeamSpot &beamSpot)
unsigned int numberOfHits() const
unsigned int numberOfHitMeas() const
unsigned int numberOfVirtualMeas() const
void constructSingleTsosWithErrors(const TrajectoryStateOnSurface &tsos, int iTsos, const MagneticField *field)
const AlgebraicVector & measurements() const
const LocalTrajectoryParameters & localParameters() const
Definition: config.py:1
const PropagationDirection propDir_
unsigned int numberOfVirtualPar() const
const SurfaceType & surface() const
const std::vector< TrajectoryStateOnSurface > & trajectoryStates() const
U second(std::pair< T, U > const &p)
AlgebraicSymMatrix theTrajectoryPositionCov
std::vector< std::pair< std::vector< gbl::GblPoint >, Eigen::MatrixXd > > theGblInput
CLHEP::HepMatrix AlgebraicMatrix
LocalVector momentum() const
Momentum vector in the local frame.
const MaterialEffects materialEffects_
const AlgebraicVector & trajectoryPositions() const
Eigen::MatrixXd MatrixXd
Definition: FitUtils.h:17
TransientTrackingRecHit::ConstRecHitContainer theRecHits
AlgebraicSymMatrix theMeasurementsCov
static constexpr unsigned int nMeasPerHit
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)
std::pair< AlgebraicMatrix, AlgebraicMatrix > Derivatives
col
Definition: cuy.py:1009
std::vector< TrajectoryStateOnSurface > theTsosVec
dictionary config
Read in AllInOne config in JSON format.
Definition: DiMuonV_cfg.py:30
const TransientTrackingRecHit::ConstRecHitContainer & recHits() const
uint32_t dimension(pat::CandKinResolution::Parametrization parametrization)
Returns the number of free parameters in a parametrization (3 or 4)
std::pair< ConstRecHitContainer, ConstRecHitContainer > ConstRecHitCollection
const AlgebraicMatrix & derivatives() const