Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
A01PrimaryGeneratorMessenger.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$
30 // --------------------------------------------------------------
31 //
35 #include "G4UIcmdWithABool.hh"
36 #include "G4ios.hh"
37 
39 :fTarget(mpga)
40 {
41  fMomentumCmd = new G4UIcmdWithADoubleAndUnit("/mydet/momentum",this);
42  fMomentumCmd->SetGuidance("Mean momentum of primaries");
43  fMomentumCmd->SetParameterName("p",true);
44  fMomentumCmd->SetRange("p>=0.");
45  fMomentumCmd->SetDefaultValue(1.);
46  fMomentumCmd->SetDefaultUnit("GeV");
47 
48  fSigmaMomCmd = new G4UIcmdWithADoubleAndUnit("/mydet/sigmaMomentum",this);
49  fSigmaMomCmd->SetGuidance("Sigma momentum of primaries");
50  fSigmaMomCmd->SetParameterName("p",true);
51  fSigmaMomCmd->SetRange("p>=0.");
52  fSigmaMomCmd->SetDefaultValue(1.);
53  fSigmaMomCmd->SetDefaultUnit("GeV");
54 
55  fSigmaAngCmd = new G4UIcmdWithADoubleAndUnit("/mydet/sigmaAngle",this);
56  fSigmaAngCmd->SetGuidance("sigma angle divergence of primaries");
57  fSigmaAngCmd->SetParameterName("t",true);
58  fSigmaAngCmd->SetRange("t>=0.");
59  fSigmaAngCmd->SetDefaultValue(1.);
60  fSigmaAngCmd->SetDefaultUnit("deg");
61 
62  fRandomCmd = new G4UIcmdWithABool("/mydet/randomizePrimary",this);
63  fRandomCmd->SetGuidance("Boolean flag for randomizing primary particle types.");
64  fRandomCmd->SetGuidance("In case this flag is false, you can select the primary particle");
65  fRandomCmd->SetGuidance(" with /gun/particle command.");
66  fRandomCmd->SetParameterName("flg",true);
67  fRandomCmd->SetDefaultValue(true);
68 }
69 
71 {
72  delete fMomentumCmd;
73  delete fSigmaMomCmd;
74  delete fSigmaAngCmd;
75  delete fRandomCmd;
76 }
77 
79 {
80  if( command==fMomentumCmd )
81  { fTarget->SetMomentum(fMomentumCmd->GetNewDoubleValue(newValue)); }
82  if( command==fSigmaMomCmd )
83  { fTarget->SetSigmaMomentum(fSigmaMomCmd->GetNewDoubleValue(newValue)); }
84  if( command==fSigmaAngCmd )
85  { fTarget->SetSigmaAngle(fSigmaAngCmd->GetNewDoubleValue(newValue)); }
86  if( command==fRandomCmd )
87  { fTarget->SetRandomize(fRandomCmd->GetNewBoolValue(newValue)); }
88 }
89 
91 {
92  G4String cv;
93  if( command==fMomentumCmd )
94  { cv = fMomentumCmd->ConvertToString(fTarget->GetMomentum(),"GeV"); }
95  if( command==fSigmaMomCmd )
96  { cv = fSigmaMomCmd->ConvertToString(fTarget->GetSigmaMomentum(),"GeV"); }
97  if( command==fSigmaAngCmd )
98  { cv = fSigmaAngCmd->ConvertToString(fTarget->GetSigmaAngle(),"deg"); }
99  if( command==fRandomCmd )
100  { cv = fRandomCmd->ConvertToString(fTarget->GetRandomize()); }
101 
102  return cv;
103 }
104