User Tools

Site Tools


root:two_stats_boxes
no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


root:two_stats_boxes [2009/03/27 14:56] (current) – created viktorh
Line 1: Line 1:
 +====== How to overlay tow histograms and draw both stats boxes ======
 +
 +void myfunction()
 +{
 +  ...
 +  TCanvas *c = new TCanvas(...)
 +  TH1D *h1 = new TH1D(...) ; // histo 1
 +  TH1D *h2 = new TH1D(...) ; // histo 2
 +
 +  // set stats options (show histo title, nEntries, mean, rms)
 +  gStyle->SetOptStat(1111);
 +
 +  // draw histo 1
 +  h1->Draw(); // draw histo and stats box on default position
 +
 +  // get stats box
 +  gPad->Update(); 
 +  TPaveStats *statsbox = (TPaveStats*)gPad->GetPrimitive("stats");
 +
 +  // get (default) y position of stats box (histo h1)
 +  double y1 = statsbox->GetY1NDC(); // (lower) y start position of stats box
 +  double y2 = statsbox->GetY2NDC(); // (upper) y start position of stats box
 +
 +  // set new position of stats box (histo h1)
 +  double newy1 = 2 * y1 - y2;   // new (lower) y start position of stats box
 +  double newy2 = y1;            // new (upper) y start position of stats box
 +  statsbox->SetY1NDC(newy1);    //set new y start position
 +  statsbox->SetY2NDC(newy2);    //set new y end position
 +
 +  // draw histo 2
 +  h2->Draw("sames"); // draw stats box on default position
 +
 +  // Draw options:
 +  // "same"  : draw histogram on same canvas, do not redraw stats box
 +  // "sames" : draw histogram on same canvas, draw stats box (in default position)
 +
 + ...
 +}
 +
  
root/two_stats_boxes.txt · Last modified: 2009/03/27 14:56 by viktorh