void hsimple() { //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* //*-* //*-* This program creates : //*-* - a one dimensional histogram //*-* - a two dimensional histogram //*-* - a profile histogram //*-* - a memory-resident ntuple //*-* //*-* These objects are filled with some random numbers and saved on a file. //*-* //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* gROOT->Reset(); // 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 *hfile = gROOT->FindObject("hsimple.root"); if (hfile) hfile->Close(); hfile = new TFile("hsimple.root","RECREATE","Demo ROOT file with histograms"); // Create some histograms, a profile histogram and an ntuple hgauss = new TH1F("hgauss","Gauss Distribution",100,-4,4); hbwigner = new TH1F("hbwigner","Breit Wigner Distribution",100,-4,4); hexp = new TH1F("hexp","Exponential Distribution",100,0,50); hpoisson = new TH1F("hpoisson","Poisson Distribution",100,0,10); hmass = new TH1F("hmass","Mass of pi, K, p",120,0,1.2); hist0 = new TH1F("hist0","",100,0,50); hist1 = new TH1F("hist1","",100,0,50); hist2 = new TH1F("hist2","",100,0,50); hist3 = new TH1F("hist3","",100,0,40); hist4 = new TH1F("hist4","",50,1.75,2.0); // Set canvas/frame attributes (save old attributes) gBenchmark->Start("hsimple"); // Fill histograms randomly gRandom->SetSeed(); Double_t mean, sigma, tau, value; Int_t amari; for ( Int_t i=0; i<25000; i++) { /* gauss */ mean=0.0; sigma=1.0; value = gRandom->Gaus(mean,sigma); hgauss->Fill(value); mean=0.0; sigma=0.8; value = gRandom->BreitWigner(mean,sigma); hbwigner->Fill(value); tau = 12.3; value = gRandom->Exp(tau); hexp->Fill(value); mean = 4; value = gRandom->PoissonD(mean); hpoisson->Fill(value); } for ( Int_t i=0; i<25000; i++) { amari=i%10; switch (amari) { case 0: case 1: case 2: case 3: case 4: mean = 0.938; sigma = 0.05; break; case 5: case 6: mean = 0.495; sigma = 0.03; break; case 7: case 8: case 9: mean = 0.139; sigma = 0.05; break; } value = gRandom->Gaus(mean,sigma); hmass->Fill(value); } TF1 *func2 = new TF1("func2","gaus(0)+[3]",0,50); func2->SetParameters(300,25,3,100); hist0->FillRandom("func2",25000); for ( Int_t i=0; i<25000; i++) { /* gauss */ mean=25.0; sigma=5.0; value = gRandom->Gaus(mean,sigma); hist1->Fill(value); tau = 12.3; value = gRandom->Exp(tau); hist1->Fill(value); } for ( Int_t i=0; i<25000; i++) { /* gauss */ mean=13.0; sigma=4.0; value = gRandom->Gaus(mean,sigma); hist2->Fill(value); mean=25.0; sigma=3.0; value = gRandom->Gaus(mean,sigma); hist2->Fill(value); } TF1 *func = new TF1("func","gaus(0)+[3]+[4]*x+[5]*x*x",0,50); func->SetParameters(300,10,2,0,40,-1); hist3->FillRandom("func",50000); for (Int_t i=0; i<17000; i++) { mean=1.86; sigma=0.017; value = gRandom->BreitWigner(mean,sigma); hist4->Fill(value); } gBenchmark->Show("hsimple"); // Save all objects in this file hfile->Write(); // Note that the file is automatically close when application terminates // or when the file destructor is called. }