Changeset 7867 for trunk


Ignore:
Timestamp:
08/08/06 17:51:35 (18 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r7865 r7867  
    2828   * msignal/MExtractedSignalCam.cc:
    2929     - some update to returning the hi-/lo-gain ratio
     30
     31   * mbase/MMath.[h,cc]:
     32     - new functions MedianDev
     33
     34   * mhist/MHCamera.[h,cc]:
     35     - new function GetMedian
     36     - new function GetMedianDev
    3037
    3138
  • trunk/MagicSoft/Mars/NEWS

    r7850 r7867  
    88   - general: Fixed some warnings thrown if more warnings are switched
    99     on in the compiler
     10
     11   - general: Added a function to MMath which returns the Median of
     12     the distribution abs(y[i]-median), which is somehow the median
     13     counterpart of the rms.
    1014
    1115   - showplot:
  • trunk/MagicSoft/Mars/mbase/MMath.cc

    r7672 r7867  
    161161}
    162162
     163// ------------------------------------------------------------------------
     164//
     165// Return the median value of the distribution of abs(a[i]-Median)
     166//
     167template <class Size, class Element>
     168Double_t MMath::MedianDevImp(Size n, const Element *a)
     169{
     170    // Get median of distribution
     171    const Double_t med = TMath::Median(n, a);
     172
     173    // Allocate space for distribution
     174    Double_t *arr = new Double_t[n];
     175
     176    // Create the abs(a[i]-med) distribution
     177    for (int i=0; i<n; i++)
     178        arr[i] = TMath::Abs(a[i]-med);
     179
     180    // FIXME: GausProb() is a workaround. It should be taken into account in Median!
     181    const Double_t rc = TMath::Median(n, arr);
     182
     183    // delete space
     184    delete arr;
     185
     186    // return result
     187    return rc;
     188}
     189
     190// ------------------------------------------------------------------------
     191//
     192// Return the median value of the distribution of abs(a[i]-Median)
     193//
     194Double_t MMath::MedianDev(Long64_t n, const Short_t *a)
     195{
     196    return MedianDevImp(n, a);
     197}
     198
     199// ------------------------------------------------------------------------
     200//
     201// Return the median value of the distribution of abs(a[i]-Median)
     202//
     203Double_t MMath::MedianDev(Long64_t n, const Int_t *a)
     204{
     205    return MedianDevImp(n, a);
     206}
     207
     208// ------------------------------------------------------------------------
     209//
     210// Return the median value of the distribution of abs(a[i]-Median)
     211//
     212Double_t MMath::MedianDev(Long64_t n, const Float_t *a)
     213{
     214    return MedianDevImp(n, a);
     215}
     216
     217// ------------------------------------------------------------------------
     218//
     219// Return the median value of the distribution of abs(a[i]-Median)
     220//
     221Double_t MMath::MedianDev(Long64_t n, const Double_t *a)
     222{
     223    return MedianDevImp(n, a);
     224}
     225
     226// ------------------------------------------------------------------------
     227//
     228// Return the median value of the distribution of abs(a[i]-Median)
     229//
     230Double_t MMath::MedianDev(Long64_t n, const Long_t *a)
     231{
     232    return MedianDevImp(n, a);
     233}
     234
     235// ------------------------------------------------------------------------
     236//
     237// Return the median value of the distribution of abs(a[i]-Median)
     238//
     239Double_t MMath::MedianDev(Long64_t n, const Long64_t *a)
     240{
     241    return MedianDevImp(n, a);
     242}
     243
    163244// --------------------------------------------------------------------------
    164245//
  • trunk/MagicSoft/Mars/mbase/MMath.h

    r7719 r7867  
    1818
    1919    Double_t GaussProb(Double_t x, Double_t sigma=1, Double_t mean=0);
     20
     21    template <class Size, class Element> Double_t MedianDevImp(Size n, const Element *a);
     22    Double_t  MedianDev(Long64_t n, const Short_t  *a);
     23    Double_t  MedianDev(Long64_t n, const Int_t    *a);
     24    Double_t  MedianDev(Long64_t n, const Float_t  *a);
     25    Double_t  MedianDev(Long64_t n, const Double_t *a);
     26    Double_t  MedianDev(Long64_t n, const Long_t   *a);
     27    Double_t  MedianDev(Long64_t n, const Long64_t *a);
    2028
    2129    Double_t Significance(Double_t s, Double_t b);
  • trunk/MagicSoft/Mars/mhist/MHCamera.cc

    r7829 r7867  
    8484
    8585#include "MArrayD.h"
     86#include "MMath.h"    // MMath::GaussProb
    8687
    8788#define kItemsLegend 48 // see SetPalette(1,0)
     
    312313    for (Int_t idx=0; idx<fNcells-2; idx++)
    313314        arr[idx] ? SetUsed(idx) : ResetUsed(idx);
     315}
     316
     317// ------------------------------------------------------------------------
     318//
     319// Return the median value on the y-axis (profile option is correctly taken
     320// into account)
     321//
     322Stat_t MHCamera::GetMedian() const
     323{
     324    // Just for speed reasons
     325    if (!TestBit(kProfile))
     326        return TMath::Median(GetSize()-2, GetArray()+1);
     327
     328    // Copy profiled data into new array (FIXME: Should we take errors into account?)
     329    TArrayD arr(fNcells-2);
     330    for (int i=1; i<fNcells-1; i++)
     331        arr[i-1] = GetBinContent(i);
     332
     333    // return Median of the profile data
     334    return TMath::Median(arr.GetSize(), arr.GetArray());
     335}
     336
     337// ------------------------------------------------------------------------
     338//
     339// Return the median value (divided by MMath::GausProb(1.0)) of the
     340// distribution of abs(y[i]-Median). This is my Median equivalent of the RMS
     341//
     342Stat_t MHCamera::GetMedianDev() const
     343{
     344    // Just for speed reasons
     345    if (!TestBit(kProfile))
     346        return MMath::MedianDev(GetSize()-2, GetArray()+1);
     347
     348    // Copy profiled data into new array (FIXME: Should we take errors into account?)
     349    TArrayD arr(fNcells-2);
     350    for (int i=1; i<fNcells-1; i++)
     351        arr[i-1] = GetBinContent(i);
     352
     353    // return MedianDev of the profile data
     354    return MMath::MedianDev(arr.GetSize(), arr.GetArray())/MMath::GaussProb(1.0);
    314355}
    315356
  • trunk/MagicSoft/Mars/mhist/MHCamera.h

    r7823 r7867  
    240240    Stat_t   GetMean(Int_t=0) const { return GetMeanSectors(TArrayI(), TArrayI(), kFALSE); }
    241241    Stat_t   GetRMS(Int_t=0)  const { return GetRmsSectors(TArrayI(), TArrayI(), kFALSE); }
     242
     243    Stat_t   GetMedian() const;
     244    Stat_t   GetMedianDev() const;
    242245
    243246    Stat_t   GetMeanSector(Int_t sector, Int_t aidx, Bool_t all=kFALSE) const
Note: See TracChangeset for help on using the changeset viewer.