#include "TTree.h"
#include "TGraph.h"
#include "TString.h"
#include "TPad.h"
#include "TMath.h"
#include <iostream>
TGraph *DrawGraph(const char *xname, const char *yname, TTree *tree,
const char *selection = "", const char *gname = "MyGraph") {
TGraph *g = ((TGraph*)0);
if (!(xname && xname[0] && yname && yname[0] && tree)) return g;
if (!selection) selection = "";
if (!(gname && gname[0])) gname = "MyGraph";
tree->SetEstimate(-1); // keep all results (assumes one result per entry)
#if 0 /* 0 or 1 */
tree->Draw(TString::Format("%s : %s", yname, xname), selection);
if (gPad) g = ((TGraph*)(gPad->GetPrimitive("Graph")));
if (g) {
g = ((TGraph*)(g->Clone(gname))); // always return a "clone"
g->SetTitle(TString::Format("%s;%s;%s", gname, xname, yname));
}
#else /* 0 or 1 */
tree->Draw(TString::Format("%s : %s", yname, xname), selection, "goff");
if (tree->GetSelectedRows() > 0) {
g = new TGraph(TMath::Min(tree->GetSelectedRows(), tree->GetEstimate()),
tree->GetV2(), tree->GetV1());
g->SetNameTitle(gname, TString::Format("%s;%s;%s", gname, xname, yname));
}
#endif /* 0 or 1 */
if (tree->GetSelectedRows() > tree->GetEstimate()) {
std::cout << "Warning : DrawGraph : increase SetEstimate and rerun : "
<< tree->GetEstimate() << " < " << tree->GetSelectedRows()
<< std::endl;
}
return g;
}
1 Like