Multiple Scattering in a Gas (I)

We now consider the effect of a gas on the passage of an electron through it with an applied, external magnetic field. As a single electron moves through the gas it receives a series of small pushes and pulls from the surrounding gas molecules (multiple scatterings) that can cause the electron to deviate from its original path. In the construction of a spectrometer like the ones used at Jefferson Lab we have to account for this effect in the analysis of our data. In this laboratory you will learn a how  to produce random numbers with a desired distribution using what is called a Monte Carlo technique. You will then solve the equations of motion for an electron moving through a gas with an external, applied magnetic field. In the next laboratory, you will put all these pieces together to simulate the motion of real particles through a gas.

1.0 Some Necessary Commands

In this section several Mathematica commands that will be useful in your simulation are demonstrated.  You should execute the commands in the cells below to investigate the new functions.

1.1 Generating random numbers

Random numbers can be generated with the following command.

xmin  =  -3;
xmax  =  +3;
TestValue  =  Random[Real, {xmin, xmax}]

1.2 An acceptance-rejection method

An acceptance-rejection method can be used to generate a set of random numbers that have a particular distribution. The While loop shown below can be used to test for acceptance or rejection of the point obtained with the Random function. The test in the While loop includes a limit on the number of iterations to prevent 'runaway' loops.

\(\(\( (*\ 
      Set\ things\ \(\(up\)\(.\)\)\ *) \)\(
\)\(\(width\  = \ 0.1;\)

    \(FunctionValue\  = \ 1.0;\)

    \(TestValue\  = \ 2.0;\)

    \(nloops\  = \ 1;\)

    \(maxloops\  = \ 5;\)

    \(FunctionMax\  = \ 1.0;\)

    \(FunctionMin = 0.0;\)

 (*\ 
      Apply\ acceptance - 
        rejection\ until\ you\ get\ a
	\ \ good\ \(\(value\)\(.\)\)\ *) 

    \(While[
	
        TestValue > FunctionValue\ \  && \ \ nloops\  < \ 
            maxloops, 
	
	 (*\ 
          Get\ the\ next\ value . \ 
              The\ Print\ command
		\ \ is\ for\ demonstration\ purposes\ \(\(only\)\(.\)\)\ *) 
\ \ \ NewAngle\  = \ 
          Random[Real, {\(-4\)*width, 4*width}]; 
\ \ \ FunctionValue\  = \ 
          Exp[\(-\((NewAngle^2)\)\)/\((2*width^2)\)]; 
\ \ \ TestValue\  = \ 
          Random[Real, {FunctionMin, \ FunctionMax}]; 
	
        nloops\  = \ nloops\  + \ 1; 
\ \ \ Print[NewAngle, " ", 
          FunctionValue, " ", TestValue]
];\)\)\)\)

1.3 Making the code modular.

Later on we will find our code is growing increasingly complex and difficult to read. To make reading and debugging easier we will create our own new functions to perform specific calculations. The code below demonstrates how to create a function from the code in the previous example. The last quantity listed in the function becomes the value of the function.

\(MSAngle[width_]\  := 
	\((\ 
        FunctionValue\  = \ 1.0; 
\ \ \ \ \ \ \ \ \ \ \ \ \ TestValue\  = \ 
          2.0; 
	\ \ \ \ nloops\  = \ 0; 
	\ \ \ \ maxloops\  = \ 
          5; 

\ \ \ \ \ \ \ \ \ \ \  (*\ 
          Apply\ acceptance - 
            rejection\ until\ you\ get\ a
	\ \ \ \ good\ \(\(value\)\(.\)\)\ *) 
\ \ \ \ \ \ \ \ \ \ While[
	\ \ \ \ \ TestValue > 
              FunctionValue\ \  && \ \ nloops\  < \ 
              maxloops, 
	
	\ \ \ \ \  (*\ 
            Get\ the\ next\ value . \ 
                The\ Print\ command
		\ \ \ is\ for\ demonstration\ purposes\ \(\(only\)\(.\)\)\ *) 
\ \ \ \ \ \ \ \ \ \ \ \ NewAngle\  = \ 
            Random[Real, {\(-4\)*width, 
                4*width}]; 
\ \ \ \ \ \ \ \ \ \ \ \ FunctionValue\  = \ 
            Exp[\(-\((NewAngle^2)\)\)/\((2*
                    width^2)\)]; 
\ \ \ \ \ \ \ \ \ \ \ \ nloops\  = \ 
            nloops\  + \ 1; 
\ \ \ \ \ \ \ \ \ \ \ TestValue\  = \ 
            Random[Real, {0, 
                1}];
\ \ \ \ \ \ \ \ \ \ \ ]; 
\ \ NewAngle)\)\)

