source: trunk/source/geometry/solids/test/SurfaceChecker/extract.pl@ 1357

Last change on this file since 1357 was 1350, checked in by garnier, 15 years ago

update to last version 4.9.4

  • Property svn:executable set to *
File size: 3.3 KB
Line 
1#!/usr/bin/perl -w
2
3use strict ;
4
5use File::Basename ;
6
7# variables
8my ($i,$j) ; # loop
9my $events ; # number of entries
10
11my @ret ; ; # variable handling (for i/o ntuple)
12
13my $mcount = 0;
14my $txtfile ;
15my $hbkfile ;
16my $file ;
17
18my @a ;
19my @surface = () ; # surface point XX (generated)
20my @vertex = (0,0,0) ; # vertex position P (generated)
21my @momentum = () ; # momentum p (generated)
22my @intersection = () ; # reconstructed intersection with solid
23my $delta = 0 ; # distance between surface point XX and intersection
24my @bestintersection = () ; # the best intersection (there are more than 1)
25my $bestdelta = 0 ;
26my $phi = 0 ; # two parameters describing the surface point
27my $u = 0;
28
29my $distance ; # distance between surface point and true vertex
30my $theta ; # angle between momentum p and surface normal at XX (true)
31
32# --------------------------------------------------------
33
34
35# now start a loop over different approximations ..
36
37my @filelist = glob "data/*.data" ;
38
39foreach $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
Note: See TracBrowser for help on using the repository browser.