Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 // G4ReflectionFactory 27 // 28 // Class description: 29 // 30 // Class providing functions for volumes placements with a general 31 // transfomation that can contain reflection. 32 // Reflection is then applied to a solid: a new G4ReflectedSolid 33 // instance is created and is placed with a transformation containing 34 // pure rotation and translation only. 35 // The pair of constituent and reflected logical volumes is 36 // considered as a generalized logical volume that is addressed 37 // by user specifying the constituent logical volume. 38 // 39 // Decomposition of a general transformation that can include reflection 40 // in a "reflection-free" transformation: 41 // 42 // x(inM') = TG*x(inM) TG - general transformation 43 // = T*(R*x(inM)) T - "reflection-free" transformation 44 // = T* x(inReflM) 45 // 46 // Daughters transformation: 47 // When a volume V containing daughter D with transformation TD 48 // is placed in mother M with a general tranformation TGV, 49 // the TGV is decomposed. New reflected volume ReflV containing 50 // a new daughter ReflD with reflected transformation ReflTD is created: 51 // 52 // x(inV) = TD * x(inD); 53 // x(inM) = TGV * x(inV) 54 // = TV * R * x(inV) 55 // = TV * R * TD * x(inD) 56 // = TV * R*TD*R-1 * R*x(inD) 57 // = TV * ReflTD * x(inReflD) 58 59 // Author: Ivana Hrivnacova (Ivana.Hrivnacova@cern.ch), 16.10.2001 60 // -------------------------------------------------------------------- 61 #ifndef G4_REFLECTION_FACTORY_HH 62 #define G4_REFLECTION_FACTORY_HH 63 64 #include "G4Types.hh" 65 #include "G4Transform3D.hh" 66 #include "geomdefs.hh" 67 68 #include <map> 69 70 class G4VPhysicalVolume; 71 class G4LogicalVolume; 72 class G4VSolid; 73 class G4VPVDivisionFactory; 74 75 using G4PhysicalVolumesPair = std::pair<G4VPhysicalVolume*, G4VPhysicalVolume*>; 76 using G4ReflectedVolumesMap = std::map<G4LogicalVolume*, G4LogicalVolume*, 77 std::less<G4LogicalVolume*> >; 78 class G4ReflectionFactory 79 { 80 using LogicalVolumesMapIterator = G4ReflectedVolumesMap::const_iterator; 81 82 public: 83 84 virtual ~G4ReflectionFactory(); 85 // Virtual destructor. 86 87 static G4ReflectionFactory* Instance(); 88 // Gets pointer to the instance of the singleton. 89 90 G4PhysicalVolumesPair Place(const G4Transform3D& transform3D, 91 const G4String& name, 92 G4LogicalVolume* LV, 93 G4LogicalVolume* motherLV, 94 G4bool isMany, 95 G4int copyNo, 96 G4bool surfCheck = false); 97 // Evaluates the passed transformation; if it contains reflection 98 // it performs its decomposition, creates new reflected solid and 99 // logical volume (or retrieves them from a map if the reflected 100 // objects were already created), transforms the daughters (if present) 101 // and place it in the given mother. 102 // The result is a pair of physical volumes; 103 // the second physical volume is a placement in a reflected mother 104 // or 0 if mother LV was not reflected. 105 106 G4PhysicalVolumesPair Replicate(const G4String& name, 107 G4LogicalVolume* LV, 108 G4LogicalVolume* motherLV, 109 EAxis axis, 110 G4int nofReplicas, 111 G4double width, 112 G4double offset = 0.); 113 // Creates replica in the given mother. 114 // The result is a pair of physical volumes; 115 // the second physical volume is a replica in a reflected mother 116 // or 0 if mother LV was not reflected. 117 118 G4PhysicalVolumesPair Divide(const G4String& name, 119 G4LogicalVolume* LV, 120 G4LogicalVolume* motherLV, 121 EAxis axis, 122 G4int nofDivisions, 123 G4double width, 124 G4double offset); 125 G4PhysicalVolumesPair Divide(const G4String& name, 126 G4LogicalVolume* LV, 127 G4LogicalVolume* motherLV, 128 EAxis axis, 129 G4int nofDivisions, 130 G4double offset); 131 G4PhysicalVolumesPair Divide(const G4String& name, 132 G4LogicalVolume* LV, 133 G4LogicalVolume* motherLV, 134 EAxis axis, 135 G4double width, 136 G4double offset); 137 // Creates division in the given mother. 138 // The result is a pair of physical volumes; 139 // the second physical volume is a division in a reflected mother 140 // or nullptr if mother LV was not reflected. 141 142 void SetVerboseLevel(G4int verboseLevel); 143 G4int GetVerboseLevel() const; 144 // Sets/gets verbosity level. 145 146 void SetVolumesNameExtension(const G4String& nameExtension); 147 const G4String& GetVolumesNameExtension() const; 148 // Returns the name extension for the reflected solids 149 // and logical volumes. 150 151 void SetScalePrecision(G4double scaleValue); 152 G4double GetScalePrecision() const; 153 // Sets/gets precision factor for the scale consistency check 154 // The default value is set to 10*kCarTolerance. 155 156 G4LogicalVolume* GetConstituentLV(G4LogicalVolume* reflLV) const; 157 // Returns the consituent volume of the given reflected volume, 158 // nullptr if the given reflected volume was not found. 159 160 G4LogicalVolume* GetReflectedLV(G4LogicalVolume* lv) const; 161 // Returns the reflected volume of the given consituent volume, 162 // nullptr if the given volume was not reflected. 163 164 G4bool IsConstituent(G4LogicalVolume* lv) const; 165 // Returns true if the given volume has been already reflected 166 // (is in the map of constituent volumes). 167 168 G4bool IsReflected(G4LogicalVolume* lv) const; 169 // Returns true if the given volume is a reflected volume 170 // (is in the map reflected volumes). 171 172 const G4ReflectedVolumesMap& GetReflectedVolumesMap() const; 173 // Returns a handle to the internal map of volumes which have 174 // been reflected, after that placement or replication is performed. 175 176 void Clean(); 177 // Clear maps of constituent and reflected volumes. 178 // To be used exclusively when volumes are removed from the stores. 179 180 G4ReflectionFactory(const G4ReflectionFactory&) = delete; 181 G4ReflectionFactory& operator=(const G4ReflectionFactory&) = delete; 182 // Disabled copy constructor and assignment operator. 183 184 protected: 185 186 G4ReflectionFactory(); 187 // Protected singleton constructor. 188 189 private: 190 191 G4LogicalVolume* ReflectLV(G4LogicalVolume* LV, G4bool surfCheck = false); 192 // Gets/creates the reflected solid and logical volume 193 // and copies + transforms LV daughters. 194 195 G4LogicalVolume* CreateReflectedLV(G4LogicalVolume* LV); 196 // Creates the reflected solid and logical volume 197 // and add the logical volumes pair in the maps. 198 199 void ReflectDaughters(G4LogicalVolume* LV, 200 G4LogicalVolume* refLV, G4bool surfCheck = false); 201 // Reflects daughters recursively. 202 203 void ReflectPVPlacement(G4VPhysicalVolume* PV, 204 G4LogicalVolume* refLV, G4bool surfCheck = false); 205 // Copies and transforms daughter of PVPlacement type of 206 // a constituent volume into a reflected volume. 207 208 void ReflectPVReplica(G4VPhysicalVolume* PV, G4LogicalVolume* refLV); 209 // Copies and transforms daughter of PVReplica type of 210 // a constituent volume into a reflected volume. 211 212 void ReflectPVDivision(G4VPhysicalVolume* PV, G4LogicalVolume* refLV); 213 // Copies and transforms daughter of PVDivision type of 214 // a constituent volume into a reflected volume. 215 216 void ReflectPVParameterised(G4VPhysicalVolume* PV, 217 G4LogicalVolume* refLV, G4bool surfChk = false); 218 // Not implemented yet. 219 // Should copy and transform daughter of PVReplica type of 220 // a constituent volume into a reflected volume. 221 222 G4bool IsReflection(const G4Scale3D& scale) const; 223 // Returns true if the scale is negative, false otherwise. 224 225 void CheckScale(const G4Scale3D& scale) const; 226 // Checks if scale correspond to fScale, if not gives exception. 227 228 G4VPVDivisionFactory* GetPVDivisionFactory() const; 229 // Checks if the division factory is instanciated, 230 // if not gives exception. 231 232 void PrintConstituentLVMap(); 233 // Temporary - for debugging purpose. 234 235 private: 236 237 static G4ThreadLocal G4ReflectionFactory* fInstance; 238 static const G4String fDefaultNameExtension; 239 static const G4Scale3D fScale; 240 G4double fScalePrecision; 241 242 G4int fVerboseLevel = 0; 243 G4String fNameExtension; 244 G4ReflectedVolumesMap fConstituentLVMap; 245 G4ReflectedVolumesMap fReflectedLVMap; 246 }; 247 248 #endif 249