#!/usr/bin/perl -w
use strict;
########################################################################
# #
# BOOST #
# #
# Reads in UrQMD file 14 output and writes the same output in the LAB #
# frame. #
# #
# This program has been written by Bjoern Baeuchle #
# and is provided under the Creative #
# Commony BY-SA license 3.0 #
# (http://creativecommons.org/licenses/by-sa/3.0/) as-is with no #
# warranty etc. #
# #
# You are free: #
# - to share (to copy, distribute and transmit the work to Remix) #
# - to adapt the work #
# - to make commercial use of the work #
# Under the following conditions: #
# - Attribution: You must attribute the work in the manner specified #
# by the author or licensor (but not in any way that #
# suggests that they endorse you or your use of the #
# work). #
# - Share Alike: If you alter, transform, or build upon this work, you #
# may distribute the resulting work only under the same #
# or similar license to this one. #
# #
########################################################################
# We need a velocity. This field is filled from the input itself.
my $beta = 0;
my $gamma = 1;
# This handles how much status output is given (all output to STDERR)
my $verbosity = 1;
# this is just for output:
my $printline = q( ).(q(%15.8e )x9).q(%10d %2d %2d %8d %4d %3d).qq(\n);
my $toleranceline = qq(Watch out, invariant varies (%10s space, line %8d): Deviation = %14.8e\n);
my %name = qw ! 0 coordinate 4 momentum !;
# warn if Lorentz transformation changes invariants be more than this fraction:
my $tolerance = 1e-6;
# this loops over the input and stores one line per iteration in $_.
while (<>) {
# This checks to see if $_ (implicit variable!) contains information
# about the velocity:
if (/^transformation betas \(NN,lab,pro\)\s+([\d\.E+-]+)\s+([\d\.E+-]+)\s+([\d\.E+-]+)$/) {
# we want the second beta, but transform in backward direction (this SHOULD
# be the same as $3, but nevermind):
$beta = -$2;
print STDERR "Found velocity information in line $.: beta = $beta\n" if $verbosity > 0;
# No error handling for invalid beta:
die "Attention, invalid veclocity found: |$beta|>=1. Died" if (abs($beta) >= 1);
my $betasq = $beta*$beta;
$gamma = 1/sqrt(1-$betasq);
}
# Particle vectors are lines that start with a digit (save some preceeding
# white-space) and have a length that is larger than 100 characters (actually
# we expect 180, but let's not be too strict here)
if (/^\s*\d/ && length > 100) {
# get rid of preceeding whitespace:
$_ =~ s/^\s+//;
# split line into separate numbers:
my @fields = split;
# 0/3 is t/z; 4/7 is E/pz:
for my $index (0,4) {
# t**2-z**2 should be invariant. We check that.
my $invariant_old = $fields[$index]**2-$fields[$index+3]**2;
# perl assigns the left hand side only after it has calculated the right
# hand side. Thus, no need to assign temporary variables.
# transform t and E: t' = gamma*(t-beta*z) ([$index ] = ...)
# transform z and pz: z' = gamma*(z-beta*t) ([$index+3] = ...)
( $fields[$index ]
, $fields[$index+3]) = ( $gamma*($fields[$index]-$beta*$fields[$index+3])
, $gamma*($fields[$index+3]-$beta*$fields[$index]));
my $invariant_new = $fields[$index]**2-$fields[$index+3]**2;
# give a warning if the invariant is changed by more than $tolerance of
# the original value:
my $divide_by = $invariant_old != 0 ? $invariant_old : 1;
my $variation = abs(($invariant_new-$invariant_old)/$divide_by);
printf STDERR $toleranceline, $name{$index}
, $.
, $variation
if $variation > $tolerance;
}
# Write stuff back to $_:
$_ = sprintf $printline, @fields;
}
}
# and in the end, everything (including the altered particle vectors) is written back to STDOUT:
continue { print; }
exit ;