CosmicFish  Reference documentation for version 1.0
Looking into future Cosmology
009_Fisher_calculator_SN.f90
Go to the documentation of this file.
1 !----------------------------------------------------------------------------------------
2 !
3 ! This file is part of CosmicFish.
4 !
5 ! Copyright (C) 2015-2016 by the CosmicFish authors
6 !
7 ! The CosmicFish code is free software;
8 ! You can use it, redistribute it, and/or modify it under the terms
9 ! of the GNU General Public License as published by the Free Software Foundation;
10 ! either version 3 of the License, or (at your option) any later version.
11 ! The full text of the license can be found in the file LICENSE at
12 ! the top level of the CosmicFish distribution.
13 !
14 !----------------------------------------------------------------------------------------
15 
18 
19 !----------------------------------------------------------------------------------------
21 
23 
25 
26  use precision
27  use modelparams
29  use omp_lib
32 
33 #ifdef COSMICFISH_EFTCAMB
34  use eftinitialization
35 #endif
36 
37  implicit none
38 
39  private
40 
43 
44 contains
45 
46  ! ---------------------------------------------------------------------------------------------
49  subroutine observed_sn_magnitude( P, FP, sn_magnitude, redshift, color, stretch, num, err )
50 
51  implicit none
52 
53  Type(cambparams) , intent(in) :: P
54  Type(cosmicfish_params), intent(in) :: FP
55  real(dl), dimension(:), intent(out) :: sn_magnitude
56  real(dl), dimension(:), intent(in) :: redshift
57  real(dl), dimension(:), intent(in) :: color
58  real(dl), dimension(:), intent(in) :: stretch
59  integer , intent(in) :: num
62  integer, intent(out) :: err
68 
69  ! other definitions:
70  integer :: i
71  real(dl) :: alpha, beta, zero_mag
72  logical :: EFTsuccess
73  ! initialization:
74  sn_magnitude = 0._dl
75  err = 0
76 
77  call cambparams_set(p)
78 
79 #ifdef COSMICFISH_EFTCAMB
80  ! check stability if EFTCAMB is used
81  if (p%EFTflag /= 0) then
82  call eftcamb_initialization(eftsuccess)
83  if (.not. eftsuccess) then
84  write(*,*) 'EFTCAMB: unstable model'
85  err = 4
86  return
87  end if
88  end if
89 #endif
90 
91  alpha = fp%fisher_SN%alpha_SN
92  beta = fp%fisher_SN%alpha_SN
93  zero_mag = fp%fisher_SN%M0_SN
94 
95  ! compute the supernova magnitude array:
96  do i=1, num
97  sn_magnitude(i) = 5._dl*log10( luminositydistance(redshift(i)) ) &
98  & -alpha*stretch(i) +beta*color(i) + zero_mag -25._dl
99  end do
100 
101  end subroutine observed_sn_magnitude
102 
103  ! ---------------------------------------------------------------------------------------------
106  subroutine generate_sn_mock_data( P, FP, sn_mock )
108  use random_utilities
109 
110  implicit none
111 
112  Type(cambparams) , intent(in) :: P
113  Type(cosmicfish_params) , intent(in) :: FP
114  real(dl), dimension(:,:), intent(out) :: sn_mock
117 
118  ! other definitions:
119  integer :: i, j, k
120 
121  ! initialize the random number generator:
122  rand_feedback = 0
123  call initrandom()
124 
125  ! generate the mock data:
126  i = 1
127  do j=1, fp%fisher_SN%number_SN_windows
128  do k=1, fp%fisher_SN%SN_number(j)
129  sn_mock(1,i) = random_uniform( fp%fisher_SN%SN_redshift_start(j), fp%fisher_SN%SN_redshift_end(j)) ! mock redshift
130  sn_mock(2,i) = random_gaussian( 0._dl, fp%fisher_SN%color_dispersion ) ! mock color
131  sn_mock(3,i) = random_gaussian( 0._dl, fp%fisher_SN%stretch_dispersion ) ! mock stretch
132  i = i + 1
133  end do
134  end do
135 
136  end subroutine generate_sn_mock_data
137 
138  ! ---------------------------------------------------------------------------------------------
141  subroutine generate_sn_mock_covariance( P, FP, sn_mock, sn_mock_covariance )
143  use constants, only : c
144 
145  implicit none
146 
147  Type(cambparams) , intent(in) :: P
148  Type(cosmicfish_params) , intent(in) :: FP
149  real(dl), dimension(:,:), intent(in) :: sn_mock
152  real(dl), dimension(:) , intent(out) :: sn_mock_covariance
154 
155  ! other definitions:
156  integer :: i, j, k
157 
158  ! generate the mock covariance first terms:
159  do i=1, fp%fisher_SN%total_SN_number
160  sn_mock_covariance(i) = (fp%fisher_SN%magnitude_sigma)**2 &
161  & +(fp%fisher_SN%sigma_lens_0*sn_mock(1,i))**2 & ! lensing term
162  & +(5._dl/sn_mock(1,i)/log(10._dl)*fp%fisher_SN%c_sigmaz/c*1000._dl)**2 ! redshift term
163  end do
164 
165  ! add the systematic effects to the covariance:
166  do i=1, fp%fisher_SN%total_SN_number
167  sn_mock_covariance(i) = sn_mock_covariance(i) &
168  & + fp%fisher_SN%beta_SN**2*(fp%fisher_SN%dcolor_offset+fp%fisher_SN%dcolor_zcorr*sn_mock(1,i)**2)**2 &
169  & + fp%fisher_SN%alpha_SN**2*(fp%fisher_SN%dshape_offset+fp%fisher_SN%dshape_zcorr*sn_mock(1,i)**2)**2 &
170  & + 2._dl*fp%fisher_SN%alpha_SN*(fp%fisher_SN%cov_ms_offset+fp%fisher_SN%cov_ms_zcorr*sn_mock(1,i)**2) &
171  & - 2._dl*fp%fisher_SN%beta_SN*(fp%fisher_SN%cov_mc_offset+fp%fisher_SN%cov_mc_zcorr*sn_mock(1,i)**2) &
172  & - 2._dl*fp%fisher_SN%alpha_SN*fp%fisher_SN%beta_SN*(fp%fisher_SN%cov_sc_offset+fp%fisher_SN%cov_sc_zcorr*sn_mock(1,i)**2)
173  end do
174 
175  end subroutine generate_sn_mock_covariance
176 
177  ! ---------------------------------------------------------------------------------------------
179  subroutine save_sn_mock_to_file( mock_size, sn_mock_data, sn_mock_covariance, filename, magnitude )
181  implicit none
182 
183  integer , intent(in) :: mock_size
184  real(dl), dimension(:,:), intent(in) :: sn_mock_data
185  real(dl), dimension(:) , intent(in) :: sn_mock_covariance
186  character(len=*) , intent(in) :: filename
187 
188  real(dl), dimension(:) , intent(in), optional :: magnitude
190 
191  ! other definitions:
192  integer :: i
193 
194  ! write the mock:
195  open(unit=666, file=filename, action="write", status="replace")
196 
197  if ( present(magnitude) ) then
198 
199  write(666,'(a)') "# number of the SN, redshift, magnitude, color, stretch, covariance "
200  do i = 1, mock_size
201  write(666,'(I10,5E15.5)') i, sn_mock_data(1,i), magnitude(i), sn_mock_data(2,i), sn_mock_data(3,i), sn_mock_covariance(i)
202  end do
203 
204  else
205 
206  write(666,'(a)') "# number of the SN, redshift, color, stretch, covariance "
207  do i = 1, mock_size
208  write(666,'(I10,4E15.5)') i, sn_mock_data(1,i), sn_mock_data(2,i), sn_mock_data(3,i), sn_mock_covariance(i)
209  end do
210 
211  end if
212 
213  close(666)
214 
215  end subroutine save_sn_mock_to_file
216 
217  ! ---------------------------------------------------------------------------------------------
221  subroutine observed_sn_magnitude_derivative( P, FP, param_num, &
222  & mag_initial, mag_derivative, mag_der_error, &
223  & sn_mock, &
224  & initial_step, &
225  & num_param, &
226  & error_code )
228  implicit none
229 
230  Type(cambparams) , intent(in) :: P
231  Type(cosmicfish_params) , intent(in) :: FP
232 
233  integer , intent(in) :: param_num
234  integer , intent(in) :: num_param
235 
236  real(dl), dimension(:), intent(in) :: mag_initial
237  real(dl), dimension(:), intent(out) :: mag_derivative
238  real(dl), dimension(:), intent(out) :: mag_der_error
239 
240  real(dl), dimension(:,:), intent(in) :: sn_mock
241 
242  real(dl), intent(in) :: initial_step
243  integer , intent(out) :: error_code
248 
249  ! definitions:
250  real(dl), dimension(:), allocatable :: sn_temp_1, sn_temp_2, errt
251  integer , dimension(:), allocatable :: accept_mask
252  real(dl), dimension(:,:,:), allocatable :: a
253  real(dl), dimension(num_param) :: param_vector, fiducial_param_vector, temp_param_vector
254  ! parameters of the algorithm:
255  real(dl), parameter :: con = 1.4_dl ! parameter that decides the decrease in the stepsize h
256  real(dl), parameter :: big = 1.d+30 ! a big number used to fill the error array initially
257  real(dl), parameter :: safe = 2._dl ! parameter used to define the stopping cryterium
258  integer , parameter :: ntab = 30 ! maximum number of Cls computation
259  real(dl) :: con2 = con*con
260  integer :: i, j, k, l, m, side, err, AllocateStatus
261  real(dl) :: fac, hh
262  real(dl) :: temp1, temp2, temp3
263  Type(cambparams) :: P_temp
264  Type(cosmicfish_params) :: FP_temp
265  integer :: accepted
266  real(dl) :: acceptance
267  integer :: mock_sn_size
268  real(dl), dimension(:), allocatable :: redshift, color, stretch
269 
270  ! initialize output variables:
271  error_code = 0
272  mag_derivative = 0._dl
273  mag_der_error = 0._dl
274 
275  ! check input values are correct
276  if ( initial_step == 0._dl ) then
277  stop 'Observed_SN_Magnitude_derivative initial stepsize is zero'
278  end if
279 
280  mock_sn_size = fp%fisher_SN%total_SN_number
281 
282  ! allocate the arrays:
283  if ( fp%adaptivity ) then
284  allocate( sn_temp_1(mock_sn_size), &
285  & sn_temp_2(mock_sn_size), &
286  & errt(mock_sn_size), &
287  & accept_mask(mock_sn_size),&
288  & stat = allocatestatus )
289  if (allocatestatus /= 0) stop "Observed_SN_Magnitude_derivative: Allocation failed. Not enough memory"
290  allocate( a(ntab, ntab, mock_sn_size) , stat = allocatestatus )
291  if (allocatestatus /= 0) stop "Observed_SN_Magnitude_derivative: Allocation failed. Not enough memory for the derivative array"
292  else
293  allocate( sn_temp_1(mock_sn_size), &
294  & sn_temp_2(mock_sn_size), &
295  & stat = allocatestatus )
296  if (allocatestatus /= 0) stop "Observed_SN_Magnitude_derivative: Allocation failed. Not enough memory"
297  allocate( a(1,1, mock_sn_size) , stat = allocatestatus )
298  if (allocatestatus /= 0) stop "Observed_SN_Magnitude_derivative: Allocation failed. Not enough memory for the derivative array"
299  end if
300 
301  allocate( redshift(mock_sn_size), &
302  & color(mock_sn_size), &
303  & stretch(mock_sn_size), &
304  & stat = allocatestatus )
305 
306  ! copy the data from the sn mock:
307  redshift(:) = sn_mock(1,:)
308  color(:) = sn_mock(2,:)
309  stretch(:) = sn_mock(3,:)
310 
311  ! initialize the parameter array:
312  p_temp = p
313  fp_temp = fp
314 
315  call camb_params_to_params_array( p_temp, fp, num_param, param_vector )
316 
317  fiducial_param_vector = param_vector
318  temp_param_vector = param_vector
319 
320  ! initialize the computation:
321  hh = initial_step
322  mag_der_error = big
323  side = 0 ! both sides
324  if ( fp%adaptivity ) accept_mask = 0
325 
326  ! do the initial step on the right:
327  param_vector(param_num) = fiducial_param_vector(param_num) + hh
328  call params_array_to_camb_param( p_temp, fp_temp, num_param, param_vector )
329  call observed_sn_magnitude( p_temp, fp_temp, sn_temp_1, redshift, color, stretch, mock_sn_size, err )
330  ! if on the right we cannot go we go to the left:
331  if ( err /= 0 ) side = 1
332  ! do the initial step on the left:
333  temp_param_vector(param_num) = fiducial_param_vector(param_num) - hh
334  call params_array_to_camb_param( p_temp, fp_temp, num_param, temp_param_vector )
335  call observed_sn_magnitude( p_temp, fp_temp, sn_temp_2, redshift, color, stretch, mock_sn_size, err )
336 
337  ! if on the left we cannot go decide what to do:
338  if ( err /= 0 ) then
339  if ( side == 1 ) then ! we cannot go to the left nor to the right. Return derivative zero with error code.
340  error_code = 4
341  mag_der_error = 0.0_dl
342  mag_derivative = 0.0_dl
343  return
344  else if ( side == 0 ) then ! we cannot go to the left but we can go to the right:
345  side = 2
346  end if
347  end if
348 
349  ! store the results based on the side we decided to go:
350  if (side == 0) then ! both sides
351  a(1,1,:) = (sn_temp_1(:) - sn_temp_2(:))/(2.0_dl*hh)
352  else if (side == 1) then ! left side: increment negative
353  a(1,1,:) = (sn_temp_2(:) - mag_initial(:))/(-hh)
354  else if (side == 2) then ! right side: increment positive
355  a(1,1,:) = (sn_temp_1(:) - mag_initial(:))/(hh)
356  end if
357 
358  ! fixed stepsize derivative if adaptivity is not wanted:
359  if ( .not. fp%adaptivity ) then
360  mag_derivative(:) = a(1,1,:)
361  mag_der_error = 0.0_dl
362  deallocate( sn_temp_1, sn_temp_2, a )
363  return
364  end if
365 
366  ! start the derivative computation:
367  do i = 2, ntab
368 
369  ! feedback for the adaptive derivative:
370  if ( fp%cosmicfish_feedback >= 2 ) then
371  accepted = sum(accept_mask)
372  acceptance = REAL(accepted)/REAL(mock_sn_size)
373  print*, 'iteration:', i
374  print*, ' stepsize:', hh
375  print*, ' accepted elements', accepted, 'accepted ratio', acceptance
376  end if
377 
378  ! decrease the stepsize:
379  hh = hh/con
380 
381  ! compute the finite difference:
382  if (side == 0) then
383  param_vector(param_num) = fiducial_param_vector(param_num) + hh
384  temp_param_vector(param_num) = fiducial_param_vector(param_num) - hh
385  ! compute for + hh
386  call params_array_to_camb_param( p_temp, fp_temp, num_param, param_vector )
387  call observed_sn_magnitude( p_temp, fp_temp, sn_temp_1, redshift, color, stretch, mock_sn_size, err )
388  if ( err /= 0 ) then
389  error_code = 4
390  mag_der_error = 0.0_dl
391  mag_derivative = 0.0_dl
392  return
393  end if
394  ! compute for - hh
395  call params_array_to_camb_param( p_temp, fp_temp, num_param, temp_param_vector )
396  call observed_sn_magnitude( p_temp, fp_temp, sn_temp_2, redshift, color, stretch, mock_sn_size, err )
397  if ( err /= 0 ) then
398  error_code = 4
399  mag_der_error = 0.0_dl
400  mag_derivative = 0.0_dl
401  return
402  end if
403  ! store the result
404  a(1,i,:) = (sn_temp_1(:) - sn_temp_2(:))/(2.0_dl*hh)
405  else if (side==1) then
406  param_vector(param_num) = fiducial_param_vector(param_num) - hh
407  call params_array_to_camb_param( p_temp, fp_temp, num_param, param_vector )
408  call observed_sn_magnitude( p_temp, fp_temp, sn_temp_1, redshift, color, stretch, mock_sn_size, err )
409  if ( err /= 0 ) then
410  error_code = 4
411  mag_der_error = 0.0_dl
412  mag_derivative = 0.0_dl
413  return
414  end if
415  ! store the result
416  a(1,i,:) = (sn_temp_1(:) - mag_initial(:))/(-hh)
417  else if (side==2) then
418  param_vector(param_num) = fiducial_param_vector(param_num) + hh
419  call params_array_to_camb_param( p_temp, fp_temp, num_param, param_vector )
420  call observed_sn_magnitude( p_temp, fp_temp, sn_temp_1, redshift, color, stretch, mock_sn_size, err )
421  if ( err /= 0 ) then
422  error_code = 4
423  mag_der_error = 0.0_dl
424  mag_derivative = 0.0_dl
425  return
426  end if
427  ! store the result
428  a(1,i,:) = (sn_temp_1(:) - mag_initial(:))/(hh)
429  end if
430 
431  ! now do the extrapolation table:
432  fac=con2
433  do j = 2, i
434 
435  forall ( k = 1:mock_sn_size, accept_mask(k) == 0 )
436  ! compute the interpolation table:
437  a(j,i,k) = (a(j-1,i,k)*fac-a(j-1,i-1,k))/(fac-1._dl)
438  ! estimate the error:
439  errt(k) = max( abs(a(j,i,k)-a(j-1,i,k)), &
440  & abs(a(j,i,k)-a(j-1,i-1,k)))
441  end forall
442 
443  fac=con2*fac
444 
445  ! if there is an improvement save the result:
446 
447  forall ( k = 1:mock_sn_size, &
448  & errt(k) .le. mag_der_error(k) .and. accept_mask(k) == 0 )
449 
450  mag_der_error(k) = errt(k)
451  mag_derivative(k) = a(j,i,k)
452  end forall
453 
454  end do
455  ! accept a value of the derivative if the value of the extrapolation is stable
456  ! Store this information into the mask matrix
457  ! so that the value contained in cl_error and cl_derivative is not overwritten.
458  forall ( k = 1:mock_sn_size, &
459  & accept_mask(k) == 0 .and. &
460  & (a(i,i,k) - a(i-1,i-1,k)) .ge. safe*mag_der_error(k) )
461 
462  accept_mask(k) = 1
463  end forall
464 
465  ! if all the entries match the required accuracy exit the loop
466  if ( sum(accept_mask) == mock_sn_size ) exit
467 
468  end do
469 
470  ! quality check on the results:
471  if ( sum(accept_mask) /= mock_sn_size ) then
472  error_code = 3
473  end if
474 
475  ! deallocate the arrays:
476  if ( fp%adaptivity ) then
477  deallocate( sn_temp_1, sn_temp_2, errt, accept_mask, a )
478  end if
479 
480  return
481 
482  end subroutine observed_sn_magnitude_derivative
483 
484  ! ---------------------------------------------------------------------------------------------
486  subroutine fisher_sn( P, FP, num_param, Fisher_Matrix, outroot )
488  implicit none
489 
490  Type(cambparams) , intent(in) :: P
491  Type(cosmicfish_params) , intent(in) :: FP
492 
493  integer , intent(in) :: num_param
494  real(dl), dimension(num_param,num_param), intent(out) :: Fisher_Matrix
495  character(len=*), intent(in), optional :: outroot
496 
497  real(dl) :: time_1, time_2, time_1_MC, time_2_MC
498  real(dl) :: initial_step, temp, temp1, temp2
499  integer :: AllocateStatus, err, ind, ind2
500  integer :: i, j, k, l, number
501  real(dl), allocatable :: param_array(:)
502  real(dl), allocatable, dimension(:,:) :: sn_mock
503  real(dl), allocatable, dimension(:) :: sn_mock_covariance
504  real(dl), allocatable, dimension(:) :: sn_fiducial, sn_derivative, sn_temp
505  real(dl), allocatable, dimension(:,:) :: sn_derivative_array
506 
507  integer :: MC_i
508  real(dl), dimension(num_param,num_param) :: MC_Fisher_Matrix
509 
510  ! allocate a parameter array:
511  allocate( param_array(num_param) )
512  ! write the parameters in the parameter array:
513  call camb_params_to_params_array( p, fp, num_param, param_array )
514 
515  number = fp%fisher_SN%total_SN_number
516 
517  ! allocation:
518  allocate( sn_mock(3,number), stat = allocatestatus )
519  if (allocatestatus /= 0) stop "Allocation failed. Not enough memory to allocate SN mock."
520  allocate( sn_mock_covariance(number), stat = allocatestatus )
521  if (allocatestatus /= 0) stop "Allocation failed. Not enough memory to allocate SN mock covariance."
522  allocate( sn_fiducial(number), sn_derivative(number), sn_temp(number), stat = allocatestatus )
523  if (allocatestatus /= 0) stop "Allocation failed. Not enough memory to allocate SN fiducial."
524  allocate( sn_derivative_array( num_param, number ), stat = allocatestatus)
525  if (allocatestatus /= 0) stop "Allocation failed. Not enough memory to allocate sn_derivative_array"
526 
527  ! do the Monte Carlo:
528 
529  mc_fisher_matrix = 0._dl
530 
531  time_1_mc = omp_get_wtime()
532  do mc_i=1, fp%fisher_SN%SN_Fisher_MC_samples
533 
534  ! generate the SN mock:
535  call generate_sn_mock_data( p, fp, sn_mock )
536 
537  ! generate the mock covariance:
538  call generate_sn_mock_covariance( p, fp, sn_mock, sn_mock_covariance )
539 
540  ! compute the fiducial:
541  time_1 = omp_get_wtime()
542  call observed_sn_magnitude( p, fp, sn_fiducial, sn_mock(1,:), sn_mock(2,:), sn_mock(3,:), &
543  & number, err )
544  time_2 = omp_get_wtime() - time_1
545 
546  if ( present(outroot) ) call save_sn_mock_to_file( number, sn_mock, sn_mock_covariance, &
547  & filename=trim(outroot)//'sn_fiducial_'//trim(adjustl(integer_to_string(mc_i)))//'.dat', magnitude = sn_fiducial )
548 
549  if ( err == 0 ) then
550  else if ( err == 4 ) then
551  write(*,*) 'Fiducial model unstable. Calculation cannot proceed.'
552  stop
553  else
554  write(*,*) 'Error in computing the fiducial. Calculation cannot proceed.'
555  stop
556  end if
557 
558  ! print some feedback
559  if ( mc_i==1 .and. fp%cosmicfish_feedback >= 1 ) then
560  write(*,'(a)') '**************************************************************'
561  write(*,'(a,i10)') 'Number of supernovae : ', number
562  write(*,'(a,i10)') 'Number of parameters : ', num_param
563  write(*,'(a,i10)') 'Number of MC repetitions : ', fp%fisher_SN%SN_Fisher_MC_samples
564  write(*,'(a,f10.3,a)') 'Time taken for SN calculation: ', time_2, ' (s)'
565  write(*,'(a,i10)') 'Number of omp processes : ', omp_get_max_threads()
566  if ( fp%adaptivity ) then
567  write(*,'(a,f10.3,a)') 'Estimated completion time : ', fp%fisher_SN%SN_Fisher_MC_samples*time_2*20._dl*num_param, ' (s)'
568  else
569  write(*,'(a,f10.3,a)') 'Estimated completion time : ', fp%fisher_SN%SN_Fisher_MC_samples*time_2*2._dl*num_param, ' (s)'
570  end if
571  write(*,'(a)') '**************************************************************'
572  end if
573 
574  if ( mc_i>1 .and. fp%cosmicfish_feedback >= 1 ) then
575  write(*,'(a)') '**************************************************************'
576  write(*,'(a,i10)') 'Doing MC computation of SN Fisher sample: ', mc_i
577  write(*,'(a)') '**************************************************************'
578  end if
579 
580  ! compute the derivatives of the Cls:
581  if ( fp%cosmicfish_feedback >= 1 ) then
582  write(*,'(a)') 'Computation of the SN magnitude derivatives'
583  end if
584 
585  time_1 = omp_get_wtime()
586  do ind = 1, num_param
587 
588  if ( fp%cosmicfish_feedback >= 1 ) then
589  write(*,'(a,i5,a,E15.5)') 'Doing parameter number: ', ind, ' value: ', param_array(ind)
590  end if
591 
592  if ( param_array(ind) /= 0._dl ) then
593  initial_step = param_array(ind)*3.0_dl/100._dl
594  else
595  initial_step = 3.0_dl/100._dl
596  end if
597 
598  call observed_sn_magnitude_derivative( p, fp, ind, &
599  & sn_fiducial, sn_derivative, sn_temp, &
600  & sn_mock, &
601  & initial_step, &
602  & num_param, &
603  & err )
604 
605  if (err /= 0) print*, 'WARNING: something went wrong with the SN derivative of parameter:', ind, 'Error code:', err
606 
607  if ( mc_i==1 .and. present(outroot) .and. fp%cosmicfish_feedback >= 2 ) then
608  call save_sn_mock_to_file( number, sn_mock, sn_mock_covariance, &
609  & filename=trim(outroot)//'sn_derivative_'//trim(adjustl(integer_to_string(ind)))//'.dat', magnitude = sn_derivative )
610  end if
611 
612  sn_derivative_array(ind,:) = sn_derivative(:)
613 
614  end do
615  time_2 = omp_get_wtime() - time_1
616 
617  if ( fp%cosmicfish_feedback >= 1 ) then
618  write(*,*)
619  write(*,'(a,f8.3,a)') 'Time to compute all the derivatives:', time_2, ' (s)'
620  end if
621 
622  ! compute the Fisher:
623  do ind = 1, num_param
624  do ind2 = 1, num_param
625 
626  temp2 = 0._dl
627 
628  do k = 1, number
629  temp2 = temp2 + sn_derivative_array(ind,k)*sn_derivative_array(ind2,k)/sn_mock_covariance(k)
630  end do
631 
632  mc_fisher_matrix(ind, ind2) = mc_fisher_matrix(ind, ind2) + temp2
633 
634  end do
635  end do
636  time_2 = omp_get_wtime() - time_1
637 
638  if ( fp%cosmicfish_feedback >= 1 ) then
639  write(*,'(a,f8.3,a)') 'Time to compute the Fisher matrix:', time_2, ' (s)'
640  end if
641 
642  end do
643  time_2_mc = omp_get_wtime() - time_1
644 
645  fisher_matrix = mc_fisher_matrix/fp%fisher_SN%SN_Fisher_MC_samples
646 
647  if ( fp%cosmicfish_feedback >= 1 ) then
648  write(*,'(a)') '**************************************************************'
649  write(*,'(a,f8.3,a)') 'Time to compute the MC Fisher matrix:', time_2_mc, ' (s)'
650  write(*,'(a)') '**************************************************************'
651  end if
652 
653  end subroutine fisher_sn
654 
655 end module fisher_calculator_sn
656 
subroutine, public params_array_to_camb_param(P, FP, num_param, params_array)
This subroutine updates the values of the parameters P and FP based on the values contained in the pa...
This module contains the subroutine and functions to generate random numbers from different distribut...
subroutine, public observed_sn_magnitude_derivative(P, FP, param_num, mag_initial, mag_derivative, mag_der_error, sn_mock, initial_step, num_param, error_code)
This subroutine computes the derivative of the observed magnitude of a set of supernovae. The calculation is carried out with a fixed stepsize finite difference formula or by the Richardson’s deferred approach to the limit.
subroutine, public generate_sn_mock_data(P, FP, sn_mock)
This subroutine generates a mock SN data set compilation based on the input specifications contained ...
subroutine, public camb_params_to_params_array(P, FP, num_param, params_array)
This subroutine updates the values of the parameters array based on the values of P and FP...
This module contains the definitions of derived data types used to store the informations about the f...
This module contains the interface layer between CosmicFish and CAMB.
This module contains several general purpose utilities.
real(dl) function random_uniform(a, b)
This function returns a random number generated from the uniform distribution in [a,b(. To improve performances no check is done in order to ensure that the random number generator is initialised.
character(10) function, public integer_to_string(number)
This function converts an integer to a string. Usefull for numbered files output. ...
real(dl) function random_gaussian(mu, sigma)
This function returns a random number generated from the gaussian distribution with mean mu and varia...
subroutine, public observed_sn_magnitude(P, FP, sn_magnitude, redshift, color, stretch, num, err)
This subroutine returns the observed magnitude of a set of supernovae based on the input cosmological...
subroutine, public fisher_sn(P, FP, num_param, Fisher_Matrix, outroot)
This subroutine computes the SN Fisher matrix.
subroutine, public save_sn_mock_to_file(mock_size, sn_mock_data, sn_mock_covariance, filename, magnitude)
This subroutine outputs to file a SN covariance.
subroutine, public generate_sn_mock_covariance(P, FP, sn_mock, sn_mock_covariance)
This subroutine generates a mock SN covariance based on the input specifications contained in the Cos...
This module contains the code that computes the Fisher matrix for Supernovae measurements.
This derived data type contains all the informations that the cosmicfish code needs to run...