CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
AlignableSiStripDet.cc
Go to the documentation of this file.
1 /*
2  * $Date: 2011/09/05 16:59:07 $
3  * $Revision: 1.9 $
4  */
5 
7 
9 
12 
20 
23 
24 #include <cmath>
25 
27  : AlignableDet(gluedDet, true), // true: adding DetUnits
28  theMonoBounds(gluedDet->monoDet()->surface().bounds().clone()),
29  theStereoBounds(gluedDet->stereoDet()->surface().bounds().clone()),
30  theMonoType(static_cast<const StripGeomDetUnit*>(gluedDet->monoDet())->specificType()),
31  theStereoType(static_cast<const StripGeomDetUnit*>(gluedDet->stereoDet())->specificType()) {
32  // It is not allowed to store a pointer to GeomDet within objects with a life time
33  // longer than an Event:
34  // GeomDet comes from TrackerGeometry that is created from GeometricDet that depends on
35  // IdealGeometryRecord from EventSetup, so it could change in next event!
36  // ==> Need to store directly what I need from it.
37  // Unfortunately the current way with references for the type does not solve that,
38  // either. But currently no way out, see header file.
39 
40  // check order mono/stereo
41  const Alignables units(this->components());
42  if (units.size() != 2 || gluedDet->monoDet()->geographicalId() != units[0]->geomDetId() ||
43  gluedDet->stereoDet()->geographicalId() != units[1]->geomDetId()) {
44  throw cms::Exception("LogicError") << "[AlignableSiStripDet] "
45  << "Either != 2 components or "
46  << "mono/stereo in wrong order for consistifyAlignments.";
47  }
48 }
49 
50 //__________________________________________________________________________________________________
52  delete theMonoBounds;
53  delete theStereoBounds;
54 }
55 
56 //__________________________________________________________________________________________________
58  const_cast<AlignableSiStripDet*>(this)->consistifyAlignments();
59 
60  return this->AlignableDet::alignments();
61 }
62 
63 //__________________________________________________________________________________________________
65  // make alignments consistent with daughters, calling method from geometry
66 
67  // The aim of all this gymnastics is to have the alignments calculated by
68  // PlaneBuilderForGluedDet::plane(const std::vector<const GeomDetUnit*> &detComps);
69  //
70  // So we take the (new) position and orientation from the AligableDetUnits,
71  // but bounds and GeomDetType from original GeomDetUnits to create new GeomDetUnits
72  // that are passed to that routine.
73 
74  const Alignables aliUnits(this->components()); // order mono==0, stereo==1 checked in ctr.
75 
77  BoundPlane::build(aliUnits[0]->globalPosition(), aliUnits[0]->globalRotation(), theMonoBounds->clone());
78  // Fortunately we do not seem to need a GeometricDet pointer and can use 0:
79  const StripGeomDetUnit monoDet(&(*monoPlane), &theMonoType, 0);
80 
81  BoundPlane::BoundPlanePointer stereoPlane =
82  BoundPlane::build(aliUnits[1]->globalPosition(), aliUnits[1]->globalRotation(), theStereoBounds->clone());
83  // Fortunately we do not seem to need a GeometricDet pointer and can use 0:
84  const StripGeomDetUnit stereoDet(&(*stereoPlane), &theStereoType, 0);
85 
86  std::vector<const GeomDetUnit*> detComps;
87  detComps.push_back(&monoDet); // order mono first, stereo second should be as in...
88  detComps.push_back(&stereoDet); // ...TrackerGeomBuilderFromGeometricDet::buildGeomDet
89 
90  // Now we have all to calculate new position and rotation via PlaneBuilderForGluedDet.
91  const PositionType oldPos(theSurface.position()); // From old surface for keeping...
92  const RotationType oldRot(theSurface.rotation()); // ...track of changes.
93 
94  PlaneBuilderForGluedDet planeBuilder;
95  theSurface = AlignableSurface(*planeBuilder.plane(detComps));
96 
97  // But do not forget to keep track of movements/rotations:
98  const GlobalVector movement(theSurface.position().basicVector() - oldPos.basicVector());
99  // Seems to be correct down to delta angles 4.*1e-8:
100  const RotationType rotation(oldRot.multiplyInverse(theSurface.rotation()));
101  this->addDisplacement(movement);
102  this->addRotation(rotation);
103 
104  // this->dumpCompareEuler(oldRot, theSurface.rotation());
105 
106  // if (movement.mag2()) { // > 1.e-10) {
107  // edm::LogWarning("Alignment") << "@SUB=consistifyAlignments"
108  // << "Delta: " << movement.x() << " " << movement.y() << " " << movement.z()
109  // << "\nPos: " << oldPos.perp() << " " << oldPos.phi() << " " << oldPos.z();
110  // }
111 }
112 
113 // #include "CLHEP/Vector/EulerAngles.h"
114 // #include "CLHEP/Vector/Rotation.h"
115 // //__________________________________________________________________________________________________
116 // void AlignableSiStripDet::dumpCompareEuler(const RotationType &oldRot,
117 // const RotationType &newRot) const
118 // {
119 // //
120 // const HepRotation oldClhep(HepRep3x3(oldRot.xx(), oldRot.xy(), oldRot.xz(),
121 // oldRot.yx(), oldRot.yy(), oldRot.yz(),
122 // oldRot.zx(), oldRot.zy(), oldRot.zz()));
123 //
124 // const HepRotation newClhep(HepRep3x3(newRot.xx(), newRot.xy(), newRot.xz(),
125 // newRot.yx(), newRot.yy(), newRot.yz(),
126 // newRot.zx(), newRot.zy(), newRot.zz()));
127 //
128 // const RotationType rotationGlob(oldRot.multiplyInverse(newRot));
129 // const RotationType rotation(theSurface.toLocal(rotationGlob)); // not 100% correct: new global...
130 // const HepRotation diff(HepRep3x3(rotation.xx(), rotation.xy(), rotation.xz(),
131 // rotation.yx(), rotation.yy(), rotation.yz(),
132 // rotation.zx(), rotation.zy(), rotation.zz()));
133 //
134 // edm::LogWarning("Alignment") << "@SUB=dumpCompareEuler"
135 // << "oldEuler " << oldClhep.eulerAngles()
136 // << "\nnewEuler " << newClhep.eulerAngles()
137 // << "\n diff_euler " << diff.eulerAngles()
138 // << "\n diff_diag (" << diff.xx() << ", " << diff.yy()
139 // << ", " << diff.zz() << ")";
140 // }
Alignments * alignments() const override
first consistify with component detunits, then call method from AlignableDet
const GeomDetUnit * monoDet() const
Definition: GluedGeomDet.h:19
Alignments * alignments() const override
Return vector of alignment data.
const StripGeomDetType & theStereoType
const StripGeomDetType & theMonoType
const Alignables & components() const override
Return vector of direct components.
const RotationType & globalRotation() const
Return the global orientation of the object.
Definition: Alignable.h:138
AlignableSiStripDet(const GluedGeomDet *geomDet)
Constructor.
void consistifyAlignments()
make alignments consistent with daughters
const RotationType & rotation() const
Return change of orientation since the creation of the object.
Definition: Alignable.h:144
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
void addRotation(const RotationType &rotation)
Definition: Alignable.cc:193
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
void addDisplacement(const GlobalVector &displacement)
Definition: Alignable.cc:190
const Bounds * theStereoBounds
TString units(TString variable, Char_t axis)
~AlignableSiStripDet() override
reduntantly make destructor virtual
const RotationType & rotation() const
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:135
virtual Bounds * clone() const =0
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:53
const PositionType & position() const
align::Alignables Alignables
Definition: Alignable.h:34
AlignableSurface theSurface
Definition: Alignable.h:237
const GeomDetUnit * stereoDet() const
Definition: GluedGeomDet.h:20
const Bounds * theMonoBounds