source: trunk/examples/extended/analysis/A01/src/A01PrimaryGeneratorMessenger.cc @ 807

Last change on this file since 807 was 807, checked in by garnier, 16 years ago

update

File size: 4.4 KB
Line 
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: A01PrimaryGeneratorMessenger.cc,v 1.4 2006/06/29 16:33:07 gunter Exp $
27// --------------------------------------------------------------
28//
29#include "A01PrimaryGeneratorMessenger.hh"
30#include "A01PrimaryGeneratorAction.hh"
31#include "G4UIcmdWithADoubleAndUnit.hh"
32#include "G4UIcmdWithABool.hh"
33#include "G4ios.hh"
34
35A01PrimaryGeneratorMessenger::A01PrimaryGeneratorMessenger(A01PrimaryGeneratorAction * mpga)
36:target(mpga)
37{
38  momentumCmd = new G4UIcmdWithADoubleAndUnit("/mydet/momentum",this);
39  momentumCmd->SetGuidance("Mean momentum of primaries");
40  momentumCmd->SetParameterName("p",true);
41  momentumCmd->SetRange("p>=0.");
42  momentumCmd->SetDefaultValue(1.);
43  momentumCmd->SetDefaultUnit("GeV");
44
45  sigmaMomCmd = new G4UIcmdWithADoubleAndUnit("/mydet/sigmaMomentum",this);
46  sigmaMomCmd->SetGuidance("Sigma momentum of primaries");
47  sigmaMomCmd->SetParameterName("p",true);
48  sigmaMomCmd->SetRange("p>=0.");
49  sigmaMomCmd->SetDefaultValue(1.);
50  sigmaMomCmd->SetDefaultUnit("GeV");
51
52  sigmaAngCmd = new G4UIcmdWithADoubleAndUnit("/mydet/sigmaAngle",this);
53  sigmaAngCmd->SetGuidance("sigma angle divergence of primaries");
54  sigmaAngCmd->SetParameterName("t",true);
55  sigmaAngCmd->SetRange("t>=0.");
56  sigmaAngCmd->SetDefaultValue(1.);
57  sigmaAngCmd->SetDefaultUnit("deg");
58
59  randomCmd = new G4UIcmdWithABool("/mydet/randomizePrimary",this);
60  randomCmd->SetGuidance("Boolean flag for randomizing primary particle types.");
61  randomCmd->SetGuidance("In case this flag is false, you can select the primary particle");
62  randomCmd->SetGuidance("  with /gun/particle command.");
63  randomCmd->SetParameterName("flg",true);
64  randomCmd->SetDefaultValue(true);
65}
66
67A01PrimaryGeneratorMessenger::~A01PrimaryGeneratorMessenger()
68{
69  delete momentumCmd;
70  delete sigmaMomCmd;
71  delete sigmaAngCmd;
72  delete randomCmd;
73}
74
75void A01PrimaryGeneratorMessenger::SetNewValue(G4UIcommand * command,G4String newValue)
76{
77  if( command==momentumCmd )
78  { target->SetMomentum(momentumCmd->GetNewDoubleValue(newValue)); }
79  if( command==sigmaMomCmd )
80  { target->SetSigmaMomentum(sigmaMomCmd->GetNewDoubleValue(newValue)); }
81  if( command==sigmaAngCmd )
82  { target->SetSigmaAngle(sigmaAngCmd->GetNewDoubleValue(newValue)); }
83  if( command==randomCmd )
84  { target->SetRandomize(randomCmd->GetNewBoolValue(newValue)); }
85}
86
87G4String A01PrimaryGeneratorMessenger::GetCurrentValue(G4UIcommand * command)
88{
89  G4String cv;
90  if( command==momentumCmd )
91  { cv = momentumCmd->ConvertToString(target->GetMomentum(),"GeV"); }
92  if( command==sigmaMomCmd )
93  { cv = sigmaMomCmd->ConvertToString(target->GetSigmaMomentum(),"GeV"); }
94  if( command==sigmaAngCmd )
95  { cv = sigmaAngCmd->ConvertToString(target->GetSigmaAngle(),"deg"); }
96  if( command==randomCmd )
97  { cv = randomCmd->ConvertToString(target->GetRandomize()); }
98
99  return cv;
100}
101
Note: See TracBrowser for help on using the repository browser.