Seg violation

Hi - I have some pretty simple code that is resulting in a seg violation. ROOT hangs at “Generating stack trace . . .” for some reason as well (I always have to kill manually). If I run the code line by line interactively, I don’t have this problem.

I’m using 3.04/02.

The output is:

edward@muon06</data1/babar/edward/root> root -l
root [0] .x bchd0picheck.cc(0)
Added ntuples
Warning: Automatic variable myCutLepCharge allocated in global scope FILE:esigkmpctfdoccnepiorpidkgsr2le.cc LINE:94
TCanvas::MakeDefCanvas: created default TCanvas with name c1
Finished here

*** Break *** segmentation violation
Generating stack trace…

Any suggestions for how to debug this error would be very much appreciated. Thanks.

(I can’t seem to add a .cc file as an attachment, and the link to “Allowed Extensions and Sizes” gives me the message You are not allowed to call this file (ID:2), so instead of attaching the code, I’m going to paste it here.)

void bchd0picheck(Int_t truthType=0){

// Truth:
// 0 = Don’t use
// 1 = Use
// 2 = Use anti

TH1F * nuEESig = new TH1F(“nuEESig”,“nuEESig”,100,0,4);
TH1F * actNuEESig = new TH1F(“actNuEESig”,“actNuEESig”,100,-4,4);
TH1F * truNuEESig = new TH1F(“truNuEESig”,“truNuEESig”,100,0,4);
TH1F * nuEDiffESig = new TH1F(“nuEDiffESig”,“nuEDiffESig”,100,-3,2);
TH1F * R2ESig = new TH1F(“R2ESig”,“R2ESig”,100,0,1);
TH1F * MESESig = new TH1F(“MESESig”,“MESESig”,80,5.14,5.3);
TH1F * E2ESig = new TH1F(“E2ESig”,“E2ESig”,80,0,8);
TH1F * coslgESig = new TH1F(“coslgESig”,“coslgESig”,110,-1.1,1.1);
TH1F * costheblgESig = new TH1F(“costheblgESig”,“costheblgESig”,120,-1.2,1.2);
TH1F * leptonEESig = new TH1F(“leptonEESig”,“leptonEESig”,100,1,3.5);
TH1F * photonEESig = new TH1F(“photonEESig”,“photonEESig”,70,0,3.5);
TH1F * nuEPMESig = new TH1F(“nuEPMESig”,“nuEPMESig”,100,-2.5,2.5);
TH1F * acthrustESig = new TH1F(“acthrustESig”,“acthrustESig”,50,0,1);
TH1F * LCTPESig = new TH1F(“LCTPESig”,“LCTPESig”,100,-1.0,1.0);
TH1F * LCTMESig = new TH1F(“LCTMESig”,“LCTMESig”,100,-1.0,1.0);

TH1F * nuECon = new TH1F(“nuECon”,“nuECon”,100,0,4);
TH1F * actNuECon = new TH1F(“actNuECon”,“actNuECon”,100,-4,4);
TH1F * filterNuCon = new TH1F(“filterNuECon”,“filterNuECon”,100,0,4);
TH1F * nuEDiffCon = new TH1F(“nuEDiffCon”,“nuEDiffCon”,100,-3,2);
TH1F * R2Con = new TH1F(“R2Con”,“R2Con”,100,0,1);
TH1F * MESCon = new TH1F(“MESCon”,“MESCon”,80,5.14,5.3);
TH1F * E2Con = new TH1F(“E2Con”,“E2Con”,80,0,8);
TH1F * coslgCon = new TH1F(“coslgSig”,“coslgCon”,110,-1.1,1.1);
TH1F * costheblgCon = new TH1F(“costheblgCon”,“costheblgCon”,120,-1.2,1.2);
TH1F * leptonECon = new TH1F(“leptonECon”,“leptonECon”,100,1,3.5);
TH1F * photonECon = new TH1F(“photonECon”,“photonECon”,70,0,3.5);
TH1F * nuEPMCon = new TH1F(“nuEPMCon”,“nuEPMCon”,100,-2.5,2.5);
TH1F * acthrustCon = new TH1F(“acthrustCon”,“acthrustCon”,50,0,1);
TH1F * LCTPCon = new TH1F(“LCTPCon”,“LCTPCon”,100,-1.0,1.0);
TH1F * LCTMCon = new TH1F(“LCTMCon”,“LCTMCon”,100,-1.0,1.0);

TCut cTL = “(1==1)”;
TCut cTG = “(1==1)”;
TCut cTLG = “(1==1)”;

TString theFileSuffix = “”;
/*
if (truthType == 1){
cTL = “issiglg[0]==1”;
cTG = “issiggg[0]==1”;
cTLG = (cTL)&&(cTG);
theFileSuffix = “Truth”;
}
else if (truthType == 2){
cTL = “issiglg[0]==1”;
cTG = “issiggg[0]==1”;
cTLG = !((cTL)&&(cTG));
theFileSuffix = “AntiTruth”;
}
*/

// Electron signal
gROOT->Macro(“esigkmpctfdoccnepiorpidkgsr2le.cc”);
ntp1->Draw(“nuE[0]>>nuEESig”,cTLG);
ntp1->Draw(“actNuE[0]>>actNuEESig”,cTLG);
ntp1->Draw(“nuCMpMC[0]>>truNuEESig”,cTLG);
ntp1->Draw("(actNuE[0]-nuCMpMC[0])>>nuEDiffESig",cTLG);
ntp1->Draw(“myR2All>>R2ESig”,cTLG);
ntp1->Draw(“recBSEM[0]>>MESESig”,cTLG);
ntp1->Draw(“actRecE[0]>>E2ESig”,cTLG);
ntp1->Draw(“coslg[0]>>coslgESig”,cTLG);
ntp1->Draw(“costheblg[0]>>costheblgESig”,cTLG);
ntp1->Draw(“abs(lE[0])>>leptonEESig”,cTLG);
ntp1->Draw(“abs(gE[0])>>photonEESig”,cTLG);
ntp1->Draw(“nuEP[0]>>nuEPMESig”,cTLG);
ntp1->Draw(“abs(cosLPrecoilThrust[0])>>acthrustESig”,cTLG);
cout << “Finished here” << endl;
ntp1->Draw("(lPZ[0]/abs(lPM[0]))>>LCTPESig",“lCharge[0]==1&&lPM[0]!=0”&&cTLG);
ntp1->Draw("(lPZ[0]/abs(lPM[0]))>>LCTMESig",“lCharge[0]==-1&&lPM[0]!=0”&&cTLG);
cout << “Finished here” << endl;

delete ntp1;

// Bch to D0 piControl sample
gROOT->Macro(“esigbchd0pictfdoccnepidkgsr2le.cc”);
ntp1->Draw(“nuE[0]>>nuECon”);
ntp1->Draw(“actNuE[0]>>actNuECon”);
ntp1->Draw(“abs(conNuCME)>>filterNuECon”);
ntp1->Draw("(actNuE[0]-abs(conNuCME))>>nuEDiffCon");
ntp1->Draw(“myR2All>>R2Con”);
ntp1->Draw(“recBSEM[0]>>MESCon”);
ntp1->Draw(“actRecE[0]>>E2Con”);
ntp1->Draw(“coslg[0]>>coslgCon”);
ntp1->Draw(“costheblg[0]>>costheblgCon”);
ntp1->Draw(“abs(lE[0])>>leptonECon”);
ntp1->Draw(“abs(gE[0])>>photonECon”);
ntp1->Draw(“nuEPM[0]>>nuEPMCon”);
ntp1->Draw(“abs(cosLPrecoilThrust[0])>>acthrustCon”);
ntp1->Draw("(lPZ[0]/abs(lPM[0]))>>LCTPCon",“lCharge[0]==1&&lPM[0]!=0”);
ntp1->Draw("(lPZ[0]/abs(lPM[0]))>>LCTMCon",“lCharge[0]==-1&&lPM[0]!=0”);

delete ntp1;

TFile * theOutputFile = new TFile(“plots/bchd0picheck”+theFileSuffix+".root",“recreate”);
gROOT->GetList()->Write();
delete theOutputFile;
}

