What happens to a temporary RooDataHist after plotOn

hi,

i have a class with a RooPlot* data member, a getter function returning that plot and a method fitting some mass peak:

class MyClass{ ... virtual void FitMassPeak(TH1D& myHisto); virtual RooPlot* GetPlot() {return myPlot;} private: RooPlot* myPlot; ... }

in the method FitMassPeak i create a temporary RooDatahist object from the TH1D and plot it after fitting:

void FitMassPeak(TH1D& myHisto) { RooDataHist myData("histName",...,&myHisto); //fit myData ... //plot myData on myPlot myData.plotOn(myPlot, ...); ... }

my question is now: what happens to the RooDataHist “myData”? it’s a temporary object, so it should be deleted after the funtion call. are the points then still stored in myPlot? cause if i say, e.g. in another class,

MyClass classy;
classy.GetPlot().Draw();

it works fine, everyhting i plotted on the RooPlot is there. but if i try out

MyClass classy;
classy.GetPlot().getAttMarker("histName")->SetMarkerColor(kGreen + 4);
classy.GetPlot().Draw();

i get a segmentation fault.

if i would get a segm fault even with classy.GetPlot().Draw(); i would understand, because then i would assume that the RooDataHist is just not there. but how can it be that i draw the RooPlot but can’t access the data markers?

hope this wasn’t too confusing. thanks for any help,
axel.

ps: just in case someone wants to ask: i made sure that i call getAttMarker(char* name) with the correct name.

Hi,

If you plot a RooDataHist on a RooPlot, it will contain a RooHist object that encodes the result, there will be no link or reference to the original RooDataHist after the plot operation, so your code should not crash because of that. If you’d be able to send a complete code fragment that I can run, I’d be able to comment (or debug) more.

Wouter

thanks for the answer, Wouter.

if i find some time during the next days to create a small running example recreating the bug i will it post here.

of course, if i find the bug myself i will also let you know.

cheers,
axel.