Skip to content

Commit 37db4c4

Browse files
author
Ilya Mandel
committed
Work on cosmic history integration
1 parent e412206 commit 37db4c4

File tree

2 files changed

+72
-82
lines changed

2 files changed

+72
-82
lines changed

compas_matlab_utils/CosmicHistoryIntegrator.m

Lines changed: 70 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function [Zlist, MergerRateByRedshiftByZ, SFRfractionZ]=...
2-
CosmicHistoryIntegrator(filename, zlistformation, zlistmerger, makeplots)
2+
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
@@ -13,7 +13,7 @@
1313
% should be in COMPAS output h5 format
1414
% zlistformation: vector of redshifts at which the formation rate is
1515
% computed
16-
% zlistmerger: vector of redshifts at which the merger rate is computed
16+
% zlistdetection: vector of redshifts at which the detection rate is computed
1717
% Msimulated: total star forming mass represented by the simulation (for
1818
% normalisation)
1919
% makeplots: if set to 1, generates a set of useful plots (default = 0)
@@ -54,49 +54,50 @@
5454
Mpc=Mpcm/c; %Gpc in seconds
5555
yr=3.15569e7; %year in seconds
5656

57-
if (nargin<3)
57+
if (nargin<4)
5858
error('Not enough input arguments.');
5959
end;
60-
if (nargin<4), makeplots=0; end;
60+
if (nargin<5), makeplots=0; end;
6161

6262
%cosmology calculator
63-
[zvec,tL]=Cosmology();
63+
[tL]=Cosmology(zlistformation);
6464
%load COMPAS data
65-
[M1,M2,Z,Tdelay]=DataRead(filename, max(tL));
65+
[M1,M2,Z,Tdelay]=DataRead(filename);
66+
Zlist=unique(Z);
6667
%metallicity-specific SFR
67-
[Zlist,SFR,SFRfractionZ]=Metallicity(Z,zvec,metallicitychoice);
68+
[SFR,Zweight]=Metallicity(Zlist,zlistformation);
6869

6970

7071
%Consider the contribution of every simulated binary to the merger rate
7172
%in every redshift bin by considering when it would have to be formed to
7273
%merge at that redshift and normalizing by the relevant
7374
%metallicity-specific star formation rate
74-
dz=zvec(2)-zvec(1);
75-
tLmerge=tL(floor(zlist/(zvec(2)-zvec(1)))+1);
76-
MergerRateByRedshiftByZ=zeros(length(zlist),length(Zlist));
75+
dz=zlistformation(2)-zlistformation(1);
76+
tLmerge=tL(floor(zlistformation/dz)+1);
77+
MergerRateByRedshiftByZ=zeros(length(zlistformation),length(Zlist));
7778
for(i=1:length(M1)),
7879
Zcounter=find(Zlist==Z(i));
7980
zformindex=find(tL>=Tdelay(i),1);
80-
for(k=1:length(zlist)),
81+
for(k=1:length(zlistformation)),
8182
zformindex=find(tL>=(Tdelay(i)+tLmerge(k)),1);
8283
MergerRateByRedshiftByZ(k,Zcounter)=...
8384
MergerRateByRedshiftByZ(k,Zcounter)+...
84-
SFR(zformindex)*SFRfractionZ(zformindex,Zcounter)/Msimulated;
85+
SFR(zformindex)*Zweight(zformindex,Zcounter)/Msimulated;
8586
end;
8687
end;
8788

8889
if(makeplots==1), %make a set of default plots
89-
MakePlots(M1,M2,Z,Tdelay,zvec,SFR,SFRfractionZ,...
90-
zlist,Zlist,MergerRateByRedshiftByZ);
90+
MakePlots(M1,M2,Z,Tdelay,zlistformation,Zlist,SFR,Zweight,...
91+
MergerRateByRedshiftByZ);
9192
end;
9293

9394
end %end of CosmicHistoryIntegrator
9495

9596

