Overlaying a TGraph and a Tprofile

Hello,

I am trying to simply overlay a TGraph on a TProfile histogram but it doesn’t work. Here is the code I use:

TCanvas *cOverlay = new TCanvas("cOverlay","TGraph and TProfile Overlay", 1200, 1200);
cOverlay->Clear();
cOverlay->Cd();
myTProfile->Draw();
myTGraph->Draw("C");

In this case the TProfile is drawn but the Tgraph is not. I have tried swapping the draw lines but it didn’t help. Trying various draw options didn’t solve the problem.
But if I replace myTProfile with a normal TH1 in the sample code above, then everything is fine and I have both TH1 and TGraph overlayed.
Would somebody please advice on this issue? Thank you in advance.

I tried to make a reproducer. But for me it works. Here it is:


void prof_graph(){
   TProfile *p = new TProfile("p", "p", 100, -2.5, 2.5);
   p->Draw();
   TGraph *g = new TGraph();
   g->SetPoint(0,0.,0.6);
   g->SetPoint(1,1,0.8);
   g->Draw("C");
}

Thank you for your quick reply.

Your example code works, but as long as the TProfile is empty! If you fill it with even one data point, then the TGraph disappears:

void testOverlay(){
   TProfile *p = new TProfile("p", "p", 100, -2.5, 2.5);
   p->Fill ( 0.0, 0.7 );
   p->Draw();
   TGraph *g = new TGraph();
   g->SetPoint(0,0.,0.6);
   g->SetPoint(1,1,0.8);
   g->Draw("C");
}

Try:

g->Draw(“L”);