Code Crashing with RVecs


I have been following the RVecs tutorial. However, when I run the code on my own data, the code crashes and gives me a segmentation violation. I realize it might be a simple error; however, I haven’t been able to fix it, so I would really appreciate any help/fixes!

I am attaching the code with some sample data:

selectXXt.cpp (4.8 KB)

I don’t know if this helps in the search but when I tried to simplify my original code to this:

selectXX1.cpp (2.8 KB)

I get an empty canvas and the errors that

newerror.txt (6.6 KB)

I am not sure if it is related (since both codes use the same structure.)

Here is the example data:

Here is the example data
tag_1_delphes_events.root (475.1 KB)

(The only thing is that the branch names should probably be changed as I have it written in my code (Muon_PT, Muon_Eta, etc) However, I forgot how to do that :frowning:

Many thanks for all your help!

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

I can’t run your code, but Apparently there is a mismatch between the variables names and the names in the ROOT file. E.g I see Muon.PT in the file, and Muon_PT in your code (or did I miss something?). Anyway, maybe @eguiraud can try to run your code and give some hints

Hi @usernew ,
can you please share the simplest version of the code that reproduces the error in a form that we can run (e.g. with the correct branch names)?


Does anyone remember how to change the branch names. I recall I did it before, but now, I can’t remember how to do it.

Change their name in your code, not in the tree…

I’m trying to run selectXXt.cpp, I changed Muon_PT, Muon_eta etc. to Muon.PT and Muon.Eta (interestingly, Muon_size appears to be an actual column).

This is what I have so far (4.7 KB) , but it does not work because the expression (Muon.PT>5) && (abs(Muon.Eta)<2.4) is not a valid Filter: Muon.PT and Muon.Eta are arrays, so what that expression returns is an array, but filters need to return a bool. Maybe you wanted to

Define("good_muon_idx", "(Muon.PT>5) && (abs(Muon.Eta)<2.4)


In any case, because of these errors I cannot reproduce the segmentation fault you mentioned.

Please let us have a simple reproducer that we can just run against the data you shared so we can debug the issue.


Ok, thank you for changing the branch names in the code. (I tried that previously and my code wouldn’t work but now I figured it was how I was working with the RVecs structure initially; I apologize for that).

Ok, now that the branch names is taken care of, the next thing I tried was replace the Filter with the Define line you suggested and I still got the segmentation violation.

Here is the code that should produce the segmentation violation/crash.
selectXXtt.c (4.7 KB)

Please let me know if you would need anything else to help solve this issue!
Thank you very much!

Alright, I think you are encountering this bug. Luckily, I think the reason you are encountering the bug is that your logic is incorrect, and fixing it should fix the crash :smiley: . In these lines:

   //Filter interesting events                                                                                          
   auto df_base = selection_4mu(df);                                                                                    
   // Reconstruct Z systems                                                                                             
   auto df_z_idx = df.Define("Z_idx", reco_zz_to_4l, {"Muon.PT", "Muon.Eta", "Muon.Phi", "m", "Muon.Charge"});          
   // Compute masses of Z systems                                                                                       
   auto df_z_mass = df_z_idx.Define("Z_mass", compute_z_masses_4l, {"Z_idx", "Muon.PT", "Muon.Eta", "Muon.Phi", "m"});  
    // Reconstruct H mass                                                                                               
   auto df_h_mass = df_z_mass.Define("XX_mass", compute_XX_mass_4l, {"Z_idx", "Muon.PT", "Muon.Eta", "Muon.Phi", "m"}); 

note how the result of the selection is df_base, but then you have all other operations depend on df instead, so the selection step will be ignored. If you really don’t want the selection, you can remove that first line of code. If you do, then the second line of code should be df_base.Define("Z_idx", ...).

Also note that Histo1D<int> should be Histo1D<float> because XX_mass is a foat.

Fixed these 2 things there is one last problem: for some reason (that I’m investigating) RDataFrame cannot automatically figure out the type of Muon.PT, so (if you need selection_4mu) you have to change

auto df_kin = df_ge4m.Define("good_muon_idx", "(Muon.PT>5) && (abs(Muon.Eta)<2.4)");

to the equivalent (but with types explicitly spelled out)

auto df_kin = df_ge4m.Define("good_muon_idx", [](rvec_f pt, rvec_f eta) { return (pt > 5) && (abs(eta) < 2.4); }, {"Muon.PT", "Muon.Eta"});

With these three changes (unused result of selection_4mu, Histo1D<float> and type of Muon.PT explicitly spelled out in a function signature) the conde compiles and runs fine for me.

Hope this helps!

1 Like

It worked! Thank you!!

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