Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Changed variable names for clearer ones, that bode nicely with the in…
…terpreter
  • Loading branch information
pmiquelm committed Aug 18, 2016
commit 08e7b2dd86a549f3cb08c86ebe0d2a22ffa703e8
24 changes: 12 additions & 12 deletions tutorials/fit/NumericalMinimization.C
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ int NumericalMinimization(const char * minName = "Minuit2",
// GSLMultiFit
// GSLSimAn
// Genetic
ROOT::Math::Minimizer* min =
ROOT::Math::Minimizer* minimum =
ROOT::Math::Factory::CreateMinimizer(minName, algoName);

// set tolerance , etc...
min->SetMaxFunctionCalls(1000000); // for Minuit/Minuit2
min->SetMaxIterations(10000); // for GSL
min->SetTolerance(0.001);
min->SetPrintLevel(1);
minimum->SetMaxFunctionCalls(1000000); // for Minuit/Minuit2
minimum->SetMaxIterations(10000); // for GSL
minimum->SetTolerance(0.001);
minimum->SetPrintLevel(1);

// create function wrapper for minimizer
// a IMultiGenFunction type
Expand All @@ -67,21 +67,21 @@ int NumericalMinimization(const char * minName = "Minuit2",
variable[1] = r.Uniform(-20,20);
}

min->SetFunction(f);
minimum->SetFunction(f);

// Set the free variables to be minimized !
min->SetVariable(0,"x",variable[0], step[0]);
min->SetVariable(1,"y",variable[1], step[1]);
minimum->SetVariable(0,"x",variable[0], step[0]);
minimum->SetVariable(1,"y",variable[1], step[1]);

// do the minimization
min->Minimize();
minimum->Minimize();

const double *xs = min->X();
const double *xs = minimum->X();
std::cout << "Minimum: f(" << xs[0] << "," << xs[1] << "): "
<< min->MinValue() << std::endl;
<< minimum->MinValue() << std::endl;

// expected minimum is 0
if ( min->MinValue() < 1.E-4 && f(xs) < 1.E-4)
if ( minimum->MinValue() < 1.E-4 && f(xs) < 1.E-4)
std::cout << "Minimizer " << minName << " - " << algoName
<< " converged to the right minimum" << std::endl;
else {
Expand Down
18 changes: 9 additions & 9 deletions tutorials/fit/TestBinomial.C
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
///
/// to show the bias performing 100 fits for 1000 events per "experiment"
///
/// ~~~ {.cpp}
/// ```cpp
/// root[0]: .x TestBinomial.C+
/// ~~~
/// ```
///
/// to show the bias performing 100 fits for 1000 events per "experiment"
///
/// ~~~ {.cpp}
/// ```cpp
/// .x TestBinomial.C+(100, 1000)
/// ~~~
/// ```
///
/// \macro_image
/// \macro_output
Expand All @@ -49,7 +49,7 @@
#include <cassert>
#include <iostream>

void TestBinomial(int nloop = 100, int nevts = 100, bool plot=false, bool debug = false, int seed = 111)
void TestBinomial(int nloop = 100, int nevts = 100, bool plot = false, bool debug = false, int seed = 111)
{
gStyle->SetMarkerStyle(20);
gStyle->SetLineWidth(2.0);
Expand Down Expand Up @@ -101,14 +101,14 @@ void TestBinomial(int nloop = 100, int nevts = 100, bool plot=false, bool debug
// First try: use a single set of parameters.
// For each try, we need to find the overall normalization

Double_t norm = 0.80;
Double_t normalization = 0.80;
Double_t threshold = 25.0;
Double_t width = 5.0;

fM2D->SetParameter(0, norm);
fM2D->SetParameter(0, normalization);
fM2D->SetParameter(1, threshold);
fM2D->SetParameter(2, width);
fM2N->SetParameter(0, norm);
fM2N->SetParameter(0, normalization);
fM2N->SetParameter(1, threshold);
fM2N->SetParameter(2, width);
Double_t integralN = fM2N->Integral(xmin, xmax);
Expand Down Expand Up @@ -240,7 +240,7 @@ void TestBinomial(int nloop = 100, int nevts = 100, bool plot=false, bool debug
}

TH1D* h = dynamic_cast<TH1D*>(hbiasNorm[fit]);
h->Fill((fnorm-norm)/enorm);
h->Fill((fnorm-normalization)/enorm);
h = dynamic_cast<TH1D*>(hbiasThreshold[fit]);
h->Fill((fthreshold-threshold)/ethreshold);
h = dynamic_cast<TH1D*>(hbiasWidth[fit]);
Expand Down
26 changes: 13 additions & 13 deletions tutorials/fit/fitLinear2.C
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void fitLinear2()
{
Int_t n=100;
Int_t i;
TRandom rand1;
TRandom randNum;
TLinearFitter *lf=new TLinearFitter(5);

//The predefined "hypN" functions are the fastest to fit
Expand All @@ -32,13 +32,13 @@ void fitLinear2()

//Create the points and put them into the fitter
for (i=0; i<n; i++){
x[0 + i*5] = rand1.Uniform(-10, 10);
x[1 + i*5] = rand1.Uniform(-10, 10);
x[2 + i*5] = rand1.Uniform(-10, 10);
x[3 + i*5] = rand1.Uniform(-10, 10);
x[4 + i*5] = rand1.Uniform(-10, 10);
x[0 + i*5] = randNum.Uniform(-10, 10);
x[1 + i*5] = randNum.Uniform(-10, 10);
x[2 + i*5] = randNum.Uniform(-10, 10);
x[3 + i*5] = randNum.Uniform(-10, 10);
x[4 + i*5] = randNum.Uniform(-10, 10);
e[i] = 0.01;
y[i] = 4*x[0+i*5] + x[1+i*5] + 2*x[2+i*5] + 3*x[3+i*5] + 0.2*x[4+i*5] + rand1.Gaus()*e[i];
y[i] = 4*x[0+i*5] + x[1+i*5] + 2*x[2+i*5] + 3*x[3+i*5] + 0.2*x[4+i*5] + randNum.Gaus()*e[i];
}

//To avoid copying the data into the fitter, the following function can be used:
Expand All @@ -61,13 +61,13 @@ void fitLinear2()

//Now suppose you want to add some more points and see if the parameters will change
for (i=n; i<n*2; i++) {
x[0+i*5] = rand1.Uniform(-10, 10);
x[1+i*5] = rand1.Uniform(-10, 10);
x[2+i*5] = rand1.Uniform(-10, 10);
x[3+i*5] = rand1.Uniform(-10, 10);
x[4+i*5] = rand1.Uniform(-10, 10);
x[0+i*5] = randNum.Uniform(-10, 10);
x[1+i*5] = randNum.Uniform(-10, 10);
x[2+i*5] = randNum.Uniform(-10, 10);
x[3+i*5] = randNum.Uniform(-10, 10);
x[4+i*5] = randNum.Uniform(-10, 10);
e[i] = 0.01;
y[i] = 4*x[0+i*5] + x[1+i*5] + 2*x[2+i*5] + 3*x[3+i*5] + 0.2*x[4+i*5] + rand1.Gaus()*e[i];
y[i] = 4*x[0+i*5] + x[1+i*5] + 2*x[2+i*5] + 3*x[3+i*5] + 0.2*x[4+i*5] + randNum.Gaus()*e[i];
}

//Assign the data the same way as before
Expand Down
16 changes: 8 additions & 8 deletions tutorials/fit/fitslicesy.C
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ void fitslicesy() {
TCanvas *c1 = new TCanvas("c1","c1",700,500);
c1->SetFillColor(42);
c1->Divide(2,1);
TPad *left = (TPad*)c1->cd(1);;
left->Divide(1,2);
TPad *leftPad = (TPad*)c1->cd(1);;
leftPad->Divide(1,2);

// Draw 2-d original histogram
left->cd(1);
leftPad->cd(1);
gPad->SetTopMargin(0.12);
gPad->SetFillColor(33);
hpxpy->Draw();
Expand All @@ -51,21 +51,21 @@ void fitslicesy() {
hpxpy->FitSlicesY(0,7,32,20);

// Show fitted "mean" for each slice
left->cd(2);
leftPad->cd(2);
gPad->SetFillColor(33);
TH2F *hpxpy_0 = (TH2F*)hsimpleFile->Get("hpxpy_0");
hpxpy_0->Draw();
TPad *right = (TPad*)c1->cd(2);
right->Divide(1,2);
right->cd(1);
TPad *rightPad = (TPad*)c1->cd(2);
rightPad->Divide(1,2);
rightPad->cd(1);
gPad->SetTopMargin(0.12);
gPad->SetLeftMargin(0.15);
gPad->SetFillColor(33);
TH2F *hpxpy_1 = (TH2F*)hsimpleFile->Get("hpxpy_1");
hpxpy_1->Draw();

// Show fitted "sigma" for each slice
right->cd(2);
rightPad->cd(2);
gPad->SetTopMargin(0.12);
gPad->SetLeftMargin(0.15);
gPad->SetFillColor(33);
Expand Down
20 changes: 10 additions & 10 deletions tutorials/graphs/exclusiongraph.C
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ TCanvas *exclusiongraph() {
mg->SetTitle("Exclusion graphs");

const Int_t n = 35;
Double_t x1[n], x2[n], x3[n], y1[n], y2[n], y3[n];
Double_t xvalues1[n], xvalues2[n], xvalues3[n], yvalues1[n], yvalues2[n], yvalues3[n];
for (Int_t i=0;i<n;i++) {
x1[i] = i*0.1;
x2[i] = x1[i];
x3[i] = x1[i]+.5;
y1[i] = 10*sin(x1[i]);
y2[i] = 10*cos(x1[i]);
y3[i] = 10*sin(x1[i])-2;
xvalues1[i] = i*0.1;
xvalues2[i] = xvalues1[i];
xvalues3[i] = xvalues1[i]+.5;
yvalues1[i] = 10*sin(xvalues1[i]);
yvalues2[i] = 10*cos(xvalues1[i]);
yvalues3[i] = 10*sin(xvalues1[i])-2;
}

TGraph *gr1 = new TGraph(n,x1,y1);
TGraph *gr1 = new TGraph(n,xvalues1,yvalues1);
gr1->SetLineColor(2);
gr1->SetLineWidth(1504);
gr1->SetFillStyle(3005);

TGraph *gr2 = new TGraph(n,x2,y2);
TGraph *gr2 = new TGraph(n,xvalues2,yvalues2);
gr2->SetLineColor(4);
gr2->SetLineWidth(-2002);
gr2->SetFillStyle(3004);
gr2->SetFillColor(9);

TGraph *gr3 = new TGraph(n,x3,y3);
TGraph *gr3 = new TGraph(n,xvalues3,yvalues3);
gr3->SetLineColor(5);
gr3->SetLineWidth(-802);
gr3->SetFillStyle(3002);
Expand Down
12 changes: 6 additions & 6 deletions tutorials/hist/multicolor.C
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/// \ingroup tutorial_hist
/// \notebook
/// Use a THStack to show a 2-D hist with cells with different colors.
/// ~~~ {.cpp}
/// ```cpp
/// root > .x multicolor.C
/// root > .x multicolor.C(1)
/// ~~~
/// ```
/// \macro_image
/// \macro_code
///
Expand All @@ -16,7 +16,7 @@
#include "THStack.h"
#include "TRandom.h"

void multicolor(Int_t stack=0) {
void multicolor(Int_t isStack=0) {
TCanvas *c1 = new TCanvas;
Int_t nbins = 20;
TH2F *h1 = new TH2F("h1","h1",nbins,-4,4,nbins,-4,4);
Expand All @@ -38,12 +38,12 @@ void multicolor(Int_t stack=0) {
Int_t bin = h1->GetBin(ix,iy);
Double_t val = h1->GetBinContent(bin);
if (val <= 0) continue;
if (!stack) h1->SetBinContent(bin,0);
if (!isStack) h1->SetBinContent(bin,0);
if (r.Rndm() > 0.5) {
if (!stack) h2->SetBinContent(bin,0);
if (!isStack) h2->SetBinContent(bin,0);
h3->SetBinContent(bin,val);
} else {
if (!stack) h3->SetBinContent(bin,0);
if (!isStack) h3->SetBinContent(bin,0);
h2->SetBinContent(bin,val);
}
}
Expand Down
20 changes: 10 additions & 10 deletions tutorials/hist/th2polyBoxes.C
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ TCanvas *th2polyBoxes() {
Int_t i,j;
Int_t nx = 40;
Int_t ny = 40;
Double_t x1,y1,x2,y2;
Double_t xval1,yval1,xval2,yval2;
Double_t dx=0.2, dy=0.1;
x1 = 0.;
x2 = dx;
xval1 = 0.;
xval2 = dx;

for (i = 0; i<nx; i++) {
y1 = 0.;
y2 = dy;
yval1 = 0.;
yval2 = dy;
for (j = 0; j<ny; j++) {
h2p->AddBin(x1, y1, x2, y2);
y1 = y2;
y2 = y2+y2*dy;
h2p->AddBin(xval1, yval1, xval2, yval2);
yval1 = yval2;
yval2 = yval2+yval2*dy;
}
x1 = x2;
x2 = x2+x2*dx;
xval1 = xval2;
xval2 = xval2+xval2*dx;
}

TRandom ran;
Expand Down
4 changes: 2 additions & 2 deletions tutorials/io/loopdir.C
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

void loopdir() {
TFile *f1 = TFile::Open("hsimple.root");
TIter next(f1->GetListOfKeys());
TIter keyList(f1->GetListOfKeys());
TKey *key;
TCanvas c1;
c1.Print("hsimple.ps[");
while ((key = (TKey*)next())) {
while ((key = (TKey*)keyList())) {
TClass *cl = gROOT->GetClass(key->GetClassName());
if (!cl->InheritsFrom("TH1")) continue;
TH1 *h = (TH1*)key->ReadObj();
Expand Down
8 changes: 4 additions & 4 deletions tutorials/math/goftest.C
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ void goftest() {

// a) User input PDF
ROOT::Math::Functor1D f(&landau);
double min = 3*TMath::MinElement(nEvents3, sample3);
double max = 3*TMath::MaxElement(nEvents3, sample3);
ROOT::Math::GoFTest* goftest_3a = new ROOT::Math::GoFTest(nEvents3, sample3, f, ROOT::Math::GoFTest::kPDF, min,max); // need to specify am interval
double minimum = 3*TMath::MinElement(nEvents3, sample3);
double maximum = 3*TMath::MaxElement(nEvents3, sample3);
ROOT::Math::GoFTest* goftest_3a = new ROOT::Math::GoFTest(nEvents3, sample3, f, ROOT::Math::GoFTest::kPDF, minimum,maximum); // need to specify am interval
// b) User input CDF
ROOT::Math::Functor1D fI(&TMath::LandauI);
ROOT::Math::GoFTest* goftest_3b = new ROOT::Math::GoFTest(nEvents3, sample3, fI, ROOT::Math::GoFTest::kCDF,min,max);
ROOT::Math::GoFTest* goftest_3b = new ROOT::Math::GoFTest(nEvents3, sample3, fI, ROOT::Math::GoFTest::kCDF,minimum,maximum);


// Returning the p-value for the Anderson-Darling test statistic
Expand Down
Loading