CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CylinderBuilderFromDet.cc
Go to the documentation of this file.
4 #include <algorithm>
5 
6 using namespace std;
7 
8 BoundCylinder* CylinderBuilderFromDet::operator()(vector<const Det*>::const_iterator first,
9  vector<const Det*>::const_iterator last) const {
10  // find mean position and radius
12  Vector posSum(0, 0, 0);
13  float rSum = 0;
14  for (vector<const Det*>::const_iterator i = first; i != last; i++) {
15  posSum += (**i).surface().position().basicVector();
16  rSum += (**i).surface().position().perp();
17  }
18  float div(1 / float(last - first));
19  PositionType meanPos(div * posSum);
20  float meanR(div * rSum);
21 
22  // find max deviations from mean pos in Z and from mean R
23  float rmin = meanR;
24  float rmax = meanR;
25  float zmin = meanPos.z();
26  float zmax = meanPos.z();
27  for (vector<const Det*>::const_iterator i = first; i != last; i++) {
28  vector<GlobalPoint> corners = BoundingBox::corners(dynamic_cast<const Plane&>((**i).surface()));
29  for (vector<GlobalPoint>::const_iterator ic = corners.begin(); ic != corners.end(); ic++) {
30  float r = ic->perp();
31  float z = ic->z();
32  rmin = min(rmin, r);
33  rmax = max(rmax, r);
34  zmin = min(zmin, z);
35  zmax = max(zmax, z);
36  }
37  // in addition to the corners we have to check the middle of the
38  // det +/- thickness/2
39  // , since the min radius for some barrel dets is reached there
40  float rdet = (**i).surface().position().perp();
41  float halfThick = (**i).surface().bounds().thickness() / 2.F;
42  rmin = min(rmin, rdet - halfThick);
43  rmax = max(rmax, rdet + halfThick);
44  }
45 
46  // the transverse position is zero by construction.
47  // the Z position is the average between zmin and zmax, since the bounds
48  // are symmetric
49  // for the same reason the R is the average between rmin and rmax,
50  // but this is done by the Bounds anyway.
51 
52  PositionType pos(0, 0, 0.5 * (zmin + zmax));
53  RotationType rot; // only "barrel" orientation supported
54 
55  auto scp = new SimpleCylinderBounds(rmin, rmax, zmin - pos.z(), zmax - pos.z());
56  return new Cylinder(Cylinder::computeRadius(*scp), pos, rot, scp);
57 }
58 
60  BoundingBox bb(dynamic_cast<const Plane&>(det.surface()));
61  for (int nc = 0; nc < 8; ++nc) {
62  float r = bb[nc].perp();
63  float z = bb[nc].z();
64  rmin = std::min(rmin, r);
65  rmax = std::max(rmax, r);
66  zmin = std::min(zmin, z);
67  zmax = std::max(zmax, z);
68  }
69  // in addition to the corners we have to check the middle of the
70  // det +/- thickness/2
71  // , since the min radius for some barrel dets is reached there
72  float rdet = det.surface().position().perp();
73  float halfThick = det.surface().bounds().thickness() / 2.F;
74  rmin = std::min(rmin, rdet - halfThick);
75  rmax = std::max(rmax, rdet + halfThick);
76 }
77 
79  PositionType pos(0, 0, 0.5 * (zmin + zmax));
80  RotationType rot; // only "barrel" orientation supported
81 
82  auto scp = new SimpleCylinderBounds(rmin, rmax, zmin - pos.z(), zmax - pos.z());
83  return new Cylinder(Cylinder::computeRadius(*scp), pos, rot, scp);
84 }
T perp() const
Definition: PV3DBase.h:69
ROOT::Math::Plane3D::Vector Vector
Definition: EcalHitMaker.cc:29
BoundCylinder * operator()(std::vector< const Det * >::const_iterator first, std::vector< const Det * >::const_iterator last) const
const Bounds & bounds() const
Definition: Surface.h:87
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
virtual float thickness() const =0
BoundCylinder * build() const
T z() const
Definition: PV3DBase.h:61
T perp() const
Magnitude of transverse component.
static std::vector< GlobalPoint > corners(const Plane &)
Definition: BoundingBox.cc:20
static float computeRadius(Bounds const &bounds)
Definition: Cylinder.h:28
tuple last
Definition: dqmdumpme.py:56
const PositionType & position() const