9697
%Load the data stored in COMPAS .h5 output format from a file
97-
%Select only binary black hole mergers of interest, and return the
98+
%Select only double compact object mergers of interest, and return the
9899
%component masses, metallicities, and star formation to merger delay times
99-
function [M1,M2,Z,Tdelay]=DataRead(file, tHubble)
100+
function [M1,M2,Z,Tdelay]=DataRead(file)
100101
if(exist(file, 'file')~=2),
101102
error('Input file does not exist');
102103
end;
@@ -108,46 +109,29 @@
108109
merges=h5read(file,'/BSE_Double_Compact_Objects/Merges_Hubble_Time');
109110
a=h5read(file,'/BSE_Double_Compact_Objects/SemiMajorAxis@DCO');
110111
e=h5read(file,'/BSE_Double_Compact_Objects/Eccentricity@DCO');
111-
mergingBBH=(type1==14) & (type2==14) & merges;
112-
BBH=(type1==14) & (type2==14);
113-
mergingBNS=(type1==13) & (type2==13) & merges;
114-
BNS=(type1==13) & (type2==13);
115-
mergingNSBH=(((type1==13) & (type2==14)) | ((type1==14) & (type2==13))) & merges;
116-
NSBH=(((type1==13) & (type2==14)) | ((type1==14) & (type2==13)));
117-
mergingDCO=mergingBNS | mergingNSBH | mergingBBH;
118-
BNScount=sum(mergingBNS); NSBHcount=sum(mergingNSBH); BBHcount=sum(mergingBBH);
112+
Ttotal=(h5read(file,'/BSE_Double_Compact_Objects/Time')+h5read(file,'/BSE_Double_Compact_Objects/Coalescence_Time'))*1e6; %to years
113+
%mergingBBH=(type1==14) & (type2==14) & merges;
114+
%BBH=(type1==14) & (type2==14);
115+
%mergingBNS=(type1==13) & (type2==13) & merges;
116+
%BNS=(type1==13) & (type2==13);
117+
%mergingNSBH=(((type1==13) & (type2==14)) | ((type1==14) & (type2==13))) & merges;
118+
%NSBH=(((type1==13) & (type2==14)) | ((type1==14) & (type2==13)));
119+
%mergingDCO=mergingBNS | mergingNSBH | mergingBBH;
120+
%BNScount=sum(mergingBNS); NSBHcount=sum(mergingNSBH); BBHcount=sum(mergingBBH);
119121
chirpmass=mass1.^0.6.*mass2.^0.6./(mass1+mass2).^0.2;
120122
q=mass2./mass1;
121123
seedCE=h5read(file,'/BSE_Common_Envelopes/SEED');
122124
[isCE,CEIndex]=ismember(seedDCO,seedCE);
123125
optCE=h5read(file,'/BSE_Common_Envelopes/Optimistic_CE');
124126
RLOFCE=h5read(file,'/BSE_Common_Envelopes/Immediate_RLOF>CE');
125-
OKCE=zeros(size(mergingDCO)); OKCE(CEIndex==0)=1; OKCE(CEIndex>0)=(~optCE(CEIndex(CEIndex>0))) & (~RLOFCE(CEIndex(CEIndex>0)));
126-
BNSCE=sum(mergingBNS & isCE & OKCE); NSBHCE=sum(mergingNSBH & isCE & OKCE); BBHCE=sum(mergingBBH & isCE & OKCE);
127-
128-
Z1index=find(strcmp(colnames,'Metallicity1'));
129-
M1index=find(strcmp(colnames,'M1'));
130-
M2index=find(strcmp(colnames,'M2'));
131-
tcindex=find(strcmp(colnames,'tc'));
132-
tformindex=find(strcmp(colnames,'tform'));
133-
type1index=find(strcmp(colnames,'stellarType1'));
134-
type2index=find(strcmp(colnames,'stellarType2'));
135-
nonRLOF=data.data(:,find(strcmp(colnames,'RLOFSecondaryAfterCEE')))==0;
136-
Pessimistic=data.data(:,find(strcmp(colnames,'optimisticCEFlag')))==0;
137-
tc=data.data(:,tcindex);
138-
tform=data.data(:,tformindex);
139-
Ttotal=(tc+tform)*1e6; %convert Megayears to years
140-
%select only binaries where both members are black holes at the last
141-
%step, the total delay time is less than the age of the Universe, there
142-
%is no Roche-lobe overflow immediately after the common-envelope phase,
143-
%and the Pessimistic common-envelope conditions are met
144-
select=Ttotal<tHubble & nonRLOF & Pessimistic & ...
145-
data.data(:,type1index)==14 & data.data(:,type2index)==14;
146-
147-
M1=data.data(select,M1index);
148-
M2=data.data(select,M2index);
149-
Z=data.data(select,Z1index);
150-
Tdelay=Ttotal(select);
127+
OKCE=zeros(size(seedDCO)); OKCE(CEIndex==0)=1; OKCE(CEIndex>0)=(~optCE(CEIndex(CEIndex>0))) & (~RLOFCE(CEIndex(CEIndex>0)));
128+
%BNSCE=sum(mergingBNS & isCE & OKCE); NSBHCE=sum(mergingNSBH & isCE & OKCE); BBHCE=sum(mergingBBH & isCE & OKCE);
129+
mergingDCO=merges & OKCE;
130+
Zsys=h5read(file,'/BSE_System_Parameters/Metallicity@ZAMS(1)');
131+
seedsys=h5read(file,'/BSE_System_Parameters/SEED');
132+
[blah,sysIndex]=ismember(seedDCO,seedsys);
133+
Zdco=Zsys(sysIndex);
134+
M1=mass1(mergingDCO); M2=mass2(mergingDCO); Z=Zdco(mergingDCO); Tdelay=Ttotal(mergingDCO);
151135
end %end of DataRead
152136

