File indexing completed on 2024-04-06 12:33:45
0001 #include <iostream.h>
0002
0003 class HistoCompare {
0004
0005 public:
0006
0007 HistoCompare() { std::cout << "Initializing HistoCompare... " << std::endl; } ;
0008
0009 Double_t KSCompute(TH1 * oldHisto , TH1 * newHisto , TText * te );
0010 Int_t KSok(TH1 * oldHisto , TH1 * newHisto);
0011 void KSdraw(TH1 * oldHisto , TH1 * newHisto);
0012
0013 private:
0014
0015 Double_t ks;
0016
0017 TH1 * myoldHisto1;
0018 TH1 * mynewHisto1;
0019
0020
0021 TText * myte;
0022
0023 };
0024
0025 Int_t HistoCompare::KSok(TH1 * oldHisto , TH1 * newHisto)
0026 {
0027 myoldHisto1 = oldHisto;
0028 mynewHisto1 = newHisto;
0029 int n_test, n_ref;
0030 int s_test, s_ref;
0031 n_test = mynewHisto1->GetEntries();
0032 n_ref = myoldHisto1->GetEntries();
0033 s_test = mynewHisto1->Integral();
0034 s_ref = myoldHisto1->Integral();
0035
0036 int flag = 1;
0037 if (n_test == 0 || n_ref == 0) flag = 0;
0038 if (n_test == 0 && n_ref == 0) {
0039 cout << "[OVAL]: Reference and test histograms are empty for "
0040 << myoldHisto1->GetName()<< endl;
0041 flag = 0;
0042 }
0043 if (s_test < 0.00000001 && s_ref < 0.00000001) {
0044 cout << "[OVAL]: Reference and test histograms have zero integral for "
0045 << myoldHisto1->GetName()<< endl;
0046 flag = 0;
0047 }
0048 if ((n_test != 0 && n_ref == 0) || (n_test == 0 && n_ref != 0)) {
0049 cout << "[OVAL]: # of hits in test histogram " << myoldHisto1->GetName() << " " <<
0050 n_test << " # of hits in reference histogram " << n_ref << endl;
0051 flag = 0;
0052 }
0053 if ((s_test > 0.00000001 && s_ref < 0.00000001) ||
0054 (s_test < 0.00000001 && s_ref > 0.00000001)) {
0055 cout << "[OVAL]: integral of test histogram "<< myoldHisto1->GetName() << " " <<
0056 s_test << " integral of reference histogram " << s_ref << endl;
0057 flag = 0;
0058 }
0059
0060 return flag;
0061 }
0062
0063
0064 Double_t HistoCompare::KSCompute(TH1 * oldHisto , TH1 * newHisto , TText * te )
0065 {
0066 myoldHisto1 = oldHisto;
0067 mynewHisto1 = newHisto;
0068 myte = te;
0069 mynewHisto1->Sumw2();
0070 myoldHisto1->Sumw2();
0071 Double_t ks = mynewHisto1->KolmogorovTest(myoldHisto1);
0072 return ks;
0073
0074 }
0075
0076 void HistoCompare::KSdraw(TH1 * oldHisto , TH1 * newHisto)
0077 {
0078 float max;
0079 myoldHisto1 = oldHisto;
0080 mynewHisto1 = newHisto;
0081 myoldHisto1->Rebin(100);
0082 mynewHisto1->Rebin(100);
0083 float max_r = myoldHisto1->GetMaximum();
0084 float max_t = mynewHisto1->GetMaximum();
0085 if (max_r>max_t) max = 1.1*max_r;
0086 else max = 1.1*max_t;
0087 myoldHisto1->SetMaximum(max);
0088 myoldHisto1->SetLineColor(2);
0089 myoldHisto1->SetLineStyle(1);
0090 mynewHisto1->SetLineColor(4);
0091 mynewHisto1->SetLineStyle(2);
0092
0093 return;
0094 }
0095
0096