Macro with subroutines

I am new to root. I am trying to write a macro which can call subroutines. Below is my attempt at doing this which does not work. I’ve written a macro as though it were a C program with a main routine and one subroutine. I’ve tried to execute in ROOT with “.x file.cxx” where file.cxx is the name of the file with this code in it. What magic mantra of commands do I need to do in order to get such a thing to work in ROOT? Thanks.

int_t ploth( *Tpad pad, *TH1F histo );

int_t main( void ) {
gROOT->Reset();
c1 = new TCanvas(“c1”,“canvas”,200,10,900,700);

pad1 = new TPad(“pad1”,“pad1”,0.02,0.70,0.24,0.88);

//Open root file which has histogram h11 in it
TFile example(“tsensor.root”);

// Draw histogram
ploth( pad1, h11 );
return 0;
}

int_t ploth( *Tpad pad, *TH1F histo ) {
pad->Draw();
histo->DrawCopy();
return 0;
}

Have a look at the User’s Guide, in particular starting at page 84
"the ROOT script processor".

From that you will learn that,

.L file.cxx
main()

has a good chance of success (( :slight_smile: after you replace int_t by Int_t
and tpad by TPad)

Thanks for the reply and reference to the User’s guide which was somewhat helpful.

I have now discovered that my real problem was in not in subroutines per se, but in the fact that I had a syntax and spelling errors in my subroutine declaration. Specifically

int ploth( *Tpad pad, *TH1F histo)

should be

int ploth( TPad *pad, TH1F *histo )

Also, I had to add a pad->cd(); to ploth in order to plot the histogram on the pad.