/***********************************************************************//** * @brief Set event bin * * @param[in] index Event index [0,...,size()-1]. * * @exception GException::out_of_range * Event index is outside valid range. * @exception GCTAException::no_energies * Energy vectors have not been set up. * @exception GCTAException::no_dirs * Sky directions and solid angles vectors have not been set up. * * This method provides the event attributes to the event bin. The event bin * is in fact physically stored in the event cube, and only a single event * bin is indeed allocated. This method sets up the pointers in the event * bin so that a client can easily access the information of individual bins * as if they were stored in an array. ***************************************************************************/ void GCTAEventCube::set_bin(const int& index) { // Optionally check if the index is valid #if defined(G_RANGE_CHECK) if (index < 0 || index >= size()) throw GException::out_of_range(G_SET_BIN, index, 0, size()-1); #endif // Check for the existence of energies and energy widths if (m_energies.size() != ebins() || m_ewidth.size() != ebins()) throw GCTAException::no_energies(G_SET_BIN); // Check for the existence of sky directions and solid angles if (m_dirs.size() != npix() || m_omega.size() != npix()) throw GCTAException::no_dirs(G_SET_BIN); // Get pixel and energy bin indices. int ipix = index % npix(); int ieng = index / npix(); // Set pointers m_bin.m_counts = &(m_map.pixels()[index]); m_bin.m_energy = &(m_energies[ieng]); m_bin.m_time = &m_time; m_bin.m_dir = &(m_dirs[ipix]); m_bin.m_omega = &(m_omega[ipix]); m_bin.m_ewidth = &(m_ewidth[ieng]); m_bin.m_ontime = &m_ontime; // Return return; }
/***********************************************************************//** * @brief Set log mean energies and energy widths of event cube. * * @exception GLATException::no_ebds * No energy boundaries found in event cube. * * This method computes the log mean energies and the energy widths of the * event cube. The log mean energies and energy widths are stored unit * independent in arrays of GEnergy objects. ***************************************************************************/ void GLATEventCube::set_energies(void) { // Throw an error if we have no energy bins if (ebins() < 1) { throw GLATException::no_ebds(G_SET_ENERGIES, "Every LAT event cube" " needs a definition of the energy boundaries."); } // Clear old bin energies and energy widths m_energies.clear(); m_ewidth.clear(); m_enodes.clear(); // Reserve space for bin energies and energy widths m_energies.reserve(ebins()); m_ewidth.reserve(ebins()); // Setup bin energies, energy widths and energy nodes for (int i = 0; i < ebins(); ++i) { m_energies.push_back(ebounds().elogmean(i)); m_ewidth.push_back(ebounds().emax(i) - ebounds().emin(i)); m_enodes.append(log10(ebounds().emin(i).MeV())); } m_enodes.append(log10(ebounds().emax(ebins()-1).MeV())); // Return return; }
/***********************************************************************//** * @brief Return energy of cube layer * * @param[in] index Event cube layer index [0,...,ebins()-1] * @return Energy of event cube layer * * @exception GException::out_of_range * Layer index is out of range. * * Returns the energy of the event cube layer specified by @p index. ***************************************************************************/ const GEnergy& GCTAEventCube::energy(const int& index) const { // Optionally check if the index is valid #if defined(G_RANGE_CHECK) if (index < 0 || index >= ebins()) { throw GException::out_of_range(G_ENERGY, "CTA event cube energy axis", index, ebins()); } #endif // Return energy return (m_energies[index]); }
/***********************************************************************//** * @brief Print event cube information ***************************************************************************/ std::string GCTAEventCube::print(void) const { // Initialise result string std::string result; // Append header result.append("=== GCTAEventCube ==="); result.append("\n"+parformat("Number of events")+str(number())); result.append("\n"+parformat("Number of elements")+str(size())); result.append("\n"+parformat("Number of pixels")+str(npix())); result.append("\n"+parformat("Number of energy bins")+str(ebins())); // Append skymap definition result.append("\n"+m_map.print()); // Append GTI intervals result.append("\n"+parformat("Time interval")); if (gti().size() > 0) { result.append(str(tstart().secs())+" - "+str(tstop().secs())+" sec"); } else { result.append("not defined"); } // Append energy intervals if (ebounds().size() > 0) { result.append("\n"+ebounds().print()); } else { result.append("\n"+parformat("Energy intervals")+"not defined"); } // Return result return result; }
/***********************************************************************//** * @brief Print event cube information * * @param[in] chatter Chattiness. * @return String containing event cube information. ***************************************************************************/ std::string GCTAEventCube::print(const GChatter& chatter) const { // Initialise result string std::string result; // Continue only if chatter is not silent if (chatter != SILENT) { // Append header result.append("=== GCTAEventCube ==="); result.append("\n"+gammalib::parformat("Number of events") + gammalib::str(number())); result.append("\n"+gammalib::parformat("Number of elements") + gammalib::str(size())); result.append("\n"+gammalib::parformat("Number of pixels") + gammalib::str(npix())); result.append("\n"+gammalib::parformat("Number of energy bins") + gammalib::str(ebins())); // Append GTI intervals result.append("\n"+gammalib::parformat("Time interval")); if (gti().size() > 0) { result.append(gammalib::str(tstart().secs()) + " - " + gammalib::str(tstop().secs())+" sec"); } else { result.append("not defined"); } // Append energy intervals if (gammalib::reduce(chatter) > SILENT) { if (ebounds().size() > 0) { result.append("\n"+ebounds().print(gammalib::reduce(chatter))); } else { result.append("\n"+gammalib::parformat("Energy intervals") + "not defined"); } } // Append skymap definition if (gammalib::reduce(chatter) > SILENT) { result.append("\n"+m_map.print(gammalib::reduce(chatter))); } } // endif: chatter was not silent // Return result return result; }
/***********************************************************************//** * @brief Set event bin * * @param[in] index Event index [0,...,size()-1]. * * @exception GException::out_of_range * Event index is outside valid range. * @exception GLATException::no_energies * Energy vectors have not been set up. * @exception GLATException::no_dirs * Sky directions and solid angles vectors have not been set up. * * This method provides the event attributes to the event bin. The event bin * is in fact physically stored in the event cube, and only a single event * bin is indeed allocated. This method sets up the pointers in the event * bin so that a client can easily access the information of individual bins * as if they were stored in an array. ***************************************************************************/ void GLATEventCube::set_bin(const int& index) { // Optionally check if the index is valid #if defined(G_RANGE_CHECK) if (index < 0 || index >= size()) { throw GException::out_of_range(G_SET_BIN, index, 0, size()-1); } #endif // Check for the existence of energies and energy widths if (m_energies.size() != ebins() || m_ewidth.size() != ebins()) { throw GLATException::no_energies(G_SET_BIN); } // Check for the existence of sky directions and solid angles if (m_dirs.size() != npix() || m_solidangle.size() != npix()) { throw GLATException::no_dirs(G_SET_BIN); } // Get pixel and energy bin indices. m_bin.m_index = index; m_bin.m_ipix = index % npix(); m_bin.m_ieng = index / npix(); // Set pointers m_bin.m_cube = this; m_bin.m_counts = const_cast<double*>(&(m_map.pixels()[index])); m_bin.m_energy = &(m_energies[m_bin.m_ieng]); m_bin.m_time = &m_time; m_bin.m_dir = &(m_dirs[m_bin.m_ipix]); m_bin.m_solidangle = &(m_solidangle[m_bin.m_ipix]); m_bin.m_ewidth = &(m_ewidth[m_bin.m_ieng]); m_bin.m_ontime = &m_ontime; // Return return; }
/***********************************************************************//** * @brief Print event cube information * * @param[in] chatter Chattiness (defaults to NORMAL). * @return String containing event cube information. ***************************************************************************/ std::string GLATEventCube::print(const GChatter& chatter) const { // Initialise result string std::string result; // Continue only if chatter is not silent if (chatter != SILENT) { // Append header result.append("=== GLATEventCube ==="); // Append information result.append("\n"+gammalib::parformat("Number of elements") + gammalib::str(size())); result.append("\n"+gammalib::parformat("Number of pixels")); result.append(gammalib::str(m_map.nx()) + " x " + gammalib::str(m_map.ny())); result.append("\n"+gammalib::parformat("Number of energy bins") + gammalib::str(ebins())); result.append("\n"+gammalib::parformat("Number of events") + gammalib::str(number())); // Append time interval result.append("\n"+gammalib::parformat("Time interval")); if (gti().size() > 0) { result.append(gammalib::str(tstart().secs()) + " - " + gammalib::str(tstop().secs())+" sec"); } else { result.append("not defined"); } // Append energy range result.append("\n"+gammalib::parformat("Energy range")); if (ebounds().size() > 0) { result.append(emin().print()+" - "+emax().print(chatter)); } else { result.append("not defined"); } // Append detailed information GChatter reduced_chatter = gammalib::reduce(chatter); if (reduced_chatter > SILENT) { // Append sky projection if (m_map.projection() != NULL) { result.append("\n"+m_map.projection()->print(reduced_chatter)); } // Append source maps result.append("\n"+gammalib::parformat("Number of source maps")); result.append(gammalib::str(m_srcmap.size())); for (int i = 0; i < m_srcmap.size(); ++i) { result.append("\n"+gammalib::parformat(" "+m_srcmap_names[i])); result.append(gammalib::str(m_srcmap[i]->nx())); result.append(" x "); result.append(gammalib::str(m_srcmap[i]->ny())); result.append(" x "); result.append(gammalib::str(m_srcmap[i]->nmaps())); } } } // endif: chatter was not silent // Return result return result; }