CMS 3D CMS Logo

CrystalPad.cc
Go to the documentation of this file.
2 
3 #include <iostream>
4 
5 std::vector<CLHEP::Hep2Vector> CrystalPad::aVector(4);
6 
8  corners_ = right.corners_;
9  dir_ = right.dir_;
10  number_ = right.number_;
12  center_ = right.center_;
13  epsilon_ = right.epsilon_;
14  dummy_ = right.dummy_;
15 }
16 
18  if (this != &right) { // don't copy into yourself
19  corners_ = right.corners_;
20  dir_ = right.dir_;
21  number_ = right.number_;
23  center_ = right.center_;
24  epsilon_ = right.epsilon_;
25  dummy_ = right.dummy_;
26  }
27  return *this;
28 }
29 
30 CrystalPad::CrystalPad(unsigned number, const std::vector<CLHEP::Hep2Vector>& corners)
31  : corners_(corners), dir_(aVector), number_(number), survivalProbability_(1.), center_(0., 0.), epsilon_(0.001) {
32  // std::cout << " Hello " << std::endl;
33  if (corners.size() != 4) {
34  std::cout << " Try to construct a quadrilateral with " << corners.size() << " points ! " << std::endl;
35  dummy_ = true;
36  } else {
37  dummy_ = false;
38  // Set explicity the z to 0 !
39  for (unsigned ic = 0; ic < 4; ++ic) {
40  dir_[ic] = (corners[(ic + 1) % 4] - corners[ic]).unit();
41  center_ += corners_[ic];
42  }
43  center_ *= 0.25;
44  }
45  // std::cout << " End of 1 constructor " << std::endl;
46  // std::cout << " Ncorners " << corners_.size() << std::endl;
47  // std::cout << " Ndirs " << dir_.size() << std::endl;
48 }
49 
51  int onEcal,
52  const std::vector<XYZPoint>& corners,
53  const XYZPoint& origin,
54  const XYZVector& vec1,
55  const XYZVector& vec2)
56  : corners_(aVector), dir_(aVector), number_(number), survivalProbability_(1.), center_(0., 0.), epsilon_(0.001) {
57  // std::cout << " We are in the 2nd constructor " << std::endl;
58  if (corners.size() != 4) {
59  std::cout << " Try to construct a quadrilateral with " << corners.size() << " points ! " << std::endl;
60  dummy_ = true;
61  } else {
62  dummy_ = false;
63  double sign = (onEcal == 1) ? -1. : 1.;
64 
65  // the good one in the central
66  trans_ = Transform3D((Point)origin,
67  (Point)(origin + vec1),
68  (Point)(origin + vec2),
69  Point(0., 0., 0.),
70  Point(0., 0., sign),
71  Point(0., 1., 0.));
73  // std::cout << " Constructor 2; input corners " << std::endl;
74  for (unsigned ic = 0; ic < 4; ++ic) {
75  // std::cout << corners[ic]<< " " ;
76  XYZPoint corner = rotation_(corners[ic]) + translation_;
77  // std::cout << corner << std::endl ;
78  corners_[ic] = CLHEP::Hep2Vector(corner.X(), corner.Y());
79  center_ += corners_[ic];
80  }
81  for (unsigned ic = 0; ic < 4; ++ic) {
82  dir_[ic] = (corners_[(ic + 1) % 4] - corners_[ic]).unit();
83  }
84  center_ *= 0.25;
85  }
86  // std::cout << " End of 2 constructor " << std::endl;
87  // std::cout << " Corners(constructor) " ;
88  // std::cout << corners_[0] << std::endl;
89  // std::cout << corners_[1] << std::endl;
90  // std::cout << corners_[2] << std::endl;
91  // std::cout << corners_[3] << std::endl;
92 }
94  unsigned number, const std::vector<XYZPoint>& corners, const Transform3D& trans, double scaf, bool bothdirections)
95  : corners_(aVector),
96  dir_(aVector),
97  number_(number),
98  survivalProbability_(1.),
99  center_(0., 0.),
100  epsilon_(0.001),
101  yscalefactor_(scaf) {
102  // std::cout << " We are in the 2nd constructor " << std::endl;
103  if (corners.size() != 4) {
104  std::cout << " Try to construct a quadrilateral with " << corners.size() << " points ! " << std::endl;
105  dummy_ = true;
106  } else {
107  dummy_ = false;
108 
109  // the good one in the central
110  trans_ = trans;
111  // std::cout << " Constructor 2; input corners " << std::endl;
113  for (unsigned ic = 0; ic < 4; ++ic) {
114  XYZPoint corner = rotation_(corners[ic]) + translation_;
115  // std::cout << corner << std::endl ;
116  double xscalefactor = (bothdirections) ? yscalefactor_ : 1.;
117  corners_[ic] = CLHEP::Hep2Vector(corner.X() * xscalefactor, corner.Y() * yscalefactor_);
118  center_ += corners_[ic];
119  }
120  for (unsigned ic = 0; ic < 4; ++ic) {
121  dir_[ic] = (corners_[(ic + 1) % 4] - corners_[ic]).unit();
122  }
123  center_ *= 0.25;
124  }
125 }
126 
127 bool CrystalPad::inside(const CLHEP::Hep2Vector& ppoint, bool debug) const {
128  // std::cout << "Inside " << ppoint <<std::endl;
129  // std::cout << "Corners " << corners_.size() << std::endl;
130  // std::cout << corners_[0] << std::endl;
131  // std::cout << corners_[1] << std::endl;
132  // std::cout << corners_[2] << std::endl;
133  // std::cout << corners_[3] << std::endl;
134  // std::cout << " Got the 2D point " << std::endl;
135  CLHEP::Hep2Vector pv0(ppoint - corners_[0]);
136  CLHEP::Hep2Vector pv2(ppoint - corners_[2]);
137  CLHEP::Hep2Vector n1(pv0 - (pv0 * dir_[0]) * dir_[0]);
138  CLHEP::Hep2Vector n2(pv2 - (pv2 * dir_[2]) * dir_[2]);
139 
140  // double N1(n1.mag());
141  // double N2(n2.mag());
142  double r1(n1 * n2);
143  bool inside1(r1 <= 0.);
144 
145  if (!inside1)
146  return false;
147 
148  // if(debug)
149  // {
150  // std::cout << n1 << std::endl;
151  // std::cout << n2 << std::endl;
152  // std::cout << r1 << std::endl;
153  // std::cout << inside1 << std::endl;
154  // }
155 
156  // bool close1=(N1<epsilon_||N2<epsilon_);
157  //
158  // if(!close1&&!inside1) return false;
159  // std::cout << " First calculation " << std::endl;
160  CLHEP::Hep2Vector pv1(ppoint - corners_[1]);
161  CLHEP::Hep2Vector pv3(ppoint - corners_[3]);
162  CLHEP::Hep2Vector n3(pv1 - (pv1 * dir_[1]) * dir_[1]);
163  CLHEP::Hep2Vector n4(pv3 - (pv3 * dir_[3]) * dir_[3]);
164  // double N3(n3.mag());
165  // double N4(n4.mag());
166  // bool close2=(N3<epsilon_||N4<epsilon_);
167  double r2(n3 * n4);
168  bool inside2(r2 <= 0.);
169  // // std::cout << " pv1 & pv3 " << pv1.mag() << " " << pv3.mag() << std::endl;
170  // // double tmp=(pv1-(pv1*dir_[1])*dir_[1])*(pv3-(pv3*dir_[3])*dir_[3]);
171  // // std::cout << " Computed tmp " << tmp << std::endl;
172  // if(debug)
173  // {
174  // std::cout << n3 << std::endl;
175  // std::cout << n4 << std::endl;
176  // std::cout << r2 << std::endl;
177  // std::cout << inside2 << std::endl;
178  // }
179  // if(!close2&&!inside2) return false;
180  // std::cout << " Second calculation " << std::endl;
181  // std::cout << " True " << std::endl;
182  // return (!close1&&!close2||(close2&&inside1||close1&&inside2));
183 
184  return inside2;
185 }
186 
187 /*
188 bool
189 CrystalPad::globalinside(XYZPoint point) const
190 {
191  // std::cout << " Global inside " << std::endl;
192  // std::cout << point << " " ;
193  ROOT::Math::Rotation3D r;
194  XYZVector t;
195  point = rotation_(point)+translation_;
196  // std::cout << point << std::endl;
197  // print();
198  CLHEP::Hep2Vector ppoint(point.X(),point.Y());
199  bool result=inside(ppoint);
200  // std::cout << " Result " << result << std::endl;
201  return result;
202 }
203 */
204 
205 void CrystalPad::print() const {
206  std::cout << " Corners " << std::endl;
207  std::cout << corners_[0] << std::endl;
208  std::cout << corners_[1] << std::endl;
209  std::cout << corners_[2] << std::endl;
210  std::cout << corners_[3] << std::endl;
211 }
212 
213 /*
214 CLHEP::Hep2Vector
215 CrystalPad::localPoint(XYZPoint point) const
216 {
217  point = rotation_(point)+translation_;
218  return CLHEP::Hep2Vector(point.X(),point.Y());
219 }
220 */
221 
222 CLHEP::Hep2Vector& CrystalPad::edge(unsigned iside, int n) { return corners_[(iside + n) % 4]; }
223 
224 CLHEP::Hep2Vector& CrystalPad::edge(CaloDirection dir) {
225  switch (dir) {
226  case NORTHWEST:
227  return corners_[0];
228  break;
229  case NORTHEAST:
230  return corners_[1];
231  break;
232  case SOUTHEAST:
233  return corners_[2];
234  break;
235  case SOUTHWEST:
236  return corners_[3];
237  break;
238  default: {
239  std::cout << " Serious problem in CrystalPad ! " << dir << std::endl;
240  return corners_[0];
241  }
242  }
243  return corners_[0];
244 }
245 
246 void CrystalPad::extrems(double& xmin, double& xmax, double& ymin, double& ymax) const {
247  xmin = ymin = 999;
248  xmax = ymax = -999;
249  for (unsigned ic = 0; ic < 4; ++ic) {
250  if (corners_[ic].x() < xmin)
251  xmin = corners_[ic].x();
252  if (corners_[ic].x() > xmax)
253  xmax = corners_[ic].x();
254  if (corners_[ic].y() < ymin)
255  ymin = corners_[ic].y();
256  if (corners_[ic].y() > ymax)
257  ymax = corners_[ic].y();
258  }
259 }
260 
262  // Find the centre-of-gravity of the Quad (after re-organization)
263  center_ = CLHEP::Hep2Vector(0., 0.);
264  for (unsigned ic = 0; ic < 4; ++ic)
265  center_ += corners_[ic];
266  center_ *= 0.25;
267 
268  // Rescale the corners to allow for some inaccuracies in
269  // in the inside test
270  for (unsigned ic = 0; ic < 4; ++ic)
271  corners_[ic] += 0.001 * (corners_[ic] - center_);
272 }
273 
274 std::ostream& operator<<(std::ostream& ost, CrystalPad& quad) {
275  ost << " Number " << quad.getNumber() << std::endl;
276  ost << NORTHWEST << quad.edge(NORTHWEST) << std::endl;
277  ost << NORTHEAST << quad.edge(NORTHEAST) << std::endl;
278  ost << SOUTHEAST << quad.edge(SOUTHEAST) << std::endl;
279  ost << SOUTHWEST << quad.edge(SOUTHWEST) << std::endl;
280 
281  return ost;
282 }
283 
284 void CrystalPad::getDrawingCoordinates(std::vector<float>& x, std::vector<float>& y) const {
285  x.clear();
286  y.clear();
287  x.push_back(corners_[0].x());
288  x.push_back(corners_[1].x());
289  x.push_back(corners_[2].x());
290  x.push_back(corners_[3].x());
291  x.push_back(corners_[0].x());
292  y.push_back(corners_[0].y());
293  y.push_back(corners_[1].y());
294  y.push_back(corners_[2].y());
295  y.push_back(corners_[3].y());
296  y.push_back(corners_[0].y());
297 }
double survivalProbability_
Definition: CrystalPad.h:109
bool dummy_
Definition: CrystalPad.h:112
double yscalefactor_
Definition: CrystalPad.h:113
ROOT::Math::Rotation3D rotation_
Definition: CrystalPad.h:107
static const char dir_[]
ROOT::Math::Transform3DPJ::Point Point
Definition: CrystalPad.h:18
void extrems(double &xmin, double &xmax, double &ymin, double &ymax) const
xmin xmax, ymin ymax of the quad
Definition: CrystalPad.cc:246
void resetCorners()
Rescale the Quad to allow for some inaccuracy ...
Definition: CrystalPad.cc:261
std::ostream & operator<<(std::ostream &ost, CrystalPad &quad)
Definition: CrystalPad.cc:274
void GetDecomposition(Rotation3D &r, Vector &v) const
CLHEP::Hep2Vector & edge(unsigned iside, int n)
access to the corners in direction iside; n=0,1
Definition: CrystalPad.cc:222
CrystalPad & operator=(const CrystalPad &rhs)
Definition: CrystalPad.cc:17
unsigned number_
Definition: CrystalPad.h:105
static std::vector< CLHEP::Hep2Vector > aVector
Definition: CrystalPad.h:101
ROOT::Math::Transform3DPJ Transform3D
Definition: CrystalPad.h:17
double epsilon_
Definition: CrystalPad.h:111
std::vector< double > vec1
Definition: HCALResponse.h:15
Transform3D trans_
Definition: CrystalPad.h:106
math::XYZVector XYZPoint
Definition: CrystalPad.h:16
std::vector< CLHEP::Hep2Vector > dir_
Definition: CrystalPad.h:104
math::XYZVector XYZVector
Definition: CrystalPad.h:15
XYZVector translation_
Definition: CrystalPad.h:108
bool inside(const CLHEP::Hep2Vector &point, bool debug=false) const
Check that the point (in the local frame) is inside the crystal.
Definition: CrystalPad.cc:127
#define debug
Definition: HDRShower.cc:19
std::vector< CLHEP::Hep2Vector > corners_
Definition: CrystalPad.h:103
CLHEP::Hep2Vector center_
Definition: CrystalPad.h:110
Structure Point Contains parameters of Gaussian fits to DMRs.
float x
void getDrawingCoordinates(std::vector< float > &x, std::vector< float > &y) const
for graphic debugging
Definition: CrystalPad.cc:284
unsigned getNumber() const
access to the number
Definition: CrystalPad.h:73
CaloDirection
Codes the local directions in the cell lattice.
Definition: CaloDirection.h:9
std::vector< vec1 > vec2
Definition: HCALResponse.h:16
void print() const
print
Definition: CrystalPad.cc:205