Message: Re: Field definition and its relation to geometry Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None Re: Field definition and its relation to geometry 

Forum: Fields: Magnetic and Otherwise
Re: Question Field definition and its relation to geometry (Ilya)
Date: 11 May, 2004
From: Vladimir GRICHINE <grichine@mail.cern.ch>

Dear Ilya,
Here one of examples:

Mc03ElectroMagneticField::Mc03ElectroMagneticField(Mc03DetectorConstruction* 
pDet)
  :  fStepper(NULL),fChordFinder(NULL), fDetector(pDet)
{
  // Reading input file field maps to arrays
  std::ifstream fin;
  // fstream fin;
  G4int i;
  G4double r,z;
  fEx =  0.*megavolt/cm;
  fEy =  0.*megavolt/cm;
  fEz =  1.*megavolt/cm; // -1.
  
  fin.open("miceabsfinalshifted.txt",std::ios::in); //  | 
std::ios::nocreate); 
  for(i=0;i<40401;i++)
  {
    // R(cm)>>Z(cm)>>Br(gauss)>>Bz(gauss)

    fin>>r>>z>>fPlusZ[i][0]>>fPlusZ[i][1];

    fPlusZ[i][0] *= gauss ; // Br
    fPlusZ[i][1] *= gauss ; // Bz

    fMinusZ[i][0] = -fPlusZ[i][0] ;
    fMinusZ[i][1] = -fPlusZ[i][1] ;
    //  
G4cout<<r<<"\t"<<z<<"\t"<<fPlusZ[i][0]<<"\t"<<fPlusZ[i][1]<<G4endl;
  }
  fin.close();
 
so in constructor you fill arrays or vectors from your field map files. 
Then during tracking you will get them from: 

void Mc03ElectroMagneticField::GetFieldValue (const G4double  yTrack[3],
                                                    G4double* B          ) 
const 
{
  G4int i;
  G4double xpos, ypos, zz, r;
 
  xpos = yTrack[0];
  ypos = yTrack[1];
  zz   = yTrack[2];
  r    = sqrt(xpos*xpos+ypos*ypos);

  if( r > 2000.)   r = 2000.;
  if(zz >=0 )      i = (G4int)(zz*201/cm + r/cm);
  else             i = (G4int)(-zz*201/cm + r/cm);

  if( i <  0     ) i = 0;
  if( i >= 40401 ) i = 40401;

  if (zz >= 0.)
  {
    B[2] = fPlusZ[i][1];
    if( r >= 10.)
    {
      B[0] = fPlusZ[i][0]*xpos/r;
      B[1] = fPlusZ[i][0]*ypos/r;
    }
    else
    {
      B[0] = 0.;
      B[1] = 0.;
    }
  } 
  else
  {
    B[2] = fMinusZ[i][1];
    if( r >= 10.)
    {
      B[0] = fMinusZ[i][0]*xpos/r;
      B[1] = fMinusZ[i][0]*ypos/r;
    }
    else
    {
      B[0] = 0.;
      B[1] = 0.;
    }
  }
  if(  ( abs(xpos)                   < fDetector->GetRFx() ) &&
       ( abs(ypos)                   < fDetector->GetRFy() ) &&
       ( abs(zz-fDetector->GetZRF()) < fDetector->GetRFz() )     )
  {
    B[3] = fEx;
    B[4] = fEy;
    B[5] = fEz;
  }
  else
  {
    B[3] = 0.;
    B[4] = 0.;
    B[5] = 0.;
  }
  //  G4cout<<"Global field at: "<<yTrack[0]/mm<<" "<<yTrack[1]/mm<<" "
  //                         <<yTrack[2]/mm<<G4endl;
  //  G4cout<<B[0]/tesla<<"  "<<B[1]/tesla<<"  "<<B[2]/tesla<<"  "
  //    <<B[3]*cm/megavolt<<"  "<<B[4]*cm/megavolt<<"  
"<<B[5]*cm/megavolt<<G4endl; 
  return;
}

this function set additional electric field in some region as well. Note 
that the fields are defined in global frame of world volume.
Don't forget on field units.
Cheers, Vladimir


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

 Add Message Add Message
to: "Re: Field definition and its relation to geometry"

 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 ]