CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
SingleTrajectoryUpdator Class Reference

#include <SingleTrajectoryUpdator.h>

Inheritance diagram for SingleTrajectoryUpdator:
KalmanAlignmentUpdator

Public Member Functions

virtual SingleTrajectoryUpdatorclone (void) const
 
virtual void process (const ReferenceTrajectoryPtr &trajectory, AlignmentParameterStore *store, AlignableNavigator *navigator, KalmanAlignmentMetricsUpdator *metrics, const MagneticField *magField=0)
 Calculate the improved estimate. More...
 
 SingleTrajectoryUpdator (const edm::ParameterSet &config)
 
virtual ~SingleTrajectoryUpdator (void)
 
- Public Member Functions inherited from KalmanAlignmentUpdator
 KalmanAlignmentUpdator (const edm::ParameterSet &config)
 
virtual ~KalmanAlignmentUpdator (void)
 

Private Member Functions

bool checkCovariance (const AlgebraicSymMatrix &cov) const
 

Private Attributes

bool theCovCheckFlag
 
double theExternalPredictionWeight
 
double theExtraWeight
 
unsigned int theMinNumberOfHits
 
unsigned int theNumberOfPreAlignmentEvts
 
unsigned int theNumberOfProcessedEvts
 

Additional Inherited Members

- Public Types inherited from KalmanAlignmentUpdator
typedef
ReferenceTrajectoryBase::ReferenceTrajectoryPtr 
ReferenceTrajectoryPtr
 
- Protected Member Functions inherited from KalmanAlignmentUpdator
virtual const std::vector
< Alignable * > 
alignablesFromAlignableDets (std::vector< AlignableDetOrUnitPtr > &alignableDets, AlignmentParameterStore *store) const
 
unsigned int nDifferentAlignables (const std::vector< Alignable * > &ali) const
 
void updateUserVariables (const std::vector< Alignable * > &alignables) const
 Update the AlignmentUserVariables, given that the Alignables hold KalmanAlignmentUserVariables. More...
 

Detailed Description

Definition at line 15 of file SingleTrajectoryUpdator.h.

Constructor & Destructor Documentation

SingleTrajectoryUpdator::SingleTrajectoryUpdator ( const edm::ParameterSet config)

Definition at line 19 of file SingleTrajectoryUpdator.cc.

References gather_cfg::cout, edm::ParameterSet::getParameter(), theCovCheckFlag, theExternalPredictionWeight, theExtraWeight, theMinNumberOfHits, theNumberOfPreAlignmentEvts, and theNumberOfProcessedEvts.

Referenced by clone().

19  :
20  KalmanAlignmentUpdator( config )
21 {
22  theMinNumberOfHits = config.getParameter< unsigned int >( "MinNumberOfHits" );
23  theExtraWeight = config.getParameter< double >( "ExtraWeight" );
24  theExternalPredictionWeight = config.getParameter< double >( "ExternalPredictionWeight" );
25  theCovCheckFlag = config.getParameter< bool >( "CheckCovariance" );
26 
27  theNumberOfPreAlignmentEvts = config.getParameter< unsigned int >( "NumberOfPreAlignmentEvts" );
29 
30  std::cout << "[SingleTrajectoryUpdator] Use " << theNumberOfPreAlignmentEvts << "events for pre-alignment" << std::endl;
31 }
T getParameter(std::string const &) const
KalmanAlignmentUpdator(const edm::ParameterSet &config)
tuple cout
Definition: gather_cfg.py:121
SingleTrajectoryUpdator::~SingleTrajectoryUpdator ( void  )
virtual

Definition at line 34 of file SingleTrajectoryUpdator.cc.

34 {}

Member Function Documentation

bool SingleTrajectoryUpdator::checkCovariance ( const AlgebraicSymMatrix cov) const
private

Definition at line 211 of file SingleTrajectoryUpdator.cc.

References i.

Referenced by process().

212 {
213  for ( int i = 0; i < cov.num_row(); ++i )
214  {
215  if ( cov[i][i] < 0. ) return false;
216  }
217 
218  return true;
219 }
int i
Definition: DBlmapReader.cc:9
virtual SingleTrajectoryUpdator* SingleTrajectoryUpdator::clone ( void  ) const
inlinevirtual

Implements KalmanAlignmentUpdator.

Definition at line 30 of file SingleTrajectoryUpdator.h.

References SingleTrajectoryUpdator().

30 { return new SingleTrajectoryUpdator( *this ); }
SingleTrajectoryUpdator(const edm::ParameterSet &config)
void SingleTrajectoryUpdator::process ( const ReferenceTrajectoryPtr trajectory,
AlignmentParameterStore store,
AlignableNavigator navigator,
KalmanAlignmentMetricsUpdator metrics,
const MagneticField magField = 0 
)
virtual

