Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // >> 26 // $Id: G4GlobalMagFieldMessenger.cc 66536 2012-12-19 14:32:36Z ihrivnac $ >> 27 // 26 // class G4GlobalMagFieldMessenger 28 // class G4GlobalMagFieldMessenger 27 // 29 // >> 30 // Implementation >> 31 // 28 // Implementation of the G4GlobalMagFieldMesse 32 // Implementation of the G4GlobalMagFieldMessenger class 29 // 33 // 30 // Author: Ivana Hrivnacova, 28/08/2013 (ivan 34 // Author: Ivana Hrivnacova, 28/08/2013 (ivana@ipno.in2p3.fr) 31 // ------------------------------------------- 35 // -------------------------------------------------------------------- 32 36 33 #include "G4GlobalMagFieldMessenger.hh" 37 #include "G4GlobalMagFieldMessenger.hh" 34 #include "G4UniformMagField.hh" 38 #include "G4UniformMagField.hh" 35 #include "G4FieldManager.hh" 39 #include "G4FieldManager.hh" 36 #include "G4TransportationManager.hh" 40 #include "G4TransportationManager.hh" 37 #include "G4UIdirectory.hh" 41 #include "G4UIdirectory.hh" 38 #include "G4UIcmdWith3VectorAndUnit.hh" 42 #include "G4UIcmdWith3VectorAndUnit.hh" 39 #include "G4UIcmdWithAnInteger.hh" 43 #include "G4UIcmdWithAnInteger.hh" 40 #include "G4UnitsTable.hh" 44 #include "G4UnitsTable.hh" 41 #include "G4SystemOfUnits.hh" 45 #include "G4SystemOfUnits.hh" 42 46 43 //____________________________________________ 47 //______________________________________________________________________________ 44 48 45 G4GlobalMagFieldMessenger::G4GlobalMagFieldMes 49 G4GlobalMagFieldMessenger::G4GlobalMagFieldMessenger(const G4ThreeVector& value) >> 50 : G4UImessenger(), >> 51 fMagField(0), >> 52 fVerboseLevel(0), >> 53 fDirectory(0), >> 54 fSetValueCmd(0), >> 55 fSetVerboseCmd(0) 46 { 56 { 47 fDirectory = new G4UIdirectory("/globalField 57 fDirectory = new G4UIdirectory("/globalField/"); 48 fDirectory->SetGuidance("Global uniform magn 58 fDirectory->SetGuidance("Global uniform magnetic field UI commands"); 49 59 50 fSetValueCmd = new G4UIcmdWith3VectorAndUnit 60 fSetValueCmd = new G4UIcmdWith3VectorAndUnit("/globalField/setValue",this); 51 fSetValueCmd->SetGuidance("Set uniform magne 61 fSetValueCmd->SetGuidance("Set uniform magnetic field value."); 52 fSetValueCmd->SetParameterName("Bx", "By", " 62 fSetValueCmd->SetParameterName("Bx", "By", "By", false); 53 fSetValueCmd->SetUnitCategory("Magnetic flux 63 fSetValueCmd->SetUnitCategory("Magnetic flux density"); 54 fSetValueCmd->AvailableForStates(G4State_Pre 64 fSetValueCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 55 65 56 fSetVerboseCmd = new G4UIcmdWithAnInteger("/ 66 fSetVerboseCmd = new G4UIcmdWithAnInteger("/globalField/verbose",this); 57 fSetVerboseCmd->SetGuidance("Set verbose lev 67 fSetVerboseCmd->SetGuidance("Set verbose level: "); 58 fSetVerboseCmd->SetGuidance(" 0: no output" 68 fSetVerboseCmd->SetGuidance(" 0: no output"); 59 fSetVerboseCmd->SetGuidance(" 1: printing n 69 fSetVerboseCmd->SetGuidance(" 1: printing new field value"); 60 fSetVerboseCmd->SetParameterName("globalFiel 70 fSetVerboseCmd->SetParameterName("globalFieldVerbose", false); 61 fSetVerboseCmd->SetRange("globalFieldVerbose 71 fSetVerboseCmd->SetRange("globalFieldVerbose>=0"); 62 fSetVerboseCmd->AvailableForStates(G4State_P 72 fSetVerboseCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 63 73 64 // Create field 74 // Create field 65 fMagField = new G4UniformMagField(value); 75 fMagField = new G4UniformMagField(value); 66 76 67 // Set field value (the field is not activat 77 // Set field value (the field is not activated if value is zero) 68 SetField(value, "G4GlobalMagFieldMessenger:: 78 SetField(value, "G4GlobalMagFieldMessenger::G4GlobalMagFieldMessenger"); 69 } 79 } 70 80 71 //____________________________________________ 81 //______________________________________________________________________________ 72 82 73 G4GlobalMagFieldMessenger::~G4GlobalMagFieldMe 83 G4GlobalMagFieldMessenger::~G4GlobalMagFieldMessenger() 74 { 84 { 75 delete fMagField; 85 delete fMagField; 76 delete fSetValueCmd; 86 delete fSetValueCmd; 77 delete fSetVerboseCmd; 87 delete fSetVerboseCmd; 78 delete fDirectory; 88 delete fDirectory; 79 } 89 } 80 90 81 //____________________________________________ 91 //______________________________________________________________________________ 82 92 83 void G4GlobalMagFieldMessenger::SetField(const 93 void G4GlobalMagFieldMessenger::SetField(const G4ThreeVector& value, 84 const 94 const G4String& /*inFunction*/) 85 { 95 { 86 // Get field manager (or create it if it doe 96 // Get field manager (or create it if it does not yet exist) 87 G4FieldManager* fieldManager 97 G4FieldManager* fieldManager 88 = G4TransportationManager::GetTransportati 98 = G4TransportationManager::GetTransportationManager()->GetFieldManager(); 89 99 90 // Inactivate field if its value is zero 100 // Inactivate field if its value is zero 91 if ( value == G4ThreeVector() ) 101 if ( value == G4ThreeVector() ) 92 { 102 { 93 fieldManager->SetDetectorField(nullptr); << 103 fieldManager->SetDetectorField(0); 94 fieldManager->CreateChordFinder(nullptr); << 104 fieldManager->CreateChordFinder(0); 95 105 96 if ( fVerboseLevel > 0 ) 106 if ( fVerboseLevel > 0 ) 97 { 107 { 98 G4cout << "Magnetic field is inactive, f 108 G4cout << "Magnetic field is inactive, fieldValue = (0,0,0)." << G4endl; 99 } 109 } 100 } 110 } 101 else 111 else 102 { 112 { 103 fMagField->SetFieldValue(value); 113 fMagField->SetFieldValue(value); 104 fieldManager->SetDetectorField(fMagField); 114 fieldManager->SetDetectorField(fMagField); 105 fieldManager->CreateChordFinder(fMagField) 115 fieldManager->CreateChordFinder(fMagField); 106 116 107 if ( fVerboseLevel > 0 ) 117 if ( fVerboseLevel > 0 ) 108 { 118 { 109 G4cout << "Magnetic field is active, fie 119 G4cout << "Magnetic field is active, fieldValue = (" 110 << G4BestUnit(value, "Magnetic fl 120 << G4BestUnit(value, "Magnetic flux density") 111 << ")." << G4endl; 121 << ")." << G4endl; 112 } 122 } 113 } 123 } 114 } 124 } 115 125 116 //____________________________________________ 126 //______________________________________________________________________________ 117 127 118 void G4GlobalMagFieldMessenger::SetNewValue(G4 128 void G4GlobalMagFieldMessenger::SetNewValue(G4UIcommand* command, G4String newValue) 119 { 129 { 120 if ( command == fSetValueCmd ) 130 if ( command == fSetValueCmd ) 121 { 131 { 122 SetField(fSetValueCmd->GetNew3VectorValue( 132 SetField(fSetValueCmd->GetNew3VectorValue(newValue), 123 "G4GlobalMagFieldMessenger::SetNe 133 "G4GlobalMagFieldMessenger::SetNewValue"); 124 } 134 } 125 else if ( command == fSetVerboseCmd ) 135 else if ( command == fSetVerboseCmd ) 126 { 136 { 127 SetVerboseLevel(fSetVerboseCmd->GetNewIntV 137 SetVerboseLevel(fSetVerboseCmd->GetNewIntValue(newValue)); 128 } 138 } 129 } 139 } 130 140 131 //____________________________________________ 141 //______________________________________________________________________________ 132 142 133 void G4GlobalMagFieldMessenger::SetFieldValue( 143 void G4GlobalMagFieldMessenger::SetFieldValue(const G4ThreeVector& value) 134 { 144 { 135 SetField(value, "G4GlobalMagFieldMessenger:: 145 SetField(value, "G4GlobalMagFieldMessenger::SetFieldValue"); 136 } 146 } 137 147 138 //____________________________________________ 148 //______________________________________________________________________________ 139 149 140 G4ThreeVector G4GlobalMagFieldMessenger::GetFi 150 G4ThreeVector G4GlobalMagFieldMessenger::GetFieldValue() const 141 { 151 { 142 if ( fMagField != nullptr ) { return fMagFie << 152 if ( fMagField ) return fMagField->GetConstantFieldValue(); 143 153 144 return {}; << 154 return G4ThreeVector(); 145 } 155 } 146 156