A ROOT script called from inside compiled code

Hi. I have a ROOT script – let’s call it myscript.C – which I run interactively from CINT. It contains the following lines:

      gROOT->Macro("cut.C"); //load a graphical cut file
      TCutG *mycut=(TCutG*)cutg->Clone("mycut"); //clone it, and delete it immediately
      delete cutg;

The object cutg as you probably guessed is created by cut.C:

   TCutG *cutg = new TCutG("cut0",33);
   cutg->SetVarX("Ec");
   cutg->SetVarY("PSD");
   cutg->SetTitle("Graph");
   cutg->SetFillColor(1);
   cutg->SetPoint(0,400,-0.35442);
   cutg->SetPoint(1,600,-0.346545);
   cutg->SetPoint(2,800,-0.335386);
etc...

Now, I would like to compile myscript.C and run it as a stand-alone executable. I set up main(), all the #include lines and all that…however, when I try to compile it the compiler (understandably) complains about cutg being undefined. The trouble is that cutg is dynamically created by cutg.C…

I still would like to retain the ability to read in cutg.C by the (new) compiled code. I am really not sure how to do that (other than use an ugly solution involving parsing cutg.C into a table). Any ideas? Any insight would be much appreciated!!

Hi,

in your outer code (the one you want to compile) you instead write

TCutG* cutg = (TCutG*) gROOT->GetListOfSpecials()->FindObject("cut0");
TCutG *mycut=(TCutG*)cutg->Clone("mycut"); //clone it, and delete it immediately
delete cutg;

Cheers, Axel.

Axel, thanks a gazillion! Works like a charm!