53 fLowerEdge (lower_edge ),
54 fUpperEdge (upper_edge),
55 fFineFactor ( FineFactor ),
57 fKDEborder ( kborder ),
61 Log() << kFATAL <<
"Called without valid histogram pointer (hist)!" <<
Endl;
78 if (fHist != NULL)
delete fHist;
79 if (fFirstIterHist != NULL)
delete fFirstIterHist;
80 if (fSigmaHist != NULL)
delete fSigmaHist;
81 if (fKernel_integ != NULL)
delete fKernel_integ;
90 if ( (par[1]<=0) || (
x[0]>
x[1]))
return -1.;
96 if (xs2==0)
return 0.;
121 fKernel_integ =
new TF1(
"GaussIntegral",
GaussIntegral,fLowerEdge,fUpperEdge,4);
130 Log() << kFATAL <<
"<SetKernelType> KDE sigma has invalid value ( <=0 ) !" <<
Endl;
134 if (fIter == kAdaptiveKDE) {
140 fHiddenIteration=
true;
142 Float_t histoLowEdge=fHist->GetBinLowEdge(1);
143 Float_t histoUpperEdge=fHist->GetBinLowEdge(fHist->GetNbinsX()+1);
145 for (
Int_t i=1;i<fHist->GetNbinsX();i++) {
147 for (
Int_t j=1;j<fFirstIterHist->GetNbinsX();j++) {
149 fFirstIterHist->AddBinContent(j,fHist->GetBinContent(i)*
150 this->GetBinKernelIntegral(fFirstIterHist->GetBinLowEdge(j),
151 fFirstIterHist->GetBinLowEdge(j+1),
152 fHist->GetBinCenter(i),
156 if (fKDEborder == 3) {
160 if (i < fHist->GetNbinsX()/5 ) {
161 for (
Int_t j=1;j<fFirstIterHist->GetNbinsX();j++) {
163 fFirstIterHist->AddBinContent(j,fHist->GetBinContent(i)*
164 this->GetBinKernelIntegral(fFirstIterHist->GetBinLowEdge(j),
165 fFirstIterHist->GetBinLowEdge(j+1),
166 2*histoLowEdge-fHist->GetBinCenter(i),
171 if (i > 4*fHist->GetNbinsX()/5) {
172 for (
Int_t j=1;j<fFirstIterHist->GetNbinsX();j++) {
174 fFirstIterHist->AddBinContent(j,fHist->GetBinContent(i)*
175 this->GetBinKernelIntegral(fFirstIterHist->GetBinLowEdge(j),
176 fFirstIterHist->GetBinLowEdge(j+1),
177 2*histoUpperEdge-fHist->GetBinCenter(i),
185 fFirstIterHist->SetEntries(fHist->GetEntries());
189 for (
Int_t j=1;j<fFirstIterHist->GetNbinsX();j++)
190 integ+=fFirstIterHist->GetBinContent(j)*fFirstIterHist->GetBinWidth(j);
191 fFirstIterHist->Scale(1./integ);
193 fHiddenIteration=
false;
199 for (
Int_t j=1;j<fFirstIterHist->GetNbinsX();j++) {
201 if (fSigma*
TMath::Sqrt(1.0/fFirstIterHist->GetBinContent(j)) <= 0 ) {
202 Log() << kFATAL <<
"<SetKernelType> KDE sigma has invalid value ( <=0 ) !" <<
Endl;
205 fSigmaHist->SetBinContent(j,fFineFactor*fSigma/
TMath::Sqrt(fFirstIterHist->GetBinContent(j)));
209 if (fKernel_integ ==0 ) {
210 Log() << kFATAL <<
"KDE kernel not correctly initialized!" <<
Endl;
219 if ((fIter == kNonadaptiveKDE) || fHiddenIteration )
220 fKernel_integ->SetParameters(mean,fSigma);
221 else if ((fIter == kAdaptiveKDE) && !fHiddenIteration )
222 fKernel_integ->SetParameters(mean,fSigmaHist->GetBinContent(binnum));
224 if ( fKDEborder == 2 ) {
225 Float_t renormFactor=1.0/fKernel_integ->Eval(fLowerEdge,fUpperEdge);
226 return (renormFactor*fKernel_integ->Eval(lowr,highr));
231 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)