File indexing completed on 2024-04-06 11:56:13
0001
0002
0003
0004
0005
0006
0007
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/Utilities/interface/Exception.h"
0010
0011 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0012
0013 #include "Alignment/CommonAlignment/interface/Alignable.h"
0014 #include "Alignment/CommonAlignment/interface/AlignableDetOrUnitPtr.h"
0015 #include "Alignment/CommonAlignmentParametrization/interface/AlignmentParametersFactory.h"
0016 #include "Alignment/CommonAlignmentParametrization/interface/KarimakiAlignmentDerivatives.h"
0017 #include "CondFormats/Alignment/interface/Definitions.h"
0018
0019 #include "Geometry/CommonTopologies/interface/TwoBowedSurfacesDeformation.h"
0020
0021
0022 #include "Alignment/CommonAlignmentParametrization/interface/TwoBowedSurfacesAlignmentParameters.h"
0023
0024 #include <cmath>
0025 #include <iostream>
0026
0027 TwoBowedSurfacesAlignmentParameters::TwoBowedSurfacesAlignmentParameters(Alignable *ali)
0028 : AlignmentParameters(ali, AlgebraicVector(N_PARAM), AlgebraicSymMatrix(N_PARAM, 0)),
0029 ySplit_(this->ySplitFromAlignable(ali)) {}
0030
0031
0032 TwoBowedSurfacesAlignmentParameters ::TwoBowedSurfacesAlignmentParameters(Alignable *alignable,
0033 const AlgebraicVector ¶meters,
0034 const AlgebraicSymMatrix &covMatrix)
0035 : AlignmentParameters(alignable, parameters, covMatrix), ySplit_(this->ySplitFromAlignable(alignable)) {
0036 if (parameters.num_row() != N_PARAM) {
0037 throw cms::Exception("BadParameters") << "in TwoBowedSurfacesAlignmentParameters(): " << parameters.num_row()
0038 << " instead of " << N_PARAM << " parameters.";
0039 }
0040 }
0041
0042
0043 TwoBowedSurfacesAlignmentParameters ::TwoBowedSurfacesAlignmentParameters(Alignable *alignable,
0044 const AlgebraicVector ¶meters,
0045 const AlgebraicSymMatrix &covMatrix,
0046 const std::vector<bool> &selection)
0047 : AlignmentParameters(alignable, parameters, covMatrix, selection), ySplit_(this->ySplitFromAlignable(alignable)) {
0048 if (parameters.num_row() != N_PARAM) {
0049 throw cms::Exception("BadParameters") << "in TwoBowedSurfacesAlignmentParameters(): " << parameters.num_row()
0050 << " instead of " << N_PARAM << " parameters.";
0051 }
0052 }
0053
0054
0055 TwoBowedSurfacesAlignmentParameters *TwoBowedSurfacesAlignmentParameters::clone(
0056 const AlgebraicVector ¶meters, const AlgebraicSymMatrix &covMatrix) const {
0057 TwoBowedSurfacesAlignmentParameters *rbap =
0058 new TwoBowedSurfacesAlignmentParameters(this->alignable(), parameters, covMatrix, selector());
0059
0060 if (this->userVariables())
0061 rbap->setUserVariables(this->userVariables()->clone());
0062 rbap->setValid(this->isValid());
0063
0064 return rbap;
0065 }
0066
0067
0068 TwoBowedSurfacesAlignmentParameters *TwoBowedSurfacesAlignmentParameters::cloneFromSelected(
0069 const AlgebraicVector ¶meters, const AlgebraicSymMatrix &covMatrix) const {
0070 return this->clone(this->expandVector(parameters, this->selector()),
0071 this->expandSymMatrix(covMatrix, this->selector()));
0072 }
0073
0074
0075 AlgebraicMatrix TwoBowedSurfacesAlignmentParameters::derivatives(const TrajectoryStateOnSurface &tsos,
0076 const AlignableDetOrUnitPtr &alidet) const {
0077 const Alignable *ali = this->alignable();
0078 AlgebraicMatrix result(N_PARAM, 2);
0079
0080 if (ali == alidet) {
0081 const AlignableSurface &surf = ali->surface();
0082
0083
0084 const AlgebraicMatrix derivs(BowedDerivs()(tsos, surf.width(), surf.length(), true, ySplit_));
0085
0086
0087 const double localY = tsos.localParameters().mixedFormatVector()[4];
0088 const unsigned int indexOffset = (localY < ySplit_ ? 0 : dx2);
0089
0090 for (unsigned int i = BowedDerivs::dx; i < BowedDerivs::N_PARAM; ++i) {
0091 result[indexOffset + i][0] = derivs[i][0];
0092 result[indexOffset + i][1] = derivs[i][1];
0093 }
0094 } else {
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105 throw cms::Exception("MisMatch") << "TwoBowedSurfacesAlignmentParameters::derivatives: The hit "
0106 "alignable must match the "
0107 << "aligned one (i.e. bowed surface parameters cannot be used for "
0108 "composed alignables)\n";
0109 }
0110
0111 return result;
0112 }
0113
0114
0115 void TwoBowedSurfacesAlignmentParameters::apply() {
0116 Alignable *alignable = this->alignable();
0117 if (!alignable) {
0118 throw cms::Exception("BadParameters") << "TwoBowedSurfacesAlignmentParameters::apply: parameters without "
0119 "alignable";
0120 }
0121
0122
0123 const AlignableSurface &surface = alignable->surface();
0124 const double halfLength = surface.length() * 0.5;
0125 const double halfLength1 = (halfLength + ySplit_) * 0.5;
0126 const double halfLength2 = (halfLength - ySplit_) * 0.5;
0127
0128
0129 const AlgebraicVector ¶ms = theData->parameters();
0130 std::vector<double> rigidBowPar1(BowedDerivs::N_PARAM);
0131 std::vector<double> rigidBowPar2(BowedDerivs::N_PARAM);
0132 for (unsigned int i = 0; i < BowedDerivs::N_PARAM; ++i) {
0133 rigidBowPar1[i] = params[i];
0134 rigidBowPar2[i] = params[i + BowedDerivs::N_PARAM];
0135 }
0136
0137
0138 rigidBowPar1[3] = params[dslopeY1] / halfLength1;
0139 rigidBowPar2[3] = params[dslopeY2] / halfLength2;
0140 rigidBowPar1[4] = -params[dslopeX1] / (surface.width() * 0.5);
0141 rigidBowPar2[4] = -params[dslopeX2] / (surface.width() * 0.5);
0142
0143 const double gammaScale1 = BowedDerivs::gammaScale(surface.width(), 2.0 * halfLength1);
0144 rigidBowPar1[5] = params[drotZ1] / gammaScale1;
0145
0146
0147 const double gammaScale2 = BowedDerivs::gammaScale(surface.width(), 2.0 * halfLength2);
0148 rigidBowPar2[5] = params[drotZ2] / gammaScale2;
0149
0150
0151 align::EulerAngles angles(3);
0152 for (unsigned int i = 0; i < 3; ++i) {
0153 angles[i] = (rigidBowPar1[i + 3] + rigidBowPar2[i + 3]) * 0.5;
0154 }
0155
0156
0157
0158 const double yMean1 = -halfLength + halfLength1;
0159 const double yMean2 = halfLength - halfLength2;
0160 rigidBowPar1[dz1] -= angles[0] * yMean1;
0161 rigidBowPar2[dz1] -= angles[0] * yMean2;
0162
0163 rigidBowPar1[dx1] += angles[2] * yMean1;
0164 rigidBowPar2[dx1] += angles[2] * yMean2;
0165
0166
0167 const align::LocalVector shift((rigidBowPar1[dx1] + rigidBowPar2[dx1]) * 0.5,
0168 (rigidBowPar1[dy1] + rigidBowPar2[dy1]) * 0.5,
0169 (rigidBowPar1[dz1] + rigidBowPar2[dz1]) * 0.5);
0170
0171 alignable->move(surface.toGlobal(shift));
0172
0173
0174
0175 align::RotationType rot(surface.toGlobal(align::toMatrix(angles)));
0176 align::rectify(rot);
0177 alignable->rotateInGlobalFrame(rot);
0178
0179
0180 if (selector()[dsagittaX1] || selector()[dsagittaXY1] || selector()[dsagittaY1] || selector()[dsagittaX2] ||
0181 selector()[dsagittaXY2] || selector()[dsagittaY2]) {
0182
0183
0184 std::vector<align::Scalar> deformations;
0185 deformations.reserve(13);
0186
0187 deformations.push_back((params[dsagittaX1] + params[dsagittaX2]) * 0.5);
0188 deformations.push_back((params[dsagittaXY1] + params[dsagittaXY2]) * 0.5);
0189 deformations.push_back((params[dsagittaY1] + params[dsagittaY2]) * 0.5);
0190
0191 for (unsigned int i = 0; i < BowedDerivs::N_PARAM; ++i) {
0192
0193
0194
0195
0196
0197 deformations.push_back((rigidBowPar1[i] - rigidBowPar2[i]) * 0.5);
0198 }
0199
0200 deformations.push_back(ySplit_);
0201
0202 const TwoBowedSurfacesDeformation deform{deformations};
0203
0204
0205
0206
0207 alignable->addSurfaceDeformation(&deform, false);
0208 }
0209 }
0210
0211
0212 int TwoBowedSurfacesAlignmentParameters::type() const { return AlignmentParametersFactory::kTwoBowedSurfaces; }
0213
0214
0215 void TwoBowedSurfacesAlignmentParameters::print() const {
0216 std::cout << "Contents of TwoBowedSurfacesAlignmentParameters:"
0217 << "\nParameters: " << theData->parameters() << "\nCovariance: " << theData->covariance() << std::endl;
0218 }
0219
0220
0221 double TwoBowedSurfacesAlignmentParameters::ySplitFromAlignable(const Alignable *ali) const {
0222 if (!ali)
0223 return 0.;
0224
0225 const align::PositionType pos(ali->globalPosition());
0226 const double r = pos.perp();
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236 if (r < 58.) {
0237 edm::LogError("Alignment") << "@SUB=TwoBowedSurfacesAlignmentParameters::ySplitFromAlignable"
0238 << "There are no split modules for radii < 58, but r = " << r;
0239 return 0.;
0240 } else if (fabs(pos.z()) < 118.) {
0241 return 0.;
0242 } else if (r > 90.) {
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255 return 0.6;
0256 } else if (r > 75.) {
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269 return -0.56;
0270 } else {
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283 return -0.9;
0284 }
0285
0286 }