File indexing completed on 2026-09-13 09:25:55
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef ROOT_TGeoVolume
0014 #define ROOT_TGeoVolume
0015
0016 #include "TNamed.h"
0017 #include "TGeoAtt.h"
0018 #include "TAttLine.h"
0019 #include "TAttFill.h"
0020 #include "TAtt3D.h"
0021 #include "TObjArray.h"
0022 #include "TGeoMedium.h"
0023 #include "TGeoShape.h"
0024 #include <mutex>
0025 #include <vector>
0026
0027
0028 class TH2F;
0029 class TGeoNode;
0030 class TGeoMatrix;
0031 class TGeoPatternFinder;
0032 class TGeoVoxelFinder;
0033 class TGeoManager;
0034 class TGeoExtension;
0035
0036
0037
0038
0039
0040
0041
0042
0043 class TGeoVolume : public TNamed, public TGeoAtt, public TAttLine, public TAttFill, public TAtt3D {
0044 protected:
0045 TObjArray *fNodes;
0046 TGeoShape *fShape;
0047 TGeoMedium *fMedium;
0048 static TGeoMedium *fgDummyMedium;
0049 TGeoPatternFinder *fFinder;
0050 TGeoVoxelFinder *fVoxels;
0051 TGeoManager *fGeoManager;
0052
0053 TObject *fField;
0054 TString fOption;
0055 Int_t fNumber;
0056 Int_t fNtotal;
0057 Int_t fRefCount;
0058 Char_t fTransparency;
0059 TGeoExtension *fUserExtension;
0060 TGeoExtension *fFWExtension;
0061
0062 private:
0063 TGeoVolume(const TGeoVolume &) = delete;
0064 TGeoVolume &operator=(const TGeoVolume &) = delete;
0065
0066 public:
0067 virtual void ClearThreadData() const;
0068 virtual void CreateThreadData(Int_t nthreads);
0069
0070 public:
0071 enum EGeoVolumeTypes {
0072 kVolumeReplicated = BIT(14),
0073 kVolumeSelected = BIT(15),
0074 kVolumeDiv = BIT(16),
0075 kVolumeOverlap = BIT(17),
0076 kVolumeImportNodes = BIT(18),
0077 kVolumeMulti = BIT(19),
0078 kVoxelsXYZ = BIT(20),
0079 kVoxelsCyl = BIT(21),
0080 kVolumeClone = BIT(22),
0081 kVolumeAdded = BIT(23),
0082 kVolumeOC = BIT(21)
0083 };
0084
0085 TGeoVolume();
0086 TGeoVolume(const char *name, const TGeoShape *shape, const TGeoMedium *med = nullptr);
0087
0088
0089 ~TGeoVolume() override;
0090
0091 virtual void cd(Int_t inode) const;
0092 void Browse(TBrowser *b) override;
0093 Double_t Capacity() const;
0094 void CheckShapes();
0095 void ClearNodes() { fNodes = nullptr; }
0096 void ClearShape();
0097 void CleanAll();
0098 virtual TGeoVolume *CloneVolume() const;
0099 void CloneNodesAndConnect(TGeoVolume *newmother) const;
0100 void CheckGeometry(Int_t nrays = 1, Double_t startx = 0, Double_t starty = 0, Double_t startz = 0) const;
0101 void CheckOverlaps(Double_t ovlp = 0.1, Option_t *option = "");
0102 void CheckOverlapsBySampling(Double_t ovlp = 0.1, Int_t npoints = 1000000);
0103 void CheckShape(Int_t testNo, Int_t nsamples = 10000, Option_t *option = "");
0104 Int_t CountNodes(Int_t nlevels = 1000, Int_t option = 0);
0105 Bool_t Contains(const Double_t *point) const { return fShape->Contains(point); }
0106 static void CreateDummyMedium();
0107 static TGeoMedium *DummyMedium();
0108 virtual Bool_t IsAssembly() const;
0109 Bool_t IsFolder() const override;
0110 Bool_t IsRunTime() const { return fShape->IsRunTimeShape(); }
0111 virtual Bool_t IsVolumeMulti() const { return kFALSE; }
0112 virtual TGeoNode *
0113 AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat = nullptr, Option_t *option = "");
0114 void AddNodeOffset(TGeoVolume *vol, Int_t copy_no, Double_t offset = 0, Option_t *option = "");
0115 virtual void AddNodeOverlap(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat = nullptr, Option_t *option = "");
0116
0117 virtual TGeoVolume *Divide(const char *divname, Int_t iaxis, Int_t ndiv, Double_t start, Double_t step,
0118 Int_t numed = 0, Option_t *option = "");
0119 Int_t DistancetoPrimitive(Int_t px, Int_t py) override;
0120 void Draw(Option_t *option = "") override;
0121 virtual void DrawOnly(Option_t *option = "");
0122 TH2F *LegoPlot(Int_t ntheta = 20, Double_t themin = 0., Double_t themax = 180., Int_t nphi = 60,
0123 Double_t phimin = 0., Double_t phimax = 360., Double_t rmin = 0., Double_t rmax = 9999999,
0124 Option_t *option = "");
0125 void Paint(Option_t *option = "") override;
0126 void Print(Option_t *option = "") const override;
0127 void PrintNodes() const;
0128 void PrintVoxels() const;
0129 void ReplayCreation(const TGeoVolume *other);
0130 void SetUserExtension(TGeoExtension *ext);
0131 void SetFWExtension(TGeoExtension *ext);
0132 Int_t GetRefCount() const { return fRefCount; }
0133 TGeoExtension *GetUserExtension() const { return fUserExtension; }
0134 TGeoExtension *GetFWExtension() const { return fFWExtension; }
0135 TGeoExtension *GrabUserExtension() const;
0136 TGeoExtension *GrabFWExtension() const;
0137 void Grab() { fRefCount++; }
0138 void Release()
0139 {
0140 fRefCount--;
0141 if (fRefCount == 0)
0142 delete this;
0143 }
0144 void ExecuteEvent(Int_t event, Int_t px, Int_t py) override;
0145
0146 Bool_t IsActive() const { return TGeoAtt::IsActive(); }
0147 Bool_t IsActiveDaughters() const { return TGeoAtt::IsActiveDaughters(); }
0148 Bool_t IsAdded() const { return TObject::TestBit(kVolumeAdded); }
0149 Bool_t IsOverlappingCandidate() const { return TObject::TestBit(kVolumeOC); }
0150 Bool_t IsReplicated() const { return TObject::TestBit(kVolumeReplicated); }
0151 Bool_t IsSelected() const { return TObject::TestBit(kVolumeSelected); }
0152 Bool_t IsCylVoxels() const { return TObject::TestBit(kVoxelsCyl); }
0153 Bool_t IsXYZVoxels() const { return TObject::TestBit(kVoxelsXYZ); }
0154 Bool_t IsTopVolume() const;
0155 Bool_t IsValid() const { return fShape->IsValid(); }
0156 virtual Bool_t IsVisible() const { return TGeoAtt::IsVisible(); }
0157 Bool_t IsVisibleDaughters() const { return TGeoAtt::IsVisDaughters(); }
0158 Bool_t IsVisContainers() const { return TGeoAtt::IsVisContainers(); }
0159 Bool_t IsVisLeaves() const { return TGeoAtt::IsVisLeaves(); }
0160 Bool_t IsVisOnly() const { return TGeoAtt::IsVisOnly(); }
0161 Bool_t IsAllInvisible() const;
0162 Bool_t IsRaytracing() const;
0163 static TGeoVolume *Import(const char *filename, const char *name = "", Option_t *option = "");
0164 Int_t Export(const char *filename, const char *name = "", Option_t *option = "");
0165 TGeoNode *FindNode(const char *name) const;
0166 void FindOverlaps() const;
0167 Bool_t FindMatrixOfDaughterVolume(TGeoVolume *vol) const;
0168 virtual Int_t GetCurrentNodeIndex() const { return -1; }
0169 virtual Int_t GetNextNodeIndex() const { return -1; }
0170 TObjArray *GetNodes() { return fNodes; }
0171 Int_t GetNdaughters() const;
0172 Int_t GetNtotal() const { return fNtotal; }
0173 virtual Int_t GetByteCount() const;
0174 TGeoManager *GetGeoManager() const { return fGeoManager; }
0175 TGeoMaterial *GetMaterial() const { return GetMedium()->GetMaterial(); }
0176 TGeoMedium *GetMedium() const { return (fMedium) ? fMedium : DummyMedium(); }
0177 TObject *GetField() const { return fField; }
0178 TGeoPatternFinder *GetFinder() const { return fFinder; }
0179 TGeoVoxelFinder *GetVoxels() const;
0180 const char *GetIconName() const override { return fShape->GetName(); }
0181 Int_t GetIndex(const TGeoNode *node) const;
0182 TGeoNode *GetNode(const char *name) const;
0183 TGeoNode *GetNode(Int_t i) const { return (TGeoNode *)fNodes->UncheckedAt(i); }
0184 Int_t GetNodeIndex(const TGeoNode *node, Int_t *check_list, Int_t ncheck) const;
0185 Int_t GetNumber() const { return fNumber; }
0186 char *GetObjectInfo(Int_t px, Int_t py) const override;
0187 Bool_t GetOptimalVoxels() const;
0188 Option_t *GetOption() const override { return fOption.Data(); }
0189 const char *GetPointerName() const;
0190 Char_t GetTransparency() const;
0191 TGeoShape *GetShape() const { return fShape; }
0192 void GrabFocus();
0193 void Gsord(Int_t ) {}
0194 Bool_t IsStyleDefault() const;
0195 void InspectMaterial() const;
0196 void InspectShape() const { fShape->InspectShape(); }
0197 virtual TGeoVolume *MakeCopyVolume(TGeoShape *newshape);
0198 void MakeCopyNodes(const TGeoVolume *other);
0199 TGeoVolume *MakeReflectedVolume(const char *newname = "") const;
0200 Bool_t OptimizeVoxels();
0201 void RandomPoints(Int_t npoints = 1000000, Option_t *option = "");
0202 void RandomRays(Int_t nrays = 10000, Double_t startx = 0, Double_t starty = 0, Double_t startz = 0,
0203 const char *target_vol = nullptr, Bool_t check_norm = kFALSE);
0204 void Raytrace(Bool_t flag = kTRUE);
0205 void RegisterYourself(Option_t *option = "");
0206 void RemoveNode(TGeoNode *node);
0207 TGeoNode *ReplaceNode(TGeoNode *nodeorig, TGeoShape *newshape = nullptr, TGeoMatrix *newpos = nullptr,
0208 TGeoMedium *newmed = nullptr);
0209 void ResetTransparency(Char_t transparency = -1);
0210 void SaveAs(const char *filename = "", Option_t *option = "") const override;
0211 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0212 void SelectVolume(Bool_t clear = kFALSE);
0213 void SetActivity(Bool_t flag = kTRUE) { TGeoAtt::SetActivity(flag); }
0214 void SetActiveDaughters(Bool_t flag = kTRUE) { TGeoAtt::SetActiveDaughters(flag); }
0215 void SetAsTopVolume();
0216 void SetAdded() { TObject::SetBit(kVolumeAdded); }
0217 void SetReplicated() { TObject::SetBit(kVolumeReplicated); }
0218 void SetCurrentPoint(Double_t x, Double_t y, Double_t z);
0219 void SetCylVoxels(Bool_t flag = kTRUE)
0220 {
0221 TObject::SetBit(kVoxelsCyl, flag);
0222 TObject::SetBit(kVoxelsXYZ, !flag);
0223 }
0224 void SetNodes(TObjArray *nodes)
0225 {
0226 fNodes = nodes;
0227 TObject::SetBit(kVolumeImportNodes);
0228 }
0229 void SetOverlappingCandidate(Bool_t flag) { TObject::SetBit(kVolumeOC, flag); }
0230 void SetShape(const TGeoShape *shape);
0231 void SetTransparency(Char_t transparency = 0);
0232 void SetField(TObject *field) { fField = field; }
0233 void SetOption(const char *option);
0234 void SetAttVisibility(Bool_t vis) { TGeoAtt::SetVisibility(vis); }
0235 void SetVisibility(Bool_t vis = kTRUE) override;
0236 void SetVisContainers(Bool_t flag = kTRUE) override;
0237 void SetVisLeaves(Bool_t flag = kTRUE) override;
0238 void SetVisOnly(Bool_t flag = kTRUE) override;
0239 void SetLineColor(Color_t lcolor) override;
0240 void SetLineStyle(Style_t lstyle) override;
0241 void SetLineWidth(Width_t lwidth) override;
0242 void SetInvisible() { SetVisibility(kFALSE); }
0243 virtual void SetMedium(TGeoMedium *medium) { fMedium = medium; }
0244 void SetVoxelFinder(TGeoVoxelFinder *finder) { fVoxels = finder; }
0245 void SetFinder(TGeoPatternFinder *finder) { fFinder = finder; }
0246 void SetNumber(Int_t number) { fNumber = number; }
0247 void SetNtotal(Int_t ntotal) { fNtotal = ntotal; }
0248 void SortNodes();
0249 void UnmarkSaved();
0250 Bool_t Valid() const;
0251 void VisibleDaughters(Bool_t vis = kTRUE);
0252 void InvisibleAll(Bool_t flag = kTRUE);
0253 void Voxelize(Option_t *option);
0254 Double_t Weight(Double_t precision = 0.01, Option_t *option = "va");
0255 Double_t WeightA() const;
0256
0257 ClassDefOverride(TGeoVolume, 7)
0258 };
0259
0260
0261
0262
0263
0264
0265
0266
0267 class TGeoVolumeMulti : public TGeoVolume {
0268 private:
0269 TObjArray *fVolumes;
0270 TGeoVolumeMulti *fDivision;
0271 Int_t fNumed;
0272 Int_t fNdiv;
0273 Int_t fAxis;
0274 Double_t fStart;
0275 Double_t fStep;
0276 Bool_t fAttSet;
0277
0278 TGeoVolumeMulti(const TGeoVolumeMulti &) = delete;
0279 TGeoVolumeMulti &operator=(const TGeoVolumeMulti &) = delete;
0280
0281 public:
0282 TGeoVolumeMulti();
0283 TGeoVolumeMulti(const char *name, TGeoMedium *med = nullptr);
0284 ~TGeoVolumeMulti() override;
0285
0286 void AddVolume(TGeoVolume *vol);
0287 TGeoVolume *GetVolume(Int_t id) const { return (TGeoVolume *)fVolumes->At(id); }
0288 TGeoNode *
0289 AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat, Option_t *option = "") override;
0290 void AddNodeOverlap(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat, Option_t *option = "") override;
0291 TGeoVolume *Divide(const char *divname, Int_t iaxis, Int_t ndiv, Double_t start, Double_t step, Int_t numed = 0,
0292 Option_t *option = "") override;
0293 TGeoShape *GetLastShape() const;
0294 Int_t GetNvolumes() const { return fVolumes->GetEntriesFast(); }
0295 Int_t GetAxis() const { return fNdiv; }
0296 Int_t GetNdiv() const { return fNdiv; }
0297 Double_t GetStart() const { return fStart; }
0298 Double_t GetStep() const { return fStep; }
0299 Bool_t IsVolumeMulti() const override { return kTRUE; }
0300 TGeoVolume *MakeCopyVolume(TGeoShape *newshape) override;
0301 void SetLineColor(Color_t lcolor) override;
0302 void SetLineStyle(Style_t lstyle) override;
0303 void SetLineWidth(Width_t lwidth) override;
0304 void SetMedium(TGeoMedium *medium) override;
0305 void SetVisibility(Bool_t vis = kTRUE) override;
0306
0307 ClassDefOverride(TGeoVolumeMulti, 3)
0308 };
0309
0310
0311
0312
0313
0314
0315
0316
0317 class TGeoVolumeAssembly : public TGeoVolume {
0318 public:
0319 struct ThreadData_t {
0320 Int_t fCurrent;
0321 Int_t fNext;
0322
0323 ThreadData_t();
0324 ~ThreadData_t();
0325 };
0326
0327 ThreadData_t &GetThreadData() const;
0328 void ClearThreadData() const override;
0329 void CreateThreadData(Int_t nthreads) override;
0330
0331 protected:
0332 mutable std::vector<ThreadData_t *> fThreadData;
0333 mutable Int_t fThreadSize;
0334 mutable std::mutex fMutex;
0335
0336 private:
0337 TGeoVolumeAssembly(const TGeoVolumeAssembly &) = delete;
0338 TGeoVolumeAssembly &operator=(const TGeoVolumeAssembly &) = delete;
0339
0340 public:
0341 TGeoVolumeAssembly();
0342 TGeoVolumeAssembly(const char *name);
0343 ~TGeoVolumeAssembly() override;
0344
0345 TGeoNode *AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat = nullptr, Option_t *option = "") override;
0346 void AddNodeOverlap(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat, Option_t *option) override;
0347 TGeoVolume *CloneVolume() const override;
0348 TGeoVolume *Divide(const char *divname, Int_t iaxis, Int_t ndiv, Double_t start, Double_t step, Int_t numed = 0,
0349 Option_t *option = "") override;
0350 TGeoVolume *Divide(TGeoVolume *cell, TGeoPatternFinder *pattern, Option_t *option = "spacedout");
0351 void DrawOnly(Option_t *) override {}
0352 Int_t GetCurrentNodeIndex() const override;
0353 Int_t GetNextNodeIndex() const override;
0354 Bool_t IsAssembly() const override { return kTRUE; }
0355 Bool_t IsVisible() const override { return kFALSE; }
0356 static TGeoVolumeAssembly *MakeAssemblyFromVolume(TGeoVolume *vol);
0357 void SetCurrentNodeIndex(Int_t index);
0358 void SetNextNodeIndex(Int_t index);
0359
0360 ClassDefOverride(TGeoVolumeAssembly, 2)
0361 };
0362
0363 inline Int_t TGeoVolume::GetNdaughters() const
0364 {
0365 if (!fNodes)
0366 return 0;
0367 return (fNodes->GetEntriesFast());
0368 }
0369
0370 inline Char_t TGeoVolume::GetTransparency() const
0371 {
0372
0373 if (fTransparency >= 0)
0374 return fTransparency;
0375 return !fMedium ? 0 : fMedium->GetMaterial()->GetTransparency();
0376 }
0377
0378 inline void TGeoVolume::SetTransparency(Char_t transparency)
0379 {
0380 if (fMedium) {
0381 fMedium->GetMaterial()->SetTransparency(transparency);
0382 }
0383 }
0384
0385 inline void TGeoVolume::ResetTransparency(Char_t transparency)
0386 {
0387 fTransparency = transparency;
0388 }
0389
0390 #endif