https://github.com/root-project/root
Tip revision: d3e3bcf2ad30bd1271455c59ad0e6aaf854e40e9 authored by Unknown Author on 06 February 2002, 11:51:14 UTC
This commit was manufactured by cvs2svn to create tag 'v3-02-04'.
This commit was manufactured by cvs2svn to create tag 'v3-02-04'.
Tip revision: d3e3bcf
dt_RunDrawTest.C
#include "TCanvas.h"
#include "TClassTable.h"
#include "TFile.h"
#include "TH1.h"
#include "TKey.h"
#include "TChain.h"
#include "TSystem.h"
#include "iostream.h"
#include "dt_DrawTest.C"
Bool_t gInteractiveTest = kTRUE;
Bool_t gQuietLevel = 0;
//_______________________________________________________________
Int_t HistCompare(TH1 *ref, TH1 *comp)
{
// Compare histograms h1 and h2
// Check number of entries, mean and rms
// if means differ by more than 1/1000 of the range return -1
// if rms differs in percent by more than 1/1000 return -2
// Otherwise return difference of number of entries
Int_t n1 = (Int_t)ref->GetEntries();
Double_t mean1 = ref->GetMean();
Double_t rms1 = ref->GetRMS();
Int_t n2 = (Int_t)comp->GetEntries();
Double_t mean2 = comp->GetMean();
Double_t rms2 = comp->GetRMS();
Int_t factor = 1;
if (n2==2*n1) {
// we have a chain.
factor = 2;
}
Float_t xrange = ref->GetXaxis()->GetXmax() - ref->GetXaxis()->GetXmin();
if (TMath::Abs((mean1-mean2)/xrange) > 0.001*xrange) return -1;
if (rms1 && TMath::Abs((rms1-rms2)/rms1) > 0.001) return -2;
return n1*factor-n2;
}
Int_t Compare(TDirectory* from) {
TFile * reffile = new TFile("dt_reference.root");
TIter next(reffile->GetListOfKeys());
TH1 *ref, *draw;
const char* name;
Int_t comp;
Int_t fail = 0;
TKey* key;
while ((key=(TKey*)next())) {
if (strcmp(key->GetClassName(),"TH1F")
&& strcmp(key->GetClassName(),"TH2F") )
continue; //may be a TList of TStreamerInfo
ref = (TH1*)reffile->Get(key->GetName());
name = ref->GetName();
if (strncmp(name,"ref",3)) continue;
name += 3;
draw = (TH1*)from->Get(name);
if (!draw) {
if (!gSkipped.FindObject(name)) {
cerr << "Miss: " << name << endl;
fail++;
}
continue;
}
comp = HistCompare(ref,draw);
if (comp!=0) {
cerr << "Fail: " << name << ":" << comp << endl;
fail++;
if (gInteractiveTest) {
TCanvas * canv = new TCanvas();
canv->Divide(2,1);
canv->cd(1); ref->Draw();
canv->cd(2); draw->Draw();
return 1;
}
} else {
if (gQuietLevel<1) cerr << "Succ: " << name << ":" << comp << endl;
}
}
return fail;
}
void SetVerboseLevel(Int_t verboseLevel) {
switch (verboseLevel) {
case 0: gInteractiveTest = kFALSE;
gQuietLevel = 2;
break;
case 1: gInteractiveTest = kFALSE;
gQuietLevel = 1;
break;
case 2: gInteractiveTest = kFALSE;
gQuietLevel = 0;
break;
case 3: gInteractiveTest = kTRUE;
gQuietLevel = 0;
break;
}
}
void dt_RunDrawTest(const char* from, Int_t mode = 0, Int_t verboseLevel = 0) {
// This launch a test a TTree::Draw.
// The mode currently available are:
// 0: Do not load the shared library
// 1: Load the shared library before opening the file
// 2: Load the shared library after opening the file
// 3: Simple TChain test with shared library
// 4: Simple Friend test with shared library
// The verboseLeve currently available:
// 0: As silent as possible, only report errors and overall speed results.
// 1: Output 0 + label for the start of each phase
// 2: Output 1 + more details on the different phase being done
// 3: Output 2 + stop at the first and draw a canvas showing the differences
SetVerboseLevel(verboseLevel);
if (mode == 1) {
if (!TClassTable::GetDict("Event")) {
gSystem->Load("libEvent");
}
gHasLibrary = kTRUE;
}
TFile *hfile = 0;
TTree *tree = 0;
if (mode <3) {
hfile = new TFile(from);
tree = (TTree*)hfile->Get("T");
}
if (mode >= 2 && mode <= 4) {
if (!TClassTable::GetDict("Event")) {
gSystem->Load("libEvent");
} else {
cerr << "Since libEvent.so has already been loaded, mode 2 can not be tested!";
cerr << endl;
}
gHasLibrary = kTRUE;
}
if (mode == 3) {
// Test Chains.
TChain * chain = new TChain("T");
chain->Add(from);
chain->Add(from);
tree = chain;
}
if (mode == 4) {
// Test friends.
tree = new TTree("T","Base of friendship");
tree->AddFriend("T",from);
}
if (gQuietLevel<2) cout << "Generating histograms from TTree::Draw" << endl;
TDirectory* where = GenerateDrawHist(tree);
if (gQuietLevel<2) cout << "Comparing histograms" << endl;
if (Compare(where)>0) {
cout << "DrawTest: Comparison failed" << endl;
return;
}
DrawMarks();
cout << "DrawTest: Comparison was successfull" << endl;
if (hfile) delete hfile;
else delete tree;
gROOT->GetList()->Delete();
}