Skip to content

Commit e991085

Browse files
author
Ilya Mandel
committed
Cosmic Integrator
1 parent 30ff94c commit e991085

File tree

1 file changed

+40
-27
lines changed

1 file changed

+40
-27
lines changed

compas_matlab_utils/CosmicHistoryIntegrator.m

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
function [Zlist, MergerRateByRedshiftByZ, SFRfractionZ]=...
1+
function [Zlist, MergerRateByRedshiftByZ, SFR, Zweight]=...
22
CosmicHistoryIntegrator(filename, zlistformation, zlistdetection, Msimulated, makeplots)
33
% Integrator for the binary black hole merger rate over cosmic history
44
% COMPAS (Compact Object Mergers: Population Astrophysics and Statistics)
55
% software package
66
%
77
% USAGE:
88
% [Zlist, MergerRateByRedshiftByZ]=...
9-
% CosmicHistoryIntegrator(filename, zlistformation, zlistmerger, [,makeplots])
9+
% CosmicHistoryIntegrator(filename, zlistformation, zlistmerger, [,makeplots, filename2, name1, name2])
1010
%
1111
% INPUTS:
1212
% filename: name of population synthesis input file
@@ -25,6 +25,8 @@
2525
% year of source time
2626
%
2727
% EXAMPLE:
28+
% CosmicHistoryIntegrator('~/Work/COMPASresults/runs/Zdistalpha1-031803.h5', ...
29+
% zlist, zlist, 90e6, 1, '~/Work/COMPASresults/runs/Zdist2stage-031803.h5', 'Default', '2 Stage')
2830
% zlist=0:0.1:5;
2931
% filename=['~/Work/COMPASresults/popsynth/runs/',...
3032
% '20170628-Coen-Pessimistic/AllMergers.dat'];
@@ -60,12 +62,11 @@
6062
if (nargin<5), makeplots=0; end;
6163

6264
%cosmology calculator
63-
[tL]=Cosmology(zlistformation);
65+
[tL]=Cosmology(zlistformation);
6466
%load COMPAS data
6567
[M1,M2,Z,Tdelay]=DataRead(filename);
66-
Zlist=unique(Z);
6768
%metallicity-specific SFR
68-
[SFR,Zweight]=Metallicity(Zlist,zlistformation);
69+
[SFR,Zlist,Zweight]=Metallicity(zlistformation,min(Z),max(Z));
6970

7071

7172
%Consider the contribution of every simulated binary to the merger rate
@@ -76,7 +77,7 @@
7677
tLmerge=tL(floor(zlistformation/dz)+1);
7778
MergerRateByRedshiftByZ=zeros(length(zlistformation),length(Zlist));
7879
for(i=1:length(M1)),
79-
Zcounter=find(Zlist==Z(i));
80+
Zcounter=find(Zlist>=Z(i),1);
8081
zformindex=find(tL>=Tdelay(i),1);
8182
for(k=1:length(zlistformation)),
8283
zformindex=find(tL>=(Tdelay(i)+tLmerge(k)),1);
@@ -88,7 +89,7 @@
8889

8990
if(makeplots==1), %make a set of default plots
9091
MakePlots(M1,M2,Z,Tdelay,zlistformation,Zlist,SFR,Zweight,...
91-
MergerRateByRedshiftByZ);
92+
MergerRateByRedshiftByZ, 1);
9293
end;
9394

9495
end %end of CosmicHistoryIntegrator
@@ -161,21 +162,22 @@
161162

162163

