EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
eASTDetectorConstructionMessenger.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file eASTDetectorConstructionMessenger.cc
1 // ********************************************************************
2 //
3 // eASTDetectorConstructionMessenger.cc
4 // A messenger class that handles geometry configuration.
5 //
6 // History
7 // May 8th, 2021 : first implementation
8 //
9 // ********************************************************************
10 
12 
14 #include "G4UIcommand.hh"
15 #include "G4UIparameter.hh"
16 #include "G4UIdirectory.hh"
17 #include "G4UIcmdWithAString.hh"
18 #include "G4UIcmdWithAnInteger.hh"
19 #include "G4UIcmdWithoutParameter.hh"
20 
22 : pDC(dc)
23 {
24  G4UIparameter* para = nullptr;
25 
26  geomDir = new G4UIdirectory("/eAST/geometry/");
27  geomDir->SetGuidance("eAST geometry commands");
28 
29  listSolidCmd = new G4UIcmdWithAnInteger("/eAST/geometry/listSolids",this);
30  listSolidCmd->SetGuidance("List all the registered solids");
31  listSolidCmd->SetParameterName("level",true);
32  listSolidCmd->SetDefaultValue(0);
33  listSolidCmd->SetRange("level>=0 && level<=2");
34  listSolidCmd->AvailableForStates(G4State_Init,G4State_Idle);
35  listSolidCmd->SetToBeBroadcasted(false);
36 
37  listLogVolCmd = new G4UIcmdWithAnInteger("/eAST/geometry/listLogicalVolumes",this);
38  listLogVolCmd->SetGuidance("List all the registered logical volumes");
39  listLogVolCmd->SetParameterName("level",true);
40  listLogVolCmd->SetDefaultValue(0);
41  listLogVolCmd->SetRange("level>=0 && level<=2");
42  listLogVolCmd->AvailableForStates(G4State_Init,G4State_Idle);
43  listLogVolCmd->SetToBeBroadcasted(false);
44 
45  listPhysVolCmd = new G4UIcmdWithAnInteger("/eAST/geometry/listPhysicalVolumes",this);
46  listPhysVolCmd->SetGuidance("List all the registered physical volumes");
47  listPhysVolCmd->SetParameterName("level",true);
48  listPhysVolCmd->SetDefaultValue(0);
49  listPhysVolCmd->SetRange("level>=0 && level<=2");
50  listPhysVolCmd->AvailableForStates(G4State_Init,G4State_Idle);
51  listPhysVolCmd->SetToBeBroadcasted(false);
52 
53  listRegionCmd = new G4UIcmdWithAnInteger("/eAST/geometry/listRegions",this);
54  listRegionCmd->SetGuidance("List all the registered regions");
55  listRegionCmd->SetParameterName("level",true);
56  listRegionCmd->SetDefaultValue(0);
57  listRegionCmd->SetRange("level>=0 && level<=2");
58  listRegionCmd->AvailableForStates(G4State_Init,G4State_Idle);
59  listRegionCmd->SetToBeBroadcasted(false);
60 
62  checkOverlapCmd = new G4UIcommand("/eAST/geometry/checkOverlap",this);
63  checkOverlapCmd->SetGuidance("Check volume overlap with existing volumes");
64  checkOverlapCmd->SetGuidance(" i.e. with mother volume for protrusion and with other siblings for overlap.");
65  checkOverlapCmd->SetGuidance(" - This command is valid only for placement and parameterized volumes. If this command is");
66  checkOverlapCmd->SetGuidance(" used for other physical volume type, e.g. replica, command will be simply ignored.");
67  checkOverlapCmd->SetGuidance(" If \"**ALL**\" is used as the volume name, all physical volumes are examined (SLOW!!).");
68  checkOverlapCmd->SetGuidance(" - nSpots specifies number of spots on the surface of the volume to be examined.");
69  checkOverlapCmd->SetGuidance(" The more spots used, the more chances to detect overlaps, but the more time it takes.");
70  checkOverlapCmd->SetGuidance(" - maxErr specifies maximum number of errors to be generated (default 1) before quiting.");
71  para = new G4UIparameter("physVol",'s',true);
72  para->SetDefaultValue("**ALL**");
73  checkOverlapCmd->SetParameter(para);
74  para = new G4UIparameter("nSpots",'i',true);
75  para->SetDefaultValue(1000);
76  para->SetGuidance("Number of trial spots on the volume surface");
77  checkOverlapCmd->SetParameter(para);
78  para = new G4UIparameter("maxErr",'i',true);
79  para->SetDefaultValue(1);
80  para->SetParameterRange("maxErr > 0");
81  para->SetGuidance("Maxinum number of report to be generated");
82  checkOverlapCmd->SetParameter(para);
83  para = new G4UIparameter("tolerance",'d',true);
84  para->SetDefaultValue(0.);
85  para->SetParameterRange("tolerance >= 0.");
86  para->SetGuidance("Tolerance (default 0.)");
87  checkOverlapCmd->SetParameter(para);
88  para = new G4UIparameter("unit",'s',true);
89  para->SetDefaultUnit("mm");
90  checkOverlapCmd->SetParameter(para);
91  checkOverlapCmd->AvailableForStates(G4State_Idle);
92  checkOverlapCmd->SetToBeBroadcasted(false);
93 
94  materialDir = new G4UIdirectory("/eAST/material/");
95  materialDir->SetGuidance("eAST material commands");
96 
97  listMatCmd = new G4UIcmdWithAString("/eAST/material/list",this);
98  listMatCmd->SetGuidance("List material property");
99  listMatCmd->SetGuidance(" If material name is not specified, this command list all registered materials");
100  listMatCmd->SetParameterName("matName",true);
101  listMatCmd->SetDefaultValue("**ALL**");
102  listMatCmd->AvailableForStates(G4State_Init,G4State_Idle);
103  listMatCmd->SetToBeBroadcasted(false);
104 
105  dumpMatCmd = new G4UIcmdWithoutParameter("/eAST/material/dumpNistMaterials",this);
106  dumpMatCmd->SetGuidance("List all pre-defined material names in G4NistManager.");
107  dumpMatCmd->SetGuidance(" Note : a material has to be instantiated with /eAST/material/create before setting it to a logical volume");
108  dumpMatCmd->AvailableForStates(G4State_Init,G4State_Idle);
109  dumpMatCmd->SetToBeBroadcasted(false);
110 
111  createMatCmd = new G4UIcmdWithAString("/eAST/material/create",this);
112  createMatCmd->SetGuidance("Instantiate a material defined in G4NistManager");
113  createMatCmd->SetGuidance(" If the material has already existed, this command does nothing.");
114  createMatCmd->SetParameterName("matName",false);
115  createMatCmd->AvailableForStates(G4State_Init,G4State_Idle);
116  createMatCmd->SetToBeBroadcasted(false);
117 
118  getMatCmd = new G4UIcmdWithAString("/eAST/material/show",this);
119  getMatCmd->SetGuidance("Show the current material of the specified logical volume");
120  getMatCmd->SetParameterName("logVol",false);
121  getMatCmd->AvailableForStates(G4State_Init,G4State_Idle);
122  getMatCmd->SetToBeBroadcasted(false);
123 
124  setMatCmd = new G4UIcommand("/eAST/material/set",this);
125  setMatCmd->SetGuidance("Set the material to the logical volume. The material has to be instantiated in advance.");
126  setMatCmd->SetGuidance(" [usage] /eAST/material/set logicalVolumeName materialName");
127  para = new G4UIparameter("logVol",'s',false);
128  setMatCmd->SetParameter(para);
129  para = new G4UIparameter("matName",'s',false);
130  setMatCmd->SetParameter(para);
131  setMatCmd->AvailableForStates(G4State_Init,G4State_Idle);
132  setMatCmd->SetToBeBroadcasted(false);
133 }
134 
136 {
137  delete listSolidCmd;
138  delete listLogVolCmd;
139  delete listPhysVolCmd;
140  delete listRegionCmd;
141  delete checkOverlapCmd;
142  delete geomDir;
143 
144  delete listMatCmd;
145  delete dumpMatCmd;
146  delete createMatCmd;
147  delete getMatCmd;
148  delete setMatCmd;
149  delete materialDir;
150 }
151 
152 #include "G4Tokenizer.hh"
153 
154 void eASTDetectorConstructionMessenger::SetNewValue(G4UIcommand* cmd, G4String val)
155 {
156  if(cmd==listSolidCmd)
157  { pDC->ListSolids(listSolidCmd->GetNewIntValue(val)); }
158  else if(cmd==listLogVolCmd)
159  { pDC->ListLogVols(listLogVolCmd->GetNewIntValue(val)); }
160  else if(cmd==listPhysVolCmd)
161  { pDC->ListPhysVols(listPhysVolCmd->GetNewIntValue(val)); }
162  else if(cmd==listRegionCmd)
163  { pDC->ListRegions(listRegionCmd->GetNewIntValue(val)); }
164  else if(cmd==checkOverlapCmd)
165  {
166  G4Tokenizer next(val);
167  G4String physVolName = next();
168  G4int nSpots = StoI(next());
169  G4int maxErr = StoI(next());
170  G4String tolStr = next();
171  G4double tol = StoD(tolStr);
172  if(tol>0.)
173  {
174  tolStr += " ";
175  tolStr += next();
176  tol = checkOverlapCmd->ConvertToDimensionedDouble(tolStr);
177  }
178  auto valid = pDC->CheckOverlap(physVolName,nSpots,maxErr,tol);
179  if(!valid)
180  {
181  G4ExceptionDescription ed;
182  ed << "Physical volume <" << physVolName << "> is not defined. Command ignored.";
183  cmd->CommandFailed(ed);
184  }
185  }
186 
187  else if(cmd==listMatCmd)
188  {
189  if(val=="**ALL**")
190  { pDC->ListAllMaterial(); }
191  else
192  {
193  auto valid = pDC->ListMaterial(val);
194  if(!valid)
195  {
196  G4ExceptionDescription ed;
197  ed << "<" << val << "> is not defined. If necessary, create it with /eAST/material/create command.";
198  cmd->CommandFailed(ed);
199  }
200  }
201  }
202  else if(cmd==dumpMatCmd)
203  { pDC->DumpNistMaterials(); }
204  else if(cmd==createMatCmd)
205  {
206  auto valid = pDC->CreateMaterial(val);
207  if(!valid)
208  {
209  G4ExceptionDescription ed;
210  ed << "The material name <" << val << "> is not defined in G4NistManager.";
211  cmd->CommandFailed(ed);
212  }
213  }
214  else if(cmd==getMatCmd)
215  {
216  auto valid = pDC->GetMaterial(val);
217  if(!valid)
218  {
219  G4ExceptionDescription ed;
220  ed << "<" << val << "> is not a name of registered logical volume.\n"
221  << "Check existing logical volumes with /eAST/geometry/listLogicalVolumes command.";
222  cmd->CommandFailed(ed);
223  }
224  }
225  else if(cmd==setMatCmd)
226  {
227  G4Tokenizer next(val);
228  G4String logVolName = next();
229  G4String matName = next();
230  auto valid = pDC->SetMaterial(logVolName,matName);
231  if(valid!=0)
232  {
233  G4ExceptionDescription ed;
234  if(valid==1 || valid==3)
235  {
236  ed << "<" << logVolName << "> is not a name of registered logical volume.\n"
237  << "Check existing logical volumes with /eAST/geometry/listLogicalVolumes command.\n";
238  }
239  if(valid==2 || valid==3)
240  {
241  ed << "<" << matName << "> is not defined. If necessary, create it with /eAST/material/create command.";
242  }
243  cmd->CommandFailed(ed);
244  }
245  }
246 
247 }
248 
250 {
251  G4String val("");
252  return val;
253 }
254 
255