Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALApps 10.1.0.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
lalapps_string_cs_gamma.py
Go to the documentation of this file.
1##python
2#
3# Copyright (C) 2007 Xavier Siemens
4# Copyright (C) 2010 Andrew Mergl
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with with program; see the file COPYING. If not, write to the
18# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19# MA 02110-1301 USA
20#
21
22#/*********************************************************************************/
23#/* Cosmic string burst rate computation code for small loops */
24#/* */
25#/* Xavier Siemens, Jolien Creighton, Irit Maor */
26#/* */
27#/* UWM/Caltech - September 2006 */
28#/*********************************************************************************/
29
30#Port to Python from the C program cs_gamma.c
31#Original C source code by Xavier Seimens
32#Port by Andrew Mergl, June 2010
33
34from __future__ import print_function
35
36import math
37import numpy
38from optparse import OptionParser
39import scipy.integrate
40import sys
41
42from lalburst import cs_gamma
43from lalburst import git_version
44
45#Constants from cs_lambda_cosmo.h
46LAMBDA_Z_EQ = 5440.0
47LAMBDA_H_0 = 2.27e-18
48LAMBDA_OMEGA_M = 0.279
49LAMBDA_OMEGA_R = 8.5e-5
50LOOPS_RAD_POWER = 50.0 # Gamma
51CUSPS_PER_LOOP = 1.0 # c
52P = 1.0 # reconnection probability
53
54
56 parser = OptionParser(
57 version = "Name: %%prog\n%s" % git_version.verbose_msg
58 )
59 parser.add_option("-a", "--frequency", type="float", help="Lowest frequency.")
60 parser.add_option("-b", "--Gmustart", type="float", help="Lowest Gmu.")
61 parser.add_option("-c", "--Gmuend", type="float", help="Largest Gmu.")
62 parser.add_option("-d", "--nGmu", type="int", help="Nubmer of Gmu bins to do.")
63 parser.add_option("-e", "--epsilonstart", type="float", help="Lowest epsilon")
64 parser.add_option("-f", "--epsilonend", type="float", help="Largest epsilon.")
65 parser.add_option("-g", "--nepsilon", type="int", help="Number of epsilon bins to do")
66 parser.add_option("-i", "--index", type="float", help="Index for alpha as function of Gmu")
67 parser.add_option("-m", "--efficiency-file", type="string", help="File with efficiency values and errors.")
68 options, filenames = parser.parse_args()
69
70 required_options = ["efficiency_file", "frequency", "Gmustart", "Gmuend", "nGmu", "epsilonstart", "epsilonend", "nepsilon", "index"]
71 missing_options = [option for option in required_options if getattr(options, option) is None]
72 if missing_options:
73 raise ValueError("missing required option(s) %s" % ", ".join("--%s" % option.replace("_", "-") for option in missing_options))
74 assert options.nGmu >= 2
75 assert options.nepsilon >= 2
76
77 return options, (filenames or [None])
78
79#------------------------------------------------------------------------------
80# Main
81#------------------------------------------------------------------------------
82
83
84ops, files = parse_command_line()
85
86#Open the efficiency file and read the three columns into three arrays
87amp, eff, Deff = numpy.loadtxt(ops.efficiency_file, dtype="double", unpack=True)
88
89#Open the output file and print the header
90outfile = open("gamma.dat", 'w')
91outfile.write('% p n epsilon Gmu gammaAverage gammaMin gammaMax\n')
92for i in range(ops.nepsilon):
93 epsilon = math.exp(math.log(ops.epsilonstart) + i * (math.log(ops.epsilonend) - math.log(ops.epsilonstart)) / (ops.nepsilon - 1))
94 for j in range(ops.nGmu):
95 Gmu = math.exp(math.log(ops.Gmustart) + j * (math.log(ops.Gmuend) - math.log(ops.Gmustart)) / (ops.nGmu - 1))
96 print("%.1f%%: Gmu=%10.4g, epsilon=%10.4g, p=%4.2g\r" % (100.0 * (i * ops.nGmu + j) / (ops.nepsilon * ops.nGmu), Gmu, epsilon, P), end=' ', file=sys.stderr)
97
98 alpha = epsilon * (LOOPS_RAD_POWER * Gmu)**ops.index
99
100 zofA = cs_gamma.findzofA(Gmu, alpha, amp)
101 dRdz = cs_gamma.finddRdz(Gmu, alpha, ops.frequency, LOOPS_RAD_POWER, zofA)
102
103 Dlnz = numpy.log(zofA[1:]) - numpy.log(zofA[:-1])
104
105 gammaAverage = scipy.integrate.simps(eff[:-1] * zofA[:-1] * dRdz[:-1] * -Dlnz) * CUSPS_PER_LOOP / P
106 gammaMin = scipy.integrate.simps(numpy.clip(eff[:-1] - Deff[:-1], 0.0, 1.0) * zofA[:-1] * dRdz[:-1] * -Dlnz) * CUSPS_PER_LOOP / P
107 gammaMax = scipy.integrate.simps(numpy.clip(eff[:-1] + Deff[:-1], 0.0, 1.0) * zofA[:-1] * dRdz[:-1] * -Dlnz) * CUSPS_PER_LOOP / P
108
109 outfile.write("%.17g %.17g %.17g %.17g %.17g %.17g %.17g\n" % (P, ops.index, epsilon, Gmu, gammaAverage, gammaMin, gammaMax))
110print("100.0%%: Gmu=%10.4g, epsilon=%10.4g, p=%4.2g" % (Gmu, epsilon, P), file=sys.stderr)