# Plotting distributions of input variables for a specific final state particle

**URL:** <https://root-forum.cern.ch/t/plotting-distributions-of-input-variables-for-a-specific-final-state-particle/33753>\
**Category:** TMVA\
**Created:** [April 24, 2019, 6:14pm UTC](https://root-forum.cern.ch/t/plotting-distributions-of-input-variables-for-a-specific-final-state-particle/33753 "2019-04-24T18:14:15Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saumyenk](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/3bc359/32.png) [@Saumyenk](https://root-forum.cern.ch/u/Saumyenk)\
**Post date:** [April 24, 2019, 6:14pm UTC](https://root-forum.cern.ch/t/plotting-distributions-of-input-variables-for-a-specific-final-state-particle/33753/1 "2019-04-24T18:14:15Z")

</div>

Hello,  
I am new to TMVA and facing some problem in dealing with the input variables.  
When I am declaring the input variables for example ‘Energy’, and ‘PT’ and running the classification macro, I am getting some distributions of the input variables. I can’t understand the distribution of a variable corresponds to which final state particle. In my case, there are 3 final state particles.  
I have converted the .root file from .lhe file generated by MG5 using ExRootAnalysis.

I will be really grateful if this problem gets solved.

Regards,  
Saumyen

---

<div class="post-metadata">

**Author:** ![kialbert](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kialbert/32/16537_2.png) [@kialbert](https://root-forum.cern.ch/u/kialbert)\
**Post date:** [April 24, 2019, 6:26pm UTC](https://root-forum.cern.ch/t/plotting-distributions-of-input-variables-for-a-specific-final-state-particle/33753/2 "2019-04-24T18:26:38Z")

</div>

Hi,

I think it would be helpful if you would post the plots to which you are referring and explain what you expect them to look like.

Additionally, I am curious what the branch/leaf structure of your root file is, and what you expect it to be.

Without this information it is difficult to give an appropriate answer.

Cheers,  
Kim

---

<div class="post-metadata">

**Author:** ![Saumyenk](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/3bc359/32.png) [@Saumyenk](https://root-forum.cern.ch/u/Saumyenk)\
**Post date:** [April 25, 2019, 11:46am UTC](https://root-forum.cern.ch/t/plotting-distributions-of-input-variables-for-a-specific-final-state-particle/33753/3 "2019-04-25T11:46:19Z")

</div>

Hi Kim  
You can look at the picture below where you can see four histograms of the four input variables, respectively, ‘Energy’, ‘Transverse momenta’, ‘rapidity’ and ‘azimuthal angle’. I defined the variables using the following commands:

dataloader-\>AddVariable( “myvar1 := E”,“Energy”,"", ‘F’ );  
dataloader-\>AddVariable( “myvar2 := PT”, “Transverse Momenta”, “”, ‘F’ );  
dataloader-\>AddVariable( “Eta”, “rapidity”, “units”, ‘F’ );  
dataloader-\>AddVariable( “Phi”, “azimuthal angle”, “units”, ‘F’ );

Now in my process, there are three particles in the final states. My question is that the variables that are plotted correspond to which particle? Is there a way that I decide (for example) to have an energy distribution of particle-3 only?

 ![variables_id_c1](https://root-forum.cern.ch/uploads/default/original/3X/4/c/4c0a3732d67d847b7ffbcd38e7a3dd9235a23da7.png)

I could see that the variables are written as ‘double\_t’ variables in arrays. As you can see in the snap below.

 ![LHEF_Tree](https://root-forum.cern.ch/uploads/default/original/3X/7/9/79414fe12625ae791177a4849068a51721f851b5.jpeg)

Regards,

Saumyen

---

<div class="post-metadata">

**Author:** ![kialbert](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kialbert/32/16537_2.png) [@kialbert](https://root-forum.cern.ch/u/kialbert)\
**Post date:** [April 25, 2019, 12:11pm UTC](https://root-forum.cern.ch/t/plotting-distributions-of-input-variables-for-a-specific-final-state-particle/33753/4 "2019-04-25T12:11:24Z")

</div>

Hi,

I think I understand a bit better now what it is you want to do, and for these things the TMVA automatic plotting might not be the best approach. This since TMVA uses a fixed plotting pipeline.

A better approach at this stage might be to construct a histogram with the information you want directly.

Directly in the shell:

```auto
$ root -l somefile.root
root [0] auto tree = static_cast<TTree *>(_file0->Get("path/to/tree"))
root [1] tree->Draw("E", "particleID==3")

```

The cut expression `"particleID==3"` can of course be customised to e.g. incorporate your background selection.

Cheers,  
Kim

---

<div class="post-metadata">

**Author:** ![Saumyenk](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/3bc359/32.png) [@Saumyenk](https://root-forum.cern.ch/u/Saumyenk)\
**Post date:** [May 10, 2019, 9:44am UTC](https://root-forum.cern.ch/t/plotting-distributions-of-input-variables-for-a-specific-final-state-particle/33753/5 "2019-05-10T09:44:41Z")

</div>

Hi Kim,  
I tried as per your suggestion. But in this case I’m getting error messages. When I entered

> $ root -l bg.root

I got the warning message:

> root [0]  
> Attaching file /home/pdas/codes/bg.root as \_file0…  
> Warning in TClass::Init: no dictionary for class TRootLHEFEvent is available  
> Warning in TClass::Init: no dictionary for class TRootWeight is available  
> Warning in TClass::Init: no dictionary for class TRootLHEFParticle is available  
> Warning in TClass::Init: no dictionary for class TSortableObject is available  
> (TFile \*) 0x1d5c520

Next, when I applied

> root [1] auto tree = static\_cast\<TTree \*\>(\_file0-\>Get(“bg.root”))

I got :

> (TTree \*) nullptr

And when I wrote

> root [2] tree-\>Draw(“E”, “particleID==22”)

I got:

> #0 0x00007f46c21a907a in \_\_GI\_\_\_waitpid (pid=8626, stat\_loc=stat\_loc  
> entry=0x7ffcf9cee730, options=options  
> entry=0) at …/sysdeps/unix/sysv/linux/waitpid.c:29  
> #1 0x00007f46c2121fbb in do\_system (line=) at …/sysdeps/posix/system.c:148  
> #2 0x00007f46c2d844a2 in TUnixSystem::Exec (shellcmd=, this=0x12ae570) at /home/pdas/HEP\_Packages/root-6.14.04/core/unix/src/TUnixSystem.cxx:2119  
> #3 TUnixSystem::StackTrace (this=0x12ae570) at /home/pdas/HEP\_Packages/root-6.14.04/core/unix/src/TUnixSystem.cxx:2413  
> #4 0x00007f46bd714dc5 in cling::MultiplexInterpreterCallbacks::PrintStackTrace() () from /usr/local/lib/libCling.so  
> #5 0x00007f46bd71487b in cling\_runtime\_internal\_throwIfInvalidPointer () from /usr/local/lib/libCling.so  
> #6 0x00007f46c337d071 in ?? ()  
> #7 0x00007ffcf9cf0bd0 in ?? ()  
> #8 0x0000000001327eb0 in ?? ()  
> #9 0x00000000021f7fd0 in ?? ()  
> #10 0x00007f46c216153c in \_\_GI\_\_\_libc\_free (mem=) at malloc.c:2968  
> #11 0x00007f46bd7158dc in cling::Interpreter::RunFunction(clang::FunctionDecl const\*, cling::Value\*) [clone .part.290] [clone .constprop.445] () from /usr/local/lib/libCling.so  
> #12 0x00007f46bd71a3b3 in cling::Interpreter::EvaluateInternal(std::\_\_cxx11::basic\_string\<char, std::char\_traits, std::allocator \> const&, cling::CompilationOptions, cling::Value\*, cling::Transaction\*\*, unsigned long) () from /usr/local/lib/libCling.so  
> #13 0x00007f46bd71a65c in cling::Interpreter::process(std::\__cxx11::basic\_string\<char, std::char\_traits, std::allocator \> const&, cling::Value\*, cling::Transaction\*\*, bool) () from /usr/local/lib/libCling.so  
> #14 0x00007f46bd7a7897 in cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value\*, bool) () from /usr/local/lib/libCling.so  
> #15 0x00007f46bd68a7ba in HandleInterpreterException (metaProcessor=0x1532e10, input\_line=0x220e9a0 “#line 1 "ROOT\_prompt\_3"\ntree-\>Draw("E", "particleID==22")”, compRes=  
> 0x7ffcf9cf0fac: cling::Interpreter::kSuccess, result=result  
> entry=0x7ffcf9cf0fc0) at /home/pdas/HEP\_Packages/root-6.14.04/core/metacling/src/TCling.cxx:2060  
> #16 0x00007f46bd69f5a4 in TCling::ProcessLine (this=0x131fb10, line=, error=0x7ffcf9cf14dc) at /home/pdas/HEP\_Packages/root-6.14.04/core/metacling/src/TCling.cxx:2218  
> #17 0x00007f46c2c3447b in TApplication::ProcessLine (this=this  
> entry=0x12e8670, line=, sync=sync  
> entry=false, err=err  
> entry=0x7ffcf9cf14dc) at /home/pdas/HEP\_Packages/root-6.14.04/core/base/src/TApplication.cxx:1021  
> #18 0x00007f46c30c90de in TRint::ProcessLineNr (this=this  
> entry=0x12e8670, filestem=filestem  
> entry=0x7f46c30da87f "ROOT\_prompt_", line=0x21e8cc0 “tree-\>Draw("E", "particleID==22")”, error=0x7ffcf9cf14dc, error  
> entry=0x0) at /home/pdas/HEP\_Packages/root-6.14.04/core/rint/src/TRint.cxx:741  
> #19 0x00007f46c30c9465 in TRint::HandleTermInput (this=0x12e8670) at /home/pdas/HEP\_Packages/root-6.14.04/core/rint/src/TRint.cxx:602  
> #20 0x00007f46c2d8617c in TUnixSystem::CheckDescriptors (this=this  
> entry=0x12ae570) at /home/pdas/HEP\_Packages/root-6.14.04/core/unix/src/TUnixSystem.cxx:1322  
> #21 0x00007f46c2d876fa in TUnixSystem::DispatchOneEvent (this=0x12ae570, pendingOnly=) at /home/pdas/HEP\_Packages/root-6.14.04/core/unix/src/TUnixSystem.cxx:1077  
> #22 0x00007f46c2ca3161 in TSystem::InnerLoop (this=0x12ae570) at /home/pdas/HEP\_Packages/root-6.14.04/core/base/src/TSystem.cxx:411  
> #23 TSystem::Run (this=0x12ae570) at /home/pdas/HEP\_Packages/root-6.14.04/core/base/src/TSystem.cxx:361  
> #24 0x00007f46c2c317cf in TApplication::Run (this=this  
> entry=0x12e8670, retrn=retrn  
> entry=false) at /home/pdas/HEP\_Packages/root-6.14.04/core/base/src/TApplication.cxx:1173  
> #25 0x00007f46c30cac1b in TRint::Run (this=this  
> entry=0x12e8670, retrn=retrn  
> entry=false) at /home/pdas/HEP\_Packages/root-6.14.04/core/rint/src/TRint.cxx:455  
> #26 0x000000000040099a in main (argc=1, argv=0x7ffcf9cf3938) at /home/pdas/HEP\_Packages/root-6.14.04/main/src/rmain.cxx:30  
> Error in : Trying to dereference null pointer or trying to call routine taking non-null arguments.  
> Execution of your code was aborted.  
> ROOT\_prompt\_3:1:1: warning: null passed to a callee that requires a non-null argument [-Wnonnull]  
> tree-\>Draw(“E”, “particleID==22”)  
> ^~~~

I don’t understand what’s wrong (actually, I’m new to ROOT as well as TMVA).

Regards,  
Saumyen

---

<div class="post-metadata">

**Author:** ![kialbert](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kialbert/32/16537_2.png) [@kialbert](https://root-forum.cern.ch/u/kialbert)\
**Post date:** [May 10, 2019, 10:11am UTC](https://root-forum.cern.ch/t/plotting-distributions-of-input-variables-for-a-specific-final-state-particle/33753/6 "2019-05-10T10:11:23Z")

</div>

Hi,

You need to pass te path to the TTree, not the path to the rootfile.

Use `_file0->ls()` to explore your file. (Or `rootls bg.root` from the command line.)

Cheers,  
Kim

---

<div class="post-metadata">

**Author:** ![usernew](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/ccd318/32.png) [@usernew](https://root-forum.cern.ch/u/usernew)\
**Post date:** [September 6, 2019, 11:09pm UTC](https://root-forum.cern.ch/t/plotting-distributions-of-input-variables-for-a-specific-final-state-particle/33753/7 "2019-09-06T23:09:28Z")

</div>

Hello, I get the same error as you got. How did you fix it?

---

<div class="post-metadata">

**Author:** ![usernew](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/ccd318/32.png) [@usernew](https://root-forum.cern.ch/u/usernew)\
**Post date:** [September 6, 2019, 11:10pm UTC](https://root-forum.cern.ch/t/plotting-distributions-of-input-variables-for-a-specific-final-state-particle/33753/8 "2019-09-06T23:10:14Z")

</div>

Hello, I am new to ROOT. Do you mind explaining more how I can fix the error from this forum

---

<div class="post-metadata">

**Author:** ![kialbert](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kialbert/32/16537_2.png) [@kialbert](https://root-forum.cern.ch/u/kialbert)\
**Post date:** [September 10, 2019, 5:58pm UTC](https://root-forum.cern.ch/t/plotting-distributions-of-input-variables-for-a-specific-final-state-particle/33753/9 "2019-09-10T17:58:58Z")

</div>

Hi and welcome to the forum!

Please note that in general it is better to post a new question instead of reviving an old one.

`TFile::Get` expects the path to an object _within the file_ and returns a pointer to it. The error was that the original poster passed the filename instead like so:

```auto
// Warning: Incorrect version!
auto file = TFile::Open("path/to/file.root");
auto tree = static_cast<TTree *>(file->Get("path/to/file.root"))

```

instead of the correct version:

```auto
// Correct version!
auto file = TFile::Open("path/to/file.root");
auto tree = static_cast<TTree *>(file->Get("path/to/ttree"))

```

The structure of a `.root` file can be explored with `rootbrowse path/to/file.root`.

Cheers,  
Kim

---

<div class="post-metadata">

**Author:** ![usernew](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/ccd318/32.png) [@usernew](https://root-forum.cern.ch/u/usernew)\
**Post date:** [September 10, 2019, 8:02pm UTC](https://root-forum.cern.ch/t/plotting-distributions-of-input-variables-for-a-specific-final-state-particle/33753/10 "2019-09-10T20:02:49Z")

</div>

Thank you for the clarification!
