CMS 3D CMS Logo

Public Member Functions | Public Attributes

TH1Keys Class Reference

#include <TH1Keys.h>

List of all members.

Public Member Functions

virtual void Add (const TH1 *h1, Double_t c1=1)
virtual void Add (const TH1 *h, const TH1 *h2, Double_t c1=1, Double_t c2=1)
virtual void AddBinContent (Int_t bin)
virtual void AddBinContent (Int_t bin, Double_t w)
virtual void Copy (TObject &hnew) const
void dont (const char *) const
virtual TH1 * DrawCopy (Option_t *option="") const
virtual Int_t Fill (Double_t x, Double_t w)
virtual Int_t Fill (Double_t x)
void FillH1 () const
virtual void FillN (Int_t ntimes, const Double_t *x, const Double_t *w, Int_t stride=1)
virtual Double_t GetBinContent (Int_t bin) const
virtual Double_t GetBinContent (Int_t bin, Int_t) const
virtual Double_t GetBinContent (Int_t bin, Int_t, Int_t) const
virtual Double_t GetEntries () const
const TH1 * GetHisto () const
TH1 * GetHisto ()
virtual void Reset (Option_t *option="")
virtual void Scale (Double_t c1=1, Option_t *option="")
virtual void SetBinContent (Int_t bin, Int_t, Double_t content)
virtual void SetBinContent (Int_t bin, Int_t, Int_t, Double_t content)
virtual void SetBinContent (Int_t bin, Double_t content)
virtual void SetBinsLength (Int_t n=-1)
 TH1Keys (const char *name, const char *title, Int_t nbinsx, Double_t xlow, Double_t xup, TString options="a", Double_t rho=1.5)
 TH1Keys ()
 TH1Keys (const char *name, const char *title, Int_t nbinsx, const Float_t *xbins, TString options="a", Double_t rho=1.5)
 TH1Keys (const char *name, const char *title, Int_t nbinsx, const Double_t *xbins, TString options="a", Double_t rho=1.5)
 TH1Keys (const TH1Keys &other)
virtual ~TH1Keys ()

Public Attributes

TH1 * cache_
RooDataSet * dataset_
Double_t globalScale_
bool isCacheGood_
TString options_
Double_t overflow_
RooArgSet point_
Double_t rho_
Double_t underflow_
ClassDef(TH1Keys, 1) private
RooRealVar * 
w_
ClassDef(TH1Keys, 1) private
RooRealVar * 
x_

Detailed Description

Definition at line 10 of file TH1Keys.h.


Constructor & Destructor Documentation

TH1Keys::TH1Keys ( )

Definition at line 8 of file TH1Keys.cc.

                 :
    x_(0),
    dataset_(0),
    underflow_(0.0), overflow_(0.0),
    globalScale_(1.0),
    cache_(0),
    isCacheGood_(false)
{
}
TH1Keys::TH1Keys ( const char *  name,
const char *  title,
Int_t  nbinsx,
Double_t  xlow,
Double_t  xup,
TString  options = "a",
Double_t  rho = 1.5 
)

Definition at line 18 of file TH1Keys.cc.

References cache_, and x_.

                                                                                                                          :
    TH1(name,title,nbinsx,xlow,xup),
    min_(xlow), max_(xup),
    x_(new RooRealVar("x", "x", min_, max_)),
    w_(new RooRealVar("w", "w", 1.0)),
    point_(*x_),
    dataset_(new RooDataSet(name, title, RooArgSet(*x_, *w_), "w")),
    underflow_(0.0), overflow_(0.0),
    globalScale_(1.0),
    options_(options),
    rho_(rho),
    cache_(new TH1F("",title,nbinsx,xlow,xup)),
    isCacheGood_(true)
{
    cache_->SetDirectory(0);
    fDimension = 1;
    x_->setBins(nbinsx);
}
TH1Keys::TH1Keys ( const char *  name,
const char *  title,
Int_t  nbinsx,
const Float_t *  xbins,
TString  options = "a",
Double_t  rho = 1.5 
)

