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 // 25 // 26 // G4ScoringProbe << 26 // 27 // ------------------------------------------- << 28 << 29 #include "G4ScoringProbe.hh" 27 #include "G4ScoringProbe.hh" 30 28 31 #include "G4Box.hh" 29 #include "G4Box.hh" 32 #include "G4LogicalVolume.hh" 30 #include "G4LogicalVolume.hh" 33 #include "G4LogicalVolumeStore.hh" 31 #include "G4LogicalVolumeStore.hh" 34 #include "G4VPhysicalVolume.hh" 32 #include "G4VPhysicalVolume.hh" 35 #include "G4PVPlacement.hh" 33 #include "G4PVPlacement.hh" 36 #include "G4Region.hh" 34 #include "G4Region.hh" 37 #include "G4RegionStore.hh" 35 #include "G4RegionStore.hh" 38 #include "G4Threading.hh" 36 #include "G4Threading.hh" 39 #include "G4Material.hh" 37 #include "G4Material.hh" 40 #include "G4NistManager.hh" 38 #include "G4NistManager.hh" 41 39 42 #include "G4MultiFunctionalDetector.hh" 40 #include "G4MultiFunctionalDetector.hh" 43 #include "G4VPrimitiveScorer.hh" 41 #include "G4VPrimitiveScorer.hh" 44 42 45 #include "G4ScoringManager.hh" 43 #include "G4ScoringManager.hh" 46 #include "G4StatDouble.hh" 44 #include "G4StatDouble.hh" 47 45 48 #include "G4SystemOfUnits.hh" 46 #include "G4SystemOfUnits.hh" 49 #include "G4VisAttributes.hh" 47 #include "G4VisAttributes.hh" 50 48 51 #include "G4AutoLock.hh" << 49 G4ScoringProbe::G4ScoringProbe(G4String lvName, G4double half_size, 52 << 53 namespace << 54 { << 55 G4Mutex logvolmutex = G4MUTEX_INITIALIZER; << 56 } << 57 << 58 G4ScoringProbe::G4ScoringProbe(const G4String& << 59 G4bool checkOve 50 G4bool checkOverlap) 60 : G4VScoringMesh(lvName) 51 : G4VScoringMesh(lvName) 61 , chkOverlap(checkOverlap) 52 , chkOverlap(checkOverlap) 62 , layeredMaterialName("none") 53 , layeredMaterialName("none") 63 , layeredMaterial(nullptr) 54 , layeredMaterial(nullptr) 64 { 55 { 65 fShape = MeshShape::probe; 56 fShape = MeshShape::probe; 66 logVolName = lvName; 57 logVolName = lvName; 67 probeSize = half_size; 58 probeSize = half_size; 68 G4double hs[] = { half_size, half_size, half 59 G4double hs[] = { half_size, half_size, half_size }; 69 SetSize(hs); 60 SetSize(hs); 70 G4int nBin[] = { 1, 1, 1 }; 61 G4int nBin[] = { 1, 1, 1 }; 71 SetNumberOfSegments(nBin); 62 SetNumberOfSegments(nBin); 72 regName = lvName + "_region"; 63 regName = lvName + "_region"; 73 if(G4Threading::IsMasterThread()) 64 if(G4Threading::IsMasterThread()) 74 { 65 { 75 new G4Region(regName); 66 new G4Region(regName); 76 } 67 } 77 } 68 } 78 69 79 void G4ScoringProbe::List() const 70 void G4ScoringProbe::List() const 80 { 71 { 81 G4cout << "G4ScoringProbe : " << logVolName 72 G4cout << "G4ScoringProbe : " << logVolName << G4endl; 82 std::size_t np = posVec.size(); 73 std::size_t np = posVec.size(); 83 for(std::size_t i = 0; i < np; ++i) 74 for(std::size_t i = 0; i < np; ++i) 84 { 75 { 85 G4cout << " >> probe #" << i << " at " << 76 G4cout << " >> probe #" << i << " at " << posVec[i] << G4endl; 86 } 77 } 87 G4VScoringMesh::List(); 78 G4VScoringMesh::List(); 88 } 79 } 89 80 >> 81 #include "G4AutoLock.hh" >> 82 namespace >> 83 { >> 84 G4Mutex logvolmutex = G4MUTEX_INITIALIZER; >> 85 } >> 86 90 void G4ScoringProbe::SetupGeometry(G4VPhysical 87 void G4ScoringProbe::SetupGeometry(G4VPhysicalVolume* worldPhys) 91 { 88 { 92 if(G4Threading::IsMasterThread()) 89 if(G4Threading::IsMasterThread()) 93 { 90 { 94 auto worldLog = worldPhys->GetLogicalVolum 91 auto worldLog = worldPhys->GetLogicalVolume(); 95 auto region = G4RegionStore::GetInstance 92 auto region = G4RegionStore::GetInstance()->GetRegion(regName); 96 assert(region != nullptr); 93 assert(region != nullptr); 97 region->AddRootLogicalVolume(worldLog); 94 region->AddRootLogicalVolume(worldLog); 98 region->SetWorld(worldPhys); 95 region->SetWorld(worldPhys); 99 96 100 auto boxSolid = 97 auto boxSolid = 101 new G4Box(logVolName + "_solid", probeSi 98 new G4Box(logVolName + "_solid", probeSize, probeSize, probeSize); 102 fMeshElementLogical = 99 fMeshElementLogical = 103 new G4LogicalVolume(boxSolid, layeredMat 100 new G4LogicalVolume(boxSolid, layeredMaterial, logVolName + "_log"); 104 101 105 std::size_t np = posVec.size(); 102 std::size_t np = posVec.size(); 106 for(std::size_t i = 0; i < np; ++i) 103 for(std::size_t i = 0; i < np; ++i) 107 { 104 { 108 new G4PVPlacement(nullptr, posVec[i], fM 105 new G4PVPlacement(nullptr, posVec[i], fMeshElementLogical, logVolName + "_phy", 109 worldLog, false, (G4in 106 worldLog, false, (G4int)i, chkOverlap); 110 } 107 } 111 108 112 auto wisatt = new G4VisAttributes(G4Colou 109 auto wisatt = new G4VisAttributes(G4Colour(.5, .5, .5)); 113 wisatt->SetVisibility(false); 110 wisatt->SetVisibility(false); 114 worldLog->SetVisAttributes(wisatt); 111 worldLog->SetVisAttributes(wisatt); 115 auto visatt = new G4VisAttributes(G4Colou 112 auto visatt = new G4VisAttributes(G4Colour(.5, .5, .5)); 116 visatt->SetVisibility(true); 113 visatt->SetVisibility(true); 117 fMeshElementLogical->SetVisAttributes(visa 114 fMeshElementLogical->SetVisAttributes(visatt); 118 } 115 } 119 else 116 else 120 { 117 { 121 G4AutoLock l(&logvolmutex); 118 G4AutoLock l(&logvolmutex); 122 fMeshElementLogical = 119 fMeshElementLogical = 123 G4LogicalVolumeStore::GetInstance()->Get 120 G4LogicalVolumeStore::GetInstance()->GetVolume(logVolName, false); 124 assert(fMeshElementLogical != nullptr); 121 assert(fMeshElementLogical != nullptr); 125 l.unlock(); 122 l.unlock(); 126 } 123 } 127 124 128 fMeshElementLogical->SetSensitiveDetector(fM 125 fMeshElementLogical->SetSensitiveDetector(fMFD); 129 } 126 } 130 127 131 G4bool G4ScoringProbe::SetMaterial(G4String va 128 G4bool G4ScoringProbe::SetMaterial(G4String val) 132 { 129 { 133 if(val == "none") << 130 if(G4Threading::IsMasterThread()) 134 { << 135 layeredMaterialName = val; << 136 layeredMassFlg = false; << 137 layeredMaterial = nullptr; << 138 } << 139 else << 140 { 131 { 141 G4AutoLock l(&logvolmutex); << 132 if(val == "none") 142 auto mat = G4NistManager::Instance()->Find << 143 if(mat == nullptr) << 144 { 133 { 145 return false; << 134 layeredMaterialName = val; >> 135 layeredMassFlg = false; >> 136 layeredMaterial = nullptr; 146 } 137 } 147 layeredMaterialName = val; << 138 else 148 layeredMassFlg = true; << 149 layeredMaterial = mat; << 150 if(G4Threading::IsMasterThread()) << 151 { 139 { 152 auto region = G4RegionStore::GetInstance << 140 auto mat = G4NistManager::Instance()->FindOrBuildMaterial(val); 153 assert(region != nullptr); << 141 if(mat == nullptr) 154 region->UpdateMaterialList(); << 142 { >> 143 return false; >> 144 } >> 145 layeredMaterialName = val; >> 146 layeredMassFlg = true; >> 147 layeredMaterial = mat; 155 } 148 } 156 l.unlock(); << 149 auto region = G4RegionStore::GetInstance()->GetRegion(regName); >> 150 assert(region != nullptr); >> 151 region->UpdateMaterialList(); 157 } 152 } 158 return true; 153 return true; 159 } 154 } 160 155