本文整理汇总了C++中TH1F::FillRandom方法的典型用法代码示例。如果您正苦于以下问题:C++ TH1F::FillRandom方法的具体用法?C++ TH1F::FillRandom怎么用?C++ TH1F::FillRandom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TH1F
的用法示例。
在下文中一共展示了TH1F::FillRandom方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MakeOnePSE
TH1F * MakeOnePSE(TH1F * sig, int nsig, TH1F * back, int nback){
//threw one data PSE and fill it
TH1F * data = (TH1F*) sig ->Clone("data");
data->Reset();
data->FillRandom(sig,nsig);
data->FillRandom(back,nback);
return data;
}//MakeOnePSE
示例2:
vector<double> one_fit(bool do_fit)
{
TH1F* h = new TH1F("h","h", 20, -10, 10);
h->FillRandom("gaus");
vector<double> ret;
if (do_fit) {
h->Fit("gaus","");
TF1* g = h->GetFunction("gaus");
h->Draw();
canvas->Modified();
canvas->Update();
for (int ind=0; ind < 3; ++ind) {
ret.push_back(g->GetParameter(ind));
}
}
else {
for (int ind=0; ind < 3; ++ind) {
ret.push_back(0.0);
}
}
ret.push_back(h->GetMean());
ret.push_back(h->GetRMS());
delete h;
return ret;
}
示例3: fitcont
void fitcont()
{
//be sure default is Minuit since we will use gMinuit
TVirtualFitter::SetDefaultFitter("Minuit");
TCanvas *c1 = new TCanvas("c1");
TH1F *h = new TH1F("h","My histogram",100,-3,3);
h->FillRandom("gaus",6000);
h->Fit("gaus");
c1->Update();
TCanvas *c2 = new TCanvas("c2","contours",10,10,600,800);
c2->Divide(1,2);
c2->cd(1);
/*get first contour for parameter 1 versus parameter 2*/
TGraph *gr12 = (TGraph*)gMinuit->Contour(40,1,2);
gr12->Draw("alp");
c2->cd(2);
/*Get contour for parameter 0 versus parameter 2 for ERRDEF=2*/
gMinuit->SetErrorDef(4); //note 4 and not 2!
TGraph *gr2 = (TGraph*)gMinuit->Contour(80,0,2);
gr2->SetFillColor(42);
gr2->Draw("alf");
/*Get contour for parameter 0 versus parameter 2 for ERRDEF=1*/
gMinuit->SetErrorDef(1);
TGraph *gr1 = (TGraph*)gMinuit->Contour(80,0,2);
gr1->SetFillColor(38);
gr1->Draw("lf");
}
示例4: peaks
void peaks(Int_t np=10) {
npeaks = TMath::Abs(np);
TH1F *h = new TH1F("h","test",500,0,1000);
//generate n peaks at random
Double_t par[3000];
par[0] = 0.8;
par[1] = -0.6/1000;
Int_t p;
for (p=0;p<npeaks;p++) {
par[3*p+2] = 1;
par[3*p+3] = 10+gRandom->Rndm()*980;
par[3*p+4] = 3+2*gRandom->Rndm();
}
TF1 *f = new TF1("f",fpeaks,0,1000,2+3*npeaks);
f->SetNpx(1000);
f->SetParameters(par);
TCanvas *c1 = new TCanvas("c1","c1",10,10,1000,900);
c1->Divide(1,2);
c1->cd(1);
h->FillRandom("f",200000);
h->Draw();
TH1F *h2 = (TH1F*)h->Clone("h2");
//Use TSpectrum to find the peak candidates
TSpectrum *s = new TSpectrum(2*npeaks);
Int_t nfound = s->Search(h,2,"",0.10);
printf("Found %d candidate peaks to fit\n",nfound);
//Estimate background using TSpectrum::Background
TH1 *hb = s->Background(h,20,"same");
if (hb) c1->Update();
if (np <0) return;
//estimate linear background using a fitting method
c1->cd(2);
TF1 *fline = new TF1("fline","pol1",0,1000);
h->Fit("fline","qn");
//Loop on all found peaks. Eliminate peaks at the background level
par[0] = fline->GetParameter(0);
par[1] = fline->GetParameter(1);
npeaks = 0;
Double_t *xpeaks = s->GetPositionX();
for (p=0;p<nfound;p++) {
Double_t xp = xpeaks[p];
Int_t bin = h->GetXaxis()->FindBin(xp);
Double_t yp = h->GetBinContent(bin);
if (yp-TMath::Sqrt(yp) < fline->Eval(xp)) continue;
par[3*npeaks+2] = yp;
par[3*npeaks+3] = xp;
par[3*npeaks+4] = 3;
npeaks++;
}
printf("Found %d useful peaks to fit\n",npeaks);
printf("Now fitting: Be patient\n");
TF1 *fit = new TF1("fit",fpeaks,0,1000,2+3*npeaks);
//we may have more than the default 25 parameters
TVirtualFitter::Fitter(h2,10+3*npeaks);
fit->SetParameters(par);
fit->SetNpx(1000);
h2->Fit("fit");
}
示例5: exec3
void exec3()
{
// Temporary work around the lack of automatic refresh of the list
// when a script is reloaded.
gROOT->GetListOfGlobalFunctions()->Delete();
TH1F *h = new TH1F("h","h",100,-3,3);
h->FillRandom("gaus",1000);
TCanvas *c1=new TCanvas("c1");
h->Draw();
c1->Update();
c1->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", 0, 0,
"exec3event(Int_t,Int_t,Int_t,TObject*)");
}
示例6: pad2png
void pad2png()
{
TCanvas *c = new TCanvas;
TH1F *h = new TH1F("gaus", "gaus", 100, -5, 5);
h->FillRandom("gaus", 10000);
h->Draw();
gSystem->ProcessEvents();
TImage *img = TImage::Create();
img->FromPad(c);
img->WriteImage("canvas.png");
}
示例7: fill_local_ocdb
void fill_local_ocdb()
{
AliceO2::CDB::Manager* cdb = AliceO2::CDB::Manager::Instance();
cdb->setDefaultStorage("local://O2CDB");
TH1F* h = 0;
for (int run = 2000; run < 2100; run++) {
cdb->setRun(run);
h = new TH1F(Form("histo for %d run", run), "gauss", 100, -5, 5);
h->FillRandom("gaus", 1000);
AliceO2::CDB::ConditionId* id = new AliceO2::CDB::ConditionId("DET/Calib/Histo", run, run, 1, 0);
AliceO2::CDB::ConditionMetaData* md = new AliceO2::CDB::ConditionMetaData();
cdb->putObject(h, *id, md);
h = 0;
}
}
示例8: exec3
void exec3()
{
// Example of using signal/slot in TCanvas/TPad to get feedback
// about processed events. Note that slots can be either functions
// or class methods. Compare this with tutorials exec1.C and exec2.C.
//Author: Ilka Antcheva
// Temporary work around the lack of automatic refresh of the list
// when a script is reloaded.
gROOT->GetListOfGlobalFunctions()->Delete();
TH1F *h = new TH1F("h","h",100,-3,3);
h->FillRandom("gaus",1000);
TCanvas *c1=new TCanvas("c1");
h->Draw();
c1->Update();
c1->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", 0, 0,
"exec3event(Int_t,Int_t,Int_t,TObject*)");
}
示例9: lochanroot
void lochanroot()
{
char name[10], title[20];
TObjArray Hlist(0); // create an array of Histograms
TH1F* g; // create a pointer to a histogram
// make and fill 15 histograms and add them to the object array
for (Int_t i = 0; i < 15; i++) {
sprintf(name,"lochan%d",i);
sprintf(title,"histo number:%d",i);
g = new TH1F(name,title,100,-4,4);
Hlist.Add(g); //changed from -> to .
g->FillRandom("gaus",1000);
}
// open a file and write the array to the file
TFile f("lochan.root","recreate");
Hlist.Write(); //changed from -> to .
f.Close();
}
示例10: customContextMenu
void customContextMenu()
{
TH1F *h;
TH1F *h2;
TClassMenuItem *n;
TList *l;
// Create test histograms
h = new TH1F("h","Schtroumpf",100,-4,4);
h->FillRandom("gaus");
h->Draw();
h2 = new TH1F("h2","h2",1000,-4,4);
h2->FillRandom("gaus",30000);
// Retrieve menu list from TClass
TClass *cl = h->IsA();
l = cl->GetMenuList();
// Add some items to the popup menus
n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
"Test object, draw a second h","Draw",h2,"Option_t*");
l->AddFirst(n);
n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl);
l->AddFirst(n);
n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
"test no 4","poptest4",0,"const char*");
l->AddFirst(n);
n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
"test no 3","poptest3",0,"");
l->AddFirst(n);
n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
"test no 2 bis","poptest2bis",0,"TObject*",2);
l->AddFirst(n);
n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
"test no 2","poptest2",0,"int,int,TObject*",2);
l->AddFirst(n);
n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
"test no 1","poptest1",0,"int,int");
l->AddFirst(n);
}
示例11: ExampleMacro
/*
* From here on, the code can also be used as a macro
* Note though, that CINT may report errors where there are none
in C++. E.g. this happens here where CINT says that f1 is
out of scope ...
==>> put your code here
(remember to update the name of you Macro in the
lines above if you intend to comile the code)
*/
void ExampleMacro() {
// Create a histogram, fill it with random gaussian numbers
TH1F *h = new TH1F ("h", "example histogram", 100, -5.,5.);
h->FillRandom("gaus",1000);
// draw the histogram
h->DrawClone();
/* - Create a new ROOT file for output
- Note that this file may contain any kind of ROOT objects, histograms,
pictures, graphics objects etc.
- the new file is now becoming the current directory */
TFile *f1 = new TFile("ExampleMacro.root","RECREATE","ExampleMacro");
// write Histogram to current directory (i.e. the file just opened)
h->Write();
// Close the file.
// (You may inspect your histogram in the file using the TBrowser class)
f1->Close();
}
示例12: billtw
void billtw(Int_t compress) {
//write N histograms to a Tree
timer.Start();
TFile f("billt.root","recreate","bill benchmark with trees",compress);
TH1F *h = new TH1F("h","h",1000,-3,3);
h->FillRandom("gaus",50000);
TTree *T = new TTree("T","test bill");
T->Branch("event","TH1F",&h,64000,0);
for (Int_t i=0;i<N;i++) {
char name[20];
sprintf(name,"h%d",i);
h->SetName(name);
h->Fill(2*gRandom->Rndm());
T->Fill();
}
T->Write();
delete T;
timer.Stop();
printf("billtw%d : RT=%7.3f s, Cpu=%7.3f s, File size= %9d bytes, CX= %g\n",compress,timer.RealTime(),timer.CpuTime(),
(Int_t)f.GetBytesWritten(),f.GetCompressionFactor());
}
示例13: fitcont
void fitcont()
{
// Example illustrating how to draw the n-sigma contour of a Minuit fit.
// To get the n-sigma contour the ERRDEF parameter in Minuit has to set
// to n^2. The fcn function has to be set before the routine is called.
//
// WARNING!!! This test works only with TMinuit
//
// The TGraph object is created via the interpreter. The user must cast it
// to a TGraph*
// Author: Rene Brun
//be sure default is Minuit since we will use gMinuit
TVirtualFitter::SetDefaultFitter("Minuit");
TCanvas *c1 = new TCanvas("c1");
TH1F *h = new TH1F("h","My histogram",100,-3,3);
h->FillRandom("gaus",6000);
h->Fit("gaus");
c1->Update();
TCanvas *c2 = new TCanvas("c2","contours",10,10,600,800);
c2->Divide(1,2);
c2->cd(1);
//get first contour for parameter 1 versus parameter 2
TGraph *gr12 = (TGraph*)gMinuit->Contour(40,1,2);
gr12->Draw("alp");
c2->cd(2);
//Get contour for parameter 0 versus parameter 2 for ERRDEF=2
gMinuit->SetErrorDef(4); //note 4 and not 2!
TGraph *gr2 = (TGraph*)gMinuit->Contour(80,0,2);
gr2->SetFillColor(42);
gr2->Draw("alf");
//Get contour for parameter 0 versus parameter 2 for ERRDEF=1
gMinuit->SetErrorDef(1);
TGraph *gr1 = (TGraph*)gMinuit->Contour(80,0,2);
gr1->SetFillColor(38);
gr1->Draw("lf");
}
示例14: pad2png
void pad2png()
{
// Create a canvas and save as png.
//Author: Valeriy Onuchin
TCanvas *c = new TCanvas;
TH1F *h = new TH1F("gaus", "gaus", 100, -5, 5);
h->FillRandom("gaus", 10000);
h->Draw();
gSystem->ProcessEvents();
TImage *img = TImage::Create();
//img->FromPad(c, 10, 10, 300, 200);
img->FromPad(c);
img->WriteImage("canvas.png");
delete h;
delete c;
delete img;
}
示例15: fitExclude
void fitExclude() {
//Create a source function
TF1 *f1 = new TF1("f1","[0] +[1]*x +gaus(2)",0,5);
f1->SetParameters(6,-1,5,3,0.2);
// create and fill histogram according to the source function
TH1F *h = new TH1F("h","background + signal",100,0,5);
h->FillRandom("f1",2000);
TF1 *fl = new TF1("fl",fline,0,5,2);
fl->SetParameters(2,-1);
//fit only the linear background excluding the signal area
reject = kTRUE;
h->Fit(fl,"0");
reject = kFALSE;
//store 2 separate functions for visualization
TF1 *fleft = new TF1("fleft",fline,0,2.5,2);
fleft->SetParameters(fl->GetParameters());
h->GetListOfFunctions()->Add(fleft);
gROOT->GetListOfFunctions()->Remove(fleft);
TF1 *fright = new TF1("fright",fline,3.5,5,2);
fright->SetParameters(fl->GetParameters());
h->GetListOfFunctions()->Add(fright);
gROOT->GetListOfFunctions()->Remove(fright);
h->Draw();
}