Geant4  10.02.p01
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 //
28 //
29 // $Id: DetectorMessenger.cc 78655 2014-01-14 11:13:41Z gcosmo $
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 {
57  fTestemDir = new G4UIdirectory("/testem/");
58  fTestemDir->SetGuidance("UI commands specific to this example");
59 
60  fDetDir = new G4UIdirectory("/testem/det/");
61  fDetDir->SetGuidance("detector construction commands");
62 
63  fSizeYZCmd = new G4UIcmdWithADoubleAndUnit("/testem/det/setSizeYZ",this);
64  fSizeYZCmd->SetGuidance("Set tranverse size of the calorimeter");
65  fSizeYZCmd->SetParameterName("Size",false);
66  fSizeYZCmd->SetRange("Size>0.");
67  fSizeYZCmd->SetUnitCategory("Length");
70 
71  fNbLayersCmd = new G4UIcmdWithAnInteger("/testem/det/setNbOfLayers",this);
72  fNbLayersCmd->SetGuidance("Set number of layers.");
73  fNbLayersCmd->SetParameterName("NbLayers",false);
74  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");
84 
85  fAbsorCmd = new G4UIcommand("/testem/det/setAbsor",this);
86  fAbsorCmd->SetGuidance("Set the absor nb, the material, the thickness.");
87  fAbsorCmd->SetGuidance(" absor number : from 1 to NbOfAbsor");
88  fAbsorCmd->SetGuidance(" material name");
89  fAbsorCmd->SetGuidance(" thickness (with unit) : t>0.");
90  //
91  G4UIparameter* AbsNbPrm = new G4UIparameter("AbsorNb",'i',false);
92  AbsNbPrm->SetGuidance("absor number : from 1 to NbOfAbsor");
93  AbsNbPrm->SetParameterRange("AbsorNb>0");
94  fAbsorCmd->SetParameter(AbsNbPrm);
95  //
96  G4UIparameter* MatPrm = new G4UIparameter("material",'s',false);
97  MatPrm->SetGuidance("material name");
98  fAbsorCmd->SetParameter(MatPrm);
99  //
100  G4UIparameter* ThickPrm = new G4UIparameter("thickness",'d',false);
101  ThickPrm->SetGuidance("thickness of absorber");
102  ThickPrm->SetParameterRange("thickness>0.");
103  fAbsorCmd->SetParameter(ThickPrm);
104  //
105  G4UIparameter* unitPrm = new G4UIparameter("unit",'s',false);
106  unitPrm->SetGuidance("unit of thickness");
108  unitPrm->SetParameterCandidates(unitList);
109  fAbsorCmd->SetParameter(unitPrm);
110  //
112  fAbsorCmd->SetToBeBroadcasted(false);
113 }
114 
115 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
116 
118 {
119  delete fSizeYZCmd;
120  delete fNbLayersCmd;
121  delete fNbAbsorCmd;
122  delete fAbsorCmd;
123  delete fDetDir;
124  delete fTestemDir;
125 }
126 
127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
128 
130 {
131  if( command == fSizeYZCmd )
133 
134  if( command == fNbLayersCmd )
136 
137  if( command == fNbAbsorCmd )
139 
140  if (command == fAbsorCmd)
141  {
142  G4int num; G4double tick;
143  G4String unt, mat;
144  std::istringstream is(newValue);
145  is >> num >> mat >> tick >> unt;
146  G4String material=mat;
147  tick *= G4UIcommand::ValueOf(unt);
148  Detector->SetAbsorMaterial (num,material);
149  Detector->SetAbsorThickness(num,tick);
150  }
151 }
152 
153 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
G4UIcmdWithAnInteger * fNbLayersCmd
void SetNewValue(G4UIcommand *, G4String)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
G4UIcommand * fAbsorCmd
static G4int GetNewIntValue(const char *paramString)
void SetParameterRange(const char *theRange)
void SetParameterCandidates(const char *theString)
void SetToBeBroadcasted(G4bool val)
Definition: G4UIcommand.hh:184
void SetUnitCategory(const char *unitCategory)
static G4double GetNewDoubleValue(const char *paramString)
int G4int
Definition: G4Types.hh:78
G4UIcmdWithAnInteger * fNbAbsorCmd
DetectorConstruction * Detector
static G4String UnitsList(const char *unitCategory)
Definition: G4UIcommand.cc:320
void SetAbsorMaterial(G4int, const G4String &)
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:239
G4UIdirectory * fDetDir
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:308
G4UIdirectory * fTestemDir
G4UIcmdWithADoubleAndUnit * fSizeYZCmd
DetectorMessenger(DetectorConstruction *)
Detector construction class to demonstrate various ways of placement.
void SetAbsorThickness(G4int, G4double)
double G4double
Definition: G4Types.hh:76
void SetGuidance(const char *theGuidance)
static G4String CategoryOf(const char *unitName)
Definition: G4UIcommand.cc:315
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)