EDepSimArbEMField.cc
Go to the documentation of this file.
1 // License and Disclaimer
2 //
3 // For use with software authored by the Geant4 Collaboration
4 //
5 // MIT License
6 //
7 // Copyright (c) 2020 Andrew Cudd
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a
10 // copy of this software and associated documentation files (the "Software"),
11 // to deal in the Software without restriction, including without limitation
12 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 // and/or sell copies of the Software, and to permit persons to whom the
14 // Software is furnished to do so, subject to the following conditions:
15 //
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
18 //
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 // DEALINGS IN THE SOFTWARE.
26 //
27 //
28 // Class for storing and handling an arbitrary EM field.
29 //
30 // History:
31 // - 2020.04.14 A.Cudd created
32 // - 2020.07.28 C.McGrew updated license with permission of A.Cudd
33 //
34 // -------------------------------------------------------------------
35 
36 #include "EDepSimArbEMField.hh"
37 
39  : efield(nullptr)
40  , bfield(nullptr)
41 {
42 }
43 
44 EDepSim::ArbEMField::ArbEMField(G4Field* efield_in, G4Field* bfield_in)
45  : efield(efield_in)
46  , bfield(bfield_in)
47 {
48 }
49 
51  : EDepSim::ArbEMField(cpy.efield, cpy.bfield)
52 {
53  efield = cpy.efield;
54  bfield = cpy.bfield;
55 }
56 
58 {
59  if(&rhs == this)
60  return *this;
61  else
62  {
63  efield = rhs.efield;
64  bfield = rhs.bfield;
65  return *this;
66  }
67 }
68 
70 {
71  delete bfield;
72  delete efield;
73 }
74 
75 void EDepSim::ArbEMField::GetFieldValue(const G4double pos[4], G4double *field) const
76 {
77  //GetFieldValue always expects an array with six elements for both the EField
78  //and BField, even if it only fills one of the fields.
79  double tmp_bfield[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
80  double tmp_efield[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
81 
82  if(bfield != nullptr)
83  bfield->GetFieldValue(pos, tmp_bfield);
84 
85  if(efield != nullptr)
86  efield->GetFieldValue(pos, tmp_efield);
87 
88  //Geant4 convention is the first three elements are Bx, By, Bz
89  //and the next three are Ex, Ey, Ez
90  field[0] = tmp_bfield[0];
91  field[1] = tmp_bfield[1];
92  field[2] = tmp_bfield[2];
93 
94  field[3] = tmp_efield[3];
95  field[4] = tmp_efield[4];
96  field[5] = tmp_efield[5];
97 }
ArbEMField & operator=(const ArbEMField &rhs)
Construct a module from components.
Definition: TG4HitSegment.h:10
virtual void GetFieldValue(const G4double pos[4], G4double *field) const