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 | // $Id: DetectorMessenger.cc,v 1.11 2006/06/29 16:52:26 gunter Exp $ |
---|
27 | // GEANT4 tag $Name: geant4-09-03-cand-01 $ |
---|
28 | // |
---|
29 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
30 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
31 | |
---|
32 | #include "DetectorMessenger.hh" |
---|
33 | |
---|
34 | #include <sstream> |
---|
35 | |
---|
36 | #include "DetectorConstruction.hh" |
---|
37 | #include "G4UIdirectory.hh" |
---|
38 | #include "G4UIcommand.hh" |
---|
39 | #include "G4UIparameter.hh" |
---|
40 | #include "G4UIcmdWithAnInteger.hh" |
---|
41 | #include "G4UIcmdWithADoubleAndUnit.hh" |
---|
42 | #include "G4UIcmdWithoutParameter.hh" |
---|
43 | |
---|
44 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
45 | |
---|
46 | DetectorMessenger::DetectorMessenger(DetectorConstruction * Det) |
---|
47 | :Detector(Det) |
---|
48 | { |
---|
49 | testemDir = new G4UIdirectory("/testem/"); |
---|
50 | testemDir->SetGuidance("UI commands specific to this example"); |
---|
51 | |
---|
52 | detDir = new G4UIdirectory("/testem/det/"); |
---|
53 | detDir->SetGuidance("detector construction commands"); |
---|
54 | |
---|
55 | SizeYZCmd = new G4UIcmdWithADoubleAndUnit("/testem/det/setSizeYZ",this); |
---|
56 | SizeYZCmd->SetGuidance("Set tranverse size of the calorimeter"); |
---|
57 | SizeYZCmd->SetParameterName("Size",false); |
---|
58 | SizeYZCmd->SetRange("Size>0."); |
---|
59 | SizeYZCmd->SetUnitCategory("Length"); |
---|
60 | SizeYZCmd->AvailableForStates(G4State_PreInit,G4State_Idle); |
---|
61 | |
---|
62 | NbLayersCmd = new G4UIcmdWithAnInteger("/testem/det/setNbOfLayers",this); |
---|
63 | NbLayersCmd->SetGuidance("Set number of layers."); |
---|
64 | NbLayersCmd->SetParameterName("NbLayers",false); |
---|
65 | NbLayersCmd->SetRange("NbLayers>0"); |
---|
66 | NbLayersCmd->AvailableForStates(G4State_PreInit,G4State_Idle); |
---|
67 | |
---|
68 | NbAbsorCmd = new G4UIcmdWithAnInteger("/testem/det/setNbOfAbsor",this); |
---|
69 | NbAbsorCmd->SetGuidance("Set number of Absorbers."); |
---|
70 | NbAbsorCmd->SetParameterName("NbAbsor",false); |
---|
71 | NbAbsorCmd->SetRange("NbAbsor>0"); |
---|
72 | NbAbsorCmd->AvailableForStates(G4State_PreInit,G4State_Idle); |
---|
73 | |
---|
74 | AbsorCmd = new G4UIcommand("/testem/det/setAbsor",this); |
---|
75 | AbsorCmd->SetGuidance("Set the absor nb, the material, the thickness."); |
---|
76 | AbsorCmd->SetGuidance(" absor number : from 1 to NbOfAbsor"); |
---|
77 | AbsorCmd->SetGuidance(" material name"); |
---|
78 | AbsorCmd->SetGuidance(" thickness (with unit) : t>0."); |
---|
79 | // |
---|
80 | G4UIparameter* AbsNbPrm = new G4UIparameter("AbsorNb",'i',false); |
---|
81 | AbsNbPrm->SetGuidance("absor number : from 1 to NbOfAbsor"); |
---|
82 | AbsNbPrm->SetParameterRange("AbsorNb>0"); |
---|
83 | AbsorCmd->SetParameter(AbsNbPrm); |
---|
84 | // |
---|
85 | G4UIparameter* MatPrm = new G4UIparameter("material",'s',false); |
---|
86 | MatPrm->SetGuidance("material name"); |
---|
87 | AbsorCmd->SetParameter(MatPrm); |
---|
88 | // |
---|
89 | G4UIparameter* ThickPrm = new G4UIparameter("thickness",'d',false); |
---|
90 | ThickPrm->SetGuidance("thickness of absorber"); |
---|
91 | ThickPrm->SetParameterRange("thickness>0."); |
---|
92 | AbsorCmd->SetParameter(ThickPrm); |
---|
93 | // |
---|
94 | G4UIparameter* unitPrm = new G4UIparameter("unit",'s',false); |
---|
95 | unitPrm->SetGuidance("unit of thickness"); |
---|
96 | G4String unitList = G4UIcommand::UnitsList(G4UIcommand::CategoryOf("mm")); |
---|
97 | unitPrm->SetParameterCandidates(unitList); |
---|
98 | AbsorCmd->SetParameter(unitPrm); |
---|
99 | // |
---|
100 | AbsorCmd->AvailableForStates(G4State_PreInit,G4State_Idle); |
---|
101 | |
---|
102 | MagFieldCmd = new G4UIcmdWithADoubleAndUnit("/testem/det/setField",this); |
---|
103 | MagFieldCmd->SetGuidance("Define magnetic field."); |
---|
104 | MagFieldCmd->SetGuidance("Magnetic field will be in Z direction."); |
---|
105 | MagFieldCmd->SetParameterName("Bz",false); |
---|
106 | MagFieldCmd->SetUnitCategory("Magnetic flux density"); |
---|
107 | MagFieldCmd->AvailableForStates(G4State_PreInit,G4State_Idle); |
---|
108 | |
---|
109 | UpdateCmd = new G4UIcmdWithoutParameter("/testem/det/update",this); |
---|
110 | UpdateCmd->SetGuidance("Update calorimeter geometry."); |
---|
111 | UpdateCmd->SetGuidance("This command MUST be applied before \"beamOn\" "); |
---|
112 | UpdateCmd->SetGuidance("if you changed geometrical value(s)."); |
---|
113 | UpdateCmd->AvailableForStates(G4State_Idle); |
---|
114 | } |
---|
115 | |
---|
116 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
117 | |
---|
118 | DetectorMessenger::~DetectorMessenger() |
---|
119 | { |
---|
120 | delete SizeYZCmd; |
---|
121 | delete NbLayersCmd; |
---|
122 | delete NbAbsorCmd; |
---|
123 | delete AbsorCmd; |
---|
124 | delete MagFieldCmd; |
---|
125 | delete UpdateCmd; |
---|
126 | delete detDir; |
---|
127 | delete testemDir; |
---|
128 | } |
---|
129 | |
---|
130 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
131 | |
---|
132 | void DetectorMessenger::SetNewValue(G4UIcommand* command,G4String newValue) |
---|
133 | { |
---|
134 | if( command == SizeYZCmd ) |
---|
135 | { Detector->SetCalorSizeYZ(SizeYZCmd->GetNewDoubleValue(newValue));} |
---|
136 | |
---|
137 | if( command == NbLayersCmd ) |
---|
138 | { Detector->SetNbOfLayers(NbLayersCmd->GetNewIntValue(newValue));} |
---|
139 | |
---|
140 | if( command == NbAbsorCmd ) |
---|
141 | { Detector->SetNbOfAbsor(NbAbsorCmd->GetNewIntValue(newValue));} |
---|
142 | |
---|
143 | if (command == AbsorCmd) |
---|
144 | { |
---|
145 | G4int num; G4double tick; |
---|
146 | G4String unt, mat; |
---|
147 | std::istringstream is(newValue); |
---|
148 | is >> num >> mat >> tick >> unt; |
---|
149 | G4String material=mat; |
---|
150 | tick *= G4UIcommand::ValueOf(unt); |
---|
151 | Detector->SetAbsorMaterial (num,material); |
---|
152 | Detector->SetAbsorThickness(num,tick); |
---|
153 | } |
---|
154 | |
---|
155 | if( command == MagFieldCmd ) |
---|
156 | { Detector->SetMagField(MagFieldCmd->GetNewDoubleValue(newValue));} |
---|
157 | |
---|
158 | if( command == UpdateCmd ) |
---|
159 | { Detector->UpdateGeometry();} |
---|
160 | } |
---|
161 | |
---|
162 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|