In attachment are the files.
I “tarred” them so that the structure is maintained. The file Plot.C is instead a stand alone routine.
Makefile compiles what is in Roottalk.tar.gz.
To launch the program after compilation:
./step13 -1 -300000 90 0.0005 0.010 0.00075
The program calculates the space charge effects felt by an electron (-1 in the line above) generated between two electrodes. The distance between the 2 electrodes is 10 cm (it goes from y=-5 cm to y = +5 cm) and the electric field is -300000 V/m (second argument in the line to launch the routine). A proton beam of energy 90 MeV (third argument in the line to launch the routine) is travelling along the z direction passing through the middle of an ionization chamber. The proton beam has the following widths:
sigma_x =0.0005 m, sigma_y = 0.01 m, sigma_z= 0.00075 m (given in the line to launch the program).
The electron was generated between the two electrodes, at a position:
- x sampled with a Gaussian distribution around 0 with sigma = sigma_x
- y sampled with a Gaussian distribution around 0 with sigma = sigma_y
- z sampled with Uniformly between -2.5 and 2.5 mm
Once the electron has been tracked all along the y direction (up to y = +5 cm), a TTree is Filled (but not saved up to the end of the program) and another electron is generated. The number of electrons generated is fixed by the variable “test” in Step13.C.
For this particular case (Ey = -300000 V/m, Proton_Energy = 90 MeV, sigma_x =0.0005 m, sigma_y = 0.01 m, sigma_z= 0.00075 m) the first time the program fails on my laptop is at test = 651.
The program uses an adaptive Runge-Kutta routine (partly copied from MATLAB) to determine for some times the position x,y,z of the electron (and since I am not a great programmer is rather slow…).
An array of times (“time”) is given as input, but the program does not really use it.
It somehow overwrites it and copy the new times chosen by itself in the array “vremia”.
Since the steps in y are defined by the “dt” chosen by program (and therefore the electron in the last step can cross the electrode passing for example from y=4.9 cm to y=5.1 cm) the program stops tracking the electron when the condition y_electron>5 cm is fulfilled. At this point a Spline is used to fit the data and find at which moment y=5 cm was reached.
Finally, in order not to save too many data, only the positions at the times = “timen” are saved.
They are obtain by fitting the spline at the times “timen”.
When the program fails, it writes on a Data.dat file:
“BEFORE” , vremia, y <-- for all the track, but the last step (since for the last step of “vremia” is overwritten with the value of the fit of the spline at y=5cm)
"BEFORE " ,variable_for_checking_t, variable_for_checking_t <— for the last step (variable_for_checking_t contains the vremia[last_step] value before it was overwritten)
"PROCESSED " vremia[length], distance <----- last step. vremia[length] is obtained by the fit of the spline
"AFTER ", timen, y <— from the spline. And they are all correct, in the sense that for that particular t, you’d obtain that y. So I really do not understand why the step “LAST” fails instead.
Have I made a mistake somewhere, pls?
If you open the Data.dat file, copy the data in the lines “BEFORE” to another file (ex. test.dat) and use the Plot.C (after cutting away the word “BEFORE” from every line) to fit them with a spline and ask it to give you the time when the electron reached the position y = +5cm, a value different from the one obtained in Data.dat, "entry = “PROCESSED” is obtained (and this value makes sense).
I am sorry the program is such a mess.
Spline.C (1.96 KB)
Roottalk.tar.gz (12.8 KB)