cp3-llbb / CommonTools

Utilities to mass create histograms, flat trees, and more
2 stars 9 forks source link

Segfault when using plotter on sample Json contaning several samples #38

Closed swertz closed 8 years ago

swertz commented 8 years ago

I'm facing a segfault when running a generated plotter on a Json contaning more than one sample:

seb=/home/fynu/swertz/scratch/CMSSW_7_4_15/src/cp3_llbb/CommonTools/histFactory/generator_build/build
${seb}/plotter.exe -d ${seb}/../../samples/TTAnalysis/15_October_Prod/DYSamples.json

yields:

Creating plots for dataset 'DYJetsToLL_M-10to50_TuneCUETP8M1_13TeV-amcatnloFXFX_MiniAODv2_p1_v0.1.1+74X-49-g662d269_TTAnalysis_12d3865'
Processing entry 1 of 24049
...
Processing entry 24001 of 24049
Done. Output saved as './DYJetsToLL_M-10to50_TuneCUETP8M1_13TeV-amcatnloFXFX_MiniAODv2_p1_v0.1.1+74X-49-g662d269_TTAnalysis_12d3865_histos.root'
Creating plots for dataset 'DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX_MiniAODv2_p1_v0.1.1+74X-49-g662d269_TTAnalysis_12d3865'
Warning in <TROOT::Append>: Replacing existing TH1: p_9065fbe3_c1c6_434e_905d_767942b2f602 (Potential memory leak).
...
Warning in <TROOT::Append>: Replacing existing TH1: p_854ed8ad_3408_43c1_bee9_715f62320043 (Potential memory leak).
Processing entry 1 of 3000100

 *** Break *** segmentation violation

===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f4603c3061e in waitpid () from /lib64/libc.so.6
#1  0x00007f4603bc2609 in do_system () from /lib64/libc.so.6
#2  0x00007f46054abfc7 in TUnixSystem::StackTrace() () from /cvmfs/cms.cern.ch/slc6_amd64_gcc491/lcg/root/6.02.00-odfocd7/lib/libCore.so
#3  0x00007f46054adf5c in TUnixSystem::DispatchSignals(ESignals) () from /cvmfs/cms.cern.ch/slc6_amd64_gcc491/lcg/root/6.02.00-odfocd7/lib/libCore.so
#4  <signal handler called>
#5  0x00000000004b2c5a in Plotter::plot(std::string const&) ()
#6  0x00000000004d59ac in main ()
===========================================================

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug 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.
===========================================================
#5  0x00000000004b2c5a in Plotter::plot(std::string const&) ()
#6  0x00000000004d59ac in main ()
===========================================================

Whereas running on TTbarSample.json, for instance, is fine (only one sample).

This is probably just a matter of adding a delete obj; at https://github.com/cp3-llbb/CommonTools/blob/master/histFactory/templates/SavePlot.tpl#L6, or making the TH1* unique_ptr's (I'll try that tomorrow). By the way, is it necessary to use this to save the histograms? Why not using {{UNIQUE_NAME}}->Write("{{PLOT_NAME}}"); (with a SetName on the way)?

I'm a but suprised that this shows up only now, since I've used the plotter successfully before on the same json's...

blinkseb commented 8 years ago

Ah yes indeed, TH1 should be unique_ptr, I've missed that, thanks!

Concerning the save, it's a relic of the TTree::Draw where it was necessary to retrieve the histograms from the directory. Indeed here, it should be enough to to the Write on the object itself. I don't exactly remember why I add the SetName with the Write, but I do remember it's needed.

I'll do the necessary changes tomorrow.

swertz commented 8 years ago

Hm weird, I still have a segfault when using unique_ptr... Only difference is that ROOT doesn't complain anymore that I'm replacing the TH1's...

blinkseb commented 8 years ago

Can you test with https://github.com/cp3-llbb/CommonTools/pull/39 ? I'm unable to reproduce (it does not crash), but if it still does, at least we will have a line number in the stack trace ...

swertz commented 8 years ago

As it turns out it was one of my plot formulas which gives the segfault. Removing the plot solved the problem. I'm still trying to understand why it causes the problem and why it doesn't happen on every sample though...

swertz commented 8 years ago

There was a bug here: https://github.com/cp3-llbb/TTAnalysis/blob/master/plugins/TTAnalyzer.cc#L663 So nothing to do with the plotter, but the missing delete's would have caused trouble sooner or later ;)