CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AlignableSiStripDet.cc
Go to the documentation of this file.
1 /*
2  * $Date: 2009/04/16 16:53:07 $
3  * $Revision: 1.7 $
4  */
5 
7 
9 
12 
23 
26 
27 #include <math.h>
28 
30  : AlignableDet(gluedDet, true), // true: adding DetUnits
31  theMonoBounds (gluedDet->monoDet() ->surface().bounds().clone()),
32  theStereoBounds(gluedDet->stereoDet()->surface().bounds().clone()),
33  theMonoType (static_cast<const StripGeomDetUnit*>(gluedDet->monoDet()) ->specificType()),
34  theStereoType(static_cast<const StripGeomDetUnit*>(gluedDet->stereoDet())->specificType())
35 {
36  // It is not allowed to store a pointer to GeomDet within objects with a life time
37  // longer than an Event:
38  // GeomDet comes from TrackerGeometry that is created from GeometricDet that depends on
39  // IdealGeometryRecord from EventSetup, so it could change in next event!
40  // ==> Need to store directly what I need from it.
41  // Unfortunately the current way with references for the type does not solve that,
42  // either. But currently no way out, see header file.
43 
44  // check order mono/stereo
45  const Alignables units(this->components());
46  if (units.size() != 2
47  || gluedDet->monoDet()->geographicalId() != units[0]->geomDetId()
48  || gluedDet->stereoDet()->geographicalId() != units[1]->geomDetId()) {
49  throw cms::Exception("LogicError")
50  << "[AlignableSiStripDet] " << "Either != 2 components or "
51  << "mono/stereo in wrong order for consistifyAlignments.";
52  }
53 }
54 
55 //__________________________________________________________________________________________________
57 {
58  delete theMonoBounds;
59  delete theStereoBounds;
60 }
61 
62 //__________________________________________________________________________________________________
64 {
65  const_cast<AlignableSiStripDet*>(this)->consistifyAlignments();
66 
67  return this->AlignableDet::alignments();
68 }
69 
70 //__________________________________________________________________________________________________
72 {
73  // make alignments consistent with daughters, calling method from geometry
74 
75  // The aim of all this gymnastics is to have the alignments calculated the same way as
76  // in PlaneBuilderForGluedDet::plane(const std::vector<const GeomDetUnit*> &detComps);
77  //
78  // So we take the (new) position and orientation from the AligableDetUnits,
79  // but bounds and GeomDetType from original GeomDetUnits to create new a new glued
80  // surface.
81 
82  const PositionType oldPos(theSurface.position()); // From old surface for keeping...
83  const RotationType oldRot(theSurface.rotation()); // ...track of changes.
84 
85  const Alignables aliUnits(this->components()); // order mono==0, stereo==1 checked in ctr.
86 
88  = BoundPlane::build(aliUnits[0]->globalPosition(), aliUnits[0]->globalRotation(),
89  *theMonoBounds);
90 
92  = BoundPlane::build(aliUnits[1]->globalPosition(), aliUnits[1]->globalRotation(),
94 
95  Surface::PositionType::BasicVectorType posSum = monoPlane->position().basicVector();
96  posSum += stereoPlane->position().basicVector();
97  Surface::PositionType meanPos(posSum/(float)aliUnits.size());
98  Surface::RotationType rotation = monoPlane->rotation();
99 
100  BoundPlane::BoundPlanePointer tmpPlane = BoundPlane::build(meanPos, rotation, OpenBounds());
101 
102  const MediumProperties* mp = monoPlane->mediumProperties();
103  MediumProperties newmp(0,0);
104  if (mp != 0) newmp = MediumProperties(mp->radLen()*2.0,mp->xi()*2.0);
105 
106  std::vector<GlobalPoint> corners;
107  std::vector<GlobalPoint> monoDC = BoundingBox().corners(*monoPlane);
108  corners.insert(corners.end(), monoDC.begin(), monoDC.end());
109  std::vector<GlobalPoint> stereoDC = BoundingBox().corners(*stereoPlane);
110  corners.insert(corners.end(), stereoDC.begin(), stereoDC.end());
111 
112  float xmin(0), xmax(0), ymin(0), ymax(0), zmin(0), zmax(0);
113  for (std::vector<GlobalPoint>::const_iterator i=corners.begin();
114  i!=corners.end();
115  ++i) {
116  LocalPoint p = tmpPlane->toLocal(*i);
117  if (p.x() < xmin) xmin = p.x();
118  if (p.x() > xmax) xmax = p.x();
119  if (p.y() < ymin) ymin = p.y();
120  if (p.y() > ymax) ymax = p.y();
121  if (p.z() < zmin) zmin = p.z();
122  if (p.z() > zmax) zmax = p.z();
123  }
124 
125  LocalVector localOffset((xmin+xmax)/2., (ymin+ymax)/2., (zmin+zmax)/2.);
126  GlobalVector offset(tmpPlane->toGlobal(localOffset));
127 
128  theSurface = AlignableSurface(BoundPlane(meanPos+offset, rotation,
129  RectangularPlaneBounds((xmax-xmin)/2, (ymax-ymin)/2, (zmax-zmin)/2),
130  &newmp));
131 
132  // But do not forget to keep track of movements/rotations:
133  const GlobalVector theMovement(theSurface.position().basicVector() - oldPos.basicVector());
134  // Seems to be correct down to delta angles 4.*1e-8:
135  const RotationType theRotation(oldRot.multiplyInverse(theSurface.rotation()));
136  this->addDisplacement(theMovement);
137  this->addRotation(theRotation);
138 
139 // this->dumpCompareEuler(oldRot, theSurface.rotation());
140 
141 // if (movement.mag2()) { // > 1.e-10) {
142 // edm::LogWarning("Alignment") << "@SUB=consistifyAlignments"
143 // << "Delta: " << movement.x() << " " << movement.y() << " " << movement.z()
144 // << "\nPos: " << oldPos.perp() << " " << oldPos.phi() << " " << oldPos.z();
145 // }
146 }
147 
148 // #include "CLHEP/Vector/EulerAngles.h"
149 // #include "CLHEP/Vector/Rotation.h"
150 // //__________________________________________________________________________________________________
151 // void AlignableSiStripDet::dumpCompareEuler(const RotationType &oldRot,
152 // const RotationType &newRot) const
153 // {
154 // //
155 // const HepRotation oldClhep(HepRep3x3(oldRot.xx(), oldRot.xy(), oldRot.xz(),
156 // oldRot.yx(), oldRot.yy(), oldRot.yz(),
157 // oldRot.zx(), oldRot.zy(), oldRot.zz()));
158 //
159 // const HepRotation newClhep(HepRep3x3(newRot.xx(), newRot.xy(), newRot.xz(),
160 // newRot.yx(), newRot.yy(), newRot.yz(),
161 // newRot.zx(), newRot.zy(), newRot.zz()));
162 //
163 // const RotationType rotationGlob(oldRot.multiplyInverse(newRot));
164 // const RotationType rotation(theSurface.toLocal(rotationGlob)); // not 100% correct: new global...
165 // const HepRotation diff(HepRep3x3(rotation.xx(), rotation.xy(), rotation.xz(),
166 // rotation.yx(), rotation.yy(), rotation.yz(),
167 // rotation.zx(), rotation.zy(), rotation.zz()));
168 //
169 // edm::LogWarning("Alignment") << "@SUB=dumpCompareEuler"
170 // << "oldEuler " << oldClhep.eulerAngles()
171 // << "\nnewEuler " << newClhep.eulerAngles()
172 // << "\n diff_euler " << diff.eulerAngles()
173 // << "\n diff_diag (" << diff.xx() << ", " << diff.yy()
174 // << ", " << diff.zz() << ")";
175 // }
int i
Definition: DBlmapReader.cc:9
float radLen() const
RotationType theRotation
Definition: Alignable.h:219
const GeomDetUnit * monoDet() const
Definition: GluedGeomDet.h:20
virtual Alignments * alignments() const
first consistify with component detunits, then call method from AlignableDet
T y() const
Definition: PV3DBase.h:57
virtual ~AlignableSiStripDet()
reduntantly make destructor virtual
virtual Alignments * alignments() const
Return vector of alignment data.
const RotationType & globalRotation() const
Return the global orientation of the object.
Definition: Alignable.h:132
AlignableSiStripDet(const GluedGeomDet *geomDet)
Constructor.
static BoundPlanePointer build(const PositionType &pos, const RotationType &rot, const Bounds *bounds, MediumProperties *mp=0)
Definition: BoundPlane.h:26
static std::vector< GlobalPoint > corners(const BoundPlane &)
Definition: BoundingBox.cc:24
void consistifyAlignments()
make alignments consistent with daughters
const RotationType & rotation() const
Return change of orientation since the creation of the object.
Definition: Alignable.h:138
T z() const
Definition: PV3DBase.h:58
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:74
unsigned int offset(bool)
float xi() const
T * clone(const T *tp)
Definition: Ptr.h:42
void addRotation(const RotationType &rotation)
Definition: Alignable.cc:206
string const
Definition: compareJSON.py:14
void addDisplacement(const GlobalVector &displacement)
Definition: Alignable.cc:198
const Bounds * theStereoBounds
Unlimited (trivial) bounds.
Definition: OpenBounds.h:10
const RotationType & rotation() const
virtual Alignables components() const
Return vector of direct components.
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:129
T x() const
Definition: PV3DBase.h:56
const PositionType & position() const
align::Alignables Alignables
Definition: Alignable.h:39
AlignableSurface theSurface
Definition: Alignable.h:216
const GeomDetUnit * stereoDet() const
Definition: GluedGeomDet.h:21
const Bounds * theMonoBounds