39 TH1K::TH1K(): TH1(), TArrayF()
53 TH1K::TH1K(
const char *name,
const char *title,Int_t nbins,Double_t xlow,Double_t xup,Int_t k)
54 : TH1(name,title,nbins,xlow,xup), TArrayF(100)
77 void TH1K::Copy(TObject &obj)
const
80 ((TH1K&)obj).fNIn = fNIn;
93 Int_t TH1K::Fill(Double_t x)
98 bin =fXaxis.FindBin(x);
99 if (bin == 0 || bin > fXaxis.GetNbins()) {
100 if (!GetStatOverflowsBehaviour())
return -1;
107 if (fNIn == fN) Set(fN*2);
116 Double_t TH1K::GetBinContent(Int_t bin)
const
119 ((TH1K*)
this)->Sort();
120 ((TH1K*)
this)->fReady=1;
122 if (!fNIn)
return 0.;
123 float x = GetBinCenter(bin);
124 int left = TMath::BinarySearch(fNIn,fArray,x);
125 int jl=left,jr=left+1,nk,nkmax =fKOrd;
126 float fl,fr,ff=0.,ffmin=1.e-6;
127 if (!nkmax) {nkmax = 3; ffmin = GetBinWidth(bin);}
128 if (nkmax >= fNIn) nkmax = fNIn-1;
129 for (nk = 1; nk <= nkmax || ff <= ffmin; nk++) {
130 fl = (jl>=0 ) ? TMath::Abs(fArray[jl]-x) : 1.e+20;
131 fr = (jr<fNIn) ? TMath::Abs(fArray[jr]-x) : 1.e+20;
132 if (jl<0 && jr>=fNIn)
break;
133 if (fl < fr) { ff = fl; jl--;}
134 else { ff = fr; jr++;}
136 ((TH1K*)
this)->fKCur = nk - 1;
137 return fNIn * 0.5*fKCur/((float)(fNIn+1))*GetBinWidth(bin)/ff;
144 Double_t TH1K::GetBinError(Int_t bin)
const
146 return TMath::Sqrt(((
double)(fNIn-fKCur+1))/((fNIn+1)*(fKCur-1)))*GetBinContent(bin);
153 void TH1K::Reset(Option_t *option)
168 void TH1K::SavePrimitive(std::ostream &out, Option_t *option )
174 out<<GetName()<<
" = new "<<ClassName()<<
"("<<quote<<GetName()<<quote<<
","<<quote<<GetTitle()<<quote
175 <<
","<<GetXaxis()->GetNbins()
176 <<
","<<GetXaxis()->GetXmin()
177 <<
","<<GetXaxis()->GetXmax()
179 out <<
");"<<std::endl;
181 if (fDirectory == 0) {
182 out<<
" "<<GetName()<<
"->SetDirectory(0);"<<std::endl;
184 if (TestBit(kNoStats)) {
185 out<<
" "<<GetName()<<
"->SetStats(0);"<<std::endl;
187 if (fOption.Length() != 0) {
188 out<<
" "<<GetName()<<
"->SetOption("<<quote<<fOption.Data()<<quote<<
");"<<std::endl;
192 out<<
" Float_t Arr[]={"<<std::endl;
193 for (
int i=0; i<fNIn; i++) {
195 if (i != fNIn-1) {out<<
",";}
else { out<<
"};";}
196 if (i%10 == 9) {out<< std::endl;}
199 out<<
" for(int i=0;i<" << fNIn <<
";i++)"<<GetName()<<
"->Fill(Arr[i]);";
202 SaveFillAttributes(out,GetName(),0,1001);
203 SaveLineAttributes(out,GetName(),1,1,1);
204 SaveMarkerAttributes(out,GetName(),1,1,1);
205 fXaxis.SaveAttributes(out,GetName(),
"->GetXaxis()");
206 fYaxis.SaveAttributes(out,GetName(),
"->GetYaxis()");
207 fZaxis.SaveAttributes(out,GetName(),
"->GetZaxis()");
208 TString opt = option;
210 if (!opt.Contains(
"nodraw")) {
211 out<<
" "<<GetName()<<
"->Draw("
212 <<quote<<option<<quote<<
");"<<std::endl;
220 static int TH1K_fcompare(
const void *f1,
const void *f2)
222 if (*((
float*)f1) < *((
float*)f2))
return -1;
223 if (*((
float*)f1) > *((
float*)f2))
return 1;
234 qsort(GetArray(),fNIn,
sizeof(Float_t),&TH1K_fcompare);