Go to the documentation of this file.00001
00008 #include "FWCore/Utilities/interface/Exception.h"
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010
00011 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00012
00013 #include "Alignment/CommonAlignment/interface/Alignable.h"
00014 #include "Alignment/CommonAlignment/interface/AlignableDetOrUnitPtr.h"
00015 #include "Alignment/CommonAlignmentParametrization/interface/KarimakiAlignmentDerivatives.h"
00016 #include "Alignment/CommonAlignmentParametrization/interface/AlignmentParametersFactory.h"
00017 #include "CondFormats/Alignment/interface/Definitions.h"
00018
00019 #include "Geometry/CommonTopologies/interface/TwoBowedSurfacesDeformation.h"
00020
00021
00022 #include "Alignment/CommonAlignmentParametrization/interface/TwoBowedSurfacesAlignmentParameters.h"
00023
00024 #include <math.h>
00025 #include <iostream>
00026
00027 TwoBowedSurfacesAlignmentParameters::TwoBowedSurfacesAlignmentParameters(Alignable *ali) :
00028 AlignmentParameters(ali, AlgebraicVector(N_PARAM), AlgebraicSymMatrix(N_PARAM, 0)),
00029 ySplit_(this->ySplitFromAlignable(ali))
00030 {
00031 }
00032
00033
00034 TwoBowedSurfacesAlignmentParameters
00035 ::TwoBowedSurfacesAlignmentParameters(Alignable *alignable,
00036 const AlgebraicVector ¶meters,
00037 const AlgebraicSymMatrix &covMatrix) :
00038 AlignmentParameters(alignable, parameters, covMatrix),
00039 ySplit_(this->ySplitFromAlignable(alignable))
00040 {
00041 if (parameters.num_row() != N_PARAM) {
00042 throw cms::Exception("BadParameters") << "in TwoBowedSurfacesAlignmentParameters(): "
00043 << parameters.num_row() << " instead of " << N_PARAM
00044 << " parameters.";
00045 }
00046 }
00047
00048
00049 TwoBowedSurfacesAlignmentParameters
00050 ::TwoBowedSurfacesAlignmentParameters(Alignable *alignable,
00051 const AlgebraicVector ¶meters,
00052 const AlgebraicSymMatrix &covMatrix,
00053 const std::vector<bool> &selection) :
00054 AlignmentParameters(alignable, parameters, covMatrix, selection),
00055 ySplit_(this->ySplitFromAlignable(alignable))
00056 {
00057 if (parameters.num_row() != N_PARAM) {
00058 throw cms::Exception("BadParameters") << "in TwoBowedSurfacesAlignmentParameters(): "
00059 << parameters.num_row() << " instead of " << N_PARAM
00060 << " parameters.";
00061 }
00062 }
00063
00064
00065 TwoBowedSurfacesAlignmentParameters*
00066 TwoBowedSurfacesAlignmentParameters::clone(const AlgebraicVector ¶meters,
00067 const AlgebraicSymMatrix &covMatrix) const
00068 {
00069 TwoBowedSurfacesAlignmentParameters* rbap =
00070 new TwoBowedSurfacesAlignmentParameters(this->alignable(), parameters, covMatrix, selector());
00071
00072 if (this->userVariables()) rbap->setUserVariables(this->userVariables()->clone());
00073 rbap->setValid(this->isValid());
00074
00075 return rbap;
00076 }
00077
00078
00079 TwoBowedSurfacesAlignmentParameters*
00080 TwoBowedSurfacesAlignmentParameters::cloneFromSelected(const AlgebraicVector ¶meters,
00081 const AlgebraicSymMatrix &covMatrix) const
00082 {
00083 return this->clone(this->expandVector(parameters, this->selector()),
00084 this->expandSymMatrix(covMatrix, this->selector()));
00085 }
00086
00087
00088 AlgebraicMatrix
00089 TwoBowedSurfacesAlignmentParameters::derivatives(const TrajectoryStateOnSurface &tsos,
00090 const AlignableDetOrUnitPtr &alidet) const
00091 {
00092 const Alignable *ali = this->alignable();
00093 AlgebraicMatrix result(N_PARAM, 2);
00094
00095 if (ali == alidet) {
00096 const AlignableSurface &surf = ali->surface();
00097
00098
00099 const AlgebraicMatrix derivs(BowedDerivs()(tsos, surf.width(), surf.length(),
00100 true, ySplit_));
00101
00102
00103 const double localY = tsos.localParameters().mixedFormatVector()[4];
00104 const unsigned int indexOffset = (localY < ySplit_ ? 0 : dx2);
00105
00106 for (unsigned int i = BowedDerivs::dx; i < BowedDerivs::N_PARAM; ++i) {
00107 result[indexOffset + i][0] = derivs[i][0];
00108 result[indexOffset + i][1] = derivs[i][1];
00109 }
00110 } else {
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 throw cms::Exception("MisMatch")
00121 << "TwoBowedSurfacesAlignmentParameters::derivatives: The hit alignable must match the "
00122 << "aligned one (i.e. bowed surface parameters cannot be used for composed alignables)\n";
00123 }
00124
00125 return result;
00126 }
00127
00128
00129 void TwoBowedSurfacesAlignmentParameters::apply()
00130 {
00131 Alignable *alignable = this->alignable();
00132 if (!alignable) {
00133 throw cms::Exception("BadParameters")
00134 << "TwoBowedSurfacesAlignmentParameters::apply: parameters without alignable";
00135 }
00136
00137
00138 const AlignableSurface &surface = alignable->surface();
00139 const double halfLength = surface.length() * 0.5;
00140 const double halfLength1 = (halfLength + ySplit_) * 0.5;
00141 const double halfLength2 = (halfLength - ySplit_) * 0.5;
00142
00143
00144 const AlgebraicVector ¶ms = theData->parameters();
00145 std::vector<double> rigidBowPar1(BowedDerivs::N_PARAM);
00146 std::vector<double> rigidBowPar2(BowedDerivs::N_PARAM);
00147 for (unsigned int i = 0; i < BowedDerivs::N_PARAM; ++i) {
00148 rigidBowPar1[i] = params[i];
00149 rigidBowPar2[i] = params[i + BowedDerivs::N_PARAM];
00150 }
00151
00152
00153 rigidBowPar1[3] = params[dslopeY1] / halfLength1;
00154 rigidBowPar2[3] = params[dslopeY2] / halfLength2;
00155 rigidBowPar1[4] = -params[dslopeX1] / (surface.width() * 0.5);
00156 rigidBowPar2[4] = -params[dslopeX2] / (surface.width() * 0.5);
00157
00158 const double gammaScale1 = BowedDerivs::gammaScale(surface.width(), 2.0*halfLength1);
00159 rigidBowPar1[5] = params[drotZ1] / gammaScale1;
00160
00161
00162 const double gammaScale2 = BowedDerivs::gammaScale(surface.width(), 2.0*halfLength2);
00163 rigidBowPar2[5] = params[drotZ2] / gammaScale2;
00164
00165
00166 align::EulerAngles angles(3);
00167 for (unsigned int i = 0; i < 3; ++i) {
00168 angles[i] = (rigidBowPar1[i+3] + rigidBowPar2[i+3]) * 0.5;
00169 }
00170
00171
00172
00173 const double yMean1 = -halfLength + halfLength1;
00174 const double yMean2 = halfLength - halfLength2;
00175 rigidBowPar1[dz1] -= angles[0] * yMean1;
00176 rigidBowPar2[dz1] -= angles[0] * yMean2;
00177
00178 rigidBowPar1[dx1] += angles[2] * yMean1;
00179 rigidBowPar2[dx1] += angles[2] * yMean2;
00180
00181
00182 const align::LocalVector shift((rigidBowPar1[dx1] + rigidBowPar2[dx1]) * 0.5,
00183 (rigidBowPar1[dy1] + rigidBowPar2[dy1]) * 0.5,
00184 (rigidBowPar1[dz1] + rigidBowPar2[dz1]) * 0.5);
00185
00186 alignable->move(surface.toGlobal(shift));
00187
00188
00189
00190 align::RotationType rot(surface.toGlobal(align::toMatrix(angles)));
00191 align::rectify(rot);
00192 alignable->rotateInGlobalFrame(rot);
00193
00194
00195 std::vector<align::Scalar> deformations; deformations.reserve(13);
00196
00197 deformations.push_back((params[dsagittaX1 ] + params[dsagittaX2 ]) * 0.5);
00198 deformations.push_back((params[dsagittaXY1] + params[dsagittaXY2]) * 0.5);
00199 deformations.push_back((params[dsagittaY1 ] + params[dsagittaY2 ]) * 0.5);
00200
00201 for (unsigned int i = 0; i < BowedDerivs::N_PARAM; ++i) {
00202
00203
00204
00205
00206
00207 deformations.push_back((rigidBowPar1[i] - rigidBowPar2[i]) * 0.5);
00208 }
00209
00210 deformations.push_back(ySplit_);
00211
00212
00213 const TwoBowedSurfacesDeformation deform(deformations);
00214
00215
00216
00217
00218 alignable->addSurfaceDeformation(&deform, false);
00219 }
00220
00221
00222 int TwoBowedSurfacesAlignmentParameters::type() const
00223 {
00224 return AlignmentParametersFactory::kTwoBowedSurfaces;
00225 }
00226
00227
00228 void TwoBowedSurfacesAlignmentParameters::print() const
00229 {
00230
00231 std::cout << "Contents of TwoBowedSurfacesAlignmentParameters:"
00232 << "\nParameters: " << theData->parameters()
00233 << "\nCovariance: " << theData->covariance() << std::endl;
00234 }
00235
00236
00237 double TwoBowedSurfacesAlignmentParameters::ySplitFromAlignable(const Alignable *ali) const
00238 {
00239 if (!ali) return 0.;
00240
00241 const align::PositionType pos(ali->globalPosition());
00242 const double r = pos.perp();
00243
00244 if (ali->geomDetId().subdetId() == 6) {
00245 edm::LogInfo("Alignment") << "@SUB=ySplitFromAlignable" << ali->surface().length()
00246 << " TEC r " << r;
00247 }
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257 if (r < 58.) {
00258 edm::LogError("Alignment") << "@SUB=TwoBowedSurfacesAlignmentParameters::ySplitFromAlignable"
00259 << "There are no split modules for radii < 58, but r = " << r;
00260 return 0.;
00261 } else if (fabs(pos.z()) < 118.) {
00262 return 0.;
00263 } else if (r > 90.) {
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 return 0.6;
00276 } else if (r > 75.) {
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289 return -0.56;
00290 } else {
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303 return -0.9;
00304 }
00305
00306 }