#     # ######  #######
#     # #     # #          ##     ####    #####
#     # #     # #         #  #   #          #
####### #     # #####    #    #   ####      #
#     # #     # #        ######       #     #
#     # #     # #        #    #  #    #     #
#     # ######  #        #    #   ####      #


The GlueX Spectrometer for Hall D

HDFast is a fast and flexible simulation program based upon the MCFast framework developed 
by the simulation group at Fermilab. MCFast consists of a set of modularized Monte Carlo 
library routines; it is designed to perform parameterized tracking by assembling a covariance 
matrix for each track that takes into account materials, efficiencies, and resolutions for all 
measurements planes, and use this matrix to smear the track parameters randomly. In principle, 
the distribution of smeared tracks produced by this method would be similar to the distribution 
of real tracks that were measured by a real detector(with the same parameters) and analyzed 
with an idealized track fitting procedure. 




[Before Building HDFast]

		Define a  $HALLD_HOME, src, and bin directories
				% setenv HALLD_HOME  /your/home/gluex
				% make dir $HALLD_HOME/src
				% make dir $HALLD_HOME/lib/
				% make dir $HALLD_HOME/lib/`uname`
				% make dir $HALLD_HOME/bin/
				% make dir $HALLD_HOME/bin/`uname`

		Get packages from Hall D cvs
				% setenv CVSROOT $USER@cvs.jlab.org:/group/halld/cvsroot
				% setenv CVS_RSH ssh
				% cd $HALLD_HOME/src
				% cvs checkout HDFast mcroot stdhep_translators genr8 hdds

		Get the MCFast tarball
				% wget   http://www.jlab.org/Hall-D/software/mcfast_v5_2.tgz  $HALLD_HOME/src/.
				% tar zxvf mcfast_v5_2.tgz

		Build the mcroot libs (Requires ROOT, See the README)
				% cd $HALLD_HOME/src/mcroot
				% make 
				% make install
		Build stdhep_translators genr8 [Note: these are not needed to build HDFast]
				%  cd $HALLD_HOME/src/genr8
				% make ; make install
				%  cd $HALLD_HOME/src/stdhep_translators
				% make ; make install


[HDFast Build Environment]

	The $CRNLIB Environmental variables must be defined pointing to your cern libs. 
	Example:
			% echo $CRNLIB 
				/usr/local/cern/2000/lib	


	Now source 
		$HALLD_HOME/src/HDFast/setup5_2.Linux_gcc3x 
					or
		$HALLD_HOME/src/HDFast/setup5_2.Linux_gcc2x 

			[depending on your version of gcc  (see gcc --version)]



[Building HDFast]

	
			% make HDFast
			% make install






[HDFast Detector Geometry]
		
	HDFast requires the detector geometry file "HDFast.db".  To build and install this geometry
	database file see the "hdds" package.




[HDFast Run Time Environment]

	Note!! HDFast, during run time, needs certain environmental variables defined.  Therefor,
	       it is suggested that one adds the following lines to cshrc (or equivalent)
	       for automatic sourcing.


		#
		# Needed for HDFast building and running
		setenv HALLD_HOME  /your/home/gluex
		source $HALLD_HOME/src/HDFast/setup5_2.Linux_gcc3x  # or _gcc2x
		set path=($path  $HALLD_HOME/bin/`uname`   $HALLD_HOME/bin )
		rehash



[Using HDFast &  Test Run]


Below is an example showing how to generate MC events and process the 
events through the HDFast simulation.
	

		% mkdir $HALLD_HOME/test
		% cp ../genr8/n_pi-pi+pi+.input ./
		% genr8 -M1000 -An_3pi.ascii < n_pi-pi+pi+.input
		% run_hdfast -N 1000 -t n_3pi -n 3





[Viewing and Using HDFast Simulation Output]

	Viewing HDFast output(An ascii dump of the data)
		// list the data groups(data branches). See "dumpRdt -h" for usage.
		% dumpRdt -L  n_3pi.rdt
			Opening n_3pi.rdt for input
			set dump branches
			List Branches
			Branch list:
			        hepevt
			        offtrk
			        bcal
			        lgdSmears
			        traces
			Virtual Branch list:
			        esr     Requires(hepevt,offtrk,bcal,lgdSmears)

			The Tree contains 981 events

		// Dump all groups for just one event
		% dumpRdt -Bhepevt,offtrk,bcal,lgdSmears,traces -Vesr -n1 n_3pi.rdt
					...
					...
		
	Create a ROOT ntuple which can be opened by the ROOT ntuple viewer for a
	quick click graphical plots for mass projections and other distributions.
	See the text file "n_3pi.ntuple_labels" for the definitions of the automatically
	generated ntuple label names.  The ROOT ntuple is contained in the
	n_3pi n_3pi.root file. 

		// See "ntp_maker -h" for usage
		% ntp_maker -on_3pi n_3pi.rdt > n_3pi.ntuple_labels				...

	
		// Start ROOT and open tree viewer
		% root
			root [0] TFile f("n_3pi.root");
			root [1] TTree *tree =(TTree *) gROOT->FindObject("ntp");
			root [2] tree->StartViewer();
			...



	Example of ROOT macro access to the HDFast simulated data.

		// get sample macro
		% wget 	http://www.jlab.org/Hall-D/software/getInfo.C ./

		// execute the root macro
		% root .x getInfo.C