Skip to content

Description of Example Code

rayrios edited this page Oct 16, 2012 · 2 revisions

(Note UCN_EX1-EX4 are not yet placed onto Github)

SCMagnet

This code uses Geant4.9.5 and is currently part of the master branch on github. This example contains a UCN guide, Superconducting Magnet, and a thin foil.

UCN_EX1: Guide transmission example

In this example we guide neutrons through material guides, they are affected only by gravity. We assume that our neutrons are produced in solid deuterium. That means, when they leave the deutrium they get an energy kick of about 100 neV. We use a spectrum from 0 to 50 neV, the neutrons are produced directly below the surface of the sD2 volume. 2 cm later a Ni-coated guide starts and leads the UCN to a mirror, which consists of magnetized iron (we dont care at the moment about the spins). The neutrons are reflected upwards to a second mirror consisting of Ni and go then horizontally through a shutter into the storage volume. The storage volume is a horizontal tube consisting of a low loss coated material. at the end is a second shutter mounted, leading to a 90 degree torodial bent Ni tube and finally an other Ni tube leads vertically downwards to the detector. On the top of the detector there is an aluminium foil (as a daughter volume of the detector- volume) where it is decided if the neutron can enter the detector or not. The stepsize must be very small inside the detector since otherwise the foil would not be seen by the stepping algorithm.

For demonstration purposes also a timedependent magnetic field is used from z = -100 mm to z = 100 mm, but is not relevant for the current geometry since only neutrons that are scattered away reach this field region.

The macro file to control the simulation is called UCN_EX1.mac, the time dependent field is in the file time.dat, bot files have to be in the binaries directory where the compiled program is.

Macro file:

/shutter/use 1 .... tell the materialboundary process, that you want to use shutters. /shutter/close 1 0 ... close the shutter #1 at time 0 s. /shutter/open 1 3.7 ... open the shutter #1 at time 3.7 s. everytime you build a shutter volume, call it "Shutter1", "Shutter2"..., the commands work nly if they find a suitable volume

(for some reason, you need something like /shutter/close 1 1000 or open so with a large time longer than your calculation that all this works properly)

/gun/usespectrum 1 .... tell the primarygenerator to use a spectrum, the default cut off is 8 m/s. to change this go to the primarygeneratoraction in the generate primaries function /gun/randomseed 80008498 .. tell the randomgenertor a initial state /gun/visual 1 or 0 ... drwa circles at the position where the particles are produced. /gun/filltime 5 ... produce neutrons from time 0 to 5 s randomly (for example, to calculate a filltime or chopper pulses) /run/beamOn 100 ... produce 100 particles

