//Version 1.0 using namespace std; #include #include #include #include #include #include #include #include #include "TROOT.h" #include "TApplication.h" #include "TCanvas.h" #include "TPaveText.h" #include "TPad.h" #include "TStyle.h" #include "TFrame.h" #include "TH1D.h" //===================================================================== int main(int argc, char **argv) { TApplication theApp("App", &argc, argv); int i; double factor = 1.0; gROOT->Reset(); // --------- Create two histograms --------------------------------------- const int NBINS = 5; const double LOW = 0.0; const double HIGH = 300.0; TH1D* hi1 = new TH1D("hi1", "The first distribution", NBINS, LOW, HIGH); hi1->SetLineColor(kGreen); hi1->SetLineWidth(3); hi1->GetXaxis()->SetTitle("Number"); TH1D* hi2 = new TH1D("hi2", "The second distribution", NBINS, LOW, HIGH); hi2->SetLineColor(kBlue); hi2->SetLineWidth(5); hi2->GetXaxis()->SetTitle("Number"); // ----- Fill the first histogram --------------------------------------- for(i=0; i<800; i++) hi1->Fill(HIGH*fabs(cos(i*4040.40))); // ------ Create and configure two canvases ------------------------- const unsigned int H = 800, V = 600; const unsigned int XC1=80, YC1=80, XC2=XC1+H, YC2=YC1+V; TCanvas* c1 = new TCanvas("c1","This is canvas 1", XC1, YC1, XC2, YC2); TCanvas* c2 = new TCanvas("c2","This is canvas 2", XC1, YC1, XC2, YC2); c1->cd(); c1->SetFillColor(kYellow-10); c1->SetFrameFillColor(10);; c1->GetFrame()->SetFillColor(kWhite); c1->GetFrame()->SetBorderSize(0); c1->GetFrame()->SetBorderMode(-1); c2->cd(); c2->SetFillColor(kBlue-10); c2->SetFrameFillColor(10);; c2->GetFrame()->SetFillColor(kWhite); c2->GetFrame()->SetBorderSize(0); c2->GetFrame()->SetBorderMode(-1); // ----------- Draw the histogram in the first canvas ----------------- c1->cd(); hi1->Draw(); // ---- Input the factor and fill the second histogram --------------- cout << "Enter the factor: "; cin >> factor; for(i=0; i<800; i++) hi2->Fill(HIGH*fabs(cos(i*factor/4040.40))); // -------Draw the second histogram in the second canvas ----------- c2->cd(); hi2->Draw(); c1->Modified(); c1->Update(); c2->Modified(); c2->Update(); theApp.Run(); return 0; } // End of main()