Write and Naming a TBox to a ROOT File

Is there a way to write a TBox to a ROOT file with a name I give it? I am having trouble finding information on this. I am creating multiple TBoxes in a loop and writing them to the same file, so I would like to be able to assign them different names for when I read them out again.

What I tried was:

TBox* tt = new TBox(xmin, fit_value-fit_error, xmax, fit_value+fit_error);
tt->SetFillColor(kRed);
tt->SetFillStyle(3001);

tt->SetName(Form(“BoxError_vtx_%i”,qtBin_ofInterest));
tt->Write();

I can use “SetName” with other ROOT objects like histograms and TLatex, but apparently not with TBox since I get the error: "error: no member named ‘SetName’ in ‘TBox’ ".

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Indeed the TBox documentation does not include SetName (if you do tt->GetName() it shows the name “TBox” by default), but you can give it a name when you Write it to a file:

TFile f("test.root", "recreate");
//...
TBox* tt = new TBox(xmin, fit_value-fit_error, xmax, fit_value+fit_error);
tt->SetFillColor(kRed);
tt->SetFillStyle(3001);

f.cd();   // make sure it goes to f
tt->Write(Form("BoxError_vtx_%i",qtBin_ofInterest));
f.Close();
2 Likes

Great, thanks for the reply!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.