Commit cd8e36fc4f297ef9159a892f505ef3b8b10cc18e

Authored by Michael Mayer
1 parent 7a8e2181

added energy binning options 'FILE' and 'LIN'

src/ctbin/ctbin.cpp
@@ -432,9 +432,21 @@ void ctbin::get_parameters(void) @@ -432,9 +432,21 @@ void ctbin::get_parameters(void)
432 m_xref = (*this)["xref"].real(); 432 m_xref = (*this)["xref"].real();
433 m_yref = (*this)["yref"].real(); 433 m_yref = (*this)["yref"].real();
434 } 434 }
435 - m_emin = (*this)["emin"].real();  
436 - m_emax = (*this)["emax"].real();  
437 - m_enumbins = (*this)["enumbins"].integer(); 435 + m_ebinalg = (*this)["ebinalg"].string();
  436 +
  437 + // if we have the binning given by a file
  438 + // read in filename next
  439 + if (m_ebinalg=="FILE") {
  440 +
  441 + // get binning filename
  442 + m_ebinfile = (*this)["ebinfile"].filename();
  443 + }
  444 + // otherwise read emin, emax and nebins
  445 + else{
  446 + m_emin = (*this)["emin"].real();
  447 + m_emax = (*this)["emax"].real();
  448 + m_enumbins = (*this)["enumbins"].integer();
  449 + }
438 m_proj = (*this)["proj"].string(); 450 m_proj = (*this)["proj"].string();
439 m_coordsys = (*this)["coordsys"].string(); 451 m_coordsys = (*this)["coordsys"].string();
440 m_binsz = (*this)["binsz"].real(); 452 m_binsz = (*this)["binsz"].real();
@@ -483,10 +495,67 @@ void ctbin::bin_events(GCTAObservation* obs) @@ -483,10 +495,67 @@ void ctbin::bin_events(GCTAObservation* obs)
483 throw GException::no_list(G_BIN_EVENTS); 495 throw GException::no_list(G_BIN_EVENTS);
484 } 496 }
485 497
486 - // Setup energy range covered by data  
487 - GEnergy emin(m_emin, "TeV");  
488 - GEnergy emax(m_emax, "TeV");  
489 - GEbounds ebds(m_enumbins, emin, emax); 498 + // Initialise empty Ebounds object
  499 + GEbounds ebds;
  500 +
  501 + // First check wether we have FITS-file defining
  502 + // the binning
  503 + if (m_ebinalg=="FILE") {
  504 +
  505 + // open fits file to check which extension is given
  506 + GFits file(m_ebinfile);
  507 +
  508 + if (file.hashdu("EBOUNDS")) {
  509 +
  510 + // Close file and load ebounds
  511 + file.close();
  512 + ebds.load(m_ebinfile,"EBOUNDS");
  513 +
  514 + } // endif: EBOUNDS extension was given
  515 +
  516 + else if (file.hashdu("ENERGYBINS")) {
  517 +
  518 + // Close file and load ebounds
  519 + file.close();
  520 + ebds.load(m_ebinfile,"ENERGYBINS");
  521 +
  522 + } // endelse: ENERGYBINS extension was given
  523 +
  524 + else {
  525 +
  526 + file.close();
  527 + // throw an exception todo: get the right status
  528 + int status=0;
  529 + throw GException::fits_hdu_not_found(G_BIN_EVENTS, "\'EBOUNDS\' or \'ENERGYBINS\'", status);
  530 +
  531 + } // endelse: no suited extension
  532 +
  533 + // Set enumbins parameter to number of ebounds
  534 + m_enumbins = ebds.size();
  535 +
  536 + } //endif: ebinalg was "FILE"
  537 +
  538 + else {
  539 +
  540 + // Initialise log mode for ebinning
  541 + bool log = true;
  542 +
  543 + // check if algorithm is linear
  544 + if (m_ebinalg == "LIN") {
  545 + log = false;
  546 + }
  547 +
  548 + // todo: should we also check if m_ebinalg is "LOG"
  549 + // and throw an exception if neither LIN/LOG/FILE
  550 + // is given?
  551 +
  552 + // Setup energy range covered by data
  553 + GEnergy emin(m_emin, "TeV");
  554 + GEnergy emax(m_emax, "TeV");
  555 + GEbounds ebounds(m_enumbins, emin, emax,log);
  556 + ebds = ebounds;
  557 +
  558 + } //endif: ebinalg was not "FILE"
