~tstainer/lbno-nd/master

« back to all changes in this revision

Viewing changes to src/simul/MagneticField.cc

  • Committer: tstainer at ac
  • Date: 2013-01-17 22:04:04 UTC
  • Revision ID: tstainer@liv.ac.uk-20130117220404-3aekvcwtz3l0c0du
updates

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "G4FieldManager.hh"
 
2
#include "G4TransportationManager.hh"
 
3
#include "G4LogicalVolume.hh"
 
4
#include "G4UniformMagField.hh"
 
5
 
 
6
#include "DetectorConstruction.hh"
 
7
#include "MagneticField.hh"
 
8
 
 
9
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 
10
 
 
11
MagneticField::MagneticField()
 
12
  : G4UniformMagField(G4ThreeVector())
 
13
{
 
14
  GetGlobalFieldManager()->SetDetectorField(this);
 
15
  GetGlobalFieldManager()->CreateChordFinder(this);
 
16
}
 
17
 
 
18
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 
19
 
 
20
MagneticField::MagneticField(G4ThreeVector fieldVector,G4LogicalVolume *vol)
 
21
  : G4UniformMagField(fieldVector)
 
22
{
 
23
 
 
24
  magField = new G4UniformMagField(fieldVector);
 
25
 
 
26
  if(vol->GetName()=="World")
 
27
  {
 
28
      GetGlobalFieldManager()->SetDetectorField(this);    
 
29
      GetGlobalFieldManager()->CreateChordFinder(this);
 
30
  }
 
31
  
 
32
  else 
 
33
    {
 
34
      localFieldMgr = new G4FieldManager(magField);
 
35
      localFieldMgr->SetDetectorField(magField);
 
36
      localFieldMgr->CreateChordFinder(magField);
 
37
      vol->SetFieldManager(localFieldMgr,true);
 
38
 
 
39
    }
 
40
  
 
41
}
 
42
 
 
43
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 
44
 
 
45
MagneticField::~MagneticField()
 
46
{
 
47
}
 
48
 
 
49
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 
50
 
 
51
// Set the value of the Global Field to fieldValue along X
 
52
//
 
53
void MagneticField::SetMagFieldValue(G4double fieldValue)
 
54
{
 
55
   SetMagFieldValue(G4ThreeVector(fieldValue,0,0));
 
56
}
 
57
 
 
58
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 
59
 
 
60
// Set the value of the Global Field
 
61
//
 
62
void MagneticField::SetMagFieldValue(G4ThreeVector fieldVector)
 
63
{
 
64
  // Find the Field Manager for the global field
 
65
  G4FieldManager* fieldMgr = GetGlobalFieldManager();
 
66
    
 
67
  if(fieldVector!=G4ThreeVector(0.,0.,0.))
 
68
    { 
 
69
      SetFieldValue(fieldVector);
 
70
      fieldMgr->SetDetectorField(this);
 
71
    } 
 
72
 
 
73
  else 
 
74
    {
 
75
      // If the new field's value is Zero, then it is best to
 
76
      //  insure that it is not used for propagation.
 
77
      G4MagneticField* magField = 0;
 
78
      fieldMgr->SetDetectorField(magField);
 
79
    }
 
80
}
 
81
 
 
82
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 
83
 
 
84
G4FieldManager*  MagneticField::GetGlobalFieldManager()
 
85
{
 
86
  return G4TransportationManager::GetTransportationManager()->GetFieldManager();
 
87
}
 
88
 
 
89
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......