271 std::cout << std::endl <<
"Getting covs..." << std::endl;
274 unsigned num_bins = 0;
276 num_bins += sample.fCentralValue->GetNbinsX();
280 std::string covariance_name =
"Covariance " +
std::to_string(variation);
281 std::string fractional_covariance_name =
"Fractional Covariance " +
std::to_string(variation);
283 cov.emplace_back(covariance_name.c_str(), covariance_name.c_str(), num_bins, 0, num_bins, num_bins, 0, num_bins);
284 fcov.emplace_back(fractional_covariance_name.c_str(), fractional_covariance_name.c_str(), num_bins, 0, num_bins, num_bins, 0, num_bins);
290 for (
auto const &sample_i: fEventSamples) {
291 for (
unsigned sample_i_bin_index = 0; sample_i_bin_index < sample_i.fCentralValue->GetNbinsX(); sample_i_bin_index++) {
293 float i_central = sample_i.fCentralValue->GetBinContent(sample_i_bin_index+1);
294 for (
auto const &sample_j: fEventSamples) {
295 for (
unsigned sample_j_bin_index = 0; sample_j_bin_index < sample_j.fCentralValue->GetNbinsX(); sample_j_bin_index++) {
297 float j_central = sample_j.fCentralValue->GetBinContent(sample_j_bin_index+1);
299 float cov_value = 0.;
302 float i_variation = sample_i.fUniverses[variation][u]->GetBinContent(sample_i_bin_index+1);
303 float j_variation = sample_j.fUniverses[variation][u]->GetBinContent(sample_j_bin_index+1);
304 cov_value += (i_central - i_variation) * (j_central - j_variation);
311 if (i_central * j_central < 1
e-6) {
315 fcov_value = cov_value / (i_central * j_central);
319 cov[variation].SetBinContent(cov_i + 1, cov_j + 1, cov_value);
320 fcov[variation].SetBinContent(cov_i + 1, cov_j + 1, fcov_value);
332 std::string correlation_name =
"Correlation " +
std::to_string(variation);
335 corr.emplace_back(correlation_name.c_str(), correlation_name.c_str(), num_bins, 0, num_bins, num_bins, 0, num_bins);
337 for (
int i = 0; i < num_bins; i++) {
338 float covii =
cov[variation].GetBinContent(i+1, i+1);
339 for (
int j = 0; j < num_bins; j++) {
340 float covjj =
cov[variation].GetBinContent(j+1, j+1);
341 float covij =
cov[variation].GetBinContent(i+1, j+1);
345 if (covii*covjj < 1
e-6) {
351 corr[variation].SetBinContent(i+1, j+1, corrij);
356 std::vector <TH2D*> hists = {&
cov[variation], &
fcov[variation], &
corr[variation]};
358 for (
auto const &sample: fEventSamples) {
360 for (TH2D* hist : hists) {
361 hist->GetXaxis()->SetBinLabel(1+bin, sample.fName.c_str());
362 hist->GetYaxis()->SetBinLabel(1+bin, sample.fName.c_str());
365 bin += sample.fBins.size() - 1;
369 for (TH2D* hist : hists) { hist->GetXaxis()->LabelsOption(
"h"); hist->GetYaxis()->LabelsOption(
"v"); }
371 std::cout << std::endl <<
" Got covs." << std::endl;
std::vector< TH2D > cov
Covariance Matrix per variation.
std::vector< TH2D > fcov
Fractional Covariance Matrix per variation.
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
std::vector< TH2D > corr
Correlation Matrix per variation.
Var Sqrt(const Var &v)
Use to take sqrt of a var.
std::string to_string(WindowPattern const &pattern)
std::vector< EventSample > fEventSamples
BEGIN_PROLOG could also be cout