/*************************************************************************** * -------------------------------------------------------------------------- * Template to exercise Random Numbers and CLT * -> Book and fill a histogram with 10000 uniform random numbers * -------------------------------------------------------------------------- * 13.06.2005, Klaus Rabbertz * * modification log: * kr, 04.07.2006: Removed explicit ex10 naming * as, 06.06.2008: Some fixes for running as macro ***************************************************************************/ /* Note that this file can be either used as a compiled program * or as a ROOT macro. * If it is used as a compiled program, additional include statements * and the definition of the main program have to be made. This is * not needed if the code is used as a macro. */ #ifndef __CINT__ // These include-statements are needed if the program is #include "TFile.h" // run as a "stand-alone application", i.e. if it is not #include "TCanvas.h" #include "TH1.h" // called from an interactive ROOT session #include "TH2.h" #include "TF1.h" #include "TProfile.h" #include "TRandom.h" #include "TMath.h" #include "TStyle.h" #include // Here we declare the functions we are goin to use later. // Each function corresponds to one subexercise void ex10(); void fermi(); void ranclt_1(); void ranclt_2(); //______________________________________________________________________________ int main() { ex10(); return 0; } #endif void ex10() { // Here we call the functions solving the subexercises. // If you are just working on one, comment out the others. fermi(); ranclt_1(); ranclt_2(); } //______________________________________________________________________________ // from here on, the code can also be used as a macro Double_t FermiDirac(Double_t *x, Double_t *par) // Fermi-Dirac distribution { return 0; // return value, insert your code ! } void fermi() { /* TFile hfile("fermi.root","RECREATE","fermi"); //eventually, open a file */ // TF1 *fermi = new TF1(...); // make a white canvas without borders // TCanvas *c1 = new TCanvas("c1", "c1", 0, 0, 700, 500); // eventually, set graphics options for TF1 fermi and TCanvas c1 // loop to plot Fermi-Dirac Distribution for different parameters /* // eventually, save all objects in the ROOT file and close it. c1->Write(); hfile.Write(); hfile.Close(); */ } void ranclt_1() { /* Create a new ROOT binary machine independent file. * Note that this file may contain any kind of ROOT objects, histograms, * pictures, graphics objects, detector geometries, tracks, events, etc.. * This file is now becoming the current directory. * TFile is a ROOT class, hfile is an instance of that class * TFile name("filename.root", "Option", "Comment"); */ TFile hfile("ranclt_1.root", "RECREATE", "ranclt_1"); /* Create a 1D histogram * TH1F is a ROOT class for 1D histograms, h100 is an instance of that class * Arguments: TH1F("identifier", "some title", NumberBins, XMin, XMax)); */ // Fill histogram with random numbers // Save all objects in this file hfile.Write(); // Close the file. Note that this is automatically done when you leave // the application. hfile.Close(); } void ranclt_2() { // Create a new ROOT file. TFile hfile("ranclt_2.root","RECREATE","ranclt_2"); // Create vector of pointers to 1D histograms. // Each pointer points to a histogram which holds the distribution // of a particular series of experiments TH1F *hlist[21]; // Book 1D histograms char title[20]; char id[5]; for (int i=2; i<=20; i++) { sprintf(title, "n= %d",i); sprintf(id, "h%d", i); hlist[i] = new TH1F(id,title,100,-5.0,5.0); } // Define and initialize needed variables //Float_t random=0.0; //Float_t y=0.0; //Float_t z=0.0; // Loop over different values of n. // Save all objects in the ROOT file and close it. hfile.Write(); hfile.Close(); }