CMS 3D CMS Logo

AlignableComposite.cc

Go to the documentation of this file.
00001 // Framework
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) { // Non-glued AlignableDets (still) contain themselves
00054     return; // (would be better to implement AlignableDet::recursiveComponents!)
00055   }
00056   for (Alignables::const_iterator iter = components.begin();
00057        iter != components.end(); ++iter) {
00058     result.push_back(*iter); // could use std::copy(..), but here we build a real hierarchy
00059     (*iter)->recursiveComponents(result);
00060   }
00061 }
00062 
00063 //__________________________________________________________________________________________________
00064 void AlignableComposite::move( const GlobalVector& displacement ) 
00065 {
00066   
00067   // Move components
00068   Alignables comp = this->components();
00069   for ( Alignables::iterator i=comp.begin(); i!=comp.end(); i++ )
00070     (**i).move( displacement);
00071 
00072   // Move surface
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       // It is much simpler to calculate the local position given in coordinates 
00117       // of the GLOBAL frame and then just apply the rotation matrix given in the 
00118       // GLOBAL frame as well. ONLY this is somewhat tricky... as Teddy's frames 
00119       // don't like this kind of mixing...
00120       
00121       // Rotations are defined for "Basic3DVector" types, without any FrameTAG,
00122       // because Rotations usually switch between different frames. You get
00123       // this by using the method .basicVector()
00124     
00125       // localPosition = globalPosition (Component) - globalPosition(Composite)
00126       // moveVector = rotated localPosition  - original localposition
00127       // LocalVector localPositionVector = (**i).globalPosition()-myPosition;
00128     
00129     
00130       // Local Position given in coordinates of the GLOBAL Frame
00131       const GlobalVector localPositionVector = (**i).globalPosition() - myPosition;
00132       GlobalVector::BasicVectorType lpvgf = localPositionVector.basicVector();
00133 
00134       // rotate with GLOBAL rotation matrix  and subtract => moveVector in 
00135       // global Coordinates
00136       // apparently... you have to use the inverse of the rotation here
00137       // (rotate the VECTOR rather than the frame) 
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   // Since no geomDet is attached, alignable composites do not have an APE
00159   // The APE is, therefore, just propagated down
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       // It is just similar to to the "movement" that results to the components
00196       // when the composite is rotated. 
00197       // Local Position given in coordinates of the GLOBAL Frame
00198       const GlobalVector localPositionVector = (**i).globalPosition()-myPosition;
00199       GlobalVector::BasicVectorType lpvgf = localPositionVector.basicVector();
00200 
00201       // rotate with GLOBAL rotation matrix  and subtract => moveVector in global coordinates
00202       // apparently... you have to use the inverse of the rotation here
00203       // (rotate the VECTOR rather than the frame) 
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   // A simple printout method. Could be specialized in the implementation classes.
00232 
00233   Alignables comp = this->components();
00234 
00235   // Dump this
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   // Dump components
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   // Recursively call alignments, until we get to an AlignableDetUnit
00255   Alignables comp = this->components();
00256 
00257   Alignments* m_alignments = new Alignments();
00258 
00259   // Add components recursively
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   // Recursively call alignmentsErrors, until we get to an AlignableDetUnit
00279   Alignables comp = this->components();
00280 
00281   AlignmentErrors* m_alignmentErrors = new AlignmentErrors();
00282 
00283   // Add components recursively
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 }

Generated on Tue Jun 9 17:23:45 2009 for CMSSW by  doxygen 1.5.4