Commit 0df5508d authored by Qi Chu's avatar Qi Chu
Browse files

Merge branch 'pwc_calcfap_fixes' into 'master'

Fix off-by-one errors in 'trigger_stats_xml_from_xml'

See merge request lscsoft/spiir!16
parents b7523654 8d5064ff
......@@ -1008,14 +1008,23 @@ gboolean trigger_stats_xml_from_xml(TriggerStatsXML *stats,
XmlArray *array_rank_pdf = (XmlArray *)malloc(sizeof(XmlArray) * nodes);
XmlArray *array_rank_fap = (XmlArray *)malloc(sizeof(XmlArray) * nodes);
// [THA]: We hold `index` to be the index into the various arrays that we
// index for printing. We also only have this many (+1)s because icombo
// starts from 0 and we need to make sure that the 0th combo & icombo != 0
// if its not in the actual combo. Thus we add 1 to get the "actual"
// combination and just use combo for indexing the combomap
// This loop is over 'combo', which enumerates all possible combinations of
// detectors. The if() statement pulls out these two cases:
// * all active detectors (combo == icombo)
// * a single detector, that is active (second clause)
// This way we print out only statistics for the individual detectors as
// well as all detectors combined (but not subsets). A reminder that (icombo
// + 1) and (combo + 1) essentially result in a bitfield on detectors.
//
// Within the loop, note that 'combo' is the detector being looked at,
// 'index' is how many combos we've printed out so far, and 'pos_xns' is
// where we actually should be in the 'xns' array.
int pos_xns, index;
for (combo = 0, index = 0; combo < icombo + 1; combo++) {
if ((combo + 1) & (icombo + 1) == combo + 1) {
if (combo == icombo // all active ifos, OR
|| ( ((combo + 1) & (icombo + 1)) // (ifo active, AND
&& __builtin_popcount(combo + 1) == 1 ) ) // single ifo only)
{
pos_xns = index;
sprintf((char *)xns[pos_xns].tag, "%s:%s_%s:array",
stats->feature_xmlname->str, IFOComboMap[combo].name,
......@@ -1023,61 +1032,61 @@ gboolean trigger_stats_xml_from_xml(TriggerStatsXML *stats,
xns[pos_xns].processPtr = readArray;
xns[pos_xns].data = &(array_lgsnr_rate[index]);
pos_xns += nifo;
pos_xns += nodes;
sprintf((char *)xns[pos_xns].tag, "%s:%s_%s:array",
stats->feature_xmlname->str, IFOComboMap[combo].name,
CHISQ_RATE_SUFFIX);
xns[pos_xns].processPtr = readArray;
xns[pos_xns].data = &(array_lgchisq_rate[index]);
pos_xns += nifo;
pos_xns += nodes;
sprintf((char *)xns[pos_xns].tag, "%s:%s_%s:array",
stats->feature_xmlname->str, IFOComboMap[combo].name,
SNR_CHISQ_RATE_SUFFIX);
xns[pos_xns].processPtr = readArray;
xns[pos_xns].data = &(array_lgsnr_lgchisq_rate[index]);
pos_xns += nifo;
pos_xns += nodes;
sprintf((char *)xns[pos_xns].tag, "%s:%s_%s:array",
stats->feature_xmlname->str, IFOComboMap[combo].name,
SNR_CHISQ_PDF_SUFFIX);
xns[pos_xns].processPtr = readArray;
xns[pos_xns].data = &(array_lgsnr_lgchisq_pdf[index]);
pos_xns += nifo;
pos_xns += nodes;
sprintf((char *)xns[pos_xns].tag, "%s:%s_%s:array",
stats->rank_xmlname->str, IFOComboMap[combo].name,
RANK_MAP_SUFFIX);
xns[pos_xns].processPtr = readArray;
xns[pos_xns].data = &(array_rank_map[index]);
pos_xns += nifo;
pos_xns += nodes;
sprintf((char *)xns[pos_xns].tag, "%s:%s_nevent:param",
stats->feature_xmlname->str, IFOComboMap[combo].name);
xns[pos_xns].processPtr = readParam;
xns[pos_xns].data = &(param_nevent[index]);
pos_xns += nifo;
pos_xns += nodes;
sprintf((char *)xns[pos_xns].tag, "%s:%s_livetime:param",
stats->feature_xmlname->str, IFOComboMap[combo].name);
xns[pos_xns].processPtr = readParam;
xns[pos_xns].data = &(param_livetime[index]);
pos_xns += nifo;
pos_xns += nodes;
sprintf((char *)xns[pos_xns].tag, "%s:%s_%s:array",
stats->rank_xmlname->str, IFOComboMap[combo].name,
RANK_RATE_SUFFIX);
xns[pos_xns].processPtr = readArray;
xns[pos_xns].data = &(array_rank_rate[index]);
pos_xns += nifo;
pos_xns += nodes;
sprintf((char *)xns[pos_xns].tag, "%s:%s_%s:array",
stats->rank_xmlname->str, IFOComboMap[combo].name,
RANK_PDF_SUFFIX);
xns[pos_xns].processPtr = readArray;
xns[pos_xns].data = &(array_rank_pdf[index]);
pos_xns += nifo;
pos_xns += nodes;
sprintf((char *)xns[pos_xns].tag, "%s:%s_%s:array",
stats->rank_xmlname->str, IFOComboMap[combo].name,
RANK_FAP_SUFFIX);
......@@ -1089,7 +1098,7 @@ gboolean trigger_stats_xml_from_xml(TriggerStatsXML *stats,
XmlParam *param_hist_trials = (XmlParam *)malloc(sizeof(XmlParam) * 1);
pos_xns = nelem * nifo;
pos_xns = nelem * nodes;
GString *hist_name = g_string_new(NULL);
g_string_printf(hist_name, "%s:hist_trials:param",
stats->feature_xmlname->str);
......@@ -1114,7 +1123,7 @@ gboolean trigger_stats_xml_from_xml(TriggerStatsXML *stats,
g_assert(array_lgsnr_rate[0].dim[0] == nbin_x);
g_assert(array_lgchisq_rate[0].dim[0] == nbin_y);
for (index = 0; index < nifo; index++) {
for (index = 0; index < nodes; index++) {
TriggerStats *cur_stats = multistats[index];
FeatureStats *feature = cur_stats->feature;
RankingStats *rank = cur_stats->rank;
......@@ -1158,7 +1167,7 @@ gboolean trigger_stats_xml_from_xml(TriggerStatsXML *stats,
/*
* free the allocated memory for xml reading
*/
for (index = 0; index < nifo; index++) {
for (index = 0; index < nodes; index++) {
free(array_lgsnr_rate[index].data);
free(array_lgchisq_rate[index].data);
free(array_lgsnr_lgchisq_rate[index].data);
......
......@@ -188,7 +188,9 @@ static int process_stats_full(
cohfar_get_stats_from_file(in_fnames, bgstats_in, bgstats_out,
&hist_trials);
if (*update_pdf == 1) {
for (ifo = 0; ifo < nifo; ifo++) {
// nifo+1 : single detectors and detector combination
// e.g. H1L1V1: H1, L1, V1, H1L1V1
for (ifo = 0; ifo < nifo+1; ifo++) {
trigger_stats_feature_rate_to_pdf(
sgstats_out->multistats[ifo]->feature);
trigger_stats_feature_to_rank(sgstats_out->multistats[ifo]->feature,
......@@ -245,7 +247,9 @@ static int process_stats_single(gchar **in_fnames,
TriggerStatsXML *stats_out = trigger_stats_xml_create(*pifos, type);
cohfar_get_stats_from_file(in_fnames, stats_in, stats_out, &hist_trials);
if (*update_pdf == 1) {
for (ifo = 0; ifo < nifo; ifo++) {
// nifo+1 : single detectors and detector combination
// e.g. H1L1V1: H1, L1, V1, H1L1V1
for (ifo = 0; ifo < nifo+1; ifo++) {
trigger_stats_feature_rate_to_pdf(
stats_out->multistats[ifo]->feature);
trigger_stats_feature_to_rank(stats_out->multistats[ifo]->feature,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment