00001
00002 #include "FWCore/Utilities/interface/Exception.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004
00005 #include "CondFormats/Alignment/interface/Alignments.h"
00006 #include "CondFormats/Alignment/interface/AlignmentErrors.h"
00007 #include "DataFormats/TrackingRecHit/interface/AlignmentPositionError.h"
00008 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00009
00010 #include "Alignment/CommonAlignment/interface/AlignableComposite.h"
00011
00012
00013
00014 AlignableComposite::AlignableComposite( const GeomDet* geomDet ) :
00015 Alignable( geomDet->geographicalId().rawId(), geomDet->surface() ),
00016 theStructureType(align::AlignableDet)
00017 {
00018 }
00019
00020 AlignableComposite::AlignableComposite(align::ID id,
00021 StructureType type,
00022 const RotationType& rot):
00023 Alignable(id, rot),
00024 theStructureType(type)
00025 {
00026 }
00027
00028 AlignableComposite::~AlignableComposite()
00029 {
00030 for (unsigned int i = 0; i < theComponents.size(); ++i) delete theComponents[i];
00031 }
00032
00033 void AlignableComposite::addComponent(Alignable* ali)
00034 {
00035 const Alignables& newComps = ali->deepComponents();
00036
00037 theDeepComponents.insert( theDeepComponents.end(), newComps.begin(), newComps.end() );
00038
00039 Scalar k = static_cast<Scalar>( newComps.size() ) / theDeepComponents.size();
00040
00041 theSurface.move( ( ali->globalPosition() - globalPosition() ) * k );
00042
00043 ali->setMother(this);
00044 theComponents.push_back(ali);
00045 }
00046
00047
00048 void AlignableComposite::recursiveComponents(Alignables &result) const
00049 {
00050
00051 Alignables components = this->components();
00052 if (this->alignableObjectId() == align::AlignableDet
00053 && components.size() <= 1) {
00054 return;
00055 }
00056 for (Alignables::const_iterator iter = components.begin();
00057 iter != components.end(); ++iter) {
00058 result.push_back(*iter);
00059 (*iter)->recursiveComponents(result);
00060 }
00061 }
00062
00063
00064 void AlignableComposite::move( const GlobalVector& displacement )
00065 {
00066
00067
00068 Alignables comp = this->components();
00069 for ( Alignables::iterator i=comp.begin(); i!=comp.end(); i++ )
00070 (**i).move( displacement);
00071
00072
00073 this->addDisplacement( displacement );
00074 theSurface.move( displacement );
00075
00076 }
00077
00078
00079
00080 void AlignableComposite::moveComponentsLocal( const LocalVector& localDisplacement )
00081 {
00082
00083 this->move( this->surface().toGlobal(localDisplacement) );
00084
00085 }
00086
00087
00088 void AlignableComposite::moveComponentLocal( const int i, const LocalVector& localDisplacement )
00089 {
00090
00091 if (i >= size() )
00092 throw cms::Exception("LogicError")
00093 << "AlignableComposite index (" << i << ") out of range";
00094
00095 Alignables comp = this->components();
00096 comp[i]->move( this->surface().toGlobal( localDisplacement ) );
00097
00098 }
00099
00100
00101
00106 void AlignableComposite::rotateInGlobalFrame( const RotationType& rotation )
00107 {
00108
00109 Alignables comp = this->components();
00110
00111 PositionType myPosition = this->globalPosition();
00112
00113 for ( Alignables::iterator i=comp.begin(); i!=comp.end(); i++ )
00114 {
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 const GlobalVector localPositionVector = (**i).globalPosition() - myPosition;
00132 GlobalVector::BasicVectorType lpvgf = localPositionVector.basicVector();
00133
00134
00135
00136
00137
00138 GlobalVector moveVector( rotation.multiplyInverse(lpvgf) - lpvgf );
00139
00140
00141 (**i).move( moveVector );
00142 (**i).rotateInGlobalFrame( rotation );
00143
00144 }
00145
00146 this->addRotation( rotation );
00147
00148 theSurface.rotate( rotation );
00149
00150 }
00151
00152
00153
00155 void AlignableComposite::setAlignmentPositionError( const AlignmentPositionError& ape )
00156 {
00157
00158
00159
00160 Alignables comp = this->components();
00161 for ( Alignables::const_iterator i=comp.begin(); i!=comp.end(); i++)
00162 {
00163 (*i)->setAlignmentPositionError(ape);
00164 }
00165
00166 }
00167
00168
00169
00170 void
00171 AlignableComposite::addAlignmentPositionError( const AlignmentPositionError& ape )
00172 {
00173
00174 Alignables comp = this->components();
00175 for ( Alignables::const_iterator i=comp.begin(); i!=comp.end(); i++)
00176 (*i)->addAlignmentPositionError(ape);
00177
00178 }
00179
00180
00181
00185 void AlignableComposite::addAlignmentPositionErrorFromRotation( const RotationType& rotation )
00186 {
00187
00188 Alignables comp = this->components();
00189
00190 PositionType myPosition=this->globalPosition();
00191
00192 for ( Alignables::const_iterator i=comp.begin(); i!=comp.end(); i++ )
00193 {
00194
00195
00196
00197
00198 const GlobalVector localPositionVector = (**i).globalPosition()-myPosition;
00199 GlobalVector::BasicVectorType lpvgf = localPositionVector.basicVector();
00200
00201
00202
00203
00204 GlobalVector moveVector( rotation.multiplyInverse(lpvgf) - lpvgf );
00205
00206 AlignmentPositionError ape( moveVector.x(), moveVector.y(), moveVector.z() );
00207 (*i)->addAlignmentPositionError( ape );
00208 (*i)->addAlignmentPositionErrorFromRotation( rotation );
00209
00210 }
00211
00212 }
00213
00214
00215
00219 void AlignableComposite::addAlignmentPositionErrorFromLocalRotation( const RotationType& rot )
00220 {
00221
00222 RotationType globalRot = globalRotation().multiplyInverse(rot*globalRotation());
00223 this->addAlignmentPositionErrorFromRotation(globalRot);
00224
00225 }
00226
00227
00228 void AlignableComposite::dump( void ) const
00229 {
00230
00231
00232
00233 Alignables comp = this->components();
00234
00235
00236 edm::LogInfo("AlignableDump")
00237 << " Alignable of type " << this->alignableObjectId()
00238 << " has " << comp.size() << " components" << std::endl
00239 << " position = " << this->globalPosition() << ", orientation:" << std::endl
00240 << this->globalRotation();
00241
00242
00243 for ( Alignables::iterator i=comp.begin(); i!=comp.end(); i++ )
00244 (*i)->dump();
00245
00246 }
00247
00248
00249
00250
00251 Alignments* AlignableComposite::alignments( void ) const
00252 {
00253
00254
00255 Alignables comp = this->components();
00256
00257 Alignments* m_alignments = new Alignments();
00258
00259
00260 for ( Alignables::iterator i=comp.begin(); i!=comp.end(); i++ )
00261 {
00262 Alignments* tmpAlignments = (*i)->alignments();
00263 std::copy( tmpAlignments->m_align.begin(), tmpAlignments->m_align.end(),
00264 std::back_inserter(m_alignments->m_align) );
00265 delete tmpAlignments;
00266 }
00267
00268
00269 return m_alignments;
00270
00271 }
00272
00273
00274
00275 AlignmentErrors* AlignableComposite::alignmentErrors( void ) const
00276 {
00277
00278
00279 Alignables comp = this->components();
00280
00281 AlignmentErrors* m_alignmentErrors = new AlignmentErrors();
00282
00283
00284 for ( Alignables::iterator i=comp.begin(); i!=comp.end(); i++ )
00285 {
00286 AlignmentErrors* tmpAlignmentErrors = (*i)->alignmentErrors();
00287 std::copy( tmpAlignmentErrors->m_alignError.begin(), tmpAlignmentErrors->m_alignError.end(),
00288 std::back_inserter(m_alignmentErrors->m_alignError) );
00289 delete tmpAlignmentErrors;
00290 }
00291
00292
00293 return m_alignmentErrors;
00294
00295 }