CMS 3D CMS Logo

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