CMS 3D CMS Logo

KalmanAlignmentUserVariables Class Reference

User variables used by the KalmanAlignmentAlgorithm. More...

#include <Alignment/KalmanAlignmentAlgorithm/interface/KalmanAlignmentUserVariables.h>

Inheritance diagram for KalmanAlignmentUserVariables:

AlignmentUserVariables

List of all members.

Public Member Functions

virtual
KalmanAlignmentUserVariables
clone (void) const
void fixAlignable (void)
void histogramParameters (std::string histoNamePrefix)
 Histogram current estimate of the alignment parameters wrt. the true values.
void hit (void)
 Call this function in case the associated Alignable was hit by a particle.
const std::string identifier (void) const
bool isAligned (void) const
 KalmanAlignmentUserVariables (void)
 KalmanAlignmentUserVariables (Alignable *parent, TrackerAlignableId *alignableId=0, int frequency=100)
 Create new user variables by specifying the associated Alignable, the Alignable's Id and how often the evolution of the estimated parameters should be updated.
int numberOfHits (void) const
 Return the number of hits.
int numberOfUpdates (void) const
 Return the number of updates.
void setAlignmentFlag (bool flag)
void unfixAlignable (void)
void update (const AlignmentParameters *param)
 Update user variables with given alignment parameters.
void update (bool enforceUpdate=false)
 Call this function in case the associated Alignable was updated by the alignment algorithm.
virtual ~KalmanAlignmentUserVariables (void)

Protected Member Functions

const AlgebraicVector extractTrueParameters (void) const
const std::string selectedParameter (const int &selected) const
const float selectedScaling (const int &selected) const
const std::string toString (const int &i) const

Protected Attributes

bool theAlignmentFlag
bool theFirstUpdate
std::string theIdentifier
int theNumberOfHits
int theNumberOfUpdates
AlignabletheParentAlignable
std::string theTypeAndLayer
int theUpdateFrequency


Detailed Description

User variables used by the KalmanAlignmentAlgorithm.

The evolution of the estimated alignment parameters is stored in graphs using the DataCollector.

Definition at line 14 of file KalmanAlignmentUserVariables.h.


Constructor & Destructor Documentation

KalmanAlignmentUserVariables::KalmanAlignmentUserVariables ( Alignable parent,
TrackerAlignableId alignableId = 0,
int  frequency = 100 
)

Create new user variables by specifying the associated Alignable, the Alignable's Id and how often the evolution of the estimated parameters should be updated.

Definition at line 11 of file KalmanAlignmentUserVariables.cc.

References Alignable::alignableObjectId(), Alignable::geomDetId(), Alignable::id(), DetId::rawId(), theIdentifier, theTypeAndLayer, toString(), and TrackerAlignableId::typeAndLayerFromDetId().

00013                                                                             :
00014     theParentAlignable( parent ),
00015     theNumberOfHits( 0 ),
00016     theNumberOfUpdates( 0 ),
00017     theUpdateFrequency( frequency ),
00018     theFirstUpdate( true ),
00019     theAlignmentFlag( false )
00020 {
00021   if ( parent && alignableId )
00022   {
00023     pair< int, int > typeAndLayer = alignableId->typeAndLayerFromDetId( parent->id() );
00024 
00025     int iType = typeAndLayer.first;
00026     int iLayer = typeAndLayer.second;
00027     int iId = parent->id();
00028 
00029     string strName = string( "ObjectId" ) + toString( parent->alignableObjectId() ) + string( "_" );
00030     string strType = string( "Type" ) + toString( iType ) + string( "_" );
00031     string strLayer = string( "Layer" ) + toString( iLayer ) + string( "_" );
00032     string strId =  string( "Id" ) + toString( iId );
00033 
00034     theTypeAndLayer = strType + strLayer;
00035     theIdentifier = theTypeAndLayer + strName + strId;
00036   }
00037   else if ( parent )
00038   {
00039     theIdentifier = string( "Alignable_Id" ) + toString( parent->geomDetId().rawId() );
00040   }
00041   else theIdentifier = string( "NoAlignable" );
00042 }

KalmanAlignmentUserVariables::KalmanAlignmentUserVariables ( void   )  [inline]

Definition at line 25 of file KalmanAlignmentUserVariables.h.

Referenced by clone().

00025                                        :
00026     theParentAlignable( 0 ),
00027     theNumberOfHits( 0 ),
00028     theNumberOfUpdates( 0 ),
00029     theUpdateFrequency( 0 ),
00030     theFirstUpdate( false ),
00031     theAlignmentFlag( false )
00032   {}

