//----------- hrandom.C #include "TStopwatch.h" #include "TRandom2.h" #include "TRandom3.h" #include "TH1.h" #include "TCanvas.h" #include void hrandom() { // example of a script computing the CPU time to fill an histogram // with 3 random number generators. const unsigned int nfills = 1000000; cout << "Llenando histogramas y midiendo eficiencias para " << nfills << " puntos" << endl; //Create timer to meassure performance TStopwatch timer; //////////////////////////////////////////////////// // First fill a histogram with a constant number //Create a histogram (see documentation) TH1F *h1 = new TH1F("h1","h1",100,0,1); //Start timer to meassure performance timer.Start(); //Loop over histogram and fill it cout << "* Primer histograma..." << endl; for (unsigned int i=0; iFill(0.5); //Show times double fillTime = timer.CpuTime(); cout << " Tiempo: " << fillTime << " segundos" << endl; //Draw the histogram h1->Draw(); ///////////////////////////////////////////////////// //Second fill a histogram with random numbers (using TRandom) // Create a new canvas to avoid redrawing on the first one TCanvas *c2 = new TCanvas(); // Create a new histogram (see documentation) TH1F *h2 = new TH1F("h2","h2",100,0,1); //Start timer to meassure performance timer.Start(); //Create random generator (see documentation) TRandom r1; //Loop over histogram and fill it cout << "* Segundo histograma..." << endl; for (unsigned int i=0; iFill(r1.Rndm()); cout << " Tiempo: " << timer.CpuTime()-fillTime << " seconds\n" << endl; //Change histogram line color and draw it h2->SetLineColor(2); h2->Draw(""); }