Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
examples/extended/electromagnetic/TestEm3/src/DetectorMessenger.cc
Go to the documentation of this file.
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 /// \file electromagnetic/TestEm3/src/DetectorMessenger.cc
27 /// \brief Implementation of the DetectorMessenger class
28 //
29 // $Id: DetectorMessenger.cc 67268 2013-02-13 11:38:40Z ihrivnac $
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "DetectorMessenger.hh"
35 
36 #include <sstream>
37 
38 #include "DetectorConstruction.hh"
39 #include "G4UIdirectory.hh"
40 #include "G4UIcommand.hh"
41 #include "G4UIparameter.hh"
42 #include "G4UIcmdWithAnInteger.hh"
45 
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
47 
49 :G4UImessenger(),Detector(Det),
50  fTestemDir(0),
51  fDetDir(0),
52  fSizeYZCmd(0),
53  fNbLayersCmd(0),
54  fNbAbsorCmd(0),
55  fAbsorCmd(0),
56  fMagFieldCmd(0),
57  fUpdateCmd(0)
58 {
59  fTestemDir = new G4UIdirectory("/testem/");
60  fTestemDir->SetGuidance("UI commands specific to this example");
61 
62  fDetDir = new G4UIdirectory("/testem/det/");
63  fDetDir->SetGuidance("detector construction commands");
64 
65  fSizeYZCmd = new G4UIcmdWithADoubleAndUnit("/testem/det/setSizeYZ",this);
66  fSizeYZCmd->SetGuidance("Set tranverse size of the calorimeter");
67  fSizeYZCmd->SetParameterName("Size",false);
68  fSizeYZCmd->SetRange("Size>0.");
69  fSizeYZCmd->SetUnitCategory("Length");
71 
72  fNbLayersCmd = new G4UIcmdWithAnInteger("/testem/det/setNbOfLayers",this);
73  fNbLayersCmd->SetGuidance("Set number of layers.");
74  fNbLayersCmd->SetParameterName("NbLayers",false);
75  fNbLayersCmd->SetRange("NbLayers>0");
77 
78  fNbAbsorCmd = new G4UIcmdWithAnInteger("/testem/det/setNbOfAbsor",this);
79  fNbAbsorCmd->SetGuidance("Set number of Absorbers.");
80  fNbAbsorCmd->SetParameterName("NbAbsor",false);
81  fNbAbsorCmd->SetRange("NbAbsor>0");
83 
84  fAbsorCmd = new G4UIcommand("/testem/det/setAbsor",this);
85  fAbsorCmd->SetGuidance("Set the absor nb, the material, the thickness.");
86  fAbsorCmd->SetGuidance(" absor number : from 1 to NbOfAbsor");
87  fAbsorCmd->SetGuidance(" material name");
88  fAbsorCmd->SetGuidance(" thickness (with unit) : t>0.");
89  //
90  G4UIparameter* AbsNbPrm = new G4UIparameter("AbsorNb",'i',false);
91  AbsNbPrm->SetGuidance("absor number : from 1 to NbOfAbsor");
92  AbsNbPrm->SetParameterRange("AbsorNb>0");
93  fAbsorCmd->SetParameter(AbsNbPrm);
94  //
95  G4UIparameter* MatPrm = new G4UIparameter("material",'s',false);
96  MatPrm->SetGuidance("material name");
97  fAbsorCmd->SetParameter(MatPrm);
98  //
99  G4UIparameter* ThickPrm = new G4UIparameter("thickness",'d',false);
100  ThickPrm->SetGuidance("thickness of absorber");
101  ThickPrm->SetParameterRange("thickness>0.");
102  fAbsorCmd->SetParameter(ThickPrm);
103  //
104  G4UIparameter* unitPrm = new G4UIparameter("unit",'s',false);
105  unitPrm->SetGuidance("unit of thickness");
107  unitPrm->SetParameterCandidates(unitList);
108  fAbsorCmd->SetParameter(unitPrm);
109  //
111 
112  fMagFieldCmd = new G4UIcmdWithADoubleAndUnit("/testem/det/setField",this);
113  fMagFieldCmd->SetGuidance("Define magnetic field.");
114  fMagFieldCmd->SetGuidance("Magnetic field will be in Z direction.");
115  fMagFieldCmd->SetParameterName("Bz",false);
116  fMagFieldCmd->SetUnitCategory("Magnetic flux density");
118 
119  fUpdateCmd = new G4UIcmdWithoutParameter("/testem/det/update",this);
120  fUpdateCmd->SetGuidance("Update calorimeter geometry.");
121  fUpdateCmd->SetGuidance("This command MUST be applied before \"beamOn\" ");
122  fUpdateCmd->SetGuidance("if you changed geometrical value(s).");
123  fUpdateCmd->AvailableForStates(G4State_Idle);
124 }
125 
126 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
127 
129 {
130  delete fSizeYZCmd;
131  delete fNbLayersCmd;
132  delete fNbAbsorCmd;
133  delete fAbsorCmd;
134  delete fMagFieldCmd;
135  delete fUpdateCmd;
136  delete fDetDir;
137  delete fTestemDir;
138 }
139 
140 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
141 
143 {
144  if( command == fSizeYZCmd )
145  { Detector->SetCalorSizeYZ(fSizeYZCmd->GetNewDoubleValue(newValue));}
146 
147  if( command == fNbLayersCmd )
148  { Detector->SetNbOfLayers(fNbLayersCmd->GetNewIntValue(newValue));}
149 
150  if( command == fNbAbsorCmd )
151  { Detector->SetNbOfAbsor(fNbAbsorCmd->GetNewIntValue(newValue));}
152 
153  if (command == fAbsorCmd)
154  {
155  G4int num; G4double tick;
156  G4String unt, mat;
157  std::istringstream is(newValue);
158  is >> num >> mat >> tick >> unt;
159  G4String material=mat;
160  tick *= G4UIcommand::ValueOf(unt);
161  Detector->SetAbsorMaterial (num,material);
162  Detector->SetAbsorThickness(num,tick);
163  }
164 
165  if( command == fMagFieldCmd )
166  { Detector->SetMagField(fMagFieldCmd->GetNewDoubleValue(newValue));}
167 
168  if( command == fUpdateCmd )
169  { Detector->UpdateGeometry();}
170 }
171 
172 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4int GetNewIntValue(const char *paramString)
void SetParameterRange(const char *theRange)
void SetParameterCandidates(const char *theString)
void SetUnitCategory(const char *unitCategory)
static G4double GetNewDoubleValue(const char *paramString)
int G4int
Definition: G4Types.hh:78
string material
Definition: eplot.py:19
static G4String UnitsList(const char *unitCategory)
Definition: G4UIcommand.cc:306
void SetRange(const char *rs)
Definition: G4UIcommand.hh:125
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:225
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:294
double G4double
Definition: G4Types.hh:76
void SetGuidance(const char *theGuidance)
static G4String CategoryOf(const char *unitName)
Definition: G4UIcommand.cc:301
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)