// root_test.C // // A simple script to demonstrate the rendering performance // of ROOT for a canvas containing sixteen 1000x1000 // histograms. // // author: Jeromy Tompkins // NSCL, Michigan State University // // // Instructions for how to run from within CINT // 1. Enter ".L root_test.C+" // 2. Enter "run()" // // In the GUI the buttons have the following meaning // Fill - Fill all histograms with some data // Update - Update all 16 subpads of the canvas // Save - Save all 16 histograms to a root file called test.root #include #include #include #include #include #include #include #include #include using namespace std; // some globals vector gHists; TCanvas* gpCanvas = 0; int gNFills = 1000000; // Utility method to create a list of histograms vector createHists(int n) { vector tmphists(n); for (int i=0; i& hists, TPad* pPad) { int nHists = hists.size(); for (int i=0; icd(i+1); hists.at(i)->Draw("colz"); } pPad->Update(); } // Utility method to fill a single histogram with gNFills // without updating the canvas. This really scatters the // contents of the histograms void fillHist(TH1* pHist) { for (int i=0; iGaus(300, 300); double y = gRandom->Gaus(600, 400); pHist->Fill(x, y); } } // Method to fill all histograms... offers a benchmark for // this performance. void fillHists(const vector& hists) { vector::const_iterator it = hists.begin(); vector::const_iterator it_end = hists.end(); TBenchmark bm; bm.Start("Fill"); while( it != it_end ) { fillHist( *it ); ++it; } bm.Stop("Fill"); bm.Print("Fill"); } // Update the canvas. This iterates through the list of // subpads and checks them each as Modified() void updateCanvas(TPad* pPad) { TBenchmark bm; // Mark the first 16 subpads as modified, because only // the first 16 subpads display histograms bm.Start("Modified"); for (int iPad=1; iPad<17; ++iPad) { pPad->cd(iPad); gPad->Modified(1); } bm.Stop("Modified"); // Call and benchmark the Update method bm.Start("Update"); pPad->Update(); bm.Stop("Update"); // Print the results of the benchmark bm.Print("Modified"); bm.Print("Update"); } // Utility method to save all histograms to a file void saveHists(TString name, vector& hists) { TFile file (name, "RECREATE"); for (size_t i=0; iWrite(); } } // The main method that will run the whole script // void run() { gHists = createHists(16); gpCanvas = new TCanvas("c1"); gpCanvas->Divide(4, 5); drawHists(gHists, gpCanvas); // Draw some buttons onto the canvas to call each method // Fill button to modify the contents of each histogram gpCanvas->cd(17); TButton* pFillButton = new TButton("Fill", "fillHists(gHists)", 0, 0, 1, 1); pFillButton->Draw(); // Update button to call updateCanvas gpCanvas->cd(18); TButton* pUpdateButton = new TButton("Update", "updateCanvas(gpCanvas)", 0, 0, 1, 1); pUpdateButton->Draw(); // Save button to call saveHists gpCanvas->cd(19); TButton* pSaveButton = new TButton("Save", "saveHists(\"test.root\", gHists)", 0, 0, 1, 1); pSaveButton->Draw(); }