Ignore:
Timestamp:
01/15/04 12:14:33 (21 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

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

    r2790 r2810  
    5252#include <TClonesArray.h>
    5353#include <THistPainter.h>
     54#include <THLimitsFinder.h>
    5455
    5556#include "MLog.h"
     
    447448}
    448449
     450// ------------------------------------------------------------------------
     451//
     452// Creates a TH1D which contains the projection of the contents of the
     453// MHCamera onto the y-axis. The maximum and minimum are calculated
     454// such that a slighly wider range than (GetMinimum(), GetMaximum()) is
     455// displayed using THLimitsFinder::OptimizeLimits.
     456//
     457// If no name is given the newly allocated histogram is removed from
     458// the current directory calling SetDirectory(0)
     459//
     460// If the standard name "_py" is given "_py" is appended to the name
     461// of the MHCamera and the corresponding histogram is searched using
     462// gROOT->FindObject and updated with the present projection.
     463//
     464// It is the responsibility of the user to make sure, that the newly
     465// created histogram is freed correctly.
     466//
     467// Currently the new histogram is restrictred to 50 bins.
     468// Maybe a optimal number can be calulated from the number of
     469// bins on the x-axis of the MHCamera?
     470//
     471// The code was taken mainly from TH2::ProjectX such the interface
     472// is more or less the same than to TH2-projections.
     473//
     474TH1D *MHCamera::Projection(const char *name) const
     475{
     476    // Create the projection histogram
     477    TString pname(name);
     478    if (name=="_py")
     479        pname.Prepend(GetName());
     480
     481    TH1D *h1=0;
     482
     483    //check if histogram with identical name exist
     484    TObject *h1obj = gROOT->FindObject(pname);
     485    if (h1obj && h1obj->InheritsFrom("TH1D")) {
     486        h1 = (TH1D*)h1obj;
     487        h1->Reset();
     488    }
     489
     490    if (!h1)
     491    {
     492        Double_t min = GetMinimum();
     493        Double_t max = GetMaximum();
     494
     495        Int_t newbins=0;
     496
     497        THLimitsFinder::OptimizeLimits(50, newbins, min, max, kFALSE);
     498
     499        h1 = new TH1D(pname, GetTitle(), 50, min, max);
     500
     501        h1->SetXTitle(GetYaxis()->GetTitle());
     502        h1->SetYTitle("Counts");
     503        h1->Sumw2();
     504        if (pname.IsNull())
     505            h1->SetDirectory(NULL);
     506    }
     507
     508    // Fill the projected histogram
     509    for (Int_t binx =0;binx<=GetNbinsX()+1;binx++) {
     510        const Double_t cont = GetBinContent(binx);
     511        if (cont!=0)
     512            h1->Fill(cont);
     513    }
     514
     515    h1->SetEntries(GetXaxis()->GetNbins());
     516
     517    return h1;
     518}
     519
     520// ------------------------------------------------------------------------
     521// Will be removed in the future
    449522void MHCamera::CreateProjection()
    450523{
    451  
    452   Int_t nbins = 50;
    453 
    454   // Create the projection histogram
    455   TString ytitle(GetYaxis()->GetTitle());
    456   fYProj = new TH1D(ytitle.Data(),GetTitle(),nbins,GetMinimum()-0.1,GetMaximum()+0.1);
    457   fYProj->SetXTitle(ytitle.Data());
    458   fYProj->SetYTitle("Nr. of pixels");
    459   fYProj->Sumw2();
    460   fYProj->SetDirectory(NULL);
    461 
    462   // Fill the projected histogram
    463   Double_t cont;
    464   for (Int_t binx =0;binx<=GetNbinsX()+1;binx++) {
    465     cont  = GetBinContent(binx);
    466     if (cont)
    467       fYProj->Fill(cont);
    468   }
    469 }
    470 
     524    Int_t nbins = 50;
     525
     526    // Create the projection histogram
     527    TString ytitle(GetYaxis()->GetTitle());
     528    fYProj = new TH1D(ytitle.Data(),GetTitle(),nbins,GetMinimum()-0.1,GetMaximum()+0.1);
     529    fYProj->SetXTitle(ytitle.Data());
     530    fYProj->SetYTitle("Nr. of pixels");
     531    fYProj->Sumw2();
     532    fYProj->SetDirectory(NULL);
     533
     534    // Fill the projected histogram
     535    Double_t cont;
     536    for (Int_t binx =0;binx<=GetNbinsX()+1;binx++) {
     537        cont  = GetBinContent(binx);
     538        if (cont)
     539            fYProj->Fill(cont);
     540    }
     541}
    471542
    472543// ------------------------------------------------------------------------
     
    618689    if (opt.Contains("proj"))
    619690    {
    620 
    621       CreateProjection();
    622       opt.ReplaceAll("proj", "");
    623       Float_t he = gStyle->GetStatH();
    624       Float_t wi = gStyle->GetStatH();
    625       gStyle->SetStatH(0.4);
    626       gStyle->SetStatW(0.25);
    627       fYProj->Paint(opt);
    628       gStyle->SetStatH(he);     
    629       gStyle->SetStatW(wi);     
    630       return;
     691        CreateProjection();
     692        opt.ReplaceAll("proj", "");
     693        Float_t he = gStyle->GetStatH();
     694        Float_t wi = gStyle->GetStatH();
     695        gStyle->SetStatH(0.4);
     696        gStyle->SetStatW(0.25);
     697        fYProj->Paint(opt);
     698        gStyle->SetStatH(he);
     699        gStyle->SetStatW(wi);
     700        return;
    631701    }
    632702   
Note: See TracChangeset for help on using the changeset viewer.