58 #define G_AT "GCOMDris::at(int&)"
59 #define G_INSERT "GCOMDris::insert(int&, GCOMDri&)"
60 #define G_REMOVE "GCOMDris::remove(int&)"
61 #define G_COMPUTE_DRWS "GCOMDris::compute_drws(GCOMObservation&,"\
62 " GCOMSelection&, double&, double&, std::string&)"
67 #define G_COMPUTE_DRWS_EHACORR
207 if (index < 0 || index >=
size()) {
230 if (index < 0 || index >=
size()) {
274 #if defined(G_RANGE_CHECK)
282 if (index < 0 || index >=
size()) {
310 #if defined(G_RANGE_CHECK)
311 if (index < 0 || index >=
size()) {
340 int num = dris.
size();
346 for (
int i = 0; i < num; ++i) {
347 m_dris.push_back(dris[i]);
380 const double& zetamin,
381 const double& timebin,
382 const std::string& method)
388 #if defined(G_DEBUG_COMPUTE_DRWS)
389 std::cout <<
"Initialisation" << std::endl;
390 std::cout <<
"--------------" << std::endl;
399 for (
int i = 0; i <
size(); ++i) {
403 std::string msg =
"Mismatch between definition of DRW "+
405 "Method only works on DRWs with identical "
411 m_dris[i].init_statistics();
415 m_dris[i].m_selection = select;
421 m_dris[i].m_drw_method = method;
424 #if defined(G_DEBUG_COMPUTE_DRWS)
425 std::cout <<
m_dris[i].print() << std::endl;
433 if (events == NULL) {
434 std::string msg =
"No event list found in COMPTEL observation. Please "
435 "specify an observation that contains an event list.";
440 if (method ==
"energy") {
445 else if (method ==
"phibar") {
450 else if (method ==
"vetorate") {
455 for (
int i = 0; i <
size(); ++i) {
458 for (
int iphibar = 0; iphibar < dri->
nphibar(); ++iphibar) {
462 int istart = iphibar * dri->
m_dri.
npix();
464 for (
int inx = istart; inx < istop; ++inx) {
470 for (
int inx = istart; inx < istop; ++inx) {
478 if (
m_dris[i].m_num_used_superpackets > 0) {
506 result.append(
"=== GCOMDris ===");
609 const double& zetamin,
610 const double& timebin)
613 #if defined(G_DEBUG_COMPUTE_DRWS)
614 std::cout <<
"GCOMDris::compute_drws_energy" << std::endl;
615 std::cout <<
"=============================" << std::endl;
627 #if defined(G_DEBUG_COMPUTE_DRWS)
628 std::cout <<
"Determine energy-dependent event rates" << std::endl;
629 std::cout <<
"--------------------------------------" << std::endl;
639 std::vector<double> rates0;
640 std::vector<double> rates1;
641 std::vector<double> rates2;
645 if (events->
size() > 0) {
646 time = (*events)[0]->time().secs();
655 for (
int i_evt = 0; i_evt < events->
size(); ++i_evt) {
668 if ((event->eha() -
event->phibar()) < zetamin) {
673 while (event->time().secs() > (time + timebin)) {
679 times.
append(time + 0.5 * timebin);
682 rates0.push_back(rate0);
683 rates1.push_back(rate1);
684 rates2.push_back(rate2);
687 #if defined(G_DEBUG_COMPUTE_DRWS)
688 std::cout <<
"t=" << time + 0.5 * timebin;
689 std::cout <<
" r0=" << rate0;
690 std::cout <<
" r1=" << rate1;
691 std::cout <<
" r2=" << rate2;
692 std::cout << std::endl;
709 double energy =
event->energy().MeV();
714 else if (energy < 4.3) {
729 times.
append(time + 0.5 * timebin);
732 rates0.push_back(rate0);
733 rates1.push_back(rate1);
734 rates2.push_back(rate2);
739 #if defined(G_DEBUG_COMPUTE_DRWS)
740 std::cout <<
"Compute DRWs" << std::endl;
741 std::cout <<
"------------" << std::endl;
745 std::vector<double> geometry(dri->
m_dri.
npix());
746 std::vector<double> eha(dri->
m_dri.
npix());
757 for (
int i_oad = 0; i_oad < obs.
oads().
size(); ++i_oad) {
765 for (
int i = 0; i <
size(); ++i) {
766 if (!
m_dris[i].use_superpacket(oad, tim, select)) {
778 std::vector<double> rates;
779 for (
int i = 0; i <
size(); ++i) {
780 if (
m_dris[i].m_ebounds.emin().MeV() > 4.3) {
783 else if (
m_dris[i].m_ebounds.emin().MeV() > 1.8) {
792 #if defined(G_DEBUG_COMPUTE_DRWS)
793 std::cout <<
"time=" << time;
794 for (
int i = 0; i <
size(); ++i) {
795 std::cout <<
" r[" << i <<
"]=" << rates[i];
797 std::cout << std::endl;
806 double theta_geocentre = double(oad.
gcel());
807 double phi_geocentre = double(oad.
gcaz());
809 geocentre_comptel.
radec_deg(phi_geocentre, 90.0-theta_geocentre);
813 for (
int index = 0; index < dri->
m_dri.
npix(); ++index) {
820 double theta = oad.
theta(sky);
821 double phi = oad.
phi(sky);
826 select, status) * omega;
832 chipsi_comptel.
radec_deg(phi, 90.0-theta);
833 eha[index] = geocentre_comptel.dist_deg(chipsi_comptel) - oad.
georad();
838 for (
int i = 0; i <
size(); ++i) {
841 double rates_sum_all = 0.0;
842 double rates_sum_cut = 0.0;
843 double ehacorr = 1.0;
844 for (
int iphibar = 0; iphibar < dri->
nphibar(); ++iphibar) {
847 for (
int index = 0; index < dri->
m_dri.
npix(); ++index) {
848 rates_sum_all += geometry[index] * rates[i];
853 double ehamin = double(iphibar) * dri->
m_phibin + zetamin;
854 for (
int index = 0; index < dri->
m_dri.
npix(); ++index) {
855 if (eha[index] >= ehamin) {
856 rates_sum_cut += geometry[index] * rates[i];
864 if (rates_sum_cut != 0.0) {
865 ehacorr = rates_sum_all / rates_sum_cut;
869 for (
int iphibar = 0; iphibar < dri->
nphibar(); ++iphibar) {
872 double ehamin = double(iphibar) * dri->
m_phibin + zetamin;
875 for (
int index = 0; index < dri->
m_dri.
npix(); ++index) {
879 if (eha[index] >= ehamin) {
882 int inx = index + iphibar * dri->
m_dri.
npix();
885 m_dris[i][inx] += geometry[index] * rates[i] * ehacorr;
925 const double& zetamin,
926 const double& timebin)
929 const double ehacorrmax = 10.0;
932 #if defined(G_DEBUG_COMPUTE_DRWS)
933 std::cout <<
"GCOMDris::compute_drws_phibar" << std::endl;
934 std::cout <<
"=============================" << std::endl;
946 #if defined(G_DEBUG_COMPUTE_DRWS)
947 std::cout <<
"Determine Phibar-dependent event rates" << std::endl;
948 std::cout <<
"--------------------------------------" << std::endl;
954 std::vector<double> rate(dri->
nphibar());
956 std::vector<std::vector<double> > rates(dri->
nphibar());
960 if (events->
size() > 0) {
961 time = (*events)[0]->time().secs();
969 for (
int i_evt = 0; i_evt < events->
size(); ++i_evt) {
982 #if defined(G_COMPUTE_DRWS_EHACORR)
983 if ((event->eha() -
event->phibar()) < zetamin) {
989 while (event->time().secs() > (time + timebin)) {
995 times.append(time + 0.5 * timebin);
998 for (
int iphibar = 0; iphibar < dri->
nphibar(); ++iphibar) {
999 rates[iphibar].push_back(rate[iphibar]);
1000 rate[iphibar] = 0.0;
1014 int iphibar = int((event->phibar() - dri->
phimin()) / dri->
phibin());
1015 if (iphibar >= 0 and iphibar < dri->nphibar()) {
1016 rate[iphibar] += 1.0;
1026 times.append(time + 0.5 * timebin);
1029 for (
int iphibar = 0; iphibar < dri->
nphibar(); ++iphibar) {
1030 rates[iphibar].push_back(rate[iphibar]);
1036 #if defined(G_DEBUG_COMPUTE_DRWS)
1037 std::ofstream debugfile;
1038 debugfile.open(
"compute_drws_phibar_tbin_rates.csv");
1039 debugfile.precision(12);
1040 for (
int i = 0; i < times.size(); ++i) {
1041 debugfile << times[i];
1042 for (
int iphibar = 0; iphibar < dri->
nphibar(); ++iphibar) {
1043 debugfile <<
"," << rates[iphibar][i];
1045 debugfile << std::endl;
1051 #if defined(G_DEBUG_COMPUTE_DRWS)
1052 std::cout <<
"Compute DRWs" << std::endl;
1053 std::cout <<
"------------" << std::endl;
1057 std::vector<double> geometry(dri->
m_dri.
npix());
1058 std::vector<double> eha(dri->
m_dri.
npix());
1069 #if defined(G_DEBUG_COMPUTE_DRWS)
1070 std::ofstream debugfile1;
1071 std::ofstream debugfile2;
1072 debugfile1.open(
"compute_drws_phibar_sp_rates.csv");
1073 debugfile2.open(
"compute_drws_phibar_sp_ehacorr.csv");
1074 debugfile1.precision(12);
1075 debugfile2.precision(12);
1079 for (
int i_oad = 0; i_oad < obs.
oads().
size(); ++i_oad) {
1087 for (
int i = 0; i <
size(); ++i) {
1088 if (!
m_dris[i].use_superpacket(oad, tim, select)) {
1101 std::vector<double> rate_oad(dri->
nphibar());
1102 for (
int iphibar = 0; iphibar < dri->
nphibar(); ++iphibar) {
1103 rate_oad[iphibar] = times.interpolate(time, rates[iphibar]);
1104 if (rate_oad[iphibar] < 0.0) {
1105 rate_oad[iphibar] = 0.0;
1115 double theta_geocentre = double(oad.
gcel());
1116 double phi_geocentre = double(oad.
gcaz());
1118 geocentre_comptel.
radec_deg(phi_geocentre, 90.0-theta_geocentre);
1122 for (
int index = 0; index < dri->
m_dri.
npix(); ++index) {
1129 double theta = oad.
theta(sky);
1130 double phi = oad.
phi(sky);
1135 select, status) * omega;
1141 chipsi_comptel.
radec_deg(phi, 90.0-theta);
1142 eha[index] = geocentre_comptel.dist_deg(chipsi_comptel) - oad.
georad();
1147 #if defined(G_DEBUG_COMPUTE_DRWS)
1153 for (
int iphibar = 0; iphibar < dri->
nphibar(); ++iphibar) {
1156 double ehamin = double(iphibar) * dri->
m_phibin + zetamin;
1159 double rates_sum_all = 0.0;
1160 double rates_sum_cut = 0.0;
1163 for (
int index = 0; index < dri->
m_dri.
npix(); ++index) {
1164 rates_sum_all += geometry[index];
1165 if (eha[index] >= ehamin) {
1166 rates_sum_cut += geometry[index];
1171 double ehacorr = (rates_sum_cut != 0.0) ? rates_sum_all / rates_sum_cut : ehacorrmax;
1172 if (ehacorr > ehacorrmax) {
1173 ehacorr = ehacorrmax;
1177 #if defined(G_COMPUTE_DRWS_EHACORR)
1178 rate_oad[iphibar] *= ehacorr;
1182 #if defined(G_DEBUG_COMPUTE_DRWS)
1183 debugfile1 <<
"," << rate_oad[iphibar];
1184 debugfile2 <<
"," << ehacorr;
1190 #if defined(G_DEBUG_COMPUTE_DRWS)
1191 debugfile1 << std::endl;
1192 debugfile2 << std::endl;
1196 for (
int i = 0; i <
size(); ++i) {
1199 for (
int iphibar = 0; iphibar < dri->
nphibar(); ++iphibar) {
1202 double ehamin = double(iphibar) * dri->
m_phibin + zetamin;
1205 for (
int index = 0; index < dri->
m_dri.
npix(); ++index) {
1209 if (eha[index] >= ehamin) {
1212 int inx = index + iphibar * dri->
m_dri.
npix();
1215 m_dris[i][inx] += geometry[index] * rate_oad[iphibar];
1228 #if defined(G_DEBUG_COMPUTE_DRWS)
1253 const double& zetamin)
1256 #if defined(G_DEBUG_COMPUTE_DRWS)
1257 std::cout <<
"GCOMDris::compute_drws_vetorate" << std::endl;
1258 std::cout <<
"===============================" << std::endl;
1265 #if defined(G_DEBUG_SAVE_WORKING_ARRAYS)
1271 for (
int i = 0; i <
size(); ++i) {
1272 m_dris[i].m_drw_fprompt = 0.5;
1277 for (
int iter = 0; iter < 4; ++iter) {
1328 const double& zetamin)
1331 #if defined(G_DEBUG_COMPUTE_DRWS)
1332 std::cout <<
"GCOMDris::vetorate_setup" << std::endl;
1333 std::cout <<
"========================" << std::endl;
1345 int nphibar = dri0->
nphibar();
1349 #if defined(G_DEBUG_COMPUTE_DRWS)
1350 std::cout <<
"Number of OAD superpackets: " << noads << std::endl;
1351 std::cout <<
"Number of pixels: " << npix << std::endl;
1352 std::cout <<
"Number of Phibar layers: " << nphibar << std::endl;
1353 std::cout <<
"Number of energies: " << neng << std::endl;
1364 for (
int i_oad = 0; i_oad < noads; ++i_oad) {
1375 std::vector<double> veto_rates;
1377 veto_rates.reserve(hdk.
size());
1378 for (
int i = 0; i < hdk.
size(); ++i) {
1379 double rate = hdk.
value(i);
1382 veto_rates.push_back(rate);
1387 std::vector<GSkyDir> skys;
1388 std::vector<double> omegas;
1389 for (
int index = 0; index < dri0->
m_dri.
npix(); ++index) {
1392 skys.push_back(sky);
1393 omegas.push_back(omega);
1397 #if defined(G_DEBUG_COMPUTE_DRWS)
1398 std::cout <<
"Setup node array for veto rate interpolation: ";
1399 std::cout << veto_times.
size() <<
" times, ";
1400 std::cout << veto_rates.size() <<
" rates" << std::endl;
1416 bool terminate =
false;
1419 for (
int i_oad = 0; i_oad < noads; ++i_oad) {
1426 for (
int i = 0; i <
size(); ++i) {
1427 if (
m_dris[i].use_superpacket(oad, tim, select)) {
1444 double theta_geocentre = double(oad.
gcel());
1445 double phi_geocentre = double(oad.
gcaz());
1447 geocentre_comptel.
radec_deg(phi_geocentre, 90.0-theta_geocentre);
1451 double total_geo = 0.0;
1452 for (
int index = 0; index < npix; ++index) {
1455 double theta = oad.
theta(skys[index]);
1456 double phi = oad.
phi(skys[index]);
1461 select, status) * omegas[index];
1464 geo(index) = geometry;
1465 total_geo += geometry;
1471 chipsi_comptel.
radec_deg(phi, 90.0-theta);
1472 eha(index) = geocentre_comptel.dist_deg(chipsi_comptel) - oad.
georad();
1477 if (total_geo > 0.0) {
1478 for (
int iphibar = 0; iphibar < nphibar; ++iphibar) {
1479 double ehamin = double(iphibar) * dri0->
m_phibin + zetamin;
1480 double accepted_geo = 0.0;
1481 for (
int index = 0; index < npix; ++index) {
1482 if (eha(index) >= ehamin) {
1483 accepted_geo += geo(index);
1494 double value = veto_times.
interpolate(time, veto_rates);
1497 for (
int ieng = 0; ieng < neng; ++ieng) {
1505 for (; i_evt < events->
size(); ++i_evt) {
1511 if (event->time() > oad.
tstop()) {
1517 for (
int i = 0; i <
size(); ++i) {
1518 if ((event->energy() >=
m_dris[i].m_ebounds.emin()) &&
1519 (event->energy() <=
m_dris[i].m_ebounds.emax())) {
1526 if (ienergy == -1) {
1537 if (event->time() < dri->
gti().
tstart()) {
1542 else if (event->time() > dri->
gti().
tstop()) {
1550 if (event->time() < oad.
tstart()) {
1564 else if (iphibar >= dri->
nphibar()) {
1570 double ehamin = double(iphibar) * dri->
m_phibin + zetamin;
1571 if (event->eha() < ehamin) {
1581 #if defined(G_DEBUG_COMPUTE_DRWS)
1582 std::cout <<
"Superpacket " << i_oad;
1583 std::cout <<
" i_sp=" << i_sp;
1584 std::cout <<
" time=" << time;
1586 std::cout <<
" total_geo=" << total_geo;
1587 std::cout << std::endl;
1595 if (terminate || i_evt >= events->
size()) {
1602 GNdarray wrk_counts(i_sp, nphibar, neng);
1603 GNdarray wrk_ehacutcorr(i_sp, nphibar);
1605 GNdarray wrk_activrate(i_sp, neng);
1606 for (
int i = 0; i < i_sp; ++i) {
1607 for (
int iphibar = 0; iphibar < nphibar; ++iphibar) {
1608 for (
int ieng = 0; ieng < neng; ++ieng) {
1609 wrk_counts(i, iphibar, ieng) =
m_wrk_counts(i, iphibar, ieng);
1613 for (
int ieng = 0; ieng < neng; ++ieng) {
1639 const double norm = 1.0;
1642 #if defined(G_DEBUG_COMPUTE_DRWS)
1643 std::cout <<
"GCOMDris::vetorate_fit" << std::endl;
1644 std::cout <<
"======================" << std::endl;
1653 #if defined(G_DEBUG_COMPUTE_DRWS)
1654 std::cout <<
"Number of used superpackets: " << nsp << std::endl;
1655 std::cout <<
"Number of Phibar layers: " << nphibar << std::endl;
1656 std::cout <<
"Number of energies: " << neng << std::endl;
1663 double nvetorate = 0.0;
1664 for (
int isp = 0; isp < nsp; ++isp) {
1669 if (nvetorate > 0.0) {
1670 for (
int isp = 0; isp < nsp; ++isp) {
1676 for (
int ieng = 0; ieng < neng; ++ieng) {
1677 double nactivrate = 0.0;
1678 for (
int isp = 0; isp < nsp; ++isp) {
1683 if (nactivrate > 0.0) {
1684 for (
int isp = 0; isp < nsp; ++isp) {
1691 for (
int ieng = 0; ieng < neng; ++ieng) {
1696 par.
range(0.0, 1.0);
1704 #if defined(G_DEBUG_COMPUTE_DRWS)
1717 double logL = opt.
value();
1720 double fprompt = pars[0]->value();
1721 double e_fprompt = pars[0]->error();
1722 double factiv = 1.0 - fprompt;
1725 for (
int isp = 0; isp < nsp; ++isp) {
1732 m_dris[ieng].m_drw_fprompt = fprompt;
1733 m_dris[ieng].m_drw_e_fprompt = e_fprompt;
1737 #if defined(G_DEBUG_COMPUTE_DRWS)
1739 std::cout <<
" logL=" << logL;
1740 std::cout <<
" fprompt=" << fprompt <<
" +/- " << e_fprompt;
1741 std::cout << std::endl;
1757 const double norm = 1.0;
1758 const double t_hour = 1.0;
1761 #if defined(G_DEBUG_COMPUTE_DRWS)
1762 std::cout <<
"GCOMDris::vetorate_update_activ" << std::endl;
1763 std::cout <<
"===============================" << std::endl;
1772 double nsmooth = 3600.0/16.384 * t_hour;
1773 double weight = -0.5 / (nsmooth * nsmooth);
1776 for (
int isp = 0; isp < nsp/2; ++isp) {
1777 double kvalue =
std::exp(weight*isp*isp);
1778 if (kvalue <= 0.0) {
1781 kernel(isp) = kvalue;
1784 kernel(nsp-isp) = kvalue;
1789 for (
int isp = 0; isp < nsp; ++isp) {
1793 GFft fft_kernel(kernel);
1796 for (
int ieng = 0; ieng < neng; ++ieng) {
1801 for (
int isp = 0; isp < nsp; ++isp) {
1802 for (
int iphibar = 0; iphibar < nphibar; ++iphibar) {
1806 for (
int iphibar = 0; iphibar < nphibar; ++iphibar) {
1807 double nevents = 0.0;
1808 double nmodel = 0.0;
1809 for (
int isp = 0; isp < nsp; ++isp) {
1810 if (model(isp, iphibar) > 0.0) {
1812 nmodel += model(isp, iphibar);
1816 n(iphibar) = norm * (nevents / nmodel);
1817 for (
int isp = 0; isp < nsp; ++isp) {
1818 model(isp, iphibar) *= n(iphibar);
1827 for (
int isp = 0; isp < nsp; ++isp) {
1828 for (
int iphibar = 0; iphibar < nphibar; ++iphibar) {
1829 residual(isp) +=
m_wrk_counts(isp, iphibar, ieng) - model(isp, iphibar);
1835 GFft fft_residual(residual);
1836 fft_residual = fft_residual * fft_kernel;
1837 residual = fft_residual.
backward();
1840 GFft fft_ehacutcorr(ehacutcorr);
1841 fft_ehacutcorr = fft_ehacutcorr * fft_kernel;
1842 ehacutcorr = fft_ehacutcorr.
backward();
1845 for (
int isp = 0; isp < nsp; ++isp) {
1846 if (ehacutcorr(isp) > 0.0) {
1847 residual(isp) /= ehacutcorr(isp);
1852 for (
int isp = 0; isp < nsp; ++isp) {
1855 double update = activ + residual(isp);
1856 if (update < 0.05 * activ) {
1857 update = 0.05 * activ;
1864 double nactivrate = 0.0;
1865 for (
int isp = 0; isp < nsp; ++isp) {
1868 if (nactivrate > 0.0) {
1869 for (
int isp = 0; isp < nsp; ++isp) {
1890 const double& zetamin)
1893 #if defined(G_DEBUG_COMPUTE_DRWS)
1894 std::cout <<
"GCOMDris::vetorate_generate" << std::endl;
1895 std::cout <<
"===========================" << std::endl;
1907 int nphibar = dri0->
nphibar();
1911 #if defined(G_DEBUG_COMPUTE_DRWS)
1912 std::cout <<
"Number of OAD superpackets: " << noads << std::endl;
1913 std::cout <<
"Number of pixels: " << npix << std::endl;
1914 std::cout <<
"Number of Phibar layers: " << nphibar << std::endl;
1915 std::cout <<
"Number of energies: " << neng << std::endl;
1923 std::vector<GSkyDir> skys;
1924 std::vector<double> omegas;
1925 for (
int index = 0; index < npix; ++index) {
1928 skys.push_back(sky);
1929 omegas.push_back(omega);
1944 for (
int i_oad = 0; i_oad < noads; ++i_oad) {
1960 double theta_geocentre = double(oad.
gcel());
1961 double phi_geocentre = double(oad.
gcaz());
1963 geocentre_comptel.
radec_deg(phi_geocentre, 90.0-theta_geocentre);
1967 for (
int index = 0; index < npix; ++index) {
1970 double theta = oad.
theta(skys[index]);
1971 double phi = oad.
phi(skys[index]);
1976 select, status) * omegas[index];
1982 chipsi_comptel.
radec_deg(phi, 90.0-theta);
1983 eha(index) = geocentre_comptel.dist_deg(chipsi_comptel) - oad.
georad();
1988 for (
int i = 0; i <
size(); ++i) {
1994 for (
int iphibar = 0; iphibar < nphibar; ++iphibar) {
1997 double ehamin = double(iphibar) * dri->
m_phibin + zetamin;
2000 for (
int index = 0; index < npix; ++index) {
2004 if (eha(index) >= ehamin) {
2007 int inx = index + iphibar * npix;
2042 #if defined(G_DEBUG_COMPUTE_DRWS)
2043 std::cout <<
"GCOMDris::vetorate_finish" << std::endl;
2044 std::cout <<
"=========================" << std::endl;
2052 for (
int i_oad = 0; i_oad < noads; ++i_oad) {
2059 #if defined(G_DEBUG_COMPUTE_DRWS)
2060 std::cout <<
"Number of OAD superpackets: " << noads << std::endl;
2061 std::cout <<
"Number of used superpackets: " << nsp << std::endl;
2065 for (
int i = 0; i <
size(); ++i) {
2081 for (
int i_oad = 0; i_oad < noads; ++i_oad) {
2092 tjd(isp) = oad.
tjd();
2093 tics(isp) = oad.
tics();
2129 #if defined(G_DEBUG_COMPUTE_DRWS)
2130 std::cout <<
"GCOMDris::vetorate_save" << std::endl;
2131 std::cout <<
"=======================" << std::endl;
2148 for (
int isp = 0; isp < nsp; ++isp) {
2149 for (
int iphibar = 0; iphibar < nphibar; ++iphibar) {
2150 for (
int ieng = 0; ieng < neng; ++ieng) {
2151 image_counts(isp, iphibar, ieng) =
m_wrk_counts(isp, iphibar, ieng);
2155 for (
int ieng = 0; ieng < neng; ++ieng) {
2160 for (
int ioad = 0; ioad < noads; ++ioad) {
2165 image_counts.
extname(
"COUNTS");
2166 image_ehacutcorr.
extname(
"EHACUTCORR");
2167 image_vetorate.
extname(
"VETORATE");
2168 image_activrate.
extname(
"ACTIVRATE");
2169 image_use_sp.
extname(
"SPUSAGE");
2173 fits.
append(image_counts);
2174 fits.
append(image_ehacutcorr);
2175 fits.
append(image_vetorate);
2176 fits.
append(image_activrate);
2177 fits.
append(image_use_sp);
2180 fits.
saveto(filename,
true);
2197 #if defined(G_DEBUG_COMPUTE_DRWS)
2198 std::cout <<
"GCOMDris::vetorate_load" << std::endl;
2199 std::cout <<
"=======================" << std::endl;
2203 GFits fits(filename);
2213 int noads = image_use_sp->
naxes(0);
2214 int nsp = image_counts->
naxes(0);
2215 int nphibar = image_counts->
naxes(1);
2216 int neng = image_counts->
naxes(2);
2219 #if defined(G_DEBUG_COMPUTE_DRWS)
2220 std::cout <<
"Number of OAD superpackets: " << noads << std::endl;
2221 std::cout <<
"Number of used superpackets: " << nsp << std::endl;
2222 std::cout <<
"Number of Phibar layers: " << nphibar << std::endl;
2223 std::cout <<
"Number of energies: " << neng << std::endl;
2234 for (
int isp = 0; isp < nsp; ++isp) {
2235 for (
int iphibar = 0; iphibar < nphibar; ++iphibar) {
2236 for (
int ieng = 0; ieng < neng; ++ieng) {
2241 for (
int ieng = 0; ieng < neng; ++ieng) {
2246 for (
int ioad = 0; ioad < noads; ++ioad) {
2290 for (
int isp = 0; isp <
m_nsp; ++isp) {
2292 if (vetorate > 0.0) {
2294 for (
int iphibar = 0; iphibar <
m_nphibar; ++iphibar) {
2306 for (
int iphibar = 0; iphibar <
m_nphibar; ++iphibar) {
2307 for (
int isp = 0; isp <
m_nsp; ++isp) {
2330 double fprompt = pars[0]->value();
2331 double factiv = 1.0 - fprompt;
2339 GNdarray model = fprompt * m_vetorate + factiv * m_activrate;
2343 for (
int iphibar = 0; iphibar < m_nphibar; ++iphibar) {
2344 for (
int isp = 0; isp < m_nsp; ++isp) {
2345 if (model(isp, iphibar) > 0.0) {
2346 nevents(iphibar) += m_this->m_wrk_counts(isp, iphibar, m_ieng);
2347 nmodel(iphibar) += model(isp, iphibar);
2350 if (nmodel(iphibar) > 0.0) {
2351 norm(iphibar) = m_norm * nevents(iphibar) / nmodel(iphibar);
2352 for (
int isp = 0; isp < m_nsp; ++isp) {
2353 model_norm(isp, iphibar) *=
norm(iphibar);
2360 for (
int isp = 0; isp < m_nsp; ++isp) {
2361 for (
int iphibar = 0; iphibar < m_nphibar; ++iphibar) {
2362 if (model_norm(isp, iphibar) > 0.0) {
2363 m_value -= m_this->m_wrk_counts(isp, iphibar, m_ieng) *
2364 std::log(model_norm(isp, iphibar)) - model_norm(isp, iphibar);
2370 for (
int iphibar = 0; iphibar < m_nphibar; ++iphibar) {
2373 double nmodel2 = nmodel(iphibar) * nmodel(iphibar);
2374 double g_norm = -m_norm * nevents(iphibar) / nmodel2 * m_diffrate_sum(iphibar);
2377 for (
int isp = 0; isp < m_nsp; ++isp) {
2380 if (model_norm(isp, iphibar) > 0.0) {
2383 double fb = m_this->m_wrk_counts(isp, iphibar, m_ieng) / model_norm(isp, iphibar);
2384 double fc = (1.0 - fb);
2385 double fa = fb / model_norm(isp, iphibar);
2388 double g =
norm(iphibar) * m_diffrate(isp, iphibar) + g_norm * model(isp, iphibar);
2391 m_gradient[0] += fc * g;
2394 m_curvature(0,0) += fa * g * g;
COMPTEL instrument status class.
int size(void) const
Return number of nodes in node array.
COMPTEL instrument status class definition.
GCOMDris * m_this
Pointer to GCOMDris object.
const double & value(const int &index) const
Return reference to Housekeeping Data value.
GCOMDris & operator=(const GCOMDris &dris)
Assignment operator.
void compute_drws(const GCOMObservation &obs, const GCOMSelection &select=GCOMSelection(), const double &zetamin=5.0, const double &timebin=300.0, const std::string &method="phibar")
Compute background weighting cubes.
Double precision FITS image class definition.
FITS table double column class interface definition.
Abstract FITS image base class.
virtual void eval(const GOptimizerPars &pars)
Log-likelihood function evaluation.
const GCOMOads & oads(void) const
Return Orbit Aspect Data.
Optimizer function abstract base class.
const double & factor_gradient(void) const
Return parameter factor gradient.
double norm(const GVector &vector)
Computes vector norm.
void max_iter(const int &max_iter)
Set maximum number of iterations.
GTime m_tstart
Selection start time.
void clear(void)
Clear array.
GCOMSelection m_selection
Selection parameters.
Sparse matrix class interface definition.
const double & phimin(void) const
Return minimum Compton scatter angle of DRI cube.
const GCOMHkds & hkds(void) const
Return Housekeeping Data collection.
GNdarray m_diffrate
Vetorate - activation rate array.
void reserve(const int &num)
Reserves space for Data space instances in container.
virtual double value(void) const
Return function value.
COMPTEL Data Space container class.
COMPTEL Data Space class definition.
COMPTEL event list class definition.
double m_phibin
Phibar binsize (deg)
Optimizer parameter container class.
GNdarray m_wrk_counts
3D event cube array
COMPTEL observation class interface definition.
COMPTEL event atom class definition.
const float & gcel(void) const
Return Geocentre zenith angle.
virtual void optimize(GOptimizerFunction &fct, GOptimizerPars &pars)
Optimize function parameters.
void reserve(const int &num)
Reserves space for nodes in node array.
double sum(const GVector &vector)
Computes vector sum.
GMatrixSparse m_curvature
Curvature matrix.
void compute_drws_phibar(const GCOMObservation &obs, const GCOMEventList *events, const GCOMSelection &select, const double &zetamin, const double &timebin)
Compute background weighting cubes using Phibar dependent rates.
GFitsTableCol * append(const GFitsTableCol &column)
Append column to the table.
bool is_empty(void) const
Signals if there are no Data space instances in container.
double phi(const GSkyDir &sky) const
Return azimuth angle of sky direction in COMPTEL coordinates.
GCOMDris(void)
Void constructor.
const GTime & tstop(void) const
Return stop time of superpacket.
const std::vector< int > & shape(void) const
Return shape of array.
int size(void) const
Return number of Orbit Aspect Data in container.
likelihood(GCOMDris *dris, const int &ieng, const double &norm)
Log-likelihood function constructor.
FITS file class interface definition.
GNdarray m_vetorate
Vetorate array multiplied by EHA cut correction.
COMPTEL Data Space container class definition.
COMPTEL selection set class.
COMPTEL Good Time Intervals class definition.
GNdarray backward(void) const
Backward Fast Fourier Transform.
void vetorate_save(const GFilename &filename) const
Save working arrays for vetorate computation.
GVector m_gradient
Gradient vector.
const float & georad(void) const
Return apparent radius of Earth.
int m_nsp
Number of superpackets.
COMPTEL Orbit Aspect Data class.
void extend(const GCOMDris &dris)
Append Data Space container.
void cout(const bool &flag)
Set standard output stream (cout) flag.
Implementation of support function used by COMPTEL classes.
int size(void) const
Return number of Good Time Intervals.
virtual void clear(void)
Clear binary table.
GCOMDri & at(const int &index)
Return reference to Data Space.
bool is_empty(void) const
Signals if there are no nodes in node array.
const GTime & tstart(void) const
Return start time of superpacket.
COMPTEL selection set class definition.
void saveto(const GFilename &filename, const bool &clobber=false)
Saves to specified FITS file.
void vetorate_fit(void)
Fit working arrays for vetorate computation.
Information logger interface definition.
const GCOMTim & tim(void) const
Return COMPTEL Good Time Intervals.
virtual int size(void) const
Return number of events in list.
bool has_pulsar(void) const
Signals that pulsar selection should be performed.
GSkyDir inx2dir(const int &index) const
Returns sky direction of pixel.
Double precision FITS image class.
GNdarray m_vetorate_sum
Time integrated vetorate array.
GTime m_tstop
Selection stop time.
Fast Fourier Transformation class.
void copy_members(const GCOMDris &dris)
Copy class members.
virtual ~GCOMDris(void)
Destructor.
GNdarray m_wrk_vetorate
1D vetorates array
virtual double pixel(const int &ix) const =0
double compute_geometry(const int &tjd, const double &theta, const double &phi, const GCOMSelection &select, const GCOMStatus &status) const
Compute DRG geometry factor.
GVector log(const GVector &vector)
Computes natural logarithm of vector elements.
double interpolate(const double &value, const std::vector< double > &vector) const
Interpolate value.
void free_members(void)
Delete class members.
GNdarray m_activrate_sum
Time integrated activation rate array.
GNdarray m_wrk_rate
2D rate array
GCOMDris * clone(void) const
Clone Data Space container.
Optimizer parameters base class definition.
Good Time Interval class.
Short integer FITS image class.
std::string print(const GChatter &chatter=NORMAL) const
Print Data Space container.
int size(void) const
Return number of Housekeeping Data in container.
void init_members(void)
Initialise class members.
GNdarray m_wrk_activrate
2D activation rate array
void radec_deg(const double &ra, const double &dec)
Set equatorial sky direction (degrees)
N-dimensional array class.
const GTime & tstop(void) const
Returns latest stop time in Good Time Intervals.
Levenberg Marquardt optimizer class interface definition.
const GTime & time(const int &index) const
Return reference to Housekeeping Data time.
const GPulsar & pulsar(void) const
Return pulsar.
const std::string & extname(void) const
Return extension name.
const GTime & tstart(void) const
Returns earliest start time in Good Time Intervals.
Short integer FITS image class definition.
void vetorate_finish(const GCOMObservation &obs)
Finish DRWs.
FITS table long integer column.
void vetorate_load(const GFilename &filename)
Load working arrays for vetorate computation.
GNdarray m_activrate
Activation rate array multiplied by EHA cut correction.
int nphibar(void) const
Return number of Phibar bins.
void clear(void)
Clear Data Space container.
GOptimizerPar * append(const GOptimizerPar &par)
Append parameter to container.
int naxes(const int &axis) const
Return dimension of an image axis.
Fast Fourier transformation class interface definition.
COMPTEL Housekeeping Data container class.
bool use_event(const GCOMEventAtom &event) const
Check if event should be used.
double m_norm
Normalisation value.
const GGti & gti(void) const
Return Good Time Intervals of DRI cube.
int m_ieng
DRW energy bin.
std::vector< bool > m_wrk_use_sp
1D superpacket usage array
GFitsImage * image(const int &extno)
Get pointer to image HDU.
const double & secs(void) const
Return time in seconds in native reference (TT)
std::vector< GCOMDri > m_dris
Data space instances.
GGti validity(void) const
Return validity intervals of pulsar ephemerides.
void compute_drws_vetorate(const GCOMObservation &obs, const GCOMEventList *events, const GCOMSelection &select, const double &zetamin)
Compute background weighting cubes using veto rates.
GFitsBinTable m_drw_table
DRW binary table to append to the FITS file.
const int & tjd(void) const
Return Truncated Julian Days of Orbit Aspect Record.
void range(const double &min, const double &max)
Set minimum and maximum parameter boundaries.
Interface class for COMPTEL observations.
virtual int iter(void) const
Return number of iterations.
GNdarray m_diffrate_sum
Time integrated difference rate array.
virtual void errors(GOptimizerFunction &fct, GOptimizerPars &pars)
Compute parameter uncertainties.
virtual GEvents * events(void)
Return events.
Exception handler interface definition.
FITS table long integer column class interface definition.
void compute_drws_energy(const GCOMObservation &obs, const GCOMEventList *events, const GCOMSelection &select, const double &zetamin, const double &timebin)
Compute background weighting cubes using energy dependent rates.
GFitsHDU * append(const GFitsHDU &hdu)
Append HDU to FITS file.
COMPTEL event list class.
COMPTEL Data Space class.
GVector exp(const GVector &vector)
Computes exponential of vector elements.
GCOMDri & insert(const int &index, const GCOMDri &dri)
Insert Data Space into container.
Optimizer parameter class interface definition.
COMPTEL Good Time Intervals class.
double solidangle(const int &index) const
Returns solid angle of pixel.
void vetorate_setup(const GCOMObservation &obs, const GCOMEventList *events, const GCOMSelection &select, const double &zetamin)
Setup working arrays for vetorate computation.
int size(void) const
Return number of Data space instances in container.
const int & tics(void) const
Return tics of Orbit Aspect Record.
int m_nphibar
Number of phibar layers.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
void append(const double &node)
Append one node to array.
void remove(const int &index)
Remove Data Space from container.
const int & npix(void) const
Returns number of pixels.
GNdarray m_wrk_ehacutcorr
2D geometry response array
const double & phibin(void) const
Return Compton scatter angle bin of DRI cube.
void vetorate_update_activ(void)
Update activation rate.
void reduce(const GGti >i)
Reduces Good Time Intervals to intersection with intervals.
void close(void)
Close FITS file.
void eps(const double &eps)
Set requested absolute convergence precision.
void vetorate_generate(const GCOMObservation &obs, const GCOMSelection &select, const double &zetamin)
Generate DRWs.
Levenberg Marquardt optimizer class.
GCOMDri & append(const GCOMDri &dri)
Append Data Space to container.
double m_phimin
Phibar minimum (deg)
FITS table double column.
double theta(const GSkyDir &sky) const
Return zenith angle of sky direction in COMPTEL coordinates.
COMPTEL Orbit Aspect Data container class definition.
COMPTEL Orbit Aspect Data class definition.
Mathematical function definitions.
const float & gcaz(void) const
Return Geocentre azimuth angle.
std::string status_string(void) const
Set fit status string.
COMPTEL event atom class.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Optimizer parameter class.