Changeset 8281


Ignore:
Timestamp:
02/01/07 11:24:19 (18 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r8280 r8281  
    1818
    1919                                                 -*-*- END OF LINE -*-*-
     20
     21 2007/02/01 Thomas Bretz
     22
     23   * mhist/MHCamEvent.[h,cc]:
     24     - allow to set a histogram for display from external
     25
     26   * mhist/MHCamera.[h,cc]:
     27     - added functions to calc Median/Dev
     28     - fixed adding a MHCamera with AddCamContent. It now takes also
     29       the errors and binentries correctly into account
     30     - simplified Reset() using TArray::Reset()
     31
     32   * mhvstime/MHSectorVsTime.[h,cc]:
     33     - added option to use median/dev instead of mean/rms
     34     - switched Grid on
     35
     36
    2037
    2138 2007/01/30 Thomas Bretz
  • trunk/MagicSoft/Mars/mhist/MHCamEvent.cc

    r8279 r8281  
    214214}
    215215
     216void MHCamEvent::SetHist(const MHCamera &cam)
     217{
     218    if (fSum)
     219        delete fSum;
     220
     221    fSum = static_cast<MHCamera*>(cam.Clone());
     222}
     223
    216224void MHCamEvent::Paint(Option_t *)
    217225{
  • trunk/MagicSoft/Mars/mhist/MHCamEvent.h

    r8279 r8281  
    4444    void SetType(Int_t type) { fType = type; }
    4545
     46    void SetHist(const MHCamera &cam);
     47
    4648    TH1 *GetHistByName(const TString name="") const;
    4749
  • trunk/MagicSoft/Mars/mhist/MHCamera.cc

    r8280 r8281  
    11/* ======================================================================== *\
    2 ! $Name: not supported by cvs2svn $:$Id: MHCamera.cc,v 1.97 2007-01-30 14:20:47 tbretz Exp $
     2! $Name: not supported by cvs2svn $:$Id: MHCamera.cc,v 1.98 2007-02-01 11:24:18 tbretz Exp $
    33! --------------------------------------------------------------------------
    44!
     
    319319// ------------------------------------------------------------------------
    320320//
    321 // Return the median value on the y-axis (profile option is correctly taken
    322 // into account)
    323 //
    324 Stat_t MHCamera::GetMedian() const
    325 {
    326     // Just for speed reasons
    327     if (!TestBit(kProfile))
    328         return TMath::Median(GetSize()-2, GetArray()+1);
    329 
    330     // Copy profiled data into new array (FIXME: Should we take errors into account?)
    331     TArrayD arr(fNcells-2);
    332     for (int i=1; i<fNcells-1; i++)
    333         arr[i-1] = GetBinContent(i);
    334 
    335     // return Median of the profile data
    336     return TMath::Median(arr.GetSize(), arr.GetArray());
    337 }
    338 
    339 // ------------------------------------------------------------------------
    340 //
    341 // Return the median value (divided by MMath::GausProb(1.0)) of the
    342 // distribution of abs(y[i]-Median). This is my Median equivalent of the RMS
    343 //
    344 Stat_t MHCamera::GetMedianDev() const
    345 {
    346     // Just for speed reasons
    347     if (!TestBit(kProfile))
    348         return MMath::MedianDev(GetSize()-2, GetArray()+1);
    349 
    350     // Copy profiled data into new array (FIXME: Should we take errors into account?)
    351     TArrayD arr(fNcells-2);
    352     for (int i=1; i<fNcells-1; i++)
    353         arr[i-1] = GetBinContent(i);
    354 
    355     // return MedianDev of the profile data
    356     return MMath::MedianDev(arr.GetSize(), arr.GetArray());
    357 }
    358 
    359 // ------------------------------------------------------------------------
    360 //
    361321// Return the mean value of all entries which are used if all=kFALSE and
    362322// of all entries if all=kTRUE if sector<0. If sector>=0 only
     
    388348// ------------------------------------------------------------------------
    389349//
    390 // Return the sqrt variance of all entries which are used if all=kFALSE and
     350// Return the median value of all entries which are used if all=kFALSE and
    391351// of all entries if all=kTRUE if sector<0. If sector>=0 only
    392352// entries with match the given sector are taken into account.
    393353//
    394 Stat_t MHCamera::GetRmsSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t ball) const
     354Stat_t MHCamera::GetMedianSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t ball) const
    395355{
    396356    if (fNcells<=1)
    397         return -1;
    398 
     357        return 0;
     358
     359    TArrayD arr(fNcells-2);
    399360    Int_t n=0;
    400 
    401     Stat_t sum = 0;
    402     Stat_t sq  = 0;
     361 
    403362    for (int i=0; i<fNcells-2; i++)
    404363    {
     
    408367                continue;
    409368
     369            arr[n++] = TestBit(kProfile) ? fArray[i+1]/fBinEntries[i+1] : fArray[i+1];
     370        }
     371    }
     372
     373    // return Median of the profile data
     374    return TMath::Median(n, arr.GetArray());
     375}
     376
     377// ------------------------------------------------------------------------
     378//
     379// Return the sqrt variance of all entries which are used if all=kFALSE and
     380// of all entries if all=kTRUE if sector<0. If sector>=0 only
     381// entries with match the given sector are taken into account.
     382//
     383Stat_t MHCamera::GetRmsSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t ball) const
     384{
     385    if (fNcells<=1)
     386        return -1;
     387
     388    Int_t n=0;
     389
     390    Stat_t sum = 0;
     391    Stat_t sq  = 0;
     392    for (int i=0; i<fNcells-2; i++)
     393    {
     394        if ((ball || IsUsed(i)) && MatchSector(i, sector, aidx))
     395        {
     396            if (TestBit(kProfile) && fBinEntries[i+1]==0)
     397                continue;
     398
    410399            const Double_t val = TestBit(kProfile) ? fArray[i+1]/fBinEntries[i+1] : fArray[i+1];
    411400
     
    423412
    424413    return TMath::Sqrt(sq-sum*sum);
     414}
     415
     416// ------------------------------------------------------------------------
     417//
     418// Return the median value (divided by MMath::GausProb(1.0)=68.3%) of the
     419// distribution of abs(y[i]-Median). This is my Median equivalent of the RMS.
     420// Return the deviation of all entries which are used if all=kFALSE and
     421// of all entries if all=kTRUE if sector<0. If sector>=0 only
     422// entries with match the given sector are taken into account.
     423//
     424Stat_t MHCamera::GetDevSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t ball) const
     425{
     426    if (fNcells<=1)
     427        return 0;
     428
     429    TArrayD arr(fNcells-2);
     430    Int_t n=0;
     431 
     432    for (int i=0; i<fNcells-2; i++)
     433    {
     434        if ((ball || IsUsed(i)) && MatchSector(i, sector, aidx))
     435        {
     436            if (TestBit(kProfile) && fBinEntries[i+1]==0)
     437                continue;
     438
     439            arr[n++] = TestBit(kProfile) ? fArray[i+1]/fBinEntries[i+1] : fArray[i+1];
     440        }
     441    }
     442
     443    // return Median of the profile data
     444    return MMath::MedianDev(n, arr.GetArray());
    425445}
    426446
     
    13911411    {
    13921412    case 1:
     1413        // Under-/Overflow bins not handled!
    13931414        for (Int_t idx=0; idx<fNcells-2; idx++)
    1394             Fill(idx, d.GetBinError(idx+1));
     1415            if (d.IsUsed(idx))
     1416                Fill(idx, d.GetBinError(idx+1));
     1417        fEntries++;
    13951418        break;
    13961419    case 2:
     1420        // Under-/Overflow bins not handled!
    13971421        for (Int_t idx=0; idx<fNcells-2; idx++)
    1398             if (d.GetBinContent(idx+1)!=0)
     1422            if (d.GetBinContent(idx+1)!=0 && d.IsUsed(idx))
    13991423                Fill(idx, TMath::Abs(d.GetBinError(idx+1)/d.GetBinContent(idx+1)));
     1424        fEntries++;
    14001425        break;
    14011426    default:
     1427        if (TestBit(kProfile)!=d.TestBit(kProfile))
     1428            gLog << warn << "WARNING - You have tried to call AddCamContent for two different kind of histograms (kProfile set or not)." << endl;
     1429
     1430        // environment
     1431        fEntries += d.fEntries;
     1432        fTsumw   += d.fTsumw;
     1433        fTsumw2  += d.fTsumw2;
     1434        fTsumwx  += d.fTsumwx;
     1435        fTsumwx2 += d.fTsumwx2;
     1436        // Bin contents
     1437        for (Int_t idx=1; idx<fNcells-1; idx++)
     1438        {
     1439            if (!d.IsUsed(idx-1))
     1440                continue;
     1441
     1442            fArray[idx]          += d.fArray[idx];
     1443            fBinEntries[idx]     += d.fBinEntries[idx];
     1444            fSumw2.fArray[idx]   += d.fSumw2.fArray[idx];
     1445        }
     1446        // Underflow bin
     1447        fArray[0]                += d.fArray[0];
     1448        fBinEntries[0]           += d.fBinEntries[0];
     1449        fSumw2.fArray[0]         += d.fSumw2.fArray[0];
     1450        // Overflow bin
     1451        fArray[fNcells-1]        += d.fArray[fNcells-1];
     1452        fBinEntries[fNcells-1]   += d.fBinEntries[fNcells-1];
     1453        fSumw2.fArray[fNcells-1] += d.fSumw2.fArray[fNcells-1];
     1454        break;
     1455/*    default:
     1456        if (TestBit(kProfile)!=d.TestBit(kProfile))
     1457            gLog << warn << "WARNING - You have tried to call AddCamContent for two different kind of histograms (kProfile set or not)." << endl;
     1458
    14021459        for (Int_t idx=0; idx<fNcells-2; idx++)
    14031460            Fill(idx, d.GetBinContent(idx+1));
    1404         break;
     1461        break;*/
    14051462    }
    14061463    fEntries++;
     
    16291686    TH1::Reset(opt);
    16301687
    1631     for (Int_t i=0; i<fNcells-2; i++)
    1632     {
    1633         fArray[i+1]=0;
    1634         fBinEntries[i]=0;
    1635         ResetUsed(i);
    1636     }
    1637 
    1638     fArray[0]         = 0;
    1639     fArray[fNcells-1] = 0;
     1688    fUsed.Reset();
     1689    fBinEntries.Reset();
     1690
     1691    for (Int_t i=0; i<fNcells; i++)
     1692        fArray[i] = 0;
    16401693}
    16411694
  • trunk/MagicSoft/Mars/mhist/MHCamera.h

    r8280 r8281  
    11/* ======================================================================== *\
    2 !  $Name: not supported by cvs2svn $:$Id: MHCamera.h,v 1.61 2007-01-30 14:16:45 tbretz Exp $
     2!  $Name: not supported by cvs2svn $:$Id: MHCamera.h,v 1.62 2007-02-01 11:24:18 tbretz Exp $
    33\* ======================================================================== */
    44#ifndef MARS_MHCamera
     
    156156    virtual void     AddCamContent(const TArrayD &arr, const TArrayC *used=NULL);
    157157    virtual void     AddCamContent(const MArrayD &arr, const TArrayC *used=NULL);
    158     virtual void     SetCamContent(const MCamEvent &evt, Int_t type=0) { Reset(); AddCamContent(evt, type); }
    159     virtual void     SetCamContent(const MHCamera &d, Int_t type=0) { Reset(); AddCamContent(d, type); fEntries=d.fEntries; }
     158    virtual void     SetCamContent(const MCamEvent &evt, Int_t type=0)           { Reset(); AddCamContent(evt, type); }
     159    virtual void     SetCamContent(const MHCamera &cam, Int_t type=0)            { Reset(); AddCamContent(cam, type); }
    160160    virtual void     SetCamContent(const TArrayD &evt, const TArrayC *used=NULL) { Reset(); AddCamContent(evt, used); }
    161161    virtual void     SetCamContent(const MArrayD &evt, const TArrayC *used=NULL) { Reset(); AddCamContent(evt, used); }
     
    243243    void     AddNotify(TObject *event);
    244244
    245     Stat_t   GetMean(Bool_t ball) const { return GetMeanSectors(TArrayI(), TArrayI(), ball); }
    246     Stat_t   GetRMS(Bool_t ball)  const { return GetRmsSectors(TArrayI(), TArrayI(), ball); }
    247 
    248     Stat_t   GetMean(Int_t=0) const { return GetMeanSectors(TArrayI(), TArrayI(), kFALSE); }
    249     Stat_t   GetRMS(Int_t=0)  const { return GetRmsSectors(TArrayI(), TArrayI(), kFALSE); }
    250 
    251     Stat_t   GetMedian() const;
    252     Stat_t   GetMedianDev() const;
     245    Stat_t   GetMean(Bool_t ball) const   { return GetMeanSectors(TArrayI(), TArrayI(), ball); }
     246    Stat_t   GetMedian(Bool_t ball) const { return GetMedianSectors(TArrayI(), TArrayI(), ball); }
     247    Stat_t   GetRMS(Bool_t ball)  const   { return GetRmsSectors(TArrayI(), TArrayI(), ball); }
     248    Stat_t   GetDev(Bool_t ball)  const   { return GetDevSectors(TArrayI(), TArrayI(), ball); }
     249
     250    Stat_t   GetMean(Int_t=0) const   { return GetMeanSectors(TArrayI(), TArrayI(), kFALSE); }
     251    Stat_t   GetMedian(Int_t=0) const { return GetMedianSectors(TArrayI(), TArrayI(), kFALSE); }
     252    Stat_t   GetRMS(Int_t=0)  const   { return GetRmsSectors(TArrayI(), TArrayI(), kFALSE); }
     253    Stat_t   GetDev(Int_t=0)  const   { return GetRmsSectors(TArrayI(), TArrayI(), kFALSE); }
    253254
    254255    Stat_t   GetMeanSector(Int_t sector, Int_t aidx, Bool_t ball=kFALSE) const
     
    256257        return GetMeanSectors(TArrayI(1, &sector), TArrayI(1, &aidx), ball);
    257258    }
     259    Stat_t   GetMedianSector(Int_t sector, Int_t aidx, Bool_t ball=kFALSE) const
     260    {
     261        return GetMedianSectors(TArrayI(1, &sector), TArrayI(1, &aidx), ball);
     262    }
    258263    Stat_t   GetRmsSector(Int_t sector, Int_t aidx, Bool_t ball=kFALSE) const
    259264    {
    260265        return GetRmsSectors(TArrayI(1, &sector), TArrayI(1, &aidx), ball);
    261266    }
     267    Stat_t   GetDevSector(Int_t sector, Int_t aidx, Bool_t ball=kFALSE) const
     268    {
     269        return GetDevSectors(TArrayI(1, &sector), TArrayI(1, &aidx), ball);
     270    }
    262271
    263272    Stat_t   GetMeanSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t all=kFALSE) const;
     273    Stat_t   GetMedianSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t all=kFALSE) const;
    264274    Stat_t   GetRmsSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t all=kFALSE) const;
     275    Stat_t   GetDevSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t all=kFALSE) const;
    265276
    266277    UInt_t   GetNumPixels() const;
  • trunk/MagicSoft/Mars/mhvstime/MHSectorVsTime.cc

    r8022 r8281  
    11/* ======================================================================== *\
     2! $Name: not supported by cvs2svn $:$Id: MHSectorVsTime.cc,v 1.13 2007-02-01 11:24:19 tbretz Exp $
     3! --------------------------------------------------------------------------
    24!
    35! *
     
    1820!   Author(s): Thomas Bretz, 3/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
    1921!
    20 !   Copyright: MAGIC Software Development, 2000-2004
     22!   Copyright: MAGIC Software Development, 2000-2006
    2123!
    2224!
     
    7072//  + Double_t fMaximum;      // User defined maximum
    7173//
     74// Class Version 3:
     75// ----------------
     76//  + Bool_t fUseMedian;     
     77//
    7278//
    7379/////////////////////////////////////////////////////////////////////////////
     
    101107//
    102108MHSectorVsTime::MHSectorVsTime(const char *name, const char *title)
    103     : fGraph(0), fEvt(NULL), fMinimum(-1111), fMaximum(-1111),
     109    : fGraph(0), fEvt(NULL), fMinimum(-1111), fMaximum(-1111), fUseMedian(kFALSE),
    104110    fType(0), fTypeErr(-1)
    105111{
     
    226232    fHCamera.SetCamContent(*evt, fType);
    227233
    228     const Double_t val0 = fHCamera.GetMeanSectors(fSectors, fAreaIndex);
     234    const Double_t val0 = fUseMedian ?
     235        fHCamera.GetMedianSectors(fSectors, fAreaIndex) :
     236        fHCamera.GetMeanSectors(fSectors, fAreaIndex);
    229237
    230238    if (!TMath::Finite(val0))
     
    235243    if (fTypeErr>=0)
    236244    {
    237         const Double_t rms0 = fHCamera.GetRmsSectors(fSectors, fAreaIndex);
     245        const Double_t rms0 = fUseMedian ?
     246            fHCamera.GetDevSectors(fSectors, fAreaIndex) :
     247
     248            fHCamera.GetRmsSectors(fSectors, fAreaIndex);
    238249        if (!TMath::Finite(rms0))
    239250            return kTRUE;
     251
    240252        ((TGraphErrors*)fGraph)->SetPointError(fGraph->GetN()-1, 0, rms0);
    241253    }
     
    334346    TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(fGraph);
    335347    pad->SetBorderMode(0);
     348    pad->SetGridx();
     349    pad->SetGridy();
    336350    AppendPad(opt);
    337351}
  • trunk/MagicSoft/Mars/mhvstime/MHSectorVsTime.h

    r7358 r8281  
     1/* ======================================================================== *\
     2!  $Name: not supported by cvs2svn $:$Id: MHSectorVsTime.h,v 1.7 2007-02-01 11:24:19 tbretz Exp $
     3\* ======================================================================== */
    14#ifndef MARS_MHSectorVsTime
    25#define MARS_MHSectorVsTime
     
    2528
    2629private:
    27     TGraph *fGraph;
     30    TGraph *fGraph;         // The TGraph output to the display
    2831
    29     MCamEvent *fEvt;        //! the current event
    30     MGeomCam  *fCam;        //! the camera geometry
     32    MCamEvent *fEvt;        //! pointer to the current event
     33    MGeomCam  *fCam;        //! pointer the camera geometry
    3134
    32     MRawEvtHeader *fHeader; //!
    33     MTime         *fTime;   //!
     35    MRawEvtHeader *fHeader; //! pointer to the event header (DAQ Evt number instead of counter)
     36    MTime         *fTime;   //! pointer to event time (time instead of number)
    3437
    35     MHCamera fHCamera;      //!
     38    MHCamera fHCamera;      //! The camera to be used for calculation
    3639
    3740    Double_t fMin;          //! Calculation of minimum
     
    4144    Double_t fMaximum;      // User defined maximum
    4245
    43     TString fNameEvt;
    44     TString fNameTime;
     46    Bool_t fUseMedian;      // Whether to display median/dev instead of mean/rms
    4547
    46     Int_t fType;
    47     Int_t fTypeErr;
     48    TString fNameEvt;       // Name of MCamEvent to be displayed
     49    TString fNameTime;      // Name of MTime container to be used
    4850
    49     TArrayI fSectors;
    50     TArrayI fAreaIndex;
     51    Int_t fType;            // Type for mean  used in GetPixelContent
     52    Int_t fTypeErr;         // Type for error used in GetPixelContent (-1 = no error)
     53
     54    TArrayI fSectors;       // Which sectors shell be displayed
     55    TArrayI fAreaIndex;     // Which pixel sized should be displayed
    5156
    5257    // MH
     
    6974    void SetMaximum(Double_t max=-1111) { fMaximum = max; }
    7075
     76    void SetUseMedian(Bool_t b=kTRUE) { fUseMedian=b; }
     77
    7178    // Getter
    7279    TH1 *GetHistByName(const TString name="") const;
     
    8087    void Paint(Option_t *o=NULL);
    8188
    82     ClassDef(MHSectorVsTime, 2) // Histogram to sum camera events
     89    ClassDef(MHSectorVsTime, 3) // Histogram to sum camera events
    8390};
    8491
Note: See TracChangeset for help on using the changeset viewer.