Function test() is not defined in current scope

Hi all, I’m really new to this, but with this code I keep receiving this error:

Error: Function test() is not defined in current scope :0:
*** Interpreter error recovered ***

in

#include

int main()
{

void PhaseSpace() {

 if (!gROOT->GetClass("TGenPhaseSpace")) gSystem->Load("libPhysics");

 TLorentzVector target(0.0, 0.0, 0.0, 0.938);
 TLorentzVector beam(0.0, 0.0, .65, .65);
 TLorentzVector W = beam + target;

 //(Momentum, Energy units are Gev/C, GeV)
 Double_t masses[3] = { 0.938, 0.139, 0.139} ;

 TGenPhaseSpace event;
 event.SetDecay(W, 3, masses);

 TH2F *h2 = new TH2F("h2","h2", 50,1.1,1.8, 50,1.1,1.<img src="/uploads/default/original/1X/fe5f42ae79e389360ae9d969db4dcc4bca03d384.gif" width="15" height="17" alt="8)" title="Cool"/>;
 for (Int_t n=0;n<100000;n++) {
    Double_t weight = event.Generate();

    TLorentzVector *pProton = event.GetDecay(0);

    TLorentzVector *pPip    = event.GetDecay(1);
    TLorentzVector *pPim    = event.GetDecay(2);

    TLorentzVector pPPip = *pProton + *pPip;
    TLorentzVector pPPim = *pProton + *pPim;

    h2->Fill(pPPip.M2() ,pPPim.M2() ,weight);
 }
 h2->Draw();

}
}

I’m aware I’ve set this up wrong but I can’t work out what to do, thanks in advance!

Main was added when I received a similar error using void alone

As I know, you can not create function inside another function

Wrong:

int main()
{
	void PhaseSpace() 
	{
	}
	return 0;
}

Right:

void PhaseSpace() 
{
}

int main()
{
	PhaseSpace() ;
	return 0;
}

Or just replace

int main() { } with

void test() { }
assuming that test.C is the name of your file, and run as root -l test.C

1 Like