Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:46:18

0001 /* 
0002  *  $Date: 2011/09/05 16:59:07 $
0003  *  $Revision: 1.9 $
0004  */
0005 
0006 #include "Alignment/TrackerAlignment/interface/AlignableSiStripDet.h"
0007 
0008 #include "Alignment/CommonAlignment/interface/AlignableSurface.h"
0009 
0010 #include "CondFormats/Alignment/interface/AlignmentErrorsExtended.h"
0011 #include "CondFormats/Alignment/interface/AlignTransformErrorExtended.h"
0012 
0013 #include "DataFormats/GeometrySurface/interface/Bounds.h"
0014 #include "DataFormats/GeometryCommonDetAlgo/interface/AlignmentPositionError.h"
0015 #include "DataFormats/GeometryCommonDetAlgo/interface/GlobalError.h"
0016 #include "DataFormats/GeometrySurface/interface/BoundPlane.h"
0017 #include "Geometry/TrackerGeometryBuilder/interface/PlaneBuilderForGluedDet.h"
0018 #include "Geometry/CommonDetUnit/interface/GluedGeomDet.h"
0019 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
0020 
0021 #include "FWCore/Utilities/interface/Exception.h"
0022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0023 
0024 #include <cmath>
0025 
0026 AlignableSiStripDet::AlignableSiStripDet(const GluedGeomDet* gluedDet)
0027     : AlignableDet(gluedDet, true),  // true: adding DetUnits
0028       theMonoBounds(gluedDet->monoDet()->surface().bounds().clone()),
0029       theStereoBounds(gluedDet->stereoDet()->surface().bounds().clone()),
0030       theMonoType(static_cast<const StripGeomDetUnit*>(gluedDet->monoDet())->specificType()),
0031       theStereoType(static_cast<const StripGeomDetUnit*>(gluedDet->stereoDet())->specificType()) {
0032   // It is not allowed to store a pointer to GeomDet within objects with a life time
0033   // longer than an Event:
0034   // GeomDet comes from TrackerGeometry that is created from GeometricDet that depends on
0035   // IdealGeometryRecord from EventSetup, so it could change in next event!
0036   //  ==> Need to store directly what I need from it.
0037   // Unfortunately the current way with references for the type does not solve that,
0038   // either. But currently no way out, see header file.
0039 
0040   // check order mono/stereo
0041   const Alignables units(this->components());
0042   if (units.size() != 2 || gluedDet->monoDet()->geographicalId() != units[0]->geomDetId() ||
0043       gluedDet->stereoDet()->geographicalId() != units[1]->geomDetId()) {
0044     throw cms::Exception("LogicError") << "[AlignableSiStripDet] "
0045                                        << "Either != 2 components or "
0046                                        << "mono/stereo in wrong order for consistifyAlignments.";
0047   }
0048 }
0049 
0050 //__________________________________________________________________________________________________
0051 AlignableSiStripDet::~AlignableSiStripDet() {
0052   delete theMonoBounds;
0053   delete theStereoBounds;
0054 }
0055 
0056 //__________________________________________________________________________________________________
0057 Alignments* AlignableSiStripDet::alignments() const {
0058   const_cast<AlignableSiStripDet*>(this)->consistifyAlignments();
0059 
0060   return this->AlignableDet::alignments();
0061 }
0062 
0063 //__________________________________________________________________________________________________
0064 void AlignableSiStripDet::consistifyAlignments() {
0065   // make alignments consistent with daughters, calling method from geometry
0066 
0067   // The aim of all this gymnastics is to have the alignments calculated by
0068   // PlaneBuilderForGluedDet::plane(const std::vector<const GeomDetUnit*> &detComps);
0069   //
0070   // So we take the (new) position and orientation from the AligableDetUnits,
0071   // but bounds and GeomDetType from original GeomDetUnits to create new GeomDetUnits
0072   // that are passed to that routine.
0073 
0074   const Alignables aliUnits(this->components());  // order mono==0, stereo==1 checked in ctr.
0075 
0076   BoundPlane::BoundPlanePointer monoPlane =
0077       BoundPlane::build(aliUnits[0]->globalPosition(), aliUnits[0]->globalRotation(), theMonoBounds->clone());
0078   // Fortunately we do not seem to need a GeometricDet pointer and can use 0:
0079   const StripGeomDetUnit monoDet(&(*monoPlane), &theMonoType, 0);
0080 
0081   BoundPlane::BoundPlanePointer stereoPlane =
0082       BoundPlane::build(aliUnits[1]->globalPosition(), aliUnits[1]->globalRotation(), theStereoBounds->clone());
0083   // Fortunately we do not seem to need a GeometricDet pointer and can use 0:
0084   const StripGeomDetUnit stereoDet(&(*stereoPlane), &theStereoType, 0);
0085 
0086   std::vector<const GeomDetUnit*> detComps;
0087   detComps.push_back(&monoDet);    // order mono first, stereo second should be as in...
0088   detComps.push_back(&stereoDet);  // ...TrackerGeomBuilderFromGeometricDet::buildGeomDet
0089 
0090   // Now we have all to calculate new position and rotation via PlaneBuilderForGluedDet.
0091   const PositionType oldPos(theSurface.position());  // From old surface for keeping...
0092   const RotationType oldRot(theSurface.rotation());  // ...track of changes.
0093 
0094   PlaneBuilderForGluedDet planeBuilder;
0095   theSurface = AlignableSurface(*planeBuilder.plane(detComps));
0096 
0097   // But do not forget to keep track of movements/rotations:
0098   const GlobalVector movement(theSurface.position().basicVector() - oldPos.basicVector());
0099   // Seems to be correct down to delta angles 4.*1e-8:
0100   const RotationType rotation(oldRot.multiplyInverse(theSurface.rotation()));
0101   this->addDisplacement(movement);
0102   this->addRotation(rotation);
0103 
0104   //   this->dumpCompareEuler(oldRot, theSurface.rotation());
0105 
0106   //   if (movement.mag2()) { // > 1.e-10) {
0107   //     edm::LogWarning("Alignment") << "@SUB=consistifyAlignments"
0108   //                                  << "Delta: " << movement.x() << " " << movement.y() << " " << movement.z()
0109   //                                  << "\nPos: " << oldPos.perp() << " " << oldPos.phi() << " " << oldPos.z();
0110   //   }
0111 }
0112 
0113 // #include "CLHEP/Vector/EulerAngles.h"
0114 // #include "CLHEP/Vector/Rotation.h"
0115 // //__________________________________________________________________________________________________
0116 // void AlignableSiStripDet::dumpCompareEuler(const RotationType &oldRot,
0117 //                     const RotationType &newRot) const
0118 // {
0119 //   //
0120 //   const HepRotation oldClhep(HepRep3x3(oldRot.xx(), oldRot.xy(), oldRot.xz(),
0121 //                     oldRot.yx(), oldRot.yy(), oldRot.yz(),
0122 //                     oldRot.zx(), oldRot.zy(), oldRot.zz()));
0123 //
0124 //   const HepRotation newClhep(HepRep3x3(newRot.xx(), newRot.xy(), newRot.xz(),
0125 //                     newRot.yx(), newRot.yy(), newRot.yz(),
0126 //                     newRot.zx(), newRot.zy(), newRot.zz()));
0127 //
0128 //   const RotationType rotationGlob(oldRot.multiplyInverse(newRot));
0129 //   const RotationType rotation(theSurface.toLocal(rotationGlob)); // not 100% correct: new global...
0130 //   const HepRotation diff(HepRep3x3(rotation.xx(), rotation.xy(), rotation.xz(),
0131 //                     rotation.yx(), rotation.yy(), rotation.yz(),
0132 //                     rotation.zx(), rotation.zy(), rotation.zz()));
0133 //
0134 //   edm::LogWarning("Alignment") << "@SUB=dumpCompareEuler"
0135 //                     << "oldEuler " << oldClhep.eulerAngles()
0136 //                     << "\nnewEuler " << newClhep.eulerAngles()
0137 //                 << "\n diff_euler " << diff.eulerAngles()
0138 //                 << "\n diff_diag (" << diff.xx() << ", " << diff.yy()
0139 //                 <<         ", " << diff.zz() << ")";
0140 // }