#include "TROOT.h" #include "TMath.h" #include "TRandom.h" #include "TGraph.h" #include "TF2.h" #include "TCanvas.h" #include "TCutG.h" #include "Math/Minimizer.h" #include "Math/Factory.h" #include "Math/Functor.h" #include #include #include using namespace std; using namespace TMath; int getRandomNumber(int min, int max) { static const double fraction = 1.0 / (static_cast(RAND_MAX) + 1.0); return static_cast(rand() * fraction * (max - min + 1) + min); } void test_macro_colors() { TH2F *matrix = new TH2F("matrix", "matrix", 10, 0, 10, 10, 0, 10); for (int i1 = 0; i1 < 11; i1++) for (int i2 = 0; i2 < 10; i2++) if (matrix->GetBinContent(i2 + 1, i1 + 1) == 0) matrix->Fill(i2 + 0.1, i1 + 0.1, getRandomNumber(1, 80)); //test colors const Double_t min = 0; const Double_t max = 100; const Int_t nLevels = 100; Double_t levels[nLevels]; for (int i = 1; i < nLevels; i++) { levels[i] = min + (max - min) / (nLevels - 1) * (i); } levels[0] = 0.001; gStyle->SetOptStat(0000); TCanvas *canv_matrix = new TCanvas("Matrix", "Matrix"); matrix->SetContour((sizeof(levels) / sizeof(Double_t)), levels); gStyle->SetPaintTextFormat("4.0f"); matrix->SetMaximum(100); matrix->Draw("colzTEXT"); matrix->GetXaxis()->SetTitle("X"); matrix->GetYaxis()->SetTitle("Y"); matrix->GetZaxis()->SetTitle("Z"); TAxis *xaxis_c = matrix->GetXaxis(); TAxis *yaxis_c = matrix->GetYaxis(); xaxis_c->CenterLabels(); yaxis_c->CenterLabels(); }