CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/Alignment/TrackerAlignment/src/AlignableSiStripDet.cc

Go to the documentation of this file.
00001 /* 
00002  *  $Date: 2011/09/05 16:59:07 $
00003  *  $Revision: 1.9 $
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), // true: adding DetUnits
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   // It is not allowed to store a pointer to GeomDet within objects with a life time
00034   // longer than an Event: 
00035   // GeomDet comes from TrackerGeometry that is created from GeometricDet that depends on
00036   // IdealGeometryRecord from EventSetup, so it could change in next event!
00037   //  ==> Need to store directly what I need from it. 
00038   // Unfortunately the current way with references for the type does not solve that,
00039   // either. But currently no way out, see header file.
00040 
00041   // check order mono/stereo
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 void AlignableSiStripDet::consistifyAlignments()
00069 {
00070   // make alignments consistent with daughters, calling method from geometry
00071 
00072   // The aim of all this gymnastics is to have the alignments calculated by
00073   // PlaneBuilderForGluedDet::plane(const std::vector<const GeomDetUnit*> &detComps);
00074   // 
00075   // So we take the (new) position and orientation from the AligableDetUnits,
00076   // but bounds and GeomDetType from original GeomDetUnits to create new GeomDetUnits
00077   // that are passed to that routine.
00078 
00079   const Alignables aliUnits(this->components()); // order mono==0, stereo==1 checked in ctr.
00080 
00081   BoundPlane::BoundPlanePointer monoPlane
00082     = BoundPlane::build(aliUnits[0]->globalPosition(), aliUnits[0]->globalRotation(),
00083                         *theMonoBounds);
00084   // Fortunately we do not seem to need a GeometricDet pointer and can use 0:
00085   const StripGeomDetUnit monoDet(&(*monoPlane), &theMonoType, 0);
00086 
00087   BoundPlane::BoundPlanePointer stereoPlane
00088     = BoundPlane::build(aliUnits[1]->globalPosition(), aliUnits[1]->globalRotation(),
00089                         *theStereoBounds);
00090   // Fortunately we do not seem to need a GeometricDet pointer and can use 0:
00091   const StripGeomDetUnit stereoDet(&(*stereoPlane), &theStereoType, 0);
00092 
00093   std::vector<const GeomDetUnit*> detComps;
00094   detComps.push_back(&monoDet);   // order mono first, stereo second should be as in...
00095   detComps.push_back(&stereoDet); // ...TrackerGeomBuilderFromGeometricDet::buildGeomDet
00096 
00097   // Now we have all to calculate new position and rotation via PlaneBuilderForGluedDet.
00098   const PositionType oldPos(theSurface.position()); // From old surface for keeping...
00099   const RotationType oldRot(theSurface.rotation()); // ...track of changes.
00100 
00101   PlaneBuilderForGluedDet planeBuilder;
00102   theSurface = AlignableSurface(*planeBuilder.plane(detComps));
00103 
00104   // But do not forget to keep track of movements/rotations:
00105   const GlobalVector movement(theSurface.position().basicVector() - oldPos.basicVector());
00106   // Seems to be correct down to delta angles 4.*1e-8:
00107   const RotationType rotation(oldRot.multiplyInverse(theSurface.rotation()));
00108   this->addDisplacement(movement);
00109   this->addRotation(rotation);
00110 
00111 //   this->dumpCompareEuler(oldRot, theSurface.rotation());
00112 
00113 //   if (movement.mag2()) { // > 1.e-10) { 
00114 //     edm::LogWarning("Alignment") << "@SUB=consistifyAlignments" 
00115 //                               << "Delta: " << movement.x() << " " << movement.y() << " " << movement.z()
00116 //                               << "\nPos: " << oldPos.perp() << " " << oldPos.phi() << " " << oldPos.z();
00117 //   }
00118 
00119 }
00120 
00121 // #include "CLHEP/Vector/EulerAngles.h"
00122 // #include "CLHEP/Vector/Rotation.h"
00123 // //__________________________________________________________________________________________________
00124 // void AlignableSiStripDet::dumpCompareEuler(const RotationType &oldRot,
00125 //                                         const RotationType &newRot) const
00126 // {
00127 //   // 
00128 //   const HepRotation oldClhep(HepRep3x3(oldRot.xx(), oldRot.xy(), oldRot.xz(),
00129 //                                     oldRot.yx(), oldRot.yy(), oldRot.yz(),
00130 //                                     oldRot.zx(), oldRot.zy(), oldRot.zz()));
00131 //
00132 //   const HepRotation newClhep(HepRep3x3(newRot.xx(), newRot.xy(), newRot.xz(),
00133 //                                     newRot.yx(), newRot.yy(), newRot.yz(),
00134 //                                     newRot.zx(), newRot.zy(), newRot.zz()));
00135 //
00136 //   const RotationType rotationGlob(oldRot.multiplyInverse(newRot));
00137 //   const RotationType rotation(theSurface.toLocal(rotationGlob)); // not 100% correct: new global...
00138 //   const HepRotation diff(HepRep3x3(rotation.xx(), rotation.xy(), rotation.xz(),
00139 //                                     rotation.yx(), rotation.yy(), rotation.yz(),
00140 //                                     rotation.zx(), rotation.zy(), rotation.zz()));
00141 //
00142 //   edm::LogWarning("Alignment") << "@SUB=dumpCompareEuler" 
00143 //                             << "oldEuler " << oldClhep.eulerAngles()
00144 //                             << "\nnewEuler " << newClhep.eulerAngles()
00145 //                             << "\n diff_euler " << diff.eulerAngles()
00146 //                             << "\n diff_diag (" << diff.xx() << ", " << diff.yy() 
00147 //                             <<         ", " << diff.zz() << ")";
00148 // }