May 7
In order to make a more accurate simulation of the cosmic rays, it is necessary to simulate particles coming from all different directions instead of just from straight above. Cosmic rays fall in a cos^2(angle) distribution, meaning that the relative probability of a cosmic ray coming at an angle theta from vertical is cos(theta)^2. However, generating random numbers in a given distribution is not trivial, as computers can only generate random numbers evenly in a range. The procedure for generating random numbers in a distribution is as follows:
First take the integral of the function
Second, take the inverse of the integrated function
If you plug in random numbers evenly in a range to that function, the outputs will be distributed in the range that you wanted.
The problem is that the integral of cos^2(theta) is not invertible. So, I wrote a python script to generate a polynomial that can approximate what the function would be. This polynomial could be used in a simulation.
The code is very short so I pasted it below:
Text Box
import sympy
from sympy.abc import x
import numpy
import math
def generatePoints(f, minx, maxx, step):
x = minx
while x < maxx:
yield (x, f(x))
x += step
def makeInverse(f, bounds, degree):
"""bounds = (minimum, maximum, step)"""
minx, maxx, step = bounds
points = generatePoints(f, minx, maxx, step)
invPts = map(lambda pt: (pt[1], pt[0]), points)
xs, ys = zip(*invPts)
coeffs = numpy.polyfit(xs, ys, degree)
return sympy.Poly(coeffs, x)
def calculateDistribution():
f = lambda x: (2*x+math.sin(2*x)+math.pi)/2/math.pi
return makeInverse(f, (-math.pi/2, math.pi/2, 0.01), 100)
The above code will calculate the inverse of a function numerically and then construct a polynomial approximating it. It uses the numpy and sympy python libraries.
The function you need to run is calculateDistribution(). It has hard coded in the integral of cos^2(theta), and will calculate a polynomial approximation of its inverse. If you want to use this code for anything else, the makeInverse function is more general. It takes f, a function, bounds, a tuple of the form (minimum, maximum, step) which specifies the values that should be plugged into f to find out its shape, and finally it takes degree, which is the degree of the polynomial to be generated.
May 1
We have simulated the triangle in Geant in order to try to get the same RMS value with simulation as we did with theoretical calculations. Unfortunately, it turns out that I had made an incorrect assumption about the way that scintillators work. The graph from Geant looks like this:
The graph should be in the shape of a triangle if my previous assumptions were correct. However, after talking to Professor Eno, it turns out that while the energy deposited is proportional to the distance that the particle travels through the material, the sensor will go off at a specific threshold, and so except at the edges of the triangle the particles will always almost always trigger the detector.
Luckily, there are no calculations to redo because it works well enough to approximate the triangle as a rectangle which is as wide as the part of the triangle thick enough to detect particles.
April 26
I have redone the triangular prisms using trapezoids. This allows them to work properly. I compared what it looks like when particles go through a solid lead box (which we know works) to the triangular prisms, and it seemed to work.
Also, I have done some theoretical calculations around the RMS of a triangle.
The amount of energy deposited in a triangle by a high energy muon, which is what cosmic rays are mostly made of, is given by this function
Where h is the height of the triangle and rho is the energy deposited per distance, and x is horizontal position of the particle going through the triangle. Using this formula to calculate RMS gives
The RMS for a square/rectangle is w/sqrt(12), so as expected the RMS is lower.
April 20
I have been able to use the polygon shape in Geant to make something that looks exactly like a triangular prism. However, when I try to shoot particles through it, it seems to only sometimes affect particles and when it does it shoots them in random directions. Also, it seems to only interact with particles at its center. In short, Geant is skrewy. I will need to try in the future to make triangular prisms in some other way. Maybe the trapezoid method will work.
Heres a picture anyway:
April 13
We finished plotting things from the Geant tutorial. Out current program will use a bash script to generate a bunch or random energies. It will then run a simulation shooting particles of that energy at the detector. From that simulation, it will calculate the RMS of all of the hits it detected. It will output a root file with the histogram to a folder, and the name of the file will contain the amount of energy that the particle was generated with. Finally, a root script will iterate through all of the .root files, get the energy from their name and the RMS from the histogram inside, and plot a graph of energy vs histogram.
Also it turns out that Geant has built in polystyrene.
March 30
We have begun to w
ork on simulating plastic scintillators in Geant. Weve found a website which explains how to make triangles out of a trapezoid, and also a website explaining how to make polystyene material. The process it suggests to make polystyrene seems overly complicated. I'll have to check if Geant has the material built in.
Professor Eno showed us the scintillators. They are
March 16
I continued to work with the Geant4 tutorial. We successfully made plots of energy from the tutorial. More importantly, we practiced root by making a script which can collect data from a bunch of histograms and plot their RMSs.
We were not entirely sure about the best way to do this. We ended up storing information about energy in the filenames of the histograms, and then we scanned those into our root script. This goes against all good coding practice, but it worked.
Here is a screenshot. Additionally, all of our code is available at https://github.com/jeprinz/CosmicRayTracker/
March 9
Finished getting eclipse configured properly. The command that worked was:
cmake -DGeant4_DIR=$MYGEANT2 -G "Eclipse CDT4 - Unix Makefiles" ../code-directory
I have put helpful scripts in this github repository: https://github.com/jeprinz/GeantUtils.git
Go to that repository to see the scripts I use to run eclipse with geant. It is necessary to use Sarah Eno's geant setup script with those scripts.
We also continued to learn Geant. Here is a graph that we made (not itself useful but now we know how to make graphs):
March 1
I got tired of using emacs. In order to do serious coding, it is necessary to have a proper coding environment setup (which is possible with emacs but the cluster has an old version installed). So, I got eclipse working! Its simple: just download the eclipse installer from their website and run it. Make sure to install the CDT version (which is the C++ version)
The hard part of getting cmake:
February 29
We got Geant working! We were able to run the example code that Geant4 provides. The picture below is a picture of the B4Examplea code. The best way to learn Geant is to look through the example code in the Geant directory on cmns.
February 23
We met with our mentor Sarah Eno, and she told us about plastic scintillators. We decided that the project that we wanted to work on was to design a cosmic ray tracker to test out radiation damaged plastic scintilators.
For now, we will learn Geant4 and read up on how plastic scintillators work.