Changeset 8978


Ignore:
Timestamp:
06/18/08 21:39:50 (17 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r8977 r8978  
    2424     - small improvement to output
    2525     - handle underflow bin of effective on-time more accurate
     26     - reddid the formattig of the spectral fit
     27
     28   * mbase/MMath.[h,cc]:
     29     - added Format member function
    2630
    2731
  • trunk/MagicSoft/Mars/mbase/MMath.cc

    r8957 r8978  
    11/* ======================================================================== *\
    2 ! $Name: not supported by cvs2svn $:$Id: MMath.cc,v 1.38 2008-06-14 15:55:50 tbretz Exp $
     2! $Name: not supported by cvs2svn $:$Id: MMath.cc,v 1.39 2008-06-18 20:39:48 tbretz Exp $
    33! --------------------------------------------------------------------------
    44!
     
    811811    return 3;
    812812}
     813
     814// --------------------------------------------------------------------------
     815//
     816// Format a value and its error corresponding to the rules (note
     817// this won't work if the error is more then eight orders smaller than
     818// the value)
     819//
     820void MMath::Format(Double_t &v, Double_t &e)
     821{
     822    // Valid digits
     823    Int_t i = TMath::FloorNint(TMath::Log10(v))-TMath::FloorNint(TMath::Log10(e));
     824
     825    // Check if error starts with 1 or 2. In this case use one
     826    // more valid digit
     827    TString error = Form("%.0e", e);
     828    if (error[0]=='1' || error[0]=='2')
     829    {
     830        i++;
     831        error = Form("%.1e", e);
     832    }
     833
     834    const char *fmt = Form("%%.%de", i);
     835
     836    v = atof(Form(fmt, v));
     837    e = error.Atof();
     838}
  • trunk/MagicSoft/Mars/mbase/MMath.h

    r8585 r8978  
    11#ifndef MARS_MMath
    22#define MARS_MMath
     3
     4#ifndef _MATH_H
     5#include <math.h>  // Needed for darwin
     6#endif
    37
    48#ifndef ROOT_TMath
     
    6973    TArrayD LeastSqFitPowerLaw(Int_t n, Double_t *x, Double_t *y);
    7074
    71     inline Int_t ModF(Double_t dbl, Double_t &frac) { Double_t rc; frac = modf(dbl, &rc); return TMath::Nint(rc); }
     75    inline Int_t ModF(Double_t dbl, Double_t &frac) { Double_t rc; frac = ::modf(dbl, &rc); return TMath::Nint(rc); }
    7276
    73     inline Double_t Sqrt3(Double_t x) { return cbrt(x); }
     77    inline Double_t Sqrt3(Double_t x) { return ::cbrt(x); }
    7478
    7579    inline Double_t Sgn(Double_t d) { return d<0 ? -1 : 1; }
     80
     81    void Format(Double_t &v, Double_t &e);
    7682}
    7783
  • trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc

    r8977 r8978  
    4848#include "MLogManip.h"
    4949
     50#include "MMath.h"
    5051#include "MDirIter.h"
    5152
     
    292293
    293294    const Double_t ufl = vstime->GetBinContent(0);
     295    const Double_t ofl = vstime->GetBinContent(vstime->GetNbinsX()+1);
     296    const Double_t eff = vstime->Integral()+ufl+ofl;
    294297    if (ufl>0)
    295298    {
     
    301304        *fLog << warn << "WARNING - " << Form("%.1f%% (%.0fs)", 100*ufl/eff, ufl) << " of the eff. observation time is in the underflow bin." << endl;
    302305    }
    303 
    304     const Double_t ofl = vstime->GetBinContent(vstime->GetNbinsX()+1);
    305     const Double_t eff = vstime->Integral()+ufl+ofl;
    306306    if (ofl>0)
    307307        *fLog << warn << "WARNING - " << Form("%.1f%% (%.0fs)", 100*ofl/eff, ofl) << " of the eff. observation time is in the overflow bin." << endl;
     
    872872TString MJSpectrum::FormString(const TF1 &f, Byte_t type)
    873873{
    874     const Double_t p0 = f.GetParameter(0);
    875     const Double_t p1 = f.GetParameter(1);
    876 
    877     const Double_t e0 = f.GetParError(0);
    878     const Double_t e1 = f.GetParError(1);
    879 
    880     const Int_t    np  = TMath::Nint(TMath::Floor(TMath::Log10(p1)));
    881     const Double_t exp = TMath::Power(10, np);
    882 
    883     const Float_t fe0 = TMath::Log10(e0);
    884     const Float_t fe1 = TMath::Log10(e1);
    885 
    886     // calc number of (gueltige ziffern) digits to be displayed
    887     const char *f0  = fe0-TMath::Floor(fe0)>0.3 ? "3.1" : "1.0";
    888     const char *f1  = fe1-TMath::Floor(fe1)>0.3 ? "3.1" : "1.0";
     874    Double_t p0 = f.GetParameter(0);
     875    Double_t p1 = f.GetParameter(1);
     876
     877    Double_t e0 = f.GetParError(0);
     878    Double_t e1 = f.GetParError(1);
     879
     880    MMath::Format(p0, e0);
     881    MMath::Format(p1, e1);
    889882
    890883    TString str;
     
    893886    case 0:
    894887        {
    895             const TString fmt0 = Form("(%%%sf#pm%%%sf)\\bullet10^{%%d}",  f1, f1);
    896             const TString fmt1 = Form("(\\frac{E}{500GeV})^{%%%sf#pm%%%sf}", f0, f0);
    897 
    898             str  = Form(fmt0.Data(), p1/exp, e1/exp, np);
    899             str += Form(fmt1.Data(), p0, e0);
     888            const Int_t    i   = TMath::FloorNint(TMath::Log10(p1));
     889            const Double_t exp = TMath::Power(10, i);
     890
     891            str  = Form("(%f#pm%f)\\bullet10^{%d}",      p1/exp, e1/exp, i);
     892            str += Form("(\\frac{E}{500GeV})^{%f#pm%f}", p0, e0);
    900893            str += "\\frac{ph}{TeVm^{2}s}";
    901894        }
Note: See TracChangeset for help on using the changeset viewer.