CMS 3D CMS Logo

MTDDiskSectorBuilderFromDet.cc
Go to the documentation of this file.
1 //#define EDM_ML_DEBUG
2 
4 
8 
9 #include <iomanip>
10 
11 using namespace std;
12 
13 namespace {
14 
15  pair<DiskSectorBounds*, GlobalVector> computeBounds(const vector<const GeomDet*>& dets) {
16  // go over all corners and compute maximum deviations
17  float rmin(dets.front()->surface().position().perp());
18  float rmax(rmin);
19  float zmin(dets.front()->surface().position().z());
20  float zmax(zmin);
21  float phimin(dets.front()->surface().position().phi());
22  float phimax(phimin);
23 
24  for (auto const& idet : dets) {
25  vector<GlobalPoint> corners = BoundingBox().corners(idet->specificSurface());
26  for (auto const& i : corners) {
27  float r = i.perp();
28  float z = i.z();
29  float phi = i.phi();
30  rmin = min(rmin, r);
31  rmax = max(rmax, r);
32  zmin = min(zmin, z);
33  zmax = max(zmax, z);
34  if (Geom::phiLess(phi, phimin))
35  phimin = phi;
36  if (Geom::phiLess(phimax, phi))
37  phimax = phi;
38  }
39  }
40 
42  edm::LogError("MTDDetLayers") << " MTDDiskSectorBuilderFromDet : "
43  << "Something went wrong with Phi Sorting !";
44  float zPos = (zmax + zmin) / 2.;
45  float phiWin = phimax - phimin;
46  float phiPos = (phimax + phimin) / 2.;
47  float rmed = (rmin + rmax) / 2.;
48  if (phiWin < 0.) {
49  if ((phimin < Geom::pi() / 2.) || (phimax > -Geom::pi() / 2.)) {
50  edm::LogError("MTDDetLayers") << " something strange going on, please check " << phimin << " " << phimax << " "
51  << phiWin;
52  }
53  phiWin += 2. * Geom::pi();
54  phiPos += Geom::pi();
55  }
56 
57  GlobalVector pos(rmed * cos(phiPos), rmed * sin(phiPos), zPos);
58 
59  LogTrace("MTDDetLayers") << "MTDDiskSectorBuilderFromDet::computeBounds sector at: " << std::fixed << pos << "\n"
60  << "zmin : " << std::setw(14) << zmin << "\n"
61  << "zmax : " << std::setw(14) << zmax << "\n"
62  << "rmin : " << std::setw(14) << rmin << "\n"
63  << "rmax : " << std::setw(14) << rmax << "\n"
64  << "phi ref : " << std::setw(14) << phiPos << "\n"
65  << "phi win : " << std::setw(14) << phiWin;
66 
67  return make_pair(new DiskSectorBounds(rmin, rmax, zmin - zPos, zmax - zPos, phiWin), pos);
68  }
69 
70  Surface::RotationType computeRotation(const vector<const GeomDet*>& dets, const Surface::PositionType pos) {
71  GlobalVector yAxis = (GlobalVector(pos.x(), pos.y(), 0.)).unit();
72 
73  GlobalVector zAxis(0., 0., 1.);
74  GlobalVector xAxis = yAxis.cross(zAxis);
75 
77  }
78 
79 } // namespace
80 
81 BoundDiskSector* MTDDiskSectorBuilderFromDet::operator()(const vector<const GeomDet*>& dets) const {
82  // check that the dets are all at about the same z
83  float zcheck = dets.front()->surface().position().z();
84  constexpr double tol(0.5); // minimal safety check on z position of modules within a sector, width ~ 10 mm
85  for (auto const& idet : dets) {
86  float zdiff = zcheck - (*idet).surface().position().z();
87  if (std::abs(zdiff) > tol) {
88  edm::LogError("MTDDetLayers")
89  << " MTDDiskSectorBuilderFromDet: Trying to build sector from Dets at different z positions !! Delta_z = "
90  << zdiff;
91  }
92  }
93 
94  auto bo = computeBounds(dets);
95 
96  Surface::PositionType pos(bo.second.x(), bo.second.y(), bo.second.z());
97  Surface::RotationType rot = computeRotation(dets, pos);
98  return new BoundDiskSector(pos, rot, bo.first);
99 }
T z() const
Definition: PV3DBase.h:61
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Log< level::Error, false > LogError
#define LogTrace(id)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Basic3DVector unit() const
bool phiLess(float phi1, float phi2)
Definition: VectorUtil.h:18
const PositionType & position() const
static std::vector< GlobalPoint > corners(const Plane &)
Definition: BoundingBox.cc:20
TkRotation< float > RotationType
constexpr double pi()
Definition: Pi.h:31
BoundDiskSector * operator()(const std::vector< const GeomDet *> &dets) const
Global3DVector GlobalVector
Definition: GlobalVector.h:10