# How to get ROC curve for TMVA::Reader?

**URL:** <https://root-forum.cern.ch/t/how-to-get-roc-curve-for-tmva-reader/39250>\
**Category:** TMVA\
**Created:** [May 4, 2020, 1:18pm UTC](https://root-forum.cern.ch/t/how-to-get-roc-curve-for-tmva-reader/39250 "2020-05-04T13:18:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![swanski82](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/d9b06d/32.png) [@swanski82](https://root-forum.cern.ch/u/swanski82)\
**Post date:** [May 4, 2020, 1:18pm UTC](https://root-forum.cern.ch/t/how-to-get-roc-curve-for-tmva-reader/39250/1 "2020-05-04T13:18:37Z")

</div>

Hi all,

I have trained the BDT and now have the weights. Then, I apply this to a mixed of signal and background events (data)

> Create TMVA::Reader and add BDT method from weight file  
> Read in data from tree
> 
> > For event in tree  
> > apply method  
> > store the BDT response and the corresponding variables to the output  
> > End for

and now I want find out the ROC curve as a check of its performance on the data events. My signal and background efficiency definition is basically eff = N(BDT)/N(S/B) as N(BDT) corresponds to the # of signal and background events passing BDT and N(S/B) all signal(S) and background(B) events. Basically, what is missing here is my S and B class in the tree. How can I store them?

Many thanks.

---

<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:** [May 5, 2020, 8:56am UTC](https://root-forum.cern.ch/t/how-to-get-roc-curve-for-tmva-reader/39250/2 "2020-05-05T08:56:56Z")

</div>

Hi,

Running the reader on all events for signal and background data you can get the vector of mva values for the two data sets. From those vectors you can create a ROCCurve class and get the graphics curve, see  
[https://root.cern.ch/doc/master/classTMVA\_1\_1ROCCurve.html](https://root.cern.ch/doc/master/classTMVA_1_1ROCCurve.html)

Lorenzo

---

<div class="post-metadata">

**Author:** ![jieunyoo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jieunyoo/32/36974_2.png) [@jieunyoo](https://root-forum.cern.ch/u/jieunyoo)\
**Post date:** [February 2, 2023, 1:55pm UTC](https://root-forum.cern.ch/t/how-to-get-roc-curve-for-tmva-reader/39250/3 "2023-02-02T13:55:48Z")

</div>

Hi @moneta I have my weights in an xml file. Is there an easy way to read them into a vector of weights? I am not sure how to read them in using:

TMVA::ROCCurve::ROCCurve (values, targets, weights).

It doesn’t seem to work with just TMVA::ROCCurve::ROCCurve (values, targets)

Thanks!

---

<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:** [February 6, 2023, 1:49pm UTC](https://root-forum.cern.ch/t/how-to-get-roc-curve-for-tmva-reader/39250/4 "2023-02-06T13:49:16Z")

</div>

Hi,  
The XML file does not contain the event weights, but the parameter of your method (NN or BDT). The event weights are normally included in your input data file.  
If your data are unweighted, you don’t need to provide the vector of weights, but if you use a vector all filled with ones, it will work too. In general for unweighted data, you should be able to use for the ROC curve, one of these 2 constructor:

```auto
 TMVA::ROCCurve::ROCCurve (values, targets)

```

Where values is a `std::vector<float>` with all th outputs of your ML method, and `targets` is a vector of bool (`true` for signal events and `false` for background events).

Or you can use

```auto
 TMVA::ROCCurve::ROCCurve (signal_values, background_values)

```

Where `signal_values` and `background_values` are `std::vector<float>` with the outputs of the signal and background events.

Best,

Lorenzo
