Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

ROOT TMVA::factory weights

  1. Aug 4, 2015 #1

    ChrisVer

    User Avatar
    Gold Member

    I have one question (simple I hope).
    In the TMVA factory one can set global weights by typing:

    Code (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:

    Code (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)
     
  2. jcsd
  3. Aug 4, 2015 #2

    mfb

    User Avatar
    2016 Award

    Staff: Mentor

    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.
     
  4. Aug 4, 2015 #3

    ChrisVer

    User Avatar
    Gold Member

    What do you mean by that?
     
  5. Aug 4, 2015 #4

    ChrisVer

    User Avatar
    Gold Member

    In my tree I have the histogram of weights, let's say it's called: "weight".
    If I try to write something like:
    Code (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 ?
     
  6. Aug 4, 2015 #5

    mfb

    User Avatar
    2016 Award

    Staff: Mentor

    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.
     
  7. Aug 4, 2015 #6

    ChrisVer

    User Avatar
    Gold Member

    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
    Code (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:
    Code (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.

    Code (C):

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

    factory->AddBackgroundTree( backgroundTraining, backgroundWeight, "Training" );
    factory->AddBackgroundTree( backgroundTesting, backgroundWeight, "Test" );
     
     
  8. Aug 4, 2015 #7

    mfb

    User Avatar
    2016 Award

    Staff: Mentor

    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)?
     
  9. Aug 4, 2015 #8

    ChrisVer

    User Avatar
    Gold Member

    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.


    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...
     
  10. Aug 4, 2015 #9

    mfb

    User Avatar
    2016 Award

    Staff: Mentor

    Omit it in the call of the method, not in terms of physics. Ideally it takes the weight you declared before.
    Was the output different from the code where you just used a weight of 1 without the other method before?
     
  11. Aug 5, 2015 #10

    ChrisVer

    User Avatar
    Gold Member


    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: Aug 5, 2015
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: ROOT TMVA::factory weights
  1. CuTee Simple factorial (Replies: 0)

  2. Fortran Factorials (Replies: 6)

  3. Factorial fortran 90 (Replies: 5)

Loading...