Home | News | Documentation | Download

Issue running same macro multiple times (segmentation violation)


#1

Hi all,

I made a macro to retrieve data from a .root file and analyse the histograms inside it. Until today, it worked flawlessly. However, after I made a backup of the file today, the file doesn’t want to run multiple consecutive times anymore. This means that I start up root, and type “.x Analyze.C” to run the macro. This works fine. I then close root, restart root and type the exact same thing (no changes have been made to the macro) and it gives me the errors listed below. The interesting thing I find though, is that if I copy paste the text of the “Analyze.C” macro into a new file say “test.C”, running that file through root works right away, but yet again, only the first time. After that it gives me the same errors. I’m running ROOT6 on Linux. If I need to provide more information, please let me know. Thanks a lot for the help!

The error:

    ------------------------------------------------------------
  | Welcome to ROOT 6.10/08                 |
  |                               (c) 1995-2017, The ROOT Team |
  | Built for linuxx8664gcc                                    |
  | From tag v6-10-08, 16 October 2017                         |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------

root [0] .x Analyze.C 

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f01730d007a in __GI___waitpid (pid=2214, stat_loc=stat_loc
entry=0x7ffc0ba561c0, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:29
#1  0x00007f0173048fbb in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:148
#2  0x00007f0173c4c15d in TUnixSystem::Exec (shellcmd=<optimized out>, this=0x1acd4f0) at /data/alisoft/root/v6-10-08/src/core/unix/src/TUnixSystem.cxx:2118
#3  TUnixSystem::StackTrace (this=0x1acd4f0) at /data/alisoft/root/v6-10-08/src/core/unix/src/TUnixSystem.cxx:2412
#4  0x00007f0173c4e74c in TUnixSystem::DispatchSignals (this=0x1acd4f0, sig=kSigSegmentationViolation) at /data/alisoft/root/v6-10-08/src/core/unix/src/TUnixSystem.cxx:3643
#5  <signal handler called>
#6  0x00007f01743c9b75 in ?? ()
#7  0x0000000002a92c30 in ?? ()
#8  0x0000000004823a40 in ?? ()
#9  0x00000000038b8ce0 in ?? ()
#10 0x00000000038ad830 in ?? ()
#11 0x00000000038ad340 in ?? ()
#12 0x00000000038ace50 in ?? ()
#13 0x00000000038aca00 in ?? ()
#14 0x0000000004826730 in ?? ()
#15 0x0000000004826240 in ?? ()
#16 0x0000000004825db0 in ?? ()
#17 0x000000000407b330 in ?? ()
#18 0x0000000004825920 in ?? ()
#19 0x000000000407ae10 in ?? ()
#20 0x00000000038b7ce0 in ?? ()
#21 0x00000000038b7850 in ?? ()
#22 0x00000000038b73c0 in ?? ()
#23 0x00000000038b6f30 in ?? ()
#24 0x00000000038bb820 in ?? ()
#25 0x00000000038bb390 in ?? ()
#26 0x00000000038b5e10 in ?? ()
#27 0x00000000038bae40 in ?? ()
#28 0x00000000038b65a0 in ?? ()
#29 0x00000000137dd170 in ?? ()
#30 0xffffffffffffffff in ?? ()
#31 0x006d45636f6c6c41 in ?? ()
#32 0x4086980000000000 in ?? ()
#33 0x40a5b40000000000 in ?? ()
#34 0x4098d00000000000 in ?? ()
#35 0x409fd80000000000 in ?? ()
#36 0x40a5460000000000 in ?? ()
#37 0x40ab8c0000000000 in ?? ()
#38 0x40a7b20000000000 in ?? ()
#39 0x0000000000000000 in ?? ()
===========================================================


The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum.
Only if you are really convinced it is a bug in ROOT then please submit a
report at http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#6  0x00007f01743c9b75 in ?? ()
#7  0x0000000002a92c30 in ?? ()
#8  0x0000000004823a40 in ?? ()
#9  0x00000000038b8ce0 in ?? ()
#10 0x00000000038ad830 in ?? ()
#11 0x00000000038ad340 in ?? ()
#12 0x00000000038ace50 in ?? ()
#13 0x00000000038aca00 in ?? ()
#14 0x0000000004826730 in ?? ()
#15 0x0000000004826240 in ?? ()
#16 0x0000000004825db0 in ?? ()
#17 0x000000000407b330 in ?? ()
#18 0x0000000004825920 in ?? ()
#19 0x000000000407ae10 in ?? ()
#20 0x00000000038b7ce0 in ?? ()
#21 0x00000000038b7850 in ?? ()
#22 0x00000000038b73c0 in ?? ()
#23 0x00000000038b6f30 in ?? ()
#24 0x00000000038bb820 in ?? ()
#25 0x00000000038bb390 in ?? ()
#26 0x00000000038b5e10 in ?? ()
#27 0x00000000038bae40 in ?? ()
#28 0x00000000038b65a0 in ?? ()
#29 0x00000000137dd170 in ?? ()
#30 0xffffffffffffffff in ?? ()
#31 0x006d45636f6c6c41 in ?? ()
#32 0x4086980000000000 in ?? ()
#33 0x40a5b40000000000 in ?? ()
#34 0x4098d00000000000 in ?? ()
#35 0x409fd80000000000 in ?? ()
#36 0x40a5460000000000 in ?? ()
#37 0x40ab8c0000000000 in ?? ()
#38 0x40a7b20000000000 in ?? ()
#39 0x0000000000000000 in ?? ()
===========================================================

#2

That sounds really weird. Can you provide a small reproducer ?
As it is on windows @bellenot may have some idea about it.


#3

Hi couet,

Would you like me to post my full macro in here? It isn’t ridiculously big. If not, I do not understand what you mean by reproducer.


#4

Actually you are running on linux. You must be on Ubuntu.

To help you we will need some macro reproducing the problem.

Can you make the smallest possible macro reproducing the problem ?


#5

So, it’s very inconsistent, but this is the smallest I can make for which it is consistent. If I make it smaller, sometimes it will work, and sometimes it won’t. Also, I’m not a master programmer, so it might not be as efficient as possible. It’s weird though, as I am only defining some variables and histograms here. Do you need the .root file from which it gets its data as well? Or is that not necessary?

The macro:

#include "TInterpreter.h"
#include "TCanvas.h"
#include "TSystem.h"
#include "TFile.h"
#include "TH2.h"
#include "TNtuple.h"
#include "TPaveLabel.h"
#include "TPaveText.h"
#include "TFrame.h"
#include "TSystem.h"
#include "TInterpreter.h"

void Analyze2()
{
  TFile *MyFile = TFile::Open("./Results/Results_pions_nov21_25mevents.root");
  if(!MyFile || MyFile->IsZombie())
    {
      cout << "failed to load" << endl;
      return;
    }

  Float_t numberbins = 500; //Histograms get rebinned using this variable
  
//===========================DECLARATIONS OF HISTOGRAMS AND CANVAS==============================//
  TH1F *pt_pion_ds_1_H      = (TH1F*)MyFile->Get("pt_soft_pion_ds_1_H;1");  //These histograms show PT of softpions in intervals
  TH1F *pt_pion_ds_2_H      = (TH1F*)MyFile->Get("pt_soft_pion_ds_2_H;1");  //of D* PT.
  TH1F *pt_pion_ds_3_H      = (TH1F*)MyFile->Get("pt_soft_pion_ds_3_H;1");
  TH1F *pt_pion_ds_4_H      = (TH1F*)MyFile->Get("pt_soft_pion_ds_4_H;1");
  TH1F *pt_pion_ds_5_H      = (TH1F*)MyFile->Get("pt_soft_pion_ds_5_H;1");
  TH1F *pt_pion_ds_6_H      = (TH1F*)MyFile->Get("pt_soft_pion_ds_6_H;1");
  TH1F *pt_pion_ds_7_H      = (TH1F*)MyFile->Get("pt_soft_pion_ds_7_H;1");
  TH1F *pt_pion_ds_8_H      = (TH1F*)MyFile->Get("pt_soft_pion_ds_8_H;1");
  

  TH1F *pt_pion_ds_1_H_copy = (TH1F*)pt_pion_ds_1_H->Clone();
  TH1F *pt_pion_ds_2_H_copy = (TH1F*)pt_pion_ds_2_H->Clone();
  TH1F *pt_pion_ds_3_H_copy = (TH1F*)pt_pion_ds_3_H->Clone();
  TH1F *pt_pion_ds_4_H_copy = (TH1F*)pt_pion_ds_4_H->Clone();
  TH1F *pt_pion_ds_5_H_copy = (TH1F*)pt_pion_ds_5_H->Clone();
  TH1F *pt_pion_ds_6_H_copy = (TH1F*)pt_pion_ds_6_H->Clone();
  TH1F *pt_pion_ds_7_H_copy = (TH1F*)pt_pion_ds_7_H->Clone();
  TH1F *pt_pion_ds_8_H_copy = (TH1F*)pt_pion_ds_8_H->Clone();

  TH1F *pt_dstar_sequence_H = (TH1F*)MyFile->Get("pt_dstar_sequence_H;1");  //Shows PT of all D* following decay sequence
  TH1F *pt_dstar_H          = (TH1F*)MyFile->Get("pt_dstar_H;1"         );  //Shows PT of all D*
  TH2F *pt_softpion_dstar_H = (TH2F*)MyFile->Get("pt_softpion_dstar;1"  );  //Shows PT of softpion against PT of D*-mother
  TH2F *pt_d0pion_dstar_H   = (TH2F*)MyFile->Get("pt_d0pion_dstar;1"    );  //Shows PT of pion from D0 against PT of D*-mother
  
  TH1F *pt_pion_d0_1_H      = (TH1F*)MyFile->Get("ptpion_ds_1_H;1"      );  //The histograms show PT of pions from D0 decay in
  TH1F *pt_pion_d0_2_H      = (TH1F*)MyFile->Get("ptpion_ds_2_H;1"      );  //intervals of D* PT.
  TH1F *pt_pion_d0_3_H      = (TH1F*)MyFile->Get("ptpion_ds_3_H;1"      );
  TH1F *pt_pion_d0_4_H      = (TH1F*)MyFile->Get("ptpion_ds_4_H;1"      );
  TH1F *pt_pion_d0_5_H      = (TH1F*)MyFile->Get("ptpion_ds_5_H;1"      );
  TH1F *pt_pion_d0_6_H      = (TH1F*)MyFile->Get("ptpion_ds_6_H;1"      );
  TH1F *pt_pion_d0_7_H      = (TH1F*)MyFile->Get("ptpion_ds_7_H;1"      );
  TH1F *pt_pion_d0_8_H      = (TH1F*)MyFile->Get("ptpion_ds_8_H;1"      );
  
  TH1F *pt_pion_d0_1_H_copy = (TH1F*)pt_pion_d0_1_H->Clone();
  TH1F *pt_pion_d0_2_H_copy = (TH1F*)pt_pion_d0_2_H->Clone();
  TH1F *pt_pion_d0_3_H_copy = (TH1F*)pt_pion_d0_3_H->Clone();
  TH1F *pt_pion_d0_4_H_copy = (TH1F*)pt_pion_d0_4_H->Clone();
  TH1F *pt_pion_d0_5_H_copy = (TH1F*)pt_pion_d0_5_H->Clone();
  TH1F *pt_pion_d0_6_H_copy = (TH1F*)pt_pion_d0_6_H->Clone();
  TH1F *pt_pion_d0_7_H_copy = (TH1F*)pt_pion_d0_7_H->Clone();
  TH1F *pt_pion_d0_8_H_copy = (TH1F*)pt_pion_d0_8_H->Clone();
  

  TH1F *pt_all_pions_H      = (TH1F*)MyFile->Get("ptpions_H;1"          );  //Shows PT of all pions
  TH1F *pt_d0_pions_H       = (TH1F*)MyFile->Get("ptpion_ds_H;1"        );  //Shows PT of pions from D0 decay
  TH1F *pt_ds_pions_H       = (TH1F*)MyFile->Get("pt_soft_pion_ds_H;1"  );  //Shows PT of softpions from D* decay
  TH1F *pt_all_pions_ds_H   = (TH1F*)MyFile->Get("pt_all_pions_ds_H;1"  );  //Copies PT of all pions
  TH1F *pt_all_pions_H_copy = (TH1F*)MyFile->Get("ptpions_H;1"          );

  TCanvas *c1 = new TCanvas("c1", "Pt all pions and all pions from decay"                , 800, 800);
  TCanvas *c2 = new TCanvas("c2", "Pt all pions from both D* and D0 decay"               , 800, 800);
  TCanvas *c3 = new TCanvas("c3", "Pt all pions from D0 decay per Pt interval of D*"     , 800, 800);
  TCanvas *c4 = new TCanvas("c4", "Pt all pions from D* decay per Pt interval of D*"     , 800, 800);
  TCanvas *c5 = new TCanvas("c5", "Ratio of ds pions to all pions"                       , 800, 800);
  TCanvas *c6 = new TCanvas("c6", "Ratio of d0 pions to all pions"                       , 800, 800);
  TCanvas *c7 = new TCanvas("c7", "Pt pions from D* and D_{0} against pt D*"             , 800, 800);
  TCanvas *c8 = new TCanvas("c8", "Pt both D* following and not following decay sequence", 800, 800);
  
  c3->Divide(2,4);
  c4->Divide(2,4);
  c5->Divide(2,4);
  c6->Divide(2,4);
  c7->Divide(1,2);
  c8->Divide(1,2);

  Double_t norm1 = pt_pion_d0_1_H->GetEntries();
  Double_t norm2 = pt_pion_d0_2_H->GetEntries();
  Double_t norm3 = pt_pion_d0_3_H->GetEntries();
  Double_t norm4 = pt_pion_d0_4_H->GetEntries();
  Double_t norm5 = pt_pion_d0_5_H->GetEntries();
  Double_t norm6 = pt_pion_d0_6_H->GetEntries();
  Double_t norm7 = pt_pion_d0_7_H->GetEntries();
  Double_t norm8 = pt_pion_d0_8_H->GetEntries();
  Double_t norm_all_pions = pt_all_pions_H->GetEntries();
  Double_t norm_all_daughter_pions = pt_d0_pions_H->GetEntries();
  Double_t norm_dstar = pt_dstar_H->GetEntries();
  Double_t norm_dstar_sequence = pt_dstar_sequence_H->GetEntries();

}

#6

Can you post the file Results_pions_nov21_25mevents.root ?


#7

I can’t upload it, it’s too big apparently. It’s 5.8MB, which is above the limit I can post it says. However, just now I uploaded it using WeTransfer, hopefully the link works: https://we.tl/t-0u8HYBOrOu.


#8

You should protect your source code against nonexistent histograms. For example, your ROOT file has no “*dstar*” histograms:

rootls -1 -l Results_pions_nov13_25mevents.root

Remove “;1” from all histograms’ names.

If you want a “histogram copy”, use “Clone”:

TH1F *pt_all_pions_H_copy = (TH1F*)pt_all_pions_H->Clone();

#9

pt_dstar_H does not exits in your file:

$ rootls Results_pions_nov13_25mevents.root -l
TH1F  Nov 14 08:11 2018 pt_all_pions_ds_H    "Pt of all pions from both D* and D0 decay"
TH1F  Nov 14 08:11 2018 pt_soft_pion_ds_1_H  "Pt of pions from D* (0< Pt D* <0.5) decay"
TH1F  Nov 14 08:11 2018 pt_soft_pion_ds_2_H  "Pt of pions from D* (0.5< Pt D* <1) decay"
TH1F  Nov 14 08:11 2018 pt_soft_pion_ds_3_H  "Pt of pions from D* (1< Pt D* <1.5) decay"
TH1F  Nov 14 08:11 2018 pt_soft_pion_ds_4_H  "Pt of pions from D* (1.5< Pt D* <2) decay"
TH1F  Nov 14 08:11 2018 pt_soft_pion_ds_5_H  "Pt of pions from D* (2< Pt D* <2.5) decay"
TH1F  Nov 14 08:11 2018 pt_soft_pion_ds_6_H  "Pt of pions from D* (2.5< Pt D* <3) decay"
TH1F  Nov 14 08:11 2018 pt_soft_pion_ds_7_H  "Pt of pions from D* (3< Pt D* <5) decay"
TH1F  Nov 14 08:11 2018 pt_soft_pion_ds_8_H  "Pt of pions from D* (5< Pt D* <8) decay"
TH1F  Nov 14 08:11 2018 pt_soft_pion_ds_H    "Pt of pions from D* decay"
TH1F  Nov 14 08:11 2018 ptpion_ds_1_H        "Pt of pions from D0 (0< Pt D* <0.5) decay"
TH1F  Nov 14 08:11 2018 ptpion_ds_2_H        "Pt of pions from D0 (0.5< Pt D* <1) decay"
TH1F  Nov 14 08:11 2018 ptpion_ds_3_H        "Pt of pions from D0 (1< Pt D* <1.5) decay"
TH1F  Nov 14 08:11 2018 ptpion_ds_4_H        "Pt of pions from D0 (1.5< Pt D* <2) decay"
TH1F  Nov 14 08:11 2018 ptpion_ds_5_H        "Pt of pions from D0 (2< Pt D* <2.5) decay"
TH1F  Nov 14 08:11 2018 ptpion_ds_6_H        "Pt of pions from D0 (2.5< Pt D* <3) decay"
TH1F  Nov 14 08:11 2018 ptpion_ds_7_H        "Pt of pions from D0 (3< Pt D* <5) decay"
TH1F  Nov 14 08:11 2018 ptpion_ds_8_H        "Pt of pions from D0 (5< Pt D* <8) decay"
TH1F  Nov 14 08:11 2018 ptpion_ds_H          "Pt of pions from D0 decay"
TH1F  Nov 14 08:11 2018 ptpions_H            "Pt of all pions"


#10

Hi Wile_E_Coyote and couet,

A few questions regarding your answer. If I use the Clone() command, doesn’t that also take the rebinning of the original histogram in effect, even though that is done much later in the macro? Because I experienced root changing variables (like the rebinning) in histograms, even though I changed the variables after that histograms should have been drawn, as if it jumps back and redoes the script everytime one of the variables changes.
I am very sorry about the histogram not existing, unfortunately, I’ve been a dumb dumb and linked the wrong file, this is the correct one (the nov21 one): https://we.tl/t-4SR4byvI2F. If I open this with TBrowser, it does show me that the file exists, again, I’m very sorry.
I will delete the “;1” in all histograms, can you explain what the purpose of it is/was perhaps?
Thanks to you both for looking into it so far!

EDIT: I just tried the changes “;1” and “Clone()”, and it seems to have worked! Just a bit unsure as to why it worked up until this morning, and only now started to be an issue. However, it’s now solved, so I can take a look at that later. Thanks you guys so much!


#11