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 theAlignmentParameters(0),
00024 theMother(0),
00025 theSurvey(0)
00026 {
00027 }
00028
00029
00030 Alignable::Alignable(align::ID id, const RotationType& rot):
00031 theDetId(),
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 ¶mComps) const
00049 {
00050 bool isConsistent = true;
00051 bool hasAliComp = false;
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()) {
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;
00064 }
00065 if (paramComps.size() != nCompBefore) {
00066 if (!first && !hasAliComp) isConsistent = false;
00067 hasAliComp = true;
00068 } else if (hasAliComp) {
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
00093
00094
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
00232
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 }