CMS 3D CMS Logo

BaseCrystal.cc
Go to the documentation of this file.
1 //FAMOS headers
3 
4 // Data Formats
6 
8 
9 BaseCrystal::BaseCrystal(const DetId &cell) : cellid_(cell) { subdetn_ = cellid_.subdetId(); }
10 
12  unsigned ncorners = vec.size();
13  if (ncorners != 8)
14  return;
15 
16  // This is really a pity to have to make the conversion GlobalPoint to XYZPoint, but the latter have many
17  // useful properties (transformations, conversions....) that aren't implemented
18  // for the GlobalPoints and GlobalVectors.
19 
20  if (subdetn_ == EcalBarrel) {
21  if (pos.z() > 0.) {
22  for (unsigned ic = 0; ic < 8; ++ic) {
23  corners_[ic] = XYZPoint(vec[ic].x(), vec[ic].y(), vec[ic].z());
24  }
25  } else {
26  corners_[0] = XYZPoint(vec[2].x(), vec[2].y(), vec[2].z());
27  corners_[1] = XYZPoint(vec[3].x(), vec[3].y(), vec[3].z());
28  corners_[2] = XYZPoint(vec[0].x(), vec[0].y(), vec[0].z());
29  corners_[3] = XYZPoint(vec[1].x(), vec[1].y(), vec[1].z());
30  corners_[4] = XYZPoint(vec[6].x(), vec[6].y(), vec[6].z());
31  corners_[5] = XYZPoint(vec[7].x(), vec[7].y(), vec[7].z());
32  corners_[6] = XYZPoint(vec[4].x(), vec[4].y(), vec[4].z());
33  corners_[7] = XYZPoint(vec[5].x(), vec[5].y(), vec[5].z());
34  }
35  } else if (subdetn_ == EcalEndcap) {
36  double x = pos.x();
37  double y = pos.y();
38  double z = pos.z();
39  unsigned offset = 0;
40  int zsign = 1;
41  if (z > 0) {
42  if (x > 0 && y > 0)
43  offset = 1;
44  else if (x < 0 && y > 0)
45  offset = 2;
46  else if (x > 0 && y < 0)
47  offset = 0;
48  else if (x < 0 && y < 0)
49  offset = 3;
50  zsign = 1;
51  } else {
52  if (x > 0 && y > 0)
53  offset = 3;
54  else if (x < 0 && y > 0)
55  offset = 2;
56  else if (x > 0 && y < 0)
57  offset = 0;
58  else if (x < 0 && y < 0)
59  offset = 1;
60  zsign = -1;
61  }
62  for (unsigned ic = 0; ic < 4; ++ic) {
63  unsigned i1 = (unsigned)((zsign * ic + offset) % 4);
64  unsigned i2 = i1 + 4;
65  corners_[ic] = XYZPoint(vec[i1].x(), vec[i1].y(), vec[i1].z());
66  corners_[4 + ic] = XYZPoint(vec[i2].x(), vec[i2].y(), vec[i2].z());
67  }
68  }
70 }
71 
73  //if(corners_.size()==0) return;
74  center_ = XYZPoint(0., 0., 0.);
75  for (unsigned ic = 0; ic < 8; ++ic) {
76  center_ += corners_[ic];
77  }
78 
79  center_ *= 0.125;
80 
81  // std::cout << " Ncorners ? " << corners_.size() << std::endl;
82  frontcenter_ = 0.25 * (corners_[0] + corners_[1] + corners_[2] + corners_[3]);
83  backcenter_ = 0.25 * (corners_[4] + corners_[5] + corners_[6] + corners_[7]);
85  firstedgedirection_ = -(corners_[1] - corners_[0]).Unit();
86  fifthedgedirection_ = -(corners_[5] - corners_[4]).Unit();
87  // std::cout << " Direction laterales " << std::endl;
88  for (unsigned il = 0; il < 4; ++il) {
89  lateraldirection_[il] = -(corners_[(il + 1) % 4] - corners_[il]).Unit();
90  }
91 
92  Plane3D frontPlane((Point)corners_[0], (Point)corners_[1], (Point)corners_[2]);
93  Plane3D backPlane((Point)corners_[4], (Point)corners_[5], (Point)corners_[6]);
94  for (unsigned i = 0; i < 4; ++i) {
95  lateralPlane_[i] = Plane3D((Point)corners_[i], (Point)corners_[(i + 1) % 4], (Point)corners_[i + 4]);
96  }
97  // Front plane i=4 (UP)
98  lateralPlane_[4] = frontPlane;
99  // Back plane i =5 (DOWN)
100  lateralPlane_[5] = backPlane;
101 
102  for (unsigned i = 0; i < 6; ++i) {
103  exitingNormal_[i] = (lateralPlane_[i].Distance(Point(center_.X(), center_.Y(), center_.Z())) < 0.)
104  ? lateralPlane_[i].Normal().Unit()
105  : -lateralPlane_[i].Normal().Unit();
106  }
107 }
108 
109 void BaseCrystal::getLateralEdges(unsigned i, XYZPoint &a, XYZPoint &b) const {
110  if (i < 4U) // i >= 0, since i is unsigned
111  {
112  a = corners_[i];
113  b = corners_[i + 4];
114  }
115 }
116 
118  a = corners_[0];
119  b = corners_[1];
120  c = corners_[2];
121  d = corners_[3];
122 }
123 
124 void BaseCrystal::getFrontSide(std::vector<XYZPoint> &corners) const {
125  if (corners.size() == 4) {
126  corners[0] = corners_[0];
127  corners[1] = corners_[1];
128  corners[2] = corners_[2];
129  corners[3] = corners_[3];
130  }
131 }
132 
134  a = corners_[4];
135  b = corners_[5];
136  c = corners_[6];
137  d = corners_[7];
138 }
139 
140 void BaseCrystal::getBackSide(std::vector<XYZPoint> &corners) const {
141  if (corners.size() == 4) {
142  corners[0] = corners_[4];
143  corners[1] = corners_[5];
144  corners[2] = corners_[6];
145  corners[3] = corners_[7];
146  }
147 }
148 
150  if (i < 4U) // i >= 0, since i is unsigned
151  {
152  getLateralEdges(i, a, b);
153  getLateralEdges((i + 1) % 4, c, d);
154  }
155 }
156 
157 void BaseCrystal::getLateralSide(unsigned i, std::vector<XYZPoint> &corners) const {
158  if (corners.size() == 4 && i < 4U) // i >= 0, since i is unsigned
159  {
160  corners[0] = corners_[i];
161  corners[1] = corners_[i + 4];
162  corners[2] = corners_[4 + (i + 1) % 4];
163  corners[3] = corners_[(i + 1) % 4];
164  }
165 }
166 
167 void BaseCrystal::getDrawingCoordinates(std::vector<float> &x, std::vector<float> &y, std::vector<float> &z) const {
168  x.clear();
169  y.clear();
170  z.clear();
171 
172  x.push_back(corners_[0].X());
173  x.push_back(corners_[3].X());
174  x.push_back(corners_[2].X());
175  x.push_back(corners_[1].X());
176  x.push_back(corners_[5].X());
177  x.push_back(corners_[6].X());
178  x.push_back(corners_[7].X());
179  x.push_back(corners_[4].X());
180  x.push_back(corners_[0].X());
181  x.push_back(corners_[1].X());
182  x.push_back(corners_[2].X());
183  x.push_back(corners_[6].X());
184  x.push_back(corners_[5].X());
185  x.push_back(corners_[4].X());
186  x.push_back(corners_[7].X());
187  x.push_back(corners_[3].X());
188 
189  y.push_back(corners_[0].Y());
190  y.push_back(corners_[3].Y());
191  y.push_back(corners_[2].Y());
192  y.push_back(corners_[1].Y());
193  y.push_back(corners_[5].Y());
194  y.push_back(corners_[6].Y());
195  y.push_back(corners_[7].Y());
196  y.push_back(corners_[4].Y());
197  y.push_back(corners_[0].Y());
198  y.push_back(corners_[1].Y());
199  y.push_back(corners_[2].Y());
200  y.push_back(corners_[6].Y());
201  y.push_back(corners_[5].Y());
202  y.push_back(corners_[4].Y());
203  y.push_back(corners_[7].Y());
204  y.push_back(corners_[3].Y());
205 
206  z.push_back(corners_[0].Z());
207  z.push_back(corners_[3].Z());
208  z.push_back(corners_[2].Z());
209  z.push_back(corners_[1].Z());
210  z.push_back(corners_[5].Z());
211  z.push_back(corners_[6].Z());
212  z.push_back(corners_[7].Z());
213  z.push_back(corners_[4].Z());
214  z.push_back(corners_[0].Z());
215  z.push_back(corners_[1].Z());
216  z.push_back(corners_[2].Z());
217  z.push_back(corners_[6].Z());
218  z.push_back(corners_[5].Z());
219  z.push_back(corners_[4].Z());
220  z.push_back(corners_[7].Z());
221  z.push_back(corners_[3].Z());
222 }
223 
225  switch (side) {
226  case UP:
227  getFrontSide(a, b, c, d);
228  break;
229  case DOWN:
230  getBackSide(a, b, c, d);
231  break;
232  default:
234  }
235 }
236 
237 void BaseCrystal::print() const {
238  std::cout << "CellID " << cellid_.rawId() << std::endl;
239  std::cout << " Corners " << std::endl;
240  for (unsigned ic = 0; ic < 8; ++ic)
241  std::cout << corners_[ic] << std::endl;
242  std::cout << " Center " << center_ << std::endl;
243  std::cout << " Front Center " << frontcenter_ << std::endl;
244  std::cout << " Back Center " << backcenter_ << std::endl;
245  std::cout << " Normales sortantes " << std::endl;
246  for (unsigned id = 0; id < 6; ++id)
247  std::cout << exitingNormal_[id] << std::endl;
248 }
249 
250 void BaseCrystal::getSide(const CaloDirection &side, std::vector<XYZPoint> &corners) const {
251  switch (side) {
252  case UP:
253  getFrontSide(corners);
254  break;
255  case DOWN:
256  getBackSide(corners);
257  break;
258  default:
260  }
261 }
void getBackSide(XYZPoint &a, XYZPoint &b, XYZPoint &c, XYZPoint &d) const
Coordinates of the back side.
Definition: BaseCrystal.cc:133
XYZPoint center_
Definition: BaseCrystal.h:113
XYZPoint backcenter_
Definition: BaseCrystal.h:115
size_type size() const
Definition: EZArrayFL.h:67
XYZVector firstedgedirection_
Definition: BaseCrystal.h:116
void setCorners(const CaloCellGeometry::CornersVec &vec, const GlobalPoint &pos)
Definition: BaseCrystal.cc:11
void getLateralSide(unsigned i, XYZPoint &a, XYZPoint &b, XYZPoint &c, XYZPoint &d) const
Coordinates of the i=th lateral side.
Definition: BaseCrystal.cc:149
void getSide(const CaloDirection &side, XYZPoint &a, XYZPoint &b, XYZPoint &c, XYZPoint &d) const
generic access
Definition: BaseCrystal.cc:224
#define X(str)
Definition: MuonsGrabber.cc:38
XYZVector lateraldirection_[4]
Definition: BaseCrystal.h:119
void getFrontSide(XYZPoint &a, XYZPoint &b, XYZPoint &c, XYZPoint &d) const
coordinates of the front side
Definition: BaseCrystal.cc:117
BaseCrystal()
Empty constructor.
Definition: BaseCrystal.h:28
float float float z
XYZPoint corners_[8]
Definition: BaseCrystal.h:110
math::XYZVector XYZPoint
Definition: BaseCrystal.h:22
ROOT::Math::Plane3D Plane3D
Definition: BaseCrystal.h:23
void getLateralEdges(unsigned i, XYZPoint &, XYZPoint &) const
get the lateral edges
Definition: BaseCrystal.cc:109
XYZPoint frontcenter_
Definition: BaseCrystal.h:114
XYZVector exitingNormal_[6]
Definition: BaseCrystal.h:121
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
Plane3D lateralPlane_[6]
Definition: BaseCrystal.h:120
static CaloDirection Side(unsigned i)
unsigned int -> Side conversion
d
Definition: ztail.py:151
ROOT::Math::Plane3D::Point Point
Definition: BaseCrystal.cc:7
Definition: DetId.h:17
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
double b
Definition: hdecay.h:118
Structure Point Contains parameters of Gaussian fits to DMRs.
double a
Definition: hdecay.h:119
void getDrawingCoordinates(std::vector< float > &x, std::vector< float > &y, std::vector< float > &z) const
for debugging.
Definition: BaseCrystal.cc:167
float x
DetId cellid_
Definition: BaseCrystal.h:111
CaloDirection
Codes the local directions in the cell lattice.
Definition: CaloDirection.h:9
XYZVector fifthedgedirection_
Definition: BaseCrystal.h:117
XYZVector crystalaxis_
Definition: BaseCrystal.h:118
void print() const
Definition: BaseCrystal.cc:237
void computeBasicProperties()
Definition: BaseCrystal.cc:72