File indexing completed on 2025-01-18 09:12:11
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "TFile.h"
0010 #include "TH1F.h"
0011 #include "TROOT.h"
0012 #include "TTree.h"
0013
0014
0015
0016
0017
0018 void
0019 compareHistograms(std::string inFile1,
0020 std::string hist1Name,
0021 int col1,
0022 std::string inFile2,
0023 std::string hist2Name,
0024 int col2,
0025 std::string inFile3 = "",
0026 std::string hist3Name = "",
0027 int col3 = 0)
0028 {
0029 std::cout << "Opening file: " << inFile1 << std::endl;
0030 TFile inputFile1(inFile1.c_str());
0031 std::cout << "Opening file: " << inFile2 << std::endl;
0032 TFile inputFile2(inFile2.c_str());
0033 std::cout << "Comparing Histograms: " << hist1Name << " & " << hist2Name
0034 << std::endl;
0035
0036 TH1F* h1 = (TH1F*)inputFile1.Get(hist1Name.c_str());
0037 TH1F* h2 = (TH1F*)inputFile2.Get(hist2Name.c_str());
0038 std::cout << "col1: " << col1 << ", col2: " << col2 << std::endl;
0039
0040 h1->SetMarkerColor(col1);
0041 h1->SetLineColor(col1);
0042 h1->SetMarkerStyle(3);
0043 h1->Draw("");
0044 h2->SetMarkerColor(col2);
0045 h2->SetLineColor(col2);
0046 h2->Draw("same");
0047 TLegend* leg = new TLegend(0.72, 0.696, 0.99, 0.936);
0048 leg->AddEntry(h1, hist1Name.c_str());
0049 leg->AddEntry(h2, hist2Name.c_str());
0050
0051 if (!inFile3.empty()) {
0052 TFile inputFile3(inFile3.c_str());
0053 TH1F* h3 = (TH1F*)inputFile3.Get(hist3Name.c_str());
0054 std::cout << " & " << hist3Name << std::endl;
0055 std::cout << "from file: " << inFile3 << std::endl;
0056 h3->SetMarkerColor(col3);
0057 h3->SetLineColor(col3);
0058 h3->Draw("same");
0059 h3->SetDirectory(0);
0060 leg->AddEntry(h3, hist3Name.c_str());
0061 inputFile3.Close();
0062 }
0063
0064 leg->Draw();
0065
0066 h1->SetDirectory(0);
0067 h2->SetDirectory(0);
0068
0069 inputFile1.Close();
0070 inputFile2.Close();
0071 }