virtual KalmanAlignmentUserVariables::~KalmanAlignmentUserVariables ( void   )  [inline, virtual]

Definition at line 34 of file KalmanAlignmentUserVariables.h.

00034 {}


Member Function Documentation

virtual KalmanAlignmentUserVariables* KalmanAlignmentUserVariables::clone ( void   )  const [inline, virtual]

Implements AlignmentUserVariables.

Definition at line 36 of file KalmanAlignmentUserVariables.h.

References KalmanAlignmentUserVariables().

00036 { return new KalmanAlignmentUserVariables( *this ); }

const AlgebraicVector KalmanAlignmentUserVariables::extractTrueParameters ( void   )  const [protected]

Definition at line 273 of file KalmanAlignmentUserVariables.cc.

References PV3DBase< T, PVType, FrameType >::basicVector(), Alignable::displacement(), TkRotation< T >::multiplyInverse(), Alignable::rotation(), Alignable::surface(), theParentAlignable, align::toAngles(), AlignableSurface::toLocal(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by update().

00274 {
00275   // get surface of alignable
00276   const AlignableSurface& surface = theParentAlignable->surface();
00277 
00278   // get global rotation
00279   const align::RotationType& globalRotation = theParentAlignable->rotation();
00280   // get local rotation
00281   align::RotationType localRotation = surface.toLocal( globalRotation );
00282   // get euler angles (local frame)
00283   align::EulerAngles localEulerAngles = align::toAngles( localRotation );
00284 
00285   // get global shifts
00286   align::GlobalVector globalShifts( globalRotation.multiplyInverse( theParentAlignable->displacement().basicVector() ) );
00287   // get local shifts
00288   align::LocalVector localShifts = surface.toLocal( globalShifts );
00289 
00290   AlgebraicVector trueParameters( 6 );
00291   trueParameters[0] = -localShifts.x();
00292   trueParameters[1] = -localShifts.y();
00293   trueParameters[2] = -localShifts.z();
00294   trueParameters[3] = -localEulerAngles[0];
00295   trueParameters[4] = -localEulerAngles[1];
00296   trueParameters[5] = -localEulerAngles[2];
00297 
00298 //   // get global rotation
00299 //   const align::RotationType& globalRotation = theParentAlignable->rotation();
00300 //   // get euler angles (global frame)
00301 //   align::EulerAngles globalEulerAngles = align::toAngles( globalRotation );
00302 
00303 //   // get global shifts
00304 //   align::GlobalVector globalShifts( globalRotation.multiplyInverse( theParentAlignable->displacement().basicVector() ) );
00305 
00306 //   AlgebraicVector trueParameters( 6 );
00307 //   trueParameters[0] = -globalShifts.x();
00308 //   trueParameters[1] = -globalShifts.y();
00309 //   trueParameters[2] = -globalShifts.z();
00310 //   trueParameters[3] = -globalEulerAngles[0];
00311 //   trueParameters[4] = -globalEulerAngles[1];
00312 //   trueParameters[5] = -globalEulerAngles[2];
00313 
00314   return trueParameters;
00315 }

void KalmanAlignmentUserVariables::fixAlignable ( void   ) 

Definition at line 255 of file KalmanAlignmentUserVariables.cc.

References Alignable::alignmentParameters(), AlignmentParameters::clone(), AlignmentParameters::covariance(), e, AlignmentParameters::parameters(), Alignable::setAlignmentParameters(), and theParentAlignable.

00256 {
00257   AlignmentParameters* oldParameters = theParentAlignable->alignmentParameters();
00258   AlgebraicSymMatrix fixedCovariance = 1e-6*oldParameters->covariance();
00259   AlignmentParameters* newParameters = oldParameters->clone( oldParameters->parameters(), fixedCovariance );
00260   theParentAlignable->setAlignmentParameters( newParameters );
00261 }

void KalmanAlignmentUserVariables::histogramParameters ( std::string  histoNamePrefix  ) 

Histogram current estimate of the alignment parameters wrt. the true values.

Referenced by KalmanAlignmentAlgorithm::terminate().

void KalmanAlignmentUserVariables::hit ( void   )  [inline]

Call this function in case the associated Alignable was hit by a particle.

Definition at line 41 of file KalmanAlignmentUserVariables.h.

References theNumberOfHits.

00041 { ++theNumberOfHits; }

const std::string KalmanAlignmentUserVariables::identifier ( void   )  const [inline]

Definition at line 52 of file KalmanAlignmentUserVariables.h.

References theIdentifier.

00052 { return theIdentifier; }

bool KalmanAlignmentUserVariables::isAligned ( void   )  const [inline]

Definition at line 55 of file KalmanAlignmentUserVariables.h.

References theAlignmentFlag.

00055 { return theAlignmentFlag; }

int KalmanAlignmentUserVariables::numberOfHits ( void   )  const [inline]

Return the number of hits.

Definition at line 39 of file KalmanAlignmentUserVariables.h.

References theNumberOfHits.

00039 { return theNumberOfHits; }

int KalmanAlignmentUserVariables::numberOfUpdates ( void   )  const [inline]

Return the number of updates.

Definition at line 44 of file KalmanAlignmentUserVariables.h.

References theNumberOfUpdates.

Referenced by KalmanAlignmentAlgorithm::terminate().

00044 { return theNumberOfUpdates; }

const string KalmanAlignmentUserVariables::selectedParameter ( const int selected  )  const [protected]

Definition at line 318 of file KalmanAlignmentUserVariables.cc.

References Exception.

Referenced by update().

00319 {
00320   switch ( selected )
00321   {
00322   case 0:
00323     return string( "X" );
00324     break;
00325   case 1:
00326     return string( "Y" );
00327     break;
00328   case 2:
00329     return string( "Z" );
00330     break;
00331   case 3:
00332     return string( "Alpha" );
00333     break;
00334   case 4:
00335     return string( "Beta" );
00336     break;
00337   case 5:
00338     return string( "Gamma" );
00339     break;
00340   default:
00341     throw cms::Exception( "OutOfRange" ) << "[KalmanAlignmentUserVariables::selectedParameter] "
00342                                          << "Index out of range (selector = " << selected << ")";
00343   }
00344 }

const float KalmanAlignmentUserVariables::selectedScaling ( const int selected  )  const [protected]

Definition at line 347 of file KalmanAlignmentUserVariables.cc.

References GenMuonPlsPt100GeV_cfg::cout, e, and lat::endl().

Referenced by update().

00348 {
00349   const float micron = 1e-4;
00350   const float millirad = 1e-3;
00351   //const float murad = 1e-6;
00352 
00353   switch ( selected )
00354   {
00355   case 0:
00356   case 1:
00357   case 2:
00358     return micron;
00359     break;
00360   case 3:
00361   case 4:
00362   case 5:
00363     return millirad;
00364     //return murad;
00365     break;
00366   default:
00367     cout << "[KalmanAlignmentUserVariables::selectedScaling] Index out of range (selector = " << selected << ")" << endl;
00368     return 1.;
00369     break;
00370   }
00371 
00372   return 1.;
00373 }

void KalmanAlignmentUserVariables::setAlignmentFlag ( bool  flag  )  [inline]

Definition at line 54 of file KalmanAlignmentUserVariables.h.

References theAlignmentFlag.

Referenced by KalmanAlignmentAlgorithm::initializeAlignmentParameters().

00054 { theAlignmentFlag = flag; }

const string KalmanAlignmentUserVariables::toString ( const int i  )  const [protected]

Definition at line 376 of file KalmanAlignmentUserVariables.cc.

References pyDBSRunClass::temp.

Referenced by KalmanAlignmentUserVariables().

00377 {
00378   char temp[10];
00379   sprintf( temp, "%u", i );
00380 
00381   return string( temp );
00382 }

void KalmanAlignmentUserVariables::unfixAlignable ( void   ) 

Definition at line 264 of file KalmanAlignmentUserVariables.cc.

References Alignable::alignmentParameters(), AlignmentParameters::clone(), AlignmentParameters::covariance(), e6, AlignmentParameters::parameters(), Alignable::setAlignmentParameters(), and theParentAlignable.

00265 {
00266   AlignmentParameters* oldParameters = theParentAlignable->alignmentParameters();
00267   AlgebraicSymMatrix fixedCovariance = 1e6*oldParameters->covariance();
00268   AlignmentParameters* newParameters = oldParameters->clone( oldParameters->parameters(), fixedCovariance );
00269   theParentAlignable->setAlignmentParameters( newParameters );
00270 }

void KalmanAlignmentUserVariables::update ( const AlignmentParameters param  ) 

Update user variables with given alignment parameters.

Definition at line 129 of file KalmanAlignmentUserVariables.cc.

References extractTrueParameters(), KalmanAlignmentDataCollector::fillGraph(), i, python::trackProbabilityAnalysis_cff::parameters, AlignmentParameters::selectedCovariance(), selectedParameter(), AlignmentParameters::selectedParameters(), selectedScaling(), AlignmentParameters::selector(), funct::sqrt(), theFirstUpdate, theIdentifier, theNumberOfUpdates, and theParentAlignable.

00130 {
00131   if ( theParentAlignable )
00132   {
00133     ++theNumberOfUpdates;
00134 
00135     const AlgebraicVector& parameters = param->selectedParameters();
00136     const AlgebraicSymMatrix& covariance = param->selectedCovariance();
00137     const vector< bool >& selector = param->selector();
00138 
00139     AlgebraicVector trueParameters( extractTrueParameters() );
00140 
00141     const int nParameter = 6;
00142     int selected = 0;
00143       
00144     for ( int i = 0; i < nParameter; ++i )
00145     {
00146       if ( selector[i] )
00147       {
00148         string parameterId = selectedParameter( i ) + string( "_" ) + theIdentifier;
00149 
00150         KalmanAlignmentDataCollector::fillGraph( string("Delta") + parameterId, theNumberOfUpdates, (parameters[selected]-trueParameters[i])/selectedScaling(i) );
00151         KalmanAlignmentDataCollector::fillGraph( string("Sigma") + parameterId, theNumberOfUpdates, sqrt(covariance[selected][selected])/selectedScaling(i) );
00152 
00153         selected++;
00154       }
00155     }
00156 
00157     if ( theFirstUpdate ) theFirstUpdate = false;
00158   }
00159 }

void KalmanAlignmentUserVariables::update ( bool  enforceUpdate = false  ) 

Call this function in case the associated Alignable was updated by the alignment algorithm.

Definition at line 45 of file KalmanAlignmentUserVariables.cc.

References Alignable::alignmentParameters(), extractTrueParameters(), KalmanAlignmentDataCollector::fillGraph(), i, python::trackProbabilityAnalysis_cff::parameters, AlignmentParameters::selectedCovariance(), selectedParameter(), AlignmentParameters::selectedParameters(), selectedScaling(), AlignmentParameters::selector(), funct::sqrt(), theFirstUpdate, theIdentifier, theNumberOfUpdates, theParentAlignable, and theUpdateFrequency.

Referenced by KalmanAlignmentAlgorithm::initializeAlignmentParameters(), KalmanAlignmentAlgorithm::terminate(), and KalmanAlignmentUpdator::updateUserVariables().

00046 {
00047   if ( theParentAlignable )
00048   {
00049     ++theNumberOfUpdates;
00050 
00051     if ( ( ( theNumberOfUpdates % theUpdateFrequency == 0  ) || enforceUpdate ) )
00052     {
00053       const AlgebraicVector parameters = theParentAlignable->alignmentParameters()->selectedParameters();
00054       const AlgebraicSymMatrix covariance = theParentAlignable->alignmentParameters()->selectedCovariance();
00055       const vector< bool >& selector = theParentAlignable->alignmentParameters()->selector();
00056 
00057       AlgebraicVector trueParameters( extractTrueParameters() );
00058 
00059       const int nParameter = 6;
00060       int selected = 0;
00061       
00062       for ( int i = 0; i < nParameter; ++i )
00063       {
00064         if ( selector[i] )
00065         {
00066           string parameterId = selectedParameter( i ) + string( "_" ) + theIdentifier;
00067 
00068           if ( theFirstUpdate )
00069           {
00070             KalmanAlignmentDataCollector::fillGraph( string("LocalDelta") + parameterId, 0, -trueParameters[i]/selectedScaling(i) );
00071             KalmanAlignmentDataCollector::fillGraph( string("LocalSigma") + parameterId, 0, sqrt(covariance[selected][selected])/selectedScaling(i) );
00072           }
00073 
00074           KalmanAlignmentDataCollector::fillGraph( string("LocalDelta") + parameterId, theNumberOfUpdates, (parameters[selected]-trueParameters[i])/selectedScaling(i) );
00075           KalmanAlignmentDataCollector::fillGraph( string("LocalSigma") + parameterId, theNumberOfUpdates, sqrt(covariance[selected][selected])/selectedScaling(i) );
00076 
00077           selected++;
00078         }
00079       }
00080 
00081       if ( theFirstUpdate ) theFirstUpdate = false;
00082 
00083 //       const AlgebraicVector& parameters = theParentAlignable->alignmentParameters()->parameters();
00084 //       const AlgebraicSymMatrix& covariance = theParentAlignable->alignmentParameters()->covariance();
00085 
00086 //       const AlignableSurface& surface = theParentAlignable->surface();
00087 
00088 //       // Get global euler angles.
00089 //       align::EulerAngles localEulerAngles( parameters.sub( 4, 6 ) );
00090 //       const align::RotationType localRotation = align::toMatrix( localEulerAngles );
00091 //       const align::RotationType globalRotation = surface.toGlobal( localRotation );
00092 //       align::EulerAngles globalEulerAngles = align::toAngles( globalRotation );
00093 
00094 //       // Get global shifts.
00095 //       align::LocalVector localShifts( parameters[0], parameters[1], parameters[2] );
00096 //       align::GlobalVector globalShifts( surface.toGlobal( localShifts ) );
00097 
00098 //       const int nParameter = 6;
00099 //       AlgebraicVector globalParameters( nParameter );
00100 //       globalParameters[0] = globalShifts.x();
00101 //       globalParameters[1] = globalShifts.y();
00102 //       globalParameters[2] = globalShifts.z();
00103 //       globalParameters[3] = globalEulerAngles[0];
00104 //       globalParameters[4] = globalEulerAngles[1];
00105 //       globalParameters[5] = globalEulerAngles[2];
00106 
00107 //       AlgebraicVector trueParameters( extractTrueParameters() );
00108       
00109 //       for ( int i = 0; i < nParameter; ++i )
00110 //       {
00111 //      string parameterId = selectedParameter( i ) + string( "_" ) + theIdentifier;
00112 
00113 //      if ( theFirstUpdate )
00114 //      {
00115 //        KalmanAlignmentDataCollector::fillGraph( string("GlobalDelta") + parameterId, 0, -trueParameters[i]/selectedScaling(i) );
00116 //        KalmanAlignmentDataCollector::fillGraph( string("LocalSigma") + parameterId, 0, sqrt(covariance[i][i])/selectedScaling(i) );
00117 //      }
00118 
00119 //      KalmanAlignmentDataCollector::fillGraph( string("GlobalDelta") + parameterId, theNumberOfUpdates, (globalParameters[i]-trueParameters[i])/selectedScaling(i) );
00120 //      KalmanAlignmentDataCollector::fillGraph( string("LocalSigma") + parameterId, theNumberOfUpdates, sqrt(covariance[i][i])/selectedScaling(i) );
00121 //       }
00122 
00123 //       if ( theFirstUpdate ) theFirstUpdate = false;
00124     }
00125   }
00126 }


Member Data Documentation

bool KalmanAlignmentUserVariables::theAlignmentFlag [protected]

Definition at line 76 of file KalmanAlignmentUserVariables.h.

Referenced by isAligned(), and setAlignmentFlag().

bool KalmanAlignmentUserVariables::theFirstUpdate [protected]

Definition at line 75 of file KalmanAlignmentUserVariables.h.

Referenced by update().

std::string KalmanAlignmentUserVariables::theIdentifier [protected]

Definition at line 78 of file KalmanAlignmentUserVariables.h.

Referenced by identifier(), KalmanAlignmentUserVariables(), and update().

int KalmanAlignmentUserVariables::theNumberOfHits [protected]

Definition at line 71 of file KalmanAlignmentUserVariables.h.

Referenced by hit(), and numberOfHits().

int KalmanAlignmentUserVariables::theNumberOfUpdates [protected]

Definition at line 72 of file KalmanAlignmentUserVariables.h.

Referenced by numberOfUpdates(), and update().

Alignable* KalmanAlignmentUserVariables::theParentAlignable [protected]

Definition at line 69 of file KalmanAlignmentUserVariables.h.

Referenced by extractTrueParameters(), fixAlignable(), unfixAlignable(), and update().

std::string KalmanAlignmentUserVariables::theTypeAndLayer [protected]

Definition at line 79 of file KalmanAlignmentUserVariables.h.

Referenced by KalmanAlignmentUserVariables().

int KalmanAlignmentUserVariables::theUpdateFrequency [protected]

Definition at line 73 of file KalmanAlignmentUserVariables.h.

Referenced by update().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:26:16 2009 for CMSSW by  doxygen 1.5.4