README nSpinSim4.0

----------------------
Updates in nSpinSim4.4

1. Includes calculations of average energy loss and average path length in target region.
2. Includes calculations of estimated false PNC angle based on either just target-scattered 
neutrons (TS) or target-scattered (TS) plus target-scattered that have cross over from one side to the
other (XTS) after scattering in a target.  

Since we are averaging rotations, the false PNC effect can be written as

1/2*[(fse-fsw)*RotAng_ns + (fsw*RotAng_ts_w - fse*RotAng_ts_e)],

where ns and ts label the average rotation angles for non-scattered and target scattered neutrons, 
and I've assumed that there is no East-West asymmetry in the non-scattered neutrons. A similar
expression can be written to include the XTS neutrons.

2. const.inc now has most of the running choices in it, e.g., choosing which angular distrbution
to use, whether to running with a single energy or a distribution of energies.

3. Bug found/fixed in logic of TS versus XTS indentification.

4. Moved the last Al plate (0.3175cm) to the end rather than before the last 10-cm air gap, since this
is the entrance window to the ion chamber.

5. Found/fixed bug in empty.f and beampipe.f where path length was not being zeroed.


----------------------
Updates in nSpinSim4.0

1.  The code now can read psm.hbook (histogram 200) which is a beam image showing
beam intensity versus x- and y-positions.  The histograms 2220,2221,2222,3333,4444 are
xy-flux plots at different locations along the beamline, where they give flux values 
normalized to the calibrated Fission Chamber PSM output measurement during NSRII.  
Histograms 441--446 are 1-cm wide by 0.02-cm wide slices through the xy-flux plots 
versus either x or y.


----------------------
Updates in nSpinSim3.9

1. New subroutines "beampipe" and "scatb." These are modeled after "empty" 
and "scate," respectively, to correct the position calculations for neutrons
that bounce in the input guide,input coil, and output coil. It also allows
neutrons to scatter off of gases in the beamline itself. The beam can be 
filled with helium gas or air using the flag "hebeam" in const.inc. The 
septum in the input guide and input coil can still be turned on and off
using sptmflg. 

2. Some minor corrections were made to uncertainty calculations (from 
nSpinSim3.6).


----------------------
Updates in nSpinSim3.8

1. 3 mm septum in input guide and input coil. To use, turn on sptmflg
in const.inc file.

2. Corrected  final x-position calculation in output coil to prevent 
crossovers. 

3. Corrected final x-position calculation for neutrons that bounce. Same 
calculation used in input guide and input coil.

4.Added "if" statements to J Cook angular distributions to allow neutrons with 
wavelengths less than 2 angstroms and greater than 12 angstroms.


----------------------
Updates in nSpinSim3.7

1. Sqrt and atan functions replaced with rsqrt and ratan. When running 
NGC beams for 1E8 events, the code would stop because of domain errors 
for these funcitons. They are redefined to ignore arguments which
may possibly cause domain errors. If the argument of a square root is 
than zero, the argument is written to the screen (and output file).

2. After the previous fix, the code failed due to a sin domain error. 
Instead of redefining every function , a line was added to throw away 
any neutron with an initial wavelength greater than 20 angstroms. After 
looking at the NGC lambda (BeBi filter) distribution, it was evident 
that very few neutrons had wavelengths longer than 20 angstroms, and it 
seemed that the energy of these neutrons could become negative due to 
rounding errors. After this,there were no problems running the NGC beams.

3. A list of "replacement" functions is at the end of the code. To use, 
uncomment them and define them as an external function with a specification
statement. Also, renaming them as the intrinsic function name will redefine 
that functions (e.g. instead of rsin, name function "sin," list it
as external, and any sin function in the code will follow the rules 
defined at the end of the code.


----------------------
Updates in nSpinSim3.6

1. Aluminum windows with correct thicknesses and locations in beam.

2. Rotation angle is calculated using theta = Sum[ PA_i*sin(theta_i)]/PA_avg. 
PA-value can be set to NSRII specifications or to 1 using PAflg in const.inc. 
Uncertainties in all calculations are calculated to reflect asin and PA. Previously
a random number and the PA-value were used to eliminate neutrons, but this affected
the detector flux.  Now, PA affects only the rotation angle, not the flux as well.


-----------------------
Updates in nSpinSim 3.3
--Reflection in all guides and target area with reflection coefficient 
R=1 for theta/lam/m_Ni<m_Ni, R linearly decreasing with m with a slope 
given by R=0.7 at theta/lam/m_Ni=3.3, and R=0 for theta/lam/m_Ni> 
m_guide or m_target. In const.inc one can set reflectflg=.true. 
to make R=1. If target gtindexx,y <1E-5, then R=0, and all wall bounces 
are absorbed.

--Multiple bounces with possible additional target scatterings between 
wall bounces is included.

--Spin rotation now done at each step of the way. So, path length and 
rotation angle are updated at each wall bounce or target scatter based 
on the previous pathlength and energy. This is done by new subroutine, 
rotation.f. This subroutine includes Kangfei's Bz-gradients (see const.inc
to change which Bz data files you wish to use).

The code works. Transmissions agree with previous studies as do rotations.
Rotations should probably be investigated more before doing real 
systematices study, however.


--------------------------------------------------------------------
Starting with nSpinSim3.1.1 (see below for changes from nSpinSim3.0)

1. target.f  -- put the gas scattering back in, to allow air or 4He gas scattering.  The scattering length is 
determined from total cross section from ENDF.  The scattering angle is assumed isotropic.
2. main_EUp.f and main_WUp.f, 
	a. weighting = 1.0 for gas targets; = wgtA/sigma only for liquid He targets
	b. fixed problems with field gradient filenames (see const.inc also)
	

---------------------------	
Starting with nSpinSim3.1.1

1. Couple more bug fixes reading the different B-field files. 
2. Number of bounces (1,2,3).  This is not what we want ultimately, really counting all bounces and 
	allowing multiple bounces within a guide.  This simply counts if a neutron bounces in more 
	than one guide.  Current guides only allow one bounce in x-direction and one in y-direction.

	
----------------------------------------------------
Starting from nSpinSim3.0 with the following changes

1.  Pi-Coil On/Off and Bz-gradient runs are controled in constant.inc
2.  int_bz.f only interpolates the Bz gradient data given in the data files
    Bz.dat, Bz_LargeFld.dat, Bz_run1154.dat, Bz_run1449.dat.  These data files
	are read into a common block in the main routine.
3.  The weighting of target scatters by 0.00436/sig(En) is done in two ways: 
	1. the weighting for
    all neutrons is 1.0 to start and then set to the weighting factor if the neutron scatters
	in the target.  All histograms, counters, rotation values are weighted averages.  In this 
	method rotations are calculated for all neutrons (wgt=1 mixed wtih wgt~0.01), 
	non-scattered neutrons (wgt=1), target-scattered neutrons (wgt~0.01), 
	and neutrons that scatter from gas, Al, or are target scattered by switched sides 
	after the target region (wgt=1 mixed wtih wgt~0.01). 
	2. If a neutron	scatters in the target and a random number [0,1] is bigger than the weight, 
	then that neutron is not used in calculating the average rotations and energy losses.  In this
	method rotations are calculated for all neutrons and scattered neutrons.
	
	These two methods appear to	give the same results within statistics, but the second 
	method eliminates ~99/100 scattered neutrons from the average rotation calculation, 
	so the statistic error on the average rotation for scattered neutrons is ~10 times 
	larger than for method 1.
4.  Changed some of the output writing.  
5.  Included nhe4.f, the routine that gives the absorption versus depth in the ion chamber.















