Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TGeoNode.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/geom:$Id$
0002 // Author: Andrei Gheata   24/10/01
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_TGeoNode
0013 #define ROOT_TGeoNode
0014 
0015 #include "TGeoAtt.h"
0016 
0017 #include "TNamed.h"
0018 
0019 #include "TGeoVolume.h"
0020 
0021 #include "TGeoPatternFinder.h"
0022 
0023 // forward declarations
0024 class TString;
0025 class TGeoVolume;
0026 class TGeoShape;
0027 class TGeoMedium;
0028 class TGeoMatrix;
0029 class TGeoHMatrix;
0030 class TGeoExtension;
0031 
0032 ////////////////////////////////////////////////////////////////////////////
0033 //                                                                        //
0034 // TGeoNode - base class for logical nodes. They represent volumes        //
0035 //   positioned inside a mother volume                                    //
0036 //                                                                        //
0037 ////////////////////////////////////////////////////////////////////////////
0038 
0039 class TGeoNode : public TNamed, public TGeoAtt {
0040 protected:
0041    TGeoVolume *fVolume = nullptr;           // volume associated with this
0042    TGeoVolume *fMother = nullptr;           // mother volume
0043    Int_t fNumber = 0;                       // copy number
0044    Int_t fNovlp = 0;                        // number of overlaps
0045    Int_t *fOverlaps = nullptr;              //[fNovlp] list of indices for overlapping brothers
0046    TGeoExtension *fUserExtension = nullptr; //! Transient user-defined extension to volumes
0047    TGeoExtension *fFWExtension = nullptr;   //! Transient framework-defined extension to volumes
0048 
0049    void CopyOverlaps(Int_t *ovlp, Int_t novlp);
0050 
0051 private:
0052    TGeoNode(const TGeoNode &) = delete;
0053    TGeoNode &operator=(const TGeoNode &) = delete;
0054 
0055 public:
0056    enum {
0057       kGeoNodeMatrix = BIT(14),
0058       kGeoNodeOffset = BIT(15),
0059       kGeoNodeVC = BIT(16),
0060       kGeoNodeOverlap = BIT(17),
0061       kGeoNodeCloned = BIT(18)
0062    };
0063 
0064    // constructors
0065    TGeoNode();
0066    TGeoNode(const TGeoVolume *vol);
0067    // destructor
0068    ~TGeoNode() override;
0069 
0070    void Browse(TBrowser *b) override;
0071    virtual void cd() const {}
0072    void CheckOverlaps(Double_t ovlp = 0.1, Option_t *option = ""); // *MENU*
0073    void CheckShapes();
0074    Int_t CountDaughters(Bool_t unique_volumes = kFALSE);
0075    Int_t DistancetoPrimitive(Int_t px, Int_t py) override;
0076    void Draw(Option_t *option = "") override;
0077    void DrawOnly(Option_t *option = "");
0078    void DrawOverlaps();
0079    void ExecuteEvent(Int_t event, Int_t px, Int_t py) override;
0080    void FillIdArray(Int_t &ifree, Int_t &nodeid, Int_t *array) const;
0081    Int_t FindNode(const TGeoNode *node, Int_t level);
0082    virtual Int_t GetByteCount() const { return 44; }
0083    TGeoNode *GetDaughter(Int_t ind) const { return fVolume->GetNode(ind); }
0084    virtual TGeoMatrix *GetMatrix() const = 0;
0085 
0086    Int_t GetColour() const { return fVolume->GetLineColor(); }
0087    virtual Int_t GetIndex() const { return 0; }
0088    virtual TGeoPatternFinder *GetFinder() const { return nullptr; }
0089    TGeoMedium *GetMedium() const { return fVolume->GetMedium(); }
0090    TGeoVolume *GetMotherVolume() const { return fMother; }
0091    Int_t GetNdaughters() const { return fVolume->GetNdaughters(); }
0092    TObjArray *GetNodes() const { return fVolume->GetNodes(); }
0093    Int_t GetNumber() const { return fNumber; }
0094    Int_t *GetOverlaps(Int_t &novlp) const
0095    {
0096       novlp = fNovlp;
0097       return fOverlaps;
0098    }
0099    TGeoVolume *GetVolume() const { return fVolume; }
0100    char *GetObjectInfo(Int_t px, Int_t py) const override;
0101    virtual Int_t GetOptimalVoxels() const { return 0; }
0102    void InspectNode() const; // *MENU*
0103    Bool_t IsCloned() const { return TObject::TestBit(kGeoNodeCloned); }
0104    Bool_t IsFolder() const override { return (GetNdaughters() ? kTRUE : kFALSE); }
0105    Bool_t IsOffset() const { return TObject::TestBit(kGeoNodeOffset); }
0106    Bool_t IsOnScreen() const; // *MENU*
0107    Bool_t IsOverlapping() const { return TObject::TestBit(kGeoNodeOverlap); }
0108    Bool_t IsVirtual() const { return TObject::TestBit(kGeoNodeVC); }
0109    Bool_t IsVisible() const { return (TGeoAtt::IsVisible() && fVolume->IsVisible()); }
0110    Bool_t IsVisDaughters() const { return (TGeoAtt::IsVisDaughters() && fVolume->IsVisDaughters()); }
0111    Bool_t MayOverlap(Int_t iother) const;
0112 
0113    virtual TGeoNode *MakeCopyNode() const { return nullptr; }
0114    Double_t Safety(const Double_t *point, Bool_t in = kTRUE) const;
0115    void SaveAttributes(std::ostream &out);
0116    void SetCurrentPoint(Double_t x, Double_t y, Double_t z) { fVolume->SetCurrentPoint(x, y, z); } // *MENU*
0117    void SetVolume(TGeoVolume *volume) { fVolume = volume; }
0118    void SetNumber(Int_t number) { fNumber = number; }
0119    void SetCloned(Bool_t flag = kTRUE) { TObject::SetBit(kGeoNodeCloned, flag); }
0120    void SetOverlapping(Bool_t flag = kTRUE) { TObject::SetBit(kGeoNodeOverlap, flag); }
0121    void SetVirtual() { TObject::SetBit(kGeoNodeVC, kTRUE); }
0122    void SetVisibility(Bool_t vis = kTRUE) override;     // *MENU*
0123    void SetInvisible() { SetVisibility(kFALSE); }       // *MENU*
0124    void SetAllInvisible() { VisibleDaughters(kFALSE); } // *MENU*
0125    void SetMotherVolume(TGeoVolume *mother) { fMother = mother; }
0126    void SetOverlaps(Int_t *ovlp, Int_t novlp);
0127    void SetUserExtension(TGeoExtension *ext);
0128    void SetFWExtension(TGeoExtension *ext);
0129    TGeoExtension *GetUserExtension() const { return fUserExtension; }
0130    TGeoExtension *GetFWExtension() const { return fFWExtension; }
0131    TGeoExtension *GrabUserExtension() const;
0132    TGeoExtension *GrabFWExtension() const;
0133 
0134    virtual void MasterToLocal(const Double_t *master, Double_t *local) const;
0135    virtual void MasterToLocalVect(const Double_t *master, Double_t *local) const;
0136    virtual void LocalToMaster(const Double_t *local, Double_t *master) const;
0137    virtual void LocalToMasterVect(const Double_t *local, Double_t *master) const;
0138 
0139    void ls(Option_t *option = "") const override;
0140    void Paint(Option_t *option = "") override;
0141    void PrintCandidates() const;              // *MENU*
0142    void PrintOverlaps() const;                // *MENU*
0143    void VisibleDaughters(Bool_t vis = kTRUE); // *MENU*
0144 
0145    ClassDefOverride(TGeoNode, 2) // base class for all geometry nodes
0146 };
0147 
0148 ////////////////////////////////////////////////////////////////////////////
0149 //                                                                        //
0150 // TGeoNodeMatrix - node containing a general transformation              //
0151 //                                                                        //
0152 ////////////////////////////////////////////////////////////////////////////
0153 
0154 class TGeoNodeMatrix : public TGeoNode {
0155 private:
0156    TGeoMatrix *fMatrix = nullptr; // transf. matrix of fNode in fMother system
0157 
0158    TGeoNodeMatrix(const TGeoNodeMatrix &gnm) = delete;
0159    TGeoNodeMatrix &operator=(const TGeoNodeMatrix &gnm) = delete;
0160 
0161 public:
0162    // constructors
0163    TGeoNodeMatrix();
0164    TGeoNodeMatrix(const TGeoVolume *vol, const TGeoMatrix *matrix);
0165    // destructor
0166    ~TGeoNodeMatrix() override;
0167 
0168    Int_t GetByteCount() const override;
0169    Int_t GetOptimalVoxels() const override;
0170    Bool_t IsFolder() const override { return kTRUE; }
0171    TGeoMatrix *GetMatrix() const override { return fMatrix; }
0172    TGeoNode *MakeCopyNode() const override;
0173    void SetMatrix(const TGeoMatrix *matrix);
0174 
0175    ClassDefOverride(TGeoNodeMatrix, 1) // a geometry node in the general case
0176 };
0177 
0178 ////////////////////////////////////////////////////////////////////////////
0179 //                                                                        //
0180 // TGeoNodeOffset - node containing only an translation offset            //
0181 //                                                                        //
0182 ////////////////////////////////////////////////////////////////////////////
0183 
0184 class TGeoNodeOffset : public TGeoNode {
0185 private:
0186    Double_t fOffset = 0.;                // X offset for this node with respect to its mother
0187    Int_t fIndex = 0;                     // index of this node in the division
0188    TGeoPatternFinder *fFinder = nullptr; // finder for this node
0189 
0190    TGeoNodeOffset(const TGeoNodeOffset &) = delete;
0191    TGeoNodeOffset &operator=(const TGeoNodeOffset &) = delete;
0192 
0193 public:
0194    // constructors
0195    TGeoNodeOffset();
0196    TGeoNodeOffset(const TGeoVolume *vol, Int_t index, Double_t offset);
0197    // destructor
0198    ~TGeoNodeOffset() override;
0199 
0200    void cd() const override { fFinder->cd(fIndex); }
0201    Double_t GetOffset() const { return fOffset; }
0202    Int_t GetIndex() const override;
0203    TGeoPatternFinder *GetFinder() const override { return fFinder; }
0204    TGeoMatrix *GetMatrix() const override
0205    {
0206       cd();
0207       return fFinder->GetMatrix();
0208    }
0209    TGeoNode *MakeCopyNode() const override;
0210    void SetFinder(TGeoPatternFinder *finder) { fFinder = finder; }
0211 
0212    ClassDefOverride(TGeoNodeOffset, 1) // a geometry node with just an offset
0213 };
0214 
0215 ////////////////////////////////////////////////////////////////////////////
0216 //                                                                        //
0217 // TGeoIteratorPlugin - Plugin for a TGeoIterator providing the method    //
0218 //                      ProcessNode each time Next is called.             //
0219 //                                                                        //
0220 ////////////////////////////////////////////////////////////////////////////
0221 
0222 class TGeoIterator;
0223 
0224 class TGeoIteratorPlugin : public TObject {
0225 protected:
0226    const TGeoIterator *fIterator = nullptr; // Caller iterator
0227 private:
0228    // No copy
0229    TGeoIteratorPlugin(const TGeoIteratorPlugin &);
0230    TGeoIteratorPlugin &operator=(const TGeoIteratorPlugin &);
0231 
0232 public:
0233    TGeoIteratorPlugin() : TObject(), fIterator(nullptr) {}
0234    ~TGeoIteratorPlugin() override {}
0235 
0236    virtual void ProcessNode() = 0;
0237    void SetIterator(const TGeoIterator *iter) { fIterator = iter; }
0238 
0239    ClassDefOverride(TGeoIteratorPlugin, 0) // ABC for user plugins connecter to a geometry iterator.
0240 };
0241 
0242 ////////////////////////////////////////////////////////////////////////////
0243 //                                                                        //
0244 // TGeoIterator - iterator for the node tree                              //
0245 //                                                                        //
0246 ////////////////////////////////////////////////////////////////////////////
0247 
0248 class TGeoIterator {
0249 private:
0250    TGeoVolume *fTop = nullptr;            // Top volume of the iterated branch
0251    Bool_t fMustResume = kFALSE;           // Private flag to resume from current node.
0252    Bool_t fMustStop = kFALSE;             // Private flag to signal that the iterator has finished.
0253    Int_t fLevel = 0;                      // Current level in the tree
0254    Int_t fType = 0;                       // Type of iteration
0255    Int_t *fArray = nullptr;               // Array of node indices for the current path
0256    TGeoHMatrix *fMatrix = nullptr;        // Current global matrix
0257    TString fTopName;                      // User name for top
0258    TGeoIteratorPlugin *fPlugin = nullptr; // User iterator plugin
0259    Bool_t fPluginAutoexec = kFALSE;       // Plugin automatically executed during next()
0260 
0261    void IncreaseArray();
0262 
0263 protected:
0264    TGeoIterator()
0265       : fTop(nullptr),
0266         fMustResume(kFALSE),
0267         fMustStop(kFALSE),
0268         fLevel(0),
0269         fType(0),
0270         fArray(nullptr),
0271         fMatrix(nullptr),
0272         fTopName(),
0273         fPlugin(nullptr),
0274         fPluginAutoexec(kFALSE)
0275    {
0276    }
0277 
0278 public:
0279    TGeoIterator(TGeoVolume *top);
0280    TGeoIterator(const TGeoIterator &iter);
0281    virtual ~TGeoIterator();
0282 
0283    TGeoIterator &operator=(const TGeoIterator &iter);
0284    TGeoNode *operator()();
0285    TGeoNode *Next();
0286    void Up()
0287    {
0288       if (fLevel > 0)
0289          fLevel--;
0290    }
0291 
0292    const TGeoMatrix *GetCurrentMatrix() const;
0293    Int_t GetIndex(Int_t i) const { return ((i <= fLevel) ? fArray[i] : -1); }
0294    Int_t GetLevel() const { return fLevel; }
0295    TGeoNode *GetNode(Int_t level) const;
0296    void GetPath(TString &path) const;
0297    TGeoIteratorPlugin *GetUserPlugin() const { return fPlugin; }
0298 
0299    TGeoVolume *GetTopVolume() const { return fTop; }
0300    Int_t GetType() const { return fType; }
0301    void Reset(TGeoVolume *top = nullptr);
0302    void SetUserPlugin(TGeoIteratorPlugin *plugin);
0303    void SetPluginAutoexec(Bool_t mode) { fPluginAutoexec = mode; }
0304    void SetType(Int_t type) { fType = type; }
0305    void SetTopName(const char *name);
0306    void Skip();
0307 
0308    ClassDef(TGeoIterator, 0) // Iterator for geometry.
0309 };
0310 
0311 #endif