Processes: in the routine void UCNPhysicsList::ConstructUCN() { // Add UCN processes UCNMaterialBoundary* theMaterialBoundary = new UCNMaterialBoundary(); UCNSimpleDecay* theSimpleDecay = new UCNSimpleDecay(); UCNSimpleAbsorption* theSimpleAbsorption = new UCNSimpleAbsorption(); UCNSimpleLoss* theSimpleLoss = new UCNSimpleLoss(); UCNMultiScattering* theMultiScattering = new UCNMultiScattering(); UCNSpin* theSpin = new UCNSpin(); UCNDetector* theDetector = new UCNDetector(); ....

the processes for UCN are added. the ordering of some processes can be important, to try out the functionality of the processes comment single processes out and look at the result. UCNMaterialBoundary.... all wall interactions UCNSimpleDecay...deacy of the free neutron UCNSimpleAbsorption...1/v absorption UCNSimpleLoss... v independent absorption UCNMultiScattering.... 4 pi random scattering (would be good, if somebody would implement a formula for scattering here, in the function

G4ThreeVector UCNMultiScattering::scatter(G4ThreeVector){

G4ThreeVector final(0.,0.,1.); // make a simple uniform distribution in 4 pi // apply scattering // calculate angle phi, theta double theta = G4UniformRand() * pi; //G4cout << "angle " << phi << G4endl; double phi = G4UniformRand() * 2 * pi; final.rotateY(theta); final.rotateZ(phi); final = final.unit();

return final; }

UCNSpin ... calculates (simple classical) spin precession in the adiabatic case, only the angle. details are not updated up to now.

UCNDetector... looks, if we reach our detector ("det") through it entrance side with an aluminim foil. if this is the case, we write some data output to the saveToFile class.

The saveToFile class can be accessed from everywhere if you include the header file and the two lines as in the class UCNDetector::PostStepDoIt(..).

Geometry: The geometry is defined in the detectorcontruction. in the DefineMaterials() routine the materials have to be defined (things like density are important for absorption length or so in materials) Then we have thngs like MaterialPropertiesTables defined here. Here we give our materials properties like the cross section, fermipotential and so on.

when you construct your geometry you need a solid: e.g. G4Tubs* solidNI = new G4Tubs("NI",t1innerradius,t1radius,t1thickness/2.,0.,twopi); using this one makes a logical volume with a material, e.g.
G4LogicalVolume* logicNI = new G4LogicalVolume(solidNI, Nickel58Material,"NI");
this volume needs to be placed in our world or an other mother volume:
G4RotationMatrix rot; rot.rotateX(phi); G4VPhysicalVolume* physiNI; physiNI = new G4PVPlacement( G4Transform3D(rot,G4ThreeVector(x,y,z)), "NI", logicNI, physiWorld, false, 0);

Particle Generator: in the UCNPrimaryGeneratorAction::GeneratePrimaries(...)

the particle's properties are set. particleGun->SetParticleTime(time); particleGun->SetParticlePolarization(spin); particleGun->SetParticleMomentumDirection(momentum); particleGun->SetParticleEnergy(n_energy*1e-9 *eV); particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0)); here we produce it
particleGun->GeneratePrimaryVertex(anEvent);

UCN_EX2: storage example (UCN Source)

This example uses a material bottle as a storage volume, the neutrons are affected by gravity. The bottle is filled from below with a Ni58 coated guide. at the bottle bottom entrance a shutter is placed, which can be opened and closed via macro file. The exit guide is at 250 mm height above the bottle in radial direction, at its end is a bend downwards and a shutter with an aluminium window. the beginning of the exit guide is also closed with a shutter.

The macro file to control the simulation is called UCN_EX2.mac, the time dependent field is in the file time.dat, bot files have to be in the binaries directory where the compiled program is. (anyway, not relevant for this application now)

Macro file:

/shutter/use 1 .... tell the materialboundary process, that you want to use shutters. /shutter/close 1 0 ... close the shutter #1 at time 0 s. /shutter/open 1 3.7 ... open the shutter #1 at time 3.7 s. everytime you build a shutter volume, call it "Shutter1", "Shutter2"..., the commands work nly if they find a suitable volume

(for some reason, you need something like /shutter/close 1 1000 or open so with a large time longer than your calculation that all this works properly)

/gun/usespectrum 1 .... tell the primarygenerator to use a spectrum, the default cut off is 8 m/s. to change this go to the primarygeneratoraction in the generate primaries function /gun/randomseed 80008498 .. tell the randomgenertor a initial state /gun/visual 1 or 0 ... drwa circles at the position where the particles are produced. /gun/filltime 5 ... produce neutrons from time 0 to 5 s randomly (for example, to calculate a filltime or chopper pulses) /run/beamOn 100 ... produce 100 particles

UCN_EX3: magnetic storage example (depol - experiment priciple)

This example uses a combined material, gravitational and magnetic bottle as a storage volume the neutrons are filled in from below for some time, while the magnetic field is slowly turned on. One spin component will be trapped then and parameters like the loss probability per wall collision can be studied.

The particle is produced somewere inside the volume while the magnetic field is turned on. after some time the field is switched off and the particle escapes through the bottom.

Macro file:

/fieldcube/enabled 1 ... the word fieldcube originates from the first approach to use field-

coordinates to calculate fieldstrength and gradients at each point in space. now it only says if you want to use a magnetic field or not.

if we use fieldcube = 1 , we need a file with data

/fieldcube/file magfield.dat ... file with field coordinates.

when does our field start in seconds

/fieldcube/starttime 0 ... beginning time of the time dependence, practically always 0 s.

/fieldcube/timedependence 1 ... if there is a time dependent field

if there is a timedependence, we need a file for this

/fieldcube/timefile time.dat

visualization of the fieldpoints

/fieldcube/drawfield 0

/run/beamOn 100 ... produce 100 particles

UCN_EX3: UCNExample 4

this example is the "basic" example which shows the principle of the code, the other examples are maybe too detailed for beginning.

A particle is bouncing with gravity on a reflecting mirror and finally hits a detector

The number of particles produced can be set in the macrofile: /run/beamOn 100 ... produce 100 particles

if the verbose levels are changed, the screen output can be made more detailed (screen output slows simulations down typically). the place, momentum and energy of particle when it is produced can be chosen in the primary generator. the processes used can be changed in the physicslist, an example to see more screen output would be to change the verbose level for the material boundary process /materialboundary/setverbose 5 in the macro file