TeamCOMPAS / COMPAS

COMPAS rapid binary population synthesis code
http://compas.science
MIT License
64 stars 66 forks source link

Analytic solution for rate normalisation from COMPAS mass cuts #378

Closed TomWagg closed 1 year ago

TomWagg commented 4 years ago

Is your feature request related to a problem? Please describe. No, I just think there is a slightly simpler way of doing this.

Describe the solution you'd like In totalMassPerZ.py, COMPAS finds the fraction of mass in COMPAS vs mass in total population in order to normalise the rates. It does this through inverse CDF sampling, but I believe it could be found analytically instead. This is both faster and also makes it so the fraction doesn't fluctuate each time.

Describe alternatives you've considered I think you can implement this by calculating the fraction like this:

image

where you can change the binary fraction, primary mass limits and secondary mass lower limit. I will post code that implements in Slack that you can use if you think this is a useful change :)

Additional context A comparison with the analytic value vs. 200 runs of the COMPAS code that calculates the same fraction with fbin=0.7, m1_min=5, m1_max=150, m2_min=0.1. I think this seems to be in agreement. image

reinhold-willcox commented 4 years ago

@TomWagg naive question: is there a reason you have (1+0.5) split up in the denominator of your equation? Should that just be 1.5, or is the 0.5 supposed to multiply with something like in the numerator?

TomWagg commented 4 years ago

@reinhold-willcox Sorry yes that should really just be 1.5. The reason I was splitting it up like that was to try to emphasise that I am summing the primary and secondary masses in case someone wasn't sure where the 1.5 came from.

ilyamandel commented 4 years ago

@TomWagg -- only comment is that it might be useful to leave the old Monte Carlo in as an option, just in case someone chooses to sample from some weird distribution that doesn't easily lend itself to analytical integration. But, of course, that's easy enough to re-include, so I am happy either way.

ilyamandel commented 2 years ago

@TomWagg -- are you still planning to implement this?

TomWagg commented 2 years ago

As I recall I didn't do it because you mentioned in Slack that it assumed uniform q which was undesirable. But I've got the code for it in my own personal stuff so would be super easy to copy over if you think it would be useful :)

ilyamandel commented 2 years ago

I think there's a broader issue that as people sample from new and exciting distributions via a grid file (whether in mass or mass ratio or metallicity), we need to think of better ways to record and process that for normalisation purposes. But let's leave this aside for now -- I think what you proposed above is a good solution for our standard default. Note, however, that I recommend using the samples to determine mass and mass ratio boundaries -- see what I mean in the new FastCosmicIntegrator which awaits your review. :)

ilyamandel commented 1 year ago

@TomWagg -- gentle ping on this as I am trying to do a bit of "issue" cleaning. :)

TomWagg commented 1 year ago

Thanks @ilyamandel and sorry for forgetting about this! I honestly probably won't have a chance to do this until the end of the spring quarter (mid-March), we're hiring two new faculty and I have a couple of classes so things are rather chaotic at the moment! Setting myself a reminder though 🙂

ilyamandel commented 1 year ago

Keeping this alive for @TomWagg . :)

avivajpeyi commented 1 year ago

Hey @TomWagg, this is awesome! If you can even upload the script here that would be helpful -- we can do the work to incorporate the code in COMPAS :)

TomWagg commented 1 year ago

Hey @avivajpeyi (+@ilyamandel ) - so sorry for taking so long to do this - I was putting it off because it required digging out my old laptop and finding this bit of code, but I (finally) did it!

I'm happy to get this into the right place - is the plan still to integrate (pun intended) it into totalMassEvolvedPerZ.py? I can make a PR for that super easily 🙂

Sorry again for my abysmal response time on this!