Hi,
I’ve got some trouble with the following piece of code (a version that creates the needed tree is attached to this post)
void tcutgdemo()
{
gStyle->SetPalette(1);
if (gDirectory == gROOT )
TFile* f = new TFile("cuttest.root","recreate");
TTree* tree = (TTree*) gDirectory->Get("bigtree");
// create example tree, if no tree found...
if (tree == NULL)
{
...
}
double ulx[4] = {40.,-2.,40.,40.};
double uly[4] = {10., 70.,70., 0.};
double lrx[4]={-60,-20,-60,-60};
double lry[4]={ 20,-50,-50, 20};
TCutG* upperleft = new TCutG( "upperleft" , 4, uly, ulx );
TCutG* lowerright= new TCutG( "lowerright", 4, lry, lrx );
upperleft->SetVarX("mipposemc[0]");
upperleft->SetVarY("mipposemc[1]");
lowerright->SetVarX("mipposemc[0]");
lowerright->SetVarY("mipposemc[1]");
c1 = new TCanvas( "c1","c1");
TH2F* ulhist = new TH2F("ulhist","ulhist",20,-100,100,20,-100,100);
TH2F* lrhist = new TH2F("lrhist","lrhist",20,-100,100,20,-100,100);
// tree->Draw("mipposemc[0]:mipposemc[1]>>ulhist","mipposemc[0]>10&&upperleft","colz");
tree->Draw("mipposemc[0]:mipposemc[1]>>ulhist","mipposemc[0]>10&&upperleft","box");
tree->Draw("mipposemc[0]:mipposemc[1]>>lrhist","mipposemc[0]<-10&&lowerright","box");
ulhist->Draw("colz");
lrhist->Draw("colz same");
// delete upperleft;
// delete lowerright;
}
If you execute this script several times (usually two or three times) without touching anything. The root crashes.
root [0] .x tcutgdemo.C
TTree bigtree not found
root [1] .x tcutgdemo.C
Warning in <TH1::Build>: Replacing existing histogram: ulhist (Potential memory leak).
Warning in <TH1::Build>: Replacing existing histogram: lrhist (Potential memory leak).
root [2] .x tcutgdemo.C
Warning in <TH1::Build>: Replacing existing histogram: ulhist (Potential memory leak).
Warning in <TH1::Build>: Replacing existing histogram: lrhist (Potential memory leak).
root [3] .x tcutgdemo.C
Warning in <TH1::Build>: Replacing existing histogram: ulhist (Potential memory leak).
Warning in <TH1::Build>: Replacing existing histogram: lrhist (Potential memory leak).
root [4] .x tcutgdemo.C
*** Break *** segmentation violation
(no debugging symbols found)
Using host libthread_db library "/lib/tls/libthread_db.so.1".
Attaching to program: /proc/20028/exe, process 20028
[Thread debugging using libthread_db enabled]
[New Thread -1218579808 (LWP 20028)]
0x011804de in __waitpid_nocancel () from /lib/tls/libc.so.6
Thread 1 (Thread -1218579808 (LWP 20028)):
#0 0x011804de in __waitpid_nocancel () from /lib/tls/libc.so.6
#1 0x011151c4 in do_system () from /lib/tls/libc.so.6
#2 0x00c8bd7f in system () from /lib/tls/libpthread.so.0
#3 0x005ef911 in TUnixSystem::Exec () from /opt/products/root/5.14.00/lib/libCore.so.5.14
#4 0x005efd2b in TUnixSystem::StackTrace () from /opt/products/root/5.14.00/lib/libCore.so.5.14
#5 0x005ede37 in TUnixSystem::DispatchSignals () from /opt/products/root/5.14.00/lib/libCore.so.5.14
...
I’ve tested this with ROOT 5.14 and ROOT 5.16. Surprisingly the number of calls needed to crash ROOT differs from try to try.
Are there some object ownerships rules, that I disobey or is there a different reason why this code does not work?
Cheers, J.
tcutgdemo.C (1.56 KB)