Geant4  9.6.p02
 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 66994 2013-01-29 14:34:08Z 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 {
76  fFieldManager = 0;
77  fChordFinder = 0;
78  fEquation = 0;
79  fMonopoleEquation = 0;
80  fMagneticField = 0;
81  fStepper = 0;
82  fMonopoleStepper = 0;
83 
84  fMinStep = 0.0;
85 
86  fMonopoleFieldMessenger = new G4MonopoleFieldMessenger(this);
87 }
88 
89 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
90 
92 {
93  if (0 == fMonopoleFieldSetup)
94  {
95  static G4MonopoleFieldSetup theInstance;
96  fMonopoleFieldSetup = &theInstance;
97  }
98 
99  return fMonopoleFieldSetup;
100 }
101 
102 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
103 
105 {
106  delete fMonopoleFieldMessenger;
107  if(fMagneticField) delete fMagneticField;
108  if(fChordFinder) delete fChordFinder;
109  if(fStepper) delete fStepper;
110  if(fMonopoleStepper) delete fMonopoleStepper;
111 }
112 
113 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
114 
116 {
117  //apply a global uniform magnetic field along Z axis
118  if (fMagneticField) { delete fMagneticField; } //delete the existing magn field
119 
120  if (fieldValue != 0.) // create a new one if non nul
121  {
122  fMagneticField = new G4UniformMagField(G4ThreeVector(0., 0., fieldValue));
123  InitialiseAll();
124  }
125  else
126  {
127  fMagneticField = 0;
128  fFieldManager->SetDetectorField(fMagneticField);
129  }
130 }
131 
132 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
133 
134 void
136 {
138  ->GetFieldManager();
139 
140  fEquation = new G4Mag_UsualEqRhs(fMagneticField);
141  fMonopoleEquation = new G4MonopoleEquation(fMagneticField);
142 
143  fMinStep = 0.01*mm ; // minimal step of 1 mm is default
144 
145  fMonopoleStepper = new G4ClassicalRK4( fMonopoleEquation, 8 ); // for time information..
146  fStepper = new G4ClassicalRK4( fEquation );
147 
149 }
150 
151 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
152 
154 {
155  if (fMagneticField)
156  {
157  fFieldManager->SetDetectorField(fMagneticField );
158 
159  if(fChordFinder) delete fChordFinder;
160 
161  switch (val)
162  {
163  case 0:
164  fChordFinder = new G4ChordFinder( fMagneticField, fMinStep, fStepper);
165  break;
166  case 1:
167  fChordFinder = new G4ChordFinder( fMagneticField, fMinStep, fMonopoleStepper);
168  break;
169  }
170 
171  fFieldManager->SetChordFinder( fChordFinder );
172  }
173 }
174 
175 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
176 
177 G4FieldManager* G4MonopoleFieldSetup::GetGlobalFieldManager()
178 {
180  ->GetFieldManager();
181 }
182 
183 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......