Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4MonopoleFieldSetup.cc
Go to the documentation of this file.
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 //
28 //
29 // $Id: G4MonopoleFieldSetup.cc 68036 2013-03-13 14:13:45Z gcosmo $
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 //
34 //
35 // G4MonopoleFieldSetup is responsible for setting up a magnetic field
36 // and the ability to use it with two different equation of motions,
37 // one for monopoles and another for the rest of the particles.
38 //
39 //
40 
41 // =======================================================================
42 // Created: 13 May 2010, B. Bozsogi
43 // =======================================================================
44 
45 #include "G4MonopoleFieldSetup.hh"
47 
48 #include "G4MagneticField.hh"
49 #include "G4UniformMagField.hh"
50 #include "G4FieldManager.hh"
52 #include "G4Mag_UsualEqRhs.hh"
53 #include "G4MonopoleEquation.hh"
55 #include "G4ChordFinder.hh"
56 
57 // #include "G4ExplicitEuler.hh"
58 // #include "G4ImplicitEuler.hh"
59 // #include "G4SimpleRunge.hh"
60 // #include "G4SimpleHeum.hh"
61 #include "G4ClassicalRK4.hh"
62 // #include "G4HelixExplicitEuler.hh"
63 // #include "G4HelixImplicitEuler.hh"
64 // #include "G4HelixSimpleRunge.hh"
65 // #include "G4CashKarpRKF45.hh"
66 // #include "G4RKG3_Stepper.hh"
67 
68 #include "G4SystemOfUnits.hh"
69 
70 G4MonopoleFieldSetup* G4MonopoleFieldSetup::fMonopoleFieldSetup=0;
71 
72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73 
74 G4MonopoleFieldSetup::G4MonopoleFieldSetup()
75  : fFieldManager(0),
76  fChordFinder(0),
77  fEquation(0),
78  fMonopoleEquation(0),
79  fMagneticField(0),
80  fStepper(0),
81  fMonopoleStepper(0),
82  fMinStep(0.0),
83  fMonopoleFieldMessenger(0)
84 {
85  fMonopoleFieldMessenger = new G4MonopoleFieldMessenger(this);
86 }
87 
88 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
89 
91 {
92  if (0 == fMonopoleFieldSetup)
93  {
94  static G4MonopoleFieldSetup theInstance;
95  fMonopoleFieldSetup = &theInstance;
96  }
97 
98  return fMonopoleFieldSetup;
99 }
100 
101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
102 
104 {
105  delete fMonopoleFieldMessenger;
106  if(fMagneticField) delete fMagneticField;
107  if(fChordFinder) delete fChordFinder;
108  if(fStepper) delete fStepper;
109  if(fMonopoleStepper) delete fMonopoleStepper;
110 }
111 
112 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
113 
115 {
116  //apply a global uniform magnetic field along Z axis
117  if (fMagneticField) { delete fMagneticField; } //delete the existing magn field
118 
119  if (fieldValue != 0.) // create a new one if non nul
120  {
121  fMagneticField = new G4UniformMagField(G4ThreeVector(0., 0., fieldValue));
122  InitialiseAll();
123  }
124  else
125  {
126  fMagneticField = 0;
127  fFieldManager->SetDetectorField(fMagneticField);
128  }
129 }
130 
131 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
132 
133 void
135 {
137  ->GetFieldManager();
138 
139  fEquation = new G4Mag_UsualEqRhs(fMagneticField);
140  fMonopoleEquation = new G4MonopoleEquation(fMagneticField);
141 
142  fMinStep = 0.01*mm ; // minimal step of 1 mm is default
143 
144  fMonopoleStepper = new G4ClassicalRK4( fMonopoleEquation, 8 ); // for time information..
145  fStepper = new G4ClassicalRK4( fEquation );
146 
148 }
149 
150 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
151 
153 {
154  if (fMagneticField)
155  {
156  fFieldManager->SetDetectorField(fMagneticField );
157 
158  if(fChordFinder) delete fChordFinder;
159 
160  switch (val)
161  {
162  case 0:
163  fChordFinder = new G4ChordFinder( fMagneticField, fMinStep, fStepper);
164  break;
165  case 1:
166  fChordFinder = new G4ChordFinder( fMagneticField, fMinStep, fMonopoleStepper);
167  break;
168  }
169 
170  fFieldManager->SetChordFinder( fChordFinder );
171  }
172 }
173 
174 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
175 
176 G4FieldManager* G4MonopoleFieldSetup::GetGlobalFieldManager()
177 {
179  ->GetFieldManager();
180 }
181 
182 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4MonopoleFieldMessenger(G4MonopoleFieldSetup *)
Definition of the G4MonopoleEquation class.
static constexpr double mm
Definition: G4SIunits.hh:115
void SetMagField(G4double fieldValue)
CLHEP::Hep3Vector G4ThreeVector
G4bool SetDetectorField(G4Field *detectorField)
void SetChordFinder(G4ChordFinder *aChordFinder)
int G4int
Definition: G4Types.hh:78
Definition of the G4MonopoleFieldSetup class.
static G4MonopoleFieldSetup * GetMonopoleFieldSetup()
static G4TransportationManager * GetTransportationManager()
#define fMinStep
G4FieldManager * GetFieldManager() const
void SetStepperAndChordFinder(G4int val)
double G4double
Definition: G4Types.hh:76
Definition of the G4MonopoleFieldMessenger class.