Calculate the improved estimate.

Implements KalmanAlignmentUpdator.

Definition at line 37 of file SingleTrajectoryUpdator.cc.

References KalmanAlignmentMetricsUpdator::additionalAlignables(), KalmanAlignmentUpdator::alignablesFromAlignableDets(), AlignableNavigator::alignablesFromHits(), checkCovariance(), CompositeAlignmentParameters::clone(), CompositeAlignmentParameters::components(), CompositeAlignmentDerivativesExtractor::correctionTerm(), gather_cfg::cout, CompositeAlignmentParameters::covarianceSubset(), Exception, KalmanAlignmentDataCollector::fillGraph(), i, KalmanAlignmentUpdator::nDifferentAlignables(), AlignmentParameterStore::numCorrelations(), CompositeAlignmentParameters::parameters(), AlignmentParameterStore::selectParameters(), theExternalPredictionWeight, theExtraWeight, theMinNumberOfHits, theNumberOfPreAlignmentEvts, theNumberOfProcessedEvts, KalmanAlignmentMetricsUpdator::update(), AlignmentParameterStore::updateParameters(), and KalmanAlignmentUpdator::updateUserVariables().

Referenced by ConfigBuilder.ConfigBuilder::addExtraStream(), ConfigBuilder.ConfigBuilder::completeInputCommand(), ConfigBuilder.ConfigBuilder::doNotInlineEventContent(), Vispa.Plugins.ConfigEditor.ConfigDataAccessor.ConfigDataAccessor::dumpPython(), ConfigBuilder.ConfigBuilder.PrintAllModules::leave(), Vispa.Plugins.ConfigEditor.ConfigDataAccessor.ConfigDataAccessor::open(), Vispa.Plugins.ConfigEditor.ConfigDataAccessor.ConfigDataAccessor::outputEventContent(), ConfigBuilder.ConfigBuilder::prepare_HLT(), ConfigBuilder.ConfigBuilder::prepare_LHE(), ConfigBuilder.ConfigBuilder::prepare_PATFILTER(), ConfigBuilder.ConfigBuilder::prepare_VALIDATION(), ConfigBuilder.ConfigBuilder::renameHLTprocessInSequence(), ConfigBuilder.ConfigBuilder::renameInputTagsInSequence(), ConfigBuilder.ConfigBuilder::scheduleSequence(), Vispa.Plugins.ConfigEditor.ConfigDataAccessor.ConfigDataAccessor::setProcess(), and Vispa.Plugins.ConfigEditor.ConfigDataAccessor.ConfigDataAccessor::setProperty().