163164
%Compute the weight of each star-forming metallicity as a function of redshift
164-
function [SFR,Zweight]=Metallicity(Zvec, zvec)
165+
function [SFR,Zvec,Zweight]=Metallicity(zvec,minZ,maxZ)
165166
%M_/odot per Mpc^3 per year -- Neijssel+ 2019 preferred model
166167
%would be SFR=0.015*(1+zvec).^2.7./(1+((1+zvec)/2.9).^5.6) in Madau & Dickinson, 2014, (15)
167168
SFR=0.01*(1+zvec).^2.77./(1+((1+zvec)/2.9).^4.7);
168-
if(length(Zvec)>1),
169+
if(maxZ>minZ),
169170
Zmean=0.035.*10.^(-0.23*zvec);
170171
Zmu=log(Zmean)-0.39^2/2;
171-
dlogZ=0.01;
172+
dlogZ=0.1;
172173
logZvec=-12:dlogZ:0; %natural log
173174
dPdlogZ=1/0.39/sqrt(2*pi)*exp(-(logZvec'-Zmu).^2/2/0.39^2);
174175
dPdlogZ=dPdlogZ./(sum(dPdlogZ,1)*dlogZ); %normalise
175-
Zrange=log(max(Zvec))-log(min(Zvec)); %ugly correction for not including tails
176+
minlogZindex=find(exp(logZvec)>=minZ,1, 'first');
177+
maxlogZindex=find(exp(logZvec)>=maxZ,1, 'first');
178+
Zrange=logZvec(maxlogZindex)-logZvec(minlogZindex); %ugly correction for not including tails
176179
PdrawZ=1/Zrange;
177-
minlogZindex=find(exp(logZvec)>=min(Zvec),1, 'first');
178-
maxlogZindex=find(exp(logZvec)>=max(Zvec),1, 'last');
180+
Zvec=exp(logZvec(minlogZindex:maxlogZindex));
179181
dPdlogZ(minlogZindex,:)=dPdlogZ(minlogZindex,:)+sum(dPdlogZ(1:minlogZindex,:),1)*dlogZ/(sum(Zvec==min(Zvec))/length(Zvec))*PdrawZ;
180182
dPdlogZ(maxlogZindex,:)=dPdlogZ(maxlogZindex,:)+sum(dPdlogZ(maxlogZindex:end,:),1)*dlogZ/(sum(Zvec==max(Zvec))/length(Zvec))*PdrawZ;
181183
dPdlogZ(1:minlogZindex,:)=0; dPdlogZ(maxlogZindex:size(dPdlogZ,1),:)=0;
@@ -185,44 +187,55 @@
185187
Zweight(:,i)=dPdlogZ(index,:)*dlogZ;
186188
end;
187189
else %relevant for single-metallicity runs -- just give all binaries the same unit weight
188-
Zweight(1:length(zvec),1:length(Zvec))=1;
190+
Zvec=minZ;
191+
Zweight=ones(length(zvec),1);
189192
end;
190193
end %end of Metallicity
191194

192195

193196
%Make a set of default plots
194197
function MakePlots(M1,M2,Z,Tdelay,zvec,Zlist,SFR,Zweight,...
195-
MergerRateByRedshiftByZ)
196-
197-
figure(1),colormap jet;
198-
plot(zvec, MergerRateByRedshiftByZ*1e9, 'LineWidth', 2),
199-
legend(num2str(Zlist)),
198+
MergerRateByRedshiftByZ, fignumber)
199+
200+
figure(fignumber), clf(fignumber); %,colormap jet;
201+
plot(zvec, sum(MergerRateByRedshiftByZ,2)*1e9, 'LineWidth', 3), hold on;
202+
plot(zvec, sum(MergerRateByRedshiftByZ(:,Zlist<=0.001),2)*1e9, 'LineWidth', 1);
203+
plot(zvec, sum(MergerRateByRedshiftByZ(:,Zlist>0.001 & Zlist<0.01),2)*1e9, 'LineWidth', 1);
204+
plot(zvec, sum(MergerRateByRedshiftByZ(:,Zlist>=0.01),2)*1e9, 'LineWidth', 1); hold off;
205+
legend('Total rate', 'From Z<=0.001', 'From 0.001<Z<0.01', 'From Z>=0.01'),
200206
set(gca, 'FontSize', 20); %for labels
201207
xlabel('z'),
202208
ylabel('DCO merger rate per Gpc^3 per yr')
203209
disp(['Total DCO merger rate at z=0: ', ...
204-
num2str(sum(MergerRateByRedshiftByZ(:,1))),...
210+
num2str(1e9*sum(MergerRateByRedshiftByZ(1,:))),...
205211
' per Gpc^3 per year']);
206212

207-
figure(2), colormap jet;
208-
scatter(M1,M2,20,log(Z)/log(10),'filled');
213+
figure(2);
214+
colormap jet;
215+
scatter(log10(M1),log10(M2),20,log(Z)/log(10),'filled');
209216
set(gca, 'FontSize', 20); %for labels
210217
H=colorbar; H.Label.String='log_{10} metallicity';
211-
xlabel('Primary mass [M_o]'), ylabel('Secondary mass [M_o]');
218+
xlabel('log_{10}(M_1/M_o)'), ylabel('log_{10}(M_2/M_o)');
212219

213-
figure(3), colormap jet;
220+
figure(3);
221+
colormap jet;
214222
scatter(M1+M2,log10(Tdelay/1e6),20,log10(Z),'filled');
215223
set(gca, 'FontSize', 20); %for labels
216224
H=colorbar; H.Label.String='log_{10} metallicity';
217225
xlabel('Total DCO mass [M_o]'), ylabel('log_{10}(Tdelay/Myr)');
226+
218227

219-
figure(4), colormap jet;
220-
plot(zvec, SFR*1e9)
228+
figure(fignumber+3), clf(fignumber+3);
229+
plot(zvec, SFR*1e9, 'LineWidth', 3); hold on;
230+
plot(zvec, SFR'.*sum(Zweight(:,Zlist<=0.001),2)*1e9, 'LineWidth', 1);
231+
plot(zvec, SFR'.*sum(Zweight(:,Zlist>0.001&Zlist<0.01),2)*1e9, 'LineWidth', 1);
232+
plot(zvec, SFR'.*sum(Zweight(:,Zlist>=0.01),2)*1e9, 'LineWidth', 1); hold off;
233+
legend('Total rate', 'From Z<=0.001', 'From 0.001<Z<0.01', 'From Z>=0.01'),
221234
set(gca, 'FontSize', 20); %for labels
222235
xlabel('z'), ylabel('Star-formation rate, M_o per Gpc^3 per yr');
223236

224237
figure(5), colormap jet;
225-
plot(zvec, Zweight)
238+
plot(zvec, Zweight, 'LineWidth', 3)
226239
set(gca, 'FontSize', 20); %for labels
227240
legend(num2str(Zlist))
228241
xlabel('z'), ylabel('Z-specific SFR weight');

0 commit comments

Comments
 (0)