Hi,

[code]ntp1->Draw("(lPZ[0]/abs(lPM[0]))>>LCTMESig",“lCharge[0]==-1&&lPM[0]!=0”&&cTLG);
cout << “Finished here” << endl;

delete ntp1;

// Bch to D0 piControl sample
gROOT->Macro(“esigbchd0pictfdoccnepidkgsr2le.cc”);
ntp1->Draw(“nuE[0]>>nuECon”);[/code]

Unless you macro esigbchd0pictfdoccnepidkgsr2le.cc actually explicitly set the value of ntp1, your code will crash because ntp1 (on the last line quoted) will try to acess the deleted object.

To debug this problem, run in the debugger:

gdb root.exe gdb> run -l root [] x bchd0picheck.cc(0)

Cheers,
Philippe

Hi - the macro esigbchd0pictfdoccnepidkgsr2le.cc has the following lines:

{

  TChain *ntp1 = new TChain("ntp1");
  ntp1->Add("sp4esignew/sigkmp/SP_eKMP1031b_1401667-1401678.root.ctfdoc.cnepi.or.pidk.gs.r2lecut/ntp1");
}

Also - the crash seems to be some sort of memory-leak problem, because it seems to happen in random places, depending on whether or where I comment out certain non-essential code. But I don’t see any potential memory leaks. The particular crash that I cited happens between these lines:

