#include <MultiHistogramFitFCN.h>
Classes | |
struct | HistogramDetails_t |
Public Member Functions | |
MultiHistogramFitFCN (double refine_factor=1) | |
~MultiHistogramFitFCN () | |
void | AddTemplate (const TH1D *hist, double time=0) |
void | SetTemplateHist (int n, const TH1D *hist) |
void | SetTimeOffset (int n, double offset) |
void | SetTime (int n, double time) |
void | SetAmplitude (int n, double amp) |
void | SetInitialValues (int n, double time_offset, double amp) |
void | SetPulseHist (const TH1D *pulse) |
void | SetRefineFactor (int refine_factor) |
double & | GetAmplitudeScaleFactor (int i) const |
double & | GetTimeOffset (int i) const |
int | GetNTemplates () const |
double | operator() (const std::vector< double > &par) const |
Used to calculate the chi-2. | |
double | Up () const |
Used for error... somehow? | |
int | GetNDoF () |
Private Types | |
typedef std::vector < HistogramDetails_t > | TemplateList |
Private Member Functions | |
void | UnpackParameters (const std::vector< double > &par) const |
void | GetHistogramBounds (int safety, int &low_edge, int &high_edge) const |
Private Attributes | |
int | fNDoF |
double | fChi2 |
double | fPedestal |
int | fRefineFactor |
TemplateList | fTemplates |
const TH1D * | fPulseHist |
Definition at line 16 of file MultiHistogramFitFCN.h.
typedef std::vector<HistogramDetails_t> MultiHistogramFitFCN::TemplateList [private] |
Definition at line 24 of file MultiHistogramFitFCN.h.
MultiHistogramFitFCN::MultiHistogramFitFCN | ( | double | refine_factor = 1 |
) |
Definition at line 7 of file MultiHistogramFitFCN.cpp.
00007 : 00008 fRefineFactor(refine_factor){ 00009 }
MultiHistogramFitFCN::~MultiHistogramFitFCN | ( | ) |
Definition at line 11 of file MultiHistogramFitFCN.cpp.
void MultiHistogramFitFCN::AddTemplate | ( | const TH1D * | hist, | |
double | time = 0 | |||
) | [inline] |
Definition at line 30 of file MultiHistogramFitFCN.h.
References MultiHistogramFitFCN::HistogramDetails_t::fNDoF, MultiHistogramFitFCN::HistogramDetails_t::fTemplateHist, fTemplates, and MultiHistogramFitFCN::HistogramDetails_t::fTimeOffset.
Referenced by TemplateMultiFitter::Init().
00030 { 00031 HistogramDetails_t tmp; 00032 tmp.fTemplateHist=hist; 00033 tmp.fTimeOffset=time; 00034 tmp.fNDoF=0; 00035 fTemplates.push_back(tmp); 00036 }
double& MultiHistogramFitFCN::GetAmplitudeScaleFactor | ( | int | i | ) | const [inline] |
Definition at line 57 of file MultiHistogramFitFCN.h.
References fTemplates.
00057 {return fTemplates.at(i).fAmplitudeScale;}
void MultiHistogramFitFCN::GetHistogramBounds | ( | int | safety, | |
int & | low_edge, | |||
int & | high_edge | |||
) | const [inline, private] |
Definition at line 96 of file MultiHistogramFitFCN.h.
References fPulseHist, and fTemplates.
Referenced by operator()().
00096 { 00097 // init to pulse histogram 00098 low_edge=safety; 00099 high_edge=fPulseHist->GetNbinsX()-safety; 00100 00101 // for each templatint 00102 int tpl_start, tpl_stop; 00103 for(TemplateList::const_iterator i_tpl=fTemplates.begin(); i_tpl!=fTemplates.end(); ++i_tpl){ 00104 tpl_start=i_tpl->fTimeOffset + safety; 00105 tpl_stop=i_tpl->fTimeOffset+i_tpl->fTemplateHist->GetNbinsX() - safety; 00106 00107 // find the maximum of all the starts of a template 00108 if(high_edge>tpl_stop) high_edge=tpl_stop; 00109 00110 // find the minimum of all the ends of a template 00111 if(low_edge>tpl_start) low_edge=tpl_start; 00112 } 00113 }
int MultiHistogramFitFCN::GetNDoF | ( | ) | [inline] |
Definition at line 76 of file MultiHistogramFitFCN.h.
References fNDoF.
Referenced by TemplateMultiFitter::FitWithAllTimesFixed(), and TemplateMultiFitter::FitWithOneTimeFree().
00076 { return fNDoF; }
int MultiHistogramFitFCN::GetNTemplates | ( | ) | const [inline] |
Definition at line 59 of file MultiHistogramFitFCN.h.
References fTemplates.
00059 {return fTemplates.size();}
double& MultiHistogramFitFCN::GetTimeOffset | ( | int | i | ) | const [inline] |
Definition at line 58 of file MultiHistogramFitFCN.h.
References fTemplates.
00058 {return fTemplates.at(i).fTimeOffset;}
double MultiHistogramFitFCN::operator() | ( | const std::vector< double > & | par | ) | const |
Used to calculate the chi-2.
The return value is the chi squared weighted by errors in fTemplateHist Parameters: 0. Pedestal 1. Amplitude of first pulse 2. Amplitude of second pulse .... N Amplitude of Nth pulse
Definition at line 29 of file MultiHistogramFitFCN.cpp.
References fNDoF, fPulseHist, fRefineFactor, fTemplates, GetHistogramBounds(), and UnpackParameters().
00029 { 00030 // Chi2 fit with pedestal P, amplitude A, and timing T 00031 // Warning: The time is truncated to an int, so if there's 00032 // so if the step size in MINUIT is smalled than 1, 00033 // Any value of T will probably be seen as minimized, which it 00034 // almost certainly will not be. 00035 UnpackParameters(par); 00036 double chi2 = 0.; 00037 00038 int safety = 6*fRefineFactor; // remove a few bins from the fit 00039 int bounds[2]; 00040 GetHistogramBounds(safety,bounds[0], bounds[1]); 00041 00042 if( (bounds[1]-bounds[0]) < 40*fRefineFactor ) throw Except::SlimlyOverlappingTemplates(); 00043 00044 // Calculate the degrees of freedom ( #data - #fit_params) 00045 // +1 because we include both ends of the bounds when we loop through 00046 fNDoF = ((bounds[1] - bounds[0] + 1)/fRefineFactor) - par.size(); 00047 00048 double tpl_height,tpl_error; 00049 for (int i = bounds[0]+(fRefineFactor/2.0); i <= bounds[1]-(fRefineFactor/2.0); i += fRefineFactor) { 00050 // calculate the chi^2 based on the centre of the 5 bins to avoid getting 00051 // abonus from mathcing all 5. We shift and scale the template so that it 00052 // matches the pulse. This is because, when we have a normalised template, 00053 // we will get the actual amplitude, pedestal and time from the fit and not 00054 // just offsets 00055 tpl_height=0; 00056 tpl_error=0; 00057 00058 for(TemplateList::const_iterator i_tpl=fTemplates.begin(); 00059 i_tpl!=fTemplates.end(); ++i_tpl){ 00060 tpl_height+=i_tpl->GetHeight(i); 00061 tpl_error+=i_tpl->fAmplitudeScale*i_tpl->GetError2(i); 00062 } 00063 00064 double delta = fPulseHist->GetBinContent(i) - tpl_height; 00065 chi2 += delta*delta / tpl_error; 00066 } 00067 00068 return chi2; 00069 }
void MultiHistogramFitFCN::SetAmplitude | ( | int | n, | |
double | amp | |||
) | [inline] |
Definition at line 46 of file MultiHistogramFitFCN.h.
References fTemplates.
Referenced by SetInitialValues().
00046 { 00047 fTemplates.at(n).fAmplitudeScale=amp/fTemplates[n].fTemplateHist->GetMaximum(); 00048 }
void MultiHistogramFitFCN::SetInitialValues | ( | int | n, | |
double | time_offset, | |||
double | amp | |||
) | [inline] |
Definition at line 49 of file MultiHistogramFitFCN.h.
References SetAmplitude(), and SetTime().
00049 { 00050 SetTime(n, time_offset); 00051 SetAmplitude(n, amp); 00052 }
void MultiHistogramFitFCN::SetPulseHist | ( | const TH1D * | pulse | ) | [inline] |
Definition at line 54 of file MultiHistogramFitFCN.h.
References fPulseHist.
Referenced by TemplateMultiFitter::FitWithAllTimesFixed(), and TemplateMultiFitter::FitWithOneTimeFree().
00054 {fPulseHist=pulse;}
void MultiHistogramFitFCN::SetRefineFactor | ( | int | refine_factor | ) | [inline] |
Definition at line 55 of file MultiHistogramFitFCN.h.
References fRefineFactor.
Referenced by TemplateMultiFitter::Init().
00055 {fRefineFactor = refine_factor;}
void MultiHistogramFitFCN::SetTemplateHist | ( | int | n, | |
const TH1D * | hist | |||
) | [inline] |
Definition at line 37 of file MultiHistogramFitFCN.h.
References fTemplates.
00037 { 00038 fTemplates.at(n).fTemplateHist=hist; 00039 }
void MultiHistogramFitFCN::SetTime | ( | int | n, | |
double | time | |||
) | [inline] |
Definition at line 43 of file MultiHistogramFitFCN.h.
References fTemplates.
Referenced by SetInitialValues().
00043 { 00044 fTemplates.at(n).fTimeOffset=time - fTemplates[n].fTemplateHist->GetMaximumBin(); 00045 }
void MultiHistogramFitFCN::SetTimeOffset | ( | int | n, | |
double | offset | |||
) | [inline] |
Definition at line 40 of file MultiHistogramFitFCN.h.
References fTemplates.
Referenced by TemplateMultiFitter::FitWithAllTimesFixed(), and TemplateMultiFitter::FitWithOneTimeFree().
00040 { 00041 fTemplates.at(n).fTimeOffset=offset; 00042 }
void MultiHistogramFitFCN::UnpackParameters | ( | const std::vector< double > & | par | ) | const [inline, private] |
Definition at line 115 of file MultiHistogramFitFCN.h.
References fPedestal, and fTemplates.
Referenced by operator()().
00115 { 00116 if ( par.size() < fTemplates.size()+1) return; 00117 const std::vector<double>::const_iterator begin=par.begin(); 00118 std::vector<double>::const_iterator i_par=begin; 00119 fPedestal=*i_par; 00120 for(++i_par ; i_par!=par.end(); ++i_par){ 00121 int n= (i_par-begin-1) ; 00122 fTemplates.at(n).fAmplitudeScale=*i_par; 00123 } 00124 }
double MultiHistogramFitFCN::Up | ( | ) | const [inline] |
double MultiHistogramFitFCN::fChi2 [mutable, private] |
Definition at line 85 of file MultiHistogramFitFCN.h.
int MultiHistogramFitFCN::fNDoF [mutable, private] |
record this for TemplateFitter to retrieve later (NB mutable so that it can be set in operator(), which is const)
Definition at line 84 of file MultiHistogramFitFCN.h.
Referenced by GetNDoF(), and operator()().
double MultiHistogramFitFCN::fPedestal [mutable, private] |
Definition at line 86 of file MultiHistogramFitFCN.h.
Referenced by UnpackParameters().
const TH1D* MultiHistogramFitFCN::fPulseHist [private] |
Definition at line 92 of file MultiHistogramFitFCN.h.
Referenced by GetHistogramBounds(), operator()(), and SetPulseHist().
int MultiHistogramFitFCN::fRefineFactor [private] |
Definition at line 88 of file MultiHistogramFitFCN.h.
Referenced by operator()(), and SetRefineFactor().
TemplateList MultiHistogramFitFCN::fTemplates [mutable, private] |
Definition at line 90 of file MultiHistogramFitFCN.h.
Referenced by AddTemplate(), GetAmplitudeScaleFactor(), GetHistogramBounds(), GetNTemplates(), GetTimeOffset(), operator()(), SetAmplitude(), SetTemplateHist(), SetTime(), SetTimeOffset(), and UnpackParameters().