Skip to content

Instantly share code, notes, and snippets.

@tsee
Created July 17, 2011 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsee/1087648 to your computer and use it in GitHub Desktop.
Save tsee/1087648 to your computer and use it in GitHub Desktop.
use strict; use warnings;
use Math::SimpleHisto::XS;
use SOOT qw/:all/;
my $nbins = 10000;
my $starttime = -7200.;
my $endtime = 0.;
my $hs = Math::SimpleHisto::XS->new(nbins => $nbins, min => $starttime, max => $endtime);
my @data = (
# end time, duration, number of records
[-5009, 523, 200],
[-4002, 1123, 500],
[-4533, 222, 100],
[-3111, 2511, 3000],
);
foreach my $d (@data) {
my ($end, $dur, $n)= @$d;
my $start = $end-$dur;
my $rate = $n/$dur;
my $lowbin = $hs->find_bin($start);
warn "$start $lowbin";
my $highbin = $hs->find_bin($end);
my $nbins_inrange = $highbin-$lowbin+1;
$hs->fill([map $hs->bin_center($_), ($lowbin .. $highbin)], [($rate) x $nbins_inrange]);
}
my $h = TH1D->new("h","h", $nbins, $starttime, $endtime)->keep;
$h->SetTitle(";Time [seconds];rate [records/second]");
$h->Fill($hs->bin_center($_), $hs->bin_content($_)) for 0..$hs->nbins-1;
my $c=TCanvas->new->keep;
$h->Draw;
$gApplication->Run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment