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] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 //
  2 // ********************************************************************
  3 // * License and Disclaimer                                           *
  4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.                             *
 10 // *                                                                  *
 11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                                                  *
 18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // ********************************************************************
 25 //
 26 //  Gorad (Geant4 Open-source Radiation Analysis and Design)
 27 //
 28 //  Author : Makoto Asai (SLAC National Accelerator Laboratory)
 29 //
 30 //  Development of Gorad is funded by NASA Johnson Space Center (JSC)
 31 //  under the contract NNJ15HK11B.
 32 //
 33 // ********************************************************************
 34 //
 35 // GRDetectorConstructionMessenger.cc
 36 //   A messenger class that handles geometry configuration.
 37 //
 38 // History
 39 //   September 8th, 2020 : first implementation
 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::GRDetectorConstructionMessenger(GRDetectorConstruction* dc)
 54 : pDC(dc)
 55 {
 56   G4UIparameter* para = nullptr;
 57 
 58   geomDir = new G4UIdirectory("/gorad/geometry/");
 59   geomDir->SetGuidance("GORAD geometry selection");
 60 
 61   selectCmd = new G4UIcmdWithAString("/gorad/geometry/selectGDML",this);
 62   selectCmd->SetGuidance("Select GDML file");
 63   selectCmd->SetParameterName("gdml",false);
 64   selectCmd->AvailableForStates(G4State_PreInit);
 65   selectCmd->SetToBeBroadcasted(false);
 66 
 67   listSolidCmd = new G4UIcmdWithAnInteger("/gorad/geometry/listSolids",this);
 68   listSolidCmd->SetGuidance("List all the registered solids");
 69   listSolidCmd->SetParameterName("level",true);
 70   listSolidCmd->SetDefaultValue(0);
 71   listSolidCmd->SetRange("level>=0 && level<=2");
 72   listSolidCmd->AvailableForStates(G4State_Idle);
 73   listSolidCmd->SetToBeBroadcasted(false);
 74 
 75   listLogVolCmd = new G4UIcmdWithAnInteger("/gorad/geometry/listLogicalVolumes",this);
 76   listLogVolCmd->SetGuidance("List all the registered logical volumes");
 77   listLogVolCmd->SetParameterName("level",true);
 78   listLogVolCmd->SetDefaultValue(0);
 79   listLogVolCmd->SetRange("level>=0 && level<=2");
 80   listLogVolCmd->AvailableForStates(G4State_Idle);
 81   listLogVolCmd->SetToBeBroadcasted(false);
 82 
 83   listPhysVolCmd = new G4UIcmdWithAnInteger("/gorad/geometry/listPhysicalVolumes",this);
 84   listPhysVolCmd->SetGuidance("List all the registered physical volumes");
 85   listPhysVolCmd->SetParameterName("level",true);
 86   listPhysVolCmd->SetDefaultValue(0);
 87   listPhysVolCmd->SetRange("level>=0 && level<=2");
 88   listPhysVolCmd->AvailableForStates(G4State_Idle);
 89   listPhysVolCmd->SetToBeBroadcasted(false);
 90 
 91   listRegionCmd = new G4UIcmdWithAnInteger("/gorad/geometry/listRegions",this);
 92   listRegionCmd->SetGuidance("List all the registered regions");
 93   listRegionCmd->SetParameterName("level",true);
 94   listRegionCmd->SetDefaultValue(0);
 95   listRegionCmd->SetRange("level>=0 && level<=2");
 96   listRegionCmd->AvailableForStates(G4State_Idle);
 97   listRegionCmd->SetToBeBroadcasted(false);
 98 
 99   createRegionCmd = new G4UIcommand("/gorad/geometry/createRegion",this);
100   createRegionCmd->SetGuidance("Create a region and set the root logical volume to it.");
101   createRegionCmd->SetGuidance("Region propagates to the daughter volumes. So, only the root logical volume (i.e. top of the hierarchy) should be defined.");
102   createRegionCmd->SetGuidance("If two isolated root logical volumes should share the same region, the same region name can be used.");
103   createRegionCmd->SetGuidance("Region must not be set to the world volume.");
104   para = new G4UIparameter("regionName",'s',false);
105   para->SetGuidance("Name of the region to be created");
106   createRegionCmd->SetParameter(para);
107   para = new G4UIparameter("logVolName",'s',false);
108   para->SetGuidance("Name of the root logical volume");
109   createRegionCmd->SetParameter(para);
110   createRegionCmd->AvailableForStates(G4State_Idle);
111   createRegionCmd->SetToBeBroadcasted(false);
112 
113   //// This command is fragile for large-scale geometry - temporally disabled
114   ////checkOverlapCmd = new G4UIcommand("/gorad/geometry/checkOverlap",this);
115   ////checkOverlapCmd->SetGuidance("Check volume overlap with existing volumes");
116   ////checkOverlapCmd->SetGuidance(" i.e. with mother volume for protrusion and with other siblings for overlap.");
117   ////checkOverlapCmd->SetGuidance(" - This command is valid only for placement and parameterized volumes. If this command is");
118   ////checkOverlapCmd->SetGuidance("   used for other physical volume type, e.g. replica, command will be simply ignored.");
119   ////checkOverlapCmd->SetGuidance("   If \"**ALL**\" is used as the volume name, all physical volumes are examined (SLOW!!).");
120   ////checkOverlapCmd->SetGuidance(" - nSpots specifies number of spots on the surface of the volume to be examined.");
121   ////checkOverlapCmd->SetGuidance("   The more spots used, the more chances to detect overlaps, but the more time it takes.");
122   ////checkOverlapCmd->SetGuidance(" - maxErr specifies maximum number of errors to be generated (default 1) before quiting.");
123   ////para = new G4UIparameter("physVol",'s',true);
124   ////para->SetDefaultValue("**ALL**");
125   ////checkOverlapCmd->SetParameter(para);
126   ////para = new G4UIparameter("nSpots",'i',true);
127   ////para->SetDefaultValue(1000);
128   ////para->SetGuidance("Number of trial spots on the volume surface");
129   ////checkOverlapCmd->SetParameter(para);
130   ////para = new G4UIparameter("maxErr",'i',true);
131   ////para->SetDefaultValue(1);
132   ////para->SetParameterRange("maxErr > 0");
133   ////para->SetGuidance("Maxinum number of report to be generated");
134   ////checkOverlapCmd->SetParameter(para);
135   ////para = new G4UIparameter("tolerance",'d',true);
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(G4State_Idle);
144   ////checkOverlapCmd->SetToBeBroadcasted(false);
145   
146   materialDir = new G4UIdirectory("/gorad/material/");
147   materialDir->SetGuidance("GORAD material commands");
148 
149   listMatCmd = new G4UIcmdWithAString("/gorad/material/list",this);
150   listMatCmd->SetGuidance("List material property");
151   listMatCmd->SetGuidance(" If material name is not specified, this command list all registered materials");
152   listMatCmd->SetParameterName("matName",true);
153   listMatCmd->SetDefaultValue("**ALL**");
154   listMatCmd->AvailableForStates(G4State_Idle);
155   listMatCmd->SetToBeBroadcasted(false);
156 
157   dumpMatCmd = new G4UIcmdWithoutParameter("/gorad/material/dumpNistMaterials",this);
158   dumpMatCmd->SetGuidance("List all pre-defined material names in G4NistManager.");
159   dumpMatCmd->SetGuidance(" Note : a material has to be instantiated with /gorad/material/create before setting it to a logical volume");
160   dumpMatCmd->AvailableForStates(G4State_Idle);
161   dumpMatCmd->SetToBeBroadcasted(false);
162 
163   createMatCmd = new G4UIcmdWithAString("/gorad/material/create",this);
164   createMatCmd->SetGuidance("Instantiate a material defined in G4NistManager");
165   createMatCmd->SetGuidance(" If the material has already existed, this command does nothing.");
166   createMatCmd->SetParameterName("matName",false);
167   createMatCmd->AvailableForStates(G4State_Idle);
168   createMatCmd->SetToBeBroadcasted(false);
169 
170   getMatCmd = new G4UIcmdWithAString("/gorad/material/show",this); 
171   getMatCmd->SetGuidance("Show the current material of the specified logical volume");
172   getMatCmd->SetParameterName("logVol",false);
173   getMatCmd->AvailableForStates(G4State_Idle);
174   getMatCmd->SetToBeBroadcasted(false);
175 
176   setMatCmd = new G4UIcommand("/gorad/material/set",this);
177   setMatCmd->SetGuidance("Set the material to the logical volume. The material has to be instantiated in advance.");
178   setMatCmd->SetGuidance("  [usage] /gorad/material/set logicalVolumeName materialName");
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::~GRDetectorConstructionMessenger()
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::SetNewValue(G4UIcommand* cmd, G4String val)
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 GDML file.";
217       cmd->CommandFailed(ed);
218     }
219   }
220   else if(cmd==listSolidCmd)
221   { pDC->ListSolids(listSolidCmd->GetNewIntValue(val)); }
222   else if(cmd==listLogVolCmd)
223   { pDC->ListLogVols(listLogVolCmd->GetNewIntValue(val)); }
224   else if(cmd==listPhysVolCmd)
225   { pDC->ListPhysVols(listPhysVolCmd->GetNewIntValue(val)); }
226   else if(cmd==listRegionCmd)
227   { pDC->ListRegions(listRegionCmd->GetNewIntValue(val)); }
228   else if(cmd==createRegionCmd)
229   {
230     G4Tokenizer next(val);
231     G4String regionName = next();
232     G4String logVolName = next();
233     auto valid = pDC->CreateRegion(regionName,logVolName);
234     if(!valid)
235     {
236       G4ExceptionDescription ed;
237       ed << "Logical volume <" << logVolName << "> is not defined. Command ignored.";
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->ConvertToDimensionedDouble(tolStr);
254     ////}
255     ////auto valid = pDC->CheckOverlap(physVolName,nSpots,maxErr,tol);
256     ////if(!valid)
257     ////{
258       ////G4ExceptionDescription ed;
259       ////ed << "Physical volume <" << physVolName << "> is not defined. Command ignored.";
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. If necessary, create it with /gorad/material/create command.";
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 << "> is not defined in G4NistManager.";
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 registered logical volume.\n"
298          << "Check existing logical volumes with /gorad/geometry/listLogicalVolumes command.";
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,matName);
308     if(valid!=0)
309     {
310       G4ExceptionDescription ed;
311       if(valid==1 || valid==3)
312       {
313         ed << "<" << logVolName << "> is not a name of registered logical volume.\n"
314            << "Check existing logical volumes with /gorad/geometry/listLogicalVolumes command.\n";
315       }
316       if(valid==2 || valid==3)
317       {
318         ed << "<" << matName << "> is not defined. If necessary, create it with /gorad/material/create command.";
319       }
320       cmd->CommandFailed(ed);
321     }
322   }
323 
324 }
325 
326 G4String GRDetectorConstructionMessenger::GetCurrentValue(G4UIcommand* cmd)
327 {
328   G4String val("");
329   if(cmd==selectCmd)
330   { val = pDC->GetGDMLFile(); }
331   return val;
332 }
333 
334 
335