From b0375e86b171595a7aa7f38dab7b2ba9be18f65f Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Thu, 13 Apr 2017 17:05:08 +0200 Subject: [PATCH] Add GEventList::has_mc_id() and GEventAtom::mc_id() methods (#1483) --- ChangeLog | 3 ++- NEWS | 10 +++++++++- inst/cta/include/GCTAEventAtom.hpp | 30 +++++++++++++++++++++++++++++- inst/cta/include/GCTAEventList.hpp | 30 ++++++++++++++++++++++++++++++ inst/cta/pyext/GCTAEventAtom.i | 4 +++- inst/cta/pyext/GCTAEventList.i | 2 ++ inst/cta/src/GCTAEventList.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++---------- 7 files changed, 121 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index b674a32..5beabda 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,9 @@ -2017-04-11 +2017-04-13 * Version 1.3.0 released ========================= + Add GEventList::has_mc_id() and GEventAtom::mc_id() methods (#1483) Add GEventList::has_phase() and GEventList::has_detxy() methods (#1982) Add GEventList::append_column() method (#1991) Add scalar addition and subtraction operators to matrix classes (#1990) diff --git a/NEWS b/NEWS index 3947dac..426c089 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ New Features and Important Changes in GammaLib 1.3.0.dev1 -11 April 2017 +13 April 2017 1. Introduction @@ -52,6 +52,10 @@ The following methods have been added: - GCTAEventList::has_phase() - GCTAEventList::has_detxy(bool&) - GCTAEventList::has_detxy() +- GCTAEventList::has_mc_id(bool&) +- GCTAEventList::has_mc_id() +- GCTAEventAtom::mc_id(int&) +- GCTAEventAtom::mc_id() The following methods have been removed: - ... @@ -225,6 +229,10 @@ event list (#1991). Add GCTAEventList::has_phase() and GCTAEventList::has_detxy() getter and setter methods to manipulate the event list information flags (#1982). +Add GCTAEventList::has_mc_id() and GCTAEventAtom::mc_id() getter and setter methods +to set the Monte Carlo identifier of a given event. This allows to attribute a +Monte Carlo simulated event to a specific model (#1483). + 21. COMPTEL interface --------------------- diff --git a/inst/cta/include/GCTAEventAtom.hpp b/inst/cta/include/GCTAEventAtom.hpp index 1c17fb8..3a47603 100644 --- a/inst/cta/include/GCTAEventAtom.hpp +++ b/inst/cta/include/GCTAEventAtom.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAEventAtom.hpp - CTA event atom class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2015 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -72,8 +72,10 @@ public: // Other methods const int& index(void) const; const unsigned long& event_id(void) const; + const int& mc_id(void) const; const float& phase(void) const; void event_id(const unsigned long& id); + void mc_id(const int& id); void phase(const float& phase); protected: @@ -88,6 +90,7 @@ protected: GEnergy m_energy; //!< Event energy GTime m_time; //!< Event time unsigned long m_event_id; //!< Event identifier + int m_mc_id; //!< Monte Carlo identifier float m_phase; //!< Optional phase }; @@ -206,6 +209,18 @@ const unsigned long& GCTAEventAtom::event_id(void) const /***********************************************************************//** + * @brief Return Monte Carlo identifier + * + * @return Monte Carlo identifier. + ***************************************************************************/ +inline +const int& GCTAEventAtom::mc_id(void) const +{ + return (m_mc_id); +} + + +/***********************************************************************//** * @brief Return event phase * * @return Event phase. @@ -231,6 +246,19 @@ void GCTAEventAtom::event_id(const unsigned long& id) /***********************************************************************//** + * @brief Set Monte Carlo identifier + * + * @param[in] id Monte Carlo identifier. + ***************************************************************************/ +inline +void GCTAEventAtom::mc_id(const int& id) +{ + m_mc_id = id; + return; +} + + +/***********************************************************************//** * @brief Set event phase * * @param[in] phase Event phase. diff --git a/inst/cta/include/GCTAEventList.hpp b/inst/cta/include/GCTAEventList.hpp index 7b79daf..d2b20d4 100644 --- a/inst/cta/include/GCTAEventList.hpp +++ b/inst/cta/include/GCTAEventList.hpp @@ -99,8 +99,10 @@ public: const std::string& gtiname(void) const; void has_phase(const bool& has_phase); void has_detxy(const bool& has_detxy); + void has_mc_id(const bool& has_mc_id); const bool& has_phase() const; const bool& has_detxy() const; + const bool& has_mc_id() const; protected: // Protected methods @@ -122,6 +124,7 @@ protected: std::string m_gti_extname; //!< GTI extension name bool m_has_phase; //!< Signal presence of phase bool m_has_detxy; //!< Signal presence of detector coordinates + bool m_has_mc_id; //!< Signal presence of MC identifier // Event list data mutable std::vector m_events; //!< Events @@ -239,6 +242,21 @@ void GCTAEventList::has_detxy(const bool& has_detxy) } +/***********************************************************************//** + * @brief Set the Monte Carlo identifier flag + * + * @param[in] has_mc_id Monte Carlo identifier flag. + * + * Set the Monte Carlo identifier flag. + ***************************************************************************/ +inline +void GCTAEventList::has_mc_id(const bool& has_mc_id) +{ + m_has_mc_id = has_mc_id; + return; +} + + /************************************************************************* * @brief Return phase information flag * @@ -262,4 +280,16 @@ const bool& GCTAEventList::has_detxy() const return m_has_detxy; } + +/************************************************************************* + * @brief Return Monte Carlo identifier flag + * + * @return True if a Monte Carlo identifier is available, false otherwise. + ***************************************************************************/ +inline +const bool& GCTAEventList::has_mc_id() const +{ + return m_has_mc_id; +} + #endif /* GCTAEVENTLIST_HPP */ diff --git a/inst/cta/pyext/GCTAEventAtom.i b/inst/cta/pyext/GCTAEventAtom.i index 3e653fa..c37cdd0 100644 --- a/inst/cta/pyext/GCTAEventAtom.i +++ b/inst/cta/pyext/GCTAEventAtom.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAEventAtom.i - CTA event atom class * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2015 by Juergen Knoedlseder * + * copyright (C) 2011-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -55,8 +55,10 @@ public: // Other methods const int& index(void) const; const unsigned long& event_id(void) const; + const int& mc_id(void) const; const float& phase(void) const; void event_id(const unsigned long& id); + void mc_id(const int& id); void phase(const float& phase); }; diff --git a/inst/cta/pyext/GCTAEventList.i b/inst/cta/pyext/GCTAEventList.i index 89a1d8c..4f1f054 100644 --- a/inst/cta/pyext/GCTAEventList.i +++ b/inst/cta/pyext/GCTAEventList.i @@ -72,8 +72,10 @@ public: const std::string& gtiname(void) const; void has_phase(const bool& has_phase); void has_detxy(const bool& has_detxy); + void has_mc_id(const bool& has_mc_id); const bool& has_phase() const; const bool& has_detxy() const; + const bool& has_mc_id() const; }; diff --git a/inst/cta/src/GCTAEventList.cpp b/inst/cta/src/GCTAEventList.cpp index e03633c..2429998 100644 --- a/inst/cta/src/GCTAEventList.cpp +++ b/inst/cta/src/GCTAEventList.cpp @@ -38,6 +38,7 @@ #include "GFitsTableCol.hpp" #include "GFitsTableFloatCol.hpp" #include "GFitsTableDoubleCol.hpp" +#include "GFitsTableLongCol.hpp" #include "GFitsTableULongCol.hpp" #include "GTime.hpp" #include "GTimeReference.hpp" @@ -382,6 +383,14 @@ void GCTAEventList::read(const GFits& fits) m_has_phase = false; } + // Signal presence of "MC_ID" column + if (events.contains("MC_ID")) { + m_has_mc_id = true; + } + else { + m_has_mc_id = false; + } + // Read GTI extension name from data sub-space keyword std::string gti_extname = gammalib::read_ds_gti_extname(events); @@ -913,6 +922,7 @@ void GCTAEventList::init_members(void) m_gti_extname = gammalib::extname_gti; //!< Default GTI extension name m_has_phase = false; m_has_detxy = true; + m_has_mc_id = false; // Initialise cache m_irf_names.clear(); @@ -938,6 +948,7 @@ void GCTAEventList::copy_members(const GCTAEventList& list) m_gti_extname = list.m_gti_extname; m_has_phase = list.m_has_phase; m_has_detxy = list.m_has_detxy; + m_has_mc_id = list.m_has_mc_id; // Copy cache m_irf_names = list.m_irf_names; @@ -1022,6 +1033,9 @@ void GCTAEventList::read_events(const GFitsTable& table) const // Optionally get pointer to PHASE column const GFitsTableCol* ptr_phase = (m_has_phase) ? table["PHASE"] : NULL; + // Optionally get pointer to MC_ID column + const GFitsTableCol* ptr_mc_id = (m_has_mc_id) ? table["MC_ID"] : NULL; + // Copy data from columns into GCTAEventAtom objects for (int i = 0; i < num; ++i) { @@ -1046,6 +1060,11 @@ void GCTAEventList::read_events(const GFitsTable& table) const event.m_phase = ptr_phase->real(i); } + // If available, set Monte Carlo identifier + if (m_has_mc_id) { + event.m_mc_id = ptr_mc_id->integer(i); + } + // Append event m_events.push_back(event); @@ -1068,7 +1087,8 @@ void GCTAEventList::read_events(const GFitsTable& table) const name == "ENERGY" || name == "DETX" || name == "DETY" || - name == "PHASE") { + name == "PHASE" || + name == "MC_ID") { continue; } @@ -1122,11 +1142,11 @@ void GCTAEventList::write_events(GFitsBinTable& hdu) const if (size() > 0) { // Allocate mandatory columns - GFitsTableULongCol col_eid = GFitsTableULongCol("EVENT_ID", size()); - GFitsTableDoubleCol col_time = GFitsTableDoubleCol("TIME", size()); - GFitsTableFloatCol col_ra = GFitsTableFloatCol("RA", size()); - GFitsTableFloatCol col_dec = GFitsTableFloatCol("DEC", size()); - GFitsTableFloatCol col_energy = GFitsTableFloatCol("ENERGY", size()); + GFitsTableULongCol col_eid("EVENT_ID", size()); + GFitsTableDoubleCol col_time("TIME", size()); + GFitsTableFloatCol col_ra("RA", size()); + GFitsTableFloatCol col_dec("DEC", size()); + GFitsTableFloatCol col_energy("ENERGY", size()); // Set units of columns // (see http://fits.gsfc.nasa.gov/standard30/fits_standard30aa.pdf) @@ -1155,8 +1175,8 @@ void GCTAEventList::write_events(GFitsBinTable& hdu) const if (m_has_detxy) { // Allocate columns - GFitsTableFloatCol col_detx = GFitsTableFloatCol("DETX", size()); - GFitsTableFloatCol col_dety = GFitsTableFloatCol("DETY", size()); + GFitsTableFloatCol col_detx("DETX", size()); + GFitsTableFloatCol col_dety("DETY", size()); // Set units of columns // (see http://fits.gsfc.nasa.gov/standard30/fits_standard30aa.pdf) @@ -1179,18 +1199,34 @@ void GCTAEventList::write_events(GFitsBinTable& hdu) const if (m_has_phase) { // Allocate columns - GFitsTableFloatCol col_phase = GFitsTableFloatCol("PHASE", size()); + GFitsTableFloatCol col_phase("PHASE", size()); // Fill columns for (int i = 0; i < size(); ++i) { col_phase(i) = m_events[i].m_phase; } - // Append columns to table + // Append column to table hdu.append(col_phase); } + // If available, add Monte Carlo identifier + if (m_has_mc_id) { + + // Allocate columns + GFitsTableLongCol col_mc_id("MC_ID", size()); + + // Fill columns + for (int i = 0; i < size(); ++i) { + col_mc_id(i) = m_events[i].m_mc_id; + } + + // Append column to table + hdu.append(col_mc_id); + + } + // Append other columns to table for (int i = 0; i < m_columns.size(); ++i) { hdu.append(*m_columns[i]); -- libgit2 0.21.4