Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-10-16 08:16:19

0001 #!/usr/bin/env perl
0002 use strict;
0003 use warnings;
0004 use DBI;
0005 
0006 my $dbname = "daq";
0007 my $host   = "sphnxdaqdbreplica";
0008 
0009 my $dbh = DBI->connect("dbi:Pg:dbname=$dbname;host=$host",
0010                        undef, undef,
0011                        { RaiseError => 1, AutoCommit => 1 })
0012           or die $DBI::errstr;
0013 
0014 if (@ARGV < 1) {
0015     print "ERROR :: Need an input run list\n";
0016     die "Usage: $0 runlist.txt\n";
0017 }
0018 
0019 my $runlist_file = $ARGV[0];
0020 open my $fh, "<", $runlist_file or die "Cannot open $runlist_file: $!";
0021 my @runs;
0022 while (<$fh>) {
0023     chomp;
0024     next if /^\s*$/;
0025     push @runs, $_;
0026 }
0027 close $fh;
0028 
0029 my $sth_counts = $dbh->prepare("
0030     SELECT SUM(raw) AS raw_sum, SUM(live) AS live_sum
0031     FROM gl1_scalers
0032     WHERE runnumber = ? AND index = 10
0033 ");
0034 
0035 my $sth_time = $dbh->prepare("
0036     SELECT EXTRACT(EPOCH FROM brtimestamp), EXTRACT(EPOCH FROM ertimestamp)
0037     FROM run
0038     WHERE runnumber = ?
0039 ");
0040 
0041 my ($tot_raw, $tot_live, $tot_raw_corr) = (0, 0, 0);
0042 my $collfreq = 111 * 78e3;  # 8.658e6
0043 
0044 foreach my $run (@runs) {
0045     $sth_counts->execute($run);
0046     my ($raw10, $live10) = $sth_counts->fetchrow_array();
0047     $raw10  ||= 0;
0048     $live10 ||= 0;
0049 
0050     # get times
0051     $sth_time->execute($run);
0052     my ($tstart, $tend) = $sth_time->fetchrow_array();
0053     next unless ($tstart && $tend);
0054     my $dt = $tend - $tstart;
0055     next if $dt <= 0;
0056 
0057     $tot_raw  += $raw10;
0058     $tot_live += $live10;
0059 
0060     my $rate = $raw10 / ($dt * $collfreq);
0061     next if $rate <= 0.0 || $rate >= 1.0;
0062 
0063     my $mu = -log(1.0 - $rate);
0064     my $corr = $mu * $dt * $collfreq;
0065 
0066     $tot_raw_corr  += $corr;
0067 }
0068 
0069 $sth_counts->finish;
0070 $sth_time->finish;
0071 $dbh->disconnect;
0072 
0073 my $tot_live_corr = 0;
0074 if ($tot_raw > 0) {
0075     my $livefrac = $tot_live / $tot_raw;
0076     $tot_live_corr = $tot_raw_corr * $livefrac;
0077 }
0078 
0079 my ($lumi_live, $lumi_raw, $lumi_live_corr, $lumi_raw_corr) = (0, 0, 0, 0);
0080 my $mbd_cross = 25.2;
0081 my $norm = 1e-09;
0082 $lumi_live = $tot_live / $mbd_cross * $norm;
0083 $lumi_raw = $tot_raw / $mbd_cross * $norm;
0084 $lumi_live_corr = $tot_live_corr / $mbd_cross * $norm;
0085 $lumi_raw_corr = $tot_raw_corr / $mbd_cross *$norm;
0086 
0087 print "Total raw (uncorrected): $tot_raw / lumi: $lumi_raw\n";
0088 print "Total live (uncorrected): $tot_live / lumi: $lumi_live\n";
0089 print "Total raw (pileup-corrected): $tot_raw_corr / lumi: $lumi_raw_corr\n";
0090 print "Total live (pileup-corrected): $tot_live_corr / lumi: $lumi_live_corr\n";