Exemple #1
0
/***********************************************************************//**
 * @brief Test binned observation handling
 ***************************************************************************/
void TestGCTAObservation::test_binned_obs(void)
{
    // Set filenames
    const std::string file1 = "test_cta_obs_binned.xml";

    // Declare observations
    GObservations   obs;
    GCTAObservation run;

    // Load binned CTA observation
    test_try("Load unbinned CTA observation");
    try {
        run.load_binned(cta_cntmap);
        run.response(cta_irf,cta_caldb);
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Test XML loading
    test_try("Test XML loading");
    try {
        obs = GObservations(cta_bin_xml);
        obs.save(file1);
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Exit test
    return;
 
}
Exemple #2
0
/***********************************************************************//**
 * @brief Test binned observation handling for a specific dataset
 *
 * @param[in] datadir Directory of test data.
 * @param[in] irf Instrument response function.
 *
 * Verifies the ability to handle binned Fermi/LAT data.
 ***************************************************************************/
void TestGLATObservation::test_one_binned_obs(const std::string& datadir, const std::string& irf)
{
    // Set filenames
    std::string lat_cntmap  = datadir+"/cntmap.fits";
    std::string lat_srcmap  = datadir+"/srcmap.fits";
    std::string lat_expmap  = datadir+"/binned_expmap.fits";
    std::string lat_ltcube  = datadir+"/ltcube.fits";
    std::string lat_bin_xml = datadir+"/obs_binned.xml";
    std::string file1       = "test_lat_obs_binned.xml";

    // Declare observations
    GObservations   obs;
    GLATObservation run;

    // Determine number of bins and events in counts map
    GFits       cntmap(lat_cntmap);
    GFitsImage* image   = cntmap.image(0);
    double      nevents = 0.0;
    int         nsize   = image->size();
    for (int i = 0; i < nsize; ++i) {
        nevents += image->pixel(i);
    }
    cntmap.close();

    // Try loading event list
    GLATEventCube cube(lat_cntmap);
    test_value(cube.number(), nevents, "Test number of events in cube.");

    // Load LAT binned observation from counts map
    test_try("Load LAT binned observation");
    try {
        run.load_binned(lat_cntmap, "", "");
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Reload LAT binned observation from source map
    test_try("Reload LAT binned observation");
    try {
        run.load_binned(lat_srcmap, "", "");
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Add observation (twice) to data
    test_try("Append observation twice");
    try {
        run.id("0001");
        obs.append(run);
        run.id("0002");
        obs.append(run);
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Loop over all events using iterator
    const GEvents* events = run.events();
    int num = 0;
    int sum = 0;
    for (int i = 0; i < events->size(); ++i) {
        num++;
        sum += (int)((*events)[i]->counts());
    }
    test_value(sum, nevents, 1.0e-20, "Test event iterator (counts)");
    test_value(num, nsize, 1.0e-20, "Test event iterator (bins)");

    // Test mean PSF
    test_try("Test mean PSF");
    try {
        run.load_binned(lat_srcmap, lat_expmap, lat_ltcube);
        run.response(irf, lat_caldb);
        GSkyDir dir;
        GLATMeanPsf psf(dir, run);
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Test XML loading
    test_try("Test XML loading");
    try {
        setenv("CALDB", lat_caldb.c_str(), 1);
        obs = GObservations(lat_bin_xml);
        obs.save(file1);
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Exit test
    return;

}
Exemple #3
0
/***********************************************************************//**
 * @brief Test unbinned observation handling
 ***************************************************************************/
void TestGCTAObservation::test_unbinned_obs(void)
{
    // Set filenames
    const std::string file1 = "test_cta_obs_unbinned.xml";

    // Declare observations
    GObservations   obs;
    GCTAObservation run;

    // Load unbinned CTA observation
    test_try("Load unbinned CTA observation");
    try {
        run.load_unbinned(cta_events);
        run.response(cta_irf,cta_caldb);
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Add observation (twice) to data
    test_try("Load unbinned CTA observation");
    try {
        obs.append(run);
        obs.append(run);
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Loop over all events using iterators
    int num = 0;
    for (GObservations::iterator event = obs.begin(); event != obs.end(); ++event) {
        num++;
    }
    test_value(num, 8794, 1.0e-20, "Test observation iterator");

    // Loop over all events using iterator
    num = 0;
    GCTAEventList *ptr = static_cast<GCTAEventList*>(const_cast<GEvents*>(run.events()));
    for (GCTAEventList::iterator event = ptr->begin(); event != ptr->end(); ++event) {
        num++;
    }
    test_value(num, 4397, 1.0e-20, "Test event iterator");

    // Test XML loading
    test_try("Test XML loading");
    try {
        obs = GObservations(cta_unbin_xml);
        obs.save(file1);
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Exit test
    return;
 
}
Exemple #4
0
/***********************************************************************//**
 * @brief Test unbinned observation handling for a specific dataset
 *
 * @param[in] datadir Directory of test data.
 *
 * Verifies the ability to handle unbinned Fermi/LAT data.
 ***************************************************************************/
void TestGLATObservation::test_one_unbinned_obs(const std::string& datadir)
{
    // Set filenames
    std::string lat_ft1       = datadir+"/ft1.fits";
    std::string lat_ft2       = datadir+"/ft2.fits";
    std::string lat_unbin_xml = datadir+"/obs_unbinned.xml";
    std::string file1         = "test_lat_obs_unbinned.xml";

    // Declare observations
    GObservations   obs;
    GLATObservation run;

    // Determine number of events in FT1 file
    GFits ft1(lat_ft1);
    int nevents = ft1.table("EVENTS")->nrows();
    ft1.close();

    // Try loading event list
    GLATEventList list(lat_ft1);
    test_value(list.number(), nevents, "Test number of events in list.");

    // Load unbinned LAT observation
    test_try("Load unbinned LAT observation");
    try {
        run.load_unbinned(lat_ft1, lat_ft2, "");
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Add observation (twice) to data
    test_try("Append observation twice");
    try {
        run.id("0001");
        obs.append(run);
        run.id("0002");
        obs.append(run);
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Loop over all events
    const GEvents *ptr = run.events();
    int num = 0;
    for (int i = 0; i < ptr->size(); ++i) {
        num++;
    }
    test_value(num, nevents, 1.0e-20, "Test event iterator");

    // Test XML loading
    test_try("Test XML loading");
    try {
        setenv("CALDB", lat_caldb.c_str(), 1);
        obs = GObservations(lat_unbin_xml);
        obs.save(file1);
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Exit test
    return;

}