1.4 Histogramming a distribution.

When we investigate statistical processes like the passage of an electon through a gas we will often want to observe the frequency distribution of a series of Monte Carlo runs or simulations. The following code demonstrates how one can generate the frequency distribution in Mathematica.

\(\(\( (*\ 
      The\ next\ two\ commands\ can\ be\ executed\ only\ once
	\ \ or\ you\ will\ have\ to\ restart\ Mathematica . \ 
          They
	\ \ load\ new\ commands\ in\ from\ files\ on\ \(\(disk\)\(.\)\)\ *) \)\(
\)\(<< Statistics`DataManipulation`

    << Graphics`Graphics`\)\)\)

\(\(\( (*\ 
      Generate\ some\ random\ numbers\ in\ a\ table\ and\ hisogram\ them
\ 
        and\ let\ Mathematica\ pick\ the\ \(\(bins\)\(.\)\)\ *) \)\(
\)\(
\)\(\(MyTable\  = \ 
        Table[Random[
            Real, \ {\(-0.5\), 
              0.5}], 
		\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {n, 1, 
            1000}
	\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ];\)


    Histogram[MyTable]\)\)\)

(* 
      now pick your own bins. *) 

MyBins =  
        Table[n, {n, -0.5, 0.5, 0.2}];

    Histogram[MyTable, HistogramCategories -> MyBins]

2.0 Simulating the Effect of Multiple Scattering.

From observation we know the effect of multiple scattering by the gas on a set of identical tracks moving at an angle (Subscript[θ, 0]) is to produce a Gaussian probability distribution P(θ) of the form

                                          P(θ)  = ((1/(Sqrt[2((Πσ)^2)])))(e^(-(((θ - (Subscript[θ, 0])))^2)/ 2(σ^2)))
                                         
where σ is the width of the distribution and (Subscript[θ, 0]) is the average angle of the distribution. As we step through the integration of the equations of motion, multiple scattering effects will introduce an  angular deviation from the original direction of the particle that accumulates from one step to the next. We will first solve the equations of motion for an electron moving in a magnetic field without gas. We then use an acceptance-rejection method here to generate a scattering angles that are distibuted as a Gaussian. In the next laboratory we will combine these pieces to produce the final simulation.

a. Using the new commands demonstrated above, create a function that will generate a random angle from a Gaussian distribution of width σ and centered at (0^o).  Make the new function depend only on the width of the distribution.

b. We now want to test your algorithm. Generate a table of values of the angle shift using the function you wrote in  part 2.a. Histogram the table and check that the distribution is a Gaussian.

c. What is the effect of increasing the width of the distribution?

d. How is the efficiency of the algorithm affected if you increase the range over which you select the random numbers? In other words, if you increase the size of the box that you use to pick the random points, is the algorithm faster or slower? Explain.

e. When we incorporate multiple scattering into our code we will confront the following problem. Consider a vector with components Δx and Δy. What is the angle θ of this vector with respect to the horizontal axis? Suppose θ is now rotated by Δθ (as we will do when we put in multiple scattering). What are the new x and y components of the rotated vector? What happens to the velocity vector?

3.0 Getting the 'Unscattered' Track.

When the electron passes through the magnetic field and the gas it will emerge with an angle or direction that is different from the angle it would have if the chamber was evacuated. First, we will study the trajectory when no gas is present and no multiple scattering occurs. Consider an electron moving horizontally that enters a cube-shaped chamber of side D=0.42 meters with a uniform magnetic field pointing downward with a field strength of B=2.1 × (10^(-3)) Tesla. The speed of the electron is 0.25c where c is the speed of light. The electron enters the chamber at the exact center of one face of the cube and is moving in a direction normal to that side.

a. What is the differential equation that describes the components of the velocity of the electron moving in the magnetic field? How would you obtain the components of the position from that result?

b. Use centered derivative formulas with a coupled equations approach to generate an algorithm for solving the equations in the previous part.

c. Calculate the trajectory of the electron as it enters the box and then, eventually, leaves the chamber. Plot the trajectory as a check. It's probably best to use a While loop in your integration of the equations of motion. This command permits you to check the y position of the electron at each step so that you can decide when the particle leaves the box.

d. Revise your code from the previous Part so that its last step is the calculation of the exit angle when the electron leaves the box. You won't need to generate a table of the position any more.

e. Now turn the code from Part 3.d into a function that has the speed of the electron as its variable.

f. Calculate the exit angle of the electron for v=0.25c. Make a table and plot the exit angle for different values of the electron velocity in the range v= 0.20c-0.30c. If the exit angle is different by (3^o), then what is the percent difference in the energy of those two electrons?