Importing TCutG saved C file inside another macro

Hi all, I have saved a graphical cut inside a C file (let’s say Cut.C) and now want to use these cut conditions in another macro that deals with importing and plotting tree variables. What I’m trying to do is to inside the tree->Draw() command in the second macro I wanna use the Cut.C file. something like this below:

tree->Draw("A", "CUT CONDITIONS from CUT.C", "colz");

Any suggestions on how to do that? Thanks!

CUT.C is attached to this post.
CutG.C (577 Bytes)

thanks for the link but still couldn’t figure it out :frowning: above attched CutG.C looks a bit different than usual.

cut.c

void cut() {
   gROOT->Macro("CutG.C");
   auto h = new TH2D("h","h",40,3,3.4,40,2,9);
   float px, py;
   for (Int_t i = 0; i < 25000; i++) {
      gRandom->Rannor(px,py);
      h->Fill(3*px,4*py);
   }
   h->Draw("col [CUTG]");
}

CutG.C

{
   TCutG *cutg = new TCutG("CUTG",8);
   cutg->SetVarX("aoq57 R61-74combined");
   cutg->SetVarY("zet7");
   cutg->SetPoint(0,3.10298,8.43579);
   cutg->SetPoint(1,3.13849,5.74994);
   cutg->SetPoint(2,3.17063,6.86904);
   cutg->SetPoint(3,3.2193,6.84271);
   cutg->SetPoint(4,3.29215,5.68411);
   cutg->SetPoint(5,3.34603,7.07312);
   cutg->SetPoint(6,3.30378,8.44237);
   cutg->SetPoint(7,3.10298,8.43579);
}

This example shows how to use a graphical cut defined in an external macro. Here it is use to draw a 2D histogram, but of course, you can also use it in a TTree:Draw command.

Thanks a lot for this detailed explanation. It helped.

Inside the CutG.C if you see the cutg->SetVarX("aoq57 R61-74combined"); row the blank space between aoq57 and R61 was giving an error while compiling. Got rid of that space now and worked fine. However, interested to know what might be the reason for this. Thanks again!!

I do not see that:

% cat CutG.C
{
   TCutG *cutg = new TCutG("CUTG",8);
   cutg->SetVarX("aoq57 R61-74combined");
   cutg->SetVarY("zet7");
   cutg->SetPoint(0,3.10298,8.43579);
   cutg->SetPoint(1,3.13849,5.74994);
   cutg->SetPoint(2,3.17063,6.86904);
   cutg->SetPoint(3,3.2193,6.84271);
   cutg->SetPoint(4,3.29215,5.68411);
   cutg->SetPoint(5,3.34603,7.07312);
   cutg->SetPoint(6,3.30378,8.44237);
   cutg->SetPoint(7,3.10298,8.43579);
}
% root CutG.C++
   ------------------------------------------------------------------
  | Welcome to ROOT 6.29/01                        https://root.cern |
  | (c) 1995-2022, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for macosx64 on Jan 24 2023, 08:38:30                      |
  | From heads/master@v6-29-01-306-geee4c8e424                       |
  | With Apple clang version 14.0.0 (clang-1400.0.29.202)            |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q'  |
   ------------------------------------------------------------------

root [0] 
Processing CutG.C++...
root [1]