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 {
46  theValidityFlag = this->construct(tsos, recHits, magField, beamSpot);
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 }
Vector3DBase< float, LocalTag >
ReferenceTrajectoryBase::recHits
const TransientTrackingRecHit::ConstRecHitContainer & recHits() const
Definition: ReferenceTrajectoryBase.h:215
ReferenceTrajectoryBase::numberOfHits
unsigned int numberOfHits() const
Definition: ReferenceTrajectoryBase.h:217
ReferenceTrajectoryBase::numberOfPar
unsigned int numberOfPar() const
Definition: ReferenceTrajectoryBase.h:218
TwoBodyDecayTrajectoryState::TsosContainer
std::pair< TrajectoryStateOnSurface, TrajectoryStateOnSurface > TsosContainer
Definition: TwoBodyDecayTrajectoryState.h:14
pat::helper::ParametrizationHelper::dimension
uint32_t dimension(pat::CandKinResolution::Parametrization parametrization)
Returns the number of free parameters in a parametrization (3 or 4)
Definition: ParametrizationHelper.h:12
TrajectoryStateOnSurface.h
TwoBodyDecayTrajectory::constructSingleTsosWithErrors
void constructSingleTsosWithErrors(const TrajectoryStateOnSurface &tsos, int iTsos, const MagneticField *field)
Definition: TwoBodyDecayTrajectory.cc:248
ReferenceTrajectoryBase::derivatives
const AlgebraicMatrix & derivatives() const
Definition: ReferenceTrajectoryBase.h:164
anyDirection
Definition: PropagationDirection.h:4
FreeTrajectoryState.h
pwdgSkimBPark_cfi.beamSpot
beamSpot
Definition: pwdgSkimBPark_cfi.py:5
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
AlgebraicObjects.h
LocalTrajectoryParameters::signedInverseMomentum
float signedInverseMomentum() const
Signed inverse momentum q/p (zero for neutrals).
Definition: LocalTrajectoryParameters.h:113
ReferenceTrajectoryBase::theNumberOfVirtualPars
unsigned int theNumberOfVirtualPars
Definition: ReferenceTrajectoryBase.h:241
TwoBodyDecayParameters::mass
Definition: TwoBodyDecayParameters.h:17
ReferenceTrajectoryBase::measurementErrors
const AlgebraicSymMatrix & measurementErrors() const
Definition: ReferenceTrajectoryBase.h:150
ReferenceTrajectoryBase
Definition: ReferenceTrajectoryBase.h:105
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
cuy.col
col
Definition: cuy.py:1010
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
ReferenceTrajectoryBase::theDerivatives
AlgebraicMatrix theDerivatives
Definition: ReferenceTrajectoryBase.h:255
ReferenceTrajectoryBase::Config
Definition: ReferenceTrajectoryBase.h:121
ReferenceTrajectoryBase::theTrajectoryPositionCov
AlgebraicSymMatrix theTrajectoryPositionCov
Definition: ReferenceTrajectoryBase.h:250
ReferenceTrajectoryBase::numberOfHitMeas
unsigned int numberOfHitMeas() const
Definition: ReferenceTrajectoryBase.h:221
ReferenceTrajectoryBase::nominalField
int nominalField() const
Definition: ReferenceTrajectoryBase.h:222
ReferenceTrajectoryBase::numberOfVirtualMeas
unsigned int numberOfVirtualMeas() const
Definition: ReferenceTrajectoryBase.h:219
ReferenceTrajectoryBase::theMeasurements
AlgebraicVector theMeasurements
Definition: ReferenceTrajectoryBase.h:246
ReferenceTrajectoryBase::theGblExtPrecisions
Eigen::VectorXd theGblExtPrecisions
Definition: ReferenceTrajectoryBase.h:267
ReferenceTrajectoryBase::measurements
const AlgebraicVector & measurements() const
Definition: ReferenceTrajectoryBase.h:146
ReferenceTrajectoryBase::trajectoryStates
const std::vector< TrajectoryStateOnSurface > & trajectoryStates() const
Definition: ReferenceTrajectoryBase.h:210
none
Definition: EcalBoundaryInfoCalculator.h:24
ReferenceTrajectoryBase::numberOfVirtualPar
unsigned int numberOfVirtualPar() const
Definition: ReferenceTrajectoryBase.h:220
config
Definition: config.py:1
ReferenceTrajectoryBase::theParameters
AlgebraicVector theParameters
Definition: ReferenceTrajectoryBase.h:252
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
TwoBodyDecayParameters.h
ReferenceTrajectoryBase::theNumberOfVirtualMeas
unsigned int theNumberOfVirtualMeas
Definition: ReferenceTrajectoryBase.h:240
Surface.h
ReferenceTrajectoryBase::theNumberOfHits
unsigned int theNumberOfHits
Definition: ReferenceTrajectoryBase.h:238
TwoBodyDecayTrajectory::ConstRecHitCollection
std::pair< ConstRecHitContainer, ConstRecHitContainer > ConstRecHitCollection
Definition: TwoBodyDecayTrajectory.h:18
submitPVResolutionJobs.config
config
parse the configuration file
Definition: submitPVResolutionJobs.py:281
reco::BeamSpot
Definition: BeamSpot.h:21
ReferenceTrajectoryBase::theGblInput
std::vector< std::pair< std::vector< gbl::GblPoint >, Eigen::MatrixXd > > theGblInput
Definition: ReferenceTrajectoryBase.h:262
TwoBodyDecayTrajectory::propDir_
const PropagationDirection propDir_
Definition: TwoBodyDecayTrajectory.h:49
ReferenceTrajectoryBase::theMeasurementsCov
AlgebraicSymMatrix theMeasurementsCov
Definition: ReferenceTrajectoryBase.h:247
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:112
ReferenceTrajectoryBase::theTrajectoryPositions
AlgebraicVector theTrajectoryPositions
Definition: ReferenceTrajectoryBase.h:249
ReferenceTrajectoryBase::trajectoryPositions
const AlgebraicVector & trajectoryPositions() const
Definition: ReferenceTrajectoryBase.h:155
FastTrackerRecHitMaskProducer_cfi.recHits
recHits
Definition: FastTrackerRecHitMaskProducer_cfi.py:8
TrajectoryStateOnSurface::localParameters
const LocalTrajectoryParameters & localParameters() const
Definition: TrajectoryStateOnSurface.h:73
LocalTrajectoryError
Definition: LocalTrajectoryError.h:20
Error.h
TwoBodyDecayTrajectory::useRefittedState_
const bool useRefittedState_
Definition: TwoBodyDecayTrajectory.h:50
ReferenceTrajectoryBase::nMeasPerHit
static constexpr unsigned int nMeasPerHit
Definition: ReferenceTrajectoryBase.h:269
ReferenceTrajectoryBase::theRecHits
TransientTrackingRecHit::ConstRecHitContainer theRecHits
Definition: ReferenceTrajectoryBase.h:244
TwoBodyDecayParameters
Definition: TwoBodyDecayParameters.h:14
TwoBodyDecayTrajectory::TwoBodyDecayTrajectory
TwoBodyDecayTrajectory(void)
Definition: TwoBodyDecayTrajectory.cc:50
TwoBodyDecayTrajectory::constructTsosVecWithErrors
void constructTsosVecWithErrors(const ReferenceTrajectory &traj1, const ReferenceTrajectory &traj2, const MagneticField *field)
Definition: TwoBodyDecayTrajectory.cc:230
ReferenceTrajectoryBase::gblInput
std::vector< std::pair< std::vector< gbl::GblPoint >, Eigen::MatrixXd > > & gblInput()
Definition: ReferenceTrajectoryBase.h:175
TwoBodyDecayTrajectory::constructTsosWithErrors_
const bool constructTsosWithErrors_
Definition: TwoBodyDecayTrajectory.h:51
TwoBodyDecayTrajectoryState
Definition: TwoBodyDecayTrajectoryState.h:12
riemannFit::MatrixXd
Eigen::MatrixXd MatrixXd
Definition: FitUtils.h:13
GeomDet.h
TwoBodyDecayTrajectoryState::Derivatives
std::pair< AlgebraicMatrix, AlgebraicMatrix > Derivatives
Definition: TwoBodyDecayTrajectoryState.h:15
AlgebraicMatrix
CLHEP::HepMatrix AlgebraicMatrix
Definition: AlgebraicObjects.h:14
RunInfoPI::state
state
Definition: RunInfoPayloadInspectoHelper.h:16
LocalTrajectoryParameters::momentum
LocalVector momentum() const
Momentum vector in the local frame.
Definition: LocalTrajectoryParameters.h:88
ReferenceTrajectory
Definition: ReferenceTrajectory.h:55
TwoBodyDecayTrajectory::materialEffects_
const MaterialEffects materialEffects_
Definition: TwoBodyDecayTrajectory.h:48
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
ReferenceTrajectoryBase::theNumberOfPars
unsigned int theNumberOfPars
Definition: ReferenceTrajectoryBase.h:239
TwoBodyDecayTrajectory::theNumberOfRecHits
std::pair< int, int > theNumberOfRecHits
Definition: TwoBodyDecayTrajectory.h:53
TwoBodyDecayTrajectory.h
TrajectoryStateOnSurface::surface
const SurfaceType & surface() const
Definition: TrajectoryStateOnSurface.h:78
ReferenceTrajectoryBase::localGBL
Definition: ReferenceTrajectoryBase.h:117
ReferenceTrajectoryBase::localToTrajectory
const AlgebraicMatrix & localToTrajectory() const
Definition: ReferenceTrajectoryBase.h:171
ReferenceTrajectoryBase::theTsosVec
std::vector< TrajectoryStateOnSurface > theTsosVec
Definition: ReferenceTrajectoryBase.h:243
ReferenceTrajectoryBase::theGblExtDerivatives
Eigen::MatrixXd theGblExtDerivatives
Definition: ReferenceTrajectoryBase.h:265
MagneticField
Definition: MagneticField.h:19
AlgebraicSymMatrix55
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
Definition: AlgebraicROOTObjects.h:23
TrajectoryStateOnSurface::surfaceSide
SurfaceSide surfaceSide() const
Position relative to material, defined relative to momentum vector.
Definition: TrajectoryStateOnSurface.h:89
ReferenceTrajectoryBase::isValid
bool isValid()
Definition: ReferenceTrajectoryBase.h:142
ReferenceTrajectoryBase::theGblExtMeasurements
Eigen::VectorXd theGblExtMeasurements
Definition: ReferenceTrajectoryBase.h:266
TwoBodyDecayTrajectory::construct
bool construct(const TwoBodyDecayTrajectoryState &state, const ConstRecHitCollection &recHits, const MagneticField *field, const reco::BeamSpot &beamSpot)
Definition: TwoBodyDecayTrajectory.cc:57
ReferenceTrajectoryBase::theValidityFlag
bool theValidityFlag
Definition: ReferenceTrajectoryBase.h:235
ReferenceTrajectoryBase::theNomField
int theNomField
Definition: ReferenceTrajectoryBase.h:263
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37