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 // Geant4 Class file 27 // 28 // File name: G4PolarizationManager 29 // 30 // Author: Andreas Schaelicke 31 // 32 // Class Description: 33 // Provides access to general polarization information and to 34 // polarization for logical volumes through macro files. 35 36 #include "G4PolarizationMessenger.hh" 37 38 #include "G4ios.hh" 39 #include "G4PolarizationManager.hh" 40 #include "G4PolarizationHelper.hh" 41 #include "G4Tokenizer.hh" 42 #include "G4UIcmdWithABool.hh" 43 #include "G4UIcmdWithAnInteger.hh" 44 #include "G4UIcmdWithAString.hh" 45 #include "G4UIcmdWithoutParameter.hh" 46 #include "G4UIdirectory.hh" 47 48 G4PolarizationMessenger::G4PolarizationMessenger(G4PolarizationManager* polMgr) 49 : polarizationManager(polMgr) 50 { 51 polarizationDirectory = new G4UIdirectory("/polarization/"); 52 polarizationDirectory->SetGuidance("polarization control commands."); 53 54 managerDirectory = new G4UIdirectory("/polarization/manager/"); 55 managerDirectory->SetGuidance("general polarization information."); 56 57 verboseCmd = new G4UIcmdWithAnInteger("/polarization/manager/verbose", this); 58 verboseCmd->SetGuidance("Set the Verbose level of G4PolarizationManager."); 59 verboseCmd->SetGuidance(" 0 : Silent (default)"); 60 verboseCmd->SetGuidance(" 1 : Verbose"); 61 verboseCmd->SetParameterName("level", true); 62 verboseCmd->SetDefaultValue(0); 63 verboseCmd->SetRange("level >=0 && level <=1"); 64 65 optActivateCmd = new G4UIcmdWithABool("/polarization/manager/activate", this); 66 optActivateCmd->SetGuidance("activate/deactivate polarization treatment"); 67 optActivateCmd->SetParameterName("flag", true); 68 optActivateCmd->SetDefaultValue(true); 69 70 volumeDirectory = new G4UIdirectory("/polarization/volume/"); 71 volumeDirectory->SetGuidance( 72 "Status control commands of registered polarized logical volumes."); 73 74 printVolumeListCmd = 75 new G4UIcmdWithoutParameter("/polarization/volume/list", this); 76 printVolumeListCmd->SetGuidance( 77 "print list of registered polarized logical volumes"); 78 printVolumeListCmd->AvailableForStates(G4State_PreInit, G4State_Idle, 79 G4State_GeomClosed); 80 81 setPolarizationCmd = new G4UIcommand("/polarization/volume/set", this); 82 setPolarizationCmd->SetGuidance( 83 "set or change polarization of a logical volume"); 84 setPolarizationCmd->AvailableForStates(G4State_PreInit, G4State_Idle, 85 G4State_GeomClosed); 86 87 G4UIparameter* param; 88 param = new G4UIparameter("logicalVolumeName", 's', false); 89 param->SetDefaultValue("worldVolume"); 90 setPolarizationCmd->SetParameter(param); 91 param = new G4UIparameter("px", 'd', true); 92 param->SetDefaultValue("0.0"); 93 setPolarizationCmd->SetParameter(param); 94 param = new G4UIparameter("py", 'd', true); 95 param->SetDefaultValue("0.0"); 96 setPolarizationCmd->SetParameter(param); 97 param = new G4UIparameter("pz", 'd', true); 98 param->SetDefaultValue("0.0"); 99 setPolarizationCmd->SetParameter(param); 100 101 testDirectory = new G4UIdirectory("/polarization/test/"); 102 testDirectory->SetGuidance("provides access to some internal test routines."); 103 104 testPolarizationTransformationCmd = new G4UIcmdWithoutParameter( 105 "/polarization/test/polarizationTransformation", this); 106 testPolarizationTransformationCmd->SetGuidance( 107 "checks definition of particle reference frame and corresponding " 108 "translation routines"); 109 testPolarizationTransformationCmd->AvailableForStates( 110 G4State_PreInit, G4State_Idle, G4State_GeomClosed); 111 112 testInteractionFrameCmd = 113 new G4UIcmdWithoutParameter("/polarization/test/interactionFrame", this); 114 testInteractionFrameCmd->SetGuidance( 115 "checks definition of interaction frame"); 116 testInteractionFrameCmd->AvailableForStates(G4State_PreInit, G4State_Idle, 117 G4State_GeomClosed); 118 } 119 120 G4PolarizationMessenger::~G4PolarizationMessenger() 121 { 122 delete verboseCmd; 123 delete testInteractionFrameCmd; 124 delete testPolarizationTransformationCmd; 125 delete testDirectory; 126 delete setPolarizationCmd; 127 delete printVolumeListCmd; 128 delete volumeDirectory; 129 delete optActivateCmd; 130 delete managerDirectory; 131 delete polarizationDirectory; 132 } 133 134 void G4PolarizationMessenger::SetNewValue(G4UIcommand* command, 135 G4String newValue) 136 { 137 if(command == verboseCmd) 138 { 139 polarizationManager->SetVerbose(verboseCmd->GetNewIntValue(newValue)); 140 } 141 else if(command == optActivateCmd) 142 { 143 polarizationManager->SetActivated( 144 optActivateCmd->GetNewBoolValue(newValue)); 145 } 146 else if(command == printVolumeListCmd) 147 { 148 polarizationManager->ListVolumes(); 149 } 150 else if(command == setPolarizationCmd) 151 { 152 G4Tokenizer next(newValue); 153 G4String volumeName = next(); 154 G4double px = 0., py = 0., pz = 0.; 155 G4String dvalue = next(); 156 if(!dvalue.empty()) 157 { 158 px = StoD(dvalue); 159 dvalue = next(); 160 if(!dvalue.empty()) 161 { 162 py = StoD(dvalue); 163 dvalue = next(); 164 if(!dvalue.empty()) 165 pz = StoD(dvalue); 166 } 167 } 168 G4ThreeVector pol(px, py, pz); 169 polarizationManager->SetVolumePolarization(volumeName, pol); 170 } 171 else if(command == testPolarizationTransformationCmd) 172 { 173 G4PolarizationHelper::TestPolarizationTransformations(); 174 } 175 else if(command == testInteractionFrameCmd) 176 { 177 G4PolarizationHelper::TestInteractionFrame(); 178 } 179 } 180 181 G4String G4PolarizationMessenger::GetCurrentValue(G4UIcommand* command) 182 { 183 G4String cv; 184 if(command == verboseCmd) 185 { 186 cv = verboseCmd->ConvertToString(polarizationManager->GetVerbose()); 187 } 188 189 return cv; 190 } 191