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_largeloops.py
Go to the documentation of this file.
1##python
2#
3# Copyright (C) 2007 Xavier Siemens
4# Copyright (C) 2018 Daichi Tsuna
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 large 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_gammaLargeLoops.c
31#Original C source code by Xavier Siemens
32#Port by Daichi Tsuna, November 2018
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
52
53
55 parser = OptionParser(
56 version = "Name: %%prog\n%s" % git_version.verbose_msg
57 )
58 parser.add_option("-a", "--frequency", type="float", help="Lowest frequency.")
59 parser.add_option("-b", "--Gmustart", type="float", help="Lowest Gmu.")
60 parser.add_option("-c", "--Gmuend", type="float", help="Largest Gmu.")
61 parser.add_option("-d", "--nGmu", type="int", help="Number of Gmu bins to do.")
62 parser.add_option("-e", "--pstart", type="float", help="Lowest p.")
63 parser.add_option("-f", "--pend", type="float", help="Largest p.")
64 parser.add_option("-g", "--np", type="int", help="Number of p bins to do.")
65 parser.add_option("-m", "--model", metavar="Siemens06|Blanco-Pillado14|Ringeval07", type="string", help="Model of loop distribution. There are three models that can be taken in this code, the 'Siemens06' model, the 'Blanco-Pillado14' model, and the 'Ringeval07' model. See arXiv:1712.01168 for details on each model.")
66 parser.add_option("-n", "--efficiency-file", type="string", help="File with efficiency values and errors.")
67 options, filenames = parser.parse_args()
68
69 required_options = ["efficiency_file", "frequency", "Gmustart", "Gmuend", "nGmu", "pstart", "pend", "np", "model"]
70 missing_options = [option for option in required_options if getattr(options, option) is None]
71 if missing_options:
72 raise ValueError("missing required option(s) %s" % ", ".join("--%s" % option.replace("_", "-") for option in missing_options))
73 if options.model not in ("Siemens06", "Blanco-Pillado14", "Ringeval07"):
74 raise ValueError("--model \"%s\" not recognized" % options.model)
75 assert options.nGmu >= 2
76 assert options.np >= 2
77
78 return options, (filenames or [None])
79
80#------------------------------------------------------------------------------
81# Main
82#------------------------------------------------------------------------------
83
84
85ops, files = parse_command_line()
86
87#Open the efficiency file and read the three columns into three arrays
88amp, eff, Deff = numpy.loadtxt(ops.efficiency_file, dtype="double", unpack=True)
89dlnA = numpy.log(amp[1:]) - numpy.log(amp[:-1])
90
91#Open the output file and print the header
92outfile = open("gamma.dat", 'w')
93outfile.write('% p Gmu gammaAverage gammaMin gammaMax\n')
94
95#Decide the redshift range to integrate over
96lnz_min = -50.0
97lnz_max = 50.0
98dlnz = 0.1
99z = numpy.logspace(lnz_min, lnz_max, int((lnz_max-lnz_min)/dlnz)+1, base = math.e)
100dRdA = numpy.zeros(len(amp), dtype = float)
101
102for i in range(ops.np):
103 P = math.exp(math.log(ops.pstart) + i * (math.log(ops.pend) - math.log(ops.pstart)) / (ops.np - 1))
104 for j in range(ops.nGmu):
105 Gmu = math.exp(math.log(ops.Gmustart) + j * (math.log(ops.Gmuend) - math.log(ops.Gmustart)) / (ops.nGmu - 1))
106 print("%.1f%%: Gmu=%10.4g, p=%4.2g\r" % (100.0 * (i * ops.nGmu + j) / (ops.np * ops.nGmu), Gmu, P), file=sys.stderr)
107
108 dRdzdA = cs_gamma.finddRdzdA(Gmu, ops.frequency, LOOPS_RAD_POWER, amp, z, ops.model)
109
110 #Integrate over z
111 for k in range(len(amp)):
112 dRdA[k] = scipy.integrate.simps(dRdzdA[k,:-1] * z[:-1] * dlnz)
113 #Integrate over A
114 gammaAverage = scipy.integrate.simps(eff[:-1] * dRdA[:-1] * amp[:-1] * dlnA) * CUSPS_PER_LOOP / P
115 gammaMin = scipy.integrate.simps(numpy.clip(eff[:-1] - Deff[:-1], 0.0, 1.0) * dRdA[:-1] * amp[:-1] * dlnA) * CUSPS_PER_LOOP / P
116 gammaMax = scipy.integrate.simps(numpy.clip(eff[:-1] + Deff[:-1], 0.0, 1.0) * dRdA[:-1] * amp[:-1] * dlnA) * CUSPS_PER_LOOP / P
117
118 outfile.write("%.17g %.17g %.17g %.17g %.17g\n" % (P, Gmu, gammaAverage, gammaMin, gammaMax))
119print("100.0%%: Gmu=%10.4g, p=%4.2g" % (Gmu, P), file=sys.stderr)