CMS 3D CMS Logo

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