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