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 // Gorad (Geant4 Open-source Radiation Analys 27 // 28 // Author : Makoto Asai (SLAC National Accele 29 // 30 // Development of Gorad is funded by NASA Joh 31 // under the contract NNJ15HK11B. 32 // 33 // ******************************************* 34 // 35 // GRDetectorConstructionMessenger.cc 36 // A messenger class that handles geometry c 37 // 38 // History 39 // September 8th, 2020 : first implementatio 40 // 41 // ******************************************* 42 43 #include "GRDetectorConstructionMessenger.hh" 44 45 #include "GRDetectorConstruction.hh" 46 #include "G4UIcommand.hh" 47 #include "G4UIparameter.hh" 48 #include "G4UIdirectory.hh" 49 #include "G4UIcmdWithAString.hh" 50 #include "G4UIcmdWithAnInteger.hh" 51 #include "G4UIcmdWithoutParameter.hh" 52 53 GRDetectorConstructionMessenger::GRDetectorCon 54 : pDC(dc) 55 { 56 G4UIparameter* para = nullptr; 57 58 geomDir = new G4UIdirectory("/gorad/geometry 59 geomDir->SetGuidance("GORAD geometry selecti 60 61 selectCmd = new G4UIcmdWithAString("/gorad/g 62 selectCmd->SetGuidance("Select GDML file"); 63 selectCmd->SetParameterName("gdml",false); 64 selectCmd->AvailableForStates(G4State_PreIni 65 selectCmd->SetToBeBroadcasted(false); 66 67 listSolidCmd = new G4UIcmdWithAnInteger("/go 68 listSolidCmd->SetGuidance("List all the regi 69 listSolidCmd->SetParameterName("level",true) 70 listSolidCmd->SetDefaultValue(0); 71 listSolidCmd->SetRange("level>=0 && level<=2 72 listSolidCmd->AvailableForStates(G4State_Idl 73 listSolidCmd->SetToBeBroadcasted(false); 74 75 listLogVolCmd = new G4UIcmdWithAnInteger("/g 76 listLogVolCmd->SetGuidance("List all the reg 77 listLogVolCmd->SetParameterName("level",true 78 listLogVolCmd->SetDefaultValue(0); 79 listLogVolCmd->SetRange("level>=0 && level<= 80 listLogVolCmd->AvailableForStates(G4State_Id 81 listLogVolCmd->SetToBeBroadcasted(false); 82 83 listPhysVolCmd = new G4UIcmdWithAnInteger("/ 84 listPhysVolCmd->SetGuidance("List all the re 85 listPhysVolCmd->SetParameterName("level",tru 86 listPhysVolCmd->SetDefaultValue(0); 87 listPhysVolCmd->SetRange("level>=0 && level< 88 listPhysVolCmd->AvailableForStates(G4State_I 89 listPhysVolCmd->SetToBeBroadcasted(false); 90 91 listRegionCmd = new G4UIcmdWithAnInteger("/g 92 listRegionCmd->SetGuidance("List all the reg 93 listRegionCmd->SetParameterName("level",true 94 listRegionCmd->SetDefaultValue(0); 95 listRegionCmd->SetRange("level>=0 && level<= 96 listRegionCmd->AvailableForStates(G4State_Id 97 listRegionCmd->SetToBeBroadcasted(false); 98 99 createRegionCmd = new G4UIcommand("/gorad/ge 100 createRegionCmd->SetGuidance("Create a regio 101 createRegionCmd->SetGuidance("Region propaga 102 createRegionCmd->SetGuidance("If two isolate 103 createRegionCmd->SetGuidance("Region must no 104 para = new G4UIparameter("regionName",'s',fa 105 para->SetGuidance("Name of the region to be 106 createRegionCmd->SetParameter(para); 107 para = new G4UIparameter("logVolName",'s',fa 108 para->SetGuidance("Name of the root logical 109 createRegionCmd->SetParameter(para); 110 createRegionCmd->AvailableForStates(G4State_ 111 createRegionCmd->SetToBeBroadcasted(false); 112 113 //// This command is fragile for large-scale 114 ////checkOverlapCmd = new G4UIcommand("/gora 115 ////checkOverlapCmd->SetGuidance("Check volu 116 ////checkOverlapCmd->SetGuidance(" i.e. with 117 ////checkOverlapCmd->SetGuidance(" - This co 118 ////checkOverlapCmd->SetGuidance(" used fo 119 ////checkOverlapCmd->SetGuidance(" If \"** 120 ////checkOverlapCmd->SetGuidance(" - nSpots 121 ////checkOverlapCmd->SetGuidance(" The mor 122 ////checkOverlapCmd->SetGuidance(" - maxErr 123 ////para = new G4UIparameter("physVol",'s',t 124 ////para->SetDefaultValue("**ALL**"); 125 ////checkOverlapCmd->SetParameter(para); 126 ////para = new G4UIparameter("nSpots",'i',tr 127 ////para->SetDefaultValue(1000); 128 ////para->SetGuidance("Number of trial spots 129 ////checkOverlapCmd->SetParameter(para); 130 ////para = new G4UIparameter("maxErr",'i',tr 131 ////para->SetDefaultValue(1); 132 ////para->SetParameterRange("maxErr > 0"); 133 ////para->SetGuidance("Maxinum number of rep 134 ////checkOverlapCmd->SetParameter(para); 135 ////para = new G4UIparameter("tolerance",'d' 136 ////para->SetDefaultValue(0.); 137 ////para->SetParameterRange("tolerance >= 0. 138 ////para->SetGuidance("Tolerance (default 0. 139 ////checkOverlapCmd->SetParameter(para); 140 ////para = new G4UIparameter("unit",'s',true 141 ////para->SetDefaultUnit("mm"); 142 ////checkOverlapCmd->SetParameter(para); 143 ////checkOverlapCmd->AvailableForStates(G4St 144 ////checkOverlapCmd->SetToBeBroadcasted(fals 145 146 materialDir = new G4UIdirectory("/gorad/mate 147 materialDir->SetGuidance("GORAD material com 148 149 listMatCmd = new G4UIcmdWithAString("/gorad/ 150 listMatCmd->SetGuidance("List material prope 151 listMatCmd->SetGuidance(" If material name i 152 listMatCmd->SetParameterName("matName",true) 153 listMatCmd->SetDefaultValue("**ALL**"); 154 listMatCmd->AvailableForStates(G4State_Idle) 155 listMatCmd->SetToBeBroadcasted(false); 156 157 dumpMatCmd = new G4UIcmdWithoutParameter("/g 158 dumpMatCmd->SetGuidance("List all pre-define 159 dumpMatCmd->SetGuidance(" Note : a material 160 dumpMatCmd->AvailableForStates(G4State_Idle) 161 dumpMatCmd->SetToBeBroadcasted(false); 162 163 createMatCmd = new G4UIcmdWithAString("/gora 164 createMatCmd->SetGuidance("Instantiate a mat 165 createMatCmd->SetGuidance(" If the material 166 createMatCmd->SetParameterName("matName",fal 167 createMatCmd->AvailableForStates(G4State_Idl 168 createMatCmd->SetToBeBroadcasted(false); 169 170 getMatCmd = new G4UIcmdWithAString("/gorad/m 171 getMatCmd->SetGuidance("Show the current mat 172 getMatCmd->SetParameterName("logVol",false); 173 getMatCmd->AvailableForStates(G4State_Idle); 174 getMatCmd->SetToBeBroadcasted(false); 175 176 setMatCmd = new G4UIcommand("/gorad/material 177 setMatCmd->SetGuidance("Set the material to 178 setMatCmd->SetGuidance(" [usage] /gorad/mat 179 para = new G4UIparameter("logVol",'s',false) 180 setMatCmd->SetParameter(para); 181 para = new G4UIparameter("matName",'s',false 182 setMatCmd->SetParameter(para); 183 setMatCmd->AvailableForStates(G4State_Idle); 184 setMatCmd->SetToBeBroadcasted(false); 185 } 186 187 GRDetectorConstructionMessenger::~GRDetectorCo 188 { 189 delete selectCmd; 190 delete listSolidCmd; 191 delete listLogVolCmd; 192 delete listPhysVolCmd; 193 delete listRegionCmd; 194 delete createRegionCmd; 195 ////delete checkOverlapCmd; 196 delete geomDir; 197 198 delete listMatCmd; 199 delete dumpMatCmd; 200 delete createMatCmd; 201 delete getMatCmd; 202 delete setMatCmd; 203 delete materialDir; 204 } 205 206 #include "G4Tokenizer.hh" 207 208 void GRDetectorConstructionMessenger::SetNewVa 209 { 210 if(cmd==selectCmd) 211 { 212 auto valid = pDC->SetGDMLFile(val); 213 if(!valid) 214 { 215 G4ExceptionDescription ed; 216 ed << "<" << val << "> is not a valid GD 217 cmd->CommandFailed(ed); 218 } 219 } 220 else if(cmd==listSolidCmd) 221 { pDC->ListSolids(listSolidCmd->GetNewIntVal 222 else if(cmd==listLogVolCmd) 223 { pDC->ListLogVols(listLogVolCmd->GetNewIntV 224 else if(cmd==listPhysVolCmd) 225 { pDC->ListPhysVols(listPhysVolCmd->GetNewIn 226 else if(cmd==listRegionCmd) 227 { pDC->ListRegions(listRegionCmd->GetNewIntV 228 else if(cmd==createRegionCmd) 229 { 230 G4Tokenizer next(val); 231 G4String regionName = next(); 232 G4String logVolName = next(); 233 auto valid = pDC->CreateRegion(regionName, 234 if(!valid) 235 { 236 G4ExceptionDescription ed; 237 ed << "Logical volume <" << logVolName < 238 cmd->CommandFailed(ed); 239 } 240 } 241 ////else if(cmd==checkOverlapCmd) 242 ////{ 243 ////G4Tokenizer next(val); 244 ////G4String physVolName = next(); 245 ////G4int nSpots = StoI(next()); 246 ////G4int maxErr = StoI(next()); 247 ////G4String tolStr = next(); 248 ////G4double tol = StoD(tolStr); 249 ////if(tol>0.) 250 ////{ 251 ////tolStr += " "; 252 ////tolStr += next(); 253 ////tol = checkOverlapCmd->ConvertToDime 254 ////} 255 ////auto valid = pDC->CheckOverlap(physVol 256 ////if(!valid) 257 ////{ 258 ////G4ExceptionDescription ed; 259 ////ed << "Physical volume <" << physVol 260 ////cmd->CommandFailed(ed); 261 ////} 262 ////} 263 264 else if(cmd==listMatCmd) 265 { 266 if(val=="**ALL**") 267 { pDC->ListAllMaterial(); } 268 else 269 { 270 auto valid = pDC->ListMaterial(val); 271 if(!valid) 272 { 273 G4ExceptionDescription ed; 274 ed << "<" << val << "> is not defined. 275 cmd->CommandFailed(ed); 276 } 277 } 278 } 279 else if(cmd==dumpMatCmd) 280 { pDC->DumpNistMaterials(); } 281 else if(cmd==createMatCmd) 282 { 283 auto valid = pDC->CreateMaterial(val); 284 if(!valid) 285 { 286 G4ExceptionDescription ed; 287 ed << "The material name <" << val << "> 288 cmd->CommandFailed(ed); 289 } 290 } 291 else if(cmd==getMatCmd) 292 { 293 auto valid = pDC->GetMaterial(val); 294 if(!valid) 295 { 296 G4ExceptionDescription ed; 297 ed << "<" << val << "> is not a name of 298 << "Check existing logical volumes wi 299 cmd->CommandFailed(ed); 300 } 301 } 302 else if(cmd==setMatCmd) 303 { 304 G4Tokenizer next(val); 305 G4String logVolName = next(); 306 G4String matName = next(); 307 auto valid = pDC->SetMaterial(logVolName,m 308 if(valid!=0) 309 { 310 G4ExceptionDescription ed; 311 if(valid==1 || valid==3) 312 { 313 ed << "<" << logVolName << "> is not a 314 << "Check existing logical volumes 315 } 316 if(valid==2 || valid==3) 317 { 318 ed << "<" << matName << "> is not defi 319 } 320 cmd->CommandFailed(ed); 321 } 322 } 323 324 } 325 326 G4String GRDetectorConstructionMessenger::GetC 327 { 328 G4String val(""); 329 if(cmd==selectCmd) 330 { val = pDC->GetGDMLFile(); } 331 return val; 332 } 333 334 335