Ignore:
Timestamp:
05/10/03 18:27:17 (22 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mhist
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mhist/MH.cc

    r2098 r2109  
    819819    return kFALSE;
    820820}
     821
     822void MH::ProjectionX(TH1D &dest, const TH2 &src, Int_t firstybin, Int_t lastybin)
     823{
     824    //*-*-*-*-*Project a 2-D histogram into a 1-D histogram along X*-*-*-*-*-*-*
     825    //*-*      ====================================================
     826    //
     827    //   The projection dest is always of the type TH1D.
     828    //   The projection is made from the channels along the Y axis
     829    //   ranging from firstybin to lastybin included.
     830    //   By default, bins 1 to ny are included
     831    //   When all bins are included, the number of entries in the projection
     832    //   is set to the number of entries of the 2-D histogram, otherwise
     833    //   the number of entries is incremented by 1 for all non empty cells.
     834    //
     835    //   if Sumw2() was called for dest, the errors are computed.
     836    //
     837    TAxis &axex = *((TH2&)src).GetXaxis();
     838    TAxis &axey = *((TH2&)src).GetYaxis();
     839
     840    const Int_t nx = axex.GetNbins();
     841    const Int_t ny = axey.GetNbins();
     842    if (firstybin < 0)
     843        firstybin = 1;
     844    if (lastybin > ny)
     845        lastybin = ny;
     846
     847    dest.Reset();
     848    SetBinning(&dest, &axex);
     849
     850    // Create the projection histogram
     851    const Bool_t computeErrors = dest.GetSumw2N() ? 1 : 0;
     852
     853    // Fill the projected histogram
     854    for (Int_t binx=0; binx<=nx+1; binx++)
     855    {
     856        Double_t err2 = 0;
     857        for (Int_t biny=firstybin; biny<=lastybin; biny++)
     858        {
     859            const Double_t cont = src.GetCellContent(binx,biny);
     860            const Double_t err1 = src.GetCellError(binx,biny);
     861            err2 += err1*err1;
     862            if (cont)
     863                dest.Fill(axex.GetBinCenter(binx), cont);
     864        }
     865        if (computeErrors)
     866            dest.SetBinError(binx, TMath::Sqrt(err2));
     867    }
     868    if (firstybin <=1 && lastybin >= ny)
     869        dest.SetEntries(src.GetEntries());
     870}
     871
     872void MH::ProjectionY(TH1D &dest, const TH2 &src, Int_t firstxbin, Int_t lastxbin)
     873{
     874    //*-*-*-*-*Project a 2-D histogram into a 1-D histogram along X*-*-*-*-*-*-*
     875    //*-*      ====================================================
     876    //
     877    //   The projection dest is always of the type TH1D.
     878    //   The projection is made from the channels along the Y axis
     879    //   ranging from firstybin to lastybin included.
     880    //   By default, bins 1 to ny are included
     881    //   When all bins are included, the number of entries in the projection
     882    //   is set to the number of entries of the 2-D histogram, otherwise
     883    //   the number of entries is incremented by 1 for all non empty cells.
     884    //
     885    //   if Sumw2() was called for dest, the errors are computed.
     886    //
     887    TAxis &axex = *((TH2&)src).GetXaxis();
     888    TAxis &axey = *((TH2&)src).GetYaxis();
     889
     890    const Int_t nx = axex.GetNbins();
     891    const Int_t ny = axey.GetNbins();
     892    if (firstxbin < 0)
     893        firstxbin = 1;
     894    if (lastxbin > nx)
     895        lastxbin = nx;
     896
     897    dest.Reset();
     898    SetBinning(&dest, &axey);
     899
     900    // Create the projection histogram
     901    const Bool_t computeErrors = dest.GetSumw2N() ? 1 : 0;
     902
     903    // Fill the projected histogram
     904    for (Int_t biny=0; biny<=ny+1; biny++)
     905    {
     906        Double_t err2 = 0;
     907        for (Int_t binx=firstxbin; binx<=lastxbin; binx++)
     908        {
     909            const Double_t cont = src.GetCellContent(binx,biny);
     910            const Double_t err1 = src.GetCellError(binx,biny);
     911            err2 += err1*err1;
     912            if (cont)
     913                dest.Fill(axey.GetBinCenter(biny), cont);
     914        }
     915        if (computeErrors)
     916            dest.SetBinError(biny, TMath::Sqrt(err2));
     917    }
     918    if (firstxbin <=1 && lastxbin >= nx)
     919        dest.SetEntries(src.GetEntries());
     920}
     921
     922// --------------------------------------------------------------------------
     923//
     924// In contradiction to TPad::FindObject this function searches recursively
     925// in a pad for an object. gPad is the default.
     926//
     927TObject *MH::FindObjectInPad(const char *name, TVirtualPad *pad)
     928{
     929    if (!pad)
     930        pad = gPad;
     931
     932    if (!pad)
     933        return NULL;
     934
     935    TObject *o;
     936
     937    TIter Next(pad->GetListOfPrimitives());
     938    while ((o=Next()))
     939    {
     940        if (!strcmp(o->GetName(), name))
     941            return o;
     942
     943        if (o->InheritsFrom("TPad"))
     944            if ((o = FindObjectInPad(name, (TVirtualPad*)o)))
     945                return o;
     946    }
     947    return NULL;
     948}
  • trunk/MagicSoft/Mars/mhist/MH.h

    r2098 r2109  
    77
    88class TH1;
     9class TH1D;
    910class TH2;
    1011class TH3;
     
    7576    static Double_t GetMinimumGT(const TH1 &h, Double_t gt=0);
    7677
     78    static void ProjectionX(TH1D &dest, const TH2 &src, Int_t firstybin=-1, Int_t lastybin=9999);
     79    static void ProjectionY(TH1D &dest, const TH2 &src, Int_t firstxbin=-1, Int_t lastxbin=9999);
     80
     81    static TObject *FindObjectInPad(const char *name, TVirtualPad *pad=NULL);
     82
    7783    ClassDef(MH, 0) //A base class for Mars histograms
    7884};
  • trunk/MagicSoft/Mars/mhist/MHSigmaTheta.cc

    r2106 r2109  
    223223// --------------------------------------------------------------------------
    224224//
     225// Update the projections and (if possible) set log scales before painting
     226//
     227void MHSigmaTheta::Paint(Option_t *opt)
     228{
     229    TVirtualPad *padsave = gPad;
     230
     231    TH1D* h;
     232
     233    padsave->cd(1);
     234    if ((h = (TH1D*)gPad->FindObject("ProjX-Theta")))
     235    {
     236        ProjectionX(*h, fSigmaTheta);
     237        if (h->GetEntries()!=0)
     238            gPad->SetLogy();
     239    }
     240
     241    padsave->cd(4);
     242    if ((h = (TH1D*)gPad->FindObject("ProjY-sigma")))
     243        ProjectionY(*h, fSigmaTheta);
     244
     245    gPad = padsave;
     246}
     247
     248// --------------------------------------------------------------------------
     249//
    225250// Draw the histogram
    226251//
     
    239264    pad->cd(1);
    240265    gPad->SetBorderMode(0);
    241     // gPad->SetLogy();
    242266    h = fSigmaTheta.ProjectionX("ProjX-Theta", -1, 9999, "E");
    243267    h->SetDirectory(NULL);
  • trunk/MagicSoft/Mars/mhist/MHSigmaTheta.h

    r2106 r2109  
    3737    TH3D fDiffPixTheta;  // 3D-distr.:Theta, pixel, sigma^2-sigmabar^2
    3838
     39    void Paint(Option_t *opt="");
    3940
    4041public:
Note: See TracChangeset for help on using the changeset viewer.