timeonaxis.C

Go to the documentation of this file.
00001 #include <time.h>
00002 
00003 void timeonaxis()
00004 {
00005 // This macro illustrates the use of the time mode on the axis
00006 // with different time intervals and time formats. It's result can
00007 // be seen begin_html <a href="gif/timeonaxis.gif">here</a> end_html
00008 // Through all this script, the time is expressed in UTC. some
00009 // information about this format (and others like GPS) may be found at
00010 // begin_html <a href="http://tycho.usno.navy.mil/systime.html">http://tycho.usno.navy.mil/systime.html</a> end_html
00011 //  or
00012 // begin_html <a href="http://www.topology.org/sci/time.html">http://www.topology.org/sci/time.html</a> end_html
00013 //
00014 // The start time is : almost NOW (the time at which the script is executed)
00015 // actualy, the nearest preceeding hour beginning.
00016 // The time is in general expressed in UTC time with the C time() function
00017 // This will obviously most of the time not be the time displayed on your watch
00018 // since it is universal time. See the C time functions for converting this time
00019 // into more useful structures.
00020 //Author: Damir Buskulic
00021 
00022    time_t script_time;
00023    script_time = time(0);
00024    script_time = 3600*(int)(script_time/3600);
00025 
00026 // The time offset is the one that will be used by all graphs.
00027 // If one changes it, it will be changed even on the graphs already defined
00028    gStyle->SetTimeOffset(script_time);
00029 
00030    ct = new TCanvas("ct","Time on axis",10,10,700,900);
00031    ct->Divide(1,3);
00032    ct->SetFillColor(28);
00033 
00034    int i;
00035 
00036 //======= Build a signal : noisy damped sine ======
00037 //        Time interval : 30 minutes
00038 
00039    gStyle->SetTitleH(0.08);
00040    float noise;
00041    ht = new TH1F("ht","Love at first sight",3000,0.,2000.);
00042    for (i=1;i<3000;i++) {
00043       noise = gRandom->Gaus(0,120);
00044       if (i>700) {
00045          noise += 1000*sin((i-700)*6.28/30)*exp((double)(700-i)/300);
00046       }
00047       ht->SetBinContent(i,noise);
00048    }
00049    ct->cd(1);
00050    ct_1->SetFillColor(41);
00051    ct_1->SetFrameFillColor(33);
00052    ht->SetLineColor(2);
00053    ht->GetXaxis()->SetLabelSize(0.05);
00054    ht->Draw();
00055 // Sets time on the X axis
00056 // The time used is the one set as time offset added to the value
00057 // of the axis. This is converted into day/month/year hour:min:sec and
00058 // a reasonnable tick interval value is chosen.
00059    ht->GetXaxis()->SetTimeDisplay(1);
00060 
00061 //======= Build a simple graph beginning at a different time ======
00062 //        Time interval : 5 seconds
00063 
00064    float x[100], t[100];
00065    for (i=0;i<100;i++) {
00066       x[i] = sin(i*4*3.1415926/50)*exp(-(double)i/20);
00067       t[i] = 6000+(double)i/20;
00068    }
00069    gt = new TGraph(100,t,x);
00070    gt->SetTitle("Politics");
00071    ct->cd(2);
00072    ct_2->SetFillColor(41);
00073    ct_2->SetFrameFillColor(33);
00074    gt->SetFillColor(19);
00075    gt->SetLineColor(5);
00076    gt->SetLineWidth(2);
00077    gt->Draw("AL");
00078    gt->GetXaxis()->SetLabelSize(0.05);
00079 // Sets time on the X axis
00080    gt->GetXaxis()->SetTimeDisplay(1);
00081    gPad->Modified();
00082 
00083 //======= Build a second simple graph for a very long time interval ======
00084 //        Time interval : a few years
00085 
00086    float x2[10], t2[10];
00087    for (i=0;i<10;i++) {
00088       x2[i] = gRandom->Gaus(500,100)*i;
00089       t2[i] = i*365*86400;
00090    }
00091    gt2 = new TGraph(10,t2,x2);
00092    gt2->SetTitle("Number of monkeys on the moon");
00093    ct->cd(3);
00094    ct_3->SetFillColor(41);
00095    ct_3->SetFrameFillColor(33);
00096    gt2->SetFillColor(19);
00097    gt2->SetMarkerColor(4);
00098    gt2->SetMarkerStyle(29);
00099    gt2->SetMarkerSize(1.3);
00100    gt2->Draw("AP");
00101    gt2->GetXaxis()->SetLabelSize(0.05);
00102 // Sets time on the X axis
00103    gt2->GetXaxis()->SetTimeDisplay(1);
00104 //
00105 // One can choose a different time format than the one chosen by default
00106 // The time format is the same as the one of the C strftime() function
00107 // It's a string containing the following formats :
00108 //    for date :
00109 //      %a abbreviated weekday name
00110 //      %b abbreviated month name
00111 //      %d day of the month (01-31)
00112 //      %m month (01-12)
00113 //      %y year without century
00114 //      %Y year with century
00115 //
00116 //    for time :
00117 //      %H hour (24-hour clock)
00118 //      %I hour (12-hour clock)
00119 //      %p local equivalent of AM or PM
00120 //      %M minute (00-59)
00121 //      %S seconds (00-61)
00122 //      %% %
00123 // The other characters are output as is.
00124 
00125    gt2->GetXaxis()->SetTimeFormat("y. %Y %F2000-01-01 00:00:00");
00126    gPad->Modified();
00127    
00128 }

Generated on Tue Jul 5 15:44:22 2011 for ROOT_528-00b_version by  doxygen 1.5.1