{"id":26507490,"url":"https://github.com/milescb/lucomptonscatter","last_synced_at":"2025-03-20T23:20:01.556Z","repository":{"id":122356723,"uuid":"455344360","full_name":"milescb/LUComptonScatter","owner":"milescb","description":"Package for data analysis specific to Lawrence University Compton scattering experiment ","archived":false,"fork":false,"pushed_at":"2022-02-27T16:19:17.000Z","size":829,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-07-29T22:46:45.630Z","etag":null,"topics":["compton-scattering","julia","peak-detection"],"latest_commit_sha":null,"homepage":"","language":"Julia","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/milescb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-02-03T22:07:03.000Z","updated_at":"2023-07-29T22:46:52.468Z","dependencies_parsed_at":"2023-07-29T22:46:52.198Z","dependency_job_id":"ab0fc862-96f0-43b2-a289-fc21d76721ee","html_url":"https://github.com/milescb/LUComptonScatter","commit_stats":null,"previous_names":["milescb/lucomptonscatter"],"tags_count":1,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milescb%2FLUComptonScatter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milescb%2FLUComptonScatter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milescb%2FLUComptonScatter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milescb%2FLUComptonScatter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/milescb","download_url":"https://codeload.github.com/milescb/LUComptonScatter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244706541,"owners_count":20496571,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compton-scattering","julia","peak-detection"],"created_at":"2025-03-20T23:20:00.977Z","updated_at":"2025-03-20T23:20:01.546Z","avatar_url":"https://github.com/milescb.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lawrence University Compton Scattering Experiment\n\nThis package includes functions for use in the analysis of compton scattering data for an experiment at Lawrence University. \n\n## Installation \n\nIn order to install this package run the following in the `julia` REPL:\n\n```\njulia\u003e using Pkg\n\njulia\u003e Pkg.add(url=\"https://github.com/lvb5/LUComptonScatter.git\")\n```\n\nor use the package manager by typing \"]\" in the REPL and then\n\n```\npkg\u003e add https://github.com/lvb5/LUComptonScatter.git\n```\n\nEach function is well documented. To get help on a certain function, type ? then the function's name. \n\n## Dependencies\n\nThis package requires the following additional packages:\n\n- `DataFrames.jl`\n- `Findpeaks.jl`\n- `Interpolations.jl`\n- `LsqFit.jl`\n- `Smoothers.jl`\n\n`Findpeaks.jl` must be downloaded from their [GitHub page](https://github.com/tungli/Findpeaks.jl).\n\n## Peak Finding\n\nSay we take a set of data and want to perform some analysis of it. The following code performs a standard analysis of a data sample\n\n```julia\nusing LUComptonScatter, Plots\n\n#function determined from calibration\nf(x) = 0.669462 * x + 55.3071\n\ndata = read_Txt(\"/path/to/file.Txt\")\nx0, y0 = get_xy_data(data, 100, f)\n\n# Plot raw data\nplot(x0, y0, label = \"data\", xlabel = \"Energy [keV]\", ylabel = \"Counts\", legend=:topleft)\n\n# extract smoothed curve and peak data\npeaks, ySmooth = peak_parameters(x0, y0, 25, 1000.0, 0.5)\n\n#plot this new data\nplt = plot(x0, ySmooth, label = \"data\", xlabel = \"Energy [keV]\", ylabel = \"Counts\", legend=:topleft)\nfor i in 1:length(peaks)\n    scatter!(x0[peaks[i]], ySmooth[peaks[i]], label = \"Peak Data $i\")\nend\ndisplay(plt)\n\n##extract value of peak\nresult, error = fit_to_gauss(x0, y0, peaks[1])\nresult[3], error[3]\n```\nPlots of the raw data and the smoothed data with extreme points located are shown below\n\n\u003cimg src=\"https://github.com/lvb5/LUComptonScatter/blob/master/examples/plot2.png\" width=\"300\"/\u003e \u003cimg src=\"https://github.com/lvb5/LUComptonScatter/blob/master/examples/plot1.png\" width=\"300\"/\u003e \n\nThe value returned by `fit_to_gauss()` is a vector containing the fit parameters and their uncertainty. Notice that this uncertainty will be relatively small. Most uncertainty comes from calibration of the instrument. This is generally the value we care about when analyzing data from the detector. \n\n## Data Fitting \n\nOnce we have found peak energies for various scattering angle, we wish to fit this to the compton formula. This is accomplished using a reduced chi squared method. An example to implement this is shown below \n\n```julia\nusing CSV, DataFrames, Plots, LaTeXStrings, LUComptonScatter\n\ndf = DataFrame(CSV.File(\"/path/to/data.csv\"))\nx = df[!,1]\ny = df[!,2]\n\n#inverse of fit function, to go from energy to channel\nf_inverse(x) = (x + 0.1221) / 0.739\n#calculate uncertainty from uncertainty propogation\nenergy_uncertainty(x) = sqrt((0.02627 * x)^2 + 16.4079^2)\n#get them uncerainty values in energy\nσy = energy_uncertainty.(f_inverse.(y))\n\n#compute paramters and error from reduced chi^2\nE, σE, m, σm, chiSq = scan_box(610.0, 700.0, 460.0, 540.0, x, y, σy, 0.08)\n\nprintln(\"E = $E ± $σE; mₑ = $m ± $σm\") #print result\n\n#data for fit plotting\nxFit = LinRange(0, x[length(x)], 1000)\nyFit = compton(xFit, [E, m])\nchiOut = round(chiSq, digits=2)\n\n#plot results\nscatter(x, y, yerror = σy,\n        label = \"Data\", \n        xlabel = \"Scattering Angle [degrees]\", \n        ylabel = \"Energy [keV]\", \n        dpi = 500, size = (350, 350))\nplot!(xFit, yFit, label = L\"Fit: $\\chi^2/\\textrm{dof} = %$chiOut$\")\n```\nThis produces the following plot\n\n\u003cimg src=https://github.com/lvb5/LUComptonScatter/blob/master/examples/scatteredPlotEg.png width=\"400\"\u003e\n\nand paramters E = 657.8125 ± 2.8125, mₑ = 517.5 ± 2.5 which agree with expected values within three standard deviations. \n\n## Contribution\n\nPull requests are encouraged!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilescb%2Flucomptonscatter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmilescb%2Flucomptonscatter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilescb%2Flucomptonscatter/lists"}