00001 #include "Alignment/CommonAlignment/interface/AlignableDetUnit.h"
00002 #include "CondFormats/Alignment/interface/Alignments.h"
00003 #include "CondFormats/Alignment/interface/AlignmentErrors.h"
00004 #include "CLHEP/Vector/RotationInterfaces.h"
00005 #include "DataFormats/TrackingRecHit/interface/AlignmentPositionError.h"
00006 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00007
00008 #include "Alignment/CommonAlignment/interface/AlignableDet.h"
00009
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011
00012
00013
00014 AlignableDet::AlignableDet( const GeomDet* geomDet, bool addComponents ) :
00015 AlignableComposite( geomDet ),
00016 theAlignmentPositionError(0)
00017 {
00018 if (addComponents) {
00019
00020
00021
00022
00023 if ( geomDet->components().size() == 0 )
00024 {
00025 edm::LogError("Alignment") << "@SUB=AlignableDet"
00026 << "No components, will become exception!";
00027 addComponent( new AlignableDetUnit( id(), geomDet->surface() ) );
00028 }
00029 else
00030 {
00031 const std::vector<const GeomDet*>& geomDets = geomDet->components();
00032 for ( std::vector<const GeomDet*>::const_iterator idet=geomDets.begin();
00033 idet != geomDets.end(); ++idet )
00034 {
00035 addComponent( new AlignableDetUnit( (*idet)->geographicalId().rawId(),
00036 (*idet)->surface() ) );
00037 }
00038 }
00039
00040 theSurface = AlignableSurface(geomDet->surface());
00041 }
00042 }
00043
00044
00045
00046 AlignableDet::~AlignableDet()
00047 {
00048
00049 delete theAlignmentPositionError;
00050
00051 }
00052
00053
00054
00055 void AlignableDet::setAlignmentPositionError(const AlignmentPositionError& ape)
00056 {
00057
00058 if ( !theAlignmentPositionError )
00059 theAlignmentPositionError = new AlignmentPositionError( ape );
00060 else
00061 *theAlignmentPositionError = ape;
00062
00063 AlignableComposite::setAlignmentPositionError( ape );
00064
00065 }
00066
00067
00068
00069 void AlignableDet::addAlignmentPositionError(const AlignmentPositionError& ape)
00070 {
00071
00072 if ( !theAlignmentPositionError ) {
00073 theAlignmentPositionError = new AlignmentPositionError( ape );
00074 } else {
00075
00076 *theAlignmentPositionError = (*theAlignmentPositionError) += ape;
00077 }
00078
00079 AlignableComposite::addAlignmentPositionError( ape );
00080
00081 }
00082
00083
00084 void AlignableDet::addAlignmentPositionErrorFromRotation(const RotationType& rot )
00085 {
00086
00087
00088
00089 GlobalVector localPositionVector = surface().toGlobal( LocalVector(.5 * surface().width(), .5 * surface().length(), 0.) );
00090
00091 LocalVector::BasicVectorType lpvgf = localPositionVector.basicVector();
00092 GlobalVector gv( rot.multiplyInverse(lpvgf) - lpvgf );
00093
00094 AlignmentPositionError ape( gv.x(),gv.y(),gv.z() );
00095 this->addAlignmentPositionError( ape );
00096
00097 AlignableComposite::addAlignmentPositionErrorFromRotation( rot );
00098
00099 }
00100
00101
00102 void AlignableDet::addAlignmentPositionErrorFromLocalRotation(const RotationType& rot )
00103 {
00104
00105 RotationType globalRot = globalRotation().multiplyInverse(rot*globalRotation());
00106 this->addAlignmentPositionErrorFromRotation(globalRot);
00107
00108 AlignableComposite::addAlignmentPositionErrorFromLocalRotation( rot );
00109
00110 }
00111
00112
00113
00114
00115 Alignments* AlignableDet::alignments() const
00116 {
00117
00118 Alignments* m_alignments = new Alignments();
00119 RotationType rot( this->globalRotation() );
00120
00121
00122 Hep3Vector clhepVector( globalPosition().x(), globalPosition().y(), globalPosition().z() );
00123 HepRotation clhepRotation( HepRep3x3( rot.xx(), rot.xy(), rot.xz(),
00124 rot.yx(), rot.yy(), rot.yz(),
00125 rot.zx(), rot.zy(), rot.zz() ) );
00126 uint32_t detId = this->geomDetId().rawId();
00127
00128 AlignTransform transform( clhepVector, clhepRotation, detId );
00129
00130
00131 m_alignments->m_align.push_back( transform );
00132
00133
00134 std::vector<Alignable*> comp = this->components();
00135 if ( comp.size() > 1 ) {
00136 for ( std::vector<Alignable*>::iterator i=comp.begin(); i!=comp.end(); i++ )
00137 {
00138 Alignments* tmpAlignments = (*i)->alignments();
00139 std::copy( tmpAlignments->m_align.begin(), tmpAlignments->m_align.end(),
00140 std::back_inserter(m_alignments->m_align) );
00141 delete tmpAlignments;
00142 }
00143 }
00144
00145
00146 return m_alignments;
00147
00148 }
00149
00150
00151
00152 AlignmentErrors* AlignableDet::alignmentErrors( void ) const
00153 {
00154
00155
00156 AlignmentErrors* m_alignmentErrors = new AlignmentErrors();
00157
00158
00159 uint32_t detId = this->geomDetId().rawId();
00160 HepSymMatrix clhepSymMatrix(3,0);
00161 if ( theAlignmentPositionError )
00162 clhepSymMatrix= theAlignmentPositionError->globalError().matrix();
00163 AlignTransformError transformError( clhepSymMatrix, detId );
00164 m_alignmentErrors->m_alignError.push_back( transformError );
00165
00166
00167 std::vector<Alignable*> comp = this->components();
00168 if ( comp.size() > 1 ) {
00169 for ( std::vector<Alignable*>::iterator i=comp.begin(); i!=comp.end(); i++ )
00170 {
00171 AlignmentErrors* tmpAlignmentErrors = (*i)->alignmentErrors();
00172 std::copy( tmpAlignmentErrors->m_alignError.begin(),
00173 tmpAlignmentErrors->m_alignError.end(),
00174 std::back_inserter(m_alignmentErrors->m_alignError) );
00175 delete tmpAlignmentErrors;
00176 }
00177 }
00178
00179 return m_alignmentErrors;
00180
00181 }