CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/Alignment/CommonAlignment/src/Alignable.cc

Go to the documentation of this file.
00001 
00008 #include "Alignment/CommonAlignment/interface/AlignmentParameters.h"
00009 #include "Alignment/CommonAlignment/interface/SurveyDet.h"
00010 
00011 #include "Alignment/CommonAlignment/interface/Alignable.h"
00012 
00013 #include "CondFormats/Alignment/interface/AlignmentSurfaceDeformations.h"
00014 #include "CondFormats/Alignment/interface/AlignmentSorter.h"
00015 
00016 #include "Geometry/CommonTopologies/interface/SurfaceDeformation.h"
00017 
00018 //__________________________________________________________________________________________________
00019 Alignable::Alignable(align::ID id, const AlignableSurface& surf):
00020   theDetId(id), // FIXME: inconsistent with other ctr., but needed for AlignableNavigator 
00021   theId(id),    // (finally get rid of one of the IDs!)
00022   theSurface(surf),
00023   theAlignmentParameters(0),
00024   theMother(0),
00025   theSurvey(0)
00026 {
00027 }
00028 
00029 //__________________________________________________________________________________________________
00030 Alignable::Alignable(align::ID id, const RotationType& rot):
00031   theDetId(), // FIXME: inconsistent with other ctr., cf. above
00032   theId(id),
00033   theSurface(PositionType(), rot),
00034   theAlignmentParameters(0),
00035   theMother(0),
00036   theSurvey(0)
00037 {
00038 }
00039 
00040 //__________________________________________________________________________________________________
00041 Alignable::~Alignable()
00042 {
00043   delete theAlignmentParameters;
00044   delete theSurvey;
00045 }
00046 
00047 //__________________________________________________________________________________________________
00048 bool Alignable::firstCompsWithParams(Alignables &paramComps) const
00049 {
00050   bool isConsistent = true;
00051   bool hasAliComp = false; // whether there are any (grand-) daughters with parameters
00052   bool first = true;
00053   const Alignables comps(this->components());
00054   for (Alignables::const_iterator iComp = comps.begin(), iCompEnd = comps.end();
00055        iComp != iCompEnd; ++iComp) {
00056     if ((*iComp)->alignmentParameters()) { // component has parameters itself
00057       paramComps.push_back(*iComp);
00058       if (!first && !hasAliComp) isConsistent = false;
00059       hasAliComp = true;
00060     } else {
00061       const unsigned int nCompBefore = paramComps.size();
00062       if (!(*iComp)->firstCompsWithParams(paramComps)) {
00063         isConsistent = false; // problem down in hierarchy
00064       }
00065       if (paramComps.size() != nCompBefore) {
00066         if (!first && !hasAliComp) isConsistent = false;
00067         hasAliComp = true;
00068       } else if (hasAliComp) { // no components with params, but previous component did have comps.
00069         isConsistent = false;
00070       }
00071     }
00072     first = false;
00073   }
00074 
00075   return isConsistent;
00076 }
00077 
00078 //__________________________________________________________________________________________________
00079 void Alignable::setAlignmentParameters( AlignmentParameters* dap )
00080 {
00081 
00082   delete theAlignmentParameters;
00083   theAlignmentParameters = dap;
00084 
00085 }
00086 
00087 
00088 //__________________________________________________________________________________________________
00089 void Alignable::rotateInLocalFrame( const RotationType& rotation)
00090 {
00091 
00092   // This is done by simply transforming the rotation from
00093   // the local system O to the global one  O^-1 * Rot * O
00094   // and then applying the global rotation  O * Rot
00095 
00096   rotateInGlobalFrame( surface().toGlobal(rotation) );
00097 
00098 }
00099 
00100 
00101 //__________________________________________________________________________________________________
00102 void Alignable::rotateAroundGlobalAxis( const GlobalVector& axis, Scalar radians )
00103 {
00104 
00105   rotateInGlobalFrame( RotationType(axis.basicVector(),radians) );
00106 
00107 }
00108 
00109 
00110 //__________________________________________________________________________________________________
00111 void Alignable::rotateAroundLocalAxis( const LocalVector& axis, Scalar radians )
00112 {
00113 
00114   rotateInLocalFrame(RotationType(axis.basicVector(), radians));
00115 
00116 }
00117 
00118 
00119 //__________________________________________________________________________________________________
00120 void Alignable::rotateAroundGlobalX( Scalar radians )
00121 {
00122 
00123   RotationType rot( 1.,  0.,            0.,
00124                     0.,  std::cos(radians),  std::sin(radians),
00125                     0., -std::sin(radians),  std::cos(radians) );
00126 
00127   rotateInGlobalFrame(rot);
00128 
00129 }
00130 
00131 
00132 //__________________________________________________________________________________________________
00133 void Alignable::rotateAroundLocalX( Scalar radians )
00134 {
00135  
00136   RotationType rot( 1.,  0.,            0.,
00137                     0.,  std::cos(radians),  std::sin(radians),
00138                     0., -std::sin(radians),  std::cos(radians) );
00139 
00140   rotateInLocalFrame(rot);
00141 
00142 }
00143 
00144 
00145 //__________________________________________________________________________________________________
00146 void Alignable::rotateAroundGlobalY( Scalar radians )
00147 {
00148 
00149   RotationType rot( std::cos(radians),  0., -std::sin(radians), 
00150                     0.,            1.,  0.,
00151                     std::sin(radians),  0.,  std::cos(radians) );
00152 
00153   rotateInGlobalFrame(rot);
00154   
00155 }
00156 
00157 
00158 //__________________________________________________________________________________________________
00159 void Alignable::rotateAroundLocalY( Scalar radians )
00160 {
00161 
00162   RotationType rot( std::cos(radians),  0., -std::sin(radians), 
00163                     0.,            1.,  0.,
00164                     std::sin(radians),  0.,  std::cos(radians) );
00165   
00166   rotateInLocalFrame(rot);
00167 
00168 }
00169 
00170 
00171 //__________________________________________________________________________________________________
00172 void Alignable::rotateAroundGlobalZ( Scalar radians )
00173 {
00174 
00175   RotationType rot(  std::cos(radians),  std::sin(radians),  0.,
00176                     -std::sin(radians),  std::cos(radians),  0.,
00177                      0.,            0.,            1. );
00178 
00179   rotateInGlobalFrame(rot);
00180   
00181 }
00182 
00183 
00184 //__________________________________________________________________________________________________
00185 void Alignable::rotateAroundLocalZ( Scalar radians)
00186 {
00187 
00188   RotationType rot(  std::cos(radians),  std::sin(radians), 0. ,
00189                     -std::sin(radians),  std::cos(radians), 0. ,
00190                      0.,            0.,           1. );
00191   
00192   rotateInLocalFrame(rot);
00193 
00194 }
00195 
00196 
00197 //__________________________________________________________________________________________________
00198 void Alignable::addDisplacement( const GlobalVector& displacement )
00199 {
00200 
00201   theDisplacement += displacement;
00202 
00203 }
00204 
00205 //__________________________________________________________________________________________________
00206 void Alignable::addRotation( const RotationType& rotation ) 
00207 {
00208 
00209   theRotation *= rotation;
00210 
00211 }
00212 
00213 //__________________________________________________________________________________________________
00214 AlignmentSurfaceDeformations* Alignable::surfaceDeformations( void ) const
00215 {
00216 
00217   typedef std::pair<int,SurfaceDeformation*> IdSurfaceDeformationPtrPair;
00218 
00219   std::vector<IdSurfaceDeformationPtrPair> result;
00220   surfaceDeformationIdPairs(result);
00221   std::sort( result.begin(), 
00222              result.end(), 
00223              lessIdAlignmentPair<IdSurfaceDeformationPtrPair>() );
00224   
00225   AlignmentSurfaceDeformations* allSurfaceDeformations = new AlignmentSurfaceDeformations();
00226   
00227   for ( std::vector<IdSurfaceDeformationPtrPair>::const_iterator iPair = result.begin();
00228         iPair != result.end();
00229         ++iPair) {
00230     
00231     // should we check for 'empty' parameters here (all zeros) and skip ?
00232     // may be add 'empty' method to SurfaceDeformation
00233     allSurfaceDeformations->add((*iPair).first,
00234                                 (*iPair).second->type(),
00235                                 (*iPair).second->parameters());
00236   }
00237   
00238   return allSurfaceDeformations;
00239 
00240 }
00241 
00242 //__________________________________________________________________________________________________
00243 void Alignable::setSurvey( const SurveyDet* survey )
00244 {
00245 
00246   delete theSurvey;
00247   theSurvey = survey;
00248 
00249 }