This tutorial shows how to fill any object the class of which exposes a Fill
method.
void fill_tree(const char *filename, const char *treeName)
{
TFile f(filename,
"RECREATE");
TTree t(treeName, treeName);
double b1;
float b2;
t.Branch("b1", &b1);
t.Branch("b2", &b2);
for (int i = 0; i < 100; ++i) {
b1 = i;
b2 = i * i;
t.Fill();
}
return;
}
int tdf005_fillAnyObject()
{
auto fileName = "tdf005_fillAnyObject.root";
auto treeName = "myTree";
fill_tree(fileName, treeName);
auto th1d = d.Fill<
double>(
TH1D(
"th1d",
"th1d", 64, 0, 128), {
"b1"});
auto th1i = d.Fill<
float>(
TH1I(
"th1i",
"th1i", 64, 0, 128), {
"b2"});
auto th2d = d.Fill<double,
float>(
TH2D(
"th2d",
"th2d", 64, 0, 128, 64, 0, 1024), {
"b1",
"b2"});
th1d->DrawClone();
th1i->DrawClone();
th2d->DrawClone("COLZ");
return 0;
}
- Date
- March 2017
- Author
- Danilo Piparo
Definition in file tdf005_fillAnyObject.C.