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