CMS 3D CMS Logo

Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes

KalmanAlignmentUserVariables Class Reference

#include <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, const TrackerTopology *tTopo, int frequency=100)
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 (bool enforceUpdate=false)
 Call this function in case the associated Alignable was updated by the alignment algorithm.
void update (const AlignmentParameters *param)
 Update user variables with given alignment parameters.
virtual ~KalmanAlignmentUserVariables (void)

Protected Member Functions

const AlgebraicVector extractTrueParameters (void) const
const std::string selectedParameter (const int &selected) 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

Static Protected Attributes

static const TrackerAlignableIdtheAlignableId = new TrackerAlignableId
static const AlignableObjectIdtheObjectId

Detailed Description

Definition at line 17 of file KalmanAlignmentUserVariables.h.


Constructor & Destructor Documentation

KalmanAlignmentUserVariables::KalmanAlignmentUserVariables ( Alignable parent,
const TrackerTopology tTopo,
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 19 of file KalmanAlignmentUserVariables.cc.

References Alignable::alignableObjectId(), Alignable::geomDetId(), Alignable::id(), AlignableObjectId::idToString(), AlCaHLTBitMon_QueryRunRegistry::string, theAlignableId, theIdentifier, theTypeAndLayer, toString(), and TrackerAlignableId::typeAndLayerFromDetId().

                                                                            :
    theParentAlignable( parent ),
    theNumberOfHits( 0 ),
    theNumberOfUpdates( 0 ),
    theUpdateFrequency( frequency ),
    theFirstUpdate( true ),
    theAlignmentFlag( false )
{
  if ( parent )
  {
    pair< int, int > typeAndLayer = theAlignableId->typeAndLayerFromDetId( parent->geomDetId(), tTopo );

    int iType = typeAndLayer.first;
    int iLayer = typeAndLayer.second;
    int iId = parent->id();

    string strName = AlignableObjectId::idToString( parent->alignableObjectId() ) + string( "_" );
    string strType = string( "Type" ) + toString( iType ) + string( "_" );
    string strLayer = string( "Layer" ) + toString( iLayer ) + string( "_" );
    string strId =  string( "Id" ) + toString( iId );

    theTypeAndLayer = strType + strLayer;
    theIdentifier = theTypeAndLayer + strName + strId;
    
  }
  else theIdentifier = string( "NoAlignable" );
}
KalmanAlignmentUserVariables::KalmanAlignmentUserVariables ( void  ) [inline]

Definition at line 28 of file KalmanAlignmentUserVariables.h.

Referenced by clone().

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

Definition at line 37 of file KalmanAlignmentUserVariables.h.

{}

Member Function Documentation

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

Implements AlignmentUserVariables.

Definition at line 39 of file KalmanAlignmentUserVariables.h.

References KalmanAlignmentUserVariables().

{ return new KalmanAlignmentUserVariables( *this ); }
const AlgebraicVector KalmanAlignmentUserVariables::extractTrueParameters ( void  ) const [protected]

Definition at line 298 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 histogramParameters(), and update().

{

#ifdef USE_LOCAL_PARAMETERS

  // get surface of alignable
  const AlignableSurface& surface = theParentAlignable->surface();

  // get global rotation
  const align::RotationType& globalRotation = theParentAlignable->rotation();
  // get local rotation
  align::RotationType localRotation = surface.toLocal( globalRotation );
  // get euler angles (local frame)
  align::EulerAngles localEulerAngles = align::toAngles( localRotation );

  // get global shifts
  align::GlobalVector globalShifts( globalRotation.multiplyInverse( theParentAlignable->displacement().basicVector() ) );
  // get local shifts
  align::LocalVector localShifts = surface.toLocal( globalShifts );

  AlgebraicVector trueParameters( 6 );
  trueParameters[0] = -localShifts.x();
  trueParameters[1] = -localShifts.y();
  trueParameters[2] = -localShifts.z();
  trueParameters[3] = -localEulerAngles[0];
  trueParameters[4] = -localEulerAngles[1];
  trueParameters[5] = -localEulerAngles[2];

#else

  // get global rotation
  const align::RotationType& globalRotation = theParentAlignable->rotation();
  // get euler angles (global frame)
  align::EulerAngles globalEulerAngles = align::toAngles( globalRotation );

  // get global shifts
  align::GlobalVector globalShifts( globalRotation.multiplyInverse( theParentAlignable->displacement().basicVector() ) );

  AlgebraicVector trueParameters( 6 );
  trueParameters[0] = -globalShifts.x();
  trueParameters[1] = -globalShifts.y();
  trueParameters[2] = -globalShifts.z();
  trueParameters[3] = -globalEulerAngles[0];
  trueParameters[4] = -globalEulerAngles[1];
  trueParameters[5] = -globalEulerAngles[2];

#endif

  return trueParameters;
}
void KalmanAlignmentUserVariables::fixAlignable ( void  )
void KalmanAlignmentUserVariables::histogramParameters ( std::string  histoNamePrefix)

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

Definition at line 178 of file KalmanAlignmentUserVariables.cc.

References Alignable::alignmentParameters(), extractTrueParameters(), KalmanAlignmentDataCollector::fillGraph(), KalmanAlignmentDataCollector::fillHistogram(), Alignable::globalPosition(), i, AlignmentParameters::parameters(), Parameters::parameters, AlignmentParameters::selectedCovariance(), selectedParameter(), AlignmentParameters::selectedParameters(), selectedScaling(), AlignmentParameters::selector(), mathSSE::sqrt(), AlCaHLTBitMon_QueryRunRegistry::string, Alignable::surface(), theParentAlignable, theTypeAndLayer, align::toAngles(), AlignableSurface::toGlobal(), and align::toMatrix().

Referenced by KalmanAlignmentAlgorithm::terminate().

{
  if ( theParentAlignable )
  {

#ifdef USE_LOCAL_PARAMETERS

    AlgebraicVector parameters = theParentAlignable->alignmentParameters()->selectedParameters();
    AlgebraicSymMatrix covariance = theParentAlignable->alignmentParameters()->selectedCovariance();
    vector< bool > selector = theParentAlignable->alignmentParameters()->selector();

    AlgebraicVector trueParameters = extractTrueParameters();

    const int nParameter = 6;
    int selected = 0;

    //histoNamePrefix += theTypeAndLayer;
      
    for ( int i = 0; i < nParameter; ++i )
    {
      if ( selector[i] )
      {
        string startHistoName = histoNamePrefix + theTypeAndLayer + string( "_Start" ) + selectedParameter( i );
        KalmanAlignmentDataCollector::fillHistogram( startHistoName, -trueParameters[i]/selectedScaling(i) );

        string deltaHistoName = histoNamePrefix + theTypeAndLayer + string( "_Delta" ) + selectedParameter( i );
        KalmanAlignmentDataCollector::fillHistogram( deltaHistoName, (parameters[selected]-trueParameters[i])/selectedScaling(i) );

        string pullsHistoName = histoNamePrefix + theTypeAndLayer + string( "_Pulls" ) + selectedParameter( i );
        KalmanAlignmentDataCollector::fillHistogram( pullsHistoName, (parameters[selected]-trueParameters[i])/sqrt(covariance[selected][selected]) );

        startHistoName = histoNamePrefix + string( "_Start" ) + selectedParameter( i );
        KalmanAlignmentDataCollector::fillHistogram( startHistoName, -trueParameters[i]/selectedScaling(i) );

        deltaHistoName = histoNamePrefix + string( "_Delta" ) + selectedParameter( i );
        KalmanAlignmentDataCollector::fillHistogram( deltaHistoName, (parameters[selected]-trueParameters[i])/selectedScaling(i) );

        pullsHistoName = histoNamePrefix + string( "_Pulls" ) + selectedParameter( i );
        KalmanAlignmentDataCollector::fillHistogram( pullsHistoName, (parameters[selected]-trueParameters[i])/sqrt(covariance[selected][selected]) );

        selected++;
      }
    }

#else

    const AlgebraicVector& parameters = theParentAlignable->alignmentParameters()->parameters();

    const AlignableSurface& surface = theParentAlignable->surface();

    // Get global euler angles.
    align::EulerAngles localEulerAngles( parameters.sub( 4, 6 ) );
    const align::RotationType localRotation = align::toMatrix( localEulerAngles );
    const align::RotationType globalRotation = surface.toGlobal( localRotation );
    align::EulerAngles globalEulerAngles = align::toAngles( globalRotation );

    // Get global shifts.
    align::LocalVector localShifts( parameters[0], parameters[1], parameters[2] );
    align::GlobalVector globalShifts( surface.toGlobal( localShifts ) );

    const int nParameter = 6;
    AlgebraicVector globalParameters( nParameter );
    globalParameters[0] = globalShifts.x();
    globalParameters[1] = globalShifts.y();
    globalParameters[2] = globalShifts.z();
    globalParameters[3] = globalEulerAngles[0];
    globalParameters[4] = globalEulerAngles[1];
    globalParameters[5] = globalEulerAngles[2];

    AlgebraicVector trueParameters( extractTrueParameters() );

    KalmanAlignmentDataCollector::fillGraph( "y_vs_dx", theParentAlignable->globalPosition().y(), trueParameters[0]-globalParameters[0] );
    KalmanAlignmentDataCollector::fillGraph( "r_vs_dx", theParentAlignable->globalPosition().perp(), trueParameters[0]-globalParameters[0] );
    KalmanAlignmentDataCollector::fillGraph( "y_vs_dx_true", theParentAlignable->globalPosition().y(), trueParameters[0] );
      
    for ( int i = 0; i < nParameter; ++i )
    {
      string startHistoName = histoNamePrefix + string( "_Start" ) + selectedParameter( i );
      KalmanAlignmentDataCollector::fillHistogram( startHistoName, -trueParameters[i]/selectedScaling(i) );

      string deltaHistoName = histoNamePrefix + string( "_Delta" ) + selectedParameter( i );
      KalmanAlignmentDataCollector::fillHistogram( deltaHistoName, (globalParameters[i]-trueParameters[i])/selectedScaling(i) );

      string valueHistoName = histoNamePrefix + string( "_Value" ) + selectedParameter( i );
      KalmanAlignmentDataCollector::fillHistogram( valueHistoName, globalParameters[i]/selectedScaling(i) );

      startHistoName = histoNamePrefix + theTypeAndLayer + string( "_Start" ) + selectedParameter( i );
      KalmanAlignmentDataCollector::fillHistogram( startHistoName, -trueParameters[i]/selectedScaling(i) );

      deltaHistoName = histoNamePrefix + theTypeAndLayer + string( "_Delta" ) + selectedParameter( i );
      KalmanAlignmentDataCollector::fillHistogram( deltaHistoName, (globalParameters[i]-trueParameters[i])/selectedScaling(i) );

      valueHistoName = histoNamePrefix + theTypeAndLayer + string( "_Value" ) + selectedParameter( i );
      KalmanAlignmentDataCollector::fillHistogram( valueHistoName, globalParameters[i]/selectedScaling(i) );
    }

#endif

  }
}
void KalmanAlignmentUserVariables::hit ( void  ) [inline]

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

Definition at line 44 of file KalmanAlignmentUserVariables.h.

References theNumberOfHits.

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

Definition at line 55 of file KalmanAlignmentUserVariables.h.

References theIdentifier.

{ return theIdentifier; }
bool KalmanAlignmentUserVariables::isAligned ( void  ) const [inline]

Definition at line 58 of file KalmanAlignmentUserVariables.h.

References theAlignmentFlag.

{ return theAlignmentFlag; }
int KalmanAlignmentUserVariables::numberOfHits ( void  ) const [inline]

Return the number of hits.

Definition at line 42 of file KalmanAlignmentUserVariables.h.

References theNumberOfHits.

{ return theNumberOfHits; }
int KalmanAlignmentUserVariables::numberOfUpdates ( void  ) const [inline]

Return the number of updates.

Definition at line 47 of file KalmanAlignmentUserVariables.h.

References theNumberOfUpdates.

Referenced by KalmanAlignmentAlgorithm::terminate().

{ return theNumberOfUpdates; }
const string KalmanAlignmentUserVariables::selectedParameter ( const int &  selected) const [protected]

Definition at line 350 of file KalmanAlignmentUserVariables.cc.

References Exception, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by histogramParameters(), and update().

{
  switch ( selected )
  {
  case 0:
    return string( "X" );
    break;
  case 1:
    return string( "Y" );
    break;
  case 2:
    return string( "Z" );
    break;
  case 3:
    return string( "Alpha" );
    break;
  case 4:
    return string( "Beta" );
    break;
  case 5:
    return string( "Gamma" );
    break;
  default:
    throw cms::Exception( "OutOfRange" ) << "[KalmanAlignmentUserVariables::selectedParameter] "
                                         << "Index out of range (selector = " << selected << ")";
  }
}
float KalmanAlignmentUserVariables::selectedScaling ( const int &  selected) const [protected]

Definition at line 379 of file KalmanAlignmentUserVariables.cc.

References alignCSCRings::e, and Exception.

Referenced by histogramParameters(), and update().

{
  const float micron = 1e-4;
  const float millirad = 1e-3;
  //const float murad = 1e-6;

  switch ( selected )
  {
  case 0:
  case 1:
  case 2:
    return micron;
    break;
  case 3:
  case 4:
  case 5:
    return millirad;
    //return murad;
    break;
  default:
    throw cms::Exception( "LogicError" ) << "@SUB=KalmanAlignmentUserVariables::selectedScaling"
                                         << "Index out of range (selector = " << selected << ")\n";
  }
}
void KalmanAlignmentUserVariables::setAlignmentFlag ( bool  flag) [inline]
const string KalmanAlignmentUserVariables::toString ( const int &  i) const [protected]

Definition at line 405 of file KalmanAlignmentUserVariables.cc.

References AlCaHLTBitMon_QueryRunRegistry::string, and groupFilesInBlocks::temp.

Referenced by KalmanAlignmentUserVariables().

{
  char temp[10];
  snprintf( temp, sizeof(temp), "%u", i );

  return string( temp );
}
void KalmanAlignmentUserVariables::unfixAlignable ( void  )
void KalmanAlignmentUserVariables::update ( bool  enforceUpdate = false)

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

Definition at line 53 of file KalmanAlignmentUserVariables.cc.

References Alignable::alignmentParameters(), AlignmentParameters::covariance(), extractTrueParameters(), KalmanAlignmentDataCollector::fillGraph(), i, AlignmentParameters::parameters(), Parameters::parameters, AlignmentParameters::selectedCovariance(), selectedParameter(), AlignmentParameters::selectedParameters(), selectedScaling(), AlignmentParameters::selector(), mathSSE::sqrt(), AlCaHLTBitMon_QueryRunRegistry::string, Alignable::surface(), theFirstUpdate, theIdentifier, theNumberOfUpdates, theParentAlignable, theUpdateFrequency, align::toAngles(), AlignableSurface::toGlobal(), and align::toMatrix().

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

{
  if ( theParentAlignable )
  {
    ++theNumberOfUpdates;

    if ( ( ( theNumberOfUpdates % theUpdateFrequency == 0  ) || enforceUpdate ) )
    {

#ifdef USE_LOCAL_PARAMETERS

      const AlgebraicVector parameters = theParentAlignable->alignmentParameters()->selectedParameters();
      const AlgebraicSymMatrix covariance = theParentAlignable->alignmentParameters()->selectedCovariance();
      const vector< bool >& selector = theParentAlignable->alignmentParameters()->selector();

      AlgebraicVector trueParameters( extractTrueParameters() );

      const int nParameter = 6;
      int selected = 0;
      
      for ( int i = 0; i < nParameter; ++i )
      {
        if ( selector[i] )
        {
          string parameterId = selectedParameter( i ) + string( "_" ) + theIdentifier;

          if ( theFirstUpdate )
          {
            KalmanAlignmentDataCollector::fillGraph( string("LocalDelta") + parameterId, 0, -trueParameters[i]/selectedScaling(i) );
            KalmanAlignmentDataCollector::fillGraph( string("LocalSigma") + parameterId, 0, sqrt(covariance[selected][selected])/selectedScaling(i) );
          }

          KalmanAlignmentDataCollector::fillGraph( string("LocalDelta") + parameterId, theNumberOfUpdates/theUpdateFrequency, (parameters[selected]-trueParameters[i])/selectedScaling(i) );
          KalmanAlignmentDataCollector::fillGraph( string("LocalSigma") + parameterId, theNumberOfUpdates/theUpdateFrequency, sqrt(covariance[selected][selected])/selectedScaling(i) );

          selected++;
        }
      }

      if ( theFirstUpdate ) theFirstUpdate = false;

#else

      const AlgebraicVector& parameters = theParentAlignable->alignmentParameters()->parameters();
      const AlgebraicSymMatrix& covariance = theParentAlignable->alignmentParameters()->covariance();

      const AlignableSurface& surface = theParentAlignable->surface();

      // Get global euler angles.
      align::EulerAngles localEulerAngles( parameters.sub( 4, 6 ) );
      const align::RotationType localRotation = align::toMatrix( localEulerAngles );
      const align::RotationType globalRotation = surface.toGlobal( localRotation );
      align::EulerAngles globalEulerAngles = align::toAngles( globalRotation );

      // Get global shifts.
      align::LocalVector localShifts( parameters[0], parameters[1], parameters[2] );
      align::GlobalVector globalShifts( surface.toGlobal( localShifts ) );

      const int nParameter = 6;
      AlgebraicVector globalParameters( nParameter );
      globalParameters[0] = globalShifts.x();
      globalParameters[1] = globalShifts.y();
      globalParameters[2] = globalShifts.z();
      globalParameters[3] = globalEulerAngles[0];
      globalParameters[4] = globalEulerAngles[1];
      globalParameters[5] = globalEulerAngles[2];

      AlgebraicVector trueParameters( extractTrueParameters() );
      
      for ( int i = 0; i < nParameter; ++i )
      {
        string parameterId = selectedParameter( i ) + string( "_" ) + theIdentifier;

        if ( theFirstUpdate )
        {
          KalmanAlignmentDataCollector::fillGraph( string("GlobalDelta") + parameterId, 0, -trueParameters[i]/selectedScaling(i) );
          KalmanAlignmentDataCollector::fillGraph( string("LocalSigma") + parameterId, 0, sqrt(covariance[i][i])/selectedScaling(i) );
        }

        KalmanAlignmentDataCollector::fillGraph( string("GlobalDelta") + parameterId, theNumberOfUpdates/theUpdateFrequency, (globalParameters[i]-trueParameters[i])/selectedScaling(i) );
        KalmanAlignmentDataCollector::fillGraph( string("LocalSigma") + parameterId, theNumberOfUpdates/theUpdateFrequency, sqrt(covariance[i][i])/selectedScaling(i) );
      }

      if ( theFirstUpdate ) theFirstUpdate = false;

#endif

    }
  }
}
void KalmanAlignmentUserVariables::update ( const AlignmentParameters param)

Update user variables with given alignment parameters.

Definition at line 145 of file KalmanAlignmentUserVariables.cc.

References extractTrueParameters(), KalmanAlignmentDataCollector::fillGraph(), i, Parameters::parameters, AlignmentParameters::selectedCovariance(), selectedParameter(), AlignmentParameters::selectedParameters(), selectedScaling(), AlignmentParameters::selector(), mathSSE::sqrt(), AlCaHLTBitMon_QueryRunRegistry::string, theFirstUpdate, theIdentifier, theNumberOfUpdates, theParentAlignable, and theUpdateFrequency.

{
  if ( theParentAlignable )
  {
    ++theNumberOfUpdates;

    const AlgebraicVector& parameters = param->selectedParameters();
    const AlgebraicSymMatrix& covariance = param->selectedCovariance();
    const vector< bool >& selector = param->selector();

    AlgebraicVector trueParameters( extractTrueParameters() );

    const int nParameter = 6;
    int selected = 0;
      
    for ( int i = 0; i < nParameter; ++i )
    {
      if ( selector[i] )
      {
        string parameterId = selectedParameter( i ) + string( "_" ) + theIdentifier;

        KalmanAlignmentDataCollector::fillGraph( string("Delta") + parameterId, theNumberOfUpdates/theUpdateFrequency, (parameters[selected]-trueParameters[i])/selectedScaling(i) );
        KalmanAlignmentDataCollector::fillGraph( string("Sigma") + parameterId, theNumberOfUpdates/theUpdateFrequency, sqrt(covariance[selected][selected])/selectedScaling(i) );

        selected++;
      }
    }

    if ( theFirstUpdate ) theFirstUpdate = false;
  }
}

Member Data Documentation

Definition at line 84 of file KalmanAlignmentUserVariables.h.

Referenced by KalmanAlignmentUserVariables().

Definition at line 79 of file KalmanAlignmentUserVariables.h.

Referenced by isAligned(), and setAlignmentFlag().

Definition at line 78 of file KalmanAlignmentUserVariables.h.

Referenced by update().

Definition at line 81 of file KalmanAlignmentUserVariables.h.

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

Definition at line 74 of file KalmanAlignmentUserVariables.h.

Referenced by hit(), and numberOfHits().

Definition at line 75 of file KalmanAlignmentUserVariables.h.

Referenced by numberOfUpdates(), and update().

Definition at line 85 of file KalmanAlignmentUserVariables.h.

Definition at line 76 of file KalmanAlignmentUserVariables.h.

Referenced by update().