#include <RecoParticleFlow/PFRootEvent/interface/ResidualFitter.h>
Public Member Functions | |
void | AddMeas (double x, double y, double z) |
void | AddTrue (double x, double y, double z) |
void | cd () |
void | CreateCanvas () |
TH1D * | CurBin () |
void | ExecuteEvent (Int_t event, Int_t px, Int_t py, TObject *sel) |
void | Fill () |
void | Fit (int x, int y, const char *opt="") |
void | FitSlicesZ (TF1 *f1=0) |
TCanvas * | GetCanvas () |
TF1 * | GetFunction () |
ResidualFitter (const char *name, const char *title, int nbinsx, double xlow, double xup, int nbinsy, double ylow, double yup, int nbinsz, double zlow, double zup) | |
void | SetAutoRange (int n) |
void | SetFitFunction (TF1 *func) |
void | SetFitOptions (const char *opt) |
void | SetMinN (int n) |
void | ShowFit (TH2 *h2d, double x, double y) |
~ResidualFitter () | |
Static Public Member Functions | |
static void | SetCanvas (int x, int y) |
Private Attributes | |
int | autoRangeN_ |
TCanvas * | canvas_ |
TCanvas * | canvasFit_ |
TH2D * | chi2_ |
TH1D * | curBin_ |
TF1 * | fitFunction_ |
std::string | fitOptions_ |
TH2D * | mean_ |
std::vector < ResidualFitter::Point > | meas_ |
int | minN_ |
if the number of entries in a bin is lower than this, fit is not performed. | |
int | oldBinx_ |
int | oldBiny_ |
TH2D * | sigma_ |
std::vector < ResidualFitter::Point > | true_ |
Static Private Attributes | |
static int | xCanvas_ = 600 |
static int | yCanvas_ = 600 |
Classes | |
class | Point |
Definition at line 11 of file ResidualFitter.h.
ResidualFitter::ResidualFitter | ( | const char * | name, | |
const char * | title, | |||
int | nbinsx, | |||
double | xlow, | |||
double | xup, | |||
int | nbinsy, | |||
double | ylow, | |||
double | yup, | |||
int | nbinsz, | |||
double | zlow, | |||
double | zup | |||
) |
Definition at line 21 of file ResidualFitter.cc.
References chi2_, GenMuonPlsPt100GeV_cfg::cout, CreateCanvas(), lat::endl(), mean_, and sigma_.
00026 : TH3D( name, title, 00027 nbinsx, xlow, xup, 00028 nbinsy, ylow, yup, 00029 nbinsz, zlow, zup ), 00030 fitFunction_( new TF1("gaus", "gaus") ), 00031 canvasFit_(0), 00032 curBin_(0), 00033 autoRangeN_(0), 00034 minN_(5) { 00035 00036 cout<<"creating residual fitter with name "<<name<<endl; 00037 00038 string meanname = name; meanname += "_mean"; 00039 mean_ = new TH2D(meanname.c_str(), meanname.c_str(), 00040 nbinsx, xlow, xup, 00041 nbinsy, ylow, yup); 00042 mean_->SetStats(0); 00043 00044 string sigmaname = name; sigmaname += "_sigma"; 00045 sigma_ = new TH2D(sigmaname.c_str(), sigmaname.c_str(), 00046 nbinsx, xlow, xup, 00047 nbinsy, ylow, yup); 00048 00049 sigma_->SetStats(0); 00050 00051 string chi2name = name; chi2name += "_chi2"; 00052 chi2_ = new TH2D(chi2name.c_str(), chi2name.c_str(), 00053 nbinsx, xlow, xup, 00054 nbinsy, ylow, yup); 00055 chi2_->SetStats(0); 00056 00057 // string nseenname = name; nseenname += "_nseen"; 00058 // nseen_ = new TH2D(nseenname.c_str(), nseenname.c_str(), 00059 // nbinsx, xlow, xup, 00060 // nbinsy, ylow, yup); 00061 // nseen_->SetStats(0); 00062 00063 gDirectory->ls(); 00064 00065 CreateCanvas(); 00066 }
ResidualFitter::~ResidualFitter | ( | ) |
Definition at line 68 of file ResidualFitter.cc.
References canvas_, chi2_, curBin_, fitFunction_, mean_, and sigma_.
00068 { 00069 delete fitFunction_; 00070 if(canvas_) delete canvas_; 00071 if(curBin_) delete curBin_; 00072 00073 delete mean_; 00074 delete sigma_; 00075 delete chi2_; 00076 // delete nseen_; 00077 }
void ResidualFitter::AddMeas | ( | double | x, | |
double | y, | |||
double | z | |||
) | [inline] |
void ResidualFitter::AddTrue | ( | double | x, | |
double | y, | |||
double | z | |||
) | [inline] |
void ResidualFitter::CreateCanvas | ( | ) |
Definition at line 79 of file ResidualFitter.cc.
References canvas_, xCanvas_, and yCanvas_.
Referenced by ResidualFitter().
00079 { 00080 string cname = "ResidualFitterCanvas_"; cname += GetName(); 00081 canvas_ = new TCanvas(cname.c_str(), cname.c_str(),xCanvas_, yCanvas_); 00082 00083 canvas_ ->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", 00084 "ResidualFitter", 00085 this, "ExecuteEvent(Int_t,Int_t,Int_t,TObject*)"); 00086 00087 00088 }
TH1D* ResidualFitter::CurBin | ( | ) | [inline] |
void ResidualFitter::ExecuteEvent | ( | Int_t | event, | |
Int_t | px, | |||
Int_t | py, | |||
TObject * | sel | |||
) |
Definition at line 124 of file ResidualFitter.cc.
References canvas_, ShowFit(), x, and y.
00124 { 00125 00126 if( event != kButton1Down ) return; 00127 00128 TH2* histo2d = dynamic_cast<TH2*>(sel); 00129 if(!histo2d) return; 00130 00131 float x = canvas_->AbsPixeltoX(px); 00132 float y = canvas_->AbsPixeltoY(py); 00133 x = canvas_->PadtoX(x); 00134 y = canvas_->PadtoY(y); 00135 00136 ShowFit(histo2d, x, y); 00137 }
void ResidualFitter::Fill | ( | ) |
Definition at line 91 of file ResidualFitter.cc.
References it, meas_, and true_.
00091 { 00092 00093 Reset(); 00094 00095 for(unsigned it = 0; it<true_.size(); it++) { 00096 for(unsigned im = 0; im<meas_.size(); im++) { 00097 TH3D::Fill(true_[it].x_, 00098 true_[it].y_, 00099 meas_[it].z_ - true_[it].z_ ); 00100 } 00101 } 00102 }
Definition at line 166 of file ResidualFitter.cc.
References autoRangeN_, chi2_, GenMuonPlsPt100GeV_cfg::cout, curBin_, lat::endl(), fitFunction_, fitOptions_, mean_, minN_, and sigma_.
Referenced by FitSlicesZ(), and ShowFit().
00166 { 00167 TH1::AddDirectory(0); 00168 00169 if(curBin_) delete curBin_; 00170 curBin_ = TH3::ProjectionZ("", binx, binx, biny, biny); 00171 00172 if(curBin_->GetEntries() < minN_ ) { 00173 TH1::AddDirectory(1); 00174 return; 00175 } 00176 00177 string sopt = fitOptions_; sopt += opt; 00178 00179 if( autoRangeN_ ) { 00180 double maxpos = curBin_->GetBinCenter( curBin_->GetMaximumBin() ); 00181 00182 double minrange = maxpos-curBin_->GetRMS()* autoRangeN_; 00183 double maxrange = maxpos+curBin_->GetRMS()* autoRangeN_; 00184 00185 fitFunction_->SetRange( minrange, maxrange ); 00186 cout<<"range : "<<minrange<<" "<<maxrange<<endl; 00187 } 00188 00189 curBin_->Fit(fitFunction_, sopt.c_str() ); 00190 00191 00192 double chi2overndf=0; 00193 if(fitFunction_->GetNDF() ) { 00194 chi2overndf = fitFunction_->GetChisquare()/ fitFunction_->GetNDF(); 00195 mean_->SetBinContent(binx,biny, fitFunction_->GetParameter(1) ); 00196 mean_->SetBinError(binx,biny, fitFunction_->GetParError(1) ); 00197 sigma_->SetBinContent(binx,biny, fitFunction_->GetParameter(2) ); 00198 sigma_->SetBinError(binx,biny, fitFunction_->GetParError(2) ); 00199 00200 chi2_->SetBinContent(binx,biny,chi2overndf); 00201 } 00202 // nseen_->SetBinContent(binx, biny, 00203 // fitFunction_->Integral( fitFunction_->GetXmin(), 00204 // fitFunction_->GetXmax()) 00205 // /curBin_->GetBinWidth(1) ); 00206 00207 TH1::AddDirectory(1); 00208 }
void ResidualFitter::FitSlicesZ | ( | TF1 * | f1 = 0 |
) |
Definition at line 104 of file ResidualFitter.cc.
References chi2_, GenMuonPlsPt100GeV_cfg::cout, lat::endl(), Fit(), mean_, SetFitFunction(), and sigma_.
00104 { 00105 00106 mean_->Reset(); 00107 sigma_->Reset(); 00108 chi2_->Reset(); 00109 // nseen_->Reset(); 00110 00111 cout<<"ResidualFitter::FitSlicesZ"<<endl; 00112 if(f1) SetFitFunction(f1); 00113 00114 for(int ix=1; ix<=GetNbinsX(); ix++) { 00115 for(int iy=1; iy<=GetNbinsY(); iy++) { 00116 Fit(ix, iy, "Q0"); 00117 } 00118 } 00119 00120 // TH3D::FitSlicesZ(f1); 00121 }
TCanvas* ResidualFitter::GetCanvas | ( | ) | [inline] |
TF1* ResidualFitter::GetFunction | ( | ) | [inline] |
Definition at line 51 of file ResidualFitter.h.
References fitFunction_.
00051 {return fitFunction_;}
Definition at line 42 of file ResidualFitter.h.
References autoRangeN_, and fitOptions_.
00042 { 00043 autoRangeN_= n; 00044 fitOptions_ += "R"; 00045 }
void ResidualFitter::SetFitFunction | ( | TF1 * | func | ) | [inline] |
Definition at line 33 of file ResidualFitter.h.
References fitFunction_.
Referenced by FitSlicesZ().
00033 { fitFunction_ = func; }
void ResidualFitter::SetFitOptions | ( | const char * | opt | ) | [inline] |
void ResidualFitter::ShowFit | ( | TH2 * | h2d, | |
double | x, | |||
double | y | |||
) |
Definition at line 140 of file ResidualFitter.cc.
References canvas_, canvasFit_, Fit(), oldBinx_, and oldBiny_.
Referenced by ExecuteEvent().
00140 { 00141 00142 if(!canvasFit_) { 00143 string cname = "ResidualFitterCanvasFit_"; cname += GetName(); 00144 canvasFit_ = new TCanvas(cname.c_str(), cname.c_str(),300,300); 00145 } 00146 canvasFit_ ->cd(); 00147 00148 int binx = histo2d->GetXaxis()->FindBin(x); 00149 int biny = histo2d->GetYaxis()->FindBin(y); 00150 00151 if(binx == oldBinx_ && biny == oldBiny_ ) return; 00152 oldBinx_ = binx; 00153 oldBiny_ = biny; 00154 00155 Fit(binx, biny); 00156 00157 canvasFit_->Modified(); 00158 canvasFit_->Update(); 00159 00160 canvas_->Modified(); 00161 canvas_->Update(); 00162 canvas_->cd(); 00163 }
int ResidualFitter::autoRangeN_ [private] |
TCanvas* ResidualFitter::canvas_ [private] |
Definition at line 77 of file ResidualFitter.h.
Referenced by cd(), CreateCanvas(), ExecuteEvent(), GetCanvas(), ShowFit(), and ~ResidualFitter().
TCanvas* ResidualFitter::canvasFit_ [private] |
TH2D* ResidualFitter::chi2_ [private] |
Definition at line 88 of file ResidualFitter.h.
Referenced by Fit(), FitSlicesZ(), ResidualFitter(), and ~ResidualFitter().
TH1D* ResidualFitter::curBin_ [private] |
Definition at line 85 of file ResidualFitter.h.
Referenced by CurBin(), Fit(), and ~ResidualFitter().
TF1* ResidualFitter::fitFunction_ [private] |
Definition at line 74 of file ResidualFitter.h.
Referenced by Fit(), GetFunction(), SetFitFunction(), and ~ResidualFitter().
std::string ResidualFitter::fitOptions_ [private] |
Definition at line 75 of file ResidualFitter.h.
Referenced by Fit(), SetAutoRange(), and SetFitOptions().
TH2D* ResidualFitter::mean_ [private] |
Definition at line 86 of file ResidualFitter.h.
Referenced by Fit(), FitSlicesZ(), ResidualFitter(), and ~ResidualFitter().
std::vector< ResidualFitter::Point > ResidualFitter::meas_ [private] |
int ResidualFitter::minN_ [private] |
if the number of entries in a bin is lower than this, fit is not performed.
set to 5 by default.
Definition at line 98 of file ResidualFitter.h.
int ResidualFitter::oldBinx_ [private] |
int ResidualFitter::oldBiny_ [private] |
TH2D* ResidualFitter::sigma_ [private] |
Definition at line 87 of file ResidualFitter.h.
Referenced by Fit(), FitSlicesZ(), ResidualFitter(), and ~ResidualFitter().
std::vector< ResidualFitter::Point > ResidualFitter::true_ [private] |
int ResidualFitter::xCanvas_ = 600 [static, private] |
int ResidualFitter::yCanvas_ = 600 [static, private] |