// @(#)root/base:$Id$
// Author: Andrei Gheata   24/10/01

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TGeoTube
#define ROOT_TGeoTube

#ifndef ROOT_TGeoBBox
#include "TGeoBBox.h"
#endif

////////////////////////////////////////////////////////////////////////////
//                                                                        //
// TGeoTube - cylindrical tube  class. A tube has 3 parameters :          //
//            Rmin - minimum radius                                       //
//            Rmax - maximum radius                                       //
//            dz - half length                                            //
//                                                                        //
////////////////////////////////////////////////////////////////////////////

class TGeoTube : public TGeoBBox
{
protected :
// data members
   Double_t              fRmin; // inner radius
   Double_t              fRmax; // outer radius
   Double_t              fDz;   // half length
// methods

public:
   // constructors
   TGeoTube();
   TGeoTube(Double_t rmin, Double_t rmax, Double_t dz);
   TGeoTube(const char * name, Double_t rmin, Double_t rmax, Double_t dz);
   TGeoTube(Double_t *params);
   // destructor
   virtual ~TGeoTube();
   // methods

   virtual Double_t      Capacity() const;
   static  Double_t      Capacity(Double_t rmin, Double_t rmax, Double_t dz);
   virtual void          ComputeBBox();
   virtual void          ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm);
   virtual void          ComputeNormal_v(const Double_t *points, const Double_t *dirs, Double_t *norms, Int_t vecsize);
   static  void          ComputeNormalS(const Double_t *point, const Double_t *dir, Double_t *norm,
                                        Double_t rmin, Double_t rmax, Double_t dz);
   virtual Bool_t        Contains(const Double_t *point) const;
   virtual void          Contains_v(const Double_t *points, Bool_t *inside, Int_t vecsize) const;
   static  Double_t      DistFromInsideS(const Double_t *point, const Double_t *dir, Double_t rmin, Double_t rmax, Double_t dz);
   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;
   virtual void          DistFromInside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t *step) const;
   static  Double_t      DistFromOutsideS(const Double_t *point, const Double_t *dir, Double_t rmin, Double_t rmax, Double_t dz);
   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;
   virtual void          DistFromOutside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t *step) const;
   static  void          DistToTube(Double_t rsq, Double_t nsq, Double_t rdotn, Double_t radius, Double_t &b, Double_t &delta);
   virtual Int_t         DistancetoPrimitive(Int_t px, Int_t py);
   virtual TGeoVolume   *Divide(TGeoVolume *voldiv, const char *divname, Int_t iaxis, Int_t ndiv,
                                Double_t start, Double_t step);
   virtual const char   *GetAxisName(Int_t iaxis) const;
   virtual Double_t      GetAxisRange(Int_t iaxis, Double_t &xlo, Double_t &xhi) const;
   virtual void          GetBoundingCylinder(Double_t *param) const;
   virtual const TBuffer3D &GetBuffer3D(Int_t reqSections, Bool_t localFrame) const;
   virtual Int_t         GetByteCount() const {return 48;}
   virtual Bool_t        GetPointsOnSegments(Int_t npoints, Double_t *array) const;
   virtual TGeoShape    *GetMakeRuntimeShape(TGeoShape *mother, TGeoMatrix *mat) const;
   virtual void          GetMeshNumbers(Int_t &nvert, Int_t &nsegs, Int_t &npols) const;
   virtual Int_t         GetNmeshVertices() const;
   virtual Double_t      GetRmin() const {return fRmin;}
   virtual Double_t      GetRmax() const {return fRmax;}
   virtual Double_t      GetDz() const   {return fDz;}
   Bool_t                HasRmin() const {return (fRmin>0)?kTRUE:kFALSE;}
   virtual void          InspectShape() const;
   virtual Bool_t        IsCylType() const {return kTRUE;}
   virtual TBuffer3D    *MakeBuffer3D() const;
   virtual Double_t      Safety(const Double_t *point, Bool_t in=kTRUE) const;
   virtual void          Safety_v(const Double_t *points, const Bool_t *inside, Double_t *safe, Int_t vecsize) const;
   static  Double_t      SafetyS(const Double_t *point, Bool_t in, Double_t rmin, Double_t rmax, Double_t dz, Int_t skipz=0);
   virtual void          SavePrimitive(std::ostream &out, Option_t *option = "");
   void                  SetTubeDimensions(Double_t rmin, Double_t rmax, Double_t dz);
   virtual void          SetDimensions(Double_t *param);
   virtual void          SetPoints(Double_t *points) const;
   virtual void          SetPoints(Float_t *points) const;
   virtual void          SetSegsAndPols(TBuffer3D &buff) const;
   virtual void          Sizeof3D() const;

   ClassDef(TGeoTube, 1)         // cylindrical tube class

};

