TProfileX problem

Dear Rooters,

Sorry for this silly issue, I tried for quite long time and yet can’t figure out what is wrong with my code.
I can’t create a Profile plot of my TH2F hist. However I saved the my TH2F into a root file and can create the TProfile.

P.S: I am using ROOT 6.10/02. Mac OsX binary release.
Follow the lines:

void Plotter() {

  TFile *f_model1 = TFile::Open("result_model1.root");
  TTree * t_f0980 = (TTree*)f_model1->Get("f0980");
  TTree * t_FCN = (TTree*)f_model1->Get("FCN");

  TH2F * h2_f0980_mag_vs_FCN = new TH2F("h2_f0980_mag_vs_FCN","", 100, 0.46,0.56, 100, 449e3,447e3);

  Double_t  magnitude;
  Double_t  fcn;

  t_f0980->SetBranchAddress("magnitude",&magnitude);
  t_FCN->SetBranchAddress("FCN",&fcn);

  for(unsigned int i=0;i<t_f0980->GetEntries();i++) {
    t_f0980->GetEntry(i);
    t_FCN->GetEntry(i);

    h2_f0980_mag_vs_FCN->Fill(magnitude,fcn,1.0);
  }

  TCanvas *c1 = new TCanvas("c1","show profile",600,900);
  c1->Divide(1,2);
  c1->cd(1);
  h2_f0980_mag_vs_FCN->Draw("colz");
  //TFile *f = new TFile("test.root", "RECREATE"); ///but if I write into a root file I can create the Profile
  //h2_f0980_mag_vs_FCN->Write();
  //f->Close();
  c1->cd(2);

  TProfile * prof = h2_f0980_mag_vs_FCN->ProfileX();
  prof->Draw(); // it is empty :frowning

}

result_model1.root (44.1 KB)

1 Like

I’m afraid this is a bug.
I also get a completely empty profile histogram (regardless whether I save the original TH2F or not) on Linux with any ROOT 6 version.

1 Like

I get also an empty histogram when I execute the macro but if I do "ProfileX’ from the pop-up menu on the 2D histogram drawn with option colz, then I get a non empty result.

So, the “brutal fix” is:

h2_f0980_mag_vs_FCN->Draw("colz");
gPad->Modified(); gPad->Update(); // make sure it's really drawn
1 Like

Dear Wile,

Thank you a lot.
It solve the problem. Hope others can profit from this brutal fix.

Regards,

Hi,
instead of gPad->Modified()…
one may use:

gSystem->ProcessEvents();

I dont claim this is simpler but it may give a hint
how to really fix the problem.
Cheers
Otto

Actually i am not sure why ProfileX() needs graphics to be done. May be @moneta has an idea.

Hi Olivier,
the problem is a missing BufferEmpty in TH1::ProfileX
as it is found e.g. in TH1::Print
So adding h2_f0980_mag_vs_FCN->BufferEmpty(1);
before ProfileX will do it.
gPad->Update() etc do that implicitly.
This should go into TH1::ProfileX etc.
Cheers
Otto

Hi Otto,

Thanks for your reply. So you suggest adding BufferEmpty(1) in TH1::ProfileX ?

Cheers,
Olivier

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