# Extracting ROC curve from a file and plotting it on a graph in root

**URL:** <https://root-forum.cern.ch/t/extracting-roc-curve-from-a-file-and-plotting-it-on-a-graph-in-root/51501>\
**Category:** TMVA\
**Created:** [September 8, 2022, 10:18am UTC](https://root-forum.cern.ch/t/extracting-roc-curve-from-a-file-and-plotting-it-on-a-graph-in-root/51501 "2022-09-08T10:18:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ema22](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Ema22](https://root-forum.cern.ch/u/Ema22)\
**Post date:** [September 8, 2022, 10:18am UTC](https://root-forum.cern.ch/t/extracting-roc-curve-from-a-file-and-plotting-it-on-a-graph-in-root/51501/1 "2022-09-08T10:18:08Z")

</div>

Hi,  
I’m trying to draw multiple ROC curves on one canvas in root. To be able to do that, first I need to extract ROC curves from the files. So far I tried the following code which I found:

// Open .root file  
TFile \*f1 = TFile::Open(“TMVA\_2022.root”);

// Set pointer to directory containing ROC-curve  
TDirectory\* dir = gFile-\>GetDirectory(“/dataset/plots”);

TString objectName( “rejBvsS” );  
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”);

But I get following error:  
Error in : Trying to dereference null pointer or trying to call routine taking non-null arguments.  
Execution of your code was aborted.  
ROOT\_prompt\_4:1:1: warning: null passed to a callee that requires a non-null argument [-Wnonnull]  
dir-\>GetObject(objectName,h);

It would be great if anyone has the solution to this problem. One person, as I saw, had the exact problem and the problem was that the top level directory wasn’t included, but that doesn’t seem to be the problem in my case. Thanks in advance for any help!

ROOT Version: 6.22.08  
\_Ubuntu Version: 20.04.4 LTS  
\_WSL

---

<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:** [September 8, 2022, 10:39am UTC](https://root-forum.cern.ch/t/extracting-roc-curve-from-a-file-and-plotting-it-on-a-graph-in-root/51501/2 "2022-09-08T10:39:48Z")

</div>

Maybe the “/dataset/plots” directory does not exist in the “TMVA\_2022.root” file.  
Try: `TDirectory *dir = gFile->GetDirectory("/dataset/plots", kTRUE);`

---

<div class="post-metadata">

**Author:** ![Ema22](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Ema22](https://root-forum.cern.ch/u/Ema22)\
**Post date:** [September 8, 2022, 10:56am UTC](https://root-forum.cern.ch/t/extracting-roc-curve-from-a-file-and-plotting-it-on-a-graph-in-root/51501/3 "2022-09-08T10:56:11Z")

</div>

Yes, you’re right it doesn’t exist. Can you direct me how to see the directories that are in the file?

---

<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:** [September 8, 2022, 1:54pm UTC](https://root-forum.cern.ch/t/extracting-roc-curve-from-a-file-and-plotting-it-on-a-graph-in-root/51501/4 "2022-09-08T13:54:50Z")

</div>

Try to execute: `rootls -1l "TMVA_2022.root:*"`

---

<div class="post-metadata">

**Author:** ![Ema22](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Ema22](https://root-forum.cern.ch/u/Ema22)\
**Post date:** [September 8, 2022, 6:28pm UTC](https://root-forum.cern.ch/t/extracting-roc-curve-from-a-file-and-plotting-it-on-a-graph-in-root/51501/5 "2022-09-08T18:28:35Z")

</div>

Everything works fine now, thanks for all the help!
