here, i use a TMultiGraph to save the gotten contours, because the contours may be not closed in a TH2D, with the function TMultiGraph * GetContours(const char * fn, const char * th2dname, int nlevel). And in the Test() function, the TGraph objects of the TMultiGraph are extracted.
void Test()
{
TMultiGraph * mg = GetContours("res_b64_fit_3id_ddmts_mc.root", "0", 1);
mg->DrawClone("ACP");
// TList * list = mg->GetListOfGraphs();
// TGraph * gr = (TGraph *)list->First();
// gr->DrawClone("ACP");
// cout << list->GetSize() << endl;
delete mg;
}
TMultiGraph * GetContours(const char * fn, const char * th2dname, int nlevel)
{
TGraph ** gr;
TFile * f = new TFile(fn, "read");
TH2D * h = (TH2D *) f->Get(th2dname);
double chisq = h->GetMinimum();
double contours[2] = {chisq + 2.3, chisq + 6.14};
h->SetContour(2, contours);
TCanvas * cc = new TCanvas(th2dname, th2dname);
cc->Divide(2,2);
cc->cd(1);
h->Draw("CONT1");
cc->cd(2);
h->Draw("CONT Z LIST");
cc->Update();/////////////////////////////
TObjArray * cont = (TObjArray *)(gROOT->GetListOfSpecials()->FindObject("contours"));
TList * list = (TList *)cont->At(nlevel);
int ngr = list->GetSize();
TGraph * grtemp;
if(ngr > 0)
{
gr = new TGraph * [ngr];
grtemp = (TGraph *)list->First();
gr[0] = grtemp->Clone();
for(int igr = 1; igr < ngr; ++ igr)
{
grtemp = (TGraph *)list->After(grtemp);
gr[igr] = grtemp->Clone();
}
}
cc->Close();
delete cc;
f->Close();
delete f;
delete grtemp;
TMultiGraph * mg = new TMultiGraph();
for(int i = 0; i < ngr; ++ i)
mg->Add(gr[i]);
delete [] gr;
return mg;
}

本文介绍了一种利用TMultiGraph来保存从TH2D获取的轮廓的方法,因为TH2D中的轮廓可能不是闭合的。通过定义特定的轮廓级别,并从TMultiGraph中提取TGraph对象进行绘制。
509

被折叠的 条评论
为什么被折叠?



