Logo ROOT  
Reference Guide
TGeoTrd1.cxx
Go to the documentation of this file.
1 // @(#)root/geom:$Id$
2 // Author: Andrei Gheata 24/10/01
3 // TGeoTrd1::Contains() and DistFromInside() implemented by Mihaela Gheata
4 
5 /*************************************************************************
6  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
7  * All rights reserved. *
8  * *
9  * For the licensing terms see $ROOTSYS/LICENSE. *
10  * For the list of contributors see $ROOTSYS/README/CREDITS. *
11  *************************************************************************/
12 
13 /** \class TGeoTrd1
14 \ingroup Geometry_classes
15 A trapezoid with only x length varying with z. It has 4
16 parameters, the half length in x at the low z surface, that at the
17 high z surface, the half length in y, and in z
18 
19 Begin_Macro
20 {
21  TCanvas *c = new TCanvas("c", "c",0,0,600,600);
22  new TGeoManager("trd1", "poza8");
23  TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
24  TGeoMedium *med = new TGeoMedium("MED",1,mat);
25  TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
26  gGeoManager->SetTopVolume(top);
27  TGeoVolume *vol = gGeoManager->MakeTrd1("Trd1",med, 10,20,30,40);
28  vol->SetLineWidth(2);
29  top->AddNode(vol,1);
30  gGeoManager->CloseGeometry();
31  gGeoManager->SetNsegments(80);
32  top->Draw();
33  TView *view = gPad->GetView();
34  view->ShowAxis();
35 }
36 End_Macro
37 */
38 
39 #include <iostream>
40 
41 #include "TGeoManager.h"
42 #include "TGeoMatrix.h"
43 #include "TGeoVolume.h"
44 #include "TGeoTrd1.h"
45 #include "TMath.h"
46 
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// dummy ctor
51 
53 {
54  fDz = fDx1 = fDx2 = fDy = 0;
56 }
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// constructor.
60 
62  :TGeoBBox(0,0,0)
63 {
65  fDx1 = dx1;
66  fDx2 = dx2;
67  fDy = dy;
68  fDz = dz;
69  if ((dx1<0) || (dx2<0) || (dy<0) || (dz<0)) {
71  printf("trd1 : dx1=%f, dx2=%f, dy=%f, dz=%f\n",
72  dx1,dx2,dy,dz);
73  }
74  else ComputeBBox();
75 }
76 
77 ////////////////////////////////////////////////////////////////////////////////
78 /// constructor.
79 
80 TGeoTrd1::TGeoTrd1(const char *name, Double_t dx1, Double_t dx2, Double_t dy, Double_t dz)
81  :TGeoBBox(name, 0,0,0)
82 {
84  fDx1 = dx1;
85  fDx2 = dx2;
86  fDy = dy;
87  fDz = dz;
88  if ((dx1<0) || (dx2<0) || (dy<0) || (dz<0)) {
90  printf("trd1 : dx1=%f, dx2=%f, dy=%f, dz=%f\n",
91  dx1,dx2,dy,dz);
92  }
93  else ComputeBBox();
94 }
95 
96 ////////////////////////////////////////////////////////////////////////////////
97 /// ctor with an array of parameters
98 /// - param[0] = dx1
99 /// - param[1] = dx2
100 /// - param[2] = dy
101 /// - param[3] = dz
102 
104  :TGeoBBox(0,0,0)
105 {
107  SetDimensions(param);
108  if ((fDx1<0) || (fDx2<0) || (fDy<=0) || (fDz<=0)) SetShapeBit(kGeoRunTimeShape);
109  else ComputeBBox();
110 }
111 
112 ////////////////////////////////////////////////////////////////////////////////
113 /// destructor
114 
116 {
117 }
118 
119 ////////////////////////////////////////////////////////////////////////////////
120 /// Computes capacity of the shape in [length^3]
121 
123 {
124  Double_t capacity = 4.*(fDx1+fDx2)*fDy*fDz;
125  return capacity;
126 }
127 
128 ////////////////////////////////////////////////////////////////////////////////
129 /// compute bounding box for a trd1
130 
132 {
133  fDX = TMath::Max(fDx1, fDx2);
134  fDY = fDy;
135  fDZ = fDz;
136  memset(fOrigin, 0, 3*sizeof(Double_t));
137 }
138 
139 ////////////////////////////////////////////////////////////////////////////////
140 /// Compute normal to closest surface from POINT.
141 
142 void TGeoTrd1::ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm)
143 {
144  Double_t safe, safemin;
145  //--- Compute safety first
146  Double_t fx = 0.5*(fDx1-fDx2)/fDz;
147  Double_t calf = 1./TMath::Sqrt(1.0+fx*fx);
148  // check Z facettes
149  safe = safemin = TMath::Abs(fDz-TMath::Abs(point[2]));
150  norm[0] = norm[1] = 0;
151  norm[2] = (dir[2]>=0)?1:-1;
152  if (safe<1E-6) return;
153  // check X facettes
154  Double_t distx = 0.5*(fDx1+fDx2)-fx*point[2];
155  if (distx>=0) {
156  safe=TMath::Abs(distx-TMath::Abs(point[0]))*calf;
157  if (safe<safemin) {
158  safemin = safe;
159  norm[0] = (point[0]>0)?calf:(-calf);
160  norm[1] = 0;
161  norm[2] = calf*fx;
162  Double_t dot = norm[0]*dir[0]+norm[1]*dir[1]+norm[2]*dir[2];
163  if (dot<0) {
164  norm[0] = -norm[0];
165  norm[2] = -norm[2];
166  }
167  if (safe<1E-6) return;
168  }
169  }
170  // check Y facettes
171  safe = TMath::Abs(fDy-TMath::Abs(point[1]));
172  if (safe<safemin) {
173  norm[0] = norm[2] = 0;
174  norm[1] = (dir[1]>=0)?1:-1;
175  }
176 }
177 
178 ////////////////////////////////////////////////////////////////////////////////
179 /// test if point is inside this shape
180 /// check Z range
181 
182 Bool_t TGeoTrd1::Contains(const Double_t *point) const
183 {
184  if (TMath::Abs(point[2]) > fDz) return kFALSE;
185  // then y
186  if (TMath::Abs(point[1]) > fDy) return kFALSE;
187  // then x
188  Double_t dx = 0.5*(fDx2*(point[2]+fDz)+fDx1*(fDz-point[2]))/fDz;
189  if (TMath::Abs(point[0]) > dx) return kFALSE;
190  return kTRUE;
191 }
192 
193 ////////////////////////////////////////////////////////////////////////////////
194 /// Compute distance from inside point to surface of the trd1
195 /// Boundary safe algorithm.
196 
197 Double_t TGeoTrd1::DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact, Double_t step, Double_t *safe) const
198 {
199  if (iact<3 && safe) {
200  // compute safe distance
201  *safe = Safety(point, kTRUE);
202  if (iact==0) return TGeoShape::Big();
203  if (iact==1 && step<*safe) return TGeoShape::Big();
204  }
205 
206  //--- Compute safety first
207  Double_t fx = 0.5*(fDx1-fDx2)/fDz;
208  Double_t cn;
209  Double_t distx = 0.5*(fDx1+fDx2)-fx*point[2];
210  //--- Compute distance to this shape
211  // first check if Z facettes are crossed
212  Double_t dist[3];
213  for (Int_t i=0; i<3; i++) dist[i]=TGeoShape::Big();
214  if (dir[2]<0) {
215  dist[0]=-(point[2]+fDz)/dir[2];
216  } else if (dir[2]>0) {
217  dist[0]=(fDz-point[2])/dir[2];
218  }
219  if (dist[0]<=0) return 0.0;
220  // now check X facettes
221  cn = -dir[0]+fx*dir[2];
222  if (cn>0) {
223  dist[1] = point[0]+distx;
224  if (dist[1]<=0) return 0.0;
225  dist[1] /= cn;
226  }
227  cn = dir[0]+fx*dir[2];
228  if (cn>0) {
229  Double_t s = distx-point[0];
230  if (s<=0) return 0.0;
231  s /= cn;
232  if (s<dist[1]) dist[1] = s;
233  }
234  // now check Y facettes
235  if (dir[1]<0) {
236  dist[2]=-(point[1]+fDy)/dir[1];
237  } else if (dir[1]>0) {
238  dist[2]=(fDy-point[1])/dir[1];
239  }
240  if (dist[2]<=0) return 0.0;
241  return dist[TMath::LocMin(3,dist)];
242 }
243 
244 ////////////////////////////////////////////////////////////////////////////////
245 /// get the most visible corner from outside point and the normals
246 
247 void TGeoTrd1::GetVisibleCorner(const Double_t *point, Double_t *vertex, Double_t *normals) const
248 {
249  Double_t fx = 0.5*(fDx1-fDx2)/fDz;
250  Double_t calf = 1./TMath::Sqrt(1.0+fx*fx);
251  Double_t salf = calf*fx;
252  // check visibility of X faces
253  Double_t distx = 0.5*(fDx1+fDx2)-fx*point[2];
254  memset(normals, 0, 9*sizeof(Double_t));
255  TGeoTrd1 *trd1 = (TGeoTrd1*)this;
256  if (point[0]>distx) {
257  // hi x face visible
258  trd1->SetShapeBit(kGeoVisX);
259  normals[0]=calf;
260  normals[2]=salf;
261  } else {
262  trd1->SetShapeBit(kGeoVisX, kFALSE);
263  normals[0]=-calf;
264  normals[2]=salf;
265  }
266  if (point[1]>fDy) {
267  // hi y face visible
268  trd1->SetShapeBit(kGeoVisY);
269  normals[4]=1;
270  } else {
271  trd1->SetShapeBit(kGeoVisY, kFALSE);
272  normals[4]=-1;
273  }
274  if (point[2]>fDz) {
275  // hi z face visible
276  trd1->SetShapeBit(kGeoVisZ);
277  normals[8]=1;
278  } else {
279  trd1->SetShapeBit(kGeoVisZ, kFALSE);
280  normals[8]=-1;
281  }
282  SetVertex(vertex);
283 }
284 
285 ////////////////////////////////////////////////////////////////////////////////
286 /// get the opposite corner of the intersected face
287 
288 void TGeoTrd1::GetOppositeCorner(const Double_t * /*point*/, Int_t inorm, Double_t *vertex, Double_t *normals) const
289 {
290  TGeoTrd1 *trd1 = (TGeoTrd1*)this;
291  if (inorm != 0) {
292  // change x face
294  normals[0]=-normals[0];
295  }
296  if (inorm != 1) {
297  // change y face
299  normals[4]=-normals[4];
300  }
301  if (inorm != 2) {
302  // hi z face visible
304  normals[8]=-normals[8];
305  }
306  SetVertex(vertex);
307 }
308 
309 ////////////////////////////////////////////////////////////////////////////////
310 /// Compute distance from outside point to surface of the trd1
311 /// Boundary safe algorithm
312 
313 Double_t TGeoTrd1::DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact, Double_t step, Double_t *safe) const
314 {
315  if (iact<3 && safe) {
316  // compute safe distance
317  *safe = Safety(point, kFALSE);
318  if (iact==0) return TGeoShape::Big();
319  if (iact==1 && step<*safe) return TGeoShape::Big();
320  }
321  // find a visible face
322  Double_t xnew,ynew,znew;
323  Double_t fx = 0.5*(fDx1-fDx2)/fDz;
324  Double_t cn;
325  Double_t distx = 0.5*(fDx1+fDx2)-fx*point[2];
326  Bool_t in = kTRUE;
327  Double_t safx = distx-TMath::Abs(point[0]);
328  Double_t safy = fDy-TMath::Abs(point[1]);
329  Double_t safz = fDz-TMath::Abs(point[2]);
330 
331  //--- Compute distance to this shape
332  // first check if Z facettes are crossed
333  if (point[2]<=-fDz) {
334  if (dir[2]<=0) return TGeoShape::Big();
335  in = kFALSE;
336  Double_t snxt = -(fDz+point[2])/dir[2];
337  // find extrapolated X and Y
338  xnew = point[0]+snxt*dir[0];
339  if (TMath::Abs(xnew) <= fDx1) {
340  ynew = point[1]+snxt*dir[1];
341  if (TMath::Abs(ynew) <= fDy) return snxt;
342  }
343  } else if (point[2]>=fDz) {
344  if (dir[2]>=0) return TGeoShape::Big();
345  in = kFALSE;
346  Double_t snxt = (fDz-point[2])/dir[2];
347  // find extrapolated X and Y
348  xnew = point[0]+snxt*dir[0];
349  if (TMath::Abs(xnew) <= fDx2) {
350  ynew = point[1]+snxt*dir[1];
351  if (TMath::Abs(ynew) <= fDy) return snxt;
352  }
353  }
354  // check if X facettes are crossed
355  if (point[0]<=-distx) {
356  cn = -dir[0]+fx*dir[2];
357  if (cn>=0) return TGeoShape::Big();
358  in = kFALSE;
359  Double_t snxt = (point[0]+distx)/cn;
360  // find extrapolated Y and Z
361  ynew = point[1]+snxt*dir[1];
362  if (TMath::Abs(ynew) <= fDy) {
363  znew = point[2]+snxt*dir[2];
364  if (TMath::Abs(znew) <= fDz) return snxt;
365  }
366  }
367  if (point[0]>=distx) {
368  cn = dir[0]+fx*dir[2];
369  if (cn>=0) return TGeoShape::Big();
370  in = kFALSE;
371  Double_t snxt = (distx-point[0])/cn;
372  // find extrapolated Y and Z
373  ynew = point[1]+snxt*dir[1];
374  if (TMath::Abs(ynew) < fDy) {
375  znew = point[2]+snxt*dir[2];
376  if (TMath::Abs(znew) < fDz) return snxt;
377  }
378  }
379  // finally check Y facettes
380  if (point[1]<=-fDy) {
381  cn = -dir[1];
382  if (cn>=0) return TGeoShape::Big();
383  in = kFALSE;
384  Double_t snxt = (point[1]+fDy)/cn;
385  // find extrapolated X and Z
386  znew = point[2]+snxt*dir[2];
387  if (TMath::Abs(znew) < fDz) {
388  xnew = point[0]+snxt*dir[0];
389  Double_t dx = 0.5*(fDx1+fDx2)-fx*znew;
390  if (TMath::Abs(xnew) < dx) return snxt;
391  }
392  } else if (point[1]>=fDy) {
393  cn = dir[1];
394  if (cn>=0) return TGeoShape::Big();
395  in = kFALSE;
396  Double_t snxt = (fDy-point[1])/cn;
397  // find extrapolated X and Z
398  znew = point[2]+snxt*dir[2];
399  if (TMath::Abs(znew) < fDz) {
400  xnew = point[0]+snxt*dir[0];
401  Double_t dx = 0.5*(fDx1+fDx2)-fx*znew;
402  if (TMath::Abs(xnew) < dx) return snxt;
403  }
404  }
405  if (!in) return TGeoShape::Big();
406  // Point actually inside
407  if (safz<safx && safz<safy) {
408  if (point[2]*dir[2]>=0) return TGeoShape::Big();
409  return 0.0;
410  }
411  if (safy<safx) {
412  if (point[1]*dir[1]>=0) return TGeoShape::Big();
413  return 0.0;
414  }
415  cn = TMath::Sign(1.0,point[0])*dir[0]+fx*dir[2];
416  if (cn>=0) return TGeoShape::Big();
417  return 0.0;
418 }
419 
420 ////////////////////////////////////////////////////////////////////////////////
421 /// Divide this trd1 shape belonging to volume "voldiv" into ndiv volumes
422 /// called divname, from start position with the given step. Returns pointer
423 /// to created division cell volume in case of Y divisions. For Z divisions just
424 /// return the pointer to the volume to be divided. In case a wrong
425 /// division axis is supplied, returns pointer to volume that was divided.
426 
427 TGeoVolume *TGeoTrd1::Divide(TGeoVolume *voldiv, const char *divname, Int_t iaxis, Int_t ndiv,
428  Double_t start, Double_t step)
429 {
430  TGeoShape *shape; //--- shape to be created
431  TGeoVolume *vol; //--- division volume to be created
432  TGeoVolumeMulti *vmulti; //--- generic divided volume
433  TGeoPatternFinder *finder; //--- finder to be attached
434  TString opt = ""; //--- option to be attached
435  Double_t zmin, zmax, dx1n, dx2n;
436  Int_t id;
437  Double_t end = start+ndiv*step;
438  switch (iaxis) {
439  case 1:
440  Warning("Divide", "dividing a Trd1 on X not implemented");
441  return 0;
442  case 2:
443  finder = new TGeoPatternY(voldiv, ndiv, start, end);
444  voldiv->SetFinder(finder);
445  finder->SetDivIndex(voldiv->GetNdaughters());
446  shape = new TGeoTrd1(fDx1, fDx2, step/2, fDz);
447  vol = new TGeoVolume(divname, shape, voldiv->GetMedium());
448  vmulti = gGeoManager->MakeVolumeMulti(divname, voldiv->GetMedium());
449  vmulti->AddVolume(vol);
450  opt = "Y";
451  for (id=0; id<ndiv; id++) {
452  voldiv->AddNodeOffset(vol, id, start+step/2+id*step, opt.Data());
453  ((TGeoNodeOffset*)voldiv->GetNodes()->At(voldiv->GetNdaughters()-1))->SetFinder(finder);
454  }
455  return vmulti;
456  case 3:
457  finder = new TGeoPatternZ(voldiv, ndiv, start, end);
458  voldiv->SetFinder(finder);
459  finder->SetDivIndex(voldiv->GetNdaughters());
460  vmulti = gGeoManager->MakeVolumeMulti(divname, voldiv->GetMedium());
461  for (id=0; id<ndiv; id++) {
462  zmin = start+id*step;
463  zmax = start+(id+1)*step;
464  dx1n = 0.5*(fDx1*(fDz-zmin)+fDx2*(fDz+zmin))/fDz;
465  dx2n = 0.5*(fDx1*(fDz-zmax)+fDx2*(fDz+zmax))/fDz;
466  shape = new TGeoTrd1(dx1n, dx2n, fDy, step/2.);
467  vol = new TGeoVolume(divname, shape, voldiv->GetMedium());
468  vmulti->AddVolume(vol);
469  opt = "Z";
470  voldiv->AddNodeOffset(vol, id, start+step/2+id*step, opt.Data());
471  ((TGeoNodeOffset*)voldiv->GetNodes()->At(voldiv->GetNdaughters()-1))->SetFinder(finder);
472  }
473  return vmulti;
474  default:
475  Error("Divide", "Wrong axis type for division");
476  return 0;
477  }
478 }
479 
480 ////////////////////////////////////////////////////////////////////////////////
481 /// Get range of shape for a given axis.
482 
484 {
485  xlo = 0;
486  xhi = 0;
487  Double_t dx = 0;
488  switch (iaxis) {
489  case 2:
490  xlo = -fDy;
491  xhi = fDy;
492  dx = xhi-xlo;
493  return dx;
494  case 3:
495  xlo = -fDz;
496  xhi = fDz;
497  dx = xhi-xlo;
498  return dx;
499  }
500  return dx;
501 }
502 
503 ////////////////////////////////////////////////////////////////////////////////
504 /// Fill vector param[4] with the bounding cylinder parameters. The order
505 /// is the following : Rmin, Rmax, Phi1, Phi2
506 
508 {
510 }
511 
512 ////////////////////////////////////////////////////////////////////////////////
513 /// Fills real parameters of a positioned box inside this. Returns 0 if successful.
514 
515 Int_t TGeoTrd1::GetFittingBox(const TGeoBBox *parambox, TGeoMatrix *mat, Double_t &dx, Double_t &dy, Double_t &dz) const
516 {
517  dx=dy=dz=0;
518  if (mat->IsRotation()) {
519  Error("GetFittingBox", "cannot handle parametrized rotated volumes");
520  return 1; // ### rotation not accepted ###
521  }
522  //--> translate the origin of the parametrized box to the frame of this box.
523  Double_t origin[3];
524  mat->LocalToMaster(parambox->GetOrigin(), origin);
525  if (!Contains(origin)) {
526  Error("GetFittingBox", "wrong matrix - parametrized box is outside this");
527  return 1; // ### wrong matrix ###
528  }
529  //--> now we have to get the valid range for all parametrized axis
530  Double_t dd[3];
531  dd[0] = parambox->GetDX();
532  dd[1] = parambox->GetDY();
533  dd[2] = parambox->GetDZ();
534  //-> check if Z range is fixed
535  if (dd[2]<0) {
536  dd[2] = TMath::Min(origin[2]+fDz, fDz-origin[2]);
537  if (dd[2]<0) {
538  Error("GetFittingBox", "wrong matrix");
539  return 1;
540  }
541  }
542  //-> check if Y range is fixed
543  if (dd[1]<0) {
544  dd[1] = TMath::Min(origin[1]+fDy, fDy-origin[1]);
545  if (dd[1]<0) {
546  Error("GetFittingBox", "wrong matrix");
547  return 1;
548  }
549  }
550  if (dd[0]>=0) {
551  dx = dd[0];
552  dy = dd[1];
553  dz = dd[2];
554  return 0;
555  }
556  //-> check now range at Z = origin[2] +/- dd[2]
557  Double_t fx = 0.5*(fDx1-fDx2)/fDz;
558  Double_t dx0 = 0.5*(fDx1+fDx2);
559  Double_t z=origin[2]-dd[2];
560  dd[0] = dx0-fx*z-origin[0];
561  z=origin[2]+dd[2];
562  dd[0] = TMath::Min(dd[0], dx0-fx*z-origin[0]);
563  if (dd[0]<0) {
564  Error("GetFittingBox", "wrong matrix");
565  return 1;
566  }
567  dx = dd[0];
568  dy = dd[1];
569  dz = dd[2];
570  return 0;
571 }
572 
573 ////////////////////////////////////////////////////////////////////////////////
574 /// in case shape has some negative parameters, these has to be computed
575 /// in order to fit the mother
576 
578 {
579  if (!TestShapeBit(kGeoRunTimeShape)) return 0;
580  if (!mother->TestShapeBit(kGeoTrd1)) {
581  Error("GetMakeRuntimeShape", "invalid mother");
582  return 0;
583  }
584  Double_t dx1, dx2, dy, dz;
585  if (fDx1<0) dx1=((TGeoTrd1*)mother)->GetDx1();
586  else dx1=fDx1;
587  if (fDx2<0) dx2=((TGeoTrd1*)mother)->GetDx2();
588  else dx2=fDx2;
589  if (fDy<0) dy=((TGeoTrd1*)mother)->GetDy();
590  else dy=fDy;
591  if (fDz<0) dz=((TGeoTrd1*)mother)->GetDz();
592  else dz=fDz;
593 
594  return (new TGeoTrd1(dx1, dx2, dy, dz));
595 }
596 
597 ////////////////////////////////////////////////////////////////////////////////
598 /// print shape parameters
599 
601 {
602  printf("*** Shape %s: TGeoTrd1 ***\n", GetName());
603  printf(" dx1 = %11.5f\n", fDx1);
604  printf(" dx2 = %11.5f\n", fDx2);
605  printf(" dy = %11.5f\n", fDy);
606  printf(" dz = %11.5f\n", fDz);
607  printf(" Bounding box:\n");
609 }
610 
611 ////////////////////////////////////////////////////////////////////////////////
612 /// computes the closest distance from given point to this shape, according
613 /// to option. The matching point on the shape is stored in spoint.
614 
615 Double_t TGeoTrd1::Safety(const Double_t *point, Bool_t in) const
616 {
617  Double_t saf[3];
618  //--- Compute safety first
619  // check Z facettes
620  saf[0] = fDz-TMath::Abs(point[2]);
621  Double_t fx = 0.5*(fDx1-fDx2)/fDz;
622  Double_t calf = 1./TMath::Sqrt(1.0+fx*fx);
623  // check X facettes
624  Double_t distx = 0.5*(fDx1+fDx2)-fx*point[2];
625  if (distx<0) saf[1]=TGeoShape::Big();
626  else saf[1]=(distx-TMath::Abs(point[0]))*calf;
627  // check Y facettes
628  saf[2] = fDy-TMath::Abs(point[1]);
629  if (in) return saf[TMath::LocMin(3,saf)];
630  for (Int_t i=0; i<3; i++) saf[i]=-saf[i];
631  return saf[TMath::LocMax(3,saf)];
632 }
633 
634 ////////////////////////////////////////////////////////////////////////////////
635 /// Save a primitive as a C++ statement(s) on output stream "out".
636 
637 void TGeoTrd1::SavePrimitive(std::ostream &out, Option_t * /*option*/ /*= ""*/)
638 {
639  if (TObject::TestBit(kGeoSavePrimitive)) return;
640  out << " // Shape: " << GetName() << " type: " << ClassName() << std::endl;
641  out << " dx1 = " << fDx1 << ";" << std::endl;
642  out << " dx2 = " << fDx2 << ";" << std::endl;
643  out << " dy = " << fDy << ";" << std::endl;
644  out << " dz = " << fDZ << ";" << std::endl;
645  out << " TGeoShape *" << GetPointerName() << " = new TGeoTrd1(\"" << GetName() << "\", dx1,dx2,dy,dz);" << std::endl;
647 }
648 
649 ////////////////////////////////////////////////////////////////////////////////
650 /// set trd1 params in one step :
651 
653 {
654  fDx1 = param[0];
655  fDx2 = param[1];
656  fDy = param[2];
657  fDz = param[3];
658  ComputeBBox();
659 }
660 
661 ////////////////////////////////////////////////////////////////////////////////
662 /// set vertex of a corner according to visibility flags
663 
665 {
666  if (TestShapeBit(kGeoVisX)) {
667  if (TestShapeBit(kGeoVisZ)) {
668  vertex[0] = fDx2;
669  vertex[2] = fDz;
671  } else {
672  vertex[0] = fDx1;
673  vertex[2] = -fDz;
675  }
676  } else {
677  if (TestShapeBit(kGeoVisZ)) {
678  vertex[0] = -fDx2;
679  vertex[2] = fDz;
681  } else {
682  vertex[0] = -fDx1;
683  vertex[2] = -fDz;
685  }
686  }
687 }
688 
689 ////////////////////////////////////////////////////////////////////////////////
690 /// create arb8 mesh points
691 
693 {
694  if (!points) return;
695  points[ 0] = -fDx1; points[ 1] = -fDy; points[ 2] = -fDz;
696  points[ 3] = -fDx1; points[ 4] = fDy; points[ 5] = -fDz;
697  points[ 6] = fDx1; points[ 7] = fDy; points[ 8] = -fDz;
698  points[ 9] = fDx1; points[10] = -fDy; points[11] = -fDz;
699  points[12] = -fDx2; points[13] = -fDy; points[14] = fDz;
700  points[15] = -fDx2; points[16] = fDy; points[17] = fDz;
701  points[18] = fDx2; points[19] = fDy; points[20] = fDz;
702  points[21] = fDx2; points[22] = -fDy; points[23] = fDz;
703 }
704 
705 ////////////////////////////////////////////////////////////////////////////////
706 /// create arb8 mesh points
707 
709 {
710  if (!points) return;
711  points[ 0] = -fDx1; points[ 1] = -fDy; points[ 2] = -fDz;
712  points[ 3] = -fDx1; points[ 4] = fDy; points[ 5] = -fDz;
713  points[ 6] = fDx1; points[ 7] = fDy; points[ 8] = -fDz;
714  points[ 9] = fDx1; points[10] = -fDy; points[11] = -fDz;
715  points[12] = -fDx2; points[13] = -fDy; points[14] = fDz;
716  points[15] = -fDx2; points[16] = fDy; points[17] = fDz;
717  points[18] = fDx2; points[19] = fDy; points[20] = fDz;
718  points[21] = fDx2; points[22] = -fDy; points[23] = fDz;
719 }
720 
721 ////////////////////////////////////////////////////////////////////////////////
722 /// fill size of this 3-D object
723 
724 void TGeoTrd1::Sizeof3D() const
725 {
727 }
728 
729 ////////////////////////////////////////////////////////////////////////////////
730 /// Check the inside status for each of the points in the array.
731 /// Input: Array of point coordinates + vector size
732 /// Output: Array of Booleans for the inside of each point
733 
734 void TGeoTrd1::Contains_v(const Double_t *points, Bool_t *inside, Int_t vecsize) const
735 {
736  for (Int_t i=0; i<vecsize; i++) inside[i] = Contains(&points[3*i]);
737 }
738 
739 ////////////////////////////////////////////////////////////////////////////////
740 /// Compute the normal for an array o points so that norm.dot.dir is positive
741 /// Input: Arrays of point coordinates and directions + vector size
742 /// Output: Array of normal directions
743 
744 void TGeoTrd1::ComputeNormal_v(const Double_t *points, const Double_t *dirs, Double_t *norms, Int_t vecsize)
745 {
746  for (Int_t i=0; i<vecsize; i++) ComputeNormal(&points[3*i], &dirs[3*i], &norms[3*i]);
747 }
748 
749 ////////////////////////////////////////////////////////////////////////////////
750 /// Compute distance from array of input points having directions specified by dirs. Store output in dists
751 
752 void TGeoTrd1::DistFromInside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t* step) const
753 {
754  for (Int_t i=0; i<vecsize; i++) dists[i] = DistFromInside(&points[3*i], &dirs[3*i], 3, step[i]);
755 }
756 
757 ////////////////////////////////////////////////////////////////////////////////
758 /// Compute distance from array of input points having directions specified by dirs. Store output in dists
759 
760 void TGeoTrd1::DistFromOutside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t* step) const
761 {
762  for (Int_t i=0; i<vecsize; i++) dists[i] = DistFromOutside(&points[3*i], &dirs[3*i], 3, step[i]);
763 }
764 
765 ////////////////////////////////////////////////////////////////////////////////
766 /// Compute safe distance from each of the points in the input array.
767 /// Input: Array of point coordinates, array of statuses for these points, size of the arrays
768 /// Output: Safety values
769 
770 void TGeoTrd1::Safety_v(const Double_t *points, const Bool_t *inside, Double_t *safe, Int_t vecsize) const
771 {
772  for (Int_t i=0; i<vecsize; i++) safe[i] = Safety(&points[3*i], inside[i]);
773 }
vertex
REAL * vertex
Definition: triangle.c:513
TGeoTrd1::GetAxisRange
virtual Double_t GetAxisRange(Int_t iaxis, Double_t &xlo, Double_t &xhi) const
Get range of shape for a given axis.
Definition: TGeoTrd1.cxx:483
TGeoVolume::SetFinder
void SetFinder(TGeoPatternFinder *finder)
Definition: TGeoVolume.h:231
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:100
TObject::TestBit
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:187
TGeoVolume::GetNdaughters
Int_t GetNdaughters() const
Definition: TGeoVolume.h:349
Option_t
const char Option_t
Definition: RtypesCore.h:66
TMath::Max
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
TGeoTrd1::~TGeoTrd1
virtual ~TGeoTrd1()
destructor
Definition: TGeoTrd1.cxx:115
gGeoManager
R__EXTERN TGeoManager * gGeoManager
Definition: TGeoManager.h:602
TString::Data
const char * Data() const
Definition: TString.h:369
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TGeoTrd1::GetBoundingCylinder
virtual void GetBoundingCylinder(Double_t *param) const
Fill vector param[4] with the bounding cylinder parameters.
Definition: TGeoTrd1.cxx:507
TGeoTrd1::Safety_v
virtual void Safety_v(const Double_t *points, const Bool_t *inside, Double_t *safe, Int_t vecsize) const
Compute safe distance from each of the points in the input array.
Definition: TGeoTrd1.cxx:770
TObject::Error
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:893
TGeoTrd1::GetFittingBox
virtual Int_t GetFittingBox(const TGeoBBox *parambox, TGeoMatrix *mat, Double_t &dx, Double_t &dy, Double_t &dz) const
Fills real parameters of a positioned box inside this. Returns 0 if successful.
Definition: TGeoTrd1.cxx:515
TMath::Sqrt
Double_t Sqrt(Double_t x)
Definition: TMath.h:691
TGeoShape::kGeoTrd1
@ kGeoTrd1
Definition: TGeoShape.h:57
TGeoBBox::fOrigin
Double_t fOrigin[3]
Definition: TGeoBBox.h:24
Float_t
float Float_t
Definition: RtypesCore.h:57
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:162
TGeoVolume.h
TGeoBBox::GetDZ
virtual Double_t GetDZ() const
Definition: TGeoBBox.h:76
TGeoTrd1::SetPoints
virtual void SetPoints(Double_t *points) const
create arb8 mesh points
Definition: TGeoTrd1.cxx:692
TGeoTrd1::TGeoTrd1
TGeoTrd1()
dummy ctor
Definition: TGeoTrd1.cxx:52
TGeoNodeOffset
Node containing an offset.
Definition: TGeoNode.h:184
TGeoShape::SetShapeBit
void SetShapeBit(UInt_t f, Bool_t set)
Equivalent of TObject::SetBit.
Definition: TGeoShape.cxx:524
TMath::Abs
Short_t Abs(Short_t d)
Definition: TMathBase.h:120
TGeoTrd1::DistFromOutside_v
virtual void DistFromOutside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t *step) const
Compute distance from array of input points having directions specified by dirs. Store output in dist...
Definition: TGeoTrd1.cxx:760
TObjArray::At
TObject * At(Int_t idx) const
Definition: TObjArray.h:166
TString
Basic string class.
Definition: TString.h:136
TGeoTrd1::ComputeNormal
virtual void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm)
Compute normal to closest surface from POINT.
Definition: TGeoTrd1.cxx:142
TMath::LocMax
Long64_t LocMax(Long64_t n, const T *a)
Return index of array with the maximum element.
Definition: TMath.h:1000
TGeoTrd1::fDy
Double_t fDy
Definition: TGeoTrd1.h:23
TGeoTrd1::SetDimensions
virtual void SetDimensions(Double_t *param)
set trd1 params in one step :
Definition: TGeoTrd1.cxx:652
TGeoTrd1::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TGeoTrd1.cxx:637
TGeoTrd1::fDx1
Double_t fDx1
Definition: TGeoTrd1.h:21
TGeoPatternFinder
Base finder class for patterns.
Definition: TGeoPatternFinder.h:32
bool
TGeoShape::TestShapeBit
Bool_t TestShapeBit(UInt_t f) const
Definition: TGeoShape.h:163
TGeoTrd1::fDx2
Double_t fDx2
Definition: TGeoTrd1.h:22
TGeoVolume::GetMedium
TGeoMedium * GetMedium() const
Definition: TGeoVolume.h:173
id
XFontStruct * id
Definition: TGX11.cxx:109
TGeoTrd1::ComputeBBox
virtual void ComputeBBox()
compute bounding box for a trd1
Definition: TGeoTrd1.cxx:131
TGeoVolumeMulti::AddVolume
void AddVolume(TGeoVolume *vol)
Add a volume with valid shape to the list of volumes.
Definition: TGeoVolume.cxx:2420
TGeoTrd1::Contains
virtual Bool_t Contains(const Double_t *point) const
test if point is inside this shape check Z range
Definition: TGeoTrd1.cxx:182
ROOT::Math::gv_detail::dist
double dist(Rotation3D const &r1, Rotation3D const &r2)
Definition: 3DDistances.cxx:48
TGeoTrd1::Capacity
virtual Double_t Capacity() const
Computes capacity of the shape in [length^3].
Definition: TGeoTrd1.cxx:122
TGeoBBox::GetDX
virtual Double_t GetDX() const
Definition: TGeoBBox.h:74
TMath::LocMin
Long64_t LocMin(Long64_t n, const T *a)
Return index of array with the minimum element.
Definition: TMath.h:972
TGeoTrd1::Contains_v
virtual void Contains_v(const Double_t *points, Bool_t *inside, Int_t vecsize) const
Check the inside status for each of the points in the array.
Definition: TGeoTrd1.cxx:734
TGeoShape
Base abstract class for all shapes.
Definition: TGeoShape.h:26
TGeoTrd1::GetMakeRuntimeShape
virtual TGeoShape * GetMakeRuntimeShape(TGeoShape *mother, TGeoMatrix *mat) const
in case shape has some negative parameters, these has to be computed in order to fit the mother
Definition: TGeoTrd1.cxx:577
TGeoTrd1.h
TGeoBBox::InspectShape
virtual void InspectShape() const
Prints shape parameters.
Definition: TGeoBBox.cxx:790
TObject::SetBit
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:696
TGeoBBox::fDY
Double_t fDY
Definition: TGeoBBox.h:22
TGeoVolume::GetNodes
TObjArray * GetNodes()
Definition: TGeoVolume.h:167
TGeoShape::kGeoVisY
@ kGeoVisY
Definition: TGeoShape.h:39
TGeoBBox::GetBoundingCylinder
virtual void GetBoundingCylinder(Double_t *param) const
Fill vector param[4] with the bounding cylinder parameters.
Definition: TGeoBBox.cxx:580
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:101
TMath::Sign
T1 Sign(T1 a, T2 b)
Definition: TMathBase.h:165
TGeoMatrix::IsRotation
Bool_t IsRotation() const
Definition: TGeoMatrix.h:68
TGeoShape::kGeoSavePrimitive
@ kGeoSavePrimitive
Definition: TGeoShape.h:65
TGeoTrd1::ComputeNormal_v
virtual void ComputeNormal_v(const Double_t *points, const Double_t *dirs, Double_t *norms, Int_t vecsize)
Compute the normal for an array o points so that norm.dot.dir is positive Input: Arrays of point coor...
Definition: TGeoTrd1.cxx:744
TGeoShape::kGeoRunTimeShape
@ kGeoRunTimeShape
Definition: TGeoShape.h:41
TGeoPatternFinder::SetDivIndex
void SetDivIndex(Int_t index)
Definition: TGeoPatternFinder.h:99
TGeoShape::GetName
virtual const char * GetName() const
Get the shape name.
Definition: TGeoShape.cxx:248
TGeoShape::kGeoVisX
@ kGeoVisX
Definition: TGeoShape.h:38
TGeoBBox::GetOrigin
virtual const Double_t * GetOrigin() const
Definition: TGeoBBox.h:77
TGeoBBox
Box class.
Definition: TGeoBBox.h:18
TGeoTrd1::SetVertex
void SetVertex(Double_t *vertex) const
set vertex of a corner according to visibility flags
Definition: TGeoTrd1.cxx:664
TGeoMatrix::LocalToMaster
virtual void LocalToMaster(const Double_t *local, Double_t *master) const
convert a point by multiplying its column vector (x, y, z, 1) to matrix inverse
Definition: TGeoMatrix.cxx:339
TObject::Warning
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:879
TMath::Min
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:180
TGeoMatrix.h
TGeoManager.h
TGeoBBox::fDZ
Double_t fDZ
Definition: TGeoBBox.h:23
TGeoTrd1::Sizeof3D
virtual void Sizeof3D() const
fill size of this 3-D object
Definition: TGeoTrd1.cxx:724
TGeoTrd1::DistFromInside_v
virtual void DistFromInside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t *step) const
Compute distance from array of input points having directions specified by dirs. Store output in dist...
Definition: TGeoTrd1.cxx:752
TGeoShape::kGeoVisZ
@ kGeoVisZ
Definition: TGeoShape.h:40
TGeoShape::GetPointerName
const char * GetPointerName() const
Provide a pointer name containing uid.
Definition: TGeoShape.cxx:699
TGeoTrd1
A trapezoid with only x length varying with z.
Definition: TGeoTrd1.h:18
Double_t
double Double_t
Definition: RtypesCore.h:59
TGeoMatrix
Geometrical transformation package.
Definition: TGeoMatrix.h:41
TGeoManager::MakeVolumeMulti
TGeoVolumeMulti * MakeVolumeMulti(const char *name, TGeoMedium *medium)
Make a TGeoVolumeMulti handling a list of volumes.
Definition: TGeoManager.cxx:3310
TGeoBBox::GetDY
virtual Double_t GetDY() const
Definition: TGeoBBox.h:75
TGeoVolumeMulti
Volume families.
Definition: TGeoVolume.h:254
TGeoTrd1::DistFromInside
virtual Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=0) const
Compute distance from inside point to surface of the trd1 Boundary safe algorithm.
Definition: TGeoTrd1.cxx:197
TGeoPatternZ
Definition: TGeoPatternFinder.h:185
points
point * points
Definition: X3DBuffer.c:22
name
char name[80]
Definition: TGX11.cxx:110
TGeoTrd1::InspectShape
virtual void InspectShape() const
print shape parameters
Definition: TGeoTrd1.cxx:600
TGeoTrd1::Divide
virtual TGeoVolume * Divide(TGeoVolume *voldiv, const char *divname, Int_t iaxis, Int_t ndiv, Double_t start, Double_t step)
Divide this trd1 shape belonging to volume "voldiv" into ndiv volumes called divname,...
Definition: TGeoTrd1.cxx:427
TGeoTrd1::fDz
Double_t fDz
Definition: TGeoTrd1.h:24
TGeoShape::Big
static Double_t Big()
Definition: TGeoShape.h:88
TGeoVolume::AddNodeOffset
void AddNodeOffset(TGeoVolume *vol, Int_t copy_no, Double_t offset=0, Option_t *option="")
Add a division node to the list of nodes.
Definition: TGeoVolume.cxx:971
TGeoTrd1::GetVisibleCorner
void GetVisibleCorner(const Double_t *point, Double_t *vertex, Double_t *normals) const
get the most visible corner from outside point and the normals
Definition: TGeoTrd1.cxx:247
TGeoBBox::Sizeof3D
virtual void Sizeof3D() const
Definition: TGeoBBox.cxx:993
TObject::ClassName
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:130
TGeoTrd1::Safety
virtual Double_t Safety(const Double_t *point, Bool_t in=kTRUE) const
computes the closest distance from given point to this shape, according to option.
Definition: TGeoTrd1.cxx:615
TMath::E
constexpr Double_t E()
Base of natural log:
Definition: TMath.h:96
TGeoVolume
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition: TGeoVolume.h:49
TGeoBBox::fDX
Double_t fDX
Definition: TGeoBBox.h:21
TGeoTrd1::DistFromOutside
virtual Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=0) const
Compute distance from outside point to surface of the trd1 Boundary safe algorithm.
Definition: TGeoTrd1.cxx:313
TMath.h
int
TGeoPatternY
Definition: TGeoPatternFinder.h:152
TGeoTrd1::GetOppositeCorner
void GetOppositeCorner(const Double_t *point, Int_t inorm, Double_t *vertex, Double_t *normals) const
get the opposite corner of the intersected face
Definition: TGeoTrd1.cxx:288