#include <SymmetryFit.h>
Static Public Member Functions | |
static TF1 * | fitfunction () |
static std::string | name (std::string base) |
static std::vector< double > | pol2_from_pol2 (TH1 *hist) |
static std::vector< double > | pol2_from_pol3 (TH1 *hist) |
static TH1 * | symmetryChi2 (const TH1 *, const std::pair< unsigned, unsigned >) |
static TH1 * | symmetryChi2 (std::string, const std::vector< TH1 * > &, const std::pair< unsigned, unsigned >) |
Private Member Functions | |
float | chi2 (std::pair< unsigned, unsigned >) |
float | chi2_element (std::pair< unsigned, unsigned >) |
std::vector< std::pair < unsigned, unsigned > > | continuousRanges () const |
void | fillchi2 () |
std::pair< unsigned, unsigned > | findUsableMinMax () const |
int | fit () |
void | makeChi2Histogram () |
SymmetryFit | operator+= (const SymmetryFit &R) |
SymmetryFit (const TH1 *, const std::pair< unsigned, unsigned >) | |
Private Attributes | |
TH1 * | chi2_ |
const unsigned | minDF_ |
const std::pair< unsigned, unsigned > | minmaxUsable_ |
unsigned | ndf_ |
const std::pair< unsigned, unsigned > | range_ |
const TH1 * | symm_candidate_ |
Definition at line 8 of file SymmetryFit.h.
SymmetryFit::SymmetryFit | ( | const TH1 * | h, |
const std::pair< unsigned, unsigned > | r | ||
) | [private] |
Definition at line 32 of file SymmetryFit.cc.
References fillchi2(), and makeChi2Histogram().
: symm_candidate_(h), minDF_(r.second-r.first), range_(r), minmaxUsable_(findUsableMinMax()), ndf_( minmaxUsable_.first<minmaxUsable_.second ? minmaxUsable_.second-minmaxUsable_.first : 0), chi2_(0) { makeChi2Histogram(); fillchi2(); }
float SymmetryFit::chi2 | ( | std::pair< unsigned, unsigned > | point | ) | [private] |
Definition at line 98 of file SymmetryFit.cc.
References chi2_element(), i, minmaxUsable_, ndf_, and XX.
Referenced by fillchi2().
{ point.first -= minmaxUsable_.first; point.second += minmaxUsable_.first; float XX=0; unsigned i=ndf_; while(i-->0) { XX += chi2_element(point); point.first--; point.second++; } return XX; }
float SymmetryFit::chi2_element | ( | std::pair< unsigned, unsigned > | range | ) | [private] |
Definition at line 112 of file SymmetryFit.cc.
References funct::pow(), and symm_candidate_.
Referenced by chi2().
{ float y0(symm_candidate_->GetBinContent(range.first)), y1(symm_candidate_->GetBinContent(range.second)), e0(symm_candidate_->GetBinError(range.first)), e1(symm_candidate_->GetBinError(range.second)); assert(e0&&e1); return pow(y0-y1, 2)/(e0*e0+e1*e1); }
std::vector< std::pair< unsigned, unsigned > > SymmetryFit::continuousRanges | ( | ) | const [private] |
Definition at line 72 of file SymmetryFit.cc.
References i, diffTwoXMLs::ranges, and symm_candidate_.
Referenced by findUsableMinMax().
{ std::vector<std::pair<unsigned,unsigned> > ranges; const unsigned Nbins = symm_candidate_->GetNbinsX(); unsigned i=0; while(++i<=Nbins) { if(symm_candidate_->GetBinError(i)) { std::pair<unsigned,unsigned> range(i,i+1); while(++i<=Nbins && symm_candidate_->GetBinError(i)) range.second++; ranges.push_back(range); } } return ranges; }
void SymmetryFit::fillchi2 | ( | ) | [private] |
Definition at line 88 of file SymmetryFit.cc.
References chi2(), chi2_, i, dttmaxenums::L, minDF_, ndf_, dttmaxenums::R, and range_.
Referenced by SymmetryFit().
std::pair< unsigned, unsigned > SymmetryFit::findUsableMinMax | ( | ) | const [private] |
Definition at line 54 of file SymmetryFit.cc.
References cont, continuousRanges(), first, dttmaxenums::L, max(), min, dttmaxenums::R, range_, and edm::second().
{ unsigned NEAR(0), FAR(0); const std::vector<std::pair<unsigned,unsigned> > cont = continuousRanges(); for(unsigned L=0; L<cont.size(); L++) { if( cont[L].first > range_.first) continue; for(unsigned R=L; R<cont.size(); R++) { if( cont[R].second < range_.second) continue; const unsigned far = std::min( range_.first - cont[L].first, cont[R].second - range_.second ); const unsigned near = std::max( range_.second<cont[L].second ? 0 : range_.second - cont[L].second, cont[R].first<range_.first ? 0 : cont[R].first - range_.first ); if ( (far>near) && (far-near)>(FAR-NEAR) ) { FAR = far; NEAR = near;} } } return std::make_pair(NEAR,FAR); }
int SymmetryFit::fit | ( | ) | [private] |
Definition at line 123 of file SymmetryFit.cc.
References chi2_, f, fitfunction(), ndf_, AlCaHLTBitMon_ParallelJobs::p, and pol2_from_pol3().
Referenced by symmetryChi2().
{ std::vector<double> p = pol2_from_pol3(chi2_); if( !p.size() || p[0] < chi2_->GetBinCenter(1) || p[0] > chi2_->GetBinCenter(chi2_->GetNbinsX())) return 7; TF1* f = fitfunction(); f->SetParameter(0, p[0]); f->SetParLimits(0, p[0], p[0]); f->SetParameter(1, p[1]); f->SetParLimits(1, p[1], p[1]); f->SetParameter(2, p[2]); f->SetParLimits(2, p[2], p[2]); f->SetParameter(3, ndf_); f->SetParLimits(3, ndf_,ndf_); //Fixed chi2_->Fit(f,"WQ"); return 0; }
TF1 * SymmetryFit::fitfunction | ( | ) | [static] |
void SymmetryFit::makeChi2Histogram | ( | ) | [private] |
Definition at line 44 of file SymmetryFit.cc.
References chi2_, name(), range_, and symm_candidate_.
Referenced by SymmetryFit().
{ std::string XXname = name(symm_candidate_->GetName()); unsigned Nbins = 2*( range_.second - range_.first ) + 1; double binwidth = symm_candidate_->GetBinWidth(1); double low = symm_candidate_->GetBinCenter(range_.first) - 3*binwidth/4; double up = symm_candidate_->GetBinCenter(range_.second-1) + 3*binwidth/4; chi2_ = new TH1F(XXname.c_str(),"", Nbins, low, up); }
static std::string SymmetryFit::name | ( | std::string | base | ) | [inline, static] |
Definition at line 14 of file SymmetryFit.h.
Referenced by makeChi2Histogram().
{return base+"_symmchi2";}
SymmetryFit SymmetryFit::operator+= | ( | const SymmetryFit & | R | ) | [inline, private] |
std::vector< double > SymmetryFit::pol2_from_pol2 | ( | TH1 * | hist | ) | [static] |
Definition at line 151 of file SymmetryFit.cc.
References AlCaHLTBitMon_ParallelJobs::p, mathSSE::sqrt(), ntuplemaker::status, and v.
{ std::vector<double> v; int status = hist->Fit("pol2","WQ"); if(!status) { std::vector<double> p; p.push_back(hist->GetFunction("pol2")->GetParameter(0)); p.push_back(hist->GetFunction("pol2")->GetParameter(1)); p.push_back(hist->GetFunction("pol2")->GetParameter(2)); if(p[2]>0) { v.push_back( -0.5*p[1]/p[2] ); v.push_back( 1./sqrt(p[2]) ); v.push_back( p[0]-0.25*p[1]*p[1]/p[2] ); } } return v; }
std::vector< double > SymmetryFit::pol2_from_pol3 | ( | TH1 * | hist | ) | [static] |
Definition at line 169 of file SymmetryFit.cc.
References AlCaHLTBitMon_ParallelJobs::p, funct::pow(), mathSSE::sqrt(), ntuplemaker::status, and v.
Referenced by fit().
{ std::vector<double> v; int status = hist->Fit("pol3","WQ"); if(!status) { std::vector<double> p; p.push_back(hist->GetFunction("pol3")->GetParameter(0)); p.push_back(hist->GetFunction("pol3")->GetParameter(1)); p.push_back(hist->GetFunction("pol3")->GetParameter(2)); p.push_back(hist->GetFunction("pol3")->GetParameter(3)); double radical = p[2]*p[2] - 3*p[1]*p[3] ; if(radical>0) { double x0 = ( -p[2] + sqrt(radical) ) / ( 3*p[3] ) ; v.push_back( x0 ); v.push_back( pow( radical, -0.25) ); v.push_back( p[0] + p[1]*x0 + p[2]*x0*x0 + p[3]*x0*x0*x0 ); } } return v; }
TH1 * SymmetryFit::symmetryChi2 | ( | std::string | basename, |
const std::vector< TH1 * > & | candidates, | ||
const std::pair< unsigned, unsigned > | range | ||
) | [static] |
Definition at line 6 of file SymmetryFit.cc.
References chi2_, runregparse::combined, fit(), and ntuplemaker::status.
Referenced by LA_Filler_Fitter::make_and_fit_symmchi2().
{ TH1* fake = (TH1*)(candidates[0]->Clone(basename.c_str())); fake->Reset(); SymmetryFit combined(fake,range); delete fake; BOOST_FOREACH(const TH1* candidate, candidates) { SymmetryFit sf(candidate,range); combined+=sf; delete sf.chi2_; } int status = combined.fit(); if(status) { delete combined.chi2_; combined.chi2_=0;} return combined.chi2_; }
TH1 * SymmetryFit::symmetryChi2 | ( | const TH1 * | candidate, |
const std::pair< unsigned, unsigned > | range | ||
) | [static] |
Definition at line 24 of file SymmetryFit.cc.
References chi2_, fit(), and ntuplemaker::status.
{ SymmetryFit sf(candidate, range); int status = sf.fit(); if(status) { delete sf.chi2_; sf.chi2_=0; } return sf.chi2_; }
TH1* SymmetryFit::chi2_ [private] |
Definition at line 35 of file SymmetryFit.h.
Referenced by fillchi2(), fit(), makeChi2Histogram(), operator+=(), and symmetryChi2().
const unsigned SymmetryFit::minDF_ [private] |
Definition at line 32 of file SymmetryFit.h.
Referenced by fillchi2().
const std::pair<unsigned,unsigned> SymmetryFit::minmaxUsable_ [private] |
Definition at line 33 of file SymmetryFit.h.
Referenced by chi2().
unsigned SymmetryFit::ndf_ [private] |
Definition at line 34 of file SymmetryFit.h.
Referenced by chi2(), fillchi2(), fit(), and operator+=().
const std::pair<unsigned,unsigned> SymmetryFit::range_ [private] |
Definition at line 33 of file SymmetryFit.h.
Referenced by fillchi2(), findUsableMinMax(), and makeChi2Histogram().
const TH1* SymmetryFit::symm_candidate_ [private] |
Definition at line 31 of file SymmetryFit.h.
Referenced by chi2_element(), continuousRanges(), and makeChi2Histogram().