Re: why the h->Draw() does not wotk in the loop

From: Axel Naumann <axel-naumann_at_gmx.de>
Date: Wed, 09 Feb 2005 11:54:01 -0600


Hi Zhong,
you need to give root some time to show a canvas. You keep is busy looping, so it defers creating the graphics until compare() exists - at which point there is nothing left to draw. cin does not allowing root to show a canvas, you'll have to trigger that manually by calling gPad->Update() before reading from cin.

A nicer option (instead of reading from cin) for you might be to use gPad->WaitPrimitive(), which returns when return is hit in the TCanvas. Axel.

Zhong Liu wrote:
> Dear ROOT experts,
>
> I'm comparing (by display) histogrames with identical names but
> located in different root files.
>
> I wrote a simple named script(in the attchment), but the Draw method did
> not work within the loop, the Canvas only show up after the loop is
> finished.
>
> I'm wonering I've made some very stupid mistake, please give a help.
>
> Thanks a lot.
>
> zhong
>
> ------------------------------------------------------------------------------
> Dr. Zhong Liu
> School of Physics, Email: zhong.liu_at_ed.ac.uk
> The University of Edinburgh, Tel: +44 131 650 5284 (office)
> James Clerk Maxwell Building, Tel: +44 131 650 5282 (lab)
> The King's Buildings, Fax: +44 131 650 7174
> Edinburgh. EH9 3JZ. UK.
> ------------------------------------------------------------------------------
>
>
> ------------------------------------------------------------------------
>
> #include "TCanvas.h"
> #include "TH1.h"
>
> Char_t amp_name[30];
> Char_t hist_name[30];
> Int_t Low, Up;
> Char_t chrange[10],go[5];
>
> int compare()
> {
>
> cout << "compare histogrames with same name base from diffrent files" << endl;
> cout << "input the name_base: " << endl;
> cin >> name_base;
> cout << "input lower and upper limits of the histogram range:" << endl;
> cin >> Low;
> cin >> Up;
>
> /* open root files where historgrames are store */
>
>
> TFile f4("4.hist");
> TFile f51("51.hist");
>
>
> for (int i=1; i<=10; i++)
> {
>
> sprintf(hist_name, "%s_%d", name_base, i);
> cout << hist_name << endl;
>
>
>
> f4.cd();
>
>
> TH1D * hist1 = (TH1D *) f4.Get(hist_name);
>
> hist1->GetXaxis()->SetRange(Low,Up);
> hist1->SetLineColor(kRed);
> hist1->Draw();
>
>
> /**** why no Canvas show up here ? ****/
>
> f51.cd();
> TH1D * hist2 = (TH1D *) f51.Get(hist_name);
> hist2->SetLineColor(kBlue);
> hist2->Draw("same");
>
> /**** no Canvas shows up here as well ****/
>
>
> cout << "Continue ?: (any character to contine)" << endl;
> cin >> go;
>
> }
>
> return 0;
>
> }
Received on Wed Feb 09 2005 - 18:54:10 MET

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:04 MET