31 use constants
, only: const_pi
39 #ifdef COSMICFISH_EFTCAMB
59 Type(cambparams) ,
intent(in) :: P
61 integer ,
intent(out) :: num
67 if ( fp%fisher_cls%Fisher_want_CMB_T ) num = num + 1
68 if ( fp%fisher_cls%Fisher_want_CMB_E ) num = num + 1
69 if ( fp%fisher_cls%Fisher_want_CMB_lensing ) num = num + 1
71 do i = 1, num_redshiftwindows
72 if ( redshift_w(i)%kind == window_counts .and. fp%fisher_cls%Fisher_want_LSS_counts )
then
74 else if ( redshift_w(i)%kind == window_lensing .and. fp%fisher_cls%Fisher_want_LSS_lensing )
then
79 if ( fp%fisher_cls%Fisher_want_CMB_B ) num = num + 1
92 integer,
intent(in) :: cl_dim
93 integer,
intent(in) :: l_min
94 integer,
intent(in) :: l_max
96 real(dl) :: cl_out(cl_dim, cl_dim, l_max-l_min+1)
97 integer,
intent(out) :: err
105 logical :: EFTsuccess
107 real(dl),
dimension(:,:),
allocatable :: outarr
108 integer ,
dimension(:) ,
allocatable :: array_select
109 integer ,
dimension(cl_dim) :: l_maxes
111 integer :: i, j, k, l, m, temp, stat, ind
112 real(dl) :: temp_factor
122 call cambparams_set(p)
124 #ifdef COSMICFISH_EFTCAMB
126 if (p%EFTflag /= 0)
then
127 call eftcamb_initialization(eftsuccess)
128 if (.not. eftsuccess)
then
129 write(*,*)
'EFTCAMB: unstable model'
137 call camb_getresults(p)
140 if (global_error_flag/=0)
then
141 write (*,*)
'Error result '//trim(global_error_message)
148 allocate(outarr(1:3+num_redshiftwindows,1:3+num_redshiftwindows))
149 allocate(array_select(3+num_redshiftwindows))
154 do i=1, 3+num_redshiftwindows
156 if ( fp%fisher_cls%Fisher_want_CMB_T ) array_select(1) = 1
157 if ( fp%fisher_cls%Fisher_want_CMB_E ) array_select(2) = 1
158 if ( fp%fisher_cls%Fisher_want_CMB_lensing ) array_select(3) = 1
160 do j = 1, num_redshiftwindows
161 if ( redshift_w(j)%kind == window_counts .and. fp%fisher_cls%Fisher_want_LSS_counts )
then
162 array_select(3+j) = 1
163 else if ( redshift_w(j)%kind == window_lensing .and. fp%fisher_cls%Fisher_want_LSS_lensing )
then
164 array_select(3+j) = 1
174 temp_factor = 2._dl*pi/(ell*(ell+1._dl))
176 outarr = temp_factor*cl_scalar_array(i,1,1:3+num_redshiftwindows,1:3+num_redshiftwindows)
177 outarr(1:2,:)=sqrt(fp%output_factor)*outarr(1:2,:)
178 outarr(:,1:2)=sqrt(fp%output_factor)*outarr(:,1:2)
183 do j=1, 3+num_redshiftwindows
184 if ( array_select(j)==1 )
then
186 do k=1, 3+num_redshiftwindows
187 if ( array_select(k)==1 )
then
188 cl_out(l, m, i-l_min+1) = outarr( j, k )
199 if ( p%WantTensors .and. .not. p%DoLensing)
then
201 do i = l_min, min( cp%Max_l_tensor, l_max )
203 temp_factor = 2*const_pi/(ell*(ell+1))
207 if ( fp%fisher_cls%Fisher_want_CMB_T ) cl_out(1,1,j) = temp_factor*fp%output_factor*(cl_scalar(i, 1, c_temp)+ cl_tensor(i, 1, c_temp))
209 if ( fp%fisher_cls%Fisher_want_CMB_T .and. fp%fisher_cls%Fisher_want_CMB_E )
then
210 cl_out(2,2,j) = temp_factor*fp%output_factor*(cl_scalar(i, 1, c_e)+ cl_tensor(i, 1, c_e))
211 cl_out(1,2,j) = temp_factor*fp%output_factor*(cl_scalar(i, 1, c_cross) + cl_tensor(i, 1, ct_cross))
214 if ( .not. fp%fisher_cls%Fisher_want_CMB_T .and. fp%fisher_cls%Fisher_want_CMB_E )
then
215 cl_out(1,1,j) = temp_factor*fp%output_factor*(cl_scalar(i, 1, c_e)+ cl_tensor(i, 1, c_e))
219 if ( fp%fisher_cls%Fisher_want_CMB_B ) cl_out( cl_dim, cl_dim, j ) = temp_factor*fp%output_factor*cl_tensor(i, 1, ct_b)
222 do i = cp%Max_l_tensor+1,l_max
224 temp_factor = 2*const_pi/(ell*(ell+1))
228 if ( fp%fisher_cls%Fisher_want_CMB_T ) cl_out(1,1,j) = temp_factor*fp%output_factor*cl_scalar(i, 1, c_temp)
230 if ( fp%fisher_cls%Fisher_want_CMB_T .and. fp%fisher_cls%Fisher_want_CMB_E )
then
231 cl_out(2,2,j) = temp_factor*fp%output_factor*cl_scalar(i, 1, c_e)
232 cl_out(1,2,j) = temp_factor*fp%output_factor*cl_scalar(i, 1, c_cross)
235 if ( .not. fp%fisher_cls%Fisher_want_CMB_T .and. fp%fisher_cls%Fisher_want_CMB_E )
then
236 cl_out(1,1,j) = temp_factor*fp%output_factor*cl_scalar(i, 1, c_e)
240 if ( fp%fisher_cls%Fisher_want_CMB_B ) cl_out( cl_dim, cl_dim, j ) = 0._dl
243 else if (.not. p%WantTensors .and. p%DoLensing)
then
245 do i = l_min, min( lmax_lensed, l_max )
247 temp_factor = 2*const_pi/(ell*(ell+1))
251 if ( fp%fisher_cls%Fisher_want_CMB_T ) cl_out(1,1,j) = temp_factor*fp%output_factor*cl_lensed(i, 1, ct_temp)
253 if ( fp%fisher_cls%Fisher_want_CMB_T .and. fp%fisher_cls%Fisher_want_CMB_E )
then
254 cl_out(2,2,j) = temp_factor*fp%output_factor*cl_lensed(i, 1, ct_e)
255 cl_out(1,2,j) = temp_factor*fp%output_factor*cl_lensed(i, 1, ct_cross)
258 if ( .not. fp%fisher_cls%Fisher_want_CMB_T .and. fp%fisher_cls%Fisher_want_CMB_E )
then
259 cl_out(1,1,j) = temp_factor*fp%output_factor*cl_lensed(i, 1, ct_e)
263 if ( fp%fisher_cls%Fisher_want_CMB_B ) cl_out( cl_dim, cl_dim, j ) = temp_factor*fp%output_factor*cl_lensed(i, 1, ct_b)
265 else if (p%WantTensors .and. p%DoLensing)
then
267 do i = l_min, min( cp%Max_l_tensor, lmax_lensed, l_max )
269 temp_factor = 2*const_pi/(ell*(ell+1))
273 if ( fp%fisher_cls%Fisher_want_CMB_T ) cl_out(1,1,j) = temp_factor*fp%output_factor*(cl_lensed(i, 1, ct_temp) +cl_tensor(i, 1, ct_temp))
275 if ( fp%fisher_cls%Fisher_want_CMB_T .and. fp%fisher_cls%Fisher_want_CMB_E )
then
276 cl_out(2,2,j) = temp_factor*fp%output_factor*(cl_lensed(i, 1, ct_e) +cl_tensor(i, 1, ct_e))
277 cl_out(1,2,j) = temp_factor*fp%output_factor*(cl_lensed(i, 1, ct_cross) +cl_tensor(i, 1, ct_cross))
280 if ( .not. fp%fisher_cls%Fisher_want_CMB_T .and. fp%fisher_cls%Fisher_want_CMB_E )
then
281 cl_out(1,1,j) = temp_factor*fp%output_factor*(cl_lensed(i, 1, ct_e) +cl_tensor(i, 1, ct_e))
285 if ( fp%fisher_cls%Fisher_want_CMB_B ) cl_out( cl_dim, cl_dim, j ) = temp_factor*fp%output_factor*(cl_lensed(i, 1, ct_b) +cl_tensor(i, 1, ct_b))
287 do i = min( cp%Max_l_tensor, lmax_lensed, l_max )+1, min( lmax_lensed, l_max )
289 temp_factor = 2*const_pi/(ell*(ell+1))
293 if ( fp%fisher_cls%Fisher_want_CMB_T ) cl_out(1,1,j) = temp_factor*fp%output_factor*cl_lensed(i, 1, ct_temp)
295 if ( fp%fisher_cls%Fisher_want_CMB_T .and. fp%fisher_cls%Fisher_want_CMB_E )
then
296 cl_out(2,2,j) = temp_factor*fp%output_factor*cl_lensed(i, 1, ct_e)
297 cl_out(1,2,j) = temp_factor*fp%output_factor*cl_lensed(i, 1, ct_cross)
300 if ( .not. fp%fisher_cls%Fisher_want_CMB_T .and. fp%fisher_cls%Fisher_want_CMB_E )
then
301 cl_out(1,1,j) = temp_factor*fp%output_factor*cl_lensed(i, 1, ct_e)
305 if ( fp%fisher_cls%Fisher_want_CMB_B ) cl_out( cl_dim, cl_dim, j ) = temp_factor*fp%output_factor*cl_lensed(i, 1, ct_b)
314 if ( fp%fisher_cls%Fisher_want_CMB_T )
then
315 l_maxes(ind) = fp%fisher_cls%l_max_TT
319 if ( fp%fisher_cls%Fisher_want_CMB_E )
then
320 l_maxes(ind) = fp%fisher_cls%l_max_EE
324 if ( fp%fisher_cls%Fisher_want_CMB_lensing )
then
325 l_maxes(ind) = min( fp%fisher_cls%l_max_TT, &
326 & fp%fisher_cls%l_max_EE, &
327 & fp%fisher_cls%l_max_BB )
331 if ( fp%fisher_cls%Fisher_want_CMB_B )
then
332 l_maxes(cl_dim) = fp%fisher_cls%l_max_BB
335 do k = 1, fp%fisher_cls%LSS_number_windows
336 l_maxes(ind) = fp%fisher_cls%LSS_lmax(k)
345 if ( i <= min(l_maxes(j), l_maxes(k)) )
then
346 cl_out( k, j, i-l_min+1) = cl_out( k, j, i-l_min+1)
348 cl_out( k, j, i-l_min+1) = 0._dl
360 cl_out( j, k, i-l_min+1) = cl_out( k, j, i-l_min+1)
367 if ( .not. fp%fisher_cls%Fisher_want_XC )
then
373 cl_out( j, k, i-l_min+1) = 0._dl
389 integer ,
intent(in) :: cl_dim
390 integer ,
intent(in) :: l_min
391 integer ,
intent(in) :: l_max
392 real(dl),
dimension(cl_dim, cl_dim, l_max-l_min+1),
intent(in) :: cl_cov_in
393 character(len=*),
intent(in) :: filename
397 real(dl),
dimension(cl_dim, cl_dim) :: dummy
399 open(unit=666, file=filename, action=
"write", status=
"replace")
401 do i = 1, l_max-l_min+1
404 dummy(:,:) = cl_cov_in(:,:,i)
405 write(666,
'(E15.5)',advance=
'no')
REAL(i+l_min-1)
409 write(666,
'(ES20.5E3)',advance=
'no') factor*dummy(j,k)
423 & cl_initial, cl_derivative, cl_error, &
425 & out_dim, l_min, l_max, num_param, &
430 Type(cambparams) ,
intent(in) :: P
433 integer ,
intent(in) :: param_num
434 integer ,
intent(in) :: out_dim
435 integer ,
intent(in) :: l_min
436 integer ,
intent(in) :: l_max
437 integer ,
intent(in) :: num_param
439 real(dl),
dimension(out_dim, out_dim, l_max-l_min+1),
intent(in) :: cl_initial
440 real(dl),
dimension(out_dim, out_dim, l_max-l_min+1),
intent(out) :: cl_derivative
441 real(dl),
dimension(out_dim, out_dim, l_max-l_min+1),
intent(out) :: cl_error
443 real(dl),
intent(in) :: initial_step
444 integer ,
intent(out) :: error_code
451 real(dl),
dimension(:,:,:),
allocatable :: cl_temp_1, cl_temp_2, errt
452 integer ,
dimension(:,:,:),
allocatable :: accept_mask
453 real(dl),
dimension(:,:,:,:,:),
allocatable :: a
454 real(dl),
dimension(num_param) :: param_vector, fiducial_param_vector, temp_param_vector
457 real(dl),
parameter :: con = 1.4_dl
458 real(dl),
parameter :: big = 1.d+30
459 real(dl),
parameter :: safe = 2._dl
460 integer ,
parameter :: ntab = 30
461 real(dl) :: con2 = con*con
462 integer :: i, j, k, l, m, side, err, AllocateStatus
464 real(dl) :: temp1, temp2, temp3
465 Type(cambparams) :: P_temp
468 real(dl) :: acceptance
472 cl_derivative = 0._dl
476 if ( initial_step == 0._dl )
then
477 stop
'cls_derivative initial stepsize is zero'
482 if ( fp%adaptivity )
then
483 allocate( cl_temp_1(out_dim, out_dim, l_max-l_min+1), &
484 & cl_temp_2(out_dim, out_dim, l_max-l_min+1), &
485 & errt(out_dim, out_dim, l_max-l_min+1), &
486 & accept_mask(out_dim, out_dim, l_max-l_min+1),&
487 & stat = allocatestatus )
488 if (allocatestatus /= 0) stop
"cls_derivative: Allocation failed. Not enough memory"
489 allocate( a(ntab, ntab, out_dim, out_dim, l_max-l_min+1) , stat = allocatestatus )
490 if (allocatestatus /= 0) stop
"cls_derivative: Allocation failed. Not enough memory for the derivative array"
492 allocate( cl_temp_1(out_dim, out_dim, l_max-l_min+1), &
493 & cl_temp_2(out_dim, out_dim, l_max-l_min+1), &
494 & stat = allocatestatus )
495 if (allocatestatus /= 0) stop
"cls_derivative: Allocation failed. Not enough memory"
496 allocate( a(1,1, out_dim, out_dim, l_max-l_min+1) , stat = allocatestatus )
497 if (allocatestatus /= 0) stop
"cls_derivative: Allocation failed. Not enough memory for the derivative array"
506 fiducial_param_vector = param_vector
507 temp_param_vector = param_vector
513 if ( fp%adaptivity ) accept_mask = 0
516 param_vector(param_num) = fiducial_param_vector(param_num) + hh
520 if ( err /= 0 ) side = 1
522 temp_param_vector(param_num) = fiducial_param_vector(param_num) - hh
528 if ( side == 1 )
then
532 cl_derivative = 0.0_dl
534 else if ( side == 0 )
then
542 a(1,1,:,:,:) = (cl_temp_1(:,:,:) - cl_temp_2(:,:,:))/(2.0_dl*hh)
543 else if (side == 1)
then
544 a(1,1,:,:,:) = (cl_temp_2(:,:,:) - cl_initial(:,:,:))/(-hh)
545 else if (side == 2)
then
546 a(1,1,:,:,:) = (cl_temp_1(:,:,:) - cl_initial(:,:,:))/(hh)
550 if ( .not. fp%adaptivity )
then
551 cl_derivative(:,:,:) = a(1,1,:,:,:)
553 deallocate( cl_temp_1, cl_temp_2, a )
561 if ( fp%cosmicfish_feedback >= 2 )
then
562 accepted = sum(accept_mask)
563 acceptance =
REAL(accepted)/
REAL(out_dim*out_dim*(l_max-l_min+1))
564 print*,
'iteration:', i
565 print*,
' stepsize:', hh
566 print*,
' accepted elements', accepted,
'accepted ratio', acceptance
574 param_vector(param_num) = fiducial_param_vector(param_num) + hh
575 temp_param_vector(param_num) = fiducial_param_vector(param_num) - hh
582 cl_derivative = 0.0_dl
591 cl_derivative = 0.0_dl
595 a(1,i,:,:,:) = (cl_temp_1(:,:,:) - cl_temp_2(:,:,:))/(2.0_dl*hh)
596 else if (side==1)
then
597 param_vector(param_num) = fiducial_param_vector(param_num) - hh
603 cl_derivative = 0.0_dl
607 a(1,i,:,:,:) = (cl_temp_1(:,:,:) - cl_initial(:,:,:))/(-hh)
608 else if (side==2)
then
609 param_vector(param_num) = fiducial_param_vector(param_num) + hh
615 cl_derivative = 0.0_dl
619 a(1,i,:,:,:) = (cl_temp_1(:,:,:) - cl_initial(:,:,:))/(hh)
626 forall ( k = 1:out_dim, l = 1:out_dim, m = 1:l_max-l_min+1, &
627 & accept_mask(k,l,m) == 0 )
629 a(j,i,k,l,m) = (a(j-1,i,k,l,m)*fac-a(j-1,i-1,k,l,m))/(fac-1._dl)
631 errt(k,l,m) = max( abs(a(j,i,k,l,m)-a(j-1,i,k,l,m)), &
632 & abs(a(j,i,k,l,m)-a(j-1,i-1,k,l,m)))
639 forall ( k = 1:out_dim, l = 1:out_dim, m = 1:l_max-l_min+1, &
640 & errt(k,l,m) .le. cl_error(k,l,m) .and. accept_mask(k,l,m) == 0 )
642 cl_error(k,l,m) = errt(k,l,m)
643 cl_derivative(k,l,m) = a(j,i,k,l,m)
651 forall ( k = 1:out_dim, l = 1:out_dim, m = 1:l_max-l_min+1, &
652 & accept_mask(k,l,m) == 0 .and. &
653 & (a(i,i,k,l,m) - a(i-1,i-1,k,l,m)) .ge. safe*cl_error(k,l,m) )
655 accept_mask(k,l,m) = 1
659 if ( sum(accept_mask) == out_dim*out_dim*(l_max-l_min+1) )
exit
664 if ( sum(accept_mask) /= out_dim*out_dim*(l_max-l_min+1) )
then
669 if ( fp%adaptivity )
then
670 deallocate( cl_temp_1, cl_temp_2, errt, accept_mask, a )
684 Type(cambparams) ,
intent(in) :: P
687 integer ,
intent(in) :: out_dim
688 integer ,
intent(in) :: l_min
689 integer ,
intent(in) :: l_max
691 real(dl),
dimension(out_dim, out_dim, l_max-l_min+1),
intent(inout) :: cl_fiducial
693 integer ,
intent(out) :: error_code
701 integer :: jjmaxTmax = 200
703 integer :: ind, i, j, k
704 real(dl) :: temp1, temp2, ell, factor
705 real(dl) :: Compute_CMB_TT_Noise, Compute_CMB_EE_Noise, Compute_CMB_BB_Noise
706 real(dl),
allocatable :: NoiseVar(:), NoiseVarPol(:), sigma2(:)
707 real(dl),
allocatable :: incls(:,:), inlcls(:,:), clnoise(:,:), nldd(:)
708 real(dl),
allocatable :: fskyes(:)
709 logical :: EFTsuccess
716 if ( fp%fisher_cls%Fisher_want_CMB_T .or. fp%fisher_cls%Fisher_want_CMB_E .or. &
717 & fp%fisher_cls%Fisher_want_CMB_B .or. fp%fisher_cls%Fisher_want_CMB_lensing )
then
719 allocate( noisevar(fp%fisher_cls%CMB_n_channels), &
720 & noisevarpol(fp%fisher_cls%CMB_n_channels), &
721 & sigma2(fp%fisher_cls%CMB_n_channels) )
723 temp1 = p%Tcmb*const_pi/180._dl/60._dl
724 temp2 = 180._dl*60._dl*sqrt(8._dl*log(2._dl))/const_pi
726 forall( i = 1:fp%fisher_cls%CMB_n_channels )
727 noisevar(i) = ( fp%fisher_cls%CMB_temp_sens(i)*fp%fisher_cls%CMB_fwhm(i)*temp1 )**2
728 noisevarpol(i) = ( fp%fisher_cls%CMB_pol_sens(i)*fp%fisher_cls%CMB_fwhm(i)*temp1 )**2
729 sigma2(i) = -1._dl*( fp%fisher_cls%CMB_fwhm(i)/temp2 )**2
735 if ( fp%fisher_cls%Fisher_want_CMB_T )
then
740 compute_cmb_tt_noise = 0._dl
741 do i=1, fp%fisher_cls%CMB_n_channels
742 compute_cmb_tt_noise = compute_cmb_tt_noise &
743 & + 1._dl/noisevar(i)*exp(ell*(ell+1)*sigma2(i) )
745 compute_cmb_tt_noise = 1._dl/compute_cmb_tt_noise
748 cl_fiducial( ind, ind, k ) = cl_fiducial( ind, ind, k ) + compute_cmb_tt_noise
754 if ( fp%fisher_cls%Fisher_want_CMB_E )
then
759 compute_cmb_ee_noise = 0._dl
760 do i=1, fp%fisher_cls%CMB_n_channels
761 compute_cmb_ee_noise = compute_cmb_ee_noise &
762 & + 1._dl/noisevarpol(i)*exp(ell*(ell+1)*sigma2(i) )
764 compute_cmb_ee_noise = 1._dl/compute_cmb_ee_noise
767 cl_fiducial( ind, ind, k ) = cl_fiducial( ind, ind, k ) + compute_cmb_ee_noise
773 if ( fp%fisher_cls%Fisher_want_CMB_lensing )
then
776 #ifdef COSMICFISH_EFTCAMB
778 if (p%EFTflag /= 0)
then
779 call cambparams_set(p)
780 call eftcamb_initialization(eftsuccess)
781 if (.not. eftsuccess)
then
782 write(*,*)
'EFTCAMB: unstable fiducial model. Calculation cannot proceed.'
787 call camb_getresults(p)
790 if (global_error_flag/=0)
then
791 write (*,*)
'Error result '//trim(global_error_message)
792 write (*,*)
'add_noise_cls_to_fiducial: calculation of fiducial model failed. Calculation cannot proceed.'
796 allocate(incls(5, 1:l_max))
797 allocate(inlcls(4, 1:l_max))
798 allocate(clnoise(2, 1:l_max))
799 allocate(nldd(1:l_max))
810 factor = 2*const_pi/(ell*(ell+1))
812 incls(1,i) = fp%output_factor*factor*cl_scalar_array(i,1,1,1)
813 incls(2,i) = fp%output_factor*factor*cl_scalar_array(i,1,2,2)
814 incls(3,i) = fp%output_factor*factor*cl_scalar_array(i,1,1,2)
815 incls(4,i) = 2*const_pi*cl_scalar_array(i,1,3,3)
816 incls(5,i) = sqrt(fp%output_factor)*sqrt(ell*(ell+1))*factor*cl_scalar_array(i,1,1,3)
818 inlcls(1,i) = fp%output_factor*factor*cl_lensed(i, 1, ct_temp)
819 inlcls(2,i) = fp%output_factor*factor*cl_lensed(i, 1, ct_e)
820 inlcls(3,i) = fp%output_factor*factor*cl_lensed(i, 1, ct_cross)
821 inlcls(4,i) = fp%output_factor*factor*cl_lensed(i, 1, ct_b)
824 compute_cmb_tt_noise = 0._dl
825 do j=1, fp%fisher_cls%CMB_n_channels
826 compute_cmb_tt_noise = compute_cmb_tt_noise &
827 & + 1._dl/noisevar(j)*exp(ell*(ell+1)*sigma2(j) )
829 compute_cmb_tt_noise = 1._dl/compute_cmb_tt_noise
830 clnoise(1,i) = compute_cmb_tt_noise
832 compute_cmb_ee_noise = 0._dl
833 do j=1, fp%fisher_cls%CMB_n_channels
834 compute_cmb_ee_noise = compute_cmb_ee_noise &
835 & + 1._dl/noisevarpol(j)*exp(ell*(ell+1)*sigma2(j) )
837 compute_cmb_ee_noise = 1._dl/compute_cmb_ee_noise
838 clnoise(2,i) = compute_cmb_ee_noise
843 call calc_nldd(incls, inlcls, clnoise, nldd, jjmaxtmax, l_max)
848 factor = 1._dl/(ell*(ell+1))
850 cl_fiducial( ind, ind, k ) = cl_fiducial( ind, ind, k ) + factor*nldd(i)
857 if ( fp%fisher_cls%Fisher_want_CMB_b )
then
862 compute_cmb_bb_noise = 0._dl
863 do i=1, fp%fisher_cls%CMB_n_channels
864 compute_cmb_bb_noise = compute_cmb_bb_noise &
865 & + 1._dl/noisevarpol(i)*exp(ell*(ell+1)*sigma2(i) )
867 compute_cmb_bb_noise = 1._dl/compute_cmb_bb_noise
870 cl_fiducial( out_dim, out_dim, k ) = cl_fiducial( out_dim, out_dim, k ) + compute_cmb_bb_noise
877 do k = 1, num_redshiftwindows
879 if ( redshift_w(k)%kind == window_counts .and. fp%fisher_cls%Fisher_want_LSS_counts )
then
880 do i = 1, l_max-l_min+1
881 cl_fiducial( ind, ind, i ) = &
882 & cl_fiducial( ind, ind, i ) + 1._dl/fp%fisher_cls%LSS_num_galaxies(j)
887 else if ( redshift_w(k)%kind == window_lensing .and. fp%fisher_cls%Fisher_want_LSS_lensing )
then
888 do i = 1, l_max-l_min+1
889 cl_fiducial( ind, ind, i ) = &
890 & cl_fiducial( ind, ind, i ) &
891 & +fp%fisher_cls%LSS_intrinsic_ellipticity(j)**2/fp%fisher_cls%LSS_num_galaxies(j)
901 allocate( fskyes(out_dim) )
906 if ( fp%fisher_cls%Fisher_want_CMB_T )
then
907 fskyes(ind) = fp%fisher_cls%CMB_TT_fsky
911 if ( fp%fisher_cls%Fisher_want_CMB_E )
then
912 fskyes(ind) = fp%fisher_cls%CMB_EE_fsky
916 if ( fp%fisher_cls%Fisher_want_CMB_lensing )
then
917 fskyes(ind) = min( fp%fisher_cls%CMB_TT_fsky, &
918 & fp%fisher_cls%CMB_EE_fsky, &
919 & fp%fisher_cls%CMB_BB_fsky )
923 if ( fp%fisher_cls%Fisher_want_CMB_B )
then
924 fskyes(out_dim) = fp%fisher_cls%CMB_BB_fsky
927 do k = 1, fp%fisher_cls%LSS_number_windows
928 fskyes(ind) = fp%fisher_cls%LSS_fsky(k)
936 cl_fiducial(j, k, :) = cl_fiducial(j, k, :)/sqrt(sqrt(fskyes(j)*fskyes(k)))
945 subroutine fisher_cls( P, FP, num_param, Fisher_Matrix, outroot )
949 Type(cambparams) ,
intent(in) :: P
952 integer ,
intent(in) :: num_param
953 real(dl),
dimension(num_param,num_param),
intent(out) :: Fisher_Matrix
954 character(len=*),
intent(in),
optional :: outroot
956 real(dl) :: time_1, time_2
957 real(dl) :: initial_step, temp, temp1, temp2
958 integer :: cl_dim, l_min, l_max, err, AllocateStatus, ind, ind2
959 integer :: i, j, k, l
960 real(dl),
allocatable :: param_array(:)
961 real(dl),
dimension(:,:,:),
allocatable :: cl_fiducial, cl_derivative, cl_temp
962 real(dl),
dimension(:,:,:,:),
allocatable :: cl_derivative_array
963 real(dl),
dimension(:,:) ,
allocatable :: dummy_matrix_1, dummy_matrix_2
964 real(dl),
dimension(:,:) ,
allocatable :: dummy_matrix_3, dummy_matrix_4, dummy_matrix_5
967 allocate( param_array(num_param) )
973 if ( cl_dim == 0 )
then
974 write(*,*)
'WARNING: the Cls matrix is of zero dimension'
975 fisher_matrix = 0._dl
981 l_max = maxval( fp%fisher_cls%LSS_lmax, fp%fisher_cls%LSS_number_windows )
982 l_max = max( l_max, fp%fisher_cls%l_max_TT, &
983 & fp%fisher_cls%l_max_EE, fp%fisher_cls%l_max_BB )
986 allocate(cl_fiducial(cl_dim, cl_dim, l_max-l_min+1), stat = allocatestatus)
987 if (allocatestatus /= 0) stop
"Allocation failed. Not enough memory to allocate cl_fiducial"
988 allocate(cl_temp(cl_dim, cl_dim, l_max-l_min+1), stat = allocatestatus)
989 if (allocatestatus /= 0) stop
"Allocation failed. Not enough memory to allocate cl_temp"
990 allocate(cl_derivative(cl_dim, cl_dim, l_max-l_min+1), stat = allocatestatus)
991 if (allocatestatus /= 0) stop
"Allocation failed. Not enough memory to allocate cl_derivative"
994 time_1 = omp_get_wtime()
996 time_2 = omp_get_wtime() - time_1
998 if (
present(outroot) )
call save_cl_covariance_to_file( cl_fiducial, cl_dim, l_min, l_max, filename=trim(outroot)//
'fiducial.dat' )
1000 if ( err == 0 )
then
1001 else if ( err == 4 )
then
1002 write(*,*)
'Fiducial model unstable. Calculation cannot proceed.'
1005 write(*,*)
'Error in computing the fiducial. Calculation cannot proceed.'
1010 if ( fp%cosmicfish_feedback >= 1 )
then
1011 write(*,
'(a)')
'**************************************************************'
1012 write(*,
'(a,i10)')
'Dimension of the Cls matrix : ', cl_dim
1013 if ( fp%fisher_cls%Fisher_want_XC )
then
1014 write(*,
'(a)')
'Using cross correlation.'
1016 write(*,
'(a)')
'Not using cross correlation.'
1018 write(*,
'(a,i10)')
'Minimum l : ', l_min
1019 write(*,
'(a,i10)')
'Maximum l : ', l_max
1020 write(*,
'(a,i10)')
'Number of parameters : ', num_param
1021 write(*,
'(a,f10.3,a)')
'Time taken for Cl calculation: ', time_2,
' (s)'
1022 write(*,
'(a,i10)')
'Number of omp processes : ', omp_get_max_threads()
1023 if ( fp%adaptivity )
then
1024 write(*,
'(a,f10.3,a)')
'Estimated completion time : ', time_2*20._dl*num_param,
' (s)'
1026 write(*,
'(a,f10.3,a)')
'Estimated completion time : ', time_2*2._dl*num_param,
' (s)'
1028 write(*,
'(a)')
'**************************************************************'
1032 if ( fp%cosmicfish_feedback >= 1 )
then
1033 write(*,
'(a)')
'**************************************************************'
1034 write(*,
'(a)')
'Computation of the Cls derivatives'
1035 write(*,
'(a)')
'**************************************************************'
1038 allocate(cl_derivative_array(num_param,cl_dim, cl_dim, l_max-l_min+1), stat = allocatestatus)
1039 if (allocatestatus /= 0) stop
"Allocation failed. Not enough memory to allocate cl_derivative_array"
1041 time_1 = omp_get_wtime()
1042 do ind = 1, num_param
1044 if ( fp%cosmicfish_feedback >= 1 )
then
1045 write(*,
'(a,i5,a,E15.5)')
'Doing parameter number: ', ind,
' value: ', param_array(ind)
1048 if ( param_array(ind) /= 0._dl )
then
1049 initial_step = param_array(ind)*3.0_dl/100._dl
1051 initial_step = 3.0_dl/100._dl
1055 & cl_fiducial, cl_derivative, cl_temp, &
1057 & cl_dim, l_min, l_max, num_param, &
1060 if (err /= 0) print*,
'WARNING: something went wrong with the Cls derivative of parameter:', ind
1062 if (
present(outroot) .and. fp%cosmicfish_feedback >= 2 )
then
1066 cl_derivative_array(ind,:,:,:) = cl_derivative(:,:,:)
1069 time_2 = omp_get_wtime() - time_1
1071 if ( fp%cosmicfish_feedback >= 1 )
then
1073 write(*,
'(a,f8.3,a)')
'Time to compute all the derivatives:', time_2,
' (s)'
1077 if ( fp%cosmicfish_feedback >= 1 )
then
1078 write(*,
'(a)')
'**************************************************************'
1079 write(*,
'(a)')
'Adding experimental noise and computing Fisher:'
1080 write(*,
'(a)')
'**************************************************************'
1083 time_1 = omp_get_wtime()
1085 cl_temp = cl_fiducial
1088 if ( err /= 0 ) stop
'Something went wrong with the computation of the cls noise'
1090 time_2 = omp_get_wtime() - time_1
1092 if (
present(outroot) .and. fp%cosmicfish_feedback >= 2 )
then
1096 if ( fp%cosmicfish_feedback >= 1 )
then
1097 write(*,
'(a,f8.3,a)')
'Time to compute the noise Cls:', time_2,
' (s)'
1101 allocate( dummy_matrix_1(cl_dim, cl_dim), dummy_matrix_2(cl_dim, cl_dim) )
1102 allocate( dummy_matrix_3(cl_dim, cl_dim), dummy_matrix_4(cl_dim, cl_dim) )
1103 allocate( dummy_matrix_5(cl_dim, cl_dim) )
1106 do ind = 1, l_max-l_min+1
1108 forall ( k = 1:cl_dim, l = 1:cl_dim )
1109 dummy_matrix_1(k,l) = cl_fiducial(k,l, ind)
1113 if ( err /= 0 )
then
1114 write(*,*)
'Matrix inversion failed. Calculation cannot proceed. Error at l= ', ind
1118 forall ( k = 1:cl_dim, l = 1:cl_dim )
1119 cl_fiducial(k,l, ind) = dummy_matrix_1(k,l)
1125 do ind = 1, num_param
1126 do ind2 = 1, num_param
1130 do i = 1, l_max-l_min+1
1132 temp =
REAL(i+l_min) -0.5_dl
1134 forall ( j = 1:cl_dim, k = 1:cl_dim )
1135 dummy_matrix_1(j, k) = cl_derivative_array(ind, j, k, i)
1136 dummy_matrix_2(j, k) = cl_derivative_array(ind2, j, k, i)
1137 dummy_matrix_3(j, k) = cl_fiducial(j, k, i)
1140 dummy_matrix_1 = matmul(dummy_matrix_1, dummy_matrix_3)
1141 dummy_matrix_1 = matmul(dummy_matrix_3, dummy_matrix_1)
1142 dummy_matrix_4 = matmul(dummy_matrix_2, dummy_matrix_1)
1146 temp1 = temp1 + dummy_matrix_4(j,j)
1149 temp2 = temp2 + temp*temp1
1153 fisher_matrix(ind, ind2) = temp2
1157 time_2 = omp_get_wtime() - time_1
1159 if ( fp%cosmicfish_feedback >= 1 )
then
1160 write(*,
'(a,f8.3,a)')
'Time to compute the Fisher matrix:', time_2,
' (s)'
subroutine, public sym_matrix_inversion(A, error_code)
This subroutine computes the inverse of a square symmetric matrix by means of LAPACK LU decomposition...
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...
subroutine, public save_cl_covariance_to_file(cl_cov_in, cl_dim, l_min, l_max, filename)
This subroutine saves to file the input Cls covariance matrix.
subroutine, public cls_derivative(P, FP, param_num, cl_initial, cl_derivative, cl_error, initial_step, out_dim, l_min, l_max, num_param, error_code)
This subroutine computes the derivative of the Cls covariance matrix with a fixed stepsize finite dif...
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 definition of the window functions that are used by CAMB sources...
This module contains the subroutine and functions to manipulate and modify matrices.
This module contains the interface layer between CosmicFish and CAMB.
This module contains several general purpose utilities.
subroutine, public add_noise_cls_to_fiducial(P, FP, cl_fiducial, out_dim, l_min, l_max, error_code)
This subroutine computes and adds the noise cls to the fiducial cls. On output the fiducial cls will ...
This module contains the code to compute the noise for CMB lensing.
subroutine, public fisher_cls(P, FP, num_param, Fisher_Matrix, outroot)
This subroutine computes the Fisher matrix for Cls.
character(10) function, public integer_to_string(number)
This function converts an integer to a string. Usefull for numbered files output. ...
subroutine, public calc_nldd(incls, inlcls, clnoise, nldd, jjmaxTmax, lmaxM)
This subroutine computes the noise for the Okamoto & Hu's estimator of the CMB lensing.
This module contains the code that computes the Fisher matrix for Cls.
subroutine, public cl_covariance_out(P, FP, cl_dim, l_min, l_max, cl_out, err)
This subroutine that gives the covariance matrix of the Cls for the desired model. Calls internally CAMB_get results.
subroutine, public init_camb_sources_windows(FP)
This function initialises the camb sources number counts and lensing window function. The default is the gaussian window that is included in camb sources. If another window is chosen it will be initialised by the CosmicFish value.
subroutine, public dimension_cl_covariance(P, FP, num)
This subroutine computes the number of entrance of the cls covariance matrix The matrix of the Cls is...
This derived data type contains all the informations that the cosmicfish code needs to run...