42 {
43  if ( !( *trajectory ).isValid() ) return;
44 
45 // std::cout << "[SingleTrajectoryUpdator::process] START" << std::endl;
46 
47  vector< AlignableDetOrUnitPtr > currentAlignableDets = navigator->alignablesFromHits( ( *trajectory ).recHits() );
48  vector< Alignable* > currentAlignables = alignablesFromAlignableDets( currentAlignableDets, store );
49 
50  if ( nDifferentAlignables( currentAlignables ) < 2 ) return;
51  if ( currentAlignables.size() < theMinNumberOfHits ) return;
52 
54  bool includeCorrelations = ( theNumberOfPreAlignmentEvts < theNumberOfProcessedEvts );
55 
56  metrics->update( currentAlignables );
57 
58  vector< Alignable* > additionalAlignables;
59  if ( includeCorrelations ) additionalAlignables = metrics->additionalAlignables( currentAlignables );
60 
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() );
65 
66  CompositeAlignmentParameters alignmentParameters = store->selectParameters( allAlignables );
67 
68  const AlgebraicVector& allAlignmentParameters = alignmentParameters.parameters();
69  AlgebraicSymMatrix currentAlignmentCov = alignmentParameters.covarianceSubset( currentAlignables );
70  AlgebraicSymMatrix additionalAlignmentCov = alignmentParameters.covarianceSubset( additionalAlignables );
71  AlgebraicMatrix mixedAlignmentCov = alignmentParameters.covarianceSubset( additionalAlignables, currentAlignables );
72  AlgebraicMatrix alignmentCovSubset = alignmentParameters.covarianceSubset( alignmentParameters.components(), currentAlignables );
73 
74  CompositeAlignmentDerivativesExtractor extractor( currentAlignables, currentAlignableDets, trajectory->trajectoryStates() );
75  AlgebraicVector correctionTerm = extractor.correctionTerm();
76  AlgebraicMatrix alignmentDeriv = extractor.derivatives();
77  AlgebraicSymMatrix alignmentCov = currentAlignmentCov.similarity( alignmentDeriv );
78 
79  AlgebraicVector allMeasurements = trajectory->measurements();
80  AlgebraicSymMatrix measurementCov = trajectory->measurementErrors();
81  AlgebraicVector referenceTrajectory = trajectory->trajectoryPositions();
82  AlgebraicMatrix derivatives = trajectory->derivatives();
83 
84  measurementCov += theExtraWeight*AlgebraicSymMatrix( measurementCov.num_row(), 1 );
85 
86  AlgebraicSymMatrix misalignedCov = measurementCov + alignmentCov;
87 
88  int checkInversion = 0;
89 
90  AlgebraicSymMatrix weightMatrix;
91  AlgebraicVector residuals;
92 
93  if ( trajectory->parameterErrorsAvailable() ) // Make an update using an external prediction for the track parameters.
94  {
95  const AlgebraicSymMatrix& externalParamCov = trajectory->parameterErrors();
96  AlgebraicSymMatrix externalTrackCov = theExternalPredictionWeight*externalParamCov.similarity( derivatives );
97  AlgebraicSymMatrix fullCov = misalignedCov + externalTrackCov;
98  measurementCov += externalTrackCov;
99 
100  weightMatrix = fullCov.inverse( checkInversion );
101  if ( checkInversion != 0 )
102  {
103  cout << "[KalmanAlignment] WARNING: 'AlgebraicSymMatrix fullCov' not invertible." << endl;
104  return;
105  }
106 
107  //const AlgebraicVector& trackParameters = trajectory->parameters();
108  //const AlgebraicVector& externalTrackParameters = trajectory->externalPrediction();
109  //AlgebraicVector trackCorrectionTerm = derivatives*( externalTrackParameters - trackParameters );
110  residuals = allMeasurements - referenceTrajectory - correctionTerm;// - trackCorrectionTerm;
111  }
112  else // No external prediction for the track parameters available --> give the track parameters weight 0.
113  {
114  AlgebraicSymMatrix invMisalignedCov = misalignedCov.inverse( checkInversion );
115  if ( checkInversion != 0 )
116  {
117  cout << "[KalmanAlignment] WARNING: 'AlgebraicSymMatrix misalignedCov' not invertible." << endl;
118  return;
119  }
120  AlgebraicSymMatrix weightMatrix1 = ( invMisalignedCov.similarityT( derivatives ) ).inverse( checkInversion );
121  if ( checkInversion != 0 )
122  {
123  cout << "[KalmanAlignment] WARNING: 'AlgebraicSymMatrix weightMatrix1' not computed." << endl;
124  return;
125  }
126  AlgebraicSymMatrix weightMatrix2 = weightMatrix1.similarity( invMisalignedCov*derivatives );
127 
128  weightMatrix = invMisalignedCov - weightMatrix2;
129  residuals = allMeasurements - referenceTrajectory - correctionTerm;
130  }
131 
132 // AlgebraicVector deltaR = allMeasurements - referenceTrajectory;
133 // for ( int i = 0; i < deltaR.num_row()/2; ++i )
134 // KalmanAlignmentDataCollector::fillHistogram( "DeltaR_", i, deltaR[2*i] );
135 // return;
136 
137  AlgebraicMatrix fullCovTimesDeriv = alignmentCovSubset*alignmentDeriv.T();
138  AlgebraicMatrix fullGainMatrix = fullCovTimesDeriv*weightMatrix;
139  AlgebraicMatrix covTimesDeriv = currentAlignmentCov*alignmentDeriv.T();
140  AlgebraicMatrix gainMatrix = covTimesDeriv*weightMatrix;
141 
142  // make updates for the kalman-filter
143  // update of parameters
144  AlgebraicVector updatedAlignmentParameters = allAlignmentParameters + fullGainMatrix*residuals;
145 
146  // update of covariance
147  int nCRow = currentAlignmentCov.num_row();
148  int nARow = additionalAlignmentCov.num_row();
149 
150  AlgebraicSymMatrix updatedAlignmentCov( nCRow + nARow );
151 
152  AlgebraicMatrix gTimesDeriv = weightMatrix*alignmentDeriv;
153  AlgebraicMatrix simMat = AlgebraicMatrix( nCRow, nCRow, 1 ) - covTimesDeriv*gTimesDeriv;
154  AlgebraicSymMatrix updatedCurrentAlignmentCov = currentAlignmentCov.similarity( simMat ) + measurementCov.similarity( gainMatrix );
155 
156  AlgebraicMatrix mixedUpdateMat = simMat.T()*simMat.T() + measurementCov.similarity( gTimesDeriv.T() )*currentAlignmentCov;
157  AlgebraicMatrix updatedMixedAlignmentCov = mixedAlignmentCov*mixedUpdateMat;
158 
159  AlgebraicSymMatrix additionalUpdateMat = misalignedCov.similarity( gTimesDeriv.T() ) - 2.*weightMatrix.similarity( alignmentDeriv.T() );
160  AlgebraicSymMatrix updatedAdditionalAlignmentCov = additionalAlignmentCov + additionalUpdateMat.similarity( mixedAlignmentCov );
161 
162  for ( int nRow=0; nRow<nCRow; nRow++ )
163  {
164  for ( int nCol=0; nCol<=nRow; nCol++ ) updatedAlignmentCov[nRow][nCol] = updatedCurrentAlignmentCov[nRow][nCol];
165  }
166 
167  for ( int nRow=0; nRow<nARow; nRow++ )
168  {
169  for ( int nCol=0; nCol<=nRow; nCol++ ) updatedAlignmentCov[nRow+nCRow][nCol+nCRow] = updatedAdditionalAlignmentCov[nRow][nCol];
170  }
171 
172  for ( int nRow=0; nRow<nARow; nRow++ )
173  {
174  for ( int nCol=0; nCol<nCRow; nCol++ ) updatedAlignmentCov[nRow+nCRow][nCol] = updatedMixedAlignmentCov[nRow][nCol];
175  }
176 
177 
178  // update in alignment-interface
179  CompositeAlignmentParameters* updatedParameters;
180  updatedParameters = alignmentParameters.clone( updatedAlignmentParameters, updatedAlignmentCov );
181 
182  if ( !checkCovariance( updatedAlignmentCov ) )
183  {
184  if ( includeCorrelations ) throw cms::Exception( "BadCovariance" );
185 
186  delete updatedParameters;
187  return;
188  }
189 
190  store->updateParameters( *updatedParameters, includeCorrelations );
191  delete updatedParameters;
192 
193 
194  // update user variables for debugging
195  //updateUserVariables( alignmentParameters.components() );
196 
197  //std::cout << "update user variables now" << std::endl;
198  updateUserVariables( currentAlignables );
199  //std::cout << "done." << std::endl;
200 
201  static int i = 0;
202  if ( i%100 == 0 ) KalmanAlignmentDataCollector::fillGraph( "correlation_entries", i, store->numCorrelations() );
203  ++i;
204 
205  //std::cout << "[SingleTrajectoryUpdator::process] DONE" << std::endl;
206 
207  return;
208 }
virtual const std::vector< Alignable * > alignablesFromAlignableDets(std::vector< AlignableDetOrUnitPtr > &alignableDets, AlignmentParameterStore *store) const
int i
Definition: DBlmapReader.cc:9
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.
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.
bool checkCovariance(const AlgebraicSymMatrix &cov) const
const unsigned int numCorrelations(void) const
get number of correlations between alignables
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
tuple cout
Definition: gather_cfg.py:121
static void fillGraph(std::string graph_name, float x_data, float y_data)
CompositeAlignmentParameters * clone(const AlgebraicVector &par, const AlgebraicSymMatrix &cov) const
Clone parameters.

Member Data Documentation

bool SingleTrajectoryUpdator::theCovCheckFlag
private

Definition at line 39 of file SingleTrajectoryUpdator.h.

Referenced by SingleTrajectoryUpdator().

double SingleTrajectoryUpdator::theExternalPredictionWeight
private

Definition at line 38 of file SingleTrajectoryUpdator.h.

Referenced by process(), and SingleTrajectoryUpdator().

double SingleTrajectoryUpdator::theExtraWeight
private

Definition at line 37 of file SingleTrajectoryUpdator.h.

Referenced by process(), and SingleTrajectoryUpdator().

unsigned int SingleTrajectoryUpdator::theMinNumberOfHits
private

Definition at line 36 of file SingleTrajectoryUpdator.h.

Referenced by process(), and SingleTrajectoryUpdator().

unsigned int SingleTrajectoryUpdator::theNumberOfPreAlignmentEvts
private

Definition at line 41 of file SingleTrajectoryUpdator.h.

Referenced by process(), and SingleTrajectoryUpdator().

unsigned int SingleTrajectoryUpdator::theNumberOfProcessedEvts
private

Definition at line 42 of file SingleTrajectoryUpdator.h.

Referenced by process(), and SingleTrajectoryUpdator().