00001
00002
00003
00004
00005
00006 #include "Alignment/TrackerAlignment/interface/AlignableSiStripDet.h"
00007
00008 #include "Alignment/CommonAlignment/interface/AlignableSurface.h"
00009
00010 #include "CondFormats/Alignment/interface/AlignmentErrors.h"
00011 #include "CondFormats/Alignment/interface/AlignTransformError.h"
00012
00013 #include "DataFormats/GeometrySurface/interface/Bounds.h"
00014 #include "DataFormats/TrackingRecHit/interface/AlignmentPositionError.h"
00015 #include "DataFormats/GeometryCommonDetAlgo/interface/GlobalError.h"
00016 #include "DataFormats/GeometrySurface/interface/BoundPlane.h"
00017 #include "Geometry/TrackerGeometryBuilder/interface/PlaneBuilderForGluedDet.h"
00018 #include "Geometry/TrackerGeometryBuilder/interface/GluedGeomDet.h"
00019 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
00020
00021 #include "FWCore/Utilities/interface/Exception.h"
00022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00023
00024 #include <math.h>
00025
00026 AlignableSiStripDet::AlignableSiStripDet(const GluedGeomDet *gluedDet)
00027 : AlignableDet(gluedDet, true),
00028 theMonoBounds (gluedDet->monoDet() ->surface().bounds().clone()),
00029 theStereoBounds(gluedDet->stereoDet()->surface().bounds().clone()),
00030 theMonoType (static_cast<const StripGeomDetUnit*>(gluedDet->monoDet()) ->specificType()),
00031 theStereoType(static_cast<const StripGeomDetUnit*>(gluedDet->stereoDet())->specificType())
00032 {
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 const Alignables units(this->components());
00043 if (units.size() != 2
00044 || gluedDet->monoDet()->geographicalId() != units[0]->geomDetId()
00045 || gluedDet->stereoDet()->geographicalId() != units[1]->geomDetId()) {
00046 throw cms::Exception("LogicError")
00047 << "[AlignableSiStripDet] " << "Either != 2 components or "
00048 << "mono/stereo in wrong order for consistifyAlignments.";
00049 }
00050 }
00051
00052
00053 AlignableSiStripDet::~AlignableSiStripDet()
00054 {
00055 delete theMonoBounds;
00056 delete theStereoBounds;
00057 }
00058
00059
00060 Alignments* AlignableSiStripDet::alignments() const
00061 {
00062 const_cast<AlignableSiStripDet*>(this)->consistifyAlignments();
00063
00064 return this->AlignableDet::alignments();
00065 }
00066
00067
00068 AlignmentErrors* AlignableSiStripDet::alignmentErrors() const
00069 {
00070 const_cast<AlignableSiStripDet*>(this)->consistifyAlignmentErrors();
00071
00072 return this->AlignableDet::alignmentErrors();
00073 }
00074
00075
00076 void AlignableSiStripDet::consistifyAlignments()
00077 {
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 const Alignables aliUnits(this->components());
00088
00089 BoundPlane::BoundPlanePointer monoPlane
00090 = BoundPlane::build(aliUnits[0]->globalPosition(), aliUnits[0]->globalRotation(),
00091 *theMonoBounds);
00092
00093 const StripGeomDetUnit monoDet(&(*monoPlane), &theMonoType, 0);
00094
00095 BoundPlane::BoundPlanePointer stereoPlane
00096 = BoundPlane::build(aliUnits[1]->globalPosition(), aliUnits[1]->globalRotation(),
00097 *theStereoBounds);
00098
00099 const StripGeomDetUnit stereoDet(&(*stereoPlane), &theStereoType, 0);
00100
00101 std::vector<const GeomDetUnit*> detComps;
00102 detComps.push_back(&monoDet);
00103 detComps.push_back(&stereoDet);
00104
00105
00106 const PositionType oldPos(theSurface.position());
00107 const RotationType oldRot(theSurface.rotation());
00108
00109 PlaneBuilderForGluedDet planeBuilder;
00110 theSurface = AlignableSurface(*planeBuilder.plane(detComps));
00111
00112
00113 const GlobalVector movement(theSurface.position().basicVector() - oldPos.basicVector());
00114
00115 const RotationType rotation(oldRot.multiplyInverse(theSurface.rotation()));
00116 this->addDisplacement(movement);
00117 this->addRotation(rotation);
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 }
00128
00129
00130
00131 void AlignableSiStripDet::consistifyAlignmentErrors()
00132 {
00133
00134
00135 AlignmentErrors *oldErrs = this->AlignableDet::alignmentErrors();
00136
00137 const Alignables units(this->components());
00138
00139 const AlignTransformError &gluedErr = this->errorFromId(oldErrs->m_alignError,
00140 this->geomDetId());
00141 const AlignTransformError &monoErr = this->errorFromId(oldErrs->m_alignError,
00142 units[0]->geomDetId());
00143 const AlignTransformError &stereoErr = this->errorFromId(oldErrs->m_alignError,
00144 units[1]->geomDetId());
00145 const GlobalError errGlued (gluedErr.matrix());
00146 const GlobalError errMono (monoErr.matrix());
00147 const GlobalError errStereo(stereoErr.matrix());
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 double maxX2 = (errMono.cxx() > errStereo.cxx() ? errMono.cxx() : errStereo.cxx());
00162 maxX2 = (maxX2 > errGlued.cxx() ? maxX2 : errGlued.cxx());
00163 double maxY2 = (errMono.cyy() > errStereo.cyy() ? errMono.cyy() : errStereo.cyy());
00164 maxY2 = (maxY2 > errGlued.cyy() ? maxY2 : errGlued.cyy());
00165 double maxZ2 = (errMono.czz() > errStereo.czz() ? errMono.czz() : errStereo.czz());
00166 maxZ2 = (maxZ2 > errGlued.czz() ? maxZ2 : errGlued.czz());
00167 const AlignmentPositionError newApeGlued(sqrt(maxX2), sqrt(maxY2), sqrt(maxZ2));
00168
00169
00170 this->setAlignmentPositionError(newApeGlued);
00171 units[0]->setAlignmentPositionError(AlignmentPositionError(errMono));
00172 units[1]->setAlignmentPositionError(AlignmentPositionError(errStereo));
00173
00174
00175
00176
00177
00178
00179
00180 delete oldErrs;
00181 }
00182
00183
00184 const AlignTransformError&
00185 AlignableSiStripDet::errorFromId(const std::vector<AlignTransformError> &trafoErrs,
00186 align::ID id) const
00187 {
00188 for (unsigned int i = 0; i < trafoErrs.size(); ++i) {
00189 if (trafoErrs[i].rawId() == id) return trafoErrs[i];
00190 }
00191
00192 throw cms::Exception("Mismatch") << "[AlignableSiStripDet::indexFromId] "
00193 << id << " not found.";
00194
00195 return trafoErrs.front();
00196 }
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246