// Written by Paul Mullen in July 2010 // Produces a histo for the mock online analysis example void mass_spectrum() { TCanvas *canv = new TCanvas("canv", "A Canvas", 800, 600); // We generate a random peak position gRandom = new TRandom3(0); gRandom->SetSeed(0); Double_t x = 0.888 + gRandom->Uniform(0.1); // mass of proton cout << "Peak position: " << x << endl; // Gaussian distribution TF1 *myfunc = new TF1("myfunc", "gaus", 0, 3); myfunc->SetParameters(1, x, 0.1); //myfunc->Draw(); // Fill distribution TH1F *Mp = new TH1F("Mp", "Mass distribution", 100, 0.5, 1.4); Mp->SetLineColor(2); Mp->FillRandom("myfunc", 100000); // number of counts Mp->SetXTitle("m [GeV/c^{2}]"); Mp->SetYTitle("counts"); Mp->Draw(); // We save to a file Char_t filename[14]; Int_t rnum = gRandom->Uniform(999999); sprintf(filename, "run%06d.root", rnum); TFile *output = new TFile(filename, "RECREATE"); Mp->Write(); output->Close(); cout << "Output saved in " << filename << endl; }