# Importing TCutG saved C file inside another macro

**URL:** <https://root-forum.cern.ch/t/importing-tcutg-saved-c-file-inside-another-macro/53232>\
**Category:** Newbie\
**Tags:** graphics, root\
**Created:** [January 23, 2023, 11:16pm UTC](https://root-forum.cern.ch/t/importing-tcutg-saved-c-file-inside-another-macro/53232 "2023-01-23T23:16:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![thegame](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/e495f1/32.png) [@thegame](https://root-forum.cern.ch/u/thegame)\
**Post date:** [January 23, 2023, 11:16pm UTC](https://root-forum.cern.ch/t/importing-tcutg-saved-c-file-inside-another-macro/53232/1 "2023-01-23T23:16:24Z")

</div>

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](https://root-forum.cern.ch/uploads/short-url/dwdOQ3Yc5N0nbDc7ST7r9vCPrGQ.C) (577 Bytes)

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [January 24, 2023, 4:57am UTC](https://root-forum.cern.ch/t/importing-tcutg-saved-c-file-inside-another-macro/53232/2 "2023-01-24T04:57:25Z")

</div>

> **[c++ include other cpp files at DuckDuckGo](https://duckduckgo.com/?q=c%2B%2B%2Binclude%2Bother%2Bcpp%2Bfiles&t=brave&ia=web)**
>
> DuckDuckGo. Privacy, Simplified.

---

<div class="post-metadata">

**Author:** ![thegame](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/e495f1/32.png) [@thegame](https://root-forum.cern.ch/u/thegame)\
**Post date:** [January 24, 2023, 5:53am UTC](https://root-forum.cern.ch/t/importing-tcutg-saved-c-file-inside-another-macro/53232/3 "2023-01-24T05:53:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [January 24, 2023, 7:48am UTC](https://root-forum.cern.ch/t/importing-tcutg-saved-c-file-inside-another-macro/53232/4 "2023-01-24T07:48:44Z")

</div>

### cut.c

```auto
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

```auto
{
   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);
}

```

 ![Screenshot 2023-01-24 at 08.47.14](https://root-forum.cern.ch/uploads/default/original/3X/b/2/b230c2789101b3850c226defa6848605dbc464ef.png)

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.

---

<div class="post-metadata">

**Author:** ![thegame](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/e495f1/32.png) [@thegame](https://root-forum.cern.ch/u/thegame)\
**Post date:** [January 24, 2023, 11:30pm UTC](https://root-forum.cern.ch/t/importing-tcutg-saved-c-file-inside-another-macro/53232/5 "2023-01-24T23:30:21Z")

</div>

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!!

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [January 25, 2023, 6:38am UTC](https://root-forum.cern.ch/t/importing-tcutg-saved-c-file-inside-another-macro/53232/6 "2023-01-25T06:38:50Z")

</div>

> [@thegame](#):
>
> was giving an error while compiling

I do not see that:

```auto
% 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] 

```