////////////////////////////////////////////////////////////////////////////
//                                                                        //
// TGeoTubeSeg - a phi segment of a tube. Has 5 parameters :              //
//            - the same 3 as a tube;                                     //
//            - first phi limit (in degrees)                              //
//            - second phi limit                                          //
//                                                                        //
////////////////////////////////////////////////////////////////////////////

class TGeoTubeSeg : public TGeoTube
{
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
   TGeoTubeSeg();
   TGeoTubeSeg(Double_t rmin, Double_t rmax, Double_t dz,
               Double_t phi1, Double_t phi2);
   TGeoTubeSeg(const char * name, Double_t rmin, Double_t rmax, Double_t dz,
               Double_t phi1, Double_t phi2);
   TGeoTubeSeg(Double_t *params);
   // 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();
   virtual void          ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm);
   virtual void          ComputeNormal_v(const Double_t *points, const Double_t *dirs, Double_t *norms, Int_t vecsize);
   static  void          ComputeNormalS(const Double_t *point, const Double_t *dir, Double_t *norm,
                                        Double_t rmin, Double_t rmax, Double_t dz,
                                        Double_t c1, Double_t s1, Double_t c2, Double_t s2);
   virtual Bool_t        Contains(const Double_t *point) const;
   virtual void          Contains_v(const Double_t *points, Bool_t *inside, Int_t vecsize) const;
   virtual Int_t         DistancetoPrimitive(Int_t px, Int_t py);
   static  Double_t      DistFromInsideS(const Double_t *point, const Double_t *dir,Double_t rmin, Double_t rmax, Double_t dz,
                                    Double_t c1, Double_t s1, Double_t c2, Double_t s2, Double_t cm, Double_t sm, Double_t cdfi);
   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;
   virtual void          DistFromInside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t *step) const;
   static  Double_t      DistFromOutsideS(const Double_t *point, const Double_t *dir, Double_t rmin, Double_t rmax, Double_t dz,
                                   Double_t c1, Double_t s1, Double_t c2, Double_t s2, Double_t cm, Double_t sm, Double_t cdfi);
   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;
   virtual void          DistFromOutside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t *step) const;
   virtual TGeoVolume   *Divide(TGeoVolume *voldiv, const char *divname, Int_t iaxis, Int_t ndiv,
                                Double_t start, Double_t step);
   virtual Double_t      GetAxisRange(Int_t iaxis, Double_t &xlo, Double_t &xhi) const;
   virtual void          GetBoundingCylinder(Double_t *param) const;
   virtual const TBuffer3D &GetBuffer3D(Int_t reqSections, Bool_t localFrame) const;
   virtual Int_t         GetByteCount() const {return 56;}
   virtual Bool_t        GetPointsOnSegments(Int_t npoints, Double_t *array) const;
   virtual TGeoShape    *GetMakeRuntimeShape(TGeoShape *mother, TGeoMatrix *mat) const;
   virtual Int_t         GetNmeshVertices() const;
   virtual void          GetMeshNumbers(Int_t &nvert, Int_t &nsegs, Int_t &npols) const;
   Double_t              GetPhi1() const {return fPhi1;}
   Double_t              GetPhi2() const {return fPhi2;}
   virtual void          InspectShape() const;
   virtual TBuffer3D    *MakeBuffer3D() const;
   virtual Double_t      Safety(const Double_t *point, Bool_t in=kTRUE) const;
   virtual void          Safety_v(const Double_t *points, const Bool_t *inside, Double_t *safe, Int_t vecsize) const;
   static  Double_t      SafetyS(const Double_t *point, Bool_t in, Double_t rmin, Double_t rmax, Double_t dz,
                                 Double_t phi1, Double_t phi2, Int_t skipz=0);
   virtual void          SavePrimitive(std::ostream &out, Option_t *option = "");
   void                  SetTubsDimensions(Double_t rmin, Double_t rmax, Double_t dz,
                                       Double_t phi1, Double_t phi2);
   virtual void          SetDimensions(Double_t *param);
   virtual void          SetPoints(Double_t *points) const;
   virtual void          SetPoints(Float_t *points) const;
   virtual void          SetSegsAndPols(TBuffer3D &buff) const;
   virtual void          Sizeof3D() const;

   ClassDef(TGeoTubeSeg, 1)         // cylindrical tube segment class
};

////////////////////////////////////////////////////////////////////////////
//                                                                        //
// TGeoCtub - a tube segment cut with 2 planes. Has 11 parameters :       //
//            - the same 5 as a tube segment;                             //
//            - x,y,z components of the normal to the -dZ cut plane in    //
//              point (0,0,-dZ)                                           //
//            -  x,y,z components of the normal to the +dZ cut plane in   //
//              point (0,0,dZ)                                            //
//                                                                        //
////////////////////////////////////////////////////////////////////////////

class TGeoCtub : public TGeoTubeSeg
{
protected:
   // data members
   Double_t             fNlow[3];  // normal to lower cut plane
   Double_t             fNhigh[3]; // normal to highet cut plane

public:
   // constructors
   TGeoCtub();
   TGeoCtub(Double_t rmin, Double_t rmax, Double_t dz, Double_t phi1, Double_t phi2,
            Double_t lx, Double_t ly, Double_t lz, Double_t tx, Double_t ty, Double_t tz);
   TGeoCtub(const char *name, Double_t rmin, Double_t rmax, Double_t dz, Double_t phi1, Double_t phi2,
            Double_t lx, Double_t ly, Double_t lz, Double_t tx, Double_t ty, Double_t tz);
   TGeoCtub(Double_t *params);
   // destructor
   virtual ~TGeoCtub();
   // methods
   virtual Double_t      Capacity() const;
   virtual void          ComputeBBox();
   virtual void          ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm);
   virtual void          ComputeNormal_v(const Double_t *points, const Double_t *dirs, Double_t *norms, Int_t vecsize);
   virtual Bool_t        Contains(const Double_t *point) const;
   virtual void          Contains_v(const Double_t *points, Bool_t *inside, Int_t vecsize) const;
   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;
   virtual void          DistFromInside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t *step) const;
   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;
   virtual void          DistFromOutside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t *step) const;
   virtual TGeoVolume   *Divide(TGeoVolume *voldiv, const char *divname, Int_t iaxis, Int_t ndiv,
                                Double_t start, Double_t step);
   virtual Double_t      GetAxisRange(Int_t iaxis, Double_t &xlo, Double_t &xhi) const;
   virtual const TBuffer3D &GetBuffer3D(Int_t reqSections, Bool_t localFrame) const;
   virtual Int_t         GetByteCount() const {return 98;}
   virtual Bool_t        GetPointsOnSegments(Int_t npoints, Double_t *array) const;
   virtual TGeoShape    *GetMakeRuntimeShape(TGeoShape *mother, TGeoMatrix *mat) const;
   virtual void          GetMeshNumbers(Int_t &nvert, Int_t &nsegs, Int_t &npols) const;
   virtual Int_t         GetNmeshVertices() const;
   const Double_t       *GetNlow() const {return &fNlow[0];}
   const Double_t       *GetNhigh() const {return &fNhigh[0];}
   Double_t              GetZcoord(Double_t xc, Double_t yc, Double_t zc) const;
   virtual void          InspectShape() const;
   virtual Double_t      Safety(const Double_t *point, Bool_t in=kTRUE) const;
   virtual void          Safety_v(const Double_t *points, const Bool_t *inside, Double_t *safe, Int_t vecsize) const;
   virtual void          SavePrimitive(std::ostream &out, Option_t *option = "");
   void                  SetCtubDimensions(Double_t rmin, Double_t rmax, Double_t dz,
                                       Double_t phi1, Double_t phi2, Double_t lx, Double_t ly, Double_t lz,
                                       Double_t tx, Double_t ty, Double_t tz);
   virtual void          SetDimensions(Double_t *param);
   virtual void          SetPoints(Double_t *points) const;
   virtual void          SetPoints(Float_t *points) const;

   ClassDef(TGeoCtub, 1)         // cut tube segment class
};

