Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:21:54

0001 #!/usr/bin/perl
0002 
0003 # Designed to read output of 'cexmc ...-orun...' program
0004 # Usage: ./mkacchist [-real] [macroName]
0005 
0006 my $floatregexp = qr/-?\d+\.\d+/o;
0007 my $col1regexp = qr/\s*(\d+)\s*\[\s*($floatregexp),\s*($floatregexp)\)\s*/o;
0008 my $col2regexp = qr/\s*($floatregexp)\s*\(\s*(\d+)\s*\/\s*(\d+)\s*\)\s*/o;
0009 my $col3regexp = qr/\s*($floatregexp)\s*\(\s*(\d+)\s*\/\s*\d+\s*\/\s*\d+\s*\)/o;
0010 my $accregexp = qr/^$col1regexp\|$col2regexp\|$col3regexp/o;
0011 
0012 my $xMin = 1.5;
0013 my $xMax = -1.5;
0014 my $nOfBins = 0;
0015 my $binWidth = 0;
0016 # 0 - real range, 1 - reconstructed range
0017 my $histoType = shift;
0018 my $macroName = shift;
0019 
0020 $macroName = "" if $macroName eq undef;
0021 
0022 if ( $histoType ne undef )
0023 {
0024     if ( $histoType eq "-real" )
0025     {
0026         $histoType = 0;
0027     }
0028     else
0029     {
0030         $macroName = $histoType;
0031         $histoType = 1;
0032     }
0033 }
0034 else
0035 {
0036     $histoType = 1;
0037 }
0038 
0039 my @histoData;
0040 my @histoErrors;
0041 
0042 $histoData[ 0 ] = 0;
0043 $histoErrors[ 0 ] = 0;
0044 
0045 
0046 sub calculateError
0047 {
0048     my ( $a, $b ) = @_;
0049 
0050     return 0 if $a == 0 || $b == 0;
0051     return sqrt( 1 / $a + 1 / $b ) * $a / $b;
0052 }
0053 
0054 
0055 while ( <> )
0056 {
0057     next unless /$accregexp/;
0058 
0059     $xMin = $3 if $3 < $xMin;
0060     $xMax = $2 if $2 > $xMax;
0061     ++$nOfBins;
0062     if ( $binWidth == 0 )
0063     {
0064         $binWidth = $2 - $3;
0065     }
0066     else
0067     {
0068         my $newBinWidth = $2 - $3;
0069         my $epsilon = 0.00001;
0070         warn "Current bin width is $binWidth, new is $newBinWidth"
0071                                 if abs( $newBinWidth - $binWidth ) > $epsilon;
0072     }
0073 
0074     if ( $histoType == 0 )
0075     {
0076         push @histoData, $4;
0077         push @histoErrors, calculateError( $5, $6 );
0078     }
0079     else
0080     {
0081         push @histoData, $7;
0082         push @histoErrors, calculateError( $8, $6 );
0083     }
0084 }
0085 
0086 die "Corrupted input" if $nOfBins == 0;
0087 
0088 push @histoData, 0;
0089 push @histoErrors, 0;
0090 
0091 my @histoDataReversed = reverse @histoData;
0092 my @histoErrorsReversed = reverse @histoErrors;
0093 
0094 $" = ",";
0095 
0096 print << "MACRO";
0097 
0098 TH1 *  mkacchist$macroName()
0099 {
0100     Double_t  histoData[] = { @histoDataReversed };
0101     Double_t  histoErrors[] = { @histoErrorsReversed };
0102 
0103     TH1 *  result = new TH1F( "acc$macroName", "Setup acceptances $macroName",
0104                               $nOfBins, $xMin, $xMax );
0105 
0106     result->SetContent( histoData );
0107     result->SetError( histoErrors );
0108 
0109     return result;
0110 }
0111 
0112 
0113 MACRO
0114