Example of quadrupole magnetic field inside a pipe

I would like to simulate the presence of a quadrupolar magnetic field inside a beam pipe, i.e.

G4Tubs*  pipe = new G4Tubs("pipe",innerR,outerR,hLen,0.,360.*deg);
G4LogicalVolume* pipeLV = new G4LogicalVolume(pipe,G4Material::GetMaterial("G4_STAINLESS-STEEL"),"pipeLV",0,0,0);
G4Tubs* magVol = new G4Tubs("magvol",0.,innerR,hLen,0.,360.*deg);
G4LogicalVolume* magLV = new G4LogicalVolume(magVol,G4Material::GetMaterial("Vacuum"),"magLV",0,0,0);

At this point I understand that I have to attach the magnetic field to magLV with a command like (taken from Book for Application Developers)

G4bool allLocal = true;
magLV->SetFieldManager(localFieldManager, allLocal)

What is not clear, is how to define the localFieldManager so that it uses G4QuadrupoleMagField. I looked around a bit but could not find an example of how to do this.

Could somebody help me and point me to the correct documentation?

Thank you

Emanuele Leonardi

Hi Emanuele,

I think that you need is something like the following:

G4FieldManager* localFieldMgr= new G4FieldManager();
G4bool allLocal= true;
localFieldMgr->SetDetectorField(magField, allLocal);
localFieldMgr->CreateChordFinder(magField);

There can be any number of ‘field manager’ objects in an application - basically they put together a field and a method to integrate the track in that field.

By the way - this seems to be in an unexpected forum. I would suggest “Geometry, Field and Transportation” for topics about creating magnetic fields and enabling Geant4 to propagate particles in them.

Cheers,
John