warning: Failed to call `main()` to execute the macro

614 Views Asked by At

I am trying to learn ROOT and I have a few codes that I can work with. Sometimes codes work but sometimes they don't.

{
 c1 = new TCanvas("c1", "My Root Plots",600, 400);
 c1->Divide(2,2);
 c1->cd(1);
 f=new TF1("f","[0]*exp(-0.5*((x-[1])/[2])**2)/(sqrt(2.0*TMath::Pi())*[2])",-100,100); f->SetTitle("Gaus;X axis ;Y axis");
 f->SetParameter(0,0.5*sqrt(2*TMath::Pi()));
 f->SetParameter(1,8);
 f->SetParameter(2,5);
 f->SetLineColor(3);
 f->SetMarkerColor(1);
 f->SetMarkerStyle(kOpenStar);
 f->SetMarkerSize(5);
 f->Draw();
 
 
 
 c1->cd(2);
 f1 = new TF1("f1", "[0]*x+[1]", 0,50);
 f1->SetParameters(10,4);
 f1->SetLineColor(5);
 f1->SetTitle("ax+b;x;y");
 f1->Draw();
 
 }

This is the code I am trying to do. Code is kinda working , ''what do you mean kinda working''. I mean it's giving me a graph but as you can see in the code I wrote ( f->SetMarkerColor(1); f->SetMarkerStyle(kOpenStar);) But markers didn't appear on the graph. Terminal doesn't giving me any errors. Is it my ROOT library missing ? I cannot upload images because I am new here.

I have a another problem. I want to share it maybe it will help solving the problem that I have.

void testRandom(Int_t nrEvents=500000000)
{
    TRandom *r1=new TRandom();
    TRandom2 *r2=new TRandom2();
    TRandom3 *r3=new TRandom3();
    TCanvas* c1=new TCanvas("c1","TRandom Number Generators", 800,600); c1->Divide(3,1);
    TH1D *h1=new TH1D("h1","TRandom",500,0,1); TH1D *h2=new TH1D("h2","TRandom2",500,0,1); TH1D *h3=new TH1D("h3","TRandom3",500,0,1); TStopwatch *st=new TStopwatch();
    st->Start();
    for (Int_t i=0; i<nrEvents; i++) { h1->Fill(r1->Uniform(0,1)); } st->Stop(); cout << "Random: " << st->CpuTime() << endl; st->Start();
    c1->cd(1); h1->SetFillColor(kRed+1); h1->SetMinimum(0); h1->Draw();
    for (Int_t i=0; i<nrEvents; i++) { h2->Fill(r2->Uniform(0,1)); } st->Stop(); cout << "Random2: " << st->CpuTime() << endl; st->Start();
    c1->cd(2); h2->SetFillColor(kGreen+1); h2->SetMinimum(0); h2->Draw();
    for (Int_t i=0; i<nrEvents; i++) { h3->Fill(r3->Uniform(0,1)); } st->Stop(); cout << "Random3:" << st->CpuTime() << endl;
    c1->cd(3);
    h3->Draw(); h3->SetFillColor(kBlue+1); h3->SetMinimum(0);
}

This is a another code I am trying to run. But this code doesn't work an it's giving me this error.

warning: Failed to call main() to execute the macro. Add this function or rename the macro. Falling back to .L.

I tried different things. I tried ,

root [1] .x main.cpp

root [1] .L main.cpp

still giving me same error.

1

There are 1 best solutions below

0
ferdymercury On

f->SetMarkerColor(1); f->SetMarkerStyle(kOpenStar);) But markers didn't appear on the graph.

Try f->Draw("PL") instead of f->Draw() to make the markers visible.

warning: Failed to call main() to execute the macro.

Rename your file, it should be called testRandom.cpp instead of main.cpp Then, you can execute it with .x testRandom.cpp.