#ifndef _CPPMAGNETICFIELD_ #define _CPPMAGNETICFIELD_ #include "G4MagneticField.hh" #include "G4SystemOfUnits.hh" #include "G4ThreeVector.hh" // The following are used to work around a problem that ROOT defines // sume functions named Info, Warning, and Error that conflict with // the enum values of the same names defiend in GEANT4. #define Info InfoXX #define Warning WarningXX #define Error ErrorXX #include #include extern DApplication *dapp; extern G4ThreeVector LAB_OFFSET; // Location of LASS volume in World volume. Used to translate to lab coordinates extern string BFIELD_MAP; // Set in CPPsim.cc extern int RUN_NUMBER; class CPPMagneticField: public G4MagneticField{ public: //----------------------- // CPPMagneticField //----------------------- CPPMagneticField(){ bfield = NULL; if( (BFIELD_MAP!="default") && (gPARMS!=NULL) ){ gPARMS->SetDefaultParameter("BFIELD_MAP", BFIELD_MAP, "B-field map"); } if(dapp) bfield = dapp->GetBfield(RUN_NUMBER); if(!bfield){ cout << "***** UNABLE TO CREATE DMagneticFieldMap ****" << endl; exit(-1); }else{ cout << "DMagneticFieldMap created at: 0x" << hex << bfield << dec <GetField(x, y, z, Bfield[0], Bfield[1], Bfield[2]); // printf("%s:%d B(%4.3f, %4.3f, %4.3f) = (%4.3f, %4.3f, %4.3f)\n", __FILE__, __LINE__, x, y, z, Bfield[0], Bfield[1], Bfield[2]); // B-field is returned in Tesla so convert to native units of GEANT4 Bfield[0] *= tesla; Bfield[1] *= tesla; Bfield[2] *= tesla; } //----------------------- // GetFieldValue //----------------------- void GetFieldValue(const G4ThreeVector &pos, G4ThreeVector &B) const{ // "pos" should be in global Geant4 coordinates (i.e. mm) withOUT // having subtracting the LAB_OFFSET (that is done internally) double Point[4] = {pos.x(), pos.y(), pos.z(), 0.0}; double Bfield[3]; GetFieldValue(Point, Bfield); B.set(Bfield[0], Bfield[1], Bfield[2]); } private: DMagneticFieldMap *bfield; }; extern CPPMagneticField *gCPPMagneticField; #endif // _CPPMAGNETICFIELD_