cout << "Finished here" << endl; 
ntp1->Draw("(lPZ[0]/abs(lPM[0]))>>LCTPESig","lCharge[0]==1&&lPM[0]!=0"&&cTLG); 
ntp1->Draw("(lPZ[0]/abs(lPM[0]))>>LCTMESig","lCharge[0]==-1&&lPM[0]!=0"&&cTLG); 
cout << "Finished here" << endl; 

But, as I said, sometimes it does seem to change. Also, as I mentioned, I do not get any crash when I run the code by typing it in directly, rather than running as a macro.

Also, I can’t get gdb to give me any useful output:
root [0] .x bchd0picheck.cc(0)
Added ntuples
Warning: Automatic variable myCutLepCharge allocated in global scope FILE:esigkmpctfdoccnepiorpidkgsr2le.cc LINE:94
TCanvas::MakeDefCanvas: created default TCanvas with name c1
Finished here

*** Break *** segmentation violation
Generating stack trace…

because it hangs here

*** Break *** keyboard interrupt FILE:bchd0picheck.cc LINE:77

Program received signal SIGINT, Interrupt.
0x40238669 in __wait4 () from /lib/i686/libc.so.6
(gdb) where
#0 0x40238669 in __wait4 () from /lib/i686/libc.so.6
#1 0x402b4154 in DTOR_END () from /lib/i686/libc.so.6
#2 0x08049464 in WaitChild ()
#3 0x080497b9 in main ()
#4 0x4019a507 in __libc_start_main (main=0x8049594 , argc=2,
ubp_av=0xbffff3f4, init=0x8048c0c <_init>, fini=0x8049ec0 <_fini>,
rtld_fini=0x4000dc14 <_dl_fini>, stack_end=0xbffff3ec)
at …/sysdeps/generic/libc-start.c:129

Any other ideas? Thanks.
[/code]

Well… you typed

gdb root instead of

Also it does sounds like it might be a problem with CINT’s memory management. Try using

