Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** >> 25 // >> 26 // >> 27 // 25 // 28 // 26 // class G4PVParameterised implementation << 29 // class G4PVParameterised >> 30 // >> 31 // Implementation 27 // 32 // 28 // 29.07.95, P.Kent - first non-stub version << 29 // ------------------------------------------- 33 // ---------------------------------------------------------------------- 30 34 31 #include "G4PVParameterised.hh" 35 #include "G4PVParameterised.hh" 32 #include "G4VPVParameterisation.hh" 36 #include "G4VPVParameterisation.hh" 33 #include "G4AffineTransform.hh" 37 #include "G4AffineTransform.hh" 34 #include "G4UnitsTable.hh" 38 #include "G4UnitsTable.hh" 35 #include "G4VSolid.hh" 39 #include "G4VSolid.hh" 36 #include "G4LogicalVolume.hh" 40 #include "G4LogicalVolume.hh" 37 41 38 // ------------------------------------------- 42 // ---------------------------------------------------------------------- 39 // Constructor 43 // Constructor 40 // 44 // 41 G4PVParameterised::G4PVParameterised( const G4 45 G4PVParameterised::G4PVParameterised( const G4String& pName, 42 G4 46 G4LogicalVolume* pLogical, 43 G4 << 47 G4VPhysicalVolume* pMother, 44 const EA 48 const EAxis pAxis, 45 const G4 49 const G4int nReplicas, 46 G4 << 50 G4VPVParameterisation *pParam, 47 G4 51 G4bool pSurfChk ) 48 : G4PVReplica(pName, nReplicas, pAxis, pLogica << 52 : G4PVReplica(pName, pLogical, pMother, pAxis, nReplicas, 0, 0), 49 pMotherPhysical != nullptr ? pMo << 50 fparam(pParam) 53 fparam(pParam) 51 { 54 { 52 G4LogicalVolume* motherLogical= pMotherPhysi << 53 pMotherPhysical->GetLogicalVolume() : nu << 54 << 55 SetMotherLogical( motherLogical ); << 56 if( motherLogical != nullptr ) << 57 { << 58 // Registration moved here to ensure that << 59 motherLogical->AddDaughter(this); << 60 } << 61 << 62 #ifdef G4VERBOSE 55 #ifdef G4VERBOSE 63 if ((pMotherPhysical != nullptr) && (pMother << 56 if ((pMother) && (pMother->IsParameterised())) 64 { 57 { 65 std::ostringstream message, hint; 58 std::ostringstream message, hint; 66 message << "A parameterised volume is bein 59 message << "A parameterised volume is being placed" << G4endl 67 << "inside another parameterised v 60 << "inside another parameterised volume !"; 68 hint << "To make sure that no overlaps are 61 hint << "To make sure that no overlaps are generated," << G4endl 69 << "you should verify the mother repl 62 << "you should verify the mother replicated shapes" << G4endl 70 << "are of the same type and dimensio 63 << "are of the same type and dimensions." << G4endl 71 << " Mother physical volume: " << p << 64 << " Mother physical volume: " << pMother->GetName() << G4endl 72 << " Parameterised volume: " << pNa 65 << " Parameterised volume: " << pName << G4endl 73 << " (To switch this warning off, co 66 << " (To switch this warning off, compile with G4_NO_VERBOSE)"; 74 G4Exception("G4PVParameterised::G4PVParame 67 G4Exception("G4PVParameterised::G4PVParameterised()", "GeomVol1002", 75 JustWarning, message, G4String 68 JustWarning, message, G4String(hint.str())); 76 } 69 } 77 #endif 70 #endif 78 if (pSurfChk) { CheckOverlaps(); } 71 if (pSurfChk) { CheckOverlaps(); } 79 } 72 } 80 73 81 // ------------------------------------------- 74 // ---------------------------------------------------------------------- 82 // Constructor 75 // Constructor 83 // 76 // 84 G4PVParameterised::G4PVParameterised( const G4 77 G4PVParameterised::G4PVParameterised( const G4String& pName, 85 G4 78 G4LogicalVolume* pLogical, 86 G4 79 G4LogicalVolume* pMotherLogical, 87 const EA 80 const EAxis pAxis, 88 const G4 81 const G4int nReplicas, 89 G4 << 82 G4VPVParameterisation *pParam, 90 G4 83 G4bool pSurfChk ) 91 : G4PVReplica(pName, nReplicas, pAxis, pLogi << 84 : G4PVReplica(pName, pLogical, pMotherLogical, pAxis, nReplicas, 0, 0), 92 fparam(pParam) 85 fparam(pParam) 93 { 86 { 94 SetMotherLogical( pMotherLogical ); << 95 if( pMotherLogical != nullptr ) << 96 { << 97 // Registration moved here to ensure that << 98 pMotherLogical->AddDaughter(this); << 99 } << 100 if (pSurfChk) { CheckOverlaps(); } 87 if (pSurfChk) { CheckOverlaps(); } 101 } 88 } 102 89 103 // ------------------------------------------- 90 // ---------------------------------------------------------------------- 104 // Fake default constructor - sets only member 91 // Fake default constructor - sets only member data and allocates memory 105 // for usage restri 92 // for usage restricted to object persistency. 106 // 93 // 107 G4PVParameterised::G4PVParameterised( __void__ 94 G4PVParameterised::G4PVParameterised( __void__& a ) 108 : G4PVReplica(a) << 95 : G4PVReplica(a), fparam(0) 109 { 96 { 110 } 97 } 111 98 112 // ------------------------------------------- 99 // ---------------------------------------------------------------------- 113 // Destructor 100 // Destructor 114 // 101 // 115 G4PVParameterised::~G4PVParameterised() = defa << 102 G4PVParameterised::~G4PVParameterised() >> 103 { >> 104 } 116 105 117 // ------------------------------------------- 106 // ---------------------------------------------------------------------- 118 // GetParameterisation 107 // GetParameterisation 119 // 108 // 120 G4VPVParameterisation* G4PVParameterised::GetP 109 G4VPVParameterisation* G4PVParameterised::GetParameterisation() const 121 { 110 { 122 return fparam; 111 return fparam; 123 } 112 } 124 113 125 // ------------------------------------------- 114 // ---------------------------------------------------------------------- 126 // IsParameterised 115 // IsParameterised 127 // 116 // 128 G4bool G4PVParameterised::IsParameterised() co 117 G4bool G4PVParameterised::IsParameterised() const 129 { 118 { 130 return true; 119 return true; 131 } 120 } 132 121 133 // ------------------------------------------- 122 // ---------------------------------------------------------------------- 134 // VolumeType << 135 // << 136 EVolume G4PVParameterised::VolumeType() const << 137 { << 138 return kParameterised; << 139 } << 140 << 141 // ------------------------------------------- << 142 // GetReplicationData 123 // GetReplicationData 143 // 124 // 144 void G4PVParameterised::GetReplicationData( EA 125 void G4PVParameterised::GetReplicationData( EAxis& axis, 145 G4 126 G4int& nReplicas, 146 G4 127 G4double& width, 147 G4 128 G4double& offset, 148 G4 129 G4bool& consuming) const 149 { 130 { 150 axis = faxis; 131 axis = faxis; 151 nReplicas = fnReplicas; 132 nReplicas = fnReplicas; 152 width = fwidth; 133 width = fwidth; 153 offset = foffset; 134 offset = foffset; 154 consuming = false; 135 consuming = false; 155 } 136 } 156 137 157 // ------------------------------------------- 138 // ---------------------------------------------------------------------- 158 // SetRegularStructureId 139 // SetRegularStructureId 159 // 140 // 160 void G4PVParameterised::SetRegularStructureId << 141 void G4PVParameterised::SetRegularStructureId( G4int Code ) 161 { 142 { 162 G4PVReplica::SetRegularStructureId( code ); << 143 G4PVReplica::SetRegularStructureId( Code ); 163 // To undertake additional preparation, a de 144 // To undertake additional preparation, a derived volume must 164 // redefine this method, while calling also << 145 // redefine this method, while calling also the above method. 165 } 146 } 166 147 167 148 168 // ------------------------------------------- 149 // ---------------------------------------------------------------------- 169 // CheckOverlaps 150 // CheckOverlaps 170 // 151 // 171 G4bool 152 G4bool 172 G4PVParameterised::CheckOverlaps(G4int res, G4 153 G4PVParameterised::CheckOverlaps(G4int res, G4double tol, 173 G4bool verbos 154 G4bool verbose, G4int maxErr) 174 { 155 { 175 if (res<=0) { return false; } 156 if (res<=0) { return false; } 176 157 177 G4int trials = 0; 158 G4int trials = 0; 178 G4bool retval = false; 159 G4bool retval = false; 179 G4VSolid *solidA = nullptr, *solidB = nullpt << 160 G4VSolid *solidA = 0, *solidB = 0; 180 G4LogicalVolume* motherLog = GetMotherLogica << 161 G4LogicalVolume *motherLog = GetMotherLogical(); 181 G4VSolid *motherSolid = motherLog->GetSolid( 162 G4VSolid *motherSolid = motherLog->GetSolid(); 182 std::vector<G4ThreeVector> points; 163 std::vector<G4ThreeVector> points; 183 164 184 if (verbose) 165 if (verbose) 185 { 166 { 186 G4cout << "Checking overlaps for parameter 167 G4cout << "Checking overlaps for parameterised volume " 187 << GetName() << " ... "; 168 << GetName() << " ... "; 188 } 169 } 189 170 190 for (auto i=0; i<GetMultiplicity(); ++i) << 171 for (G4int i=0; i<GetMultiplicity(); i++) 191 { 172 { 192 solidA = fparam->ComputeSolid(i, this); 173 solidA = fparam->ComputeSolid(i, this); 193 solidA->ComputeDimensions(fparam, i, this) 174 solidA->ComputeDimensions(fparam, i, this); 194 fparam->ComputeTransformation(i, this); 175 fparam->ComputeTransformation(i, this); 195 176 196 // Create the transformation from daughter 177 // Create the transformation from daughter to mother 197 // 178 // 198 G4AffineTransform Tm( GetRotation(), GetTr 179 G4AffineTransform Tm( GetRotation(), GetTranslation() ); 199 180 200 // Generate random points on surface accor 181 // Generate random points on surface according to the given resolution, 201 // transform them to the mother's coordina 182 // transform them to the mother's coordinate system and if no overlaps 202 // with the mother volume, cache them in a 183 // with the mother volume, cache them in a vector for later use with 203 // the daughters 184 // the daughters 204 // 185 // 205 for (auto n=0; n<res; ++n) << 186 for (G4int n=0; n<res; n++) 206 { 187 { 207 G4ThreeVector mp = Tm.TransformPoint(sol 188 G4ThreeVector mp = Tm.TransformPoint(solidA->GetPointOnSurface()); 208 189 209 // Checking overlaps with the mother vol 190 // Checking overlaps with the mother volume 210 // 191 // 211 if (motherSolid->Inside(mp)==kOutside) 192 if (motherSolid->Inside(mp)==kOutside) 212 { 193 { 213 G4double distin = motherSolid->Distanc 194 G4double distin = motherSolid->DistanceToIn(mp); 214 if (distin > tol) 195 if (distin > tol) 215 { 196 { 216 ++trials; retval = true; << 197 trials++; retval = true; 217 std::ostringstream message; 198 std::ostringstream message; 218 message << "Overlap with mother volu 199 message << "Overlap with mother volume !" << G4endl 219 << " Overlap is dete 200 << " Overlap is detected for volume " 220 << GetName() << ", parameter 201 << GetName() << ", parameterised instance: " << i << G4endl 221 << " with its mothe 202 << " with its mother volume " 222 << motherLog->GetName() << G 203 << motherLog->GetName() << G4endl 223 << " at mother loca 204 << " at mother local point " << mp << ", " 224 << "overlapping by at least: 205 << "overlapping by at least: " 225 << G4BestUnit(distin, "Lengt 206 << G4BestUnit(distin, "Length"); 226 if (trials>=maxErr) 207 if (trials>=maxErr) 227 { 208 { 228 message << G4endl 209 message << G4endl 229 << "NOTE: Reached maximum 210 << "NOTE: Reached maximum fixed number -" << maxErr 230 << "- of overlaps reports 211 << "- of overlaps reports for this volume !"; 231 } 212 } 232 G4Exception("G4PVParameterised::Chec 213 G4Exception("G4PVParameterised::CheckOverlaps()", 233 "GeomVol1002", JustWarni 214 "GeomVol1002", JustWarning, message); 234 if (trials>=maxErr) { return true; 215 if (trials>=maxErr) { return true; } 235 } 216 } 236 } 217 } 237 points.push_back(mp); 218 points.push_back(mp); 238 } 219 } 239 220 240 // Checking overlaps with each other param 221 // Checking overlaps with each other parameterised instance 241 // 222 // 242 for (auto j=i+1; j<GetMultiplicity(); ++j) << 223 std::vector<G4ThreeVector>::iterator pos; >> 224 for (G4int j=i+1; j<GetMultiplicity(); j++) 243 { 225 { 244 solidB = fparam->ComputeSolid(j,this); 226 solidB = fparam->ComputeSolid(j,this); 245 solidB->ComputeDimensions(fparam, j, thi 227 solidB->ComputeDimensions(fparam, j, this); 246 fparam->ComputeTransformation(j, this); 228 fparam->ComputeTransformation(j, this); 247 229 248 // Create the transformation for daughte 230 // Create the transformation for daughter volume 249 // 231 // 250 G4AffineTransform Td( GetRotation(), Get 232 G4AffineTransform Td( GetRotation(), GetTranslation() ); 251 233 252 for (const auto & point : points) << 234 for (pos=points.begin(); pos!=points.end(); pos++) 253 { 235 { 254 // Transform each point according to d 236 // Transform each point according to daughter's frame 255 // 237 // 256 G4ThreeVector md = Td.InverseTransform << 238 G4ThreeVector md = Td.InverseTransformPoint(*pos); 257 239 258 if (solidB->Inside(md)==kInside) 240 if (solidB->Inside(md)==kInside) 259 { 241 { 260 G4double distout = solidB->DistanceT 242 G4double distout = solidB->DistanceToOut(md); 261 if (distout > tol) 243 if (distout > tol) 262 { 244 { 263 ++trials; retval = true; << 245 trials++; retval = true; 264 std::ostringstream message; 246 std::ostringstream message; 265 message << "Overlap within paramet 247 message << "Overlap within parameterised volumes !" << G4endl 266 << " Overlap is d 248 << " Overlap is detected for volume " 267 << GetName() << ", paramet 249 << GetName() << ", parameterised instance: " << i << G4endl 268 << " with paramet 250 << " with parameterised volume instance: " << j 269 << G4endl 251 << G4endl 270 << " at local poi 252 << " at local point " << md << ", " 271 << "overlapping by at leas 253 << "overlapping by at least: " 272 << G4BestUnit(distout, "Le 254 << G4BestUnit(distout, "Length") 273 << ", related to volume in 255 << ", related to volume instance: " << j << "."; 274 if (trials>=maxErr) 256 if (trials>=maxErr) 275 { 257 { 276 message << G4endl 258 message << G4endl 277 << "NOTE: Reached maximu 259 << "NOTE: Reached maximum fixed number -" << maxErr 278 << "- of overlaps report 260 << "- of overlaps reports for this volume !"; 279 } 261 } 280 G4Exception("G4PVParameterised::Ch 262 G4Exception("G4PVParameterised::CheckOverlaps()", 281 "GeomVol1002", JustWar 263 "GeomVol1002", JustWarning, message); 282 if (trials>=maxErr) { return true 264 if (trials>=maxErr) { return true; } 283 } 265 } 284 } 266 } 285 } 267 } 286 } 268 } 287 } 269 } 288 if (verbose) 270 if (verbose) 289 { 271 { 290 G4cout << "OK! " << G4endl; 272 G4cout << "OK! " << G4endl; 291 } 273 } 292 274 293 return retval; 275 return retval; 294 } 276 } 295 277