carry out the eigenvector computations.
Exclusion of any source of uncertainty has to be done before calling this method
1567{
1568
1569
1570
1571
1572
1573
1574
1575
1577
1578 TMatrixDSym corr(cov);
1579 for (
int row = 0 ;
row <
cov.GetNrows() ;
row++){
1580 for (
int col = 0 ; col <
cov.GetNcols() ; col++){
1581 double rowvar = sqrt(
cov(row,row));
1582 double colvar = sqrt(
cov(col,col));
1583 corr(row,col) = corr(row,col)/(rowvar * colvar);
1584 }
1585 }
1586
1588
1589
1590
1591
1592 std::vector<double> combined_result;
1593 std::map<std::string, int> flav_bins;
1594
1596
1597
1599
1600 TH1*
result =
dynamic_cast<TH1*
>(
c->GetValue(
"result"));
1601 if (not result){
1602 std::cerr<<"CalibrationDataGlobalEigenVariations::initialize: dynamic cast failed\n ";
1603 continue;
1604 }
1605
1606 if (
c->getTagWeightAxis() == -1){
1607 flav_bins[flavour] =
result->GetNbinsY();
1608 if (
m_verbose) std::cout <<
"flav_bins["<<flavour<<
"] = " << flav_bins[flavour] << std::endl;
1609 for(
int i = 0 ;
i < flav_bins[flavour] ;
i++){
1610
1612 double res_value =
result->GetBinContent(bin);
1613 combined_result.push_back(res_value);
1614 }
1615 }
else if (
c->getTagWeightAxis() == 0) {
1616 flav_bins[flavour] =
result->GetNbinsX()*
result->GetNbinsY();
1617 int tagbins =
result->GetNbinsX();
1618 int ptbins =
result->GetNbinsY();
1619 if (
m_verbose) std::cout <<
"flav_bins["<<flavour<<
"] = " << flav_bins[flavour] << std::endl;
1620 for(
int i = 0 ;
i < tagbins ;
i++){
1621 for(
int j = 0 ;
j < ptbins ;
j++){
1622
1624 double res_value =
result->GetBinContent(bin);
1625 combined_result.push_back(res_value);
1626 }
1627 }
1628 }
else if (
c->getTagWeightAxis() == 1) {
1629 flav_bins[flavour] =
result->GetNbinsX()*
result->GetNbinsY();
1630 int tagbins =
result->GetNbinsY();
1631 int ptbins =
result->GetNbinsX();
1632 if (
m_verbose) std::cout <<
"flav_bins["<<flavour<<
"] = " << flav_bins[flavour] << std::endl;
1633 for(
int i = 0 ;
i < tagbins ;
i++){
1634 for(
int j = 0 ;
j < ptbins ;
j++){
1635
1637 double res_value =
result->GetBinContent(bin);
1638 combined_result.push_back(res_value);
1639 }
1640 }
1641 }
else if (
c->getTagWeightAxis() == 2) {
1642 flav_bins[flavour] =
result->GetNbinsX()*
result->GetNbinsZ();
1643 int tagbins =
result->GetNbinsZ();
1644 int ptbins =
result->GetNbinsX();
1645 if (
m_verbose) std::cout <<
"flav_bins["<<flavour<<
"] = " << flav_bins[flavour] << std::endl;
1646 for(
int i = 0 ;
i < tagbins ;
i++){
1647 for(
int j = 0 ;
j < ptbins ;
j++){
1648
1650 double res_value =
result->GetBinContent(bin);
1651 combined_result.push_back(res_value);
1652 }
1653 }
1654 }
1655
1656
1657
1658
1660 TH1* hunc = (TH1*)
c->GetValue(
it->first.c_str());
1661
1662
1664 TString namedvar("namedVar");
1665 namedvar +=
it->first.c_str();
1666 TString namedvarUp(namedvar); namedvarUp += "_up";
1667 TString namedvarDown(namedvar); namedvarDown += "_down";
1668 TH1* resultVariedUp = (TH1*)
result->Clone(namedvarUp);
1669 TH1* resultVariedDown = (TH1*)
result->Clone(namedvarDown);
1670 if (hunc){
1671 resultVariedUp->Add(hunc, 1.0); resultVariedUp->SetDirectory(0);
1672 resultVariedDown->Add(hunc, -1.0); resultVariedDown->SetDirectory(0);
1673 } else {
1674 resultVariedUp->SetDirectory(0);
1675 resultVariedDown->SetDirectory(0);
1676 }
1677 p.first = resultVariedUp;
1678 p.second = resultVariedDown;
1679 }
1680
1681
1682
1683
1684 if (TH1* hunc = (TH1*)
c->GetValue(
"extrapolation")) {
1685 TH1* resultVariedUp = (TH1*) hunc->Clone("extrapolation_up"); resultVariedUp->SetDirectory(0);
1686 TH1* resultVariedDown = (TH1*) hunc->Clone("extrapolation_down"); resultVariedDown->SetDirectory(0);
1687 Int_t nbinx = hunc->GetNbinsX()+2, nbiny = hunc->GetNbinsY()+2, nbinz = hunc->GetNbinsZ()+2;
1688 Int_t firstbinx = hunc->GetXaxis()->FindFixBin(
result->GetXaxis()->GetBinCenter(1));
1689 Int_t firstbiny =
result->GetDimension() > 1 ? hunc->GetYaxis()->FindFixBin(
result->GetYaxis()->GetBinCenter(1)) : 1;
1690 Int_t firstbinz =
result->GetDimension() > 2 ? hunc->GetZaxis()->FindFixBin(
result->GetZaxis()->GetBinCenter(1)) : 1;
1691 for (Int_t binx = 1; binx < nbinx-1; ++binx) {
1692 Int_t binxResult = binx - firstbinx + 1;
1693 if (binxResult < 1) binxResult = 1;
1694 if (binxResult >
result->GetNbinsX()) binxResult =
result->GetNbinsX();
1695 for (Int_t biny = 1; biny < nbiny-1; ++biny) {
1696 Int_t binyResult = biny - firstbiny + 1;
1697 if (binyResult >
result->GetNbinsY()) binyResult =
result->GetNbinsY();
1698 for (Int_t binz = 1; binz < nbinz-1; ++binz) {
1699 Int_t binzResult = binz - firstbinz + 1;
1700 if (binzResult >
result->GetNbinsZ()) binzResult =
result->GetNbinsZ();
1701 Int_t
bin = hunc->GetBin(binx, biny, binz);
1702 double contResult =
result->GetBinContent(binxResult, binyResult, binzResult);
1703 resultVariedUp->SetBinContent(bin, contResult + hunc->GetBinContent(bin));
1704 resultVariedDown->SetBinContent(bin, contResult - hunc->GetBinError(bin));
1705 }
1706 }
1707 }
1708 m_flav_named[flavour].push_back(std::make_pair(resultVariedUp, resultVariedDown));
1710 }
1711
1712
1713 }
1714
1715
1716
1717
1718
1719 std::unique_ptr<TH1> comb_result(new TH1D("combined_result", "", combined_result.size(), 0., 1.));
1720 int nbins = comb_result->GetNbinsX()+2;
1721 int ndim = comb_result->GetDimension();
1722 if (ndim > 1)
nbins*= (comb_result->GetNbinsY()+2);
1723 if (ndim > 2)
nbins*= (comb_result->GetNbinsZ()+2);
1724
1725
1726 for (
unsigned int i=0 ;
i<combined_result.size() ;
i++){
1727
1728 comb_result->SetBinContent(i+1, combined_result[i]);
1729 }
1730
1731
1733
1734 int size = matrixVariationJacobian.GetNrows();
1735
1736
1737 const TMatrixDSym matrixCovariance =
cov.Similarity(matrixVariationJacobian);
1738
1739
1740 TMatrixDSymEigen eigenValueMaker (matrixCovariance);
1741 TVectorT<double> eigenValues = eigenValueMaker.GetEigenValues();
1742 TMatrixT<double> eigenVectors = eigenValueMaker.GetEigenVectors();
1743 TMatrixT<double> matrixVariations (
size,
size);
1744
1745
1747
1748 for (
int i = 0;
i <
size; ++
i) {
1749 for (
int r = 0;
r <
size; ++
r) {
1750
1751 matrixVariations(i,
r) = -1.0*eigenVectors[
r][
i]*sqrt(fabs(eigenValues[i]));
1752 }
1753 }
1754
1755 TMatrixT<double> matrixVariationsWithZeros = matrixVariations * matrixVariationJacobian;
1756
1757
1758 for (
int i = 0;
i < matrixVariationsWithZeros.GetNrows(); ++
i) {
1759 TString superstring("eigenVar");
1761
1762 TString nameUp(superstring); nameUp += "_up";
1763 TString nameDown(superstring); nameDown += "_down";
1764
1765
1766 TH1* resultVariedUp = (TH1*)comb_result->Clone(nameUp); resultVariedUp->SetDirectory(0);
1767 TH1* resultVariedDown = (TH1*)comb_result->Clone(nameDown); resultVariedDown->SetDirectory(0);
1768
1769 for (
int u = 0;
u < comb_result->GetNbinsX(); ++
u) {
1770 resultVariedUp->SetBinContent(u,(comb_result->GetBinContent(u) + matrixVariationsWithZeros(i,u)));
1771 resultVariedDown->SetBinContent(u,(comb_result->GetBinContent(u) - matrixVariationsWithZeros(i,u)));
1772 }
1773
1774 m_eigen.push_back(std::make_pair(resultVariedUp, resultVariedDown));
1775
1776
1777 }
1778
1779
1781
1783
1784
1785
1786
1787
1789
1790
1792 size_t current_set = 0;
1793
1794
1795 min_variance = 1.0E-6;
1797 bool keep_variation = false;
1798 TH1*
up =
static_cast<TH1*
>(
m_eigen[
index].first->Clone());
up->SetDirectory(0);
1799 up->Add(comb_result.get(), -1.0);
1800
1802 if (fabs(
up->GetBinContent(bin)) > min_variance) {
1803 keep_variation = true;
1804 break;
1805 }
1806 }
1807 if (!keep_variation){
1808 final_set.insert(current_set);
1809 } else {
1811 }
1813 ++current_set;
1814 }
1815 if (final_set.size() > 0){
1816 if (
m_verbose) std::cout <<
"CalibrationDataEigenVariations: Removing " << final_set.size() <<
" eigenvector variations leading to sub-tolerance effects, retaining " <<
m_eigen.size()-final_set.size() <<
" variations" << std::endl;
1817 }
1818
1820
1821
1822
1823
1824 std::streamsize
ss = std::cout.precision();
1826 std::cout.precision(
ss);
1832 }
1833
1834
1836
1837
1838
1839
1840
1841
1843
1844
1845 for(
const std::pair<TH1*,TH1*>& var :
m_eigen){
1846
1847 TString eigenvarup =
var.first->GetName();
1848 TString eigenvardown =
var.second->GetName();
1849 int bin_baseline = 0;
1850 for (
const std::string& flavour :
m_flavours){
1852 TH1*
result =
dynamic_cast<TH1*
>(
c->GetValue(
"result"));
1853 if (not result){
1854 std::cerr<<"CalibrationDataGlobalEigenVariations::initialize: dynamic cast failed\n";
1855 continue;
1856 }
1857 TH1* resultVariedUp = (TH1*)
result->Clone(eigenvarup); resultVariedUp->SetDirectory(0);
1858 TH1* resultVariedDown = (TH1*)
result->Clone(eigenvardown); resultVariedDown->SetDirectory(0);
1859 int up_to_bin = flav_bins[flavour];
1860 int current_bin = 1;
1861 for(int flav_bin = bin_baseline+1 ; flav_bin < up_to_bin+1 ; flav_bin++){
1862 Int_t
bin =
result->GetBin(1,current_bin);
1863 resultVariedUp->SetBinContent(bin,
var.first->GetBinContent(flav_bin));
1864 resultVariedDown->SetBinContent(bin,
var.second->GetBinContent(flav_bin));
1865 current_bin+=1;
1866 }
1867 bin_baseline+=up_to_bin;
1868 m_flav_eigen[flavour].push_back(std::make_pair(resultVariedUp, resultVariedDown));
1869 }
1870 }
1871
1874 }
1875
1877}
void removeVariations(const IndexSet &set)
remove all variations in the given set
double m_capturedvariance
std::set< size_t > IndexSet
TMatrixDSym getEigenCovarianceMatrix()
also provide (some) access to the underlying information: covariance matrix corresponding to eigenvec...
std::map< std::string, int > m_flav_namedExtrapolation