153137
%Compute the star formation rate and lookback time (in years)
@@ -157,7 +141,7 @@
157141
global Mpc
158142
global yr
159143
%zmax=10; dz=0.001; zvec=0:dz:zmax;
160-
Nz=length(zvec);
144+
Nz=length(zvec); dz=zvec(2)-zvec(1);
161145

162146
%Planck cosmology
163147
OmegaM=0.236+0.046; %2012arXiv1212.5226H
@@ -176,66 +160,72 @@
176160
end %end of Cosmology
177161

178162

179-
%Compute the fraction of star formation that happens in a given metallicity
180-
%bin as a function of redshift
181-
function [Zlist,SFR,SFRfractionZ]=Metallicity(zvec,Z)
163+
%Compute the weight of each star-forming metallicity as a function of redshift
164+
function [SFR,Zweight]=Metallicity(Zvec, zvec)
182165
%M_/odot per Mpc^3 per year -- Neijssel+ 2019 preferred model
183166
%would be SFR=0.015*(1+zvec).^2.7./(1+((1+zvec)/2.9).^5.6) in Madau & Dickinson, 2014, (15)
184167
SFR=0.01*(1+zvec).^2.77./(1+((1+zvec)/2.9).^4.7);
185-
Zmean=0.035.*10.^(-0.23*zvec);
186-
Zmu=log(Zmean)-0.39^2/2;
187-
dlogZ=0.01;
188-
logZvec=-12:dlogZ:0; %natural log
189-
dPdlogZ=1/0.39/sqrt(2*pi)*exp(-(logZvec'-Zmu).^2/2/0.39^2);
190-
dPdlogZ=dPdlogZ./(sum(dPdlogZ,1)*dlogZ); %normalise
191-
Zrange=log(max(Z))-log(min(Z)); %ugly correction for not including tails
192-
PdrawZ=1/Zrange;
193-
minlogZindex=find(exp(logZvec)>=min(Z),1, 'first');
194-
maxlogZindex=find(exp(logZvec)<=max(Z),1, 'last');
195-
dPdlogZ(minlogZindex,:)=dPdlogZ(minlogZindex,:)+sum(dPdlogZ(1:minlogZindex,:),1)*dlogZ/(sum(Z==min(Z))/length(Z))*PdrawZ;
196-
dPdlogZ(maxlogZindex,:)=dPdlogZ(maxlogZindex,:)+sum(dPdlogZ(maxlogZindex:end,:),1)*dlogZ/(sum(Z==max(Z))/length(Z))*PdrawZ;
197-
dPdlogZ=dPdlogZ./(sum(dPdlogZ,1)*dlogZ); %normalise
168+
if(length(Zvec)>1),
169+
Zmean=0.035.*10.^(-0.23*zvec);
170+
Zmu=log(Zmean)-0.39^2/2;
171+
dlogZ=0.01;
172+
logZvec=-12:dlogZ:0; %natural log
173+
dPdlogZ=1/0.39/sqrt(2*pi)*exp(-(logZvec'-Zmu).^2/2/0.39^2);
174+
dPdlogZ=dPdlogZ./(sum(dPdlogZ,1)*dlogZ); %normalise
175+
Zrange=log(max(Zvec))-log(min(Zvec)); %ugly correction for not including tails
176+
PdrawZ=1/Zrange;
177+
minlogZindex=find(exp(logZvec)>=min(Zvec),1, 'first');
178+
maxlogZindex=find(exp(logZvec)>=max(Zvec),1, 'last');
179+
dPdlogZ(minlogZindex,:)=dPdlogZ(minlogZindex,:)+sum(dPdlogZ(1:minlogZindex,:),1)*dlogZ/(sum(Zvec==min(Zvec))/length(Zvec))*PdrawZ;
180+
dPdlogZ(maxlogZindex,:)=dPdlogZ(maxlogZindex,:)+sum(dPdlogZ(maxlogZindex:end,:),1)*dlogZ/(sum(Zvec==max(Zvec))/length(Zvec))*PdrawZ;
181+
dPdlogZ(1:minlogZindex,:)=0; dPdlogZ(maxlogZindex:size(dPdlogZ,1),:)=0;
182+
dPdlogZ=dPdlogZ./(sum(dPdlogZ,1)*dlogZ); %normalise
183+
for(i=1:length(Zvec))
184+
index=find(exp(logZvec)>=Zvec(i), 1, 'first');
185+
Zweight(:,i)=dPdlogZ(index,:)*dlogZ;
186+
end;
187+
else %relevant for single-metallicity runs -- just give all binaries the same unit weight
188+
Zweight(1:length(zvec),1:length(Zvec))=1;
189+
end;
198190
end %end of Metallicity
199191

200192

201193
%Make a set of default plots
202-
function MakePlots(M1,M2,Z,Tdelay,zvec,SFR,SFRfractionZ,...
203-
zlist,Zlist,MergerRateByRedshiftByZ)
194+
function MakePlots(M1,M2,Z,Tdelay,zvec,Zlist,SFR,Zweight,...
195+
MergerRateByRedshiftByZ)
204196

205197
figure(1),colormap jet;
206-
plot(zlist, MergerRateByRedshiftByZ, 'LineWidth', 2),
198+
plot(zvec, MergerRateByRedshiftByZ*1e9, 'LineWidth', 2),
207199
legend(num2str(Zlist)),
208200
set(gca, 'FontSize', 20); %for labels
209201
xlabel('z'),
210-
ylabel('Pessimistic non-RLOF BBH merger rate, per Gpc^3 per yr')
211-
disp(['Total BBH merger rate at z=0: ', ...
202+
ylabel('DCO merger rate per Gpc^3 per yr')
203+
disp(['Total DCO merger rate at z=0: ', ...
212204
num2str(sum(MergerRateByRedshiftByZ(:,1))),...
213205
' per Gpc^3 per year']);
214206

215-
216207
figure(2), colormap jet;
217208
scatter(M1,M2,20,log(Z)/log(10),'filled');
218209
set(gca, 'FontSize', 20); %for labels
219210
H=colorbar; H.Label.String='log_{10} metallicity';
220-
xlabel('Primary BH mass [M_o]'), ylabel('Secondary BH mass [M_o]');
211+
xlabel('Primary mass [M_o]'), ylabel('Secondary mass [M_o]');
221212

222213
figure(3), colormap jet;
223-
scatter(M1+M2,log(Tdelay/1e6)/log(10),20,log(Z)/log(10),'filled');
214+
scatter(M1+M2,log10(Tdelay/1e6),20,log10(Z),'filled');
224215
set(gca, 'FontSize', 20); %for labels
225216
H=colorbar; H.Label.String='log_{10} metallicity';
226-
xlabel('Total BBH mass [M_o]'), ylabel('log(Tdelay/Myr)');
217+
xlabel('Total DCO mass [M_o]'), ylabel('log_{10}(Tdelay/Myr)');
227218

228219
figure(4), colormap jet;
229-
plot(zvec, SFR)
220+
plot(zvec, SFR*1e9)
230221
set(gca, 'FontSize', 20); %for labels
231222
xlabel('z'), ylabel('Star-formation rate, M_o per Gpc^3 per yr');
232-
233223

234224
figure(5), colormap jet;
235-
plot(zvec, SFRfractionZ)
225+
plot(zvec, Zweight)
236226
set(gca, 'FontSize', 20); %for labels
237227
legend(num2str(Zlist))
238-
xlabel('z'), ylabel('Z-specific SFR fraction');
228+
xlabel('z'), ylabel('Z-specific SFR weight');
239229

240230
end %end of MakePlots
241231

online-docs/pages/quick-links.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ Quick Links
66

77
./User guide/Program options/program-options-list-defaults
88
./User guide/COMPAS output/standard-logfiles-record-types
9-
./User guide/COMPAS output/standard-logfiles-record-specification-stellar.html
10-
./User guide/COMPAS output/standard-logfiles-record-specification-binary.html
9+
./User guide/COMPAS output/standard-logfiles-record-specification-stellar
10+
./User guide/COMPAS output/standard-logfiles-record-specification-binary
1111
./how-to-cite

0 commit comments

Comments
 (0)