Skip to content

Commit 525f65b

Browse files
committed
Enhanced multi-tracer nside aiming
1 parent f010b22 commit 525f65b

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

grid_covariance.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,28 +182,31 @@ int main(int argc, char *argv[]) {
182182
// Create grid(s) and see if the particle density is acceptable
183183
bool nside_local_success = true; // assume this attempt succeeded be default, can be unset
184184
int index;
185+
Float grid_density[max_no_fields];
185186
for (index = 0; index < no_fields; index++) {
186187
// Now ready to compute!
187188
// Sort particles into grid(s)
188189
Float nofznorm = par.nofznorm;
189190
if (index == 1) nofznorm = par.nofznorm2;
190191
Grid tmp_grid(all_particles[index], all_np[index], par.rect_boxsize, par.cellsize, par.nside, shift, nofznorm);
191192

192-
Float grid_density = (Float)tmp_grid.np/tmp_grid.nf;
193+
grid_density[index] = (Float)tmp_grid.np/tmp_grid.nf;
193194
printf("\n RANDOM CATALOG %d DIAGNOSTICS:\n", index+1);
194-
printf("Average number of particles per grid cell = %6.2f\n", grid_density);
195-
if (grid_density > max_density) {
195+
printf("Average number of particles per grid cell = %6.2f\n", grid_density[index]);
196+
if (grid_density[index] > max_density) {
196197
nside_local_success = false; // unset this attempt's success flag
197198
Float aimed_density = cbrt(max_density * max_density * min_density); // aim for density between the limits but closer to max
198-
Float nside_approx = cbrt(grid_density/aimed_density) * par.nside; // approximate value of nside to reach this density
199+
if (index) aimed_density = sqrt(max_density * min_density * grid_density[index] / grid_density[0]); // for two tracers, if the failure happens for the second tracer, effectively aim the geometric mean density of the two tracers at the geometric mean of the limits. specifically, put the naively aimed densities for both tracers equally close to the limits in log-space. this is the aimed density for the second tracer = sqrt(max_density * min_density) * sqrt(grid_density[1] / grid_density[0]), the expectation for the first tracer would then be sqrt(max_density * min_density) * sqrt(grid_density[0] / grid_density[1]). the previous method would not reach a resolution if the tracer densities come close to or above (max_density/min_density)^(2/3) = 4. the new method should be able to push the limit closer to max_density/min_density = 8, but it will probably fail a bit earlier because the aim is approximate due to discreteness
200+
Float nside_approx = cbrt(grid_density[index]/aimed_density) * par.nside; // approximate value of nside to reach this density
199201
par.nside = 2 * (int)round((nside_approx + 1)/2) - 1; // round to closest odd integer
200202
printf("# INFO: Average particle density exceeds maximum advised particle density (%.0f particles per cell). Setting nside=%d.\n", max_density, par.nside);
201203
break; // terminate the inner, tracer loop
202204
}
203-
if (grid_density < min_density) {
205+
if (grid_density[index] < min_density) {
204206
nside_local_success = false; // unset this attempt's success flag
205207
Float aimed_density = cbrt(max_density * min_density * min_density); // aim for density between the limits but closer to min
206-
Float nside_approx = cbrt(grid_density/aimed_density) * par.nside; // approximate value of nside to reach this density
208+
if (index) aimed_density = sqrt(max_density * min_density * grid_density[index] / grid_density[0]); // for two tracers, if the failure happens for the second tracer, effectively aim the geometric mean density of the two tracers at the geometric mean of the limits. specifically, put the naively aimed densities for both tracers equally close to the limits in log-space. this is the aimed density for the second tracer = sqrt(max_density * min_density) * sqrt(grid_density[1] / grid_density[0]), the expectation for the first tracer would then be sqrt(max_density * min_density) * sqrt(grid_density[0] / grid_density[1]). the previous method would not reach a resolution if the tracer densities come close to or above (max_density/min_density)^(2/3) = 4. the new method should be able to push the limit closer to max_density/min_density = 8, but it will probably fail a bit earlier because the aim is approximate due to discreteness
209+
Float nside_approx = cbrt(grid_density[index]/aimed_density) * par.nside; // approximate value of nside to reach this density
207210
par.nside = 2 * (int)round((nside_approx + 1)/2) - 1; // round to closest odd integer
208211
printf("# INFO: grid appears inefficiently fine (average density less than %.0f particles per cell). Setting nside=%d.\n", min_density, par.nside);
209212
break; // terminate the inner, tracer loop

0 commit comments

Comments
 (0)