Ignore:
Timestamp:
05/10/03 18:27:17 (22 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.