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.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 /// \file exoticphysics/monopole/src/G4MonopoleFieldSetup.cc
 27 /// \brief Implementation of the G4MonopoleFieldSetup class
 28 //
 29 //
 30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 32 //
 33 //
 34 // G4MonopoleFieldSetup is responsible for setting up a magnetic field
 35 // and the ability to use it with two different equation of motions,
 36 // one for monopoles and another for the rest of the particles.
 37 //
 38 //
 39 
 40 // =======================================================================
 41 // Created:  13 May 2010, B. Bozsogi
 42 // =======================================================================
 43 
 44 #include "G4MonopoleFieldSetup.hh"
 45 
 46 #include "G4ChordFinder.hh"
 47 #include "G4FieldManager.hh"
 48 #include "G4MagIntegratorStepper.hh"
 49 #include "G4Mag_UsualEqRhs.hh"
 50 #include "G4MagneticField.hh"
 51 #include "G4MonopoleEquation.hh"
 52 #include "G4MonopoleFieldMessenger.hh"
 53 #include "G4TransportationManager.hh"
 54 #include "G4UniformMagField.hh"
 55 
 56 // #include "G4ExplicitEuler.hh"
 57 // #include "G4ImplicitEuler.hh"
 58 // #include "G4SimpleRunge.hh"
 59 // #include "G4SimpleHeum.hh"
 60 #include "G4ClassicalRK4.hh"
 61 // #include "G4HelixExplicitEuler.hh"
 62 // #include "G4HelixImplicitEuler.hh"
 63 // #include "G4HelixSimpleRunge.hh"
 64 // #include "G4CashKarpRKF45.hh"
 65 // #include "G4RKG3_Stepper.hh"
 66 
 67 #include "G4SystemOfUnits.hh"
 68 
 69 // G4MonopoleFieldSetup* G4MonopoleFieldSetup::fMonopoleFieldSetup=0;
 70 
 71 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 72 
 73 G4MonopoleFieldSetup::G4MonopoleFieldSetup()
 74   : fFieldManager(0),
 75     fChordFinder(0),
 76     fUsualChordFinder(0),
 77     fMonopoleChordFinder(0),
 78     fEquation(0),
 79     fMonopoleEquation(0),
 80     fMagneticField(0),
 81     fStepper(0),
 82     fMonopoleStepper(0),
 83     fMinStep(0.0),
 84     fZmagFieldValue(0.2 * tesla),
 85     fMonopoleFieldMessenger(0)
 86 {
 87   fMonopoleFieldMessenger = new G4MonopoleFieldMessenger(this);
 88   fFieldManager = GetGlobalFieldManager();
 89 }
 90 
 91 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 92 
 93 // G4MonopoleFieldSetup* G4MonopoleFieldSetup::GetMonopoleFieldSetup()
 94 // {
 95 //    if (0 == fMonopoleFieldSetup)
 96 //    {
 97 //      static G4ThreadLocal G4MonopoleFieldSetup theInstance;
 98 //      fMonopoleFieldSetup = &theInstance;
 99 //    }
100 
101 //    return fMonopoleFieldSetup;
102 // }
103 
104 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
105 
106 G4MonopoleFieldSetup::~G4MonopoleFieldSetup()
107 {
108   delete fMonopoleFieldMessenger;
109   if (fMagneticField) delete fMagneticField;
110   //  if(fChordFinder)   delete fChordFinder;
111   if (fUsualChordFinder) delete fUsualChordFinder;
112   if (fMonopoleChordFinder) delete fMonopoleChordFinder;
113   if (fStepper) delete fStepper;
114   if (fMonopoleStepper) delete fMonopoleStepper;
115 }
116 
117 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
118 
119 void G4MonopoleFieldSetup::SetZMagFieldValue(G4double val)
120 {
121   // set new magnetic field value and rebuild the field
122   fZmagFieldValue = val;
123 
124   ConstructMagField();
125 }
126 
127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
128 
129 void G4MonopoleFieldSetup::ConstructMagField()
130 {
131   // apply a global uniform magnetic field along Z axis
132   if (fMagneticField) {
133     delete fMagneticField;
134   }  // delete the existing magn field
135 
136   if (fZmagFieldValue != 0.)  // create a new one if non nul
137   {
138     // G4cout << "Go to create new field ..." << G4endl;
139     fMagneticField = new G4UniformMagField(G4ThreeVector(0., 0., fZmagFieldValue));
140     InitialiseAll();
141   }
142   else {
143     // G4cout << "Set field = 0 ..." << G4endl;
144     fMagneticField = 0;
145   }
146 
147   fFieldManager->SetDetectorField(fMagneticField);
148 }
149 
150 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
151 
152 void G4MonopoleFieldSetup::InitialiseAll()
153 {
154   fEquation = new G4Mag_UsualEqRhs(fMagneticField);
155   fMonopoleEquation = new G4MonopoleEquation(fMagneticField);
156 
157   fMinStep = 0.01 * mm;  // minimal step of 1 mm is default
158 
159   fMonopoleStepper = new G4ClassicalRK4(fMonopoleEquation, 8);
160   fStepper = new G4ClassicalRK4(fEquation);
161 
162   fUsualChordFinder = new G4ChordFinder(fMagneticField, fMinStep, fStepper);
163   fMonopoleChordFinder = new G4ChordFinder(fMagneticField, fMinStep, fMonopoleStepper);
164 
165   SetStepperAndChordFinder(0);
166 }
167 
168 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
169 
170 void G4MonopoleFieldSetup::SetStepperAndChordFinder(G4int val)
171 {
172   if (fMagneticField) {
173     fFieldManager->SetDetectorField(fMagneticField);
174     //    if(fChordFinder) delete fChordFinder;
175 
176     switch (val) {
177         //       case 0:
178         //         fChordFinder = new G4ChordFinder( fMagneticField, fMinStep, fStepper);
179         //         break;
180         //       case 1:
181         //         fChordFinder = new G4ChordFinder( fMagneticField, fMinStep,
182         //                                             fMonopoleStepper);
183         //         break;
184       case 0:
185         fChordFinder = fUsualChordFinder;
186         break;
187       case 1:
188         fChordFinder = fMonopoleChordFinder;
189         break;
190     }
191 
192     fFieldManager->SetChordFinder(fChordFinder);
193   }
194 }
195 
196 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
197 
198 G4FieldManager* G4MonopoleFieldSetup::GetGlobalFieldManager()
199 {
200   return G4TransportationManager::GetTransportationManager()->GetFieldManager();
201 }
202 
203 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
204