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 // 26 // class G4GlobalMagFieldMessenger 27 // class G4GlobalMagFieldMessenger 27 // 28 // >> 29 // Implementation >> 30 // 28 // Implementation of the G4GlobalMagFieldMesse 31 // Implementation of the G4GlobalMagFieldMessenger class 29 // 32 // 30 // Author: Ivana Hrivnacova, 28/08/2013 (ivan 33 // Author: Ivana Hrivnacova, 28/08/2013 (ivana@ipno.in2p3.fr) 31 // ------------------------------------------- 34 // -------------------------------------------------------------------- 32 35 33 #include "G4GlobalMagFieldMessenger.hh" 36 #include "G4GlobalMagFieldMessenger.hh" 34 #include "G4UniformMagField.hh" 37 #include "G4UniformMagField.hh" 35 #include "G4FieldManager.hh" 38 #include "G4FieldManager.hh" 36 #include "G4TransportationManager.hh" 39 #include "G4TransportationManager.hh" 37 #include "G4UIdirectory.hh" 40 #include "G4UIdirectory.hh" 38 #include "G4UIcmdWith3VectorAndUnit.hh" 41 #include "G4UIcmdWith3VectorAndUnit.hh" 39 #include "G4UIcmdWithAnInteger.hh" 42 #include "G4UIcmdWithAnInteger.hh" 40 #include "G4UnitsTable.hh" 43 #include "G4UnitsTable.hh" 41 #include "G4SystemOfUnits.hh" 44 #include "G4SystemOfUnits.hh" 42 45 43 //____________________________________________ 46 //______________________________________________________________________________ 44 47 45 G4GlobalMagFieldMessenger::G4GlobalMagFieldMes 48 G4GlobalMagFieldMessenger::G4GlobalMagFieldMessenger(const G4ThreeVector& value) >> 49 : G4UImessenger(), >> 50 fMagField(0), >> 51 fVerboseLevel(0), >> 52 fDirectory(0), >> 53 fSetValueCmd(0), >> 54 fSetVerboseCmd(0) 46 { 55 { 47 fDirectory = new G4UIdirectory("/globalField 56 fDirectory = new G4UIdirectory("/globalField/"); 48 fDirectory->SetGuidance("Global uniform magn 57 fDirectory->SetGuidance("Global uniform magnetic field UI commands"); 49 58 50 fSetValueCmd = new G4UIcmdWith3VectorAndUnit 59 fSetValueCmd = new G4UIcmdWith3VectorAndUnit("/globalField/setValue",this); 51 fSetValueCmd->SetGuidance("Set uniform magne 60 fSetValueCmd->SetGuidance("Set uniform magnetic field value."); 52 fSetValueCmd->SetParameterName("Bx", "By", " 61 fSetValueCmd->SetParameterName("Bx", "By", "By", false); 53 fSetValueCmd->SetUnitCategory("Magnetic flux 62 fSetValueCmd->SetUnitCategory("Magnetic flux density"); 54 fSetValueCmd->AvailableForStates(G4State_Pre 63 fSetValueCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 55 64 56 fSetVerboseCmd = new G4UIcmdWithAnInteger("/ 65 fSetVerboseCmd = new G4UIcmdWithAnInteger("/globalField/verbose",this); 57 fSetVerboseCmd->SetGuidance("Set verbose lev 66 fSetVerboseCmd->SetGuidance("Set verbose level: "); 58 fSetVerboseCmd->SetGuidance(" 0: no output" 67 fSetVerboseCmd->SetGuidance(" 0: no output"); 59 fSetVerboseCmd->SetGuidance(" 1: printing n 68 fSetVerboseCmd->SetGuidance(" 1: printing new field value"); 60 fSetVerboseCmd->SetParameterName("globalFiel 69 fSetVerboseCmd->SetParameterName("globalFieldVerbose", false); 61 fSetVerboseCmd->SetRange("globalFieldVerbose 70 fSetVerboseCmd->SetRange("globalFieldVerbose>=0"); 62 fSetVerboseCmd->AvailableForStates(G4State_P 71 fSetVerboseCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 63 72 64 // Create field 73 // Create field 65 fMagField = new G4UniformMagField(value); 74 fMagField = new G4UniformMagField(value); 66 75 67 // Set field value (the field is not activat 76 // Set field value (the field is not activated if value is zero) 68 SetField(value, "G4GlobalMagFieldMessenger:: 77 SetField(value, "G4GlobalMagFieldMessenger::G4GlobalMagFieldMessenger"); 69 } 78 } 70 79 71 //____________________________________________ 80 //______________________________________________________________________________ 72 81 73 G4GlobalMagFieldMessenger::~G4GlobalMagFieldMe 82 G4GlobalMagFieldMessenger::~G4GlobalMagFieldMessenger() 74 { 83 { 75 delete fMagField; 84 delete fMagField; 76 delete fSetValueCmd; 85 delete fSetValueCmd; 77 delete fSetVerboseCmd; 86 delete fSetVerboseCmd; 78 delete fDirectory; 87 delete fDirectory; 79 } 88 } 80 89 81 //____________________________________________ 90 //______________________________________________________________________________ 82 91 83 void G4GlobalMagFieldMessenger::SetField(const 92 void G4GlobalMagFieldMessenger::SetField(const G4ThreeVector& value, 84 const 93 const G4String& /*inFunction*/) 85 { 94 { 86 // Get field manager (or create it if it doe 95 // Get field manager (or create it if it does not yet exist) 87 G4FieldManager* fieldManager 96 G4FieldManager* fieldManager 88 = G4TransportationManager::GetTransportati 97 = G4TransportationManager::GetTransportationManager()->GetFieldManager(); 89 98 90 // Inactivate field if its value is zero 99 // Inactivate field if its value is zero 91 if ( value == G4ThreeVector() ) 100 if ( value == G4ThreeVector() ) 92 { 101 { 93 fieldManager->SetDetectorField(nullptr); << 102 fieldManager->SetDetectorField(0); 94 fieldManager->CreateChordFinder(nullptr); << 103 fieldManager->CreateChordFinder(0); 95 104 96 if ( fVerboseLevel > 0 ) 105 if ( fVerboseLevel > 0 ) 97 { 106 { 98 G4cout << "Magnetic field is inactive, f 107 G4cout << "Magnetic field is inactive, fieldValue = (0,0,0)." << G4endl; 99 } 108 } 100 } 109 } 101 else 110 else 102 { 111 { 103 fMagField->SetFieldValue(value); 112 fMagField->SetFieldValue(value); 104 fieldManager->SetDetectorField(fMagField); 113 fieldManager->SetDetectorField(fMagField); 105 fieldManager->CreateChordFinder(fMagField) 114 fieldManager->CreateChordFinder(fMagField); 106 115 107 if ( fVerboseLevel > 0 ) 116 if ( fVerboseLevel > 0 ) 108 { 117 { 109 G4cout << "Magnetic field is active, fie 118 G4cout << "Magnetic field is active, fieldValue = (" 110 << G4BestUnit(value, "Magnetic fl 119 << G4BestUnit(value, "Magnetic flux density") 111 << ")." << G4endl; 120 << ")." << G4endl; 112 } 121 } 113 } 122 } 114 } 123 } 115 124 116 //____________________________________________ 125 //______________________________________________________________________________ 117 126 118 void G4GlobalMagFieldMessenger::SetNewValue(G4 127 void G4GlobalMagFieldMessenger::SetNewValue(G4UIcommand* command, G4String newValue) 119 { 128 { 120 if ( command == fSetValueCmd ) 129 if ( command == fSetValueCmd ) 121 { 130 { 122 SetField(fSetValueCmd->GetNew3VectorValue( 131 SetField(fSetValueCmd->GetNew3VectorValue(newValue), 123 "G4GlobalMagFieldMessenger::SetNe 132 "G4GlobalMagFieldMessenger::SetNewValue"); 124 } 133 } 125 else if ( command == fSetVerboseCmd ) 134 else if ( command == fSetVerboseCmd ) 126 { 135 { 127 SetVerboseLevel(fSetVerboseCmd->GetNewIntV 136 SetVerboseLevel(fSetVerboseCmd->GetNewIntValue(newValue)); 128 } 137 } 129 } 138 } 130 139 131 //____________________________________________ 140 //______________________________________________________________________________ 132 141 133 void G4GlobalMagFieldMessenger::SetFieldValue( 142 void G4GlobalMagFieldMessenger::SetFieldValue(const G4ThreeVector& value) 134 { 143 { 135 SetField(value, "G4GlobalMagFieldMessenger:: 144 SetField(value, "G4GlobalMagFieldMessenger::SetFieldValue"); 136 } 145 } 137 146 138 //____________________________________________ 147 //______________________________________________________________________________ 139 148 140 G4ThreeVector G4GlobalMagFieldMessenger::GetFi 149 G4ThreeVector G4GlobalMagFieldMessenger::GetFieldValue() const 141 { 150 { 142 if ( fMagField != nullptr ) { return fMagFie << 151 if ( fMagField ) return fMagField->GetConstantFieldValue(); 143 152 144 return {}; << 153 return G4ThreeVector(); 145 } 154 } 146 155