Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:11

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "TFile.h"
0010 #include "TH1F.h"
0011 #include "TROOT.h"
0012 #include "TTree.h"
0013 
0014 /// This root script reads in two histograms with the names 'hist1Name' and
0015 /// 'hist2Name' from the root file 'inFile' and draws them normalized with
0016 /// different colors in one Canvas
0017 
0018 void
0019 compareDistributions(std::string inFile1,
0020                      std::string hist1Name,
0021                      int         col1,
0022                      std::string inFile2,
0023                      std::string hist2Name,
0024                      int         col2)
0025 {
0026   std::cout << "Opening file: " << inFile1 << std::endl;
0027   TFile inputFile1(inFile1.c_str());
0028   std::cout << "Opening file: " << inFile2 << std::endl;
0029   TFile inputFile2(inFile2.c_str());
0030   std::cout << "Comparing Histograms: " << hist1Name << " & " << hist2Name
0031             << std::endl;
0032 
0033   TH1F* h1 = (TH1F*)inputFile1.Get(hist1Name.c_str());
0034   TH1F* h2 = (TH1F*)inputFile2.Get(hist2Name.c_str());
0035 
0036   h1->SetLineColor(col1);
0037   h1->DrawNormalized();
0038   h2->SetLineColor(col2);
0039   h2->DrawNormalized("same");
0040 
0041   TLegend* leg = new TLegend(0.72, 0.71, 0.99, 0.95);
0042   leg->AddEntry(h1, hist1Name.c_str());
0043   leg->AddEntry(h2, hist2Name.c_str());
0044   leg->Draw();
0045 
0046   h1->SetDirectory(0);
0047   h2->SetDirectory(0);
0048 
0049   inputFile1.Close();
0050   inputFile2.Close();
0051 }