diff --git a/geom/geom/inc/TGeoCone.h b/geom/geom/inc/TGeoCone.h index 54831a03f95a919b8666c8fb27da6f9801660227..1ae7980a7a4627baf7c67a6e0289affaf907f4e6 100644 --- a/geom/geom/inc/TGeoCone.h +++ b/geom/geom/inc/TGeoCone.h @@ -124,6 +124,16 @@ protected: // data members Double_t fPhi1; // first phi limit Double_t fPhi2; // second phi limit + // Transient trigonometric data + Double_t fS1; //!sin(phi1) + Double_t fC1; //!cos(phi1) + Double_t fS2; //!sin(phi2) + Double_t fC2; //!cos(phi2) + Double_t fSm; //!sin(0.5*(phi1+phi2)) + Double_t fCm; //!cos(0.5*(phi1+phi2)) + Double_t fCdfi; //!cos(0.5*(phi1-phi2)) + + void InitTrigonometry(); public: // constructors @@ -136,6 +146,7 @@ public: // destructor virtual ~TGeoConeSeg(); // methods + virtual void AfterStreamer(); virtual Double_t Capacity() const; static Double_t Capacity(Double_t dz, Double_t rmin1, Double_t rmax1, Double_t rmin2, Double_t rmax2, Double_t phi1, Double_t phi2); virtual void ComputeBBox(); diff --git a/geom/geom/inc/TGeoShape.h b/geom/geom/inc/TGeoShape.h index d9595128bad20fe5016f4f670ef1ef7f4e7dadc4..51452086f977990e8df09c82d751ed4cdb3a7ee5 100644 --- a/geom/geom/inc/TGeoShape.h +++ b/geom/geom/inc/TGeoShape.h @@ -101,6 +101,7 @@ public: static Double_t Tolerance() {return 1.E-10;} static Double_t ComputeEpsMch(); static Double_t EpsMch(); + virtual void AfterStreamer() {}; virtual Double_t Capacity() const = 0; void CheckShape(Int_t testNo, Int_t nsamples=10000, Option_t *option=""); virtual void ComputeBBox() = 0; diff --git a/geom/geom/inc/TGeoTube.h b/geom/geom/inc/TGeoTube.h index 19e3e6448010579663f3f98000edc4cc24820552..c606fa1fc9013abf67a1f07650b8836edf9d0c56 100644 --- a/geom/geom/inc/TGeoTube.h +++ b/geom/geom/inc/TGeoTube.h @@ -111,6 +111,16 @@ protected: // data members Double_t fPhi1; // first phi limit Double_t fPhi2; // second phi limit + // Transient trigonometric data + Double_t fS1; //!sin(phi1) + Double_t fC1; //!cos(phi1) + Double_t fS2; //!sin(phi2) + Double_t fC2; //!cos(phi2) + Double_t fSm; //!sin(0.5*(phi1+phi2)) + Double_t fCm; //!cos(0.5*(phi1+phi2)) + Double_t fCdfi; //!cos(0.5*(phi1-phi2)) + + void InitTrigonometry(); public: // constructors @@ -123,6 +133,7 @@ public: // destructor virtual ~TGeoTubeSeg(); // methods + virtual void AfterStreamer(); virtual Double_t Capacity() const; static Double_t Capacity(Double_t rmin, Double_t rmax, Double_t dz, Double_t phi1, Double_t phi2); virtual void ComputeBBox(); diff --git a/geom/geom/src/TGeoCone.cxx b/geom/geom/src/TGeoCone.cxx index d5edc4c456ce0bd183d9238f202573d4aac1f6d5..c9a77fd3f727c889a494e96dfcdf82bdabe9a71c 100644 --- a/geom/geom/src/TGeoCone.cxx +++ b/geom/geom/src/TGeoCone.cxx @@ -1152,6 +1152,8 @@ ClassImp(TGeoConeSeg) //_____________________________________________________________________________ TGeoConeSeg::TGeoConeSeg() + :TGeoCone(), + fPhi1(0.), fPhi2(0.), fS1(0.), fC1(0.), fS2(0.), fC2(0.), fSm(0.), fCm(0.), fCdfi(0.) { // Default constructor SetShapeBit(TGeoShape::kGeoConeSeg); @@ -1161,7 +1163,9 @@ TGeoConeSeg::TGeoConeSeg() //_____________________________________________________________________________ TGeoConeSeg::TGeoConeSeg(Double_t dz, Double_t rmin1, Double_t rmax1, Double_t rmin2, Double_t rmax2, Double_t phi1, Double_t phi2) - :TGeoCone(dz, rmin1, rmax1, rmin2, rmax2) + :TGeoCone(dz, rmin1, rmax1, rmin2, rmax2), + fPhi1(0.), fPhi2(0.), fS1(0.), fC1(0.), fS2(0.), fC2(0.), fSm(0.), fCm(0.), fCdfi(0.) + { // Default constructor specifying minimum and maximum radius SetShapeBit(TGeoShape::kGeoConeSeg); @@ -1172,7 +1176,8 @@ TGeoConeSeg::TGeoConeSeg(Double_t dz, Double_t rmin1, Double_t rmax1, //_____________________________________________________________________________ TGeoConeSeg::TGeoConeSeg(const char *name, Double_t dz, Double_t rmin1, Double_t rmax1, Double_t rmin2, Double_t rmax2, Double_t phi1, Double_t phi2) - :TGeoCone(name, dz, rmin1, rmax1, rmin2, rmax2) + :TGeoCone(name, dz, rmin1, rmax1, rmin2, rmax2), + fPhi1(0.), fPhi2(0.), fS1(0.), fC1(0.), fS2(0.), fC2(0.), fSm(0.), fCm(0.), fCdfi(0.) { // Default constructor specifying minimum and maximum radius SetShapeBit(TGeoShape::kGeoConeSeg); @@ -1182,7 +1187,8 @@ TGeoConeSeg::TGeoConeSeg(const char *name, Double_t dz, Double_t rmin1, Double_t //_____________________________________________________________________________ TGeoConeSeg::TGeoConeSeg(Double_t *param) - :TGeoCone(0,0,0,0,0) + :TGeoCone(0,0,0,0,0), + fPhi1(0.), fPhi2(0.), fS1(0.), fC1(0.), fS2(0.), fC2(0.), fSm(0.), fCm(0.), fCdfi(0.) { // Default constructor specifying minimum and maximum radius // param[0] = dz @@ -1203,6 +1209,30 @@ TGeoConeSeg::~TGeoConeSeg() // destructor } +//_____________________________________________________________________________ +void TGeoConeSeg::AfterStreamer() +{ +// Function called after streaming an object of this class. + InitTrigonometry(); +} + +//_____________________________________________________________________________ +void TGeoConeSeg::InitTrigonometry() +{ +// Init frequently used trigonometric values + Double_t phi1 = fPhi1*TMath::DegToRad(); + Double_t phi2 = fPhi2*TMath::DegToRad(); + fC1 = TMath::Cos(phi1); + fS1 = TMath::Sin(phi1); + fC2 = TMath::Cos(phi2); + fS2 = TMath::Sin(phi2); + Double_t fio = 0.5*(phi1+phi2); + fCm = TMath::Cos(fio); + fSm = TMath::Sin(fio); + Double_t dfi = 0.5*(phi2-phi1); + fCdfi = TMath::Cos(dfi); +} + //_____________________________________________________________________________ Double_t TGeoConeSeg::Capacity() const { @@ -1230,14 +1260,14 @@ void TGeoConeSeg::ComputeBBox() Double_t xc[4]; Double_t yc[4]; - xc[0] = rmax*TMath::Cos(fPhi1*TMath::DegToRad()); - yc[0] = rmax*TMath::Sin(fPhi1*TMath::DegToRad()); - xc[1] = rmax*TMath::Cos(fPhi2*TMath::DegToRad()); - yc[1] = rmax*TMath::Sin(fPhi2*TMath::DegToRad()); - xc[2] = rmin*TMath::Cos(fPhi1*TMath::DegToRad()); - yc[2] = rmin*TMath::Sin(fPhi1*TMath::DegToRad()); - xc[3] = rmin*TMath::Cos(fPhi2*TMath::DegToRad()); - yc[3] = rmin*TMath::Sin(fPhi2*TMath::DegToRad()); + xc[0] = rmax*fC1; + yc[0] = rmax*fS1; + xc[1] = rmax*fC2; + yc[1] = rmax*fS2; + xc[2] = rmin*fC1; + yc[2] = rmin*fS1; + xc[3] = rmin*fC2; + yc[3] = rmin*fS2; Double_t xmin = xc[TMath::LocMin(4, &xc[0])]; Double_t xmax = xc[TMath::LocMax(4, &xc[0])]; @@ -1277,11 +1307,6 @@ void TGeoConeSeg::ComputeNormal(const Double_t *point, const Double_t *dir, Doub Double_t tg2 = 0.5*(fRmax2-fRmax1)/fDz; Double_t cr2 = 1./TMath::Sqrt(1.+tg2*tg2); - Double_t c1 = TMath::Cos(fPhi1*TMath::DegToRad()); - Double_t s1 = TMath::Sin(fPhi1*TMath::DegToRad()); - Double_t c2 = TMath::Cos(fPhi2*TMath::DegToRad()); - Double_t s2 = TMath::Sin(fPhi2*TMath::DegToRad()); - Double_t r=TMath::Sqrt(point[0]*point[0]+point[1]*point[1]); Double_t rin = tg1*point[2]+ro1; Double_t rout = tg2*point[2]+ro2; @@ -1289,8 +1314,8 @@ void TGeoConeSeg::ComputeNormal(const Double_t *point, const Double_t *dir, Doub saf[1] = (ro1>0)?(TMath::Abs((r-rin)*cr1)):TGeoShape::Big(); saf[2] = TMath::Abs((rout-r)*cr2); Int_t i = TMath::LocMin(3,saf); - if (((fPhi2-fPhi1)<360.) && TGeoShape::IsCloseToPhi(saf[i], point,c1,s1,c2,s2)) { - TGeoShape::NormalPhi(point,dir,norm,c1,s1,c2,s2); + if (((fPhi2-fPhi1)<360.) && TGeoShape::IsCloseToPhi(saf[i], point,fC1,fS1,fC2,fS2)) { + TGeoShape::NormalPhi(point,dir,norm,fC1,fS1,fC2,fS2); return; } if (i==0) { @@ -1515,20 +1540,9 @@ Double_t TGeoConeSeg::DistFromInside(const Double_t *point, const Double_t *dir, if ((iact==1) && (*safe>step)) return TGeoShape::Big(); } if ((fPhi2-fPhi1)>=360.) return TGeoCone::DistFromInsideS(point,dir,fDz,fRmin1,fRmax1,fRmin2,fRmax2); - Double_t phi1 = fPhi1*TMath::DegToRad(); - Double_t phi2 = fPhi2*TMath::DegToRad(); - Double_t c1 = TMath::Cos(phi1); - Double_t c2 = TMath::Cos(phi2); - Double_t s1 = TMath::Sin(phi1); - Double_t s2 = TMath::Sin(phi2); - Double_t phim = 0.5*(phi1+phi2); - Double_t cm = TMath::Cos(phim); - Double_t sm = TMath::Sin(phim); - Double_t dfi = 0.5*(phi2-phi1); - Double_t cdfi = TMath::Cos(dfi); // compute distance to surface - return TGeoConeSeg::DistFromInsideS(point,dir,fDz,fRmin1,fRmax1,fRmin2,fRmax2,c1,s1,c2,s2,cm,sm,cdfi); + return TGeoConeSeg::DistFromInsideS(point,dir,fDz,fRmin1,fRmax1,fRmin2,fRmax2,fC1,fS1,fC2,fS2,fCm,fSm,fCdfi); } //_____________________________________________________________________________ @@ -1819,18 +1833,7 @@ Double_t TGeoConeSeg::DistFromOutside(const Double_t *point, const Double_t *dir Double_t sdist = TGeoBBox::DistFromOutside(point,dir, fDX, fDY, fDZ, fOrigin, step); if (sdist>=step) return TGeoShape::Big(); if ((fPhi2-fPhi1)>=360.) return TGeoCone::DistFromOutsideS(point,dir,fDz,fRmin1,fRmax1,fRmin2,fRmax2); - Double_t phi1 = fPhi1*TMath::DegToRad(); - Double_t phi2 = fPhi2*TMath::DegToRad(); - Double_t c1 = TMath::Cos(phi1); - Double_t c2 = TMath::Cos(phi2); - Double_t s1 = TMath::Sin(phi1); - Double_t s2 = TMath::Sin(phi2); - Double_t phim = 0.5*(phi1+phi2); - Double_t cm = TMath::Cos(phim); - Double_t sm = TMath::Sin(phim); - Double_t dfi = 0.5*(phi2-phi1); - Double_t cdfi = TMath::Cos(dfi); - return TGeoConeSeg::DistFromOutsideS(point,dir,fDz,fRmin1,fRmax1,fRmin2,fRmax2,c1,s1,c2,s2,cm,sm,cdfi); + return TGeoConeSeg::DistFromOutsideS(point,dir,fDz,fRmin1,fRmax1,fRmin2,fRmax2,fC1,fS1,fC2,fS2,fCm,fSm,fCdfi); } //_____________________________________________________________________________ @@ -2152,7 +2155,8 @@ void TGeoConeSeg::SetConsDimensions(Double_t dz, Double_t rmin1, Double_t rmax1, while (fPhi1<0) fPhi1+=360.; fPhi2 = phi2; while (fPhi2<=fPhi1) fPhi2+=360.; - if (TGeoShape::IsSameWithinTolerance(fPhi1,fPhi2)) Error("SetConsDimensions", "In shape %s invalid phi1=%g, phi2=%g\n", GetName(), fPhi1, fPhi2); + if (TGeoShape::IsSameWithinTolerance(fPhi1,fPhi2)) Fatal("SetConsDimensions", "In shape %s invalid phi1=%g, phi2=%g\n", GetName(), fPhi1, fPhi2); + InitTrigonometry(); } //_____________________________________________________________________________ diff --git a/geom/geom/src/TGeoManager.cxx b/geom/geom/src/TGeoManager.cxx index 5387796efa5a64371723f5cf4bd6c988e8e5d13a..eeceda51bda89cd0c0a9ec4d28cf0a93a2b8f4f6 100644 --- a/geom/geom/src/TGeoManager.cxx +++ b/geom/geom/src/TGeoManager.cxx @@ -1448,6 +1448,9 @@ void TGeoManager::CloseGeometry(Option_t *option) // Create a geometry navigator if not present if (!GetCurrentNavigator()) fCurrentNavigator = AddNavigator(); nnavigators = GetListOfNavigators()->GetEntriesFast(); + TIter next(fShapes); + TGeoShape *shape; + while ((shape = (TGeoShape*)next())) shape->AfterStreamer(); Voxelize("ALL"); CountLevels(); for (Int_t i=0; i<nnavigators; i++) { @@ -3355,9 +3358,7 @@ void TGeoManager::CheckGeometryFull(Int_t ntracks, Double_t vx, Double_t vy, Dou //_____________________________________________________________________________ void TGeoManager::CheckGeometry(Option_t * /*option*/) { -// Instanciate a TGeoChecker object and investigates the geometry according to -// option. Not implemented yet. - // check shapes first + // Perform last checks on the geometry if (fgVerboseLevel>0) Info("CheckGeometry","Fixing runtime shapes..."); TIter next(fShapes); TIter nextv(fVolumes); @@ -3368,6 +3369,7 @@ void TGeoManager::CheckGeometry(Option_t * /*option*/) if (shape->IsRunTimeShape()) { has_runtime = kTRUE; } + if (fIsGeomReading) shape->AfterStreamer(); if (shape->TestShapeBit(TGeoShape::kGeoPcon) || shape->TestShapeBit(TGeoShape::kGeoArb8)) if (!shape->TestShapeBit(TGeoShape::kGeoClosedShape)) shape->ComputeBBox(); } diff --git a/geom/geom/src/TGeoTube.cxx b/geom/geom/src/TGeoTube.cxx index 1f43c7dc9812673bbde7d77df338a5cadf9a747f..27cadf43a923e7ef77fa14d483a1ed42fd08951a 100644 --- a/geom/geom/src/TGeoTube.cxx +++ b/geom/geom/src/TGeoTube.cxx @@ -1175,16 +1175,18 @@ ClassImp(TGeoTubeSeg) //_____________________________________________________________________________ TGeoTubeSeg::TGeoTubeSeg() + :TGeoTube(), + fPhi1(0.), fPhi2(0.), fS1(0.), fC1(0.), fS2(0.), fC2(0.), fSm(0.), fCm(0.), fCdfi(0.) { // Default constructor SetShapeBit(TGeoShape::kGeoTubeSeg); - fPhi1 = fPhi2 = 0.0; } //_____________________________________________________________________________ TGeoTubeSeg::TGeoTubeSeg(Double_t rmin, Double_t rmax, Double_t dz, Double_t phiStart, Double_t phiEnd) - :TGeoTube(rmin, rmax, dz) + :TGeoTube(rmin, rmax, dz), + fPhi1(0.), fPhi2(0.), fS1(0.), fC1(0.), fS2(0.), fC2(0.), fSm(0.), fCm(0.), fCdfi(0.) { // Default constructor specifying minimum and maximum radius. // The segment will be from phiStart to phiEnd expressed in degree. @@ -1226,6 +1228,30 @@ TGeoTubeSeg::~TGeoTubeSeg() // destructor } +//_____________________________________________________________________________ +void TGeoTubeSeg::AfterStreamer() +{ +// Function called after streaming an object of this class. + InitTrigonometry(); +} + +//_____________________________________________________________________________ +void TGeoTubeSeg::InitTrigonometry() +{ +// Init frequently used trigonometric values + Double_t phi1 = fPhi1*TMath::DegToRad(); + Double_t phi2 = fPhi2*TMath::DegToRad(); + fC1 = TMath::Cos(phi1); + fS1 = TMath::Sin(phi1); + fC2 = TMath::Cos(phi2); + fS2 = TMath::Sin(phi2); + Double_t fio = 0.5*(phi1+phi2); + fCm = TMath::Cos(fio); + fSm = TMath::Sin(fio); + Double_t dfi = 0.5*(phi2-phi1); + fCdfi = TMath::Cos(dfi); +} + //_____________________________________________________________________________ Double_t TGeoTubeSeg::Capacity() const { @@ -1247,14 +1273,14 @@ void TGeoTubeSeg::ComputeBBox() // compute bounding box of the tube segment Double_t xc[4]; Double_t yc[4]; - xc[0] = fRmax*TMath::Cos(fPhi1*TMath::DegToRad()); - yc[0] = fRmax*TMath::Sin(fPhi1*TMath::DegToRad()); - xc[1] = fRmax*TMath::Cos(fPhi2*TMath::DegToRad()); - yc[1] = fRmax*TMath::Sin(fPhi2*TMath::DegToRad()); - xc[2] = fRmin*TMath::Cos(fPhi1*TMath::DegToRad()); - yc[2] = fRmin*TMath::Sin(fPhi1*TMath::DegToRad()); - xc[3] = fRmin*TMath::Cos(fPhi2*TMath::DegToRad()); - yc[3] = fRmin*TMath::Sin(fPhi2*TMath::DegToRad()); + xc[0] = fRmax*fC1; + yc[0] = fRmax*fS1; + xc[1] = fRmax*fC2; + yc[1] = fRmax*fS2; + xc[2] = fRmin*fC1; + yc[2] = fRmin*fS1; + xc[3] = fRmin*fC2; + yc[3] = fRmin*fS2; Double_t xmin = xc[TMath::LocMin(4, &xc[0])]; Double_t xmax = xc[TMath::LocMax(4, &xc[0])]; @@ -1294,23 +1320,19 @@ void TGeoTubeSeg::ComputeNormal(const Double_t *point, const Double_t *dir, Doub Double_t saf[3]; Double_t rsq = point[0]*point[0]+point[1]*point[1]; Double_t r = TMath::Sqrt(rsq); - Double_t c1 = TMath::Cos(fPhi1*TMath::DegToRad()); - Double_t s1 = TMath::Sin(fPhi1*TMath::DegToRad()); - Double_t c2 = TMath::Cos(fPhi2*TMath::DegToRad()); - Double_t s2 = TMath::Sin(fPhi2*TMath::DegToRad()); saf[0] = TMath::Abs(fDz-TMath::Abs(point[2])); saf[1] = (fRmin>1E-10)?TMath::Abs(r-fRmin):TGeoShape::Big(); saf[2] = TMath::Abs(fRmax-r); Int_t i = TMath::LocMin(3,saf); - if (((fPhi2-fPhi1)<360.) && TGeoShape::IsCloseToPhi(saf[i], point,c1,s1,c2,s2)) { - TGeoShape::NormalPhi(point,dir,norm,c1,s1,c2,s2); + if (((fPhi2-fPhi1)<360.) && TGeoShape::IsCloseToPhi(saf[i], point,fC1,fS1,fC2,fS2)) { + TGeoShape::NormalPhi(point,dir,norm,fC1,fS1,fC2,fS2); return; } if (i==0) { norm[0] = norm[1] = 0.; norm[2] = TMath::Sign(1.,dir[2]); return; - } + }; norm[2] = 0; Double_t phi = TMath::ATan2(point[1], point[0]); norm[0] = TMath::Cos(phi); @@ -1424,20 +1446,9 @@ Double_t TGeoTubeSeg::DistFromInside(const Double_t *point, const Double_t *dir, if ((iact==1) && (*safe>step)) return TGeoShape::Big(); } if ((fPhi2-fPhi1)>=360.) return TGeoTube::DistFromInsideS(point,dir,fRmin,fRmax,fDz); - Double_t phi1 = fPhi1*TMath::DegToRad(); - Double_t phi2 = fPhi2*TMath::DegToRad(); - Double_t c1 = TMath::Cos(phi1); - Double_t c2 = TMath::Cos(phi2); - Double_t s1 = TMath::Sin(phi1); - Double_t s2 = TMath::Sin(phi2); - Double_t phim = 0.5*(phi1+phi2); - Double_t cm = TMath::Cos(phim); - Double_t sm = TMath::Sin(phim); - Double_t dfi = 0.5*(phi2-phi1); - Double_t cdfi = TMath::Cos(dfi); // compute distance to surface - return TGeoTubeSeg::DistFromInsideS(point,dir,fRmin,fRmax,fDz,c1,s1,c2,s2,cm,sm,cdfi); + return TGeoTubeSeg::DistFromInsideS(point,dir,fRmin,fRmax,fDz,fC1,fS1,fC2,fS2,fCm,fSm,fCdfi); } //_____________________________________________________________________________ @@ -1710,20 +1721,9 @@ Double_t TGeoTubeSeg::DistFromOutside(const Double_t *point, const Double_t *dir Double_t sdist = TGeoBBox::DistFromOutside(point,dir, fDX, fDY, fDZ, fOrigin, step); if (sdist>=step) return TGeoShape::Big(); if ((fPhi2-fPhi1)>=360.) return TGeoTube::DistFromOutsideS(point,dir,fRmin,fRmax,fDz); - Double_t phi1 = fPhi1*TMath::DegToRad(); - Double_t phi2 = fPhi2*TMath::DegToRad(); - Double_t c1 = TMath::Cos(phi1); - Double_t s1 = TMath::Sin(phi1); - Double_t c2 = TMath::Cos(phi2); - Double_t s2 = TMath::Sin(phi2); - Double_t fio = 0.5*(phi1+phi2); - Double_t cm = TMath::Cos(fio); - Double_t sm = TMath::Sin(fio); - Double_t dfi = 0.5*(phi2-phi1); - Double_t cdfi = TMath::Cos(dfi); // find distance to shape - return TGeoTubeSeg::DistFromOutsideS(point, dir, fRmin, fRmax, fDz, c1, s1, c2, s2, cm, sm, cdfi); + return TGeoTubeSeg::DistFromOutsideS(point, dir, fRmin, fRmax, fDz, fC1, fS1, fC2, fS2, fCm, fSm, fCdfi); } //_____________________________________________________________________________ @@ -1981,7 +1981,7 @@ void TGeoTubeSeg::SetSegsAndPols(TBuffer3D &buff) const //_____________________________________________________________________________ Double_t TGeoTubeSeg::Safety(const Double_t *point, Bool_t in) const { -// computes the closest distance from given point to this shape, according +// computes the closest distance from given point InitTrigonometry();to this shape, according // to option. The matching point on the shape is stored in spoint. Double_t saf[3]; Double_t rsq = point[0]*point[0]+point[1]*point[1]; @@ -2072,7 +2072,8 @@ void TGeoTubeSeg::SetTubsDimensions(Double_t rmin, Double_t rmax, Double_t dz, if (fPhi1 < 0) fPhi1 += 360.; fPhi2 = phiEnd; while (fPhi2<=fPhi1) fPhi2+=360.; - if (TGeoShape::IsSameWithinTolerance(fPhi1,fPhi2)) Error("SetTubsDimensions", "In shape %s invalid phi1=%g, phi2=%g\n", GetName(), fPhi1, fPhi2); + if (TGeoShape::IsSameWithinTolerance(fPhi1,fPhi2)) Fatal("SetTubsDimensions", "In shape %s invalid phi1=%g, phi2=%g\n", GetName(), fPhi1, fPhi2); + InitTrigonometry(); } //_____________________________________________________________________________ @@ -2454,23 +2455,23 @@ void TGeoCtub::ComputeBBox() } - xc = fRmin*TMath::Cos(fPhi1*TMath::DegToRad()); - yc = fRmin*TMath::Sin(fPhi1*TMath::DegToRad()); + xc = fRmin*fC1; + yc = fRmin*fS1; z[0] = GetZcoord(xc, yc, -fDz); z[4] = GetZcoord(xc, yc, fDz); - xc = fRmin*TMath::Cos(fPhi2*TMath::DegToRad()); - yc = fRmin*TMath::Sin(fPhi2*TMath::DegToRad()); + xc = fRmin*fC2; + yc = fRmin*fS2; z[1] = GetZcoord(xc, yc, -fDz); z[5] = GetZcoord(xc, yc, fDz); - xc = fRmax*TMath::Cos(fPhi1*TMath::DegToRad()); - yc = fRmax*TMath::Sin(fPhi1*TMath::DegToRad()); + xc = fRmax*fC1; + yc = fRmax*fS1; z[2] = GetZcoord(xc, yc, -fDz); z[6] = GetZcoord(xc, yc, fDz); - xc = fRmax*TMath::Cos(fPhi2*TMath::DegToRad()); - yc = fRmax*TMath::Sin(fPhi2*TMath::DegToRad()); + xc = fRmax*fC2; + yc = fRmax*fS2; z[3] = GetZcoord(xc, yc, -fDz); z[7] = GetZcoord(xc, yc, fDz); @@ -2506,12 +2507,8 @@ void TGeoCtub::ComputeNormal(const Double_t *point, const Double_t *dir, Double_ saf[3] = TMath::Abs(fRmax-r); Int_t i = TMath::LocMin(4,saf); if (isseg) { - Double_t c1 = TMath::Cos(fPhi1*TMath::DegToRad()); - Double_t s1 = TMath::Sin(fPhi1*TMath::DegToRad()); - Double_t c2 = TMath::Cos(fPhi2*TMath::DegToRad()); - Double_t s2 = TMath::Sin(fPhi2*TMath::DegToRad()); - if (TGeoShape::IsCloseToPhi(saf[i], point,c1,s1,c2,s2)) { - TGeoShape::NormalPhi(point,dir,norm,c1,s1,c2,s2); + if (TGeoShape::IsCloseToPhi(saf[i], point,fC1,fS1,fC2,fS2)) { + TGeoShape::NormalPhi(point,dir,norm,fC1,fS1,fC2,fS2); return; } } @@ -2618,23 +2615,9 @@ Double_t TGeoCtub::DistFromOutside(const Double_t *point, const Double_t *dir, I saf[1] = point[0]*fNhigh[0] + point[1]*fNhigh[1] + (point[2]-fDz)*fNhigh[2]; Double_t rsq = point[0]*point[0]+point[1]*point[1]; Double_t r = TMath::Sqrt(rsq); - Double_t c1=0,s1=0,c2=0,s2=0; - Double_t fio=0, cfio=0, sfio=0, dfi=0, cdfi=0, cpsi=0; - Double_t phi1 = fPhi1*TMath::DegToRad(); - Double_t phi2 = fPhi2*TMath::DegToRad(); + Double_t cpsi=0; Bool_t tub = kFALSE; if (TMath::Abs(fPhi2-fPhi1-360.)<1E-8) tub = kTRUE; - if (!tub) { - c1 = TMath::Cos(phi1); - c2 = TMath::Cos(phi2); - s1 = TMath::Sin(phi1); - s2 = TMath::Sin(phi2); - fio = 0.5*(phi1+phi2); - cfio = TMath::Cos(fio); - sfio = TMath::Sin(fio); - dfi = 0.5*(phi2-phi1); - cdfi = TMath::Cos(dfi); - } // find distance to shape Double_t r2; @@ -2650,8 +2633,8 @@ Double_t TGeoCtub::DistFromOutside(const Double_t *point, const Double_t *dir, I r2=xi*xi+yi*yi; if (((fRmin*fRmin)<=r2) && (r2<=(fRmax*fRmax))) { if (tub) return s; - cpsi=(xi*cfio+yi*sfio)/TMath::Sqrt(r2); - if (cpsi>=cdfi) return s; + cpsi=(xi*fCm+yi*fSm)/TMath::Sqrt(r2); + if (cpsi>=fCdfi) return s; } } } @@ -2664,8 +2647,8 @@ Double_t TGeoCtub::DistFromOutside(const Double_t *point, const Double_t *dir, I r2=xi*xi+yi*yi; if (((fRmin*fRmin)<=r2) && (r2<=(fRmax*fRmax))) { if (tub) return s; - cpsi=(xi*cfio+yi*sfio)/TMath::Sqrt(r2); - if (cpsi>=cdfi) return s; + cpsi=(xi*fCm+yi*fSm)/TMath::Sqrt(r2); + if (cpsi>=fCdfi) return s; } } } @@ -2687,8 +2670,8 @@ Double_t TGeoCtub::DistFromOutside(const Double_t *point, const Double_t *dir, I if ((-xi*fNlow[0]-yi*fNlow[1]-(zi+fDz)*fNlow[2])>0) { if ((-xi*fNhigh[0]-yi*fNhigh[1]+(fDz-zi)*fNhigh[2])>0) { if (tub) return s; - cpsi=(xi*cfio+yi*sfio)/fRmax; - if (cpsi>=cdfi) return s; + cpsi=(xi*fCm+yi*fSm)/fRmax; + if (cpsi>=fCdfi) return s; } } } @@ -2707,8 +2690,8 @@ Double_t TGeoCtub::DistFromOutside(const Double_t *point, const Double_t *dir, I if ((-xi*fNlow[0]-yi*fNlow[1]-(zi+fDz)*fNlow[2])>0) { if ((-xi*fNhigh[0]-yi*fNhigh[1]+(fDz-zi)*fNhigh[2])>0) { if (tub) return s; - cpsi=(xi*cfio+yi*sfio)/fRmin; - if (cpsi>=cdfi) snxt=s; + cpsi=(xi*fCm+yi*fSm)/fRmin; + if (cpsi>=fCdfi) snxt=s; } } } @@ -2716,9 +2699,9 @@ Double_t TGeoCtub::DistFromOutside(const Double_t *point, const Double_t *dir, I } // check phi planes if (tub) return snxt; - Double_t un=dir[0]*s1-dir[1]*c1; + Double_t un=dir[0]*fS1-dir[1]*fC1; if (un<-TGeoShape::Tolerance()) { - s=(point[1]*c1-point[0]*s1)/un; + s=(point[1]*fC1-point[0]*fS1)/un; if (s>=0) { xi=point[0]+s*dir[0]; yi=point[1]+s*dir[1]; @@ -2727,7 +2710,7 @@ Double_t TGeoCtub::DistFromOutside(const Double_t *point, const Double_t *dir, I if ((-xi*fNhigh[0]-yi*fNhigh[1]+(fDz-zi)*fNhigh[2])>0) { r2=xi*xi+yi*yi; if ((fRmin*fRmin<=r2) && (r2<=fRmax*fRmax)) { - if ((yi*cfio-xi*sfio)<=0) { + if ((yi*fCm-xi*fSm)<=0) { if (s<snxt) snxt=s; } } @@ -2735,9 +2718,9 @@ Double_t TGeoCtub::DistFromOutside(const Double_t *point, const Double_t *dir, I } } } - un=dir[0]*s2-dir[1]*c2; + un=dir[0]*fS2-dir[1]*fC2; if (un>TGeoShape::Tolerance()) { - s=(point[1]*c2-point[0]*s2)/un; + s=(point[1]*fC2-point[0]*fS2)/un; if (s>=0) { xi=point[0]+s*dir[0]; yi=point[1]+s*dir[1]; @@ -2746,7 +2729,7 @@ Double_t TGeoCtub::DistFromOutside(const Double_t *point, const Double_t *dir, I if ((-xi*fNhigh[0]-yi*fNhigh[1]+(fDz-zi)*fNhigh[2])>0) { r2=xi*xi+yi*yi; if ((fRmin*fRmin<=r2) && (r2<=fRmax*fRmax)) { - if ((yi*cfio-xi*sfio)>=0) { + if ((yi*fCm-xi*fSm)>=0) { if (s<snxt) snxt=s; } } @@ -2765,21 +2748,8 @@ Double_t TGeoCtub::DistFromInside(const Double_t *point, const Double_t *dir, In if (iact==0) return TGeoShape::Big(); if ((iact==1) && (*safe>step)) return TGeoShape::Big(); Double_t rsq = point[0]*point[0]+point[1]*point[1]; - Double_t c1=0,s1=0,c2=0,s2=0,cm=0,sm=0,phim=0; - Double_t phi1 = fPhi1*TMath::DegToRad(); - Double_t phi2 = fPhi2*TMath::DegToRad(); Bool_t tub = kFALSE; if (TMath::Abs(fPhi2-fPhi1-360.)<1E-8) tub = kTRUE; - if (!tub) { - if (phi2<phi1) phi2+=2.*TMath::Pi(); - phim = 0.5*(phi1+phi2); - c1 = TMath::Cos(phi1); - c2 = TMath::Cos(phi2); - s1 = TMath::Sin(phi1); - s2 = TMath::Sin(phi2); - cm = TMath::Cos(phim); - sm = TMath::Sin(phim); - } // compute distance to surface // Do Z Double_t sz = TGeoShape::Big(); @@ -2824,7 +2794,7 @@ Double_t TGeoCtub::DistFromInside(const Double_t *point, const Double_t *dir, In } // phi planes Double_t sfmin = TGeoShape::Big(); - if (!tub) sfmin=TGeoShape::DistToPhiMin(point, dir, s1, c1, s2, c2, sm, cm); + if (!tub) sfmin=TGeoShape::DistToPhiMin(point, dir, fS1, fC1, fS2, fC2, fSm, fCm); return TMath::Min(TMath::Min(sz,sr), sfmin); }