radiation 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+ require 'radiation'
3
+
4
+ file = "./B0-Ra226.xml"
5
+ source = Radiation::Source.new(nuclide: "Ra-226", resource: "nucleide.org")
6
+
7
+ puts ["E_ɣ", "I_ɣ", "ΔI_ɣ", "e", "Δe"].join("\t")
8
+ peaks = Radiation::Spectrum.new(source: source).parse_hdtv(file).calibrate.efficiencies.peaks.select{|p| p[:intensity] > 0.3}.sort_by{|k| k[:energy]}
9
+ peaks.each do |p|
10
+ puts "#{p[:energy].to_f.round(1)}\t#{p[:intensity].value}\t#{p[:intensity].delta}\t#{p[:efficiency].value.round(1)}\t#{p[:efficiency].delta.round(1)}"
11
+ end
12
+
13
+
14
+ require 'open3'
15
+ require 'tmpdir'
16
+
17
+ variables = ["a","b","c"]
18
+
19
+ gnuplot_commands = <<"End"
20
+ # Activate fit errors
21
+ set fit errorvariables
22
+ # Disable fit logging
23
+ set fit quiet
24
+ set fit logfile "#{Dir.tmpdir}/radiation/fit.log"
25
+ # Redirect print output to stdout
26
+ set print "-"
27
+ # Prepare fit
28
+ a = #{peaks.first[:efficiency]}
29
+ b = 0.2
30
+ c = #{peaks.first[:efficiency]}
31
+ d = 0.2
32
+ f(x) = a*exp(-b*b*x)+c#*exp(-d*d*x)
33
+ fit f(x) "-" via a,b,c#,d
34
+ End
35
+
36
+ peaks.each do |p|
37
+ gnuplot_commands << "#{p[:energy]} #{p[:efficiency]}\n"
38
+ end
39
+ gnuplot_commands << "e\n"
40
+
41
+ variables.each do |v|
42
+ gnuplot_commands << "print #{v}, #{v}_err\n"
43
+ end
44
+
45
+ values, s = Open3.capture2("gnuplot", :stdin_data=>gnuplot_commands, :binmode=>true)
46
+
47
+ puts values
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Mayer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-04 00:00:00.000000000 Z
11
+ date: 2013-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: plusminus
@@ -173,6 +173,7 @@ files:
173
173
  - samples/calibrate_a_spectrum.rb
174
174
  - samples/calibration_from_hdtv_xml.rb
175
175
  - samples/efficiencies.rb
176
+ - samples/efficiencies_fit.rb
176
177
  - samples/get_some_data.rb
177
178
  - spec/radiation_spec.rb
178
179
  - spec/spec_helper.rb