#!/usr/bin/perl -w

#cdc

$pi = 3.1415926;
$epsilon = 0.00015;
$lambda = 70*$pi/180.0;
$zcdc = 1.67 - 0.65;
$rmin = 0.10960;
$rmax = 0.56534;
$n = 23;
$nstereo = 10;
$nrl = 0.03437;
$nrlfront = 0.01437;
$m = 0.139;
$p = 1.0;
$stereo = 6*$pi/180;
$b = 1.74;
$pt = $p*cos($lambda);
$k = 0.3*$b/$pt;

$ldet = $rmax - $rmin;
$e = sqrt($p*$p + $m*$m);
$gamma = $e/$m;
$beta = sqrt(1.0 - 1.0/($gamma*$gamma));
$lprime = $zcdc/tan($lambda) - $rmin;
$l = $lprime/cos($lambda);
$neff = $n*$lprime/$ldet;
$nstereoeff = $nstereo*$lprime/$ldet;
$nrleff = $nrl/cos($lambda)*$lprime/$ldet;
$nrlfronteff = $nrlfront/cos($lambda);
$theta0 = .0136/($beta*$p)*sqrt($nrleff + $nrlfronteff)*(1 + 0.038*log($nrleff + $nrlfronteff));
$rmid = ($rmax + $rmin)/2;

print "quick calculation\n";
print "e=$e gamma=$gamma beta=$beta lprime=$lprime l=$l\n";
print "neff=$neff nrleff=$nrleff\n";
print "nstereoeff=$nstereoeff\n";
print "pt=$pt k=$k\n";

#curvature
$pos = $epsilon/$lprime**2*sqrt(720/($neff + 4));
$ms = 0.016/($l*$p*$beta*cos($lambda)**2)*sqrt($nrleff);
$sum = sqrt($pos**2 + $ms**2);
print "cdc, curve $ms, $pos, $sum\n";
$sumk = $sum; #save this for later
#relative transverse momentum
$pos = $pos/$k;
$ms = $ms/$k;
$sum = $sum/$k;
print "cdc, dpt/pt $ms, $pos, $sum\n";
#azimuth
$pos = $epsilon/$lprime*sqrt(12.0*($neff - 1)/($neff*($neff + 1)));
$ms = $theta0/sqrt(3);
$kres = $rmid*$sumk;
$sum = sqrt($pos**2 + $ms**2 + $kres**2);
print "cdc, azimu $ms, $pos, $kres, $sum\n";
#polar
$pos = $epsilon*cos($lambda)**2/sin($stereo)/$lprime*sqrt(12.0*($nstereoeff - 1)/($nstereoeff*($nstereoeff + 1)));
$ms = $theta0/sqrt(3);
$sum = sqrt($pos**2 + $ms**2);
print "cdc, polar $ms, $pos, $sum\n";

#fdc

$epsilon = 0.00020;
$zmin = 1.90 - 0.65;
$zmax = 3.57 - 0.65;
$n = 24;
$nrl = 0.028258;

$ldet = $zmax - $zmin;
$ldeteff = $ldet - ($zmax - $rmax*tan($lambda));
$lprime = $ldeteff/tan($lambda);
$neff = $n*$ldeteff/$ldet;
$nrleff = $nrl/sin($lambda)*$ldeteff/$ldet;
$l = $ldeteff/sin($lambda);
$theta0 = .0136/($beta*$p)*sqrt($nrleff)*(1 + 0.038*log($nrleff));
$rmid = $rmax/2;

#curvature
$pos = $epsilon/$lprime**2*sqrt(720/($neff + 4));
$ms = 0.016/($l*$p*$beta*cos($lambda)**2)*sqrt($nrleff);
$sum = sqrt($pos**2 + $ms**2);
print "fdc, curve $ms, $pos, $sum\n";
$sumk = $sum; #save this for later
#relative transverse momentum
$pos = $pos/$k;
$ms = $ms/$k;
$sum = $sum/$k;
print "fdc, dpt/pt $ms, $pos, $sum\n";
#azimuth
$pos = $epsilon/$lprime*sqrt(12.0*($neff - 1)/($neff*($neff + 1)));
$ms = $theta0/sqrt(3);
$kres = $rmid*$sumk;
$sum = sqrt($pos**2 + $ms**2 + $kres**2);
print "fdc, azimu $ms, $pos, $kres, $sum\n";
#polar
$pos = $epsilon*sin($lambda)**2/$ldeteff*sqrt(12.0*($neff - 1)/($neff*($neff + 1)));
$ms = $theta0/sqrt(3);
$sum = sqrt($pos**2 + $ms**2);
print "fdc, polar $ms, $pos, $sum\n";

exit;

sub tan { sin($_[0]) / cos($_[0])  }

# end of perl script
