CMS 3D CMS Logo

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