forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcompareDistributions.C
More file actions
51 lines (43 loc) · 1.55 KB
/
compareDistributions.C
File metadata and controls
51 lines (43 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// This file is part of the ACTS project.
//
// Copyright (C) 2016 CERN for the benefit of the ACTS project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
#include "TFile.h"
#include "TH1F.h"
#include "TROOT.h"
#include "TTree.h"
/// This root script reads in two histograms with the names 'hist1Name' and
/// 'hist2Name' from the root file 'inFile' and draws them normalized with
/// different colors in one Canvas
void
compareDistributions(std::string inFile1,
std::string hist1Name,
int col1,
std::string inFile2,
std::string hist2Name,
int col2)
{
std::cout << "Opening file: " << inFile1 << std::endl;
TFile inputFile1(inFile1.c_str());
std::cout << "Opening file: " << inFile2 << std::endl;
TFile inputFile2(inFile2.c_str());
std::cout << "Comparing Histograms: " << hist1Name << " & " << hist2Name
<< std::endl;
TH1F* h1 = (TH1F*)inputFile1.Get(hist1Name.c_str());
TH1F* h2 = (TH1F*)inputFile2.Get(hist2Name.c_str());
h1->SetLineColor(col1);
h1->DrawNormalized();
h2->SetLineColor(col2);
h2->DrawNormalized("same");
TLegend* leg = new TLegend(0.72, 0.71, 0.99, 0.95);
leg->AddEntry(h1, hist1Name.c_str());
leg->AddEntry(h2, hist2Name.c_str());
leg->Draw();
h1->SetDirectory(0);
h2->SetDirectory(0);
inputFile1.Close();
inputFile2.Close();
}