Magnetic field from field map file

Hi I am trying to simulate a beam line with different magnets and fields read from their respective field maps. I have constructed the magnets in separate classes so that one can construct them in a beam line as required. Now for the field maps I have 2d files as Bz is always 0. My magnets are in separate logical volumes so that they can be rotated and placed independently. My question is for the field maps when I define it in my class the co-ordinates are with respect to the magnet co-ordinates and not the global co-ordinates. If I set that logical volume to be true for the particular field manager will it be according to the local co-ordinate of the logical volume or should I translate it to the global co-ordinate ? e.g., I have a field map defined within 0 - 700 mm in y in the co-ordinate system of the magnet, if I now place the magnet at 150 mm in y and set the field manager to be true for its logical volume will the field map be defined in terms of the co-ordinate system of the magnet or I have to redefine each field map according to the global co-ordinate system ? Please let me know. Thank you very much in advance for any help…

The field classes are intended to operate with global coordinates. During tracking, that’s how they’ll be called.

My application has a similar situation to yours: we have multiple detectors, each with its own local electric field. The field is computed with a mesh in the local volume coordinates.

To solve the problem, we ended up writing two custom classes:

First, we have a LocalElectroMagField class, which can take another field object as argument (e.g., something that handles a mesh). This class is what will get called during transport, and has functionality to convert the input global coordinates to local, and then to convert the resulting field vectors from local to global on exit. The global-to-local transform is passed into this class via a public accessor function, used below.

We also have a custom FieldManager class, which I could attach to the detector LV. The class keeps data members for the current PV (taken from the track), and the global-to-local transform associated with it via the Touchable. In the ConfigureForTrack() function, if the track’s PV is different from the cached data member, then the transforms are updated accordingly. The transform is registered into the LocalElectroMagField object registered with the field manager.

With those wrappers, you can have your “real” magnetic fields defined conveniently to work purely in local coordinates. The wrapper object will take care of the transform, no matter where you end up placing the magnets in your geometry.

Hi Michael

Thanks a lot for the reply. So I should write my own class as well then. I was hoping since we can set the field to a particular logical volume the traits of the volume will be passed to the read field as well.
Thanks again for the explanation :slight_smile: