Skip to content
This repository has been archived by the owner on Jun 4, 2021. It is now read-only.

Commit

Permalink
added k->tau
Browse files Browse the repository at this point in the history
  • Loading branch information
kreczko committed Mar 5, 2015
1 parent a08d3bb commit 35f41bd
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 43 deletions.
4 changes: 2 additions & 2 deletions ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ echo "Checking PyROOT installation"
time python -c 'import ROOT; ROOT.TBrowser()'

# Check that RooUnfold can be imported
echo "Checking RooUnfold library"
echo "Checking RooUnfold library in PyROOT"
time python -c 'from ROOT import gSystem; gSystem.Load("libRooUnfold.so");from ROOT import RooUnfoldResponse'

time python test/test_pyroot.py
echo "Executing unit tests"
make test
5 changes: 3 additions & 2 deletions include/TauSVDUnfold.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ class TauSVDUnfold: public TSVDUnfold_local {
*/
static TH2D* get_data_covariance_matrix(const TH1D* data_histogram);

static double get_global_correlation(const TH1D* data_histogram);
static double get_global_correlation(const TH2D* stat_cov_hist, const TH1D* data_histogram);

static TH1D* get_global_correlation_hist(const TH1D* data_histogram);
static TH1D* get_global_correlation_hist(const TH2D* covariance_hist, const TH1D* data_histogram);

TVectorD getASV() const;
protected:
double fTau;
double fCurv;
Expand Down
46 changes: 30 additions & 16 deletions src/TauSVDUnfold.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,11 @@ TH1D* TauSVDUnfold::Unfold(double tau) {
TDecompSVD ASVD(mA * mCinv);
TMatrixD Uort = ASVD.GetU();
TMatrixD Vort = ASVD.GetV();
// TODO: This part is failing for tau unfolding
// A = fU fSig fV^T
TVectorD ASV = ASVD.GetSig();
// fASV = TVectorD(ASV);
fASV.Clear();
fASV.ResizeTo(ASV.GetNoElements());
fASV = ASV;
if (!fToyMode && !fMatToyMode) {
V2H(ASV, *fSVHist);
}
Expand Down Expand Up @@ -242,7 +244,7 @@ TH1D* TauSVDUnfold::Unfold(double tau) {

double TauSVDUnfold::kToTau(int kreg) const {
double tau(0.);
if (fASV.NonZeros() == 0 && kreg > 0)
if (fASV.NonZeros() > 0 && kreg > 0)
tau = fASV(kreg);
return tau;
}
Expand Down Expand Up @@ -271,18 +273,16 @@ TH2D* TauSVDUnfold::get_data_covariance_matrix(const TH1D* data_histogram) {
return data_covariance_matrix;
}

TH1D* TauSVDUnfold::get_global_correlation_hist(const TH1D* data_histogram) {
TH2D* covariance_hist = (TH2D*) TauSVDUnfold::get_data_covariance_matrix(data_histogram);

unsigned int n_bins = data_histogram->GetNbinsX();
TH1D* TauSVDUnfold::get_global_correlation_hist(const TH2D* covariance_hist, const TH1D* data_histogram) {
uint32_t n_bins = data_histogram->GetNbinsX();
vector<int> bin_map;
bin_map.resize(n_bins);

unsigned int number_of_bins_to_skip(0);
unsigned int bin_counter(0);

// all bins except underflow (0) and overflow (nbins + 1)
for (auto i = 1; i <= n_bins; ++i) {
for (uint32_t i = 1; i <= n_bins; ++i) {
double data = data_histogram->GetBinContent(i);
if (data <= 0.) {
// Through out bin with no data
Expand All @@ -291,7 +291,7 @@ TH1D* TauSVDUnfold::get_global_correlation_hist(const TH1D* data_histogram) {
} else {
// Search for bins with empty rows/columns
bool skip_bin = true;
for (auto j = 1; j <= n_bins; ++j) {
for (uint32_t j = 1; j <= n_bins; ++j) {
double value = covariance_hist->GetBinContent(i, j);
if (value != 0.) {
skip_bin = false;
Expand Down Expand Up @@ -383,10 +383,6 @@ TH1D* TauSVDUnfold::get_global_correlation_hist(const TH1D* data_histogram) {
if (cov_prod > 0)
var = 1. / cov_prod;
double global_correlation_squared = 0.;
// cout << "cov: " << cov << endl;
// cout << "covinv: " << covinv << endl;
// cout << "cov_prod: " << cov_prod << endl;
// cout << "var: " << var << endl;
if (var > 0.)
global_correlation_squared = 1. - var;

Expand All @@ -403,13 +399,13 @@ TH1D* TauSVDUnfold::get_global_correlation_hist(const TH1D* data_histogram) {
global_correlation_hist->SetBinContent(i, global_correlation);
global_correlation_hist->SetBinError(i, 0.);
}
delete covariance_hist;

return global_correlation_hist;
}

double TauSVDUnfold::get_global_correlation(const TH1D* data_histogram) {
TH1D * global_correlation_hist = TauSVDUnfold::get_global_correlation_hist(data_histogram);
double TauSVDUnfold::get_global_correlation(const TH2D* covariance_hist, const TH1D* data_histogram) {

TH1D * global_correlation_hist = TauSVDUnfold::get_global_correlation_hist(covariance_hist, data_histogram);

double sum = 0.;
double average = 0.;
Expand Down Expand Up @@ -623,3 +619,21 @@ TH2D* TauSVDUnfold::GetAdetCovMatrix(Int_t ntoys, Int_t seed = 1) {

return unfcov;
}

double TauSVDUnfold::GetLcurveX() const {
return 0;
}

double TauSVDUnfold::GetLcurveY() const {
return 0;
}

TGraph* TauSVDUnfold::ScanLCurve(unsigned int n_point, double tau_min, double tau_max){
return 0;
}

TVectorD TauSVDUnfold::getASV() const {
return fASV;
}


13 changes: 6 additions & 7 deletions test/TestTVectorD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@
#include <iostream>
#include "TVectorD.h"
#include <exception>

#define N 3
using namespace std;

BOOST_AUTO_TEST_SUITE (TVectorDTestSuite)
BOOST_AUTO_TEST_CASE(test_assign) {
uint32_t n(3);
double elements[n] = { 1., 2., 3. };
TVectorD vector = TVectorD(n, elements);
BOOST_CHECK_EQUAL(vector.GetNoElements(), n);
double elements[N] = { 1., 2., 3. };
TVectorD vector = TVectorD(N, elements);
BOOST_CHECK_EQUAL(vector.GetNoElements(), N);

// initialise vector with default constructor
TVectorD copy = TVectorD();
copy.Clear();
// does not work without resize
copy.ResizeTo(n);
copy.ResizeTo(N);
// this returns "vectors not compatible" without copy.ResizeTo(n);
copy = vector;
BOOST_CHECK_EQUAL(copy.GetNoElements(), n);
BOOST_CHECK_EQUAL(copy.GetNoElements(), N);
BOOST_CHECK_EQUAL(copy[0], 1.);
BOOST_CHECK_EQUAL(copy[1], 2.);
BOOST_CHECK_EQUAL(copy[2], 3.);
Expand Down
58 changes: 42 additions & 16 deletions test/TestTauSVDUnfold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "../include/RooUnfoldSvd.h"
#include "../include/RooUnfoldResponse.h"
#include <iostream>
#include "TROOT.h"

using namespace std;

Expand All @@ -23,12 +22,10 @@ struct TauSVDUnfoldSetup {
gen_var(new TH1D("gen_var", "gen_var", nbins, 0, nbins)),
reco_var(new TH1D("reco_var", "reco_var", nbins, 0, nbins)),
gen_vs_reco(new TH2D("gen_vs_reco", "gen_vs_reco", nbins, 0, nbins, nbins, 0, nbins)),
cov_hist(),
roo_response(),
roounfold_svd_k(),
roounfold_svd_tau(){
gROOT->SetBatch(1);
// gROOT->ProcessLine("gErrorIgnoreLevel = 1001;");
gROOT->ProcessLine("gErrorAbortLevel = 1001;");
roounfold_svd_tau() {
// from toy MC 1
data->SetBinContent(1, 365);
data->SetBinContent(2, 578);
Expand All @@ -45,7 +42,7 @@ struct TauSVDUnfoldSetup {
reco_var->SetBinContent(4, 195);
reco_var->SetBinContent(5, 61);
reco_var->SetBinContent(6, 29);
set_sqrt_N_error (reco_var);
set_sqrt_N_error(reco_var);

gen_var->SetBinContent(1, 3441);
gen_var->SetBinContent(2, 5181);
Expand Down Expand Up @@ -88,15 +85,18 @@ struct TauSVDUnfoldSetup {
roounfold_svd_k = new RooUnfoldSvd(roo_response, data, kreg, n_toy);
roounfold_svd_tau = new RooUnfoldSvd(roo_response, data, taureg, n_toy);

roounfold_svd_tau->Hreco(RooUnfold::kNoError);
TH2D* cov = TauSVDUnfold::get_data_covariance_matrix(data);
cov_hist = roounfold_svd_tau->Impl()->GetUnfoldCovMatrix(cov, n_toy);
delete cov;
}
~TauSVDUnfoldSetup() {
delete data;
delete gen_var;
delete reco_var;
delete gen_vs_reco;
delete cov_hist;
delete roo_response;
// delete tau_svd_unfold;
delete roounfold_svd_k;
delete roounfold_svd_tau;
}

Expand All @@ -114,14 +114,14 @@ struct TauSVDUnfoldSetup {
}
}

unsigned int nbins;
uint32_t nbins;
unsigned int n_toy;
int kreg;
double taureg;
TH1D* data, *gen_var, *reco_var;
TH2D* gen_vs_reco;
TH2D* cov_hist;
RooUnfoldResponse* roo_response;
// TauSVDUnfold* tau_svd_unfold;
RooUnfoldSvd* roounfold_svd_k;
RooUnfoldSvd* roounfold_svd_tau;

Expand All @@ -130,24 +130,50 @@ struct TauSVDUnfoldSetup {
BOOST_AUTO_TEST_SUITE (TauSVDUnfoldTestSuite)
BOOST_FIXTURE_TEST_CASE(test_get_data_covariance_matrix, TauSVDUnfoldSetup) {
TH2D* cov = TauSVDUnfold::get_data_covariance_matrix(data);
for (auto i = 1; i <= nbins; ++i) {
for (uint32_t i = 1; i <= nbins; ++i) {
double data_error = data->GetBinError(i);
BOOST_CHECK_EQUAL(cov->GetBinContent(i, i), data_error * data_error);
}
delete cov;
}

BOOST_FIXTURE_TEST_CASE(test_get_global_correlation, TauSVDUnfoldSetup) {
double corr = TauSVDUnfold::get_global_correlation(data);
BOOST_CHECK_EQUAL(corr, -1.);
double corr = TauSVDUnfold::get_global_correlation(cov_hist, data);
BOOST_CHECK_CLOSE(corr, 99, 1);
}

BOOST_FIXTURE_TEST_CASE(test_get_global_correlation_hist, TauSVDUnfoldSetup) {
TH1D* corr_hist = TauSVDUnfold::get_global_correlation_hist(data);
for (auto i = 1; i <= nbins; ++i) {
BOOST_CHECK_EQUAL(corr_hist->GetBinContent(i), i * i);
TH1D* corr_hist = TauSVDUnfold::get_global_correlation_hist(cov_hist, data);
// for the above example, the first bin should be around 95 %
BOOST_CHECK_CLOSE(corr_hist->GetBinContent(1), 95, 1);
// for all others it should be between 99 and 100 %
for (uint32_t i = 2; i <= nbins; ++i) {
BOOST_CHECK_CLOSE(corr_hist->GetBinContent(i), 99, 1);
}
delete corr_hist;
}

BOOST_FIXTURE_TEST_CASE(test_k_to_tau, TauSVDUnfoldSetup) {
const TauSVDUnfold* tau_svd = (TauSVDUnfold*) roounfold_svd_tau->Impl();
double tau = tau_svd->GetTau();
BOOST_CHECK_EQUAL(tau, taureg);
TVectorD ASV = tau_svd->getASV();
uint32_t n_elements = ASV.GetNoElements();
BOOST_CHECK_EQUAL(n_elements, nbins + 1);
tau = tau_svd->kToTau(kreg);
BOOST_CHECK_CLOSE(tau, 3.83, 0.1);
}

BOOST_FIXTURE_TEST_CASE(test_get_tau, TauSVDUnfoldSetup) {
double tau = ((TauSVDUnfold*) roounfold_svd_tau->Impl())->GetTau();
BOOST_CHECK_EQUAL(tau, taureg);
}

BOOST_FIXTURE_TEST_CASE(test_get_ASV, TauSVDUnfoldSetup) {
const TauSVDUnfold* tau_svd = (TauSVDUnfold*) roounfold_svd_tau->Impl();
TVectorD ASV = tau_svd->getASV();
uint32_t n_elements = ASV.GetNoElements();
BOOST_CHECK_EQUAL(n_elements, nbins + 1);
BOOST_CHECK(ASV.NonZeros() > 0);
}
BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 35f41bd

Please sign in to comment.