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