Skip to content
Snippets Groups Projects
Commit e2f4f625 authored by Mark Jones's avatar Mark Jones Committed by Mark K Jones
Browse files

Add file onlineGUI/Macros/comp_histos.C

comp_histos.C does a chi-squared comparision between histograms
  in two root files. Need to create the subdirectory Output
  The execution is
  .x Macros/comp_histos.C("oldfile.root","newfile.root")

  Main purpose is for comparing histograms
  after changes to hcana. Histograms which are exactly the same
  have a chi-square = 0 .
  For histograms that fail the chi-square test, a list of
  names in placed in Output/hist_diff_NoMatch_output.txt
  and the histograms are plotted and the plots saved to
   Output/hist_diff_NoMatchoutput.pdf
  For histograms that pass the chi-square test, a list of
  names in placed in Output/hist_diff_Match_output.txt
parent e13f4027
No related branches found
No related tags found
No related merge requests found
......@@ -4,3 +4,6 @@ online
*#
onlineDict.C
.root_history
*.root
*.pdf
#include <iostream>
#include "TFile.h"
#include "TH1D.h"
#include "TKey.h"
using namespace std;
void comp_histos(TString old_file="",TString new_file="") {
if (old_file=="") {
cout << "Enter original version root file name: " << endl;
cin >> old_file;
}
if (new_file=="") {
cout << "Enter new version root file name: " << endl;
cin >> new_file;
}
TFile* f1= new TFile(old_file,"READ");
if (f1->IsZombie()) {
cout << "Cannot find : " << old_file << endl;
return;
}
TFile* f2= new TFile(new_file,"READ");
if (f2->IsZombie()) {
cout << "Cannot find : " << new_file << endl;
return;
}
TIter nextkey1(f1->GetListOfKeys());
TIter nextkey2(f2->GetListOfKeys());
TKey *key1;
TKey *key2;
ofstream Matchoutfile("Output/hist_diff_Match_output.txt");
ofstream NoMatchoutfile("Output/hist_diff_NoMatch_output.txt");
Int_t cnt=0;
Int_t igood;
Double_t test_chi;
Int_t test_ndf;
TCanvas *can = new TCanvas("can"," ",800,800);
while ( (key1= (TKey*)nextkey1()) && (key2= (TKey*)nextkey2())) {
TClass *cl1= gROOT->GetClass(key1->GetClassName());
TClass *cl2= gROOT->GetClass(key2->GetClassName());
if ( cl1->InheritsFrom ("TH1") && cl2->InheritsFrom ("TH1") && !(cl1->InheritsFrom ("TH2") && cl2->InheritsFrom ("TH2"))) {
TH1 *h1 = (TH1*)key1->ReadObj();
TH1 *h2 = (TH1*)key2->ReadObj();
if (h1->Integral()>0 && h2->Integral()>0) {
h1->Chi2TestX(h2,test_chi,test_ndf,igood,"UU");
if (test_chi >0) {
NoMatchoutfile << " histogram " << key1->GetTitle() << " does not match chi2 = " << test_chi<< " " << endl;
can->Clear();
can->Divide(1,1);
can->cd(1);
h1->Draw();
h2->Draw("same");
h2->SetLineColor(2);
cnt++;
if (cnt == 1) can->Print("Output/hist_diff_NoMatchoutput.pdf(");
if (cnt >1) can->Print("Output/hist_diff_NoMatchoutput.pdf");
can->Update();
can->WaitPrimitive();
//can->Clear();
} else {
Matchoutfile << " histogram " << key1->GetTitle() << " matches" << endl;
}
}
}
//
if ( cl1->InheritsFrom ("TH2") && cl2->InheritsFrom ("TH2")) {
TH2 *hh1 = (TH2*)key1->ReadObj();
TH2 *hh2 = (TH2*)key2->ReadObj();
if ( (hh1->Integral()>0 && hh2->Integral()>0)) {
hh1->Chi2TestX(hh2,test_chi,test_ndf,igood,"UU");
if (test_chi >1) {
NoMatchoutfile << "2d histogram " << key1->GetTitle() << " does not match chi2 = " << test_chi<< " " << endl;
can->Clear();
can->Divide(1,2);
can->cd(1);
hh1->Draw("colz");
can->cd(2);
hh2->Draw("colz");
can->Update();
can->WaitPrimitive();
cnt++;
if (cnt == 1) can->Print("Output/hist_diff_NoMatchoutput.pdf(");
if (cnt >1) can->Print("Output/hist_diff_NoMatchoutput.pdf");
//can->Clear();
} else {
Matchoutfile << " histogram " << key1->GetTitle() << " matches" << endl;
}
}
}
//
//
}
//
if (cnt >0) can->Print("Output/hist_diff_NoMatchoutput.pdf)");
can->Close();
if (cnt == 0) NoMatchoutfile << " All histograms matched. Congratulations !" << endl;
if (cnt == 0) cout << " All histograms matched. Congratulations !" << endl;
if (cnt > 0) NoMatchoutfile << " Some histograms did not matched. " << endl;
if (cnt > 0) cout << " Some histograms did not matched. " << endl;
cout << " Histograms with matched output are listed in Output/hist_diff_Match_output.txt" << endl;
cout << " Histograms with unmatched output are listed in Output/hist_diff_NoMatch_output.txt"<< endl;
//
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment