Difference between revisions of "Optim2g4beam.pl"
Jump to navigation
Jump to search
(Created page with '=Version 1= <pre> #!/usr/bin/env perl #use lib "/home/golge/g4beamline/"; #use TOOLS; #use serkan_tools; $file_IN = $ARGV[0]; my $file_OUT = "z_positions.in"; $deg2rad=3.14159...') |
|||
Line 146: | Line 146: | ||
close(OUT); | close(OUT); | ||
</pre> | </pre> | ||
+ | |||
+ | |||
+ | [[OptiM32_HRRL_PositronDesign]] |
Latest revision as of 16:18, 20 November 2009
Version 1
#!/usr/bin/env perl #use lib "/home/golge/g4beamline/"; #use TOOLS; #use serkan_tools; $file_IN = $ARGV[0]; my $file_OUT = "z_positions.in"; $deg2rad=3.141592/180.0; open(IN, "< $file_IN"); open(OUT, "> $file_OUT"); while(<IN>) { chomp; next if (/^\#/); @line = split; push @El_Num, $line[0]; push @Name, $line[1]; push @S, $line[2]; push @Length, $line[3]; push @B, $line[4]; push @G, $line[5]; push @BA, $line[9]; $_ = $line[1]; if (/^q/) { if($line[3] == 13) { printf OUT ("place QType13 gradient=%f z=%.2f rename=%s\n",$line[5]*10.,($line[2]-$line[3]/2.)*10.0, $line[1]); } elsif($line[3] == 15) { printf OUT ("place QType15 gradient=%f z=%.2f rename=%s\n",$line[5]*10.,($line[2]-$line[3]/2.)*10.0, $line[1]); } elsif($line[3] == 8) { printf OUT ("place QType8 gradient=%f z=%.2f rename=%s\n",$line[5]*10.,($line[2]-$line[3]/2.)*10.0, $line[1]); } elsif($line[3] == 10) { printf OUT ("place QType10 gradient=%f z=%.2f rename=%s\n",$line[5]*10.,($line[2]-$line[3]/2.)*10.0, $line[1]); } elsif($line[3] == 20) { printf OUT ("place QType20 gradient=%f z=%.2f rename=%s\n",$line[5]*10.,($line[2]-$line[3]/2.)*10.0, $line[1]); } elsif($line[3] == 30) { printf OUT ("place QType30 gradient=%f z=%.2f rename=%s\n",$line[5]*10.,($line[2]-$line[3]/2.)*10.0, $line[1]); } } #elsif (/^o/) #{ # printf OUT ("place pipe_1 length=%.3f z=%.3f rename=%s\n", $line[3]*10.0, ($line[2]- ($line[3]/2.0))*10.0 , $line[1] ); #} elsif (/^b/) { if($line[3] == 15) { printf OUT ("tune %s z0=%.2f z1=%.2f initial=%.8f step=0.00001 expr=atan(Px1/Pz1) tolerance=0.0000001\n",$line[1],($line[2]-$line[3]-10.0)*10.0, ($line[2]+$l ine[3]/3.)*10),$line[4]/10.0; printf OUT ("place SECT_BEND1 By=%s z=%.3f rename=%s\n",$line[1],($line[2]-$line[3])*10.0, $line[1]); $rho=(10*$line[3])/($deg2rad*abs($line[9])); #Convert the bend radi cm-to-mm# printf OUT ("cornerarc C1 z=%.3f centerRadius=%.6f angle=%.6f\n", ($line[2]-$line[3])*10.0, $rho, -$line[9] ); } elsif($line[3] == 30) { printf OUT ("tune %s z0=%.2f z1=%.2f initial=%.8f step=0.00001 expr=atan(Px1/Pz1) tolerance=0.0000001\n",$line[1],($line[2]-$line[3]-10.0)*10.0, ($line[2]+$l ine[3]/3.)*10),$line[4]/10.0; printf OUT ("place SECT_BEND2 By=%s z=%.3f rename=%s\n",$line[1],$line[4]/10., ($line[2]-$line[3])*10.0, $line[1]); $rho=(10*$line[3])/($deg2rad*abs($line[9])); printf OUT ("cornerarc C1 z=%.3f centerRadius=%.6f angle=%.6f\n", ($line[2]-$line[3])*10.0, $rho, -$line[9] ); } } elsif (/^B/) { if($line[4] > 0.0 ) { #printf OUT ("tune %s z0=%.2f z1=%.2f initial=%.8f step=0.00001 expr=atan(Px1/Pz1) tolerance=0.0000001\n",$line[1],($line[2]-$line[3]-10.0)*10.0, ($line[2] +$line[3]/3.)*10),$line[4]/10.0; # printf OUT ("place G_DIPOLE By=%s x=G_X_offset z=(G_Z_offset)+%.3f rotation=Y%.3f rename=%s\n",$line[1],($line[2]-$line[3])*10.0, -$line[9]/2,$line ine[1]); $rho=(10*$line[3])/($deg2rad*abs($line[9])); #Convert the bend radi cm-to-mm# printf OUT ("cornerarc C1 z=%.3f centerRadius=%.6f angle=corrected_bend_ang1\n", ($line[2]-$line[3])*10.0, $rho); } if($line[4] < 0.0 ) { #printf OUT ("tune %s z0=%.2f z1=%.2f initial=%.8f step=0.00001 expr=atan(Px1/Pz1) tolerance=0.0000001\n",$line[1],($line[2]-$line[3]-10.0)*10.0, ($line[2]+$ line[3]/3.)*10),$line[4]/10.0; #printf OUT ("place G_DIPOLE By=%s x=-G_X_offset z=(G_Z_offset)+%.3f rotation=Y%.3f rename=%s\n",$line[1],($line[2]-$line[3])*10.0, -$line[9]/2,$line[1]); printf OUT ("place G_DIPOLE By=%.8f x=-G_X_offset z=(G_Z_offset)+%.3f rotation=Y%.3f rename=%s\n",$line[4]/10,($line[2]-$line[3])*10.0,-$line[9]/2,$l ine[1]); $rho=(10*$line[3])/($deg2rad*abs($line[9])); #Convert the bend radi cm-to-mm# printf OUT ("cornerarc C1 z=%.3f centerRadius=%.6f angle=icorrected_bend_ang1\n", ($line[2]-$line[3])*10.0, $rho); } } elsif (/^a/) { printf OUT ("place Cell_RF1 z=%.3f rename=%s\n", ($line[2]-$line[3]/2)*10.0 , $line[1] ); } elsif (/^w/) { printf OUT ("place Cell_RF2 z=%.3f rename=%s\n", ($line[2]-$line[3]/2)*10.0 , $line[1] ); } elsif (/^iIPM/) { printf OUT ("place Det z=%.2f rename=%s\n",($line[2]-$line[3]/2.)*10.0, $line[1]); } elsif (/^k/) { if($line[7] == 90) { printf OUT ("place Corrector By=%.3f z=%.2f rotation=Z90 rename=%s\n",$line[4]/10., ($line[2]-$line[3]/2.)*10.0, $line[1]); } elsif($line[7] == 0) { printf OUT ("place Corrector By=%.3f z=%.2f rename=%s\n",$line[4]/10., ($line[2]-$line[3]/2.)*10.0, $line[1]); } } } close(IN); close(OUT);