Store TMarker on top of TH2F into root file

Hi, I have the following code

TObjArray plotList(0);
TH2F *plot = new TH2F(“plot name”, “plot title”, 10, 1, 10, 10, 1, 10);
plotList.Add(plot);
/// here goes part generating x,y,z
for (…)
{
plot->Fill(x,y,z);
}
TFile f(“test.root”, “recreate”);
plot.Write();
f.Close();

Now I would like to somehow add custom point with TMarker on top of the TH2F, so that it gets written into .root file

The tutorials that I found instantiate TMarker, then proceed with calling the Draw() method, but I did not find how to store the TMarker into .root file

Any help will be much appreciated

I guess you could write your marker as a separate object or you could attach it to your histogram (before writing the histogram);

TMarker *m1 = new TMarker(...); // separate object
TMarker *m2 = new TMarker(...); // attached to histogram
TH2F *plot = new TH2F(...);
plot->GetListOfFunctions()->Add(m2);
// ...
plot->Draw();
m1->Draw();
// ...
plot->Write();
m1->Write("MyMarker1");
// ...
delete plot;
delete m1;

This

plot->GetListOfFunctions()->Add(m2);

solved my headache

Thank you !!

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