root[] .O 0 Also you may want to run valgrind on the root executable (see valgrind.kde.org
Cheers,
Philippe.

Hi - I tried a few more things:

(1) Changed from void bchd0picheck (Int_t truthType) to void bchd0picheck()

(2) Copied the macro code in esigkmpctfdoccnepiorpidkgsr2le.cc directly into bchd0picheck().

(3) Tried 3.10/02

Still got a seg violation with (1)-(3)

(4) Also tried the .O 0 command as you suggested - what does it do exactly?

(5) Couldn’t get valgrind working.

(6) Ran with gdb. Here’s the output:

[code] Finished here

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1024 (LWP 1964)]
0x40d16e9c in chunk_free (ar_ptr=0x40dca620, p=0x96d9e80) at malloc.c:3228
3228 malloc.c: No such file or directory.
in malloc.c
(gdb) where
#0 0x40d16e9c in chunk_free (ar_ptr=0x40dca620, p=0x96d9e80) at malloc.c:3228
#1 0x40d16bf4 in __libc_free (mem=0x96d9e88) at malloc.c:3154
#2 0x40c581f6 in __builtin_delete (ptr=0x96d9e88) from /usr/lib/libstdc+±libc6.2-2.so.3
#3 0x40c5821f in __builtin_vec_delete (ptr=0x96d9e88) from /usr/lib/libstdc+±libc6.2-2.so.3
#4 0x40142b28 in TString::~TString () at eval.c:41
#5 0x40acd80f in TCut::~TCut () at eval.c:41
#6 0x40acb0f3 in TChain::Draw () at eval.c:41
#7 0x40b0a5ba in G__TChain_Draw_2_1 () at eval.c:41
#8 0x4056e69f in G__call_cppfunc () at eval.c:41
#9 0x4055df35 in G__interpret_func () at eval.c:41
#10 0x40543fa5 in G__getfunction () at eval.c:41
#11 0x405d0d3f in G__getstructmem () at eval.c:41
#12 0x405c9b4a in G__getvariable () at eval.c:41
#13 0x4053c09d in G__getitem () at eval.c:41
#14 0x4053a863 in G__getexpr () at eval.c:41
#15 0x4058553b in G__exec_function () at eval.c:41
#16 0x4058c924 in G__exec_statement () at eval.c:41
#17 0x4055f79c in G__interpret_func () at eval.c:41
#18 0x40544728 in G__getfunction () at eval.c:41
#19 0x4053c0c9 in G__getitem () at eval.c:41
#20 0x4053a863 in G__getexpr () at eval.c:41
#21 0x405319a2 in G__calc_internal () at eval.c:41
#22 0x40592267 in G__process_cmd () at eval.c:41
#23 0x401710ba in TCint::ProcessLine () at eval.c:41
#24 0x401711a8 in TCint::ProcessLineSynch () at eval.c:41
#25 0x40107bb6 in TApplication::ProcessFile () at eval.c:41
#26 0x40107320 in TApplication::ProcessLine () at eval.c:41
#27 0x40bec45b in TRint::HandleTermInput () at eval.c:41
#28 0x40beb780 in TTermInputHandler::Notify () at eval.c:41
#29 0x40bfb853 in TTermInputHandler::ReadNotify () at eval.c:41
#30 0x401ad9af in TUnixSystem::CheckDescriptors () at eval.c:41
#31 0x401ad0c2 in TUnixSystem::DispatchOneEvent () at eval.c:41
#32 0x4014a669 in TSystem::InnerLoop () at eval.c:41
#33 0x4014a5fe in TSystem::Run () at eval.c:41
#34 0x40107f2d in TApplication::Run () at eval.c:41
#35 0x40bebf96 in TRint::Run () at eval.c:41
#36 0x08048802 in main () at eval.c:41
#37 0x40cb2507 in __libc_start_main (main=0x80487b0 , argc=2, ubp_av=0xbffff404, init=0x80485f4 <_init>,
fini=0x80488b0 <_fini>, rtld_fini=0x4000dc14 <_dl_fini>, stack_end=0xbffff3fc) at …/sysdeps/generic/libc-start.c:12[/code]

This is pretty simple code - projecting histograms from TChain’s with TCut’s. It seems like it should work. Is there a bug somewhere in ROOT?

Hi,

Indeed there seems to be a problem. As far as I can tell this problem was solved in ROOT 3.05/04 and is linked the fact that the TCut were passed by value to the Draw member function. You can work around the problem by replacing

ntp1->Draw("recBSEM[0]>>MESESig",cTLG); by

Cheers,
Philippe.

Hi - I actually still get the crash in 3.10/02.

However, if I add .GetTitle(), then this line doesn’t work:

Also, if I comment out this line, I don’t get the crashes anymore. Somehow, combining the TCut with the string causes problems. I replaced the string with another TCut, and the seg violation now seems to go away.

Thanks for you help.

-Ed

Hi,

The result of “Charge[0]==1&&lPM[0]!=0”&&cTLG.GetTitle() is actually a bool and hence is not suitable for TTree::Draw (which requires a char* or TCut object).

In addiition, (this is C++ syntax), “Charge[0]==1&&lPM[0]!=0”&&cTLG
also yields a bool because it is evaluated left to right and char* && char* returns a bool. Hence
cTLC&&"Charge[0]==1&&lPM[0]!=0"
would work.

Cheers,
Philippe.