Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:33:59

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4AssemblyVolume
0027 //
0028 // Class description:
0029 //
0030 // G4AssemblyVolume is a helper class to make the build process of geometry
0031 // easier. It allows one to combine several volumes together in an arbitrary way
0032 // in 3D space and then work with the result as with a single logical volume
0033 // for placement.
0034 // The resulting objects are independent copies of each of the assembled
0035 // logical volumes. The placements are not, however, bound one to each other
0036 // when placement is done. They are seen as independent physical volumes in
0037 // space.
0038 
0039 // Authors: R.Chytracek, J.Apostolakis, G.Cosmo (CERN), November 2000
0040 // ----------------------------------------------------------------------
0041 #ifndef G4_ASSEMBLYVOLUME_HH
0042 #define G4_ASSEMBLYVOLUME_HH 1
0043 
0044 #include <vector>
0045 
0046 #include "G4Transform3D.hh"
0047 #include "G4AssemblyTriplet.hh"
0048 
0049 class G4VPhysicalVolume;
0050 
0051 /**
0052  * @brief G4AssemblyVolume is a helper class to make the build process of
0053  * geometry easier. It allows one to combine several volumes together in an
0054  * arbitrary way in 3D space and then work with the result as with a single
0055  * logical volume for placement.
0056  * The resulting objects are independent copies of each of the assembled
0057  * logical volumes. The placements are not, however, bound one to each other
0058  * when placement is done. They are seen as independent physical volumes in
0059  * space.
0060  */
0061 
0062 class G4AssemblyVolume
0063 {
0064   public:
0065 
0066     /**
0067      * Default Constructor.
0068      */
0069     G4AssemblyVolume();    
0070 
0071     /**
0072      * Constructor.
0073      * The rotation matrix passed as argument can be nullptr (identity) or an
0074      * address even of an object on the upper stack frame. During assembly
0075      * imprint, a new matrix is created anyway and it is kept track of it so
0076      * it can be automatically deleted later at the end of the application.
0077      * This policy is adopted since user has no control on the way the
0078      * rotations are combined.
0079      *  @param[in] volume Pointer to the logical volume of the assembly.
0080      *  @param[in] translation Translation vector of the assembly.
0081      *  @param[in] rotation Pointer to the rotation matrix of the assembly.
0082      */
0083     G4AssemblyVolume( G4LogicalVolume* volume,
0084                       G4ThreeVector& translation,
0085                       G4RotationMatrix* rotation);
0086     
0087     /**
0088      * Destructor.
0089      * At destruction all the generated physical volumes and associated
0090      * rotation matrices of the imprints will be destroyed.
0091      */
0092     ~G4AssemblyVolume();
0093 
0094     /**
0095      * Places the given volume 'pPlacedVolume' inside the assembly.
0096      *
0097      * The adopted approach:
0098      *
0099      * - Place it w.r.t. the assembly coordinate system.
0100      *   This step is applied to each of the participating volumes.
0101      *
0102      * The other possible approaches:
0103      *
0104      * - Place w.r.t. the firstly added volume.
0105      *   When placed the first, the virtual coordinate system becomes
0106      *   the coordinate system of the first one.
0107      *   Every next volume being added into the assembly will be placed
0108      *   w.r.t to the first one.
0109      *
0110      * - Place w.r.t the last placed volume.
0111      *   When placed the first, the virtual coordinate system becomes
0112      *   the coordinate system of the first one.
0113      *   Every next volume being added into the assembly will be placed
0114      *   w.r.t to the previous one.
0115      *
0116      * The rotation matrix passed as argument can be nullptr (identity) or an
0117      * address even of an object on the upper stack frame. During assembly
0118      * imprint, a new matrix is created anyway and it is kept track of it so
0119      * it can be automatically deleted later at the end of the application.
0120      * This policy is adopted since user has no control on the way the
0121      * rotations are combined.
0122      *  @param[in] pPlacedVolume Pointer to the logical volume of the volume
0123      *             to be added to the assembly.
0124      *  @param[in] translation Translation vector of the volume.
0125      *  @param[in] rotation Pointer to the rotation matrix of the volume.
0126      */
0127     void AddPlacedVolume( G4LogicalVolume* pPlacedVolume,
0128                           G4ThreeVector& translation,
0129                           G4RotationMatrix* rotation);
0130 
0131     /**
0132      * The same as previous method, except that it takes the complete 3D
0133      * transformation in space as its argument.
0134      *  @param[in] pPlacedVolume Pointer to the logical volume of the volume
0135      *             to be added to the assembly.
0136      *  @param[in] transformation The 3D transformation in space.
0137      */
0138     void AddPlacedVolume( G4LogicalVolume* pPlacedVolume,
0139                           G4Transform3D&   transformation);
0140 
0141     /**
0142      * The same as previous method, but takes an assembly volume as argument.
0143      *  @param[in] pAssembly Pointer to the assembly volume to be added
0144      *             to the assembly.
0145      *  @param[in] transformation The 3D transformation in space.
0146      */
0147     void AddPlacedAssembly( G4AssemblyVolume* pAssembly,
0148                             G4Transform3D&    transformation);
0149 
0150     /**
0151      * The same as previous method, but takes an assembly volume 
0152      * as its argument with translation and rotation.
0153      *  @param[in] pAssembly Pointer to the assembly volume to be added
0154      *             to the assembly.
0155      *  @param[in] translation Translation vector of the volume.
0156      *  @param[in] rotation Pointer to the rotation matrix of the volume.
0157      */
0158     void AddPlacedAssembly( G4AssemblyVolume* pAssembly,
0159                             G4ThreeVector& translation,
0160                             G4RotationMatrix* rotation);
0161 
0162     /**
0163      * Creates instance of an assembly volume inside the given mother volume.
0164      *  @param[in] pMotherLV Pointer to the logical volume of the assembly.
0165      *  @param[in] translationInMother Translation vector of the imprint.
0166      *  @param[in] pRotationInMother Pointer to the rotation of the imprint.
0167      *  @param[in] copyNumBase Optional index to assign to the imprint.
0168      *  @param[in] surfCheck Flag to enable overlaps checking while imprinting.
0169      */
0170     void MakeImprint( G4LogicalVolume* pMotherLV,
0171                       G4ThreeVector& translationInMother,
0172                       G4RotationMatrix* pRotationInMother,
0173                       G4int copyNumBase = 0,
0174                       G4bool surfCheck = false );
0175 
0176     /**
0177      * The same as previous Imprint() method, but takes a complete 3D
0178      * transformation in space as its argument.
0179      *  @param[in] pMotherLV Pointer to the logical volume of the assembly.
0180      *  @param[in] transformation The 3D transformation in space of the imprint.
0181      *  @param[in] copyNumBase Optional index to assign to the imprint.
0182      *  @param[in] surfCheck Flag to enable overlaps checking while imprinting.
0183      */
0184     void MakeImprint( G4LogicalVolume* pMotherLV,
0185                       G4Transform3D&   transformation,
0186                       G4int copyNumBase = 0,
0187                       G4bool surfCheck = false );
0188 
0189     /**
0190      * To access the physical volumes imprinted through an iterator.
0191      */
0192     inline std::vector<G4VPhysicalVolume*>::iterator GetVolumesIterator();
0193 
0194     /**
0195      * Returns the total number of imprinted volumes of the assembly.
0196      */
0197     inline std::size_t TotalImprintedVolumes() const;
0198 
0199     /**
0200      * To access the 3D transformation in space for each imprint, given the ID.
0201      */
0202     inline G4Transform3D& GetImprintTransformation(unsigned int imprintID);
0203 
0204     /**
0205      * To access the created triplets in the assembly through an iterator.
0206      */
0207     inline std::vector<G4AssemblyTriplet>::iterator GetTripletsIterator();
0208 
0209     /**
0210      * Returns the total number of triplets in the assembly.
0211      */
0212     inline std::size_t TotalTriplets() const;
0213   
0214     /**
0215      * Returns the number of currently made imprints.
0216      */
0217     inline unsigned int GetImprintsCount() const;
0218 
0219     /**
0220      * Returns the number of existing instances of G4AssemblyVolume class.
0221      */
0222     unsigned int GetInstanceCount() const;
0223 
0224     /**
0225      * Returns the instance number of the assembly.
0226      */
0227     inline unsigned int GetAssemblyID()    const;
0228   
0229   protected:
0230 
0231     inline void SetInstanceCount( unsigned int value );
0232     inline void SetAssemblyID( unsigned int value );
0233  
0234     void InstanceCountPlus();
0235     void InstanceCountMinus();
0236 
0237     // Internal counting mechanism, used to compute unique the names of
0238     // physical volumes created by MakeImprint() methods.
0239     //
0240     inline void SetImprintsCount( unsigned int value );
0241     inline void ImprintsCountPlus();
0242     inline void ImprintsCountMinus();
0243 
0244   private:    
0245 
0246     /**
0247      * Function for placement of the given assembly in the given mother
0248      * (called recursively if the assembly contains an assembly).
0249      */
0250     void MakeImprint( G4AssemblyVolume* pAssembly,
0251                       G4LogicalVolume*  pMotherLV,
0252                       G4Transform3D&    transformation,
0253                       G4int copyNumBase = 0,
0254                       G4bool surfCheck = false );
0255 
0256   private:
0257 
0258     /** Participating volumes represented as a vector of
0259      *  <logical volume, translation, rotation>. */
0260     std::vector<G4AssemblyTriplet> fTriplets;
0261 
0262     /** We need to keep list of physical volumes created by MakeImprint()
0263      * in order to be able to cleanup the objects when not needed anymore.
0264      * This requires the user to keep assembly objects in memory during the
0265      * whole job or during the life-time of G4Navigator, logical volume store
0266      * and physical volume store keep pointers to physical volumes generated
0267      * by the assembly volume.
0268      * When an assembly object is about to die it will destroy all its
0269      * generated physical volumes and rotation matrices as well ! */
0270     std::vector<G4VPhysicalVolume*> fPVStore;
0271 
0272     /** Number of imprints of the given assembly volume. */
0273     unsigned int fImprintsCounter;
0274 
0275     /** Class instance counter. */
0276     static G4ThreadLocal unsigned int fsInstanceCounter;
0277 
0278     /** Assembly object ID derived from instance counter at construction time. */
0279     unsigned int fAssemblyID = 0;
0280 
0281     /** Container of transformations for each imprint (used in GDML). */
0282     std::map<unsigned int, G4Transform3D> fImprintsTransf;
0283 };
0284 
0285 #include "G4AssemblyVolume.icc"
0286 
0287 #endif