# TMVA ROC-Curve Extraction and Modification

**URL:** <https://root-forum.cern.ch/t/tmva-roc-curve-extraction-and-modification/29395>\
**Category:** TMVA\
**Created:** [June 16, 2018, 11:49am UTC](https://root-forum.cern.ch/t/tmva-roc-curve-extraction-and-modification/29395 "2018-06-16T11:49:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roderfeen](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roderfeen/32/16484_2.png) [@Roderfeen](https://root-forum.cern.ch/u/Roderfeen)\
**Post date:** [June 16, 2018, 11:49am UTC](https://root-forum.cern.ch/t/tmva-roc-curve-extraction-and-modification/29395/1 "2018-06-16T11:49:49Z")

</div>

ROOT Version 6.08/04  
Platform Xubuntu 17.04  
Compiler gcc6.3

Hello forum!

After a successful TMVA run the ROC-Curves are saved in my fdmTMVA.root file.  
Each method gets a folder:

fdmTMVA.root -\> TDirectoryFile::dataset -\> TDirectoryFile::Method\_KNN -\> TDirectoryFile::KNN -\>  
TH1D::MVA\_KNN\_effBvsS (ROC-curve)

- My question is, how do I extract the TH1D ROC-curve? I.e. how do I traverse TDirectoryFile folders?

- Secondly, how do I modify it using the TSyle and THistPainter Classes?

Attempt:

```auto
// Open .root file
TFile *f1 = TFile::Open("fdmTMVA.root");

// Set pointer to directory containing ROC-curve
TDirectory* dir = gFile->GetDirectory("/dataset/Method_KNN/KNN");

TString objectName( "MVA_KNN_effBvsS" );
TH1D* h;

// Extract ROC-curve
dir->GetObject(objectName,h);

// Set Canvas
TCanvas *c = new TCanvas("c");
gPad->SetGrid(); 
// more style options etc...

// Draw and save
h->Draw();
c->SaveAs(objectName + ".png");

delete c;
delete f1;

```

This doesn’t work as it gives the following warning:

- Warning: null passed to a callee that requires a non-null argument [-Wnonnull] dir-\>GetObject(objectName,h);

Many thanks in advance!

Edit: This now works by replacing GetDirectory(“Method\_KNN/KNN”) with GetDirectory("/dataset/Method\_KNN/KNN")

---

<div class="post-metadata">

**Author:** ![Roderfeen](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roderfeen/32/16484_2.png) [@Roderfeen](https://root-forum.cern.ch/u/Roderfeen)\
**Post date:** [June 16, 2018, 5:11pm UTC](https://root-forum.cern.ch/t/tmva-roc-curve-extraction-and-modification/29395/2 "2018-06-16T17:11:44Z")

</div>

Update: I’m now manually extracting the ROC-Curve via TBrowser, saving it in a .root file. Which allows me to interact with it in other macros.

Surely I am missing something benign here, can’t I do this same operation in my macro out of the original .root file?

Thanks again.

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [June 18, 2018, 6:53am UTC](https://root-forum.cern.ch/t/tmva-roc-curve-extraction-and-modification/29395/3 "2018-06-18T06:53:34Z")

</div>

@moneta @kialbert can one of you help?

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [June 18, 2018, 7:55am UTC](https://root-forum.cern.ch/t/tmva-roc-curve-extraction-and-modification/29395/4 "2018-06-18T07:55:23Z")

</div>

Hi,

You need to specify correctly the directory. I think you missing the top-level directory (this is normally the Name of the DataLoader class). You can do f1-\>ls() to see the name

Lorenzo

---

<div class="post-metadata">

**Author:** ![Roderfeen](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roderfeen/32/16484_2.png) [@Roderfeen](https://root-forum.cern.ch/u/Roderfeen)\
**Post date:** [June 19, 2018, 10:31am UTC](https://root-forum.cern.ch/t/tmva-roc-curve-extraction-and-modification/29395/5 "2018-06-19T10:31:08Z")

</div>

Thanks for the reply. That’s a good point, I’ve changed it to

```auto
TDirectory* dir = gFile->GetDirectory("./dataset/Method_KNN/KNN");

```

Unfortunately, this does not fix the error.

Should it help, this is the .root file:  
[fdmTMVA.root](https://root-forum.cern.ch/uploads/default/original/3X/a/d/ad843c5f5b070815d20cc7b694cc061a98fd746a.root) (1.2 MB)

I also cannot get to the directory via the root commandline. Am I using the wrong commands?

Thanks.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [June 19, 2018, 10:34am UTC](https://root-forum.cern.ch/t/tmva-roc-curve-extraction-and-modification/29395/6 "2018-06-19T10:34:26Z")

</div>

```auto
gFile->GetDirectory("/dataset/Method_KNN/KNN")->ls();
gFile->GetDirectory("dataset/Method_KNN/KNN")->ls();

```

---

<div class="post-metadata">

**Author:** ![Roderfeen](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roderfeen/32/16484_2.png) [@Roderfeen](https://root-forum.cern.ch/u/Roderfeen)\
**Post date:** [June 19, 2018, 10:46am UTC](https://root-forum.cern.ch/t/tmva-roc-curve-extraction-and-modification/29395/7 "2018-06-19T10:46:48Z")

</div>

Works! I was supplying it with the wrong directory then.

I’ve edited the original code in the first post to reflect this.

Thanks people.
