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