| 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 | //
|
|---|
| 27 | // $Id: F03FieldSetup.cc,v 1.5 2007/04/28 01:31:12 gum Exp $
|
|---|
| 28 | // GEANT4 tag $Name: $
|
|---|
| 29 | //
|
|---|
| 30 | //
|
|---|
| 31 | // Field Setup class implementation.
|
|---|
| 32 | //
|
|---|
| 33 |
|
|---|
| 34 | #include "F03FieldSetup.hh"
|
|---|
| 35 | #include "F03FieldMessenger.hh"
|
|---|
| 36 |
|
|---|
| 37 | #include "G4UniformMagField.hh"
|
|---|
| 38 | #include "G4MagneticField.hh"
|
|---|
| 39 | #include "G4FieldManager.hh"
|
|---|
| 40 | #include "G4TransportationManager.hh"
|
|---|
| 41 | #include "G4Mag_UsualEqRhs.hh"
|
|---|
| 42 | #include "G4MagIntegratorStepper.hh"
|
|---|
| 43 | #include "G4ChordFinder.hh"
|
|---|
| 44 |
|
|---|
| 45 | #include "G4ExplicitEuler.hh"
|
|---|
| 46 | #include "G4ImplicitEuler.hh"
|
|---|
| 47 | #include "G4SimpleRunge.hh"
|
|---|
| 48 | #include "G4SimpleHeum.hh"
|
|---|
| 49 | #include "G4ClassicalRK4.hh"
|
|---|
| 50 | #include "G4HelixExplicitEuler.hh"
|
|---|
| 51 | #include "G4HelixImplicitEuler.hh"
|
|---|
| 52 | #include "G4HelixSimpleRunge.hh"
|
|---|
| 53 | #include "G4CashKarpRKF45.hh"
|
|---|
| 54 | #include "G4RKG3_Stepper.hh"
|
|---|
| 55 |
|
|---|
| 56 | //////////////////////////////////////////////////////////////////////////
|
|---|
| 57 | //
|
|---|
| 58 | // Constructors:
|
|---|
| 59 |
|
|---|
| 60 | F03FieldSetup::F03FieldSetup()
|
|---|
| 61 | : fChordFinder(0), fLocalChordFinder(0), fStepper(0)
|
|---|
| 62 | {
|
|---|
| 63 | fMagneticField = new G4UniformMagField(
|
|---|
| 64 | G4ThreeVector(3.3*tesla,
|
|---|
| 65 | 0.0, // 0.5*tesla,
|
|---|
| 66 | 0.0 ));
|
|---|
| 67 | fLocalMagneticField = new G4UniformMagField(
|
|---|
| 68 | G4ThreeVector(3.3*tesla,
|
|---|
| 69 | 0.0, // 0.5*tesla,
|
|---|
| 70 | 0.0 ));
|
|---|
| 71 |
|
|---|
| 72 | fFieldMessenger = new F03FieldMessenger(this) ;
|
|---|
| 73 |
|
|---|
| 74 | fEquation = new G4Mag_UsualEqRhs(fMagneticField);
|
|---|
| 75 | fLocalEquation = new G4Mag_UsualEqRhs(fLocalMagneticField);
|
|---|
| 76 |
|
|---|
| 77 | fMinStep = 0.25*mm ; // minimal step of 1 mm is default
|
|---|
| 78 | fStepperType = 4 ; // ClassicalRK4 is default stepper
|
|---|
| 79 |
|
|---|
| 80 | fFieldManager = GetGlobalFieldManager();
|
|---|
| 81 | fLocalFieldManager = new G4FieldManager();
|
|---|
| 82 |
|
|---|
| 83 | UpdateField();
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | /////////////////////////////////////////////////////////////////////////////////
|
|---|
| 87 |
|
|---|
| 88 | F03FieldSetup::F03FieldSetup(G4ThreeVector fieldVector)
|
|---|
| 89 | {
|
|---|
| 90 | fMagneticField = new G4UniformMagField(fieldVector);
|
|---|
| 91 | GetGlobalFieldManager()->CreateChordFinder(fMagneticField);
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | ////////////////////////////////////////////////////////////////////////////////
|
|---|
| 95 |
|
|---|
| 96 | F03FieldSetup::~F03FieldSetup()
|
|---|
| 97 | {
|
|---|
| 98 | if(fMagneticField) delete fMagneticField;
|
|---|
| 99 | if(fChordFinder) delete fChordFinder;
|
|---|
| 100 | if(fStepper) delete fStepper;
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 104 | //
|
|---|
| 105 | // Update field
|
|---|
| 106 | //
|
|---|
| 107 |
|
|---|
| 108 | void F03FieldSetup::UpdateField()
|
|---|
| 109 | {
|
|---|
| 110 | SetStepper();
|
|---|
| 111 | G4cout<<"The minimal step is equal to "<<fMinStep/mm<<" mm"<<G4endl ;
|
|---|
| 112 |
|
|---|
| 113 | fFieldManager->SetDetectorField(fMagneticField );
|
|---|
| 114 | fLocalFieldManager->SetDetectorField(fLocalMagneticField );
|
|---|
| 115 |
|
|---|
| 116 | if(fChordFinder) delete fChordFinder;
|
|---|
| 117 | if(fLocalChordFinder) delete fLocalChordFinder;
|
|---|
| 118 |
|
|---|
| 119 | fChordFinder = new G4ChordFinder( fMagneticField, fMinStep,fStepper);
|
|---|
| 120 | fLocalChordFinder = new G4ChordFinder( fLocalMagneticField,
|
|---|
| 121 | fMinStep,fLocalStepper);
|
|---|
| 122 |
|
|---|
| 123 | fFieldManager->SetChordFinder( fChordFinder );
|
|---|
| 124 | fLocalFieldManager->SetChordFinder( fLocalChordFinder );
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 128 | //
|
|---|
| 129 | // Set stepper according to the stepper type
|
|---|
| 130 | //
|
|---|
| 131 |
|
|---|
| 132 | void F03FieldSetup::SetStepper()
|
|---|
| 133 | {
|
|---|
| 134 | if(fStepper) delete fStepper;
|
|---|
| 135 |
|
|---|
| 136 | switch ( fStepperType )
|
|---|
| 137 | {
|
|---|
| 138 | case 0:
|
|---|
| 139 | fStepper = new G4ExplicitEuler( fEquation );
|
|---|
| 140 | fLocalStepper = new G4ExplicitEuler( fLocalEquation );
|
|---|
| 141 | G4cout<<"G4ExplicitEuler is calledS"<<G4endl;
|
|---|
| 142 | break;
|
|---|
| 143 | case 1:
|
|---|
| 144 | fStepper = new G4ImplicitEuler( fEquation );
|
|---|
| 145 | fLocalStepper = new G4ImplicitEuler( fLocalEquation );
|
|---|
| 146 | G4cout<<"G4ImplicitEuler is called"<<G4endl;
|
|---|
| 147 | break;
|
|---|
| 148 | case 2:
|
|---|
| 149 | fStepper = new G4SimpleRunge( fEquation );
|
|---|
| 150 | fLocalStepper = new G4SimpleRunge( fLocalEquation );
|
|---|
| 151 | G4cout<<"G4SimpleRunge is called"<<G4endl;
|
|---|
| 152 | break;
|
|---|
| 153 | case 3:
|
|---|
| 154 | fStepper = new G4SimpleHeum( fEquation );
|
|---|
| 155 | fLocalStepper = new G4SimpleHeum( fLocalEquation );
|
|---|
| 156 | G4cout<<"G4SimpleHeum is called"<<G4endl;
|
|---|
| 157 | break;
|
|---|
| 158 | case 4:
|
|---|
| 159 | fStepper = new G4ClassicalRK4( fEquation );
|
|---|
| 160 | fLocalStepper = new G4ClassicalRK4( fLocalEquation );
|
|---|
| 161 | G4cout<<"G4ClassicalRK4 (default) is called"<<G4endl;
|
|---|
| 162 | break;
|
|---|
| 163 | case 5:
|
|---|
| 164 | fStepper = new G4HelixExplicitEuler( fEquation );
|
|---|
| 165 | fLocalStepper = new G4HelixExplicitEuler( fLocalEquation );
|
|---|
| 166 | G4cout<<"G4HelixExplicitEuler is called"<<G4endl;
|
|---|
| 167 | break;
|
|---|
| 168 | case 6:
|
|---|
| 169 | fStepper = new G4HelixImplicitEuler( fEquation );
|
|---|
| 170 | fLocalStepper = new G4HelixImplicitEuler( fLocalEquation );
|
|---|
| 171 | G4cout<<"G4HelixImplicitEuler is called"<<G4endl;
|
|---|
| 172 | break;
|
|---|
| 173 | case 7:
|
|---|
| 174 | fStepper = new G4HelixSimpleRunge( fEquation );
|
|---|
| 175 | fLocalStepper = new G4HelixSimpleRunge( fLocalEquation );
|
|---|
| 176 | G4cout<<"G4HelixSimpleRunge is called"<<G4endl;
|
|---|
| 177 | break;
|
|---|
| 178 | case 8:
|
|---|
| 179 | fStepper = new G4CashKarpRKF45( fEquation );
|
|---|
| 180 | fLocalStepper = new G4CashKarpRKF45( fLocalEquation );
|
|---|
| 181 | G4cout<<"G4CashKarpRKF45 is called"<<G4endl;
|
|---|
| 182 | break;
|
|---|
| 183 | case 9:
|
|---|
| 184 | fStepper = new G4RKG3_Stepper( fEquation );
|
|---|
| 185 | fLocalStepper = new G4RKG3_Stepper( fLocalEquation );
|
|---|
| 186 | G4cout<<"G4RKG3_Stepper is called"<<G4endl;
|
|---|
| 187 | break;
|
|---|
| 188 | default: fStepper = 0;
|
|---|
| 189 | }
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 193 | //
|
|---|
| 194 | // Set the value of the Global Field to fieldValue along Z
|
|---|
| 195 | //
|
|---|
| 196 |
|
|---|
| 197 | void F03FieldSetup::SetFieldValue(G4double fieldStrength)
|
|---|
| 198 | {
|
|---|
| 199 | G4ThreeVector fieldSetVec(0.0, 0.0, fieldStrength);
|
|---|
| 200 | this->SetFieldValue( fieldSetVec );
|
|---|
| 201 | // *************
|
|---|
| 202 |
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | ///////////////////////////////////////////////////////////////////////////////
|
|---|
| 206 | //
|
|---|
| 207 | // Set the value of the Global Field
|
|---|
| 208 | //
|
|---|
| 209 |
|
|---|
| 210 | void F03FieldSetup::SetFieldValue(G4ThreeVector fieldVector)
|
|---|
| 211 | {
|
|---|
| 212 | if(fMagneticField) delete fMagneticField;
|
|---|
| 213 |
|
|---|
| 214 | if(fieldVector != G4ThreeVector(0.,0.,0.))
|
|---|
| 215 | {
|
|---|
| 216 | fMagneticField = new G4UniformMagField(fieldVector);
|
|---|
| 217 | }
|
|---|
| 218 | else
|
|---|
| 219 | {
|
|---|
| 220 | // If the new field's value is Zero, then
|
|---|
| 221 | // setting the pointer to zero ensures
|
|---|
| 222 | // that it is not used for propagation.
|
|---|
| 223 | fMagneticField = 0;
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | // Either
|
|---|
| 227 | // - UpdateField() to reset all (ChordFinder, Equation);
|
|---|
| 228 | // UpdateField();
|
|---|
| 229 | // or simply update the field manager & equation of motion
|
|---|
| 230 | // with pointer to new field
|
|---|
| 231 | GetGlobalFieldManager()->SetDetectorField(fMagneticField);
|
|---|
| 232 | fEquation->SetFieldObj( fMagneticField );
|
|---|
| 233 |
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 | ////////////////////////////////////////////////////////////////////////////////
|
|---|
| 237 | //
|
|---|
| 238 | // Utility method
|
|---|
| 239 |
|
|---|
| 240 | G4FieldManager* F03FieldSetup::GetGlobalFieldManager()
|
|---|
| 241 | {
|
|---|
| 242 | return G4TransportationManager::GetTransportationManager()
|
|---|
| 243 | ->GetFieldManager();
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 | // In place of G4UniformField::GetConstantFieldValue ...
|
|---|
| 248 | //
|
|---|
| 249 | G4ThreeVector F03FieldSetup::GetConstantFieldValue()
|
|---|
| 250 | {
|
|---|
| 251 | static G4double fieldValue[6], position[4];
|
|---|
| 252 | position[0] = position[1] = position[2] = position[3] = 0.0;
|
|---|
| 253 |
|
|---|
| 254 | fMagneticField->GetFieldValue( position, fieldValue);
|
|---|
| 255 | G4ThreeVector fieldVec(fieldValue[0], fieldValue[1], fieldValue[2]);
|
|---|
| 256 |
|
|---|
| 257 | return fieldVec;
|
|---|
| 258 | }
|
|---|