Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:15

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4TwistedTubs
0027 //
0028 // Class description:
0029 //
0030 //  G4TwistedTubs is a sector of a twisted hollow cylinder.
0031 //  A twisted cylinder which is placed along with z-axis and is
0032 //  separated into phi-segments should become a hyperboloid, and
0033 //  its each segmented piece should be tilted with a stereo angle.
0034 //  G4TwistedTubs is a G4VSolid.
0035 //
0036 //  Details of the implementation: "Development of a Geant4 solid
0037 //  for stereo mini-jet cells in a cylindrical drift chamber",
0038 //  Computer Physics Communications 153 (2003) pp.373–391
0039 
0040 // 01-Aug-2002 - Kotoyo Hoshina (hoshina@hepburn.s.chiba-u.ac.jp), created.
0041 // 13-Nov-2003 - O.Link (Oliver.Link@cern.ch), Integration in Geant4
0042 //               from original version in Jupiter-2.5.02 application.
0043 // --------------------------------------------------------------------
0044 #ifndef G4TWISTEDTUBS_HH
0045 #define G4TWISTEDTUBS_HH
0046 
0047 #include "G4VSolid.hh"
0048 #include "G4TwistTubsFlatSide.hh"
0049 #include "G4TwistTubsSide.hh"
0050 #include "G4TwistTubsHypeSide.hh"
0051 
0052 class G4SolidExtentList;
0053 class G4ClippablePolygon;
0054 
0055 class G4TwistedTubs : public G4VSolid
0056 {
0057   public:
0058  
0059     G4TwistedTubs(const G4String& pname,        // Name of instance
0060                         G4double  twistedangle, // Twisted angle
0061                         G4double  endinnerrad,  // Inner radius at endcap 
0062                         G4double  endouterrad,  // Outer radius at endcap 
0063                         G4double  halfzlen,     // half z length 
0064                         G4double  dphi);        // Phi angle of a segment
0065                       
0066     G4TwistedTubs(const G4String& pname,        // Name of instance
0067                         G4double  twistedangle, // Stereo angle
0068                         G4double  endinnerrad,  // Inner radius at endcap 
0069                         G4double  endouterrad,  // Outer radius at endcap 
0070                         G4double  halfzlen,     // half z length 
0071                         G4int     nseg,         // Number of segments in totalPhi
0072                         G4double  totphi);      // Total angle of all segments
0073                       
0074     G4TwistedTubs(const G4String& pname,        // Name of instance
0075                         G4double  twistedangle, // Twisted angle
0076                         G4double  innerrad,     // Inner radius at z=0 
0077                         G4double  outerrad,     // Outer radius at z=0 
0078                         G4double  negativeEndz, // -ve z endplate
0079                         G4double  positiveEndz, // +ve z endplate
0080                         G4double  dphi);        // Phi angle of a segment
0081 
0082     G4TwistedTubs(const G4String& pname,        // Name of instance
0083                         G4double  twistedangle, // Stereo angle
0084                         G4double  innerrad,     // Inner radius at z=0 
0085                         G4double  outerrad,     // Outer radius at z=0 
0086                         G4double  negativeEndz, // -ve z endplate
0087                         G4double  positiveEndz, // +ve z endplate
0088                         G4int     nseg,         // Number of segments in totalPhi
0089                         G4double  totphi);      // Total angle of all segments
0090 
0091    ~G4TwistedTubs() override;
0092              
0093     void ComputeDimensions(G4VPVParameterisation*    /* p  */ ,
0094                            const G4int               /* n  */ ,
0095                            const G4VPhysicalVolume*  /* prep */ ) override;
0096 
0097     void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const override;
0098 
0099     G4bool CalculateExtent(const EAxis               pAxis,
0100                            const G4VoxelLimits&     pVoxelLimit,
0101                            const G4AffineTransform& pTransform,
0102                                  G4double&          pMin,
0103                                  G4double&          pMax ) const override;
0104 
0105     G4double DistanceToIn (const G4ThreeVector& p,
0106                            const G4ThreeVector& v ) const override;
0107 
0108     G4double DistanceToIn (const G4ThreeVector& p ) const override;
0109    
0110     G4double DistanceToOut(const G4ThreeVector& p, 
0111                            const G4ThreeVector& v,
0112                            const G4bool calcnorm = false,
0113                                  G4bool* validnorm = nullptr, 
0114                                  G4ThreeVector* n = nullptr ) const override;
0115 
0116     G4double DistanceToOut(const G4ThreeVector& p) const override;
0117   
0118     EInside Inside (const G4ThreeVector& p) const override;
0119 
0120     G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const override;
0121 
0122     void          DescribeYourselfTo (G4VGraphicsScene& scene) const override;
0123     G4Polyhedron* CreatePolyhedron   () const override;
0124     G4Polyhedron* GetPolyhedron      () const override;
0125 
0126     std::ostream &StreamInfo(std::ostream& os) const override;
0127 
0128     // accessors
0129   
0130     inline G4double GetDPhi        () const { return fDPhi       ; }
0131     inline G4double GetPhiTwist    () const { return fPhiTwist   ; }
0132     inline G4double GetInnerRadius () const { return fInnerRadius; }
0133     inline G4double GetOuterRadius () const { return fOuterRadius; }
0134     inline G4double GetInnerStereo () const { return fInnerStereo; }
0135     inline G4double GetOuterStereo () const { return fOuterStereo; }
0136     inline G4double GetZHalfLength () const { return fZHalfLength; }
0137     inline G4double GetKappa       () const { return fKappa      ; }
0138 
0139     inline G4double GetTanInnerStereo () const { return fTanInnerStereo  ; }
0140     inline G4double GetTanInnerStereo2() const { return fTanInnerStereo2 ; }
0141     inline G4double GetTanOuterStereo () const { return fTanOuterStereo  ; }
0142     inline G4double GetTanOuterStereo2() const { return fTanOuterStereo2 ; }
0143   
0144     inline G4double GetEndZ           (G4int i) const { return fEndZ[i]  ; }
0145     inline G4double GetEndPhi         (G4int i) const { return fEndPhi[i]; }
0146     inline G4double GetEndInnerRadius (G4int i) const
0147                     { return fEndInnerRadius[i]; }
0148     inline G4double GetEndOuterRadius (G4int i) const
0149                     { return fEndOuterRadius[i]; }
0150     inline G4double GetEndInnerRadius () const 
0151                     { return (fEndInnerRadius[0] > fEndInnerRadius[1] ?
0152                       fEndInnerRadius[0] : fEndInnerRadius[1]); }
0153     inline G4double GetEndOuterRadius () const
0154                     { return (fEndOuterRadius[0] > fEndOuterRadius[1] ?
0155                       fEndOuterRadius[0] : fEndOuterRadius[1]); }
0156   
0157     G4VisExtent     GetExtent    () const override;
0158     G4GeometryType  GetEntityType() const override;
0159     G4VSolid* Clone() const override;
0160 
0161     G4double GetCubicVolume() override;
0162       // Returns an estimation of the geometrical cubic volume of the
0163       // solid. Caches the computed value once computed the first time.
0164     G4double GetSurfaceArea() override;
0165       // Returns the geometrical surface area of the solid.
0166       // Caches the computed value once computed the first time.
0167 
0168     G4ThreeVector GetPointOnSurface() const override ;
0169 
0170     G4TwistedTubs(__void__&);
0171       // Fake default constructor for usage restricted to direct object
0172       // persistency for clients requiring preallocation of memory for
0173       // persistifiable objects.
0174 
0175     G4TwistedTubs(const G4TwistedTubs& rhs);
0176     G4TwistedTubs& operator=(const G4TwistedTubs& rhs); 
0177       // Copy constructor and assignment operator.
0178 
0179 #ifdef G4TWISTDEBUG
0180     G4VTwistSurface* GetOuterHype() const { return fOuterHype; }
0181 #endif
0182   
0183   private:
0184  
0185     inline void SetFields(G4double phitwist, G4double innerrad,
0186                           G4double outerrad,
0187                           G4double negativeEndz, G4double positiveEndz);
0188     void CreateSurfaces();
0189     G4double GetLateralArea(G4double a, G4double r, G4double z) const;
0190     G4double GetPhiCutArea(G4double a, G4double r, G4double z) const;
0191 
0192   private:
0193  
0194     G4double fPhiTwist;       // Twist angle from -fZHalfLength to fZHalfLength
0195     G4double fInnerRadius;    // Inner-hype radius at z=0
0196     G4double fOuterRadius;    // Outer-hype radius at z=0
0197     G4double fEndZ[2];        // z at endcaps, [0] = -ve z, [1] = +ve z
0198     G4double fDPhi;           // Phi-width of a segment fDPhi > 0
0199     G4double fZHalfLength;    // Half length along z-axis
0200  
0201     G4double fInnerStereo;       // Inner-hype stereo angle
0202     G4double fOuterStereo;       // Outer-hype stereo angle
0203     G4double fTanInnerStereo;    // std::tan(innerStereoAngle)
0204     G4double fTanOuterStereo;    // std::tan(outerStereoAngle)
0205     G4double fKappa;             // std::tan(fPhiTwist/2)/fZHalfLen;
0206     G4double fEndInnerRadius[2]; // Inner-hype radii endcaps [0] -ve z, [1] +ve z
0207     G4double fEndOuterRadius[2]; // Outer-hype radii endcaps [0] -ve z, [1] +ve z
0208     G4double fEndPhi[2];         // Phi endcaps, [0] = -ve z, [1] = +ve z
0209   
0210     G4double fInnerRadius2;      // fInnerRadius * fInnerRadius
0211     G4double fOuterRadius2;      // fOuterRadius * fOuterRadius
0212     G4double fTanInnerStereo2;   // fInnerRadius * fInnerRadius
0213     G4double fTanOuterStereo2;   // fInnerRadius * fInnerRadius
0214     G4double fEndZ2[2];          // fEndZ * fEndZ
0215   
0216     G4VTwistSurface* fLowerEndcap;    // Surface of -ve z
0217     G4VTwistSurface* fUpperEndcap;    // Surface of +ve z
0218     G4VTwistSurface* fLatterTwisted;  // Surface of -ve phi
0219     G4VTwistSurface* fFormerTwisted;  // Surface of +ve phi
0220     G4VTwistSurface* fInnerHype;      // Surface of -ve r
0221     G4VTwistSurface* fOuterHype;      // Surface of +ve r
0222 
0223     G4double fCubicVolume = 0.0;      // Cached value for cubic volume
0224     G4double fSurfaceArea = 0.0;      // Cached value for surface area
0225 
0226     mutable G4bool fRebuildPolyhedron = false;
0227     mutable G4Polyhedron* fpPolyhedron = nullptr; // polyhedron for vis
0228 
0229 };
0230 
0231 //=====================================================================
0232 
0233 //---------------------
0234 // inline functions
0235 //---------------------
0236 
0237 inline
0238 void G4TwistedTubs::SetFields(G4double phitwist, G4double innerrad, 
0239                               G4double outerrad, G4double negativeEndz, 
0240                               G4double positiveEndz)
0241 {
0242    fCubicVolume  = 0.;
0243    fPhiTwist     = phitwist;
0244    fEndZ[0]      = negativeEndz;
0245    fEndZ[1]      = positiveEndz;
0246    fEndZ2[0]     = fEndZ[0] * fEndZ[0];
0247    fEndZ2[1]     = fEndZ[1] * fEndZ[1];
0248    fInnerRadius  = innerrad;
0249    fOuterRadius  = outerrad;
0250    fInnerRadius2 = fInnerRadius * fInnerRadius;
0251    fOuterRadius2 = fOuterRadius * fOuterRadius;
0252    
0253    if (std::fabs(fEndZ[0]) >= std::fabs(fEndZ[1]))
0254    {
0255       fZHalfLength = std::fabs(fEndZ[0]);
0256    }
0257    else
0258    {
0259       fZHalfLength = std::fabs(fEndZ[1]);
0260    }
0261 
0262    G4double parity         = (fPhiTwist > 0 ? 1 : -1); 
0263    G4double tanHalfTwist   = std::tan(0.5 * fPhiTwist);
0264    G4double innerNumerator = std::fabs(fInnerRadius * tanHalfTwist) * parity;
0265    G4double outerNumerator = std::fabs(fOuterRadius * tanHalfTwist) * parity;
0266 
0267    fTanInnerStereo    = innerNumerator / fZHalfLength; 
0268    fTanOuterStereo    = outerNumerator / fZHalfLength; 
0269    fTanInnerStereo2   = fTanInnerStereo * fTanInnerStereo;
0270    fTanOuterStereo2   = fTanOuterStereo * fTanOuterStereo;
0271    fInnerStereo       = std::atan2(innerNumerator,  fZHalfLength); 
0272    fOuterStereo       = std::atan2(outerNumerator,  fZHalfLength); 
0273    fEndInnerRadius[0] = std::sqrt(fInnerRadius2 + fEndZ2[0] * fTanInnerStereo2);
0274    fEndInnerRadius[1] = std::sqrt(fInnerRadius2 + fEndZ2[1] * fTanInnerStereo2);
0275    fEndOuterRadius[0] = std::sqrt(fOuterRadius2 + fEndZ2[0] * fTanOuterStereo2);
0276    fEndOuterRadius[1] = std::sqrt(fOuterRadius2 + fEndZ2[1] * fTanOuterStereo2);
0277 
0278    fKappa          = tanHalfTwist / fZHalfLength;
0279    fEndPhi[0]      = std::atan2(fEndZ[0] * tanHalfTwist, fZHalfLength);
0280    fEndPhi[1]      = std::atan2(fEndZ[1] * tanHalfTwist, fZHalfLength);
0281 
0282 #ifdef G4TWISTDEBUG
0283    G4cout << "/********* G4TwistedTubs::SetFields() Field Parameters ***************** " << G4endl;
0284    G4cout << "/*   fPhiTwist                  : " << fPhiTwist << G4endl;
0285    G4cout << "/*   fEndZ(0, 1)                : " << fEndZ[0] << " , " << fEndZ[1] << G4endl; 
0286    G4cout << "/*   fEndPhi(0, 1)              : " << fEndPhi[0] << " , " << fEndPhi[1] << G4endl; 
0287    G4cout << "/*   fInnerRadius, fOuterRadius : " << fInnerRadius << " , " << fOuterRadius << G4endl; 
0288    G4cout << "/*   fEndInnerRadius(0, 1)      : " << fEndInnerRadius[0] << " , " 
0289           << fEndInnerRadius[1] << G4endl; 
0290    G4cout << "/*   fEndOuterRadius(0, 1)      : " << fEndOuterRadius[0] << " , " 
0291           << fEndOuterRadius[1] << G4endl; 
0292    G4cout << "/*   fInnerStereo, fOuterStereo : " << fInnerStereo << " , " << fOuterStereo << G4endl; 
0293    G4cout << "/*   tanHalfTwist, fKappa       : " << tanHalfTwist << " , " << fKappa << G4endl; 
0294    G4cout << "/*********************************************************************** " << G4endl;
0295 #endif
0296 }
0297 
0298 #endif