[1350] | 1 | #!/usr/bin/perl -w |
---|
| 2 | |
---|
| 3 | use strict ; |
---|
| 4 | |
---|
| 5 | use File::Basename ; |
---|
| 6 | |
---|
| 7 | # variables |
---|
| 8 | my ($i,$j) ; # loop |
---|
| 9 | my $events ; # number of entries |
---|
| 10 | |
---|
| 11 | my @ret ; ; # variable handling (for i/o ntuple) |
---|
| 12 | |
---|
| 13 | my $mcount = 0; |
---|
| 14 | my $txtfile ; |
---|
| 15 | my $hbkfile ; |
---|
| 16 | my $file ; |
---|
| 17 | |
---|
| 18 | my @a ; |
---|
| 19 | my @surface = () ; # surface point XX (generated) |
---|
| 20 | my @vertex = (0,0,0) ; # vertex position P (generated) |
---|
| 21 | my @momentum = () ; # momentum p (generated) |
---|
| 22 | my @intersection = () ; # reconstructed intersection with solid |
---|
| 23 | my $delta = 0 ; # distance between surface point XX and intersection |
---|
| 24 | my @bestintersection = () ; # the best intersection (there are more than 1) |
---|
| 25 | my $bestdelta = 0 ; |
---|
| 26 | my $phi = 0 ; # two parameters describing the surface point |
---|
| 27 | my $u = 0; |
---|
| 28 | |
---|
| 29 | my $distance ; # distance between surface point and true vertex |
---|
| 30 | my $theta ; # angle between momentum p and surface normal at XX (true) |
---|
| 31 | |
---|
| 32 | # -------------------------------------------------------- |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | # now start a loop over different approximations .. |
---|
| 36 | |
---|
| 37 | my @filelist = glob "data/*.data" ; |
---|
| 38 | |
---|
| 39 | foreach $file ( @filelist ) { |
---|
| 40 | |
---|
| 41 | next unless ( -s $file ) ; |
---|
| 42 | |
---|
| 43 | $txtfile = "hbk/" . basename($file,".data") . ".txt" ; |
---|
| 44 | $hbkfile = "hbk/" . basename($file,".data") . ".hbk" ; |
---|
| 45 | |
---|
| 46 | if ( -e $hbkfile ) |
---|
| 47 | { |
---|
| 48 | print "merge of $hbkfile already done...\n" ; |
---|
| 49 | next ; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | print "merge $file to temporary $txtfile\n" ; |
---|
| 53 | |
---|
| 54 | open(TXT,">$txtfile") || die "cannot open file $txtfile:$!\n"; |
---|
| 55 | |
---|
| 56 | open(FH,$file) || die "cannot open file $file:$!\n"; |
---|
| 57 | $mcount = 0 ; |
---|
| 58 | while ( <FH> ) { |
---|
| 59 | |
---|
| 60 | next unless /^(Event|Surface|Vertex|Momentum|EndOfEvent|Intersection|Distance|Angle)/ ; |
---|
| 61 | |
---|
| 62 | s/[(),]/ /g ; # substitute brackets {} and , |
---|
| 63 | @a = split ; # split the line |
---|
| 64 | |
---|
| 65 | if ( $a[0] eq "Event" ) { |
---|
| 66 | |
---|
| 67 | $mcount ++ ; # event counter |
---|
| 68 | |
---|
| 69 | $bestdelta = 1e99 ; # reset the data for every event |
---|
| 70 | @surface = ( 1e99,1e99,1e99) ; |
---|
| 71 | @vertex = (1e99,1e99,1e99) ; |
---|
| 72 | @momentum = (1e99,1e99,1e99) ; |
---|
| 73 | @intersection = (1e99,1e99,1e99) ; |
---|
| 74 | $distance = 1e99 ; |
---|
| 75 | $theta = 1e99 ; |
---|
| 76 | |
---|
| 77 | if ( $mcount % 10000 == 0 ) { |
---|
| 78 | print "event nr. $mcount\n" ; |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | elsif ( $a[0] eq "Surface" ) { |
---|
| 82 | @surface = ( $a[1], $a[2], $a[3] ) ; |
---|
| 83 | } |
---|
| 84 | elsif ( $a[0] eq "Vertex" ) { |
---|
| 85 | @vertex = ( $a[1], $a[2], $a[3] ) ; |
---|
| 86 | $u = $a[4] ; $phi = $a[5] ; |
---|
| 87 | } |
---|
| 88 | elsif ( $a[0] eq "Momentum" ) { |
---|
| 89 | @momentum = ( $a[1], $a[2], $a[3] ) ; |
---|
| 90 | } |
---|
| 91 | elsif ( $a[0] eq "Distance" ) { |
---|
| 92 | $distance = $a[1] ; |
---|
| 93 | } |
---|
| 94 | elsif ( $a[0] eq "Angle" ) { |
---|
| 95 | $theta = $a[1] ; |
---|
| 96 | } |
---|
| 97 | elsif ( $a[0] eq "Intersection" ) { |
---|
| 98 | @intersection = ( $a[1], $a[2], $a[3] ) ; |
---|
| 99 | $delta = $a[4] ; |
---|
| 100 | if ( $delta < $bestdelta ) { |
---|
| 101 | $bestdelta = $delta ; |
---|
| 102 | @bestintersection = @intersection ; |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | elsif ( $a[0] eq "EndOfEvent" ) { |
---|
| 106 | @ret = ( $phi, $u, @surface , @vertex, |
---|
| 107 | $distance, @momentum, @bestintersection, |
---|
| 108 | $bestdelta, $theta) ; |
---|
| 109 | |
---|
| 110 | print TXT "@ret\n" ; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | print "$mcount events merged to file $txtfile\n" ; |
---|
| 118 | |
---|
| 119 | close FH ; |
---|
| 120 | close TXT ; |
---|
| 121 | |
---|
| 122 | print "start converting ascii $txtfile to hbook file $hbkfile...\n" ; |
---|
| 123 | |
---|
| 124 | system("export arg1=$txtfile; export arg2=$hbkfile; export arg3=$mcount ; paw -w 0 -b ntuple") && die "cannot create the ntuple in $hbkfile:$!\n" ; |
---|
| 125 | |
---|
| 126 | # delete the temporary ascii file. Comment out this line if needed. |
---|
| 127 | system("rm $txtfile") && die "cannot remove $txtfile.$!\n" ; |
---|
| 128 | |
---|
| 129 | print "\n\n" ; |
---|
| 130 | |
---|
| 131 | } |
---|
| 132 | |
---|