ATLAS Offline Software
Functions
Trk::MultiComponentStateCombiner Namespace Reference

Functions

std::unique_ptr< Trk::TrackParameterscombineToSingle (const MultiComponentState &, const bool useMode=false)
 @bried Calculate combined state of many components More...
 
void combineWithWeight (Trk::ComponentParameters &mergeTo, const Trk::ComponentParameters &addThis)
 Combined/merge a component to another one. More...
 
void combineParametersWithWeight (AmgVector(5) &firstParameters, double &firstWeight, const AmgVector(5) &secondParameters, const double secondWeight)
 Update parameters. More...
 
void combineCovWithWeight (const AmgVector(5) &firstParameters, AmgSymMatrix(5) &firstMeasuredCov, const double firstWeight, const AmgVector(5) &secondParameters, const AmgSymMatrix(5) &secondMeasuredCov, const double secondWeight)
 Update cov matrix. More...
 
Trk::MultiComponentState combineWithSmoother (const Trk::MultiComponentState &forwardsMultiState, const Trk::MultiComponentState &smootherMultiState, unsigned int maximumNumberOfComponents)
 Helper to combine forward with smoother MultiComponentStates. More...
 

Function Documentation

◆ combineCovWithWeight()

ATH_FLATTEN void Trk::MultiComponentStateCombiner::combineCovWithWeight ( const AmgVector(5) &  firstParameters,
AmgSymMatrix(5) &  firstMeasuredCov,
const double  firstWeight,
const AmgVector(5) &  secondParameters,
const AmgSymMatrix(5) &  secondMeasuredCov,
const double  secondWeight 
)

Update cov matrix.

Definition at line 385 of file MultiComponentStateCombiner.cxx.

392 {
393  double invTotalWeight = 1.0/(firstWeight + secondWeight);
394  AmgVector(5) parameterDifference = firstParameters - secondParameters;
395  parameterDifference[2] = CxxUtils::wrapToPi(parameterDifference[2]);
396  parameterDifference *= invTotalWeight;
397  firstMeasuredCov =
398  (firstWeight * firstMeasuredCov + secondWeight * secondMeasuredCov) *
399  invTotalWeight;
400  firstMeasuredCov += firstWeight * secondWeight * parameterDifference *
401  parameterDifference.transpose();
402 }

◆ combineParametersWithWeight()

ATH_FLATTEN void Trk::MultiComponentStateCombiner::combineParametersWithWeight ( AmgVector(5) &  firstParameters,
double &  firstWeight,
const AmgVector(5) &  secondParameters,
const double  secondWeight 
)

Update parameters.

Moment-preserving merge of two 5D components for example see Runnalls, Andrew R.

(2007) Kullback-Leibler approach to Gaussian mixture reduction equations (2),(3),(4)

Definition at line 358 of file MultiComponentStateCombiner.cxx.

363 {
364  double totalWeight = firstWeight + secondWeight;
365  double invTotalWeight = 1.0/totalWeight;
366  double deltaPhi = firstParameters[2] - secondParameters[2];
367  if (deltaPhi > M_PI) {
368  firstParameters[2] -= 2 * M_PI;
369  } else if (deltaPhi < -M_PI) {
370  firstParameters[2] += 2 * M_PI;
371  }
372  firstParameters =
373  (firstWeight * firstParameters + secondWeight * secondParameters) *
374  invTotalWeight;
375  // Ensure that phi is between -pi and pi
376  firstParameters[2] = CxxUtils::wrapToPi(firstParameters[2]);
377  firstWeight = totalWeight;
378 }

◆ combineToSingle()

std::unique_ptr< Trk::TrackParameters > Trk::MultiComponentStateCombiner::combineToSingle ( const MultiComponentState uncombinedState,
const bool  useMode = false 
)

@bried Calculate combined state of many components

Definition at line 305 of file MultiComponentStateCombiner.cxx.

306  {
307  Trk::ComponentParameters combinedComponent =
308  combineToSingleImpl(uncombinedState, useMode);
309  return std::move(combinedComponent.params);
310 }

◆ combineWithSmoother()

ATH_FLATTEN Trk::MultiComponentState Trk::MultiComponentStateCombiner::combineWithSmoother ( const Trk::MultiComponentState forwardsMultiState,
const Trk::MultiComponentState smootherMultiState,
unsigned int  maximumNumberOfComponents 
)

Helper to combine forward with smoother MultiComponentStates.

Definition at line 409 of file MultiComponentStateCombiner.cxx.

413 {
414 
415  std::unique_ptr<Trk::MultiComponentState> combinedMultiState =
416  std::make_unique<Trk::MultiComponentState>();
417 
418  // Loop over all components in forwards multi-state
419  for (const auto& forwardsComponent : forwardsMultiState) {
420  // Need to check that all components have associated weight matricies
421  const AmgSymMatrix(5)* forwardMeasuredCov =
422  forwardsComponent.params->covariance();
423  // Loop over all components in the smoother multi-state
424  for (const auto& smootherComponent : smootherMultiState) {
425  // Need to check that all components have associated weight matricies
426  const AmgSymMatrix(5)* smootherMeasuredCov =
427  smootherComponent.params->covariance();
428  if (!smootherMeasuredCov && !forwardMeasuredCov) {
429  return {};
430  }
431 
432  if (!forwardMeasuredCov) {
433  Trk::ComponentParameters smootherComponentOnly = {
434  smootherComponent.params->uniqueClone(), smootherComponent.weight};
435  combinedMultiState->push_back(std::move(smootherComponentOnly));
436  continue;
437  }
438 
439  if (!smootherMeasuredCov) {
440  Trk::ComponentParameters forwardComponentOnly = {
441  forwardsComponent.params->uniqueClone(), forwardsComponent.weight};
442  combinedMultiState->push_back(std::move(forwardComponentOnly));
443  continue;
444  }
445 
446  const AmgSymMatrix(5) summedCovariance =
447  *forwardMeasuredCov + *smootherMeasuredCov;
448  const AmgSymMatrix(5) K =
449  *forwardMeasuredCov * summedCovariance.inverse();
450  const AmgVector(5) newParameters =
451  forwardsComponent.params->parameters() +
452  K * (smootherComponent.params->parameters() -
453  forwardsComponent.params->parameters());
454  const AmgVector(5) parametersDiff =
455  forwardsComponent.params->parameters() -
456  smootherComponent.params->parameters();
457 
458  AmgSymMatrix(5) covarianceOfNewParameters =
459  AmgSymMatrix(5)(K * *smootherMeasuredCov);
460 
461  std::unique_ptr<Trk::TrackParameters> combinedTrackParameters =
462  (forwardsComponent.params)
463  ->associatedSurface()
464  .createUniqueTrackParameters(newParameters[Trk::loc1],
465  newParameters[Trk::loc2],
466  newParameters[Trk::phi],
467  newParameters[Trk::theta],
468  newParameters[Trk::qOverP],
469  std::move(covarianceOfNewParameters));
470  const AmgSymMatrix(5) invertedSummedCovariance =
471  summedCovariance.inverse();
472  // Determine the scaling factor for the new weighting. Determined from the
473  // PDF of the many-dimensional gaussian
474  double exponent =
475  parametersDiff.transpose() * invertedSummedCovariance * parametersDiff;
476  double weightScalingFactor = exp(-0.5 * exponent);
477  double combinedWeight = smootherComponent.weight *
478  forwardsComponent.weight * weightScalingFactor;
479  Trk::ComponentParameters combinedComponent = {
480  std::move(combinedTrackParameters), combinedWeight};
481  combinedMultiState->push_back(std::move(combinedComponent));
482  }
483  }
484  // Component reduction on the combined state
485  Trk::MultiComponentState mergedState =
486  merge(std::move(*combinedMultiState), maximumNumberOfComponents);
487  // Before return the weights of the states need to be renormalised to one.
489 
490  return mergedState;
491 }

◆ combineWithWeight()

void Trk::MultiComponentStateCombiner::combineWithWeight ( Trk::ComponentParameters mergeTo,
const Trk::ComponentParameters addThis 
)

Combined/merge a component to another one.

Definition at line 313 of file MultiComponentStateCombiner.cxx.

316 {
317  const Trk::TrackParameters* firstTrackParameters = mergeTo.params.get();
318  const AmgVector(5)& firstParameters = firstTrackParameters->parameters();
319  double firstWeight = mergeTo.weight;
320 
321  const Trk::TrackParameters* secondTrackParameters = addThis.params.get();
322  const AmgVector(5)& secondParameters = secondTrackParameters->parameters();
323  double secondWeight = addThis.weight;
324 
325  // copy over the first
326  AmgVector(5) finalParameters(firstParameters);
327  double finalWeight = firstWeight;
329  finalParameters, finalWeight, secondParameters, secondWeight);
330 
331  const AmgSymMatrix(5)* firstMeasuredCov = firstTrackParameters->covariance();
332  const AmgSymMatrix(5)* secondMeasuredCov = secondTrackParameters->covariance();
333  // Check to see if first track parameters are measured or not
334  if (firstMeasuredCov && secondMeasuredCov) {
335  AmgSymMatrix(5) finalMeasuredCov(*firstMeasuredCov);
336  combineCovWithWeight(firstParameters, finalMeasuredCov, firstWeight,
337  secondParameters, *secondMeasuredCov, secondWeight);
338  mergeTo.params->updateParameters(finalParameters, finalMeasuredCov);
339  mergeTo.weight = finalWeight;
340  } else {
341  mergeTo.params->updateParameters(finalParameters);
342  mergeTo.weight = finalWeight;
343  }
344 }
Trk::ComponentParameters::weight
double weight
Definition: ComponentParameters.h:24
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
xAOD::deltaPhi
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap setEtaBin setIsTgcFailure setDeltaPt deltaPhi
Definition: L2StandAloneMuon_v1.cxx:160
CxxUtils::wrapToPi
T wrapToPi(T phi)
Wrap angle in radians to [-pi, pi].
Definition: phihelper.h:24
theta
Scalar theta() const
theta method
Definition: AmgMatrixBasePlugin.h:75
M_PI
#define M_PI
Definition: ActiveFraction.h:11
Trk::loc2
@ loc2
generic first and second local coordinate
Definition: ParamDefs.h:35
InDetAccessor::qOverP
@ qOverP
perigee
Definition: InDetAccessor.h:35
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
AmgSymMatrix
#define AmgSymMatrix(dim)
Definition: EventPrimitives.h:50
xAOD::TrackParameters
TrackParameters_v1 TrackParameters
Definition: Event/xAOD/xAODTracking/xAODTracking/TrackParameters.h:11
Trk::MultiComponentStateCombiner::combineCovWithWeight
void combineCovWithWeight(const AmgVector(5) &firstParameters, AmgSymMatrix(5) &firstMeasuredCov, const double firstWeight, const AmgVector(5) &secondParameters, const AmgSymMatrix(5) &secondMeasuredCov, const double secondWeight)
Update cov matrix.
Definition: MultiComponentStateCombiner.cxx:385
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
MuonR4::inverse
CalibratedSpacePoint::Covariance_t inverse(const CalibratedSpacePoint::Covariance_t &mat)
Inverts the parsed matrix.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/src/UtilFunctions.cxx:65
AmgVector
AmgVector(4) T2BSTrackFilterTool
Definition: T2BSTrackFilterTool.cxx:114
CxxUtils
Definition: aligned_vector.h:29
Trk::MultiComponentState
std::vector< ComponentParameters > MultiComponentState
Definition: ComponentParameters.h:27
Trk::ParametersBase
Definition: ParametersBase.h:55
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::MultiComponentStateCombiner::combineParametersWithWeight
void combineParametersWithWeight(AmgVector(5) &firstParameters, double &firstWeight, const AmgVector(5) &secondParameters, const double secondWeight)
Update parameters.
Definition: MultiComponentStateCombiner.cxx:358
Trk::MultiComponentStateHelpers::renormaliseState
void renormaliseState(MultiComponentState &, double norm=1)
Performing renormalisation of total state weighting to one.
Definition: ComponentParameters.cxx:80
Trk::ComponentParameters
Definition: ComponentParameters.h:22
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:567
python.utility.LHE.merge
def merge(input_file_pattern, output_file)
Merge many input LHE files into a single output file.
Definition: LHE.py:29
physics_parameters.parameters
parameters
Definition: physics_parameters.py:144
PowhegControl_ttFCNC_NLO.params
params
Definition: PowhegControl_ttFCNC_NLO.py:226
Trk::loc1
@ loc1
Definition: ParamDefs.h:34
Trk::ComponentParameters::params
std::unique_ptr< Trk::TrackParameters > params
Definition: ComponentParameters.h:23