Defining a magnetic field for a detector

Hi all,
I am new to ROOT. I’ve been trying to simulate the track of charged particles passing through a detector with a magnetic field inside it.
Using ROOT geometry package, I understand that the followings have to be done:
1- design the detector geometry. (did it)
2. define the magnetic field inside the detector. ( didn’t know how to do it. I have the magnetic field data in a txt file, but how to link it to the geometry?)
3. study the track. (not there yet).

so, my main question is: how can I define a non-uniform magnetic field as a medium for a detector. And are there some examples that I can learn from?


Any help!!

(I asked the expert in that field to look at your question)

The geometry package offers a hook for a user defined magnetic field. You have to derive from TVirtualMagField and implement the method Field(const Double_t *x, Double_t *B) which returns the field value in the point x. A uniform field is provided by the class TGeoUniformMagField. After creating a field object, one can register it an make it publicly available by using: TGeoGlobalMagField::Instance()->SetField(myField), then use it from wherever with TGeoGlobalMagField::Instance()->GetField(). Note that there are no utilities in the geometry package making use of the field, you have to write your own simulation based on it.