[ROOT] TimeDisplay

From: Go IWAI (iwai@hep.sc.niigata-u.ac.jp)
Date: Fri May 02 2003 - 00:20:18 MEST


Dear ROOTers,

I want to monitor transition of temperature by time.
I make a program with reference to $ROOTSYS/tutorial/"seism.C".
According to source code("TH1.cxx"), if fTimeDisplay is set to 1, rescale
X axis automatically.
But the bin content isn't set, and it's 0, right after that rescaled X
axis. I attached "m1.C".

I tried like as "m2.C" method for avoid this trouble.
However, trigger rate isn't always 1Hz.
For example, If I made it seem to be "m3.C", it had been uneven.
And so, it become similar appearance with the passage of time even if I
use Draw("p").
In addition, it is too late rendering to use TGraph instead of TH1.

Do you know how can I resolve?

----
Go IWAI


void m1()
{
  //! adjust time offset
  TDatime dtime;
  unsigned int starttime = dtime.Convert();
  gStyle -> SetTimeOffset( starttime );

  TCanvas canvas( "tempmonitor", "Temperature Monitor" );
  TH1D ht( "ht","Temperature Transition", 10, 0.0, 10.0 );

  //! temperature: from -140 to 40
  ht.SetMaximum( 40.0 );
  ht.SetMinimum( -140.0 );

  //! not need status
  ht.SetStats( 0 );

  //! automatic rescale
  ht.GetXaxis() -> SetTimeDisplay( 1 );
  ht.Draw();

  unsigned int pasttime = 0;
  while ( 1 ) {
    //! generate fake temperature
    double t = gRandom -> Gaus( -80.0, 4.0 );
    pasttime ++;
    ht.SetBinContent( pasttime, t );

    canvas.Modified();
    canvas.Update();
    gSystem -> ProcessEvents();
  }

  return;
}


void m2()
{
  //! adjust time offset
  TDatime dtime;
  unsigned int starttime = dtime.Convert();
  gStyle -> SetTimeOffset( starttime );

  TCanvas canvas( "tempmonitor", "Temperature Monitor" );
  TH1D ht( "ht","Temperature Transition", 10, 0.0, 10.0 );

  //! temperature: from -140 to 40
  ht.SetMaximum( 40.0 );
  ht.SetMinimum( -140.0 );

  //! not need status
  ht.SetStats( 0 );

  //! automatic rescale
  ht.GetXaxis() -> SetTimeDisplay( 1 );
  ht.Draw();

  unsigned int pasttime = 0;
  int timebuf = -1;
  int lastfilled = 0;
  double tempbuf = 0.0;
  while ( 1 ) {
    //! generate fake temperature
    double t = gRandom -> Gaus( -80.0, 4.0 );
    pasttime ++;
    double xmax = ht.GetXaxis() -> GetXmax();
    if ( pasttime > xmax && timebuf < 0 ) {
      timebuf = pasttime;
      tempbuf = t;
      continue;
    }

    ht.SetBinContent( pasttime, t );
    lastfilled = pasttime;

    if ( timebuf > 0 && timebuf < lastfilled ) {
      ht.SetBinContent( timebuf, tempbuf );
      timebuf = -1;
    }

    canvas.Modified();
    canvas.Update();
    gSystem -> ProcessEvents();
  }

  return;
}


void m3()
{
  //! adjust time offset
  TDatime dtime;
  unsigned int starttime = dtime.Convert();
  gStyle -> SetTimeOffset( starttime );

  TCanvas canvas( "tempmonitor", "Temperature Monitor" );
  TH1D ht( "ht","Temperature Transition", 10, 0.0, 10.0 );

  //! temperature: from -140 to 40
  ht.SetMaximum( 40.0 );
  ht.SetMinimum( -140.0 );

  //! not need status
  ht.SetStats( 0 );

  //! automatic rescale
  ht.GetXaxis() -> SetTimeDisplay( 1 );

  ht.Draw();

  int timebuf = -1;
  double tempbuf = 0.0;
  unsigned int lastfilled;
  unsigned int now;
  unsigned int pasttime = 0;
  while ( 1 ) {
    //! generate fake temperature
    double t = gRandom -> Gaus( -80.0, 4.0 );
    double xmax = ht.GetXaxis() -> GetXmax();

    TDatime dtime;
    now = dtime.Convert();
    pasttime = now - starttime;
    if ( lastfilled == pasttime ) {
      gSystem -> Sleep( 3*1000 );
      continue;
    }

    if ( pasttime > xmax && timebuf < 0 ) {
      timebuf = pasttime;
      tempbuf = t;
      continue;
    }

    ht.SetBinContent( pasttime, t );
    lastfilled = pasttime;

    if ( timebuf > 0 && timebuf < lastfilled ) {
      ht.SetBinContent( timebuf, tempbuf );
      timebuf = -1;
    }

    canvas.Modified();
    canvas.Update();
    gSystem -> ProcessEvents();
  }

  return;
}



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:11 MET