Delphes-root file or root for TMVA

Hi,

I am new here regarding using TMVA and root as well. I have many background processes and a specific signal, generated using madgraph(with pythia for showering/hadronization and delphes for detector simulation), My data files are .root files (the tree name is “Delphes”). could i use just delphes-root file especially when you need many variables inside a macro in order to use TMVA Or i need to produce another root file?if yes how?
Thank you in advance.

1 Like

Hi and welcome to the ROOT forum!

TMVA natively understands .root files and TTrees contained within. You can check out the TMVAClassification.C example (in your $ROOTSYS/tutorials/tmva directory and here)

You can add the branches of your Delphes tree to the dataloader and TMVA will read the data. You can even define combinations such as "myvar := branch1 + branch2".

Condensed:

   TFile * file = TFile::Open("/path/to/file.root");
   TTree * tree     = static_cast<TTree*>(input->Get("Delphes"));
   TMVA::Factory * factory = new TMVA::Factory("TestSetup", "<options>" );
   TMVA::DataLoader * dataloader = new TMVA::DataLoader("dataset");
   dataloader->AddVariable("branch/in/tree");
   dataloader->AddSignalTree(tree);
   dataloader->AddBackgroundTree(tree);

   // Here <sigcut> and <bkgcut> is a string convertible to a TCut, e.g. `"branch1 > 0.5 && branch2 != 0"`.
   dataloader->PrepareTrainingAndTestTree("<sigcut>", "<bkgcut>");

   // ... Do training here...

Cheers,
Kim

Hi Kim,
Thank you very much for your reply.
What i do not able to do is how i define a combination variables for example the invariant mass of the two leading b-jet from the branch. also i want to put some cuts on the defined variables. i followed your suggest and i tried to write a macro. as it’s uploaded.
Best regards
Hilal tmvatest.C (9.0 KB)

Hi,

To define a combination variable you can do like this (non-sensical example but the principle is valid):

dataloader->AddVariable("Combined := Jet.PT + MissingET", "Combined", 'F');

What kinds of cuts do you want to put? For global cuts on signal and background you can use:

dataloader->PrepareTrainingAndTestTree("<sigcut>", "<bkgcut>");

where "<sigcut>" is a string such as "Jet.PT < 2".

More complex cuts are better handled outside TMVA.

Finally I see that the call to dataloader->PrepareTrainingAndTestTree is missing from your macro. This is probably a mistake, this is where you control the creation of data that is fed to your ML algorithm! See here under “3.1.4 Preparing the training and test data” for more info.

Cheers,
Kim

Hi Kim,
thanks a lot, i will let you know when i do the requirement corrections.

Hi Kim,
Sorry for this late.
I added dataloader->PrepareTrainingAndTestTree to my macro and it is workingtmvatest.C (9.0 KB) .
But as i said before i want know how i can write one combined variable at least, like the invariant mass of the two leading b-jet because in delphes-root file there is just Jets.

Thanks in advance,
Hilal

Hi Hilal,

Could you explain in more detail how the proposed solution (i.e. AddVariable("combinded := part1 + part2")) fails you?

If there is information lacking in the delphes tree you need to either: look at the program that produced it and modify that accordingly; or talk to those who produced it and ask them to include the necessary information.

Cheers,
Kim

Hi Kim,
I mean that i am interested in b-jet not in all jets in order to do my combination (i.e. AddVariable("Eb1b2 := Eb1 + Eb2") ).
Indeed as you said i found that i have to produce another root file (from the original one) where i include all needed tree.
Thank you very much.
Hilal