#endif
 TGeoTube.h:1
 TGeoTube.h:2
 TGeoTube.h:3
 TGeoTube.h:4
 TGeoTube.h:5
 TGeoTube.h:6
 TGeoTube.h:7
 TGeoTube.h:8
 TGeoTube.h:9
 TGeoTube.h:10
 TGeoTube.h:11
 TGeoTube.h:12
 TGeoTube.h:13
 TGeoTube.h:14
 TGeoTube.h:15
 TGeoTube.h:16
 TGeoTube.h:17
 TGeoTube.h:18
 TGeoTube.h:19
 TGeoTube.h:20
 TGeoTube.h:21
 TGeoTube.h:22
 TGeoTube.h:23
 TGeoTube.h:24
 TGeoTube.h:25
 TGeoTube.h:26
 TGeoTube.h:27
 TGeoTube.h:28
 TGeoTube.h:29
 TGeoTube.h:30
 TGeoTube.h:31
 TGeoTube.h:32
 TGeoTube.h:33
 TGeoTube.h:34
 TGeoTube.h:35
 TGeoTube.h:36
 TGeoTube.h:37
 TGeoTube.h:38
 TGeoTube.h:39
 TGeoTube.h:40
 TGeoTube.h:41
 TGeoTube.h:42
 TGeoTube.h:43
 TGeoTube.h:44
 TGeoTube.h:45
 TGeoTube.h:46
 TGeoTube.h:47
 TGeoTube.h:48
 TGeoTube.h:49
 TGeoTube.h:50
 TGeoTube.h:51
 TGeoTube.h:52
 TGeoTube.h:53
 TGeoTube.h:54
 TGeoTube.h:55
 TGeoTube.h:56
 TGeoTube.h:57
 TGeoTube.h:58
 TGeoTube.h:59
 TGeoTube.h:60
 TGeoTube.h:61
 TGeoTube.h:62
 TGeoTube.h:63
 TGeoTube.h:64
 TGeoTube.h:65
 TGeoTube.h:66
 TGeoTube.h:67
 TGeoTube.h:68
 TGeoTube.h:69
 TGeoTube.h:70
 TGeoTube.h:71
 TGeoTube.h:72
 TGeoTube.h:73
 TGeoTube.h:74
 TGeoTube.h:75
 TGeoTube.h:76
 TGeoTube.h:77
 TGeoTube.h:78
 TGeoTube.h:79
 TGeoTube.h:80
 TGeoTube.h:81
 TGeoTube.h:82
 TGeoTube.h:83
 TGeoTube.h:84
 TGeoTube.h:85
 TGeoTube.h:86
 TGeoTube.h:87
 TGeoTube.h:88
 TGeoTube.h:89
 TGeoTube.h:90
 TGeoTube.h:91
 TGeoTube.h:92
 TGeoTube.h:93
 TGeoTube.h:94
 TGeoTube.h:95
 TGeoTube.h:96
 TGeoTube.h:97
 TGeoTube.h:98
 TGeoTube.h:99
 TGeoTube.h:100
 TGeoTube.h:101
 TGeoTube.h:102
 TGeoTube.h:103
 TGeoTube.h:104
 TGeoTube.h:105
 TGeoTube.h:106
 TGeoTube.h:107
 TGeoTube.h:108
 TGeoTube.h:109
 TGeoTube.h:110
 TGeoTube.h:111
 TGeoTube.h:112
 TGeoTube.h:113
 TGeoTube.h:114
 TGeoTube.h:115
 TGeoTube.h:116
 TGeoTube.h:117
 TGeoTube.h:118
 TGeoTube.h:119
 TGeoTube.h:120
 TGeoTube.h:121
 TGeoTube.h:122
 TGeoTube.h:123
 TGeoTube.h:124
 TGeoTube.h:125
 TGeoTube.h:126
 TGeoTube.h:127
 TGeoTube.h:128
 TGeoTube.h:129
 TGeoTube.h:130
 TGeoTube.h:131
 TGeoTube.h:132
 TGeoTube.h:133
 TGeoTube.h:134
 TGeoTube.h:135
 TGeoTube.h:136
 TGeoTube.h:137
 TGeoTube.h:138
 TGeoTube.h:139
 TGeoTube.h:140
 TGeoTube.h:141
 TGeoTube.h:142
 TGeoTube.h:143
 TGeoTube.h:144
 TGeoTube.h:145
 TGeoTube.h:146
 TGeoTube.h:147
 TGeoTube.h:148
 TGeoTube.h:149
 TGeoTube.h:150
 TGeoTube.h:151
 TGeoTube.h:152
 TGeoTube.h:153
 TGeoTube.h:154
 TGeoTube.h:155
 TGeoTube.h:156
 TGeoTube.h:157
 TGeoTube.h:158
 TGeoTube.h:159
 TGeoTube.h:160
 TGeoTube.h:161
 TGeoTube.h:162
 TGeoTube.h:163
 TGeoTube.h:164
 TGeoTube.h:165
 TGeoTube.h:166
 TGeoTube.h:167
 TGeoTube.h:168
 TGeoTube.h:169
 TGeoTube.h:170
 TGeoTube.h:171
 TGeoTube.h:172
 TGeoTube.h:173
 TGeoTube.h:174
 TGeoTube.h:175
 TGeoTube.h:176
 TGeoTube.h:177
 TGeoTube.h:178
 TGeoTube.h:179
 TGeoTube.h:180
 TGeoTube.h:181
 TGeoTube.h:182
 TGeoTube.h:183
 TGeoTube.h:184
 TGeoTube.h:185
 TGeoTube.h:186
 TGeoTube.h:187
 TGeoTube.h:188
 TGeoTube.h:189
 TGeoTube.h:190
 TGeoTube.h:191
 TGeoTube.h:192
 TGeoTube.h:193
 TGeoTube.h:194
 TGeoTube.h:195
 TGeoTube.h:196
 TGeoTube.h:197
 TGeoTube.h:198
 TGeoTube.h:199
 TGeoTube.h:200
 TGeoTube.h:201
 TGeoTube.h:202
 TGeoTube.h:203
 TGeoTube.h:204
 TGeoTube.h:205
 TGeoTube.h:206
 TGeoTube.h:207
 TGeoTube.h:208
 TGeoTube.h:209
 TGeoTube.h:210
 TGeoTube.h:211
 TGeoTube.h:212
 TGeoTube.h:213
 TGeoTube.h:214
 TGeoTube.h:215
 TGeoTube.h:216
 TGeoTube.h:217
 TGeoTube.h:218
 TGeoTube.h:219
 TGeoTube.h:220
 TGeoTube.h:221
 TGeoTube.h:222
 TGeoTube.h:223
 TGeoTube.h:224
 TGeoTube.h:225
 TGeoTube.h:226
 TGeoTube.h:227
 TGeoTube.h:228
 TGeoTube.h:229
 TGeoTube.h:230
 TGeoTube.h:231
 TGeoTube.h:232
 TGeoTube.h:233
 TGeoTube.h:234
 TGeoTube.h:235
 TGeoTube.h:236
 TGeoTube.h:237
 TGeoTube.h:238
 TGeoTube.h:239
 TGeoTube.h:240
 TGeoTube.h:241
 TGeoTube.h:242
 TGeoTube.h:243
 TGeoTube.h:244
 TGeoTube.h:245
 TGeoTube.h:246
 TGeoTube.h:247
 TGeoTube.h:248
 TGeoTube.h:249
 TGeoTube.h:250
 TGeoTube.h:251
 TGeoTube.h:252
 TGeoTube.h:253
 TGeoTube.h:254
 TGeoTube.h:255