Extracting variables from Delphes ROOT file


ROOT Version: 6.14/04
Platform: linuxx8664
Compiler: gcc


Hi,

I was trying to extract some variables from a ROOT file generated after Delphes simulation and write those into another ROOT file. As you know Delphes ROOT files contain Delphes TChain containing multiple Branches (like Particles, Electrons, etc.) that again contains multiple Leaves (different variables).
The output ROOT file with a TTree that contains Branches of different variables, i.e., Leaves only. But all the variables are showing 1entry only. I have attached the output file also.

I also tried writing a DATA file (.dat) and making a ROOT file of that. But that is also posing problems as the two different branches have different entries; like in my case Photon Branch has 9128 entries and MissingET has 10000. So the DATA file is getting erroneous and so is the ROOT file made from it.

Below is the code that contains both the codes, i.e., for Delphes ROOT to Simpler ROOT as well as Delphes ROOT to DATA file.

The two files that are attached are the macro and the output ROOT file, respectively. Any Delphes ROOT file can be used here as the input.

Summary

DelphesAnalysis.C (3.6 KB)

DelphesExtracted.root (6.2 KB)

Regards,
Saumyen

Hi,

I am extremely sorry to say that I made a very silly mistake in the above macro. I put the
outtree->Fill();
command outside the event loop.

After correction, it’s writing the entries of the branches.

But I came across another problem. While in the original ROOT file (i.e., in the Delphes ROOT file) for the Photon Branch the variables had entries 9128, in the newly extracted ROOT file the Photon variables also have 10000 entries. And due to this the Mean and Std Dev are also getting altered. I am attaching a screenshot of the output of these two files with the histograms of a variable.

Is there a way to make these two ROOT files consistent with each other?

I will be very thankful if helped to resolve this issue.

Regards,
Saumyen

It us difficult to run your macro because of some Delphes include missing. I get:

root [0] 
Processing DelphesAnalysis.C...
input_line_10:1:10: fatal error: 'libDelphes' file not found
#include "libDelphes"
         ^~~~~~~~~~~~
In file included from input_line_9:1:
/Users/couet/Downloads/DelphesAnalysis.C:3:10: fatal error: 'classes/DelphesClasses.h' file not found
#include "classes/DelphesClasses.h"
         ^~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/couet/Downloads/DelphesAnalysis.C:24:1: error: expected unqualified-id
##include "TVirtualPad.h"

so the problem is that the new file has 10000 entires instead of 9128 ?
Can you check the final values of your loops indices ? May be they are wrong.

Hi Olivier,

Thanks a lot for response!

If you run this macro from the Delphes installation directory it will run properly.

Regarding the 10000 events, I actually couldn’t explain the thing properly. Let me try once. The Delphes ROOT file that corresponds to the HEP process has 10000 events. But after Delphes simulation, the reconstructed photon branch has 9128 entries. Rest of the entries are empty as a result of (as I guess) showering. But the MissingET branch has all the entry, i.e., 10000. I wrote some leaves from the Photon Branch in a DATA file. A portion of that looks somewhat like as follows:

--------- New Event (9945) ---------
170.65	32.9839	-2.32727	2.21841
--------- New Event (9946) ---------
92.315	63.4838	-0.920232	-1.06961
--------- New Event (9947) ---------
--------- New Event (9948) ---------
41.6572	13.7071	1.77647	0.808839
--------- New Event (9949) ---------
88.5528	17.3491	-2.31347	-1.02044
--------- New Event (9950) ---------
34.3302	30.4173	-0.501941	-0.635938
--------- New Event (9951) ---------
--------- New Event (9952) ---------
54.7244	11.7467	-2.22016	-1.12757
--------- New Event (9953) ---------
126.32	120.102	-0.320413	-2.57039
--------- New Event (9954) ---------
22.3318	14.0582	-1.03773	-2.51931
--------- New Event (9955) ---------
--------- New Event (9956) ---------
--------- New Event (9957) ---------
146.723	41.489	1.93564	1.4095
--------- New Event (9958) ---------
44.6393	20.2618	1.42701	0.734545

You can see that for certain events (like 9947, 9951, etc) the entries are missing. But for the MissingET Branch it doesn’t happen as all the events are present there.
Now, in the same way, I wrote the specific variables of the new ROOT file and that looks like as below:

--------- New Event (9945) ---------
170.65	 32.9839 	 -2.32727	2.21841
--------- New Event (9946) ---------
92.315	 63.4838 	 -0.920232	-1.06961
--------- New Event (9947) ---------
92.315	 63.4838 	 -0.920232	-1.06961
--------- New Event (9948) ---------
41.6572	 13.7071 	 1.77647	0.808839
--------- New Event (9949) ---------
88.5528	 17.3491 	 -2.31347	-1.02044
--------- New Event (9950) ---------
34.3302	 30.4173 	 -0.501941	-0.635938
--------- New Event (9951) ---------
34.3302	 30.4173 	 -0.501941	-0.635938
--------- New Event (9952) ---------
54.7244	 11.7467 	 -2.22016	-1.12757
--------- New Event (9953) ---------
126.32	 120.102 	 -0.320413	-2.57039
--------- New Event (9954) ---------
22.3318	 14.0582 	 -1.03773	-2.51931
--------- New Event (9955) ---------
22.3318	 14.0582 	 -1.03773	-2.51931
--------- New Event (9956) ---------
22.3318	 14.0582 	 -1.03773	-2.51931
--------- New Event (9957) ---------
146.723	 41.489 	 1.93564	1.4095
--------- New Event (9958) ---------
44.6393	 20.2618 	 1.42701	0.734545

