Skip to content

Commit 964275c

Browse files
author
Ilya Mandel
committed
Clean up random draw
1 parent 98b43d7 commit 964275c

File tree

3 files changed

+40
-22
lines changed

3 files changed

+40
-22
lines changed

compas_matlab_utils/ComparisonPlots.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ function ComparisonPlots(filename1, name1, filename2, name2)
160160
end %end of ComparisonPlots
161161

162162

163-
%Plot double compact objects; returns DCO counts
163+
%Plot double compact objects; returns DCO counts, and counts of CEs leading
164+
%to DCOs
164165
function [BNScount, NSBHcount, BBHcount, BNSCE, NSBHCE, BBHCE, CEBBH1count] = ...
165166
DCOplot(file, name, fignumber, colour, point)
166167
global Msunkg G AU

compas_matlab_utils/CosmicHistoryIntegrator.m

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
function [Zlist, MergerRateByRedshiftByZ, SFRfractionZ]=...
2-
CosmicHistoryIntegrator(filename,zlist,metallicitychoice, makeplots)
2+
CosmicHistoryIntegrator(filename, zlistformation, zlistmerger, 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, zlistdetection, Msimulated, [,makeplots])
9+
% CosmicHistoryIntegrator(filename, zlistformation, zlistmerger, [,makeplots])
1010
%
1111
% INPUTS:
1212
% filename: name of population synthesis input file
1313
% should be in COMPAS output h5 format
1414
% zlistformation: vector of redshifts at which the formation rate is
1515
% computed
1616
% zlistmerger: vector of redshifts at which the merger rate is computed
17-
% zlistdetection: vector of redshifts at which the detection rate is
18-
% computed
1917
% Msimulated: total star forming mass represented by the simulation (for
2018
% normalisation)
2119
% makeplots: if set to 1, generates a set of useful plots (default = 0)
@@ -56,7 +54,7 @@
5654
Mpc=Mpcm/c; %Gpc in seconds
5755
yr=3.15569e7; %year in seconds
5856

59-
if (nargin<2)
57+
if (nargin<3)
6058
error('Not enough input arguments.');
6159
end;
6260
if (nargin<4), makeplots=0; end;
@@ -95,17 +93,38 @@
9593
end %end of CosmicHistoryIntegrator
9694

9795

98-
%Load the data stored in COMPAS output format from a file
96+
%Load the data stored in COMPAS .h5 output format from a file
9997
%Select only binary black hole mergers of interest, and return the
10098
%component masses, metallicities, and star formation to merger delay times
101-
function [M1,M2,Z,Tdelay]=DataRead(filename, tHubble)
102-
global BH
103-
if(exist(filename, 'file')~=2),
99+
function [M1,M2,Z,Tdelay]=DataRead(file, tHubble)
100+
if(exist(file, 'file')~=2),
104101
error('Input file does not exist');
105-
end;
106-
data = importdata(filename, '\t', 2);
107-
108-
colnames=data.textdata(2,:);
102+
end;
103+
type1=h5read(file,'/BSE_Double_Compact_Objects/Stellar_Type(1)');
104+
type2=h5read(file,'/BSE_Double_Compact_Objects/Stellar_Type(2)');
105+
mass1=h5read(file,'/BSE_Double_Compact_Objects/Mass(1)');
106+
mass2=h5read(file,'/BSE_Double_Compact_Objects/Mass(2)');
107+
seedDCO=h5read(file,'/BSE_Double_Compact_Objects/SEED');
108+
merges=h5read(file,'/BSE_Double_Compact_Objects/Merges_Hubble_Time');
109+
a=h5read(file,'/BSE_Double_Compact_Objects/SemiMajorAxis@DCO');
110+
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);
119+
chirpmass=mass1.^0.6.*mass2.^0.6./(mass1+mass2).^0.2;
120+
q=mass2./mass1;
121+
seedCE=h5read(file,'/BSE_Common_Envelopes/SEED');
122+
[isCE,CEIndex]=ismember(seedDCO,seedCE);
123+
optCE=h5read(file,'/BSE_Common_Envelopes/Optimistic_CE');
124+
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+
109128
Z1index=find(strcmp(colnames,'Metallicity1'));
110129
M1index=find(strcmp(colnames,'M1'));
111130
M2index=find(strcmp(colnames,'M2'));
@@ -133,11 +152,11 @@
133152

134153
%Compute the star formation rate and lookback time (in years)
135154
%for an array of redshifts
136-
function [zvec,tL]=Cosmology()
155+
function [tL]=Cosmology(zvec)
137156
global Mpcm
138157
global Mpc
139158
global yr
140-
zmax=10; dz=0.001; zvec=0:dz:zmax;
159+
%zmax=10; dz=0.001; zvec=0:dz:zmax;
141160
Nz=length(zvec);
142161

143162
%Planck cosmology

src/BaseStar.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3907,12 +3907,10 @@ double BaseStar::DrawSNKickMagnitude(const double p_Sigma,
39073907
// use Maxwellians with sigma set in CalculateSNKickMagnitude() for other SN types
39083908
SN_EVENT thisSNevent = utils::SNEventType(m_SupernovaDetails.events.current); // current SN event
39093909
if (thisSNevent == SN_EVENT::CCSN || (thisSNevent == SN_EVENT::PPISN && OPTIONS->NatalKickForPPISN())) {
3910-
kickMagnitude = DISBERG_MANDEL_MAX_KICK + 1.0;
3911-
double rand = p_Rand; // makes it possible to adjust if p_Rand is too high, to avoid getting stuck
3912-
while (utils::Compare(kickMagnitude, DISBERG_MANDEL_MAX_KICK) > 0) { // maximum kick of 1000 km/s, following Disberg & Mandel (2025)
3913-
kickMagnitude = gsl_cdf_lognormal_Pinv(rand, DISBERG_MANDEL_MU, DISBERG_MANDEL_SIGMA);
3914-
rand = 0.99 * rand;
3915-
}
3910+
// maximum kick of DISBERG_MANDEL_MAX_KICK = 1000 km/s, following Disberg & Mandel (2025)
3911+
// normalise the draw so that the kick is uniformly drawn from the inverse CDF below this maximum
3912+
double cdfMax = gsl_cdf_lognormal(DISBERG_MANDEL_MAX_KICK, DISBERG_MANDEL_MU, DISBERG_MANDEL_SIGMA);
3913+
kickMagnitude = gsl_cdf_lognormal_Pinv(p_Rand*cdfMax, DISBERG_MANDEL_MU, DISBERG_MANDEL_SIGMA);
39163914
}
39173915
else
39183916
kickMagnitude = DrawKickMagnitudeDistributionMaxwell(p_Sigma, p_Rand);

0 commit comments

Comments
 (0)