61 fLowerEdge (lower_edge ),
62 fUpperEdge (upper_edge),
63 fFineFactor ( FineFactor ),
65 fKDEborder ( kborder ),
69 Log() << kFATAL <<
"Called without valid histogram pointer (hist)!" <<
Endl;
86 if (fHist != NULL)
delete fHist;
87 if (fFirstIterHist != NULL)
delete fFirstIterHist;
88 if (fSigmaHist != NULL)
delete fSigmaHist;
89 if (fKernel_integ != NULL)
delete fKernel_integ;
98 if ( (par[1]<=0) || (
x[0]>
x[1]))
return -1.;
104 if (xs2==0)
return 0.;
129 fKernel_integ =
new TF1(
"GaussIntegral",
GaussIntegral,fLowerEdge,fUpperEdge,4);
138 Log() << kFATAL <<
"<SetKernelType> KDE sigma has invalid value ( <=0 ) !" <<
Endl;
142 if (fIter == kAdaptiveKDE) {
148 fHiddenIteration=
true;
150 Float_t histoLowEdge=fHist->GetBinLowEdge(1);
151 Float_t histoUpperEdge=fHist->GetBinLowEdge(fHist->GetNbinsX()+1);
153 for (
Int_t i=1;i<fHist->GetNbinsX();i++) {
155 for (
Int_t j=1;j<fFirstIterHist->GetNbinsX();j++) {
157 fFirstIterHist->AddBinContent(j,fHist->GetBinContent(i)*
158 this->GetBinKernelIntegral(fFirstIterHist->GetBinLowEdge(j),
159 fFirstIterHist->GetBinLowEdge(j+1),
160 fHist->GetBinCenter(i),
164 if (fKDEborder == 3) {
168 if (i < fHist->GetNbinsX()/5 ) {
169 for (
Int_t j=1;j<fFirstIterHist->GetNbinsX();j++) {
171 fFirstIterHist->AddBinContent(j,fHist->GetBinContent(i)*
172 this->GetBinKernelIntegral(fFirstIterHist->GetBinLowEdge(j),
173 fFirstIterHist->GetBinLowEdge(j+1),
174 2*histoLowEdge-fHist->GetBinCenter(i),
179 if (i > 4*fHist->GetNbinsX()/5) {
180 for (
Int_t j=1;j<fFirstIterHist->GetNbinsX();j++) {
182 fFirstIterHist->AddBinContent(j,fHist->GetBinContent(i)*
183 this->GetBinKernelIntegral(fFirstIterHist->GetBinLowEdge(j),
184 fFirstIterHist->GetBinLowEdge(j+1),
185 2*histoUpperEdge-fHist->GetBinCenter(i),
193 fFirstIterHist->SetEntries(fHist->GetEntries());
197 for (
Int_t j=1;j<fFirstIterHist->GetNbinsX();j++)
198 integ+=fFirstIterHist->GetBinContent(j)*fFirstIterHist->GetBinWidth(j);
199 fFirstIterHist->Scale(1./integ);
201 fHiddenIteration=
false;
207 for (
Int_t j=1;j<fFirstIterHist->GetNbinsX();j++) {
209 if (fSigma*
TMath::Sqrt(1.0/fFirstIterHist->GetBinContent(j)) <= 0 ) {
210 Log() << kFATAL <<
"<SetKernelType> KDE sigma has invalid value ( <=0 ) !" <<
Endl;
213 fSigmaHist->SetBinContent(j,fFineFactor*fSigma/
TMath::Sqrt(fFirstIterHist->GetBinContent(j)));
217 if (fKernel_integ ==0 ) {
218 Log() << kFATAL <<
"KDE kernel not correctly initialized!" <<
Endl;
227 if ((fIter == kNonadaptiveKDE) || fHiddenIteration )
228 fKernel_integ->SetParameters(mean,fSigma);
229 else if ((fIter == kAdaptiveKDE) && !fHiddenIteration )
230 fKernel_integ->SetParameters(mean,fSigmaHist->GetBinContent(binnum));
232 if ( fKDEborder == 2 ) {
233 Float_t renormFactor=1.0/fKernel_integ->Eval(fLowerEdge,fUpperEdge);
234 return (renormFactor*fKernel_integ->Eval(lowr,highr));
239 return (fKernel_integ->Eval(lowr,highr));
Double_t GaussIntegral(Double_t *x, Double_t *par)
when using Gaussian as Kernel function this is faster way to calculate the integrals
1-D histogram with a float per channel (see TH1 documentation)}
virtual void Reset(Option_t *option="")
Reset.
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
KDE Kernel for "smoothing" the PDFs.
KDEKernel(EKernelIter kiter=kNonadaptiveKDE, const TH1 *hist=0, Float_t lower_edge=0., Float_t upper_edge=1., EKernelBorder kborder=kNoTreatment, Float_t FineFactor=1.)
constructor sanity check
virtual ~KDEKernel(void)
destructor
void SetKernelType(EKernelType ktype=kGauss)
fIter == 1 —> nonadaptive KDE fIter == 2 —> adaptive KDE
Float_t GetBinKernelIntegral(Float_t lowr, Float_t highr, Float_t mean, Int_t binnum)
calculates the integral of the Kernel
ostringstream derivative to redirect and format output
MsgLogger & Endl(MsgLogger &ml)
Double_t Erf(Double_t x)
Computation of the error function erf(x).
Double_t Sqrt(Double_t x)
LongDouble_t Power(LongDouble_t x, LongDouble_t y)