Geant4 Cross Reference |
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 // 27 /// \file field/field04/include/F04ElementField.hh 28 /// \brief Definition of the F04ElementField class 29 // 30 31 #ifndef F04ElementField_h 32 #define F04ElementField_h 1 33 34 #include "CLHEP/Units/SystemOfUnits.h" 35 36 #include "G4Navigator.hh" 37 #include "G4TransportationManager.hh" 38 #include "G4UserLimits.hh" 39 #include "G4VisAttributes.hh" 40 #include "globals.hh" 41 42 // class F04ElementField - interface for the EM field of one element 43 44 // This is the interface class used by GlobalField to compute the field 45 // value at a given point[]. 46 47 // An element that represents an element with an EM field will 48 // derive a class from this one and implement the computation for the 49 // element. The Construct() function will add the derived object into 50 // GlobalField. 51 52 class F04ElementField 53 { 54 public: 55 /// Constructor. 56 F04ElementField(const G4ThreeVector, G4LogicalVolume*); 57 58 /// the actual implementation constructs the F04ElementField 59 void Construct(); 60 61 /// Destructor. 62 virtual ~F04ElementField() = default; 63 64 /// SetMaxStep(G4double) sets the max. step size 65 void SetMaxStep(G4double stp) 66 { 67 fMaxStep = stp; 68 fUserLimits->SetMaxAllowedStep(fMaxStep); 69 fVolume->SetUserLimits(fUserLimits); 70 } 71 72 /// GetMaxStep() returns the max. step size 73 G4double GetMaxStep() { return fMaxStep; } 74 75 /// SetColor(G4String) sets the color 76 void SetColor(G4String c) 77 { 78 fColor = c; 79 fVolume->SetVisAttributes(GetVisAttribute(fColor)); 80 } 81 82 /// GetColor() returns the color 83 G4String GetColor() { return fColor; } 84 85 /// GetVisAttribute() returns the appropriate G4VisAttributes. 86 static G4VisAttributes* GetVisAttribute(G4String color); 87 88 /// SetGlobalPoint() ensures that the point is within the global 89 /// bounding box of this ElementField's global coordinates. 90 /// Normally called 8 times for the corners of the local bounding 91 /// box, after a local->global coordinate transform. 92 /// If never called, the global bounding box is infinite. 93 /// BEWARE: if called only once, the bounding box is just a point. 94 void SetGlobalPoint(const G4double point[4]) 95 { 96 if (fMinX == -DBL_MAX || fMinX > point[0]) fMinX = point[0]; 97 if (fMinY == -DBL_MAX || fMinY > point[1]) fMinY = point[1]; 98 if (fMinZ == -DBL_MAX || fMinZ > point[2]) fMinZ = point[2]; 99 if (fMaxX == DBL_MAX || fMaxX < point[0]) fMaxX = point[0]; 100 if (fMaxY == DBL_MAX || fMaxY < point[1]) fMaxY = point[1]; 101 if (fMaxZ == DBL_MAX || fMaxZ < point[2]) fMaxZ = point[2]; 102 } 103 104 /// IsInBoundingBox() returns true if the point is within the 105 /// global bounding box - global coordinates. 106 bool IsInBoundingBox(const G4double point[4]) const 107 { 108 if (point[2] < fMinZ || point[2] > fMaxZ) return false; 109 if (point[0] < fMinX || point[0] > fMaxX) return false; 110 if (point[1] < fMinY || point[1] > fMaxY) return false; 111 return true; 112 } 113 114 /// AddFieldValue() will add the field value for this element to field[]. 115 /// Implementations must be sure to verify that point[] is within 116 /// the field region, and do nothing if not. 117 /// point[] is in global coordinates and geant4 units; x,y,z,t. 118 /// field[] is in geant4 units; Bx,By,Bz,Ex,Ey,Ez. 119 /// For efficiency, the caller may (but need not) call 120 /// IsInBoundingBox(point), and only call this function if that 121 /// returns true. 122 virtual void AddFieldValue(const G4double point[4], G4double field[6]) const = 0; 123 124 virtual G4double GetLength() = 0; 125 virtual G4double GetWidth() = 0; 126 virtual G4double GetHeight() = 0; 127 128 protected: 129 G4LogicalVolume* fVolume = nullptr; 130 131 G4AffineTransform fGlobal2local; 132 133 // F04ElementField(const F04ElementField&); 134 135 private: 136 F04ElementField& operator=(const F04ElementField&); 137 138 static G4ThreadLocal G4Navigator* fNavigator; 139 140 G4String fColor = "1,1,1"; 141 142 G4ThreeVector fCenter; 143 G4double fMinX = -DBL_MAX; 144 G4double fMinY = -DBL_MAX; 145 G4double fMinZ = -DBL_MAX; 146 G4double fMaxX = DBL_MAX; 147 G4double fMaxY = DBL_MAX; 148 G4double fMaxZ = DBL_MAX; 149 150 G4double fMaxStep = 1. * CLHEP::mm; 151 G4UserLimits* fUserLimits = nullptr; 152 }; 153 154 #endif 155