Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 09:12:46

0001 // @(#)root/geom:$Id$
0002 // Author: Andrei Gheata   31/01/02
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TGeoShape
0013 #define ROOT_TGeoShape
0014 
0015 #include "TNamed.h"
0016 
0017 // forward declarations
0018 class TGeoBoolCombinator;
0019 class TGeoBBox;
0020 class TGeoMatrix;
0021 class TGeoHMatrix;
0022 class TGeoVolume;
0023 class TBuffer3D;
0024 
0025 class TGeoShape : public TNamed {
0026 private:
0027    static TGeoMatrix *fgTransform; // current transformation matrix that applies to shape
0028    static Double_t fgEpsMch;       // Machine round-off error
0029 public:
0030    enum EShapeType {
0031       kBitMask32 = 0xffffffff,
0032       kGeoNoShape = 0,
0033       kGeoBad = BIT(0),
0034       kGeoRSeg = BIT(1),
0035       kGeoPhiSeg = BIT(2),
0036       kGeoThetaSeg = BIT(3),
0037       kGeoVisX = BIT(4),
0038       kGeoVisY = BIT(5),
0039       kGeoVisZ = BIT(6),
0040       kGeoRunTimeShape = BIT(7),
0041       kGeoInvalidShape = BIT(8),
0042       kGeoTorus = BIT(9),
0043       kGeoBox = BIT(10),
0044       kGeoPara = BIT(11),
0045       kGeoSph = BIT(12),
0046       kGeoTube = BIT(13),
0047       kGeoTubeSeg = BIT(14),
0048       kGeoCone = BIT(15),
0049       kGeoConeSeg = BIT(16),
0050       kGeoPcon = BIT(17),
0051       kGeoPgon = BIT(18),
0052       kGeoArb8 = BIT(19),
0053       kGeoEltu = BIT(20),
0054       kGeoTrap = BIT(21),
0055       kGeoCtub = BIT(22),
0056       kGeoTrd1 = BIT(23),
0057       kGeoTrd2 = BIT(24),
0058       kGeoComb = BIT(25),
0059       kGeoClosedShape = BIT(26),
0060       kGeoXtru = BIT(27),
0061       kGeoParaboloid = BIT(28),
0062       kGeoHalfSpace = BIT(29),
0063       kGeoHype = BIT(30),
0064       kGeoSavePrimitive = BIT(20)
0065    };
0066 
0067    enum EInside {
0068       kInside = 1,
0069       kOutside = 2,
0070       kSurface = 3
0071    };
0072 
0073    virtual void ClearThreadData() const {}
0074    virtual void CreateThreadData(Int_t) {}
0075 
0076 protected:
0077    // data members
0078    Int_t fShapeId;    // shape id
0079    UInt_t fShapeBits; // shape bits
0080                       // methods
0081    virtual void FillBuffer3D(TBuffer3D &buffer, Int_t reqSections, Bool_t localFrame) const;
0082    Int_t GetBasicColor() const;
0083    void SetOnBoundary(Bool_t /*flag=kTRUE*/) {}
0084    void TransformPoints(Double_t *points, UInt_t NbPoints) const;
0085 
0086 public:
0087    // constructors
0088    TGeoShape();
0089    TGeoShape(const char *name);
0090    // destructor
0091    ~TGeoShape() override;
0092    // methods
0093 
0094    static Double_t Big() { return 1.E30; }
0095    static TGeoMatrix *GetTransform();
0096    static void SetTransform(TGeoMatrix *matrix);
0097    static Double_t Tolerance() { return 1.E-10; }
0098    static Double_t ComputeEpsMch();
0099    static Double_t EpsMch();
0100    virtual void AfterStreamer(){};
0101    virtual Double_t Capacity() const = 0;
0102    void CheckShape(Int_t testNo, Int_t nsamples = 10000, Option_t *option = "");
0103    virtual void ComputeBBox() = 0;
0104    virtual void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) const = 0;
0105    virtual void ComputeNormal_v(const Double_t *, const Double_t *, Double_t *, Int_t) {}
0106    virtual Bool_t Contains(const Double_t *point) const = 0;
0107    virtual void Contains_v(const Double_t *, Bool_t *, Int_t) const {}
0108    virtual Bool_t CouldBeCrossed(const Double_t *point, const Double_t *dir) const = 0;
0109    Int_t DistancetoPrimitive(Int_t px, Int_t py) override = 0;
0110    virtual Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact = 1,
0111                                    Double_t step = TGeoShape::Big(), Double_t *safe = nullptr) const = 0;
0112    virtual void DistFromInside_v(const Double_t *, const Double_t *, Double_t *, Int_t, Double_t *) const {}
0113    virtual Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact = 1,
0114                                     Double_t step = TGeoShape::Big(), Double_t *safe = nullptr) const = 0;
0115    virtual void DistFromOutside_v(const Double_t *, const Double_t *, Double_t *, Int_t, Double_t *) const {}
0116    static Double_t DistToPhiMin(const Double_t *point, const Double_t *dir, Double_t s1, Double_t c1, Double_t s2,
0117                                 Double_t c2, Double_t sm, Double_t cm, Bool_t in = kTRUE);
0118    virtual TGeoVolume *
0119    Divide(TGeoVolume *voldiv, const char *divname, Int_t iaxis, Int_t ndiv, Double_t start, Double_t step) = 0;
0120    void Draw(Option_t *option = "") override; // *MENU*
0121    void ExecuteEvent(Int_t event, Int_t px, Int_t py) override;
0122    virtual const char *GetAxisName(Int_t iaxis) const = 0;
0123    virtual Double_t GetAxisRange(Int_t iaxis, Double_t &xlo, Double_t &xhi) const = 0;
0124    virtual void GetBoundingCylinder(Double_t *param) const = 0;
0125    virtual const TBuffer3D &GetBuffer3D(Int_t reqSections, Bool_t localFrame) const;
0126    virtual Int_t GetByteCount() const = 0;
0127    virtual Bool_t GetPointsOnSegments(Int_t npoints, Double_t *array) const = 0;
0128    virtual Int_t
0129    GetFittingBox(const TGeoBBox *parambox, TGeoMatrix *mat, Double_t &dx, Double_t &dy, Double_t &dz) const = 0;
0130    Int_t GetId() const { return fShapeId; }
0131    virtual TGeoShape *GetMakeRuntimeShape(TGeoShape *mother, TGeoMatrix *mat) const = 0;
0132    virtual void GetMeshNumbers(Int_t & /*nvert*/, Int_t & /*nsegs*/, Int_t & /*npols*/) const {}
0133    const char *GetName() const override;
0134    virtual Int_t GetNmeshVertices() const { return 0; }
0135    const char *GetPointerName() const;
0136    virtual EInside Inside(const Double_t *point) const;
0137    virtual Bool_t IsAssembly() const { return kFALSE; }
0138    virtual Bool_t IsComposite() const { return kFALSE; }
0139    virtual Bool_t IsCylType() const = 0;
0140    static Bool_t
0141    IsCloseToPhi(Double_t epsil, const Double_t *point, Double_t c1, Double_t s1, Double_t c2, Double_t s2);
0142    static Bool_t IsCrossingSemiplane(const Double_t *point, const Double_t *dir, Double_t cphi, Double_t sphi,
0143                                      Double_t &snext, Double_t &rxy);
0144    static Bool_t IsSameWithinTolerance(Double_t a, Double_t b);
0145    static Bool_t IsSegCrossing(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Double_t x3, Double_t y3,
0146                                Double_t x4, Double_t y4);
0147    static Bool_t IsInPhiRange(const Double_t *point, Double_t phi1, Double_t phi2);
0148    virtual Bool_t IsReflected() const { return kFALSE; }
0149    virtual Bool_t IsVecGeom() const { return kFALSE; }
0150    Bool_t IsRunTimeShape() const { return TestShapeBit(kGeoRunTimeShape); }
0151    Bool_t IsValid() const { return !TestShapeBit(kGeoInvalidShape); }
0152    virtual Bool_t IsValidBox() const = 0;
0153    virtual void InspectShape() const = 0;
0154    virtual TBuffer3D *MakeBuffer3D() const { return nullptr; }
0155    static void NormalPhi(const Double_t *point, const Double_t *dir, Double_t *norm, Double_t c1, Double_t s1,
0156                          Double_t c2, Double_t s2);
0157    void Paint(Option_t *option = "") override;
0158    virtual Double_t Safety(const Double_t *point, Bool_t in = kTRUE) const = 0;
0159    virtual void Safety_v(const Double_t *, const Bool_t *, Double_t *, Int_t) const {}
0160    static Double_t SafetyPhi(const Double_t *point, Bool_t in, Double_t phi1, Double_t phi2);
0161    static Double_t SafetySeg(Double_t r, Double_t z, Double_t r1, Double_t z1, Double_t r2, Double_t z2, Bool_t outer);
0162    virtual void SetDimensions(Double_t *param) = 0;
0163    void SetId(Int_t id) { fShapeId = id; }
0164    virtual void SetPoints(Double_t *points) const = 0;
0165    virtual void SetPoints(Float_t *points) const = 0;
0166    virtual void SetSegsAndPols(TBuffer3D &buff) const = 0;
0167    void SetRuntime(Bool_t flag = kTRUE) { SetShapeBit(kGeoRunTimeShape, flag); }
0168    Int_t ShapeDistancetoPrimitive(Int_t numpoints, Int_t px, Int_t py) const;
0169    virtual void Sizeof3D() const = 0;
0170 
0171    //----- bit manipulation
0172    void SetShapeBit(UInt_t f, Bool_t set);
0173    void SetShapeBit(UInt_t f) { fShapeBits |= f & kBitMask32; }
0174    void ResetShapeBit(UInt_t f) { fShapeBits &= ~(f & kBitMask32); }
0175    Bool_t TestShapeBit(UInt_t f) const { return (Bool_t)((fShapeBits & f) != 0); }
0176    Int_t TestShapeBits(UInt_t f) const { return (Int_t)(fShapeBits & f); }
0177    void InvertShapeBit(UInt_t f) { fShapeBits ^= f & kBitMask32; }
0178 
0179    ClassDefOverride(TGeoShape, 2) // base class for shapes
0180 };
0181 
0182 namespace tgeo_impl {
0183 /// @brief Generic implementation of the inside function using just Contains and GetNormal
0184 template <typename Solid>
0185 TGeoShape::EInside Inside(const Double_t *point, Solid const *solid)
0186 {
0187    // This emulates the Inside funtionality in Geant4 and VecGeom, i.e instead of
0188    // just 'inside' and 'outside', points closer to the shape surface by less than
0189    // TGeoShape::Tolerance() (1.e-9 mm) are considered on surface.
0190    // This function is expensive because it costs 2 * Contains + 1 * GetNormal calls
0191 
0192    // Compute the normal in the point, along a radial direction
0193    constexpr TGeoShape::EInside kTable[4] = {TGeoShape::kOutside, TGeoShape::kSurface, TGeoShape::kSurface,
0194                                              TGeoShape::kInside};
0195    constexpr double dir[3] = {1., 0., 0.};
0196    double pt_push[3], pt_pull[3], norm[3];
0197    solid->ComputeNormal(point, &dir[0], norm);
0198    // Move the point back and forth along the normal and check if the Contains changes
0199    for (auto i = 0; i < 3; ++i) {
0200       pt_push[i] = point[i] + 10. * TGeoShape::Tolerance() * norm[i];
0201       pt_pull[i] = point[i] - 10. * TGeoShape::Tolerance() * norm[i];
0202    }
0203    int in_push = solid->Contains(pt_push);
0204    int in_pull = solid->Contains(pt_pull);
0205    return kTable[in_push + 2 * in_pull];
0206 }
0207 } // namespace tgeo_impl
0208 
0209 #endif