# How to use "GetROCCurve" with an existing loader folder

**URL:** <https://root-forum.cern.ch/t/how-to-use-getroccurve-with-an-existing-loader-folder/50109>\
**Category:** TMVA\
**Created:** [May 25, 2022, 2:16am UTC](https://root-forum.cern.ch/t/how-to-use-getroccurve-with-an-existing-loader-folder/50109 "2022-05-25T02:16:34Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jackhammer0102](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@Jackhammer0102](https://root-forum.cern.ch/u/Jackhammer0102)\
**Post date:** [May 25, 2022, 2:16am UTC](https://root-forum.cern.ch/t/how-to-use-getroccurve-with-an-existing-loader-folder/50109/1 "2022-05-25T02:16:34Z")

</div>

Hi, experts,

In the TMVA tutorial TMVA\_CNN\_Classification.C, there is this line in the end of the program:

auto c1 = factory.GetROCCurve(loader);

How do I use this function by itself when I already have an existing loader folder with my training and testing results? I would like to just plot some ROC curves without having to run the whole training and testing process. And also, this c1 is a TCanvas, is there anyway that I can get the ROC curve in a TGraph? I just want to set different x and y ranges, or if I can do it with the TCanvas?

Best Regards,  
Jackhammer

---

<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:** [May 25, 2022, 5:34am UTC](https://root-forum.cern.ch/t/how-to-use-getroccurve-with-an-existing-loader-folder/50109/2 "2022-05-25T05:34:14Z")

</div>

Welcome to the ROOT forum.  
I think @moneta can help you.

---

<div class="post-metadata">

**Author:** ![Jackhammer0102](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@Jackhammer0102](https://root-forum.cern.ch/u/Jackhammer0102)\
**Post date:** [June 1, 2022, 10:23pm UTC](https://root-forum.cern.ch/t/how-to-use-getroccurve-with-an-existing-loader-folder/50109/3 "2022-06-01T22:23:51Z")

</div>

Thank you for tagging an expert for me, but it’s been a week. I hope someone can give me some suggestions.

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [June 16, 2022, 7:27am UTC](https://root-forum.cern.ch/t/how-to-use-getroccurve-with-an-existing-loader-folder/50109/4 "2022-06-16T07:27:48Z")

</div>

Hi @Jackhammer0102 ,

thank you for the ping and sorry for the high latency. @moneta we need your help here 🙂

Cheers,  
Enrico

---

<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 16, 2022, 9:16am UTC](https://root-forum.cern.ch/t/how-to-use-getroccurve-with-an-existing-loader-folder/50109/5 "2022-06-16T09:16:04Z")

</div>

Hi ,  
Apologies for the delay in answering. I have missed your message.

When you have done your training, you can still compute the ROC curve, but you need to use the TMVA output file, which contains all the result of the training and testing.  
You can use either the TMVAGUI or the [TMVA::ROCCurve](https://root.cern.ch/doc/master/classTMVA_1_1ROCCurve.html) class using the output that is read from the file. If you need I can provide an example for the second case.  
The class itself returns a TGraph so you can customise the range

Cheers

Lorenzo

---

<div class="post-metadata">

**Author:** ![Jackhammer0102](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@Jackhammer0102](https://root-forum.cern.ch/u/Jackhammer0102)\
**Post date:** [June 16, 2022, 3:41pm UTC](https://root-forum.cern.ch/t/how-to-use-getroccurve-with-an-existing-loader-folder/50109/6 "2022-06-16T15:41:05Z")

</div>

Hi, Enrico,

Thank you so much for tagging the expert for me!

---

<div class="post-metadata">

**Author:** ![Jackhammer0102](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@Jackhammer0102](https://root-forum.cern.ch/u/Jackhammer0102)\
**Post date:** [June 16, 2022, 3:47pm UTC](https://root-forum.cern.ch/t/how-to-use-getroccurve-with-an-existing-loader-folder/50109/7 "2022-06-16T15:47:56Z")

</div>

Hi, Lorenzo,

That’s totally fine, and thank you for the reply!  
I would really appreciate if you could show me an example on how to use TMVA::ROCCurve to make ROC curves using the TMVA output file.

Best Regards,  
Jackhammer

---

<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 16, 2022, 5:14pm UTC](https://root-forum.cern.ch/t/how-to-use-getroccurve-with-an-existing-loader-folder/50109/8 "2022-06-16T17:14:24Z")

</div>

Hi,  
Here is an example using the output file after running the tutorial [TMVA\_Higgs\_Classification.C](https://root.cern.ch/doc/master/TMVA __Higgs__ Classification_8C.html):

```auto
TFile f("Higgs_ClassificationOutput.root"); // open output file created after training
t = (TTree*) f.Get("dataset/TestTree"); // use test tree 
t->Print();
// get BDT signal result
size_t ns = t->Draw("BDT","classID==0");
std::vector<float> bdt_s(t->GetV1(), t->GetV1()+ns);    
// get BDT background result
size_t nb = t->Draw("BDT","classID==1");
std::vector<float> bdt_b(t->GetV1(), t->GetV1()+nb);
TMVA::ROCCurve roc(bdt_s, bdt_b);
TGraph * g = roc.GetROCCurve();
// you can now change the graph as you wish
g->SetLineColor(kRed); 
g->Draw("AL");

```

Lorenzo

---

<div class="post-metadata">

**Author:** ![Jackhammer0102](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@Jackhammer0102](https://root-forum.cern.ch/u/Jackhammer0102)\
**Post date:** [June 17, 2022, 3:39am UTC](https://root-forum.cern.ch/t/how-to-use-getroccurve-with-an-existing-loader-folder/50109/9 "2022-06-17T03:39:30Z")

</div>

> [@moneta](#):
>
> Lorenzo

Hi, Lorenzo,

Thank you for the example, it was very helpful and I’ve successfully plotted out the ROC curve for my BDT test tree, but I am having a hard time trying to plot other ROC curves all together. I also have DNN and CNN in the same TMVA output file, how can I plot all of them in one graph?

I did this but I didn’t get three ROC curves in one graph, I only got one ROC curve:

```auto
  // Get BDT signal result
  size_t ns_bdt = testTree->Draw("BDT", "classID==0");
  std::vector<float> s_bdt(testTree->GetV1(), testTree->GetV1()+ns_bdt);
  // Get BDT background result
  size_t nb_bdt = testTree->Draw("BDT", "classID==1");
  std::vector<float> b_bdt(testTree->GetV1(), testTree->GetV1()+nb_bdt);
  // TGraph ROC curve for BDT
  TMVA::ROCCurve roc_bdt(s_bdt, b_bdt);
  TGraph *g_bdt = roc_bdt.GetROCCurve();

  // Get CNN signal result
  size_t ns_cnn = testTree->Draw("TMVA_CNN_CPU", "classID==0");
  std::vector<float> s_cnn(testTree->GetV1(), testTree->GetV1()+ns_cnn);
  // Get CNN background result
  size_t nb_cnn = testTree->Draw("TMVA_CNN_CPU", "classID==1");
  std::vector<float> b_cnn(testTree->GetV1(), testTree->GetV1()+nb_cnn);
  // TGraph ROC curve for CNN
  TMVA::ROCCurve roc_cnn(s_cnn, b_cnn);
  TGraph *g_cnn = roc_cnn.GetROCCurve();

  // Get DNN signal result
  size_t ns_dnn = testTree->Draw("TMVA_DNN_CPU", "classID==0");
  std::vector<float> s_dnn(testTree->GetV1(), testTree->GetV1()+ns_dnn);
  // Get DNN background result
  size_t nb_dnn = testTree->Draw("TMVA_DNN_CPU", "classID==1");
  std::vector<float> b_dnn(testTree->GetV1(), testTree->GetV1()+nb_dnn);
  // TGraph ROC curve for DNN
  TMVA::ROCCurve roc_dnn(s_dnn, b_dnn);
  TGraph *g_dnn = roc_dnn.GetROCCurve();

  // Draw TGraph ROC curves
  g_bdt->Draw("AL");
  g_cnn->Draw("AL, same");
  g_dnn->Draw("AL, same");

```

---

<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 17, 2022, 8:02am UTC](https://root-forum.cern.ch/t/how-to-use-getroccurve-with-an-existing-loader-folder/50109/10 "2022-06-17T08:02:27Z")

</div>

Hi,  
You should use the `A` option in TGraph::Draw (draw axis) only for the first one. Do:

```auto
g_bdt->Draw("AL");
  g_cnn->Draw("L,");
  g_dnn->Draw("L");

```

or you can use the TMuktiGraph class, see [ROOT: tutorials/graphs/multigraph.C File Reference](https://root.cern.ch/doc/master/multigraph_8C.html)

Lorenzo

---

<div class="post-metadata">

**Author:** ![Jackhammer0102](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@Jackhammer0102](https://root-forum.cern.ch/u/Jackhammer0102)\
**Post date:** [June 17, 2022, 8:23am UTC](https://root-forum.cern.ch/t/how-to-use-getroccurve-with-an-existing-loader-folder/50109/11 "2022-06-17T08:23:33Z")

</div>

Hi, Lorenzo,

Now it works, thank you so much for your help, I really appreciate that!

Best Regards,  
Jackhammer