Definition at line 37 of file TH1Keys.cc.

References cache_, i, and x_.

                                                                                                                     :
    TH1(name,title,nbinsx,xbins),
    min_(xbins[0]), max_(xbins[nbinsx]),
    x_(new RooRealVar("x", "x", min_, max_)),
    w_(new RooRealVar("w", "w", 1.0)),
    point_(*x_),
    dataset_(new RooDataSet(name, title, RooArgSet(*x_, *w_), "w")),
    underflow_(0.0), overflow_(0.0),
    globalScale_(1.0),
    options_(options),
    rho_(rho),
    cache_(new TH1F("",title,nbinsx,xbins)),
    isCacheGood_(true)
{
    cache_->SetDirectory(0);
    fDimension = 1;
    std::vector<Double_t> boundaries(nbinsx+1);
    for (Int_t i = 0; i <= nbinsx; ++i) boundaries[i] = xbins[i];
    x_->setBinning(RooBinning(nbinsx, &boundaries[0]));
}
TH1Keys::TH1Keys ( const char *  name,
const char *  title,
Int_t  nbinsx,
const Double_t *  xbins,
TString  options = "a",
Double_t  rho = 1.5 
)

Definition at line 58 of file TH1Keys.cc.

References cache_, and x_.

                                                                                                                     :
    TH1(name,title,nbinsx,xbins),
    min_(xbins[0]), max_(xbins[nbinsx]),
    x_(new RooRealVar("x", "x", min_, max_)),
    w_(new RooRealVar("w", "w", 1.0)),
    point_(*x_),
    dataset_(new RooDataSet(name, title, RooArgSet(*x_, *w_), "w")),
    underflow_(0.0), overflow_(0.0),
    globalScale_(1.0),
    options_(options),
    rho_(rho),
    cache_(new TH1F("",title,nbinsx,xbins)),
    isCacheGood_(true)
{
    cache_->SetDirectory(0);
    fDimension = 1;
    x_->setBinning(RooBinning(nbinsx, xbins));
}
TH1Keys::TH1Keys ( const TH1Keys other)

Definition at line 78 of file TH1Keys.cc.

References x_.

                                      :
    TH1(other),
    min_(other.min_), max_(other.max_),
    x_(new RooRealVar("x", "x", min_, max_)),
    w_(new RooRealVar("w", "w", 1.0)),
    point_(*x_),
    dataset_(new RooDataSet(other.GetName(), other.GetTitle(), RooArgSet(*x_, *w_), "w")),
    underflow_(other.underflow_), overflow_(other.overflow_),
    globalScale_(other.globalScale_),
    options_(other.options_),
    rho_(other.rho_),
    cache_((TH1*)other.cache_->Clone()),
    isCacheGood_(other.isCacheGood_)
{
    fDimension = 1;
    x_->setBinning(other.x_->getBinning());
}
TH1Keys::~TH1Keys ( ) [virtual]

Definition at line 97 of file TH1Keys.cc.

References cache_, dataset_, and x_.

{
    delete cache_;
    delete dataset_;
    delete x_;
}

Member Function Documentation

void TH1Keys::Add ( const TH1 *  h1,
Double_t  c1 = 1 
) [virtual]

Definition at line 125 of file TH1Keys.cc.

References dataset_, dont(), and isCacheGood_.

{
    if (c1 != 1.0) dont("Add with constant != 1");
    const TH1Keys *other = dynamic_cast<const TH1Keys *>(h1);
    if (other == 0) dont("Add with a non TH1Keys");
    dataset_->append(const_cast<RooDataSet&>(*other->dataset_));
    isCacheGood_ = false;
}
virtual void TH1Keys::Add ( const TH1 *  h,
const TH1 *  h2,
Double_t  c1 = 1,
Double_t  c2 = 1 
) [inline, virtual]

Definition at line 27 of file TH1Keys.h.

References dont().

{ dont("Add with two arguments"); } 
virtual void TH1Keys::AddBinContent ( Int_t  bin) [inline, virtual]

Definition at line 29 of file TH1Keys.h.

