Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
emiglior committed Jun 25, 2014
1 parent cb3e8c4 commit ba560e8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
28 changes: 14 additions & 14 deletions MuonAnalysis/MomentumScaleCalibration/plugins/MuScleFitUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1994,13 +1994,13 @@ std::vector<TGraphErrors*> MuScleFitUtils::fitMass (TH2F* histo) {

// Cleanup
// -------
delete x;
delete ym;
delete eym;
delete yw;
delete eyw;
delete yc;
delete e;
delete[] x;
delete[] ym;
delete[] eym;
delete[] yw;
delete[] eyw;
delete[] yc;
delete[] e;
delete fitFcn;

results.push_back(grM);
Expand Down Expand Up @@ -2104,13 +2104,13 @@ std::vector<TGraphErrors*> MuScleFitUtils::fitReso (TH2F* histo) {

// Cleanup
// -------
delete x;
delete ym;
delete eym;
delete yw;
delete eyw;
delete yc;
delete e;
delete[] x;
delete[] ym;
delete[] eym;
delete[] yw;
delete[] eyw;
delete[] yc;
delete[] e;
delete fitFcn;

results.push_back (grM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
* The methods names after the variables return the fit result.
*/


namespace
{
typedef std::pair<RooRealVar, RooDataHist*> rooPair;
Expand Down Expand Up @@ -75,7 +74,7 @@ class FitWithRooFit
// Declare observable x
RooRealVar x("x", "x", xMin, xMax);
// Create a binned dataset that imports contents of TH1 and associates its contents to observable 'x'
return( std::make_pair(x, new RooDataHist("dh","dh",x,Import(*histo))) );
return( std::make_pair(x, new RooDataHist("dh","dh",x,RooFit::Import(*histo))) );
}

// Plot and fit a RooDataHist fitting signal and background
Expand All @@ -86,21 +85,21 @@ class FitWithRooFit
RooDataHist * dh = imported.second;

// Make plot of binned dataset showing Poisson error bars (RooFit default)
RooPlot* frame = x.frame(Title("Imported TH1 with Poisson error bars")) ;
RooPlot* frame = x.frame(RooFit::Title("Imported TH1 with Poisson error bars")) ;
frame->SetName(TString(histo->GetName())+"_frame");
dh->plotOn(frame);

// Build the composite model
RooAbsPdf * model = buildModel(&x, signalType, backgroundType);

RooChi2Var chi2("chi2", "chi2", *model, *dh, DataError(RooAbsData::SumW2));
RooChi2Var chi2("chi2", "chi2", *model, *dh, RooFit::DataError(RooAbsData::SumW2));

// Fit the composite model
// -----------------------
// Fit with likelihood
if( !useChi2_ ) {
if( sumW2Error ) {
model->fitTo(*dh, Save(), SumW2Error(kTRUE));
model->fitTo(*dh, RooFit::Save(), RooFit::SumW2Error(kTRUE));
}
else {
model->fitTo(*dh);
Expand All @@ -115,8 +114,8 @@ class FitWithRooFit
// RooFitResult* r_chi2_wgt = m.save();
}
model->plotOn(frame);
model->plotOn(frame, Components(backgroundType), LineStyle(kDotted), LineColor(kRed));
model->paramOn(frame, Label("fit result"), Format("NEU", AutoPrecision(2)));
model->plotOn(frame, RooFit::Components(backgroundType), RooFit::LineStyle(kDotted), RooFit::LineColor(kRed));
model->paramOn(frame, RooFit::Label("fit result"), RooFit::Format("NEU", RooFit::AutoPrecision(2)));

// TODO: fix next lines to get the prob(chi2) (ndof should be dynamically set according to the choosen pdf)
// double chi2 = xframe.chiSquare("model","data",ndof);
Expand All @@ -129,11 +128,11 @@ class FitWithRooFit
// If histogram has custom error (i.e. its contents is does not originate from a Poisson process
// but e.g. is a sum of weighted events) you can data with symmetric 'sum-of-weights' error instead
// (same error bars as shown by ROOT)
RooPlot* frame2 = x.frame(Title("Imported TH1 with internal errors")) ;
dh->plotOn(frame2,DataError(RooAbsData::SumW2)) ;
RooPlot* frame2 = x.frame(RooFit::Title("Imported TH1 with internal errors")) ;
dh->plotOn(frame2,RooFit::DataError(RooAbsData::SumW2)) ;
model->plotOn(frame2);
model->plotOn(frame2, Components(backgroundType), LineColor(kRed));
model->paramOn(frame2, Label("fit result"), Format("NEU", AutoPrecision(2)));
model->plotOn(frame2, RooFit::Components(backgroundType), RooFit::LineColor(kRed));
model->paramOn(frame2, RooFit::Label("fit result"), RooFit::Format("NEU", RooFit::AutoPrecision(2)));


// Please note that error bars shown (Poisson or SumW2) are for visualization only, the are NOT used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "TPaveText.h"
#include "TF1.h"

#include <iomanip>
#include <sstream>

/**
Expand Down

0 comments on commit ba560e8

Please sign in to comment.