# Signal peaking on the wrong side?

**URL:** <https://root-forum.cern.ch/t/signal-peaking-on-the-wrong-side/35223>\
**Category:** TMVA\
**Created:** [July 16, 2019, 4:42pm UTC](https://root-forum.cern.ch/t/signal-peaking-on-the-wrong-side/35223 "2019-07-16T16:42:30Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![fiorini](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/e47c2d/32.png) [@fiorini](https://root-forum.cern.ch/u/fiorini)\
**Post date:** [July 16, 2019, 4:42pm UTC](https://root-forum.cern.ch/t/signal-peaking-on-the-wrong-side/35223/1 "2019-07-16T16:42:31Z")

</div>

Hello,  
I switched from ROOT 6.08 to 6.16 and I found a strange “feature” when training with BDT Gradient:  
The signal accumulated on the negative side of the score distribution, instead of the positive one.  
I checked that it is not a plotting issue, the ones in blue are really signal events and the one in red are background events.

Even if the actual score value is just a convention, this seems an unexpected behavior.  
If you confirm so, I can fill a bug report.

Best,  
Luca ![bdt](https://root-forum.cern.ch/uploads/default/original/3X/2/a/2aed4d0dcff767d1297063b8749e137d4b17d5cf.png)

---

<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:** [July 22, 2019, 8:14am UTC](https://root-forum.cern.ch/t/signal-peaking-on-the-wrong-side/35223/2 "2019-07-22T08:14:51Z")

</div>

Do you have some simple reproducer we can test both with 6.08 and 6.16 ?

---

<div class="post-metadata">

**Author:** ![fiorini](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/e47c2d/32.png) [@fiorini](https://root-forum.cern.ch/u/fiorini)\
**Post date:** [July 24, 2019, 5:30pm UTC](https://root-forum.cern.ch/t/signal-peaking-on-the-wrong-side/35223/3 "2019-07-24T17:30:05Z")

</div>

Hello,  
I send you the original dataset, because I failed to produce for you a smaller test sample:  
[https://cernbox.cern.ch/index.php/s/2ZpW3V8o7aG8DYH](https://cernbox.cern.ch/index.php/s/2ZpW3V8o7aG8DYH)

The factory book parameters I used for the BDT are:  
“!H:!V:NTrees=1000:MaxDepth=2:MinNodeSize=2.5%:nCuts=20:BoostType=Grad:UseBaggedBoost=true:Shrinkage=0.1:BaggedSampleFraction=0.5”

Let m know if you need more information.  
Luca.

---

<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:** [July 25, 2019, 1:02pm UTC](https://root-forum.cern.ch/t/signal-peaking-on-the-wrong-side/35223/4 "2019-07-25T13:02:12Z")

</div>

Hi,

I cannot reproduce this problem with the TMVA example code (e.g. TMVAClassification.C). I would need your full macro to reproduce this

Lorenzo

---

<div class="post-metadata">

**Author:** ![fiorini](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/e47c2d/32.png) [@fiorini](https://root-forum.cern.ch/u/fiorini)\
**Post date:** [July 27, 2019, 12:12pm UTC](https://root-forum.cern.ch/t/signal-peaking-on-the-wrong-side/35223/5 "2019-07-27T12:12:55Z")

</div>

Dear Lonrezo,

I was able to reproduce the problem with this modified version of TMVAClassification.C (attached)[TMVAClassification.C](https://root-forum.cern.ch/uploads/short-url/aJjOdzQZj8PJhXEGt9I5OzNoATG.C) (30.2 KB)

Can you please have a look?

Best Regards,  
Luca.

---

<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:** [July 29, 2019, 8:21am UTC](https://root-forum.cern.ch/t/signal-peaking-on-the-wrong-side/35223/6 "2019-07-29T08:21:31Z")

</div>

Hi,  
Can you please also attach or send a link to the input data ?  
Thank you

Lorenzo

---

<div class="post-metadata">

**Author:** ![fiorini](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/e47c2d/32.png) [@fiorini](https://root-forum.cern.ch/u/fiorini)\
**Post date:** [July 29, 2019, 8:55am UTC](https://root-forum.cern.ch/t/signal-peaking-on-the-wrong-side/35223/7 "2019-07-29T08:55:57Z")

</div>

Hello Lorenzo,

the input data was already provided on [Wed 24th July](https://root-forum.cern.ch/t/signal-peaking-on-the-wrong-side/35223/3) in this thread. See the message just above your first comment.

---

<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:** [July 29, 2019, 3:52pm UTC](https://root-forum.cern.ch/t/signal-peaking-on-the-wrong-side/35223/8 "2019-07-29T15:52:20Z")

</div>

Hi,

Sorry for this. Yes, I can reproduce now the problem, it is probably due to the fact you are adding signal and background events individually using `DataLoader::AddBackgroundTrainingEvent` and `DataLoader::AddSignalTrainingEvent`

I will check those functions.  
Thank you for reporting this and providing a way to reproduce this problem

Lorenzo

---

<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:** [July 29, 2019, 4:48pm UTC](https://root-forum.cern.ch/t/signal-peaking-on-the-wrong-side/35223/9 "2019-07-29T16:48:52Z")

</div>

I noticed this is happening only for BDTG and not BDT.  
Also it is dependent of the order of assigning first. If you are adding to the dataloader first the background event (or tree), you get this behaviour, if you are doing it with the signal you will get the correct plot.  
This is due to the definition of the class index in `TMVA::DataSetInfo`.  
Every method should be independent of that class index value, but thisis not the case for BDTG. This is then a bug and we will fix it.  
As a workaround make sure that the signal event are added first.  
For example in your macro addfirst the signal events and then the background ones:

```auto
   int ntrainEvts = trainTree->GetEntries();

   for (UInt_t i=0; i< ntrainEvts; i++) {
     trainTree->GetEntry(i);
     for (UInt_t ivar=0; ivar<11; ivar++) vars[ivar] = treevars[ivar];
     if (classID==1) dataloader->AddSignalTrainingEvent( vars, weight );
   }

 
   for (UInt_t i=0; i< ntrainEvts; i++) {
     trainTree->GetEntry(i);
     for (UInt_t ivar=0; ivar<11; ivar++) vars[ivar] = treevars[ivar];

     if (classID==0) dataloader->AddBackgroundTrainingEvent( vars, weight );
   }

```

Cheers

Lorenzo

---

<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:** [July 30, 2019, 6:08pm UTC](https://root-forum.cern.ch/t/signal-peaking-on-the-wrong-side/35223/10 "2019-07-30T18:08:05Z")

</div>

Hi,

The bug has been fixed in the ROOT master.  
Thank you for reporting it

Lorenzo

---

<div class="post-metadata">

**Author:** ![fiorini](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/e47c2d/32.png) [@fiorini](https://root-forum.cern.ch/u/fiorini)\
**Post date:** [July 31, 2019, 11:28am UTC](https://root-forum.cern.ch/t/signal-peaking-on-the-wrong-side/35223/11 "2019-07-31T11:28:41Z")

</div>

Dear Lorenzo,

thanks, I’m glad that this has been fixed.

Cheers,  
Luca.
