Message: Problem with magnetic field from a table Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None Problem with magnetic field from a table 

Keywords: field map
Forum: Fields: Magnetic and Otherwise
Date: 25 Jan, 2008
From: Mariusz <Mariusz>


  I have a 2d table with values of Bx and By (Bz is 0). It is quite large: 4900 points
with spacing of 7.7mm. I use Geant 4.9.0.p01.
  I have a class:

---------------------VVV ------------------------
class WSMagneticField: public G4MagneticField

   WSMagneticField(G4ThreeVector);  //  The value of the field
   WSMagneticField();               //  A zero field

   void SetFieldValue(G4double fieldValue);
   void SetFieldValue(G4ThreeVector fieldVector);

   void GetFieldValue(const double Point[3],
                double *Bfield) const;           

      // Find the global Field Manager
      G4FieldManager* GetGlobalFieldManager();   
      static const int imesh=4900;
      float x[imesh];
      float y[imesh];
      float Bx[imesh];
      float By[imesh];   
In the constructor I fill the tables x,y,Bx,By:

        // here open and read file      
        ifstream bmap;
        string line;
        const char *charline;
        int ni1,ni2,idx=0;
        float modB;
        char ni3;"");
        while(bmap) {
                sscanf(charline,"  %d  %d  %f  %f  %f  %f  %f  %c\n",
                G4cout << "mag field check i = " << idx << " x = " << x[idx] << " Bx = " << Bx[idx] <<G4endl;


and I have GetFieldValue function: --------------------VVV-------------------------

// argument is position in mm
void WSMagneticField::GetFieldValue(const double Point[3], double *Bfield) const
        Bfield[0] = 0.;
        Bfield[1] = 0.;
        Bfield[2] = 0.;
        G4float dmesh=7.93; // [mm]
        G4double cPoint[3];
        cPoint[1]=Point[1]-77.; // [mm] shift back the Quad to World ref.    
        G4double radius = pow(pow(cPoint[0],2)+pow(cPoint[1],2),0.5);
        if(cPoint[0]>0 && radius < 240. && fabs(cPoint[2]) < 1400.) {
         for(G4int i=0; i<3; i++) if(cPoint[i]<0) cPoint[i]*=(-1); // because of symmetry
         for(G4int i=0; i<4900; i++) {

                if(fabs(cPoint[0]-x[i])<dmesh/2 && fabs(cPoint[1]-y[i])<dmesh/2) {

And then, in DetectorConstruction I have:
        WSMagneticField* myField = new WSMagneticField();
        G4FieldManager* fieldMgr
                                = G4TransportationManager::GetTransportationManager()

// I tried this and it did not work either // fieldMgr->SetDetectorField(myField); // fieldMgr->CreateChordFinder(myField);

/* ... geometry declaration ... */

   G4FieldManager *localFieldMgr = new G4FieldManager(myField);

The program compiles, the file with table of values is read but never ever any event has finished being calculated. I've left it even for the whole night even if in normal conditions one event takes about 15 minutes.

I would appreciate any suggestion leading to solution;-)

 Mariusz Sapinski  

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 None: Re: Problem with magnetic field from a table   (John Apostolakis - 25 Jan, 2008)
1 None: Re: Problem with magnetic field from a table   (Mariusz - 26 Jan, 2008)
1 None: Re: Problem with magnetic field from a table   (John Apostolakis - 28 Jan, 2008)
3 None: Re: Problem with magnetic field from a table   (Mariusz - 27 Jan, 2008)
1 None: Re: Problem with magnetic field from a table   (John Apostolakis - 28 Jan, 2008)
 Add Message Add Message
to: "Problem with magnetic field from a table"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews

[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]