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),
00021 theId(id),
00022 theSurface(surf),
00023 theCachedSurface(surf),
00024 theAlignmentParameters(0),
00025 theMother(0),
00026 theSurvey(0)
00027 {
00028 }
00029
00030
00031 Alignable::Alignable(align::ID id, const RotationType& rot):
00032 theDetId(),
00033 theId(id),
00034 theSurface(PositionType(), rot),
00035 theCachedSurface(PositionType(), rot),
00036 theAlignmentParameters(0),
00037 theMother(0),
00038 theSurvey(0)
00039 {
00040 }
00041
00042
00043 Alignable::~Alignable()
00044 {
00045 delete theAlignmentParameters;
00046 delete theSurvey;
00047 }
00048
00049
00050 bool Alignable::firstCompsWithParams(Alignables ¶mComps) const
00051 {
00052 bool isConsistent = true;
00053 bool hasAliComp = false;
00054 bool first = true;
00055 const Alignables comps(this->components());
00056 for (Alignables::const_iterator iComp = comps.begin(), iCompEnd = comps.end();
00057 iComp != iCompEnd; ++iComp) {
00058 if ((*iComp)->alignmentParameters()) {
00059 paramComps.push_back(*iComp);
00060 if (!first && !hasAliComp) isConsistent = false;
00061 hasAliComp = true;
00062 } else {
00063 const unsigned int nCompBefore = paramComps.size();
00064 if (!(*iComp)->firstCompsWithParams(paramComps)) {
00065 isConsistent = false;
00066 }
00067 if (paramComps.size() != nCompBefore) {
00068 if (!first && !hasAliComp) isConsistent = false;
00069 hasAliComp = true;
00070 } else if (hasAliComp) {
00071 isConsistent = false;
00072 }
00073 }
00074 first = false;
00075 }
00076
00077 return isConsistent;
00078 }
00079
00080
00081 void Alignable::setAlignmentParameters( AlignmentParameters* dap )
00082 {
00083
00084 delete theAlignmentParameters;
00085 theAlignmentParameters = dap;
00086
00087 }
00088
00089
00090
00091 void Alignable::rotateInLocalFrame( const RotationType& rotation)
00092 {
00093
00094
00095
00096
00097
00098 rotateInGlobalFrame( surface().toGlobal(rotation) );
00099
00100 }
00101
00102
00103
00104 void Alignable::rotateAroundGlobalAxis( const GlobalVector& axis, Scalar radians )
00105 {
00106
00107 rotateInGlobalFrame( RotationType(axis.basicVector(),radians) );
00108
00109 }
00110
00111
00112
00113 void Alignable::rotateAroundLocalAxis( const LocalVector& axis, Scalar radians )
00114 {
00115
00116 rotateInLocalFrame(RotationType(axis.basicVector(), radians));
00117
00118 }
00119
00120
00121
00122 void Alignable::rotateAroundGlobalX( Scalar radians )
00123 {
00124
00125 RotationType rot( 1., 0., 0.,
00126 0., std::cos(radians), std::sin(radians),
00127 0., -std::sin(radians), std::cos(radians) );
00128
00129 rotateInGlobalFrame(rot);
00130
00131 }
00132
00133
00134
00135 void Alignable::rotateAroundLocalX( Scalar radians )
00136 {
00137
00138 RotationType rot( 1., 0., 0.,
00139 0., std::cos(radians), std::sin(radians),
00140 0., -std::sin(radians), std::cos(radians) );
00141
00142 rotateInLocalFrame(rot);
00143
00144 }
00145
00146
00147
00148 void Alignable::rotateAroundGlobalY( Scalar radians )
00149 {
00150
00151 RotationType rot( std::cos(radians), 0., -std::sin(radians),
00152 0., 1., 0.,
00153 std::sin(radians), 0., std::cos(radians) );
00154
00155 rotateInGlobalFrame(rot);
00156
00157 }
00158
00159
00160
00161 void Alignable::rotateAroundLocalY( Scalar radians )
00162 {
00163
00164 RotationType rot( std::cos(radians), 0., -std::sin(radians),
00165 0., 1., 0.,
00166 std::sin(radians), 0., std::cos(radians) );
00167
00168 rotateInLocalFrame(rot);
00169
00170 }
00171
00172
00173
00174 void Alignable::rotateAroundGlobalZ( Scalar radians )
00175 {
00176
00177 RotationType rot( std::cos(radians), std::sin(radians), 0.,
00178 -std::sin(radians), std::cos(radians), 0.,
00179 0., 0., 1. );
00180
00181 rotateInGlobalFrame(rot);
00182
00183 }
00184
00185
00186
00187 void Alignable::rotateAroundLocalZ( Scalar radians)
00188 {
00189
00190 RotationType rot( std::cos(radians), std::sin(radians), 0. ,
00191 -std::sin(radians), std::cos(radians), 0. ,
00192 0., 0., 1. );
00193
00194 rotateInLocalFrame(rot);
00195
00196 }
00197
00198
00199
00200 void Alignable::addDisplacement( const GlobalVector& displacement )
00201 {
00202
00203 theDisplacement += displacement;
00204
00205 }
00206
00207
00208 void Alignable::addRotation( const RotationType& rotation )
00209 {
00210
00211 theRotation *= rotation;
00212
00213 }
00214
00215
00216 AlignmentSurfaceDeformations* Alignable::surfaceDeformations( void ) const
00217 {
00218
00219 typedef std::pair<int,SurfaceDeformation*> IdSurfaceDeformationPtrPair;
00220
00221 std::vector<IdSurfaceDeformationPtrPair> result;
00222 surfaceDeformationIdPairs(result);
00223 std::sort( result.begin(),
00224 result.end(),
00225 lessIdAlignmentPair<IdSurfaceDeformationPtrPair>() );
00226
00227 AlignmentSurfaceDeformations* allSurfaceDeformations = new AlignmentSurfaceDeformations();
00228
00229 for ( std::vector<IdSurfaceDeformationPtrPair>::const_iterator iPair = result.begin();
00230 iPair != result.end();
00231 ++iPair) {
00232
00233
00234
00235 allSurfaceDeformations->add((*iPair).first,
00236 (*iPair).second->type(),
00237 (*iPair).second->parameters());
00238 }
00239
00240 return allSurfaceDeformations;
00241
00242 }
00243
00244 void Alignable::cacheTransformation()
00245 {
00246 theCachedSurface = theSurface;
00247 theCachedDisplacement = theDisplacement;
00248 theCachedRotation = theRotation;
00249 }
00250
00251 void Alignable::restoreCachedTransformation()
00252 {
00253
00254 theSurface = theCachedSurface;
00255 theDisplacement = theCachedDisplacement;
00256 theRotation = theCachedRotation;
00257
00258
00259 const Alignables comps(this->components());
00260
00261 for (auto it = comps.begin(); it != comps.end(); ++it) {
00262 (*it)->restoreCachedTransformation();
00263 }
00264
00265 }
00266
00267
00268 void Alignable::setSurvey( const SurveyDet* survey )
00269 {
00270
00271 delete theSurvey;
00272 theSurvey = survey;
00273
00274 }