#include #include "TH1F.h" #include "TF1.h" #include "TNtuple.h" #include "TCanvas.h" void draw_test() { // #ifndef _GLIBCXX_VECTOR // #include // #endif const int nbins = 50; double loXbin = 1; double hiXbin = 10000; double binwidth = (log10(hiXbin) - log10(loXbin))/nbins; double XbinEdges[nbins + 1]; // XbinEdges[0] = xmin; for (int i = 0; i <= nbins; ++i) { XbinEdges[i] = pow( 10, log10(loXbin) + i*binwidth); } std::vector h_all_datasets; TF1* bw1 = new TF1("bw1", "TMath::BreitWigner(x,400,20)", 0, 5000); TF1* bw2 = new TF1("bw2", "TMath::BreitWigner(x,700,150)", 0, 5000); TNtuple* funnyTree = new TNtuple("funnyTree", "Just 2 variables", "var1:var2"); for (int i = 0; i < 1000000; ++i) { funnyTree->Fill( bw1->GetRandom(), bw2->GetRandom()); } TH1F* test1 = new TH1F( "test1", "log binned 1st fn", nbins, XbinEdges); TCanvas *c1 = new TCanvas( "c1", "Canvas 1", 800, 600); c1->SetLogx(); c1->SetLogy(); funnyTree->Draw( "var1>>test1"); h_all_datasets.push_back((TH1F*)gPad->GetPrimitive("test1")); h_all_datasets[0]->SetNameTitle("oldtest1", "properly binned 1st fn : test1"); h_all_datasets[0]->Print("all"); TH1F* test2 = new TH1F( "test2", "log binned 2nd fn", nbins, XbinEdges); TCanvas *c2 = new TCanvas( "c2", "Canvas 2", 800, 600); c2->SetLogx(); c2->SetLogy(); // funnyTree->Draw( "var2>>test2"); // This respects the variable binning // h_all_datasets.push_back((TH1F*)gPad->GetPrimitive("test2")); funnyTree->Draw( "var2>>test1"); // This doesn't h_all_datasets.push_back((TH1F*)gPad->GetPrimitive("test1")); h_all_datasets[1]->SetNameTitle("newtest1", "improperly binned 2nd fn : reused test1"); h_all_datasets[1]->Print("all"); }