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