490 559
491 // Get Good Time intervals 560 // Get Good Time intervals
492 GGti gti = obs->events()->gti(); 561 GGti gti = obs->events()->gti();
@@ -605,6 +674,8 @@ void ctbin::init_members(void) @@ -605,6 +674,8 @@ void ctbin::init_members(void)
605 m_prefix.clear(); 674 m_prefix.clear();
606 m_proj.clear(); 675 m_proj.clear();
607 m_coordsys.clear(); 676 m_coordsys.clear();
  677 + m_ebinalg.clear();
  678 + m_ebinfile.clear();
608 m_usepnt = false; 679 m_usepnt = false;
609 m_emin = 0.0; 680 m_emin = 0.0;
610 m_emax = 0.0; 681 m_emax = 0.0;
@@ -642,6 +713,8 @@ void ctbin::copy_members(const ctbin& app) @@ -642,6 +713,8 @@ void ctbin::copy_members(const ctbin& app)
642 m_prefix = app.m_prefix; 713 m_prefix = app.m_prefix;
643 m_proj = app.m_proj; 714 m_proj = app.m_proj;
644 m_coordsys = app.m_coordsys; 715 m_coordsys = app.m_coordsys;
  716 + m_ebinalg = app.m_ebinalg;
  717 + m_ebinfile = app.m_ebinfile;
645 m_usepnt = app.m_usepnt; 718 m_usepnt = app.m_usepnt;
646 m_emin = app.m_emin; 719 m_emin = app.m_emin;
647 m_emax = app.m_emax; 720 m_emax = app.m_emax;
src/ctbin/ctbin.hpp
@@ -89,6 +89,8 @@ protected: @@ -89,6 +89,8 @@ protected:
89 int m_enumbins; //!< Number of energy bins 89 int m_enumbins; //!< Number of energy bins
90 std::string m_proj; //!< WCS projection 90 std::string m_proj; //!< WCS projection
91 std::string m_coordsys; //!< Coordinate system 91 std::string m_coordsys; //!< Coordinate system
  92 + std::string m_ebinalg; //!< Algorithm for energy binning
  93 + std::string m_ebinfile; //!< FITS-file containing energy binning
92 double m_xref; //!< Longitude reference coordinate 94 double m_xref; //!< Longitude reference coordinate
93 double m_yref; //!< Latitude reference coordinate 95 double m_yref; //!< Latitude reference coordinate
94 double m_binsz; //!< Pixel size 96 double m_binsz; //!< Pixel size
src/ctbin/ctbin.par
@@ -23,11 +23,11 @@ prefix, s, h, &quot;cntmap_&quot;,,,&quot;Prefix for counts maps in observation definition fil @@ -23,11 +23,11 @@ prefix, s, h, &quot;cntmap_&quot;,,,&quot;Prefix for counts maps in observation definition fil
23 # 23 #
24 # Energy binning parameters 24 # Energy binning parameters
25 #========================== 25 #==========================
26 -ebinalg, s, h, "LOG", FILE|LIN|LOG,,"Algorithm for defining energy bins" 26 +ebinalg, s, a, "LOG", FILE|LIN|LOG,,"Algorithm for defining energy bins"
27 emin, r, a, 0.1,,,"Start value for first energy bin in TeV" 27 emin, r, a, 0.1,,,"Start value for first energy bin in TeV"
28 emax, r, a, 100.0,,,"Stop value for last energy bin in TeV" 28 emax, r, a, 100.0,,,"Stop value for last energy bin in TeV"
29 enumbins, i, a, 20,,,"Number of energy bins" 29 enumbins, i, a, 20,,,"Number of energy bins"
30 -ebinfile, f, h, "NONE",,,"Name of the file containing the energy bin definition" 30 +ebinfile, f, a, "NONE",,,"Name of the file containing the energy bin definition"
31 # 31 #
32 # Spatial binning parameters 32 # Spatial binning parameters
33 #=========================== 33 #===========================