#include "TH1.h" #include "TCanvas.h" #include "TROOT.h" #include "TStyle.h" #include #include bool HistScaledGT ( TH1F* h1, TH1F* h2 ) { return (h1->GetMaximum()/h1->Integral()) < (h2->GetMaximum()/h2->Integral()); } TH1F* DrawNormHists( const std::vector &h_vec ) { std::vector::const_iterator it, it2; it = max_element( h_vec.begin(), h_vec.end(), HistScaledGT ); if( it != h_vec.end() ) { (*it)->DrawNormalized("hist"); // Drawn with axis for( it2 = h_vec.begin() ; it2 != h_vec.end() ; it2++ ) if( (*it2)->Integral() > 0 ) (*it2)->DrawNormalized("hist same A"); } return *it; // Return histogram used to build axis } int tmp_root() { gROOT->SetStyle("Plain"); // gStyle->SetOptTitle(0); gStyle->SetOptStat(0); std::vector h_vec; h_vec.push_back( new TH1F("h1", "h1", 50, -10, 10) ); h_vec.back()->FillRandom("gaus"); h_vec.push_back( new TH1F("h2", "h2", 50, -10, 10) ); h_vec.back()->FillRandom("landau"); h_vec.push_back( new TH1F("h3", "h3", 50, -10, 10) ); h_vec.back()->FillRandom("expo"); // This will be the maximum h_vec.back()->SetTitle("InitTitle"); TCanvas *c = new TCanvas("tmp","", 600, 600); TH1* f = DrawNormHists( h_vec ); // These don't work. Why ? f->SetTitle("A title"); f->GetXaxis()->SetTitle("Hello"); c->Modified(); c->Update(); c->ForceUpdate(); // Even after this c->Print(".png"); return 0; }