Dear Root users,
I write this small code following:
[code]void coin(string root_filename, string name, int BL1, int BR1, int L, int R, int BL2, int BR2)
{
TFile f(root_filename.c_str());
TH2F h = (TH2F)f.Get(“h2”);
h->SetDirectory(gROOT);
f.Close();
string s1, s2, s3;
s1 = name + "d.coin";
s2 = name + "b.coin";
TH1D *b11 = h->ProjectionX("b11",BL1,BR1);
TH1D *b12 = h->ProjectionY("b12",BL1,BR1);
TH1D *b21 = h->ProjectionX("b21",BL2,BR2);
TH1D *b22 = h->ProjectionY("b22",BL2,BR2);
TH1D *d1 = h->ProjectionX("d1",L,R);
TH1D *d2 = h->ProjectionY("d2",L,R);
TH1D *d = d1;
TH1D *b = b11;
d->Add(d2);
b->Add(b12);
b->Add(b21);
b->Add(b22);
// d->Draw();
// b->SetLineColor(kRed);
// b->Draw("SAME");
ofstream of1, of2;
of1.open(s1.c_str());
of2.open(s2.c_str());
for (int i=1; i<=size; i++)
{
of1<<i<<" "<<d->GetBinContent(i)<<endl;
of2<<i<<" "<<b->GetBinContent(i)<<endl;
}
of1.close();
of2.close();
delete h;
delete b11;
delete b12;
delete b21;
delete b22;
delete d1;
delete d2;
//delete d;
//delete b;
}[/code]
If I don’t delete d and b, I can run it without problem. However, If I try to delete d and b, program is crashed.
Could you please help me to solve this problem?
Thank you very much,