CMS 3D CMS Logo

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