34from __future__
import print_function
38from optparse
import OptionParser
42from lalburst
import cs_gamma
43from lalburst
import git_version
49LAMBDA_OMEGA_R = 8.5e-5
55 parser = OptionParser(
56 version =
"Name: %%prog\n%s" % git_version.verbose_msg
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()
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]
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
78 return options, (filenames
or [
None])
88amp, eff, Deff = numpy.loadtxt(ops.efficiency_file, dtype=
"double", unpack=
True)
89dlnA = numpy.log(amp[1:]) - numpy.log(amp[:-1])
92outfile = open(
"gamma.dat",
'w')
93outfile.write(
'% p Gmu gammaAverage gammaMin gammaMax\n')
99z = numpy.logspace(lnz_min, lnz_max, int((lnz_max-lnz_min)/dlnz)+1, base = math.e)
100dRdA = numpy.zeros(len(amp), dtype = float)
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)
108 dRdzdA = cs_gamma.finddRdzdA(Gmu, ops.frequency, LOOPS_RAD_POWER, amp, z, ops.model)
111 for k
in range(len(amp)):
112 dRdA[k] = scipy.integrate.simps(dRdzdA[k,:-1] * z[:-1] * dlnz)
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
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)