Geant4 Cross Reference |
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 #include "PrimaryGeneratorMessenger.hh" 27 #include "PrimaryGeneratorAction.hh" 28 29 #include "G4UIcmdWithABool.hh" 30 #include "G4UIcmdWithADouble.hh" 31 #include "G4UIcmdWithADoubleAndUnit.hh" 32 #include "G4UIcmdWithAString.hh" 33 #include "G4UIcmdWithAnInteger.hh" 34 #include "G4UIdirectory.hh" 35 36 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 37 38 PrimaryGeneratorMessenger::PrimaryGeneratorMessenger( 39 PrimaryGeneratorAction *aPrimaryGeneratorAction) 40 : fPrimaryGenerator(aPrimaryGeneratorAction) { 41 fDirectory = new G4UIdirectory("/HGCalTestbeam/generator/"); 42 fDirectory->SetGuidance("Primary generator control commands."); 43 44 #ifdef WITHROOT 45 fReadInputCmd = 46 new G4UIcmdWithABool("/HGCalTestbeam/generator/readInputFile", this); 47 fReadInputCmd->SetGuidance( 48 "If instead of particle gun, particle data should be read from file."); 49 fReadInputCmd->SetParameterName("ifInput", true); 50 fReadInputCmd->SetDefaultValue(false); 51 52 fPathInputCmd = 53 new G4UIcmdWithAString("/HGCalTestbeam/generator/pathInputFile", this); 54 fPathInputCmd->SetGuidance("Path to input file containing particle data."); 55 fPathInputCmd->SetParameterName("path", true); 56 57 fStartFromEventCmd = 58 new G4UIcmdWithAnInteger("/HGCalTestbeam/generator/startFromEvent", this); 59 fStartFromEventCmd->SetGuidance( 60 "From which event in the file HGCalTestbeam should be started."); 61 fStartFromEventCmd->SetParameterName("startFrom", true); 62 fStartFromEventCmd->SetDefaultValue(0); 63 #endif 64 fMomentumSpreadCmd = 65 new G4UIcmdWithADouble("/HGCalTestbeam/generator/momentumSpread", this); 66 fMomentumSpreadCmd->SetGuidance("For particle gun generator:"); 67 fMomentumSpreadCmd->SetGuidance( 68 "Gaussian momentum spread relative to gun energy"); 69 fMomentumSpreadCmd->SetGuidance("(e.g. 0.05 means 5% * gun energy))"); 70 fMomentumSpreadCmd->SetParameterName("momentumSpread", true); 71 fMomentumSpreadCmd->SetRange("momentumSpread>=0"); 72 fMomentumSpreadCmd->SetDefaultValue(0); 73 74 fBeamSpreadTypeCmd = 75 new G4UIcmdWithAString("/HGCalTestbeam/generator/beamSpread", this); 76 fBeamSpreadTypeCmd->SetGuidance("Type of beam profile spread."); 77 fBeamSpreadTypeCmd->SetParameterName("beamSpreadType", true); 78 fBeamSpreadTypeCmd->SetCandidates("none Gaussian flat"); 79 fBeamSpreadTypeCmd->SetDefaultValue("none"); 80 81 fBeamSpreadXCmd = new G4UIcmdWithADoubleAndUnit( 82 "/HGCalTestbeam/generator/beamSpreadX", this); 83 fBeamSpreadXCmd->SetGuidance("Defines sigma_X for Gaussian spread, or " 84 "half-side range for flat spread."); 85 fBeamSpreadXCmd->SetParameterName("sigmaBeamX", true, true); 86 fBeamSpreadXCmd->SetRange("sigmaBeamX>=0"); 87 fBeamSpreadXCmd->SetDefaultUnit("cm"); 88 fBeamSpreadXCmd->SetUnitCandidates("micron mm cm m km"); 89 90 fBeamSpreadYCmd = new G4UIcmdWithADoubleAndUnit( 91 "/HGCalTestbeam/generator/beamSpreadY", this); 92 fBeamSpreadYCmd->SetGuidance("Defines sigma_Y for Gaussian spread, or " 93 "half-side range for flat spread."); 94 fBeamSpreadYCmd->SetParameterName("sigmaBeamY", true, true); 95 fBeamSpreadYCmd->SetRange("sigmaBeamY>=0"); 96 fBeamSpreadYCmd->SetDefaultUnit("cm"); 97 fBeamSpreadYCmd->SetUnitCandidates("micron mm cm m km"); 98 99 fBeamZ0Cmd = 100 new G4UIcmdWithADoubleAndUnit("/HGCalTestbeam/generator/beamZ0", this); 101 fBeamZ0Cmd->SetGuidance( 102 "Beam position along the beam line (default: edge of the world volume)."); 103 fBeamZ0Cmd->SetParameterName("z0", true, true); 104 fBeamZ0Cmd->SetDefaultUnit("cm"); 105 fBeamZ0Cmd->SetUnitCandidates("micron mm cm m km"); 106 } 107 108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 109 110 PrimaryGeneratorMessenger::~PrimaryGeneratorMessenger() { 111 delete fDirectory; 112 #ifdef WITHROOT 113 delete fReadInputCmd; 114 delete fPathInputCmd; 115 delete fStartFromEventCmd; 116 #endif 117 delete fMomentumSpreadCmd; 118 delete fBeamSpreadTypeCmd; 119 delete fBeamSpreadXCmd; 120 delete fBeamSpreadYCmd; 121 delete fBeamZ0Cmd; 122 } 123 124 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 125 126 void PrimaryGeneratorMessenger::SetNewValue(G4UIcommand *command, 127 G4String newValues) { 128 if (command == fMomentumSpreadCmd) { 129 fPrimaryGenerator->SetMomentumSpread( 130 fMomentumSpreadCmd->GetNewDoubleValue(newValues)); 131 } else if (command == fBeamSpreadTypeCmd) { 132 fPrimaryGenerator->SetBeamSpreadType(newValues); 133 } else if (command == fBeamSpreadXCmd) { 134 fPrimaryGenerator->SetBeamSpreadX( 135 fBeamSpreadXCmd->GetNewDoubleValue(newValues)); 136 } else if (command == fBeamSpreadYCmd) { 137 fPrimaryGenerator->SetBeamSpreadY( 138 fBeamSpreadYCmd->GetNewDoubleValue(newValues)); 139 } else if (command == fBeamZ0Cmd) { 140 fPrimaryGenerator->SetBeamZ0(fBeamZ0Cmd->GetNewDoubleValue(newValues)); 141 } 142 #ifdef WITHROOT 143 else if (command == fReadInputCmd) { 144 fPrimaryGenerator->SetIfUseInputFiles( 145 fReadInputCmd->GetNewBoolValue(newValues)); 146 } else if (command == fPathInputCmd) { 147 fPrimaryGenerator->SetInputFiles(newValues); 148 } else if (command == fStartFromEventCmd) { 149 fPrimaryGenerator->SetStartFromEvent( 150 fStartFromEventCmd->GetNewIntValue(newValues)); 151 } 152 #endif 153 } 154 155 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 156 157 G4String PrimaryGeneratorMessenger::GetCurrentValue(G4UIcommand *command) { 158 G4String cv; 159 if (command == fMomentumSpreadCmd) { 160 cv = fMomentumSpreadCmd->ConvertToString( 161 fPrimaryGenerator->GetMomentumSpread()); 162 } else if (command == fBeamSpreadTypeCmd) { 163 cv = fPrimaryGenerator->GetBeamSpreadType(); 164 } else if (command == fBeamSpreadXCmd) { 165 cv = fBeamSpreadXCmd->ConvertToString(fPrimaryGenerator->GetBeamSpreadX()); 166 } else if (command == fBeamSpreadYCmd) { 167 cv = fBeamSpreadYCmd->ConvertToString(fPrimaryGenerator->GetBeamSpreadY()); 168 } else if (command == fBeamZ0Cmd) { 169 cv = fBeamZ0Cmd->ConvertToString(fPrimaryGenerator->GetBeamZ0()); 170 } 171 #ifdef WITHROOT 172 else if (command == fReadInputCmd) { 173 cv = 174 fReadInputCmd->ConvertToString(fPrimaryGenerator->GetIfUseInputFiles()); 175 } else if (command == fPathInputCmd) { 176 cv = fPrimaryGenerator->GetInputFiles(); 177 } 178 #endif 179 return cv; 180 } 181