References AddBinContent().

Referenced by AddBinContent().

{ AddBinContent(bin, 1.0); }
virtual void TH1Keys::AddBinContent ( Int_t  bin,
Double_t  w 
) [inline, virtual]

Definition at line 30 of file TH1Keys.h.

References dont().

{ dont("AddBinContent"); }
virtual void TH1Keys::Copy ( TObject &  hnew) const [inline, virtual]

Definition at line 31 of file TH1Keys.h.

References dont().

{ dont("Copy"); }
void TH1Keys::dont ( const char *  msg) const

Definition at line 169 of file TH1Keys.cc.

Referenced by Add(), AddBinContent(), Copy(), DrawCopy(), SetBinContent(), and SetBinsLength().

                                        {
    TObject::Error("TH1Keys",msg);
    throw std::runtime_error(std::string("Error in TH1Keys: ")+msg);
}
virtual TH1* TH1Keys::DrawCopy ( Option_t *  option = "") const [inline, virtual]

Definition at line 33 of file TH1Keys.h.

References dont().

{ dont("DrawCopy"); return 0; }
Int_t TH1Keys::Fill ( Double_t  x,
Double_t  w 
) [virtual]

Definition at line 104 of file TH1Keys.cc.

References dataset_, isCacheGood_, overflow_, point_, underflow_, w(), and x_.

{
    isCacheGood_ = false;
    if (x >= max_) overflow_ += w;
    else if (x < min_) underflow_ += w;
    else {
        x_->setVal(x);
        dataset_->add(point_, w);
        return 1;
    } 
    return -1;
}
virtual Int_t TH1Keys::Fill ( Double_t  x) [inline, virtual]

Definition at line 22 of file TH1Keys.h.

References Fill().

Referenced by Fill(), and FillN().

{ return Fill(x,1.0); }
void TH1Keys::FillH1 ( ) const

Definition at line 150 of file TH1Keys.cc.

References cache_, dataset_, globalScale_, instance, isCacheGood_, options_, overflow_, rho_, underflow_, and x_.

Referenced by GetHisto().

{
    if (dataset_->numEntries() == 0) {
        cache_->Reset(); // make sure it's empty
    } else {
        RooFit::MsgLevel gKill = RooMsgService::instance().globalKillBelow();
        RooMsgService::instance().setGlobalKillBelow(RooFit::FATAL);
        delete cache_;
        RooNDKeysPdf pdf("","",*x_,*dataset_,options_,rho_);
        cache_ = pdf.createHistogram(GetName(), *x_);
        if (cache_->Integral()) cache_->Scale(1.0/cache_->Integral());
        cache_->SetBinContent(0,                     underflow_);
        cache_->SetBinContent(cache_->GetNbinsX()+1, overflow_);
        cache_->Scale(dataset_->sumEntries() * globalScale_);
        RooMsgService::instance().setGlobalKillBelow(gKill);
    }
    isCacheGood_ = true;
}
void TH1Keys::FillN ( Int_t  ntimes,
const Double_t *  x,
const Double_t *  w,
Int_t  stride = 1 
) [virtual]

Definition at line 117 of file TH1Keys.cc.

References Fill(), i, and isCacheGood_.

{
    isCacheGood_ = false;
    for (Int_t i = 0; i < ntimes; i += stride) {
        Fill(x[i], w[i]);
    }
}
virtual Double_t TH1Keys::GetBinContent ( Int_t  bin) const [inline, virtual]

Definition at line 35 of file TH1Keys.h.

References GetHisto().

{ return GetHisto()->GetBinContent(bin); }
virtual Double_t TH1Keys::GetBinContent ( Int_t  bin,
Int_t   
) const [inline, virtual]

Definition at line 36 of file TH1Keys.h.

References GetHisto().

{ return GetHisto()->GetBinContent(bin); }
virtual Double_t TH1Keys::GetBinContent ( Int_t  bin,
Int_t  ,
Int_t   
) const [inline, virtual]

Definition at line 37 of file TH1Keys.h.

References GetHisto().

{return GetHisto()->GetBinContent(bin); }
virtual Double_t TH1Keys::GetEntries ( ) const [inline, virtual]

Definition at line 39 of file TH1Keys.h.

References dataset_.

{ return dataset_->numEntries(); }
const TH1* TH1Keys::GetHisto ( ) const [inline]

Definition at line 20 of file TH1Keys.h.

References cache_, FillH1(), and isCacheGood_.

{ if (!isCacheGood_) FillH1(); return cache_; }
TH1* TH1Keys::GetHisto ( ) [inline]

Definition at line 19 of file TH1Keys.h.

References cache_, FillH1(), and isCacheGood_.

Referenced by GetBinContent().

{ if (!isCacheGood_) FillH1(); return cache_; }
void TH1Keys::Reset ( Option_t *  option = "") [virtual]

Definition at line 140 of file TH1Keys.cc.

References cache_, dataset_, globalScale_, isCacheGood_, overflow_, and underflow_.

                                    {
    dataset_->reset();
    overflow_ = underflow_ = 0.0;
    globalScale_ = 1.0;
    cache_->Reset();
    isCacheGood_ = true;
}
void TH1Keys::Scale ( Double_t  c1 = 1,
Option_t *  option = "" 
) [virtual]

Definition at line 134 of file TH1Keys.cc.

References alignmentValidation::c1, cache_, and globalScale_.

{
    globalScale_ *= c1;
    if (cache_) cache_->Scale(c1);
}
virtual void TH1Keys::SetBinContent ( Int_t  bin,
Double_t  content 
) [inline, virtual]

Definition at line 42 of file TH1Keys.h.

References dont().

{ dont("SetBinContent"); }
virtual void TH1Keys::SetBinContent ( Int_t  bin,
Int_t  ,
Int_t  ,
Double_t  content 
) [inline, virtual]

Definition at line 44 of file TH1Keys.h.

References SetBinContent().

Referenced by SetBinContent().

virtual void TH1Keys::SetBinContent ( Int_t  bin,
Int_t  ,
Double_t  content 
) [inline, virtual]

Definition at line 43 of file TH1Keys.h.

References SetBinContent().

Referenced by SetBinContent().

virtual void TH1Keys::SetBinsLength ( Int_t  n = -1) [inline, virtual]

Definition at line 45 of file TH1Keys.h.

References dont().

{ dont("SetBinLength"); }

Member Data Documentation

TH1* TH1Keys::cache_ [mutable]

Definition at line 61 of file TH1Keys.h.

Referenced by FillH1(), GetHisto(), Reset(), Scale(), TH1Keys(), and ~TH1Keys().

RooDataSet* TH1Keys::dataset_

Definition at line 54 of file TH1Keys.h.

Referenced by Add(), Fill(), FillH1(), GetEntries(), Reset(), and ~TH1Keys().

Definition at line 56 of file TH1Keys.h.

Referenced by FillH1(), Reset(), and Scale().

bool TH1Keys::isCacheGood_ [mutable]

Definition at line 62 of file TH1Keys.h.

Referenced by Add(), Fill(), FillH1(), FillN(), GetHisto(), and Reset().

Definition at line 58 of file TH1Keys.h.

Referenced by FillH1().

Definition at line 55 of file TH1Keys.h.

Referenced by Fill(), FillH1(), and Reset().

RooArgSet TH1Keys::point_

Definition at line 53 of file TH1Keys.h.

Referenced by Fill().

Double_t TH1Keys::rho_

Definition at line 59 of file TH1Keys.h.

Referenced by FillH1().

Definition at line 55 of file TH1Keys.h.

Referenced by Fill(), FillH1(), and Reset().

ClassDef (TH1Keys,1) private RooRealVar * TH1Keys::w_

Definition at line 48 of file TH1Keys.h.

ClassDef (TH1Keys,1) private RooRealVar* TH1Keys::x_

Definition at line 48 of file TH1Keys.h.

Referenced by Fill(), FillH1(), TH1Keys(), and ~TH1Keys().