28 std::string hist1Name,
29 std::string legendName1,
31 std::string hist2Name,
32 std::string legendName2,
33 std::string dirName1 =
"",
34 std::string dirName2 =
"")
36 std::cout <<
"Opening file: " << inFile1 << std::endl;
37 TFile inputFile1(inFile1.c_str());
38 std::cout <<
"Opening file: " << inFile2 << std::endl;
39 TFile inputFile2(inFile2.c_str());
40 std::cout <<
"Comparing Histograms: " << hist1Name <<
" & " << hist2Name
46 if (!dirName1.empty() && !dirName2.empty()) {
47 TDirectory* dir1 = inputFile1.GetDirectory(dirName1.c_str());
48 TDirectory* dir2 = inputFile2.GetDirectory(dirName2.c_str());
49 h1 = (TH1F*)dir1->Get(hist1Name.c_str());
50 h2 = (TH1F*)dir2->Get(hist2Name.c_str());
52 h1 = (TH1F*)inputFile1.Get(hist1Name.c_str());
53 h2 = (TH1F*)inputFile2.Get(hist2Name.c_str());
59 int bins = h1->GetXaxis()->GetNbins();
60 float min = h1->GetXaxis()->GetXmin();
61 float max = h1->GetXaxis()->GetXmax();
62 std::cout <<
"creating new histogram with min: " << min <<
", max: " << max
63 <<
", nBins: " << bins << std::endl;
64 TH1F* error =
new TH1F(
"error",
"relative error", bins, min, max);
66 if (!(bins == h2->GetXaxis()->GetNbins())) {
67 std::cout <<
"Number of bins of the two histograms not equal : return"
71 for (
int i = 0; i <
bins; i++) {
72 error->Fill(h1->GetBinCenter(i),
73 (h1->GetBinContent(i) - h2->GetBinContent(i)));
75 TCanvas*
c1 =
new TCanvas();
76 gStyle->SetOptStat(0);
79 h1->SetMarkerColor(1);
82 h2->SetMarkerColor(2);
85 TLegend*
leg =
new TLegend(0.72, 0.696, 0.99, 0.936);
86 leg->AddEntry(h1, legendName1.c_str());
87 leg->AddEntry(h2, legendName2.c_str());
94 error->SetDirectory(0);
101 std::string hist1Name,
102 std::string legendName1,
104 std::string hist2Name,
105 std::string legendName2,
106 std::string dirName1 =
"",
107 std::string dirName2 =
"")
109 std::cout <<
"Opening file: " << inFile1 << std::endl;
110 TFile inputFile1(inFile1.c_str());
111 std::cout <<
"Opening file: " << inFile2 << std::endl;
112 TFile inputFile2(inFile2.c_str());
113 std::cout <<
"Comparing Histograms: " << hist1Name <<
" & " << hist2Name
119 if (!dirName1.empty() && !dirName2.empty()) {
120 TDirectory* dir1 = inputFile1.GetDirectory(dirName1.c_str());
121 TDirectory* dir2 = inputFile2.GetDirectory(dirName2.c_str());
122 h1 = (TH2F*)dir1->Get(hist1Name.c_str());
123 h2 = (TH2F*)dir2->Get(hist2Name.c_str());
125 h1 = (TH2F*)inputFile1.Get(hist1Name.c_str());
126 h2 = (TH2F*)inputFile2.Get(hist2Name.c_str());
131 int bins1 = h1->GetXaxis()->GetNbins();
132 int bins2 = h1->GetYaxis()->GetNbins();
133 float min1 = h1->GetXaxis()->GetXmin();
134 float max1 = h1->GetXaxis()->GetXmax();
135 float min2 = h1->GetYaxis()->GetXmin();
136 float max2 = h1->GetYaxis()->GetXmax();
137 std::cout <<
"creating new histogram with min1: " << min1
138 <<
", max1: " << max1 <<
", nBins1: " << bins1 <<
", min2: " << min2
139 <<
", max2: " << max2 <<
", nBins2: " << bins2 << std::endl;
141 std::string
title =
"relative error";
142 if (hist1Name == hist2Name)
143 title +=
" of " + hist1Name +
" in " + legendName1 +
" and " + legendName2;
145 title +=
" of " + hist1Name +
" in " + legendName1 +
" and " + hist1Name
148 =
new TH2F(
"error", title.c_str(), bins1, min1, max1, bins2, min2, max2);
150 if (!(bins1 == h2->GetXaxis()->GetNbins())
151 && !(bins2 == h2->GetYaxis()->GetNbins())) {
152 std::cout <<
"Number of bins of the two histograms not equal : return"
156 for (
int i = 0; i < bins1; i++) {
157 for (
int j = 0; j < bins2; j++) {
158 error->Fill(h1->GetXaxis()->GetBinCenter(i),
159 h1->GetYaxis()->GetBinCenter(j),
160 (h1->GetBinContent(i, j) - h2->GetBinContent(i, j)));
163 TCanvas*
c1 =
new TCanvas();
164 gStyle->SetOptStat(0);
168 error->SetDirectory(0);