File indexing completed on 2025-01-31 09:22:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 #include "PrimaryGeneratorMessenger.hh"
0027 #include "PrimaryGeneratorAction.hh"
0028
0029 #include "G4UIcmdWithABool.hh"
0030 #include "G4UIcmdWithADouble.hh"
0031 #include "G4UIcmdWithADoubleAndUnit.hh"
0032 #include "G4UIcmdWithAString.hh"
0033 #include "G4UIcmdWithAnInteger.hh"
0034 #include "G4UIdirectory.hh"
0035
0036
0037
0038 PrimaryGeneratorMessenger::PrimaryGeneratorMessenger(
0039 PrimaryGeneratorAction *aPrimaryGeneratorAction)
0040 : fPrimaryGenerator(aPrimaryGeneratorAction) {
0041 fDirectory = new G4UIdirectory("/HGCalTestbeam/generator/");
0042 fDirectory->SetGuidance("Primary generator control commands.");
0043
0044 #ifdef WITHROOT
0045 fReadInputCmd =
0046 new G4UIcmdWithABool("/HGCalTestbeam/generator/readInputFile", this);
0047 fReadInputCmd->SetGuidance(
0048 "If instead of particle gun, particle data should be read from file.");
0049 fReadInputCmd->SetParameterName("ifInput", true);
0050 fReadInputCmd->SetDefaultValue(false);
0051
0052 fPathInputCmd =
0053 new G4UIcmdWithAString("/HGCalTestbeam/generator/pathInputFile", this);
0054 fPathInputCmd->SetGuidance("Path to input file containing particle data.");
0055 fPathInputCmd->SetParameterName("path", true);
0056
0057 fStartFromEventCmd =
0058 new G4UIcmdWithAnInteger("/HGCalTestbeam/generator/startFromEvent", this);
0059 fStartFromEventCmd->SetGuidance(
0060 "From which event in the file HGCalTestbeam should be started.");
0061 fStartFromEventCmd->SetParameterName("startFrom", true);
0062 fStartFromEventCmd->SetDefaultValue(0);
0063 #endif
0064 fMomentumSpreadCmd =
0065 new G4UIcmdWithADouble("/HGCalTestbeam/generator/momentumSpread", this);
0066 fMomentumSpreadCmd->SetGuidance("For particle gun generator:");
0067 fMomentumSpreadCmd->SetGuidance(
0068 "Gaussian momentum spread relative to gun energy");
0069 fMomentumSpreadCmd->SetGuidance("(e.g. 0.05 means 5% * gun energy))");
0070 fMomentumSpreadCmd->SetParameterName("momentumSpread", true);
0071 fMomentumSpreadCmd->SetRange("momentumSpread>=0");
0072 fMomentumSpreadCmd->SetDefaultValue(0);
0073
0074 fBeamSpreadTypeCmd =
0075 new G4UIcmdWithAString("/HGCalTestbeam/generator/beamSpread", this);
0076 fBeamSpreadTypeCmd->SetGuidance("Type of beam profile spread.");
0077 fBeamSpreadTypeCmd->SetParameterName("beamSpreadType", true);
0078 fBeamSpreadTypeCmd->SetCandidates("none Gaussian flat");
0079 fBeamSpreadTypeCmd->SetDefaultValue("none");
0080
0081 fBeamSpreadXCmd = new G4UIcmdWithADoubleAndUnit(
0082 "/HGCalTestbeam/generator/beamSpreadX", this);
0083 fBeamSpreadXCmd->SetGuidance("Defines sigma_X for Gaussian spread, or "
0084 "half-side range for flat spread.");
0085 fBeamSpreadXCmd->SetParameterName("sigmaBeamX", true, true);
0086 fBeamSpreadXCmd->SetRange("sigmaBeamX>=0");
0087 fBeamSpreadXCmd->SetDefaultUnit("cm");
0088 fBeamSpreadXCmd->SetUnitCandidates("micron mm cm m km");
0089
0090 fBeamSpreadYCmd = new G4UIcmdWithADoubleAndUnit(
0091 "/HGCalTestbeam/generator/beamSpreadY", this);
0092 fBeamSpreadYCmd->SetGuidance("Defines sigma_Y for Gaussian spread, or "
0093 "half-side range for flat spread.");
0094 fBeamSpreadYCmd->SetParameterName("sigmaBeamY", true, true);
0095 fBeamSpreadYCmd->SetRange("sigmaBeamY>=0");
0096 fBeamSpreadYCmd->SetDefaultUnit("cm");
0097 fBeamSpreadYCmd->SetUnitCandidates("micron mm cm m km");
0098
0099 fBeamZ0Cmd =
0100 new G4UIcmdWithADoubleAndUnit("/HGCalTestbeam/generator/beamZ0", this);
0101 fBeamZ0Cmd->SetGuidance(
0102 "Beam position along the beam line (default: edge of the world volume).");
0103 fBeamZ0Cmd->SetParameterName("z0", true, true);
0104 fBeamZ0Cmd->SetDefaultUnit("cm");
0105 fBeamZ0Cmd->SetUnitCandidates("micron mm cm m km");
0106 }
0107
0108
0109
0110 PrimaryGeneratorMessenger::~PrimaryGeneratorMessenger() {
0111 delete fDirectory;
0112 #ifdef WITHROOT
0113 delete fReadInputCmd;
0114 delete fPathInputCmd;
0115 delete fStartFromEventCmd;
0116 #endif
0117 delete fMomentumSpreadCmd;
0118 delete fBeamSpreadTypeCmd;
0119 delete fBeamSpreadXCmd;
0120 delete fBeamSpreadYCmd;
0121 delete fBeamZ0Cmd;
0122 }
0123
0124
0125
0126 void PrimaryGeneratorMessenger::SetNewValue(G4UIcommand *command,
0127 G4String newValues) {
0128 if (command == fMomentumSpreadCmd) {
0129 fPrimaryGenerator->SetMomentumSpread(
0130 fMomentumSpreadCmd->GetNewDoubleValue(newValues));
0131 } else if (command == fBeamSpreadTypeCmd) {
0132 fPrimaryGenerator->SetBeamSpreadType(newValues);
0133 } else if (command == fBeamSpreadXCmd) {
0134 fPrimaryGenerator->SetBeamSpreadX(
0135 fBeamSpreadXCmd->GetNewDoubleValue(newValues));
0136 } else if (command == fBeamSpreadYCmd) {
0137 fPrimaryGenerator->SetBeamSpreadY(
0138 fBeamSpreadYCmd->GetNewDoubleValue(newValues));
0139 } else if (command == fBeamZ0Cmd) {
0140 fPrimaryGenerator->SetBeamZ0(fBeamZ0Cmd->GetNewDoubleValue(newValues));
0141 }
0142 #ifdef WITHROOT
0143 else if (command == fReadInputCmd) {
0144 fPrimaryGenerator->SetIfUseInputFiles(
0145 fReadInputCmd->GetNewBoolValue(newValues));
0146 } else if (command == fPathInputCmd) {
0147 fPrimaryGenerator->SetInputFiles(newValues);
0148 } else if (command == fStartFromEventCmd) {
0149 fPrimaryGenerator->SetStartFromEvent(
0150 fStartFromEventCmd->GetNewIntValue(newValues));
0151 }
0152 #endif
0153 }
0154
0155
0156
0157 G4String PrimaryGeneratorMessenger::GetCurrentValue(G4UIcommand *command) {
0158 G4String cv;
0159 if (command == fMomentumSpreadCmd) {
0160 cv = fMomentumSpreadCmd->ConvertToString(
0161 fPrimaryGenerator->GetMomentumSpread());
0162 } else if (command == fBeamSpreadTypeCmd) {
0163 cv = fPrimaryGenerator->GetBeamSpreadType();
0164 } else if (command == fBeamSpreadXCmd) {
0165 cv = fBeamSpreadXCmd->ConvertToString(fPrimaryGenerator->GetBeamSpreadX());
0166 } else if (command == fBeamSpreadYCmd) {
0167 cv = fBeamSpreadYCmd->ConvertToString(fPrimaryGenerator->GetBeamSpreadY());
0168 } else if (command == fBeamZ0Cmd) {
0169 cv = fBeamZ0Cmd->ConvertToString(fPrimaryGenerator->GetBeamZ0());
0170 }
0171 #ifdef WITHROOT
0172 else if (command == fReadInputCmd) {
0173 cv =
0174 fReadInputCmd->ConvertToString(fPrimaryGenerator->GetIfUseInputFiles());
0175 } else if (command == fPathInputCmd) {
0176 cv = fPrimaryGenerator->GetInputFiles();
0177 }
0178 #endif
0179 return cv;
0180 }