#include <stdlib.h>
#include "Riostream.h"
#include "TH1K.h"
#include "TMath.h"
ClassImp(TH1K)
TH1K::TH1K(): TH1(), TArrayF()
{
fDimension = 1;
fNIn = 0;
fReady = 0;
fKOrd = 3;
}
TH1K::TH1K(const char *name,const char *title,Int_t nbins,Double_t xlow,Double_t xup,Int_t k)
: TH1(name,title,nbins,xlow,xup), TArrayF(100)
{
fDimension = 1;
fNIn = 0;
fReady = 0;
fKOrd = k;
}
TH1K::~TH1K()
{
}
Int_t TH1K::Fill(Double_t x)
{
fReady = 0;
Int_t bin;
fEntries++;
bin =fXaxis.FindBin(x);
if (bin == 0 || bin > fXaxis.GetNbins()) {
if (!fgStatOverflows) return -1;
}
++fTsumw;
++fTsumw2;
fTsumwx += x;
fTsumwx2 += x*x;
fReady = 0;
if (fNIn == fN) Set(fN*2);
AddAt(x,fNIn++);
return bin;
}
Double_t TH1K::GetBinContent(Int_t bin) const
{
if (!fReady) {
((TH1K*)this)->Sort();
((TH1K*)this)->fReady=1;
}
if (!fNIn) return 0.;
float x = GetBinCenter(bin);
int left = TMath::BinarySearch(fNIn,fArray,x);
int jl=left,jr=left+1,nk,nkmax =fKOrd;
float fl,fr,ff=0.,ffmin=1.e-6;
if (!nkmax) {nkmax = 3; ffmin = GetBinWidth(bin);}
if (nkmax >= fNIn) nkmax = fNIn-1;
for (nk = 1; nk <= nkmax || ff <= ffmin; nk++) {
fl = (jl>=0 ) ? TMath::Abs(fArray[jl]-x) : 1.e+20;
fr = (jr<fNIn) ? TMath::Abs(fArray[jr]-x) : 1.e+20;
if (jl<0 && jr>=fNIn) break;
if (fl < fr) { ff = fl; jl--;}
else { ff = fr; jr++;}
}
((TH1K*)this)->fKCur = nk - 1;
return fNIn * 0.5*fKCur/((float)(fNIn+1))*GetBinWidth(bin)/ff;
}
Double_t TH1K::GetBinError(Int_t bin) const
{
return TMath::Sqrt(((double)(fNIn-fKCur+1))/((fNIn+1)*(fKCur-1)))*GetBinContent(bin);
}
void TH1K::Reset(Option_t *option)
{
fNIn =0;
fReady = 0;
TH1::Reset(option);
}
void TH1K::SavePrimitive(ostream &out, Option_t *option )
{
char quote = '"';
out<<" "<<endl;
out<<" "<<"TH1 *";
out<<GetName()<<" = new "<<ClassName()<<"("<<quote<<GetName()<<quote<<","<<quote<<GetTitle()<<quote
<<","<<GetXaxis()->GetNbins()
<<","<<GetXaxis()->GetXmin()
<<","<<GetXaxis()->GetXmax()
<<","<<fKOrd;
out <<");"<<endl;
if (fDirectory == 0) {
out<<" "<<GetName()<<"->SetDirectory(0);"<<endl;
}
if (TestBit(kNoStats)) {
out<<" "<<GetName()<<"->SetStats(0);"<<endl;
}
if (fOption.Length() != 0) {
out<<" "<<GetName()<<"->SetOption("<<quote<<fOption.Data()<<quote<<");"<<endl;
}
if (fNIn) {
out<<" Float_t Arr[]={"<<endl;
for (int i=0; i<fNIn; i++) {
out<< fArray[i];
if (i != fNIn-1) {out<< ",";} else { out<< "};";}
if (i%10 == 9) {out<< endl;}
}
out<< endl;
out<<" for(int i=0;i<" << fNIn << ";i++)"<<GetName()<<"->Fill(Arr[i]);";
out<< endl;
}
SaveFillAttributes(out,GetName(),0,1001);
SaveLineAttributes(out,GetName(),1,1,1);
SaveMarkerAttributes(out,GetName(),1,1,1);
fXaxis.SaveAttributes(out,GetName(),"->GetXaxis()");
fYaxis.SaveAttributes(out,GetName(),"->GetYaxis()");
fZaxis.SaveAttributes(out,GetName(),"->GetZaxis()");
TString opt = option;
opt.ToLower();
if (!opt.Contains("nodraw")) {
out<<" "<<GetName()<<"->Draw("
<<quote<<option<<quote<<");"<<endl;
}
}
static int TH1K_fcompare(const void *f1,const void *f2)
{
if (*((float*)f1) < *((float*)f2)) return -1;
if (*((float*)f1) > *((float*)f2)) return 1;
return 0;
}
void TH1K::Sort()
{
if (fNIn<2) return;
qsort(GetArray(),fNIn,sizeof(Float_t),&TH1K_fcompare);
}
Last change: Wed Jun 25 08:46:43 2008
Last generated: 2008-06-25 08:46
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.