00001 // BLGlobalField.hh 00002 /* 00003 This source file is part of G4beamline, http://g4beamline.muonsinc.com 00004 Copyright (C) 2003,2004,2005,2006 by Tom Roberts, all rights reserved. 00005 00006 This program is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU General Public License 00008 as published by the Free Software Foundation; either version 2 00009 of the License, or (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 http://www.gnu.org/copyleft/gpl.html 00017 */ 00018 00019 #ifndef BLGLOBALFIELD_HH 00020 #define BLGLOBALFIELD_HH 00021 00022 #include <vector> 00023 #include "G4ElectroMagneticField.hh" 00024 00025 #include "BLElementField.hh" 00026 00027 /** BLGlobalField - handles the global ElectroMagnetic field 00028 * 00029 * There is a single BLGlobalField object. 00030 * 00031 * The field from each individual beamline element is given by a 00032 * BLElementField object. Any number of overlapping BLElementField 00033 * objects can be added to the global field. Any element command that 00034 * represents an element with an EM field must add the appropriate 00035 * BLElementField to the global BLGlobalField object. 00036 **/ 00037 class BLGlobalField : public G4ElectroMagneticField { 00038 protected: 00039 std::vector<const BLElementField *> fields; 00040 const BLElementField **fp; 00041 bool first; 00042 int nfp; 00043 bool forceEfieldZero; 00044 static BLGlobalField *object; 00045 BLGlobalField(); 00046 ~BLGlobalField(); 00047 BLGlobalField(const BLGlobalField&); // undefined 00048 BLGlobalField& operator=(const BLGlobalField&); // undefined 00049 void setupArray(); 00050 public: 00051 /// getObject() returns the single BLGlobalField object. 00052 /// It is constructed, if necessary. 00053 static BLGlobalField *getObject(); 00054 00055 /// GetFieldValue() returns the field value at a given point[]. 00056 /// field is really field[6]: Bx,By,Bz,Ex,Ey,Ez. 00057 /// point[] is in global coordinates: x,y,z,t. 00058 /// Uses the field map for solenoids, when possible. 00059 void GetFieldValue(const G4double *point, G4double *field) const; 00060 00061 void getFieldValue(G4ThreeVector &pos, G4double t, G4ThreeVector &B, 00062 G4ThreeVector &E) { 00063 G4double point[4], field[6]; 00064 point[0]=pos[0]; point[1]=pos[1]; point[2]=pos[2],point[3]=t; 00065 GetFieldValue(point,field); 00066 B.setX(field[0]); B.setY(field[1]); B.setZ(field[2]); 00067 E.setX(field[3]); E.setY(field[4]); E.setZ(field[5]); 00068 } 00069 00070 /// DoesFieldChangeEnergy() returns true. 00071 G4bool DoesFieldChangeEnergy() const { return true; } 00072 00073 /// addElementField() adds the BLElementField object for a single 00074 /// element to the global field. 00075 void addElementField(const BLElementField* f) 00076 { fields.push_back(f); } 00077 00078 /// clear() removes all BLElementField-s from the global object, 00079 /// and destroys them. Used before the geometry is completely 00080 /// re-created. 00081 void clear(); 00082 00083 /// zeroEfield() sets the flag that forces the Efield to be zero 00084 /// everywhere. Used for ICOOL-style reference particle tracking. 00085 void zeroEfield(bool v) { forceEfieldZero = v; } 00086 }; 00087 00088 #endif // BLGLOBALFIELD_HH