How can I use event-wise weights in the TMVA factory?

  • Thread starter Thread starter ChrisVer
  • Start date Start date
  • Tags Tags
    Root
Click For Summary

Discussion Overview

The discussion revolves around the use of event-wise weights in the TMVA (Toolkit for Multivariate Data Analysis) factory, focusing on how to implement and utilize these weights in the context of signal and background event training and testing. Participants explore the technical aspects of setting weight expressions and the implications of using global versus event-specific weights.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant questions how to use event-wise weights after setting them with commands like factory->SetWeightExpression.
  • Another participant suggests that elements of the tree can be accessed using methods like GetEntry or GetEvent, but clarification is sought on how to implement this.
  • A participant mentions encountering an error when trying to use a weight histogram in the AddBackgroundTree method, indicating a misunderstanding of the expected argument types.
  • Discussion arises about the necessity of background weights, with some participants arguing that omitting them could lead to discrepancies in variable distributions due to correlations.
  • Participants analyze the source code to understand the functionality of the SetBackgroundWeightExpression method and its relationship with other methods like AddTree.
  • One participant shares their experience of using a global signal weight and expresses concerns about the effectiveness of using a simple number for background weight, noting that it did not yield the desired similarity in distributions.
  • Another participant reflects on the differences in output when using a weight of 1 versus applying the background weight method, indicating a potential error in their previous approach.

Areas of Agreement / Disagreement

Participants express differing views on the necessity and impact of using background weights versus global weights, with no consensus reached on the best approach to take. The discussion remains unresolved regarding the optimal implementation of event-wise weights.

Contextual Notes

Participants reference specific lines in the source code to analyze the behavior of various methods, indicating a reliance on the underlying implementation details. There are mentions of unresolved mathematical steps and assumptions regarding the correlation of variables.

ChrisVer
Science Advisor
Messages
3,372
Reaction score
465
I have one question (simple I hope).
In the TMVA factory one can set global weights by typing:

C:
// global event weights (see below for setting event-wise weights)
Double_t signalWeight = 1.0;
Double_t backgroundWeight = 1.0;

And use them afterwards by calling their names signalWeight, backgroundWeight.

If I want to use event-wise weights, the code below uses the factory->SetBackgroundWeightExpression etc:

C:
factory->SetWeightExpression("EventWeight");
factory->SetSignalWeightExpression("EventWeight");
factory->SetBackgroundWeightExpression("EventWeight");

// This would set individual event weights (the variables defined in the
// expression need to exist in the original TTree)
// for signal : factory->SetSignalWeightExpression("weight1*weight2");
// for background: factory->SetBackgroundWeightExpression("weight1*weight2");

I was wondering, later on how can I use those weights? Should I put this whole command in position where "signalWeight" should be used?

Thanks. (https://hep.pa.msu.edu/wiki/pub/AtlasSingleTop/AnalysisVersion1405006Check/TMVAnalysis_test3.C)
 
Technology news on Phys.org
Well, you use elements of the tree, so you should be able to access them like everything else in the tree if you have to. GetEntry, GetEvent or whatever you like as method, together with a branch address set somewhere.
 
mfb said:
together with a branch address set somewhere.

What do you mean by that?
 
In my tree I have the histogram of weights, let's say it's called: "weight".
If I try to write something like:
C:
//BckgTraining is a string
factory->AddBackgroundTree(BckgTraining,
                           factory->SetBackgroundWeightExpression("weight") , "Training");

I am getting an error because the AddBackgroundTree expects to get a Double_t as a 2nd argument.
Or you mean that I could write:
weight->GetEntry ?
 
How do you access things in your tree in general?
There are multiple ways to do that.

I don't understand what your code example is supposed to do. The set method will probably return an integer as success message, and should be called exactly once to setup the readout.
 
It's pretty much the same as in the example of the link (https://hep.pa.msu.edu/wiki/pub/AtlasSingleTop/AnalysisVersion1405006Check/TMVAnalysis_test3.C)

My tree is in a root file, I open the file and use the commands
C:
TTree *signalTraining = (TTree*)inputTraining->Get("TMVAInputTree");
TTree *backgroundTraining = (TTree*)inputTraining->Get("TMVAInputTree");

TTree *signalTesting = (TTree*)inputTesting->Get("TMVAInputTree");
TTree *backgroundTesting = (TTree*)inputTesting->Get("TMVAInputTree");
The signal/bckg variable distributions are registered with AddVariable() or AddSpectator().

The thing is that when I read about weighting by event it gives that command with factory...

What I want to do... In the tree I have the signal and background events together with the weight histogram I want to use. I want to run the training/testing with weighting the background to the signal. In that case I could use a global signal weight:
C:
Double_t sig_weight = 1.0;
But I cannot use the global background weight 1.0... Instead I want to use the weight histogram values.

C:
factory->AddSignalTree( signalTraining, sig_weight, "Training" );
factory->AddSignalTree( signalTesting, sig_weight, "Test" );

factory->AddBackgroundTree( backgroundTraining, backgroundWeight, "Training" );
factory->AddBackgroundTree( backgroundTesting, backgroundWeight, "Test" );
 
Looking at the source, SetBackgroundWeightExpression sets some variable somewhere. There are so many AddTree methods that I don't see where something is actually done (probably in line 399, but where is this hidden?).

The background weight is optional - what happens if you just omit it?
What happens if you plug in a number, but call SetBackgroundWeightExpression before (compared to not calling it)?
 
mfb said:
The background weight is optional - what happens if you just omit it?

I don't think I want to omit it... If I do then there will be some differencies between the variables because they are correlated to the momenta. In particular the weight I got, was by trying to make the background and signal Pt distributions look the same.
I tried doing that with a simple number (with that call and a background weight=1.0) and OK, my BDT ran normally , but didn't get what I started for to get (it didn't work). I know it didn't because if it did, the resulted Pt variable distributions would look similar which wasn't the case.
mfb said:
Looking at the source, SetBackgroundWeightExpression sets some variable somewhere. There are so many AddTree methods that I don't see where something is actually done (probably in line 399, but where is this hidden?).

The one leads to the other... The:
AddBackgroundTree() (line 431) leads to AddTree (line 367 ) and that to AddTree of line 384 . I am not sure what is that in line 399...
 
ChrisVer said:
I don't think I want to omit it... If I do then there will be some differencies between the variables because they are correlated to the momenta. In particular the weight I got, was by trying to make the background and signal Pt distributions look the same.
Omit it in the call of the method, not in terms of physics. Ideally it takes the weight you declared before.
ChrisVer said:
I tried doing that with a simple number (with that call and a background weight=1.0) and OK, my BDT ran normally , but didn't get what I started for to get (it didn't work). I know it didn't because if it did, the resulted Pt variable distributions would look similar which wasn't the case.
Was the output different from the code where you just used a weight of 1 without the other method before?
 
  • #10
mfb said:
Was the output different from the code where you just used a weight of 1 without the other method before?
Hmmm...I just tried it and no they are different... If I understood how that method works, then probably I'd figure out the error.
 
Last edited:

Similar threads

Replies
11
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 18 ·
Replies
18
Views
7K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
1
Views
2K
Replies
37
Views
7K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K