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 // G4tgrVolume implementation << 27 // 26 // 28 // Author: P.Arce, CIEMAT (November 2007) << 27 // $Id: G4tgrVolume.cc,v 1.7 2008/12/18 13:00:16 gunter Exp $ 29 // ------------------------------------------- << 28 // GEANT4 tag $Name: geant4-09-02 $ >> 29 // >> 30 // >> 31 // class G4tgrVolume >> 32 >> 33 // History: >> 34 // - Created. P.Arce, CIEMAT (November 2007) >> 35 // ------------------------------------------------------------------------- 30 36 31 #include "G4tgrVolume.hh" 37 #include "G4tgrVolume.hh" 32 #include "G4tgrUtils.hh" 38 #include "G4tgrUtils.hh" 33 #include "G4tgrSolid.hh" 39 #include "G4tgrSolid.hh" 34 #include "G4tgrVolumeMgr.hh" 40 #include "G4tgrVolumeMgr.hh" 35 #include "G4tgrPlace.hh" 41 #include "G4tgrPlace.hh" 36 #include "G4tgrPlaceSimple.hh" 42 #include "G4tgrPlaceSimple.hh" 37 #include "G4tgrPlaceDivRep.hh" 43 #include "G4tgrPlaceDivRep.hh" 38 #include "G4tgrPlaceParameterisation.hh" 44 #include "G4tgrPlaceParameterisation.hh" 39 #include "G4tgrFileReader.hh" 45 #include "G4tgrFileReader.hh" 40 #include "G4tgrMessenger.hh" 46 #include "G4tgrMessenger.hh" 41 #include "G4UIcommand.hh" 47 #include "G4UIcommand.hh" 42 48 43 // ------------------------------------------- << 49 //------------------------------------------------------------- 44 G4tgrVolume::G4tgrVolume() 50 G4tgrVolume::G4tgrVolume() 45 { 51 { 46 } 52 } 47 53 48 // ------------------------------------------- << 54 >> 55 //------------------------------------------------------------- 49 G4tgrVolume::~G4tgrVolume() 56 G4tgrVolume::~G4tgrVolume() 50 { 57 { 51 delete[] theRGBColour; << 52 } 58 } 53 59 54 // ------------------------------------------- << 60 55 G4tgrVolume::G4tgrVolume(const std::vector<G4S << 61 //------------------------------------------------------------- >> 62 G4tgrVolume::G4tgrVolume( const std::vector<G4String>& wl) 56 { 63 { 57 theType = "VOLSimple"; 64 theType = "VOLSimple"; 58 65 59 //---------- set name << 66 //---------- set name 60 theName = G4tgrUtils::GetString(wl[1]); << 67 theName = G4tgrUtils::GetString( wl[1] ); 61 68 62 theVisibility = true; << 69 theVisibility = 1; 63 theRGBColour = new G4double[4]; << 70 theRGBColour = new G4double[4]; 64 for(std::size_t ii = 0; ii < 4; ++ii) << 71 for(size_t ii=0; ii<4; ii++) { theRGBColour[ii] = -1.; } 65 { << 72 theCheckOverlaps = 0; 66 theRGBColour[ii] = -1.; << 67 } << 68 theCheckOverlaps = false; << 69 73 70 if(wl.size() != 4) << 74 if( wl.size() != 4 ) 71 { 75 { 72 //:VOLU tag to build a volume creating sol 76 //:VOLU tag to build a volume creating solid and material 73 //---------- set material name 77 //---------- set material name 74 theMaterialName = G4tgrUtils::GetString(wl << 78 theMaterialName = G4tgrUtils::GetString( wl[wl.size()-1] ); 75 << 79 76 //---------- create only vector<double> of 80 //---------- create only vector<double> of theSolidParams 77 theSolid = G4tgrVolumeMgr::GetInstance()-> << 81 theSolid = G4tgrVolumeMgr::GetInstance()->CreateSolid( wl, 1 ); 78 82 79 #ifdef G4VERBOSE 83 #ifdef G4VERBOSE 80 if(G4tgrMessenger::GetVerboseLevel() >= 1) << 84 if( G4tgrMessenger::GetVerboseLevel() >= 1 ) 81 { << 85 { 82 G4cout << "Created from new solid: " << << 86 G4cout << "Created from new solid: " 83 } << 87 << *this << G4endl; >> 88 } 84 #endif 89 #endif 85 } 90 } 86 else 91 else 87 { << 88 //:VOLU tag to build a volume assigning ma << 89 //---------- set material name << 90 theMaterialName = G4tgrUtils::GetString(wl << 91 theSolid = G4tgrVolumeMgr::GetInsta << 92 << 93 #ifdef G4VERBOSE << 94 if(G4tgrMessenger::GetVerboseLevel() >= 1) << 95 { 92 { 96 G4cout << "Created from existing solid: << 93 //:VOLU tag to build a volume assigning material to solid 97 } << 94 //---------- set material name >> 95 theMaterialName = G4tgrUtils::GetString( wl[3] ); >> 96 theSolid = G4tgrVolumeMgr::GetInstance()->FindSolid( wl[2], true ); >> 97 >> 98 #ifdef G4VERBOSE >> 99 if( G4tgrMessenger::GetVerboseLevel() >= 1 ) >> 100 { >> 101 G4cout << "Created from existing solid: " >> 102 << *this << G4endl; >> 103 } 98 #endif 104 #endif 99 } << 105 } >> 106 100 } 107 } 101 108 102 // ------------------------------------------- << 109 103 G4tgrVolume::G4tgrVolume(const G4tgrVolume& vo << 110 //------------------------------------------------------------------------- >> 111 G4tgrVolume* G4tgrVolume::GetVolume( G4int ii ) const 104 { 112 { 105 theName = vol.GetName(); << 113 G4String ErrMessage = "Should only be called for composite solids... " 106 theType = vol.GetType(); << 114 + G4UIcommand::ConvertToString(ii); 107 theMaterialName = vol.GetMaterialName(); << 115 G4Exception("G4tgrVolume::GetVolume()", "InvalidCall", 108 theSolid = vol.GetSolid(); << 116 FatalException, ErrMessage); 109 thePlacements = vol.GetPlacements(); << 117 return 0; 110 theVisibility = vol.GetVisibility(); << 118 } 111 theRGBColour = vol.GetRGBColour(); << 119 112 theCheckOverlaps = vol.GetCheckOverlaps(); << 120 113 } << 121 //------------------------------------------------------------- 114 << 122 G4tgrPlace* G4tgrVolume::AddPlace( const std::vector<G4String>& wl ) 115 // ------------------------------------------- << 123 { 116 G4tgrVolume* G4tgrVolume::GetVolume(G4int ii) << 124 //---------- Check for exact number of words read 117 { << 125 G4tgrUtils::CheckWLsize( wl, 8, WLSIZE_EQ, " G4tgrVolume::AddPlace"); 118 G4String ErrMessage = "Should only be called << 126 //---------- set G4tgrPlace 119 G4UIcommand::ConvertTo << 127 G4tgrPlaceSimple* pl = new G4tgrPlaceSimple( wl ); 120 G4Exception("G4tgrVolume::GetVolume()", "Inv << 121 ErrMessage); << 122 return nullptr; << 123 } << 124 << 125 // ------------------------------------------- << 126 G4tgrPlace* G4tgrVolume::AddPlace(const std::v << 127 { << 128 //---------- Check for exact number of words << 129 G4tgrUtils::CheckWLsize(wl, 8, WLSIZE_EQ, " << 130 //---------- set G4tgrPlace << 131 G4tgrPlaceSimple* pl = new G4tgrPlaceSimple( << 132 //---------- check that there is no previous 128 //---------- check that there is no previous placement in 133 // the same parent with the same c << 129 // the same parent with the same copyNo 134 for(auto ite = thePlacements.cbegin(); ite ! << 130 std::vector<G4tgrPlace*>::iterator ite; >> 131 for( ite = thePlacements.begin(); ite != thePlacements.end(); ite++) 135 { 132 { 136 if(((*ite)->GetCopyNo() == pl->GetCopyNo() << 133 if( ((*ite)->GetCopyNo() == pl->GetCopyNo()) 137 ((*ite)->GetParentName() == pl->GetPare << 134 && ((*ite)->GetParentName() == pl->GetParentName()) ) 138 { 135 { 139 G4String ErrMessage = << 136 G4String ErrMessage = "Repeated placement. Volume " 140 "Repeated placement. Volume " + theNam << 137 + theName + " in " + pl->GetParentName(); 141 G4Exception("G4tgrVolume::AddPlace()", " 138 G4Exception("G4tgrVolume::AddPlace()", "InvalidArgument", 142 FatalErrorInArgument, ErrMes 139 FatalErrorInArgument, ErrMessage); 143 } 140 } 144 } << 141 } 145 142 146 pl->SetVolume(this); << 143 pl->SetVolume( this ); 147 thePlacements.push_back(pl); << 144 thePlacements.push_back( pl ); 148 145 149 #ifdef G4VERBOSE 146 #ifdef G4VERBOSE 150 if(G4tgrMessenger::GetVerboseLevel() >= 2) << 147 if( G4tgrMessenger::GetVerboseLevel() >= 2 ) 151 { 148 { 152 G4cout << " G4tgrVolume: New placement: " 149 G4cout << " G4tgrVolume: New placement: " << thePlacements.size() 153 << " added for Volume " << theName << 150 << " added for Volume " << theName 154 << pl->GetParentName() << " type " << 151 << " inside " << pl->GetParentName() >> 152 << " type " << pl->GetType() << G4endl; 155 } 153 } 156 #endif 154 #endif 157 //---------- register parent - child << 155 //---------- register parent - child 158 G4tgrVolumeMgr::GetInstance()->RegisterParen << 156 G4tgrVolumeMgr::GetInstance()->RegisterParentChild( pl->GetParentName(), pl ); 159 157 160 return pl; 158 return pl; 161 } 159 } 162 160 163 // ------------------------------------------- << 164 G4tgrPlaceDivRep* G4tgrVolume::AddPlaceReplica << 165 { << 166 //---------- Check for exact number of words << 167 G4tgrUtils::CheckWLsize(wl, 6, WLSIZE_GE, " << 168 G4tgrUtils::CheckWLsize(wl, 7, WLSIZE_LE, " << 169 161 170 if((wl.size() == 7) && (G4tgrUtils::GetDoubl << 162 //------------------------------------------------------------- 171 (wl[3] != "PHI")) << 163 G4tgrPlaceDivRep* >> 164 G4tgrVolume::AddPlaceReplica( const std::vector<G4String>& wl ) >> 165 { >> 166 //---------- Check for exact number of words read >> 167 G4tgrUtils::CheckWLsize( wl, 6, WLSIZE_GE, " G4tgrVolume::AddPlaceReplica"); >> 168 G4tgrUtils::CheckWLsize( wl, 7, WLSIZE_LE, " G4tgrVolume::AddPlaceReplica"); >> 169 >> 170 if( (wl.size() == 7) && (G4tgrUtils::GetDouble(wl[6]) != 0.) >> 171 && (wl[3] != "PHI") ) 172 { 172 { 173 G4Exception("G4tgrVolume::AddPlaceReplica" 173 G4Exception("G4tgrVolume::AddPlaceReplica", 174 "Offset set for replica not al 174 "Offset set for replica not along PHI, it will not be used", 175 JustWarning, 175 JustWarning, 176 G4String("Volume " + wl[1] + " << 176 G4String("Volume "+wl[1]+" in volume "+wl[2]).c_str()); 177 } 177 } 178 << 178 179 //---------- set G4tgrPlace << 179 //---------- set G4tgrPlace 180 G4tgrPlaceDivRep* pl = new G4tgrPlaceDivRep( << 180 G4tgrPlaceDivRep* pl = new G4tgrPlaceDivRep( wl ); 181 pl->SetType("PlaceReplica"); 181 pl->SetType("PlaceReplica"); 182 pl->SetVolume(this); << 182 pl->SetVolume( this ); 183 thePlacements.push_back(pl); << 183 thePlacements.push_back( pl ); 184 184 185 #ifdef G4VERBOSE 185 #ifdef G4VERBOSE 186 if(G4tgrMessenger::GetVerboseLevel() >= 2) << 186 if( G4tgrMessenger::GetVerboseLevel() >= 2 ) 187 { 187 { 188 G4cout << " G4tgrVolume: New placement re 188 G4cout << " G4tgrVolume: New placement replica: " << thePlacements.size() 189 << " added for Volume " << theName << 189 << " added for Volume " << theName 190 << pl->GetParentName() << G4endl; << 190 << " inside " << pl->GetParentName() << G4endl; 191 } 191 } 192 #endif 192 #endif 193 //---------- register parent - child << 193 //---------- register parent - child 194 G4tgrVolumeMgr::GetInstance()->RegisterParen << 194 G4tgrVolumeMgr::GetInstance()->RegisterParentChild( pl->GetParentName(), pl ); 195 195 196 return pl; 196 return pl; 197 } 197 } 198 198 199 // ------------------------------------------- << 199 >> 200 //------------------------------------------------------------- 200 G4tgrPlaceParameterisation* 201 G4tgrPlaceParameterisation* 201 G4tgrVolume::AddPlaceParam(const std::vector<G << 202 G4tgrVolume::AddPlaceParam( const std::vector<G4String>& wl ) 202 { 203 { 203 //---------- set G4tgrPlaceParameterisation 204 //---------- set G4tgrPlaceParameterisation 204 G4tgrPlaceParameterisation* pl = new G4tgrPl << 205 G4tgrPlaceParameterisation* pl = new G4tgrPlaceParameterisation( wl ); 205 206 206 pl->SetVolume(this); << 207 pl->SetVolume( this ); 207 thePlacements.push_back(pl); << 208 thePlacements.push_back( pl ); 208 209 209 #ifdef G4VERBOSE 210 #ifdef G4VERBOSE 210 if(G4tgrMessenger::GetVerboseLevel() >= 2) << 211 if( G4tgrMessenger::GetVerboseLevel() >= 2 ) 211 { 212 { 212 G4cout << " G4tgrVolume: New placement Pa 213 G4cout << " G4tgrVolume: New placement Param: " << thePlacements.size() 213 << " added for Volume " << theName << 214 << " added for Volume " << theName 214 << pl->GetParentName() << G4endl; << 215 << " inside " << pl->GetParentName() << G4endl; 215 } 216 } 216 #endif 217 #endif 217 //---------- register parent - child << 218 //---------- register parent - child 218 G4tgrVolumeMgr::GetInstance()->RegisterParen << 219 G4tgrVolumeMgr::GetInstance()->RegisterParentChild( pl->GetParentName(), pl ); 219 220 220 return pl; 221 return pl; 221 } 222 } 222 223 223 // ------------------------------------------- << 224 224 void G4tgrVolume::AddVisibility(const std::vec << 225 //------------------------------------------------------------- >> 226 void G4tgrVolume::AddVisibility( const std::vector<G4String>& wl ) 225 { 227 { 226 //---------- Check for exact number of words << 228 //---------- Check for exact number of words read 227 G4tgrUtils::CheckWLsize(wl, 3, WLSIZE_EQ, " << 229 G4tgrUtils::CheckWLsize( wl, 3, WLSIZE_EQ, " G4tgrVolume::AddVisibility"); 228 230 229 //---------- Set visibility 231 //---------- Set visibility 230 theVisibility = G4tgrUtils::GetBool(wl[2]); << 232 theVisibility = G4tgrUtils::GetBool( wl[2] ); 231 } 233 } 232 234 233 // ------------------------------------------- << 234 void G4tgrVolume::AddRGBColour(const std::vect << 235 { << 236 //---------- Check for exact number of words << 237 G4tgrUtils::CheckWLsize(wl, 5, WLSIZE_GE, " << 238 235 >> 236 //------------------------------------------------------------- >> 237 void G4tgrVolume::AddRGBColour( const std::vector<G4String>& wl ) >> 238 { >> 239 //---------- Check for exact number of words read >> 240 G4tgrUtils::CheckWLsize( wl, 5, WLSIZE_GE, " G4tgrVolume::AddRGBColour"); >> 241 239 //---------- Set RGB colour 242 //---------- Set RGB colour 240 theRGBColour[0] = G4tgrUtils::GetDouble(wl[2 << 243 theRGBColour[0] = G4tgrUtils::GetDouble( wl[2] ); 241 theRGBColour[1] = G4tgrUtils::GetDouble(wl[3 << 244 theRGBColour[1] = G4tgrUtils::GetDouble( wl[3] ); 242 theRGBColour[2] = G4tgrUtils::GetDouble(wl[4 << 245 theRGBColour[2] = G4tgrUtils::GetDouble( wl[4] ); 243 ///--------- Set transparency 246 ///--------- Set transparency 244 if(wl.size() == 6) << 247 if( wl.size() == 6 ) 245 { 248 { 246 theRGBColour[3] = G4tgrUtils::GetDouble(wl << 249 theRGBColour[3] = G4tgrUtils::GetDouble( wl[5] ); 247 } 250 } 248 } 251 } 249 252 250 // ------------------------------------------- << 253 251 void G4tgrVolume::AddCheckOverlaps(const std:: << 254 //------------------------------------------------------------- >> 255 void G4tgrVolume::AddCheckOverlaps( const std::vector<G4String>& wl ) 252 { 256 { 253 //---------- Check for exact number of words << 257 //---------- Check for exact number of words read 254 G4tgrUtils::CheckWLsize(wl, 3, WLSIZE_GE, " << 258 G4tgrUtils::CheckWLsize( wl, 3, WLSIZE_GE, " G4tgrVolume::AddCheckOverlaps"); >> 259 >> 260 ///--------- Set check overlaps >> 261 theCheckOverlaps = G4tgrUtils::GetBool( wl[2] ); 255 262 256 ///--------- Set check overlaps << 257 theCheckOverlaps = G4tgrUtils::GetBool(wl[2] << 258 } 263 } 259 264 260 // ------------------------------------------- << 265 >> 266 // ------------------------------------------------------------------------- 261 std::ostream& operator<<(std::ostream& os, con 267 std::ostream& operator<<(std::ostream& os, const G4tgrVolume& obj) 262 { 268 { 263 os << "G4tgrVolume= " << obj.theName << " Ty 269 os << "G4tgrVolume= " << obj.theName << " Type= " << obj.theType 264 << " Material= " << obj.theMaterialName < << 270 << " Material= " << obj.theMaterialName 265 << obj.theVisibility << " Colour " << (ob << 271 << " Visibility " << obj.theVisibility 266 << (obj.theRGBColour)[1] << " " << (obj.t << 272 << " Colour " << (obj.theRGBColour)[0] << " " 267 << (obj.theRGBColour)[3] << " " << 273 << (obj.theRGBColour)[1] << " " 268 << " CheckOverlaps " << obj.theCheckOverl << 274 << (obj.theRGBColour)[2] << " " 269 << obj.thePlacements.size() << G4endl; << 275 << (obj.theRGBColour)[3] << " " 270 << 276 << " CheckOverlaps " << obj.theCheckOverlaps >> 277 << " N placements " << obj.thePlacements.size() << G4endl; >> 278 271 return os; 279 return os; 272 } 280 } 273 281