You can see those particular events contains the contents of the previous event. There’s no scope for this to happen for the other branch as all the events has entries.
Now how to get rid of this issue? I hope you get me this time. Is there a way by which I can ask the branch loop to skip in the cases when there’s no entry?

Thanks again.

Regards,
Saumyen

Hi Saumyen,
Thanks for the clarification. I think @pcanal may have some ideas about you problem.

Can you upload you the latest version of your script?

Hi pcanal,

Yes sure. Here is the updated macro:
DelphesAnalysis.C (3.9 KB)

If you want as a sample Delphes ROOT file, here you can find the one I’m working with:

Regards,
Saumyen

In that code you are storing only the last ‘missing ET’ and the last ‘photon’
of each entry/event. Essentially the code does:

for each event/entry
   read the data from the TTree
   for each 'missing ET'
       assign values into 'simple variable' so each iteration **overrides** the previous value
   for each 'photon'
       assign values into 'simple variable' so each iteration **overrides** the previous value
   store into the new TTree the 'current' value of the simple variable (i.e. the value assigned at the last iteration).

In order to preserve the data and the association of the data to entries/events (if that is needed) you will need to replace the simple variable by a container (for example a std::vector<Double_t>)

Thank you so much, Philippe, for the explanation and the advice.

I modified the macro a bit. But couldn’t implement that in the loop properly. Actually, I don’t know at all how to deal with this type of variables. I tried a few things but in vain. Can you help me writing the loop properly with vector<Double_t> type container to establish the association of the data to entries? Here is my macro:
DelphesAnalysis.C (4.7 KB)

With this I’m getting horrible results, the number of entries is of the order of (e+07). I know that I am making mistakes in constructing both the loops (event and specific particles). I did this after going through some examples, but no idea how these works, also didn’t get anything in the ROOT manual too. It will be very helpful if you direct me on how to do this.

With regards,
Saumyen

DelphesAnalysis.C (4.6 KB)

See new version …

Thanks, Philippe, but this doesn’t solve the problem. I’m still getting entries 5.0005e+07.
I tried running the Photon and MissingET branch separately inside two different event loop. But that also doesn’t solve the problem.
The reason for these many entries is, I guess, corresponding to every value of event number it’s considering all the photon numbers and event number being 10000 and 9128, it ends up in the value of the order e+07.


But the situation is corresponding to some events there is no entries for the Photon branch and it should skip writing anything for the Photon branch but keep writing for the MissingET branch.

I’m getting no idea how to do this. Can the Tree or Branch Cloning function be used to clone a leaf as a branch?

Regards,
Saumyen

In the “${ROOTSYS}/etc/system.rootrc” file (or in your own “${HOME}/.rootrc” file), try to set:

Hist.Precision.1D:           double

Hi Wile,

I tried what you suggested but that didn’t change anything.

Regards,
Saumyen

Hi Saumyen,

I am confused on whether the problem is that you are not plotting what you want or whether the data is wrongly copied.

The reason for these many entries is, I guess, corresponding to every value of event number it’s considering all the photon numbers and event number being 10000 and 9128, it ends up in the value of the order e+07.

This says, that there is roughly a single photon per event, is that really the case (i.e. is it what you mean).

How did you assert this number? What does the Draw command and the plot look like on the original data. What is the Draw command on the copied data?

Cheers,
Philippe.

Hi Philippe,

Yes, that is what I meant. There are some events from the generated 10000 events where there is no photon ( probably decayed to jets due to showering simulation). But for the MissingET has all the entries.

Now when I am copying only one branch (say, Photon) keeping the line outtree->Fill(); inside the branch loop, it’s giving the output correctly without using vector array container. But when I am adding also the MissingET branch, it’s starting to have the problem.
By the way, I am thinking about extracting the variables to a data (.dat) file (as the code was there also in the macro) with the ‘NaN’ character for the empty events and convert that to a ROOT file. But in that case, also I have no idea how to deal with ‘NaN’. I tried a code after looking at some post in the forum only. But that gave a hell lot of errors.

So, I am quite puzzled and stuck here. Any help to get me outta here will be appreciated.

Regards,
Saumyen

Hi Philippe,

Let me explain the problem once again. I have a ROOT file (Google drive link of the file is given earlier) generated via Delphes simulation. Now I want to extract some variables from multiple branches (Photon and MissingET in this case) and write them to another ROOT file with a Tree and Leaf-like Branches. I have in total 10k events in the tree.
Now with my earlier macro, I was getting 10k entries for all the variables while the Photon Branch has 9128 entries.
With your suggested Vector type array, I was getting entries of the order 5.0005e+07 and also from the title (Eph.Eph) of the histogram it looks like the problem not just of the huge number of entries but something else.
I am attaching here both the macros.

WithoutVectorArray.C (4.6 KB) WithVectorArray.C (3.8 KB)

Does it have anything to do with the Branch called Photon_size and MissingET_size just below the respective Branches? Or, the ‘@size’ leaves inside the respective Branches?

Regards,
Saumyen

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.