30 std::cout <<
"[SingleTrajectoryUpdator] Use " << theNumberOfPreAlignmentEvts <<
"events for pre-alignment" << std::endl;
43 if ( !( *trajectory ).isValid() )
return;
47 vector< AlignableDetOrUnitPtr > currentAlignableDets = navigator->
alignablesFromHits( ( *trajectory ).recHits() );
56 metrics->
update( currentAlignables );
58 vector< Alignable* > additionalAlignables;
59 if ( includeCorrelations ) additionalAlignables = metrics->
additionalAlignables( currentAlignables );
61 vector< Alignable* > allAlignables;
62 allAlignables.reserve( currentAlignables.size() + additionalAlignables.size() );
63 allAlignables.insert( allAlignables.end(), currentAlignables.begin(), currentAlignables.end() );
64 allAlignables.insert( allAlignables.end(), additionalAlignables.begin(), additionalAlignables.end() );
81 AlgebraicVector referenceTrajectory = trajectory->trajectoryPositions();
88 int checkInversion = 0;
93 if ( trajectory->parameterErrorsAvailable() )
98 measurementCov += externalTrackCov;
100 weightMatrix = fullCov.inverse( checkInversion );
101 if ( checkInversion != 0 )
103 cout <<
"[KalmanAlignment] WARNING: 'AlgebraicSymMatrix fullCov' not invertible." << endl;
110 residuals = allMeasurements - referenceTrajectory - correctionTerm;
115 if ( checkInversion != 0 )
117 cout <<
"[KalmanAlignment] WARNING: 'AlgebraicSymMatrix misalignedCov' not invertible." << endl;
120 AlgebraicSymMatrix weightMatrix1 = ( invMisalignedCov.similarityT( derivatives ) ).inverse( checkInversion );
121 if ( checkInversion != 0 )
123 cout <<
"[KalmanAlignment] WARNING: 'AlgebraicSymMatrix weightMatrix1' not computed." << endl;
126 AlgebraicSymMatrix weightMatrix2 = weightMatrix1.similarity( invMisalignedCov*derivatives );
128 weightMatrix = invMisalignedCov - weightMatrix2;
129 residuals = allMeasurements - referenceTrajectory - correctionTerm;
137 AlgebraicMatrix fullCovTimesDeriv = alignmentCovSubset*alignmentDeriv.T();
139 AlgebraicMatrix covTimesDeriv = currentAlignmentCov*alignmentDeriv.T();
144 AlgebraicVector updatedAlignmentParameters = allAlignmentParameters + fullGainMatrix*residuals;
147 int nCRow = currentAlignmentCov.num_row();
148 int nARow = additionalAlignmentCov.num_row();
154 AlgebraicSymMatrix updatedCurrentAlignmentCov = currentAlignmentCov.similarity( simMat ) + measurementCov.similarity( gainMatrix );
156 AlgebraicMatrix mixedUpdateMat = simMat.T()*simMat.T() + measurementCov.similarity( gTimesDeriv.T() )*currentAlignmentCov;
157 AlgebraicMatrix updatedMixedAlignmentCov = mixedAlignmentCov*mixedUpdateMat;
159 AlgebraicSymMatrix additionalUpdateMat = misalignedCov.similarity( gTimesDeriv.T() ) - 2.*weightMatrix.similarity( alignmentDeriv.T() );
160 AlgebraicSymMatrix updatedAdditionalAlignmentCov = additionalAlignmentCov + additionalUpdateMat.similarity( mixedAlignmentCov );
162 for (
int nRow=0; nRow<nCRow; nRow++ )
164 for (
int nCol=0; nCol<=nRow; nCol++ ) updatedAlignmentCov[nRow][nCol] = updatedCurrentAlignmentCov[nRow][nCol];
167 for (
int nRow=0; nRow<nARow; nRow++ )
169 for (
int nCol=0; nCol<=nRow; nCol++ ) updatedAlignmentCov[nRow+nCRow][nCol+nCRow] = updatedAdditionalAlignmentCov[nRow][nCol];
172 for (
int nRow=0; nRow<nARow; nRow++ )
174 for (
int nCol=0; nCol<nCRow; nCol++ ) updatedAlignmentCov[nRow+nCRow][nCol] = updatedMixedAlignmentCov[nRow][nCol];
180 updatedParameters = alignmentParameters.
clone( updatedAlignmentParameters, updatedAlignmentCov );
184 if ( includeCorrelations )
throw cms::Exception(
"BadCovariance" );
186 delete updatedParameters;
191 delete updatedParameters;
213 for (
int i = 0;
i < cov.num_row(); ++
i )
215 if ( cov[
i][
i] < 0. )
return false;
T getParameter(std::string const &) const
virtual const std::vector< Alignable * > alignablesFromAlignableDets(std::vector< AlignableDetOrUnitPtr > &alignableDets, AlignmentParameterStore *store) const
virtual void process(const ReferenceTrajectoryPtr &trajectory, AlignmentParameterStore *store, AlignableNavigator *navigator, KalmanAlignmentMetricsUpdator *metrics, const MagneticField *magField=0)
Calculate the improved estimate.
void updateUserVariables(const std::vector< Alignable * > &alignables) const
Update the AlignmentUserVariables, given that the Alignables hold KalmanAlignmentUserVariables.
virtual const std::vector< Alignable * > additionalAlignables(const std::vector< Alignable * > &alignables)=0
virtual void update(const std::vector< Alignable * > &alignables)=0
void updateParameters(const CompositeAlignmentParameters &aap, bool updateCorrelations=true)
update parameters
const AlgebraicVector & parameters() const
Get alignment parameters.
unsigned int theNumberOfPreAlignmentEvts
virtual ~SingleTrajectoryUpdator(void)
AlgebraicSymMatrix covarianceSubset(const std::vector< Alignable * > &vec) const
Extract covariance matrix for subset of alignables.
CLHEP::HepMatrix AlgebraicMatrix
Components components() const
Get vector of alignable components.
SingleTrajectoryUpdator(const edm::ParameterSet &config)
bool checkCovariance(const AlgebraicSymMatrix &cov) const
const unsigned int numCorrelations(void) const
get number of correlations between alignables
double theExternalPredictionWeight
unsigned int theNumberOfProcessedEvts
unsigned int nDifferentAlignables(const std::vector< Alignable * > &ali) const
CLHEP::HepVector AlgebraicVector
CompositeAlignmentParameters selectParameters(const std::vector< AlignableDet * > &alignabledets) const
std::vector< AlignableDetOrUnitPtr > alignablesFromHits(const std::vector< const TransientTrackingRecHit * > &hitvec)
Returns vector AlignableDetOrUnitPtr for given vector of Hits.
CLHEP::HepSymMatrix AlgebraicSymMatrix
unsigned int theMinNumberOfHits
#define DEFINE_EDM_PLUGIN(factory, type, name)
static void fillGraph(std::string graph_name, float x_data, float y_data)
CompositeAlignmentParameters * clone(const AlgebraicVector &par, const AlgebraicSymMatrix &cov) const
Clone parameters.