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