*	~mc/mcv3k/paw/mcv3k_ana.kumac
*
*	kumac to create some histograms from NTUPLE files
*	of the MCV3K simulations of the muonium experiment
*	at PSI performed at piE1 in May 1994. 
*	one input parameter - the filename of the NTUPLE file which
*	must have the extension .NT - is required without extension.
*	the relevant variables are E0 (energy in MeV) and T0 (time
*	of flight between S1 and MCP2 ins ns), the NTUPLE id is 111.
*	1.6 ns are substracted from the TOF's to correct for the
*	TOF S1 - Target foil. This is necessary since the experimental
*	TOF's are also corrected for this time.
*
*	the new histograms are
*
*	-	3 TOF's with different binnings (0.5, 1.0 and 2.0 ns)
*		in the intervall [0,200]ns
*	-	3 energy histograms in the intervals [0,1500] keV with 10keV 
*		bins
*		[0,100]keV with 1keV bins and
*		[0,30]keV with 1keV bins
*		the purpose of the last two ones is to get information
*		on the fraction of muons having energies in the 10 keV region
*		to be able to make some predictions on muonium formation 
*
*
*	no cuts are necessary since the NTUPLE data contain only those
*	muons hitting the MCP2. The distances and dimensions of the
*	various elementes from the Mylar foil and S1 to the MCP2
*	were rechecked fro the MCV3K simulation and they should be ok now.
*
*	at the end the new histograms are written to a .RZ file with the
*	same name as the NTUPLE file had.
*
*	TP, 20-July-1995
*
*
*	added a second parameter to indicate if a Postscript output should
*	be done ( if [2]=PS  then post script)
*
*
*	TP, 18-dec-1995	renamed from RUN7_ANA.KUMAC
*	TP, 09-feb-1998 changed bin size of ID1 from 257ps to 258ps
*	TP, 14-sep-2000 Unix version
*-----------------------------------------------------------------------------
*
*	open the NTUPLE file
*
	close 0		| first close all open units
	file = $mcv3k_out/[1].nt
	hi/file 20 [file] 4096
	message NTUPLE file = [file]
*
*	book now the histograms needed
*
	do i =1,6	| delete existing histograms
		hi/del [i]
	enddo
	1d 1 'TOF - 1.7ns, 0.258ns binning' 501 -.129 129.129
	1d 2 'TOF - 1.7ns, 0.5ns binning' 401 -.25 200.25
	1d 3 'TOF - 1.7ns, 1.0ns binning' 201 -.5 200.5
	1d 4 'energy in keV' 301 -5. 3005.
	1d 5 'energy below 100 keV' 101 -.5 100.5
	1d 6 'energy below  30 keV' 31  -.5 30.5
*
*	fill the histograms
*
	opt liny
	set ysiz 28
	zone 2 3
	opt nfil
	title [1]
*
*	open PostScript file if desired
*
	if [2] .eq. 'PS' .or. [2] .eq. 'ps' then
		for/file 66  $mcv3k_out/[1].ps 
		meta 66 -111
* 
	endif
	nt/pl 111.(t0-1.7) id>1 ! -1	| id>1 necessary because of a little
	nt/pl 111.(t0-1.7) id>1 ! -2	| mistake in the routine which creates
	nt/pl 111.(t0-1.7) id>1 ! -3	| the ntuple files
	nt/pl 111.1000*e0 id>1 ! -4	| energy in keV
	nt/pl 111.1000*e0 id>1 ! -5
	nt/pl 111.1000*e0 id>1 ! -6
*
*	write histograms to RZ files
*
	n = 0
	do i = 1, 6
		temp = $HINFO([i],'ENTRIES')
		if ([temp].eq.0) then
			n = [n] + 1
		endif
	enddo
	if ( [n] .eq. 6) then
		goto ret
	endif
*
	set ysiz
	opt fit
	set fit 111111
	v/cre par(3) r 200 450 200
*	hi/fit 4 gauss_ener.for l 3 par
	hi/file 21 $mcv3k_out/[1].rz ! n	| "! n" means new file
*
	if [2] .eq. 'PS' .or. [2] .eq. 'ps' then
		close 66
		message PostScript file $mcv3k_out/[1].ps
	endif
*	
	do i = 1,6
		hrout [i]
	enddo
	message Histograms written to $mcv3k_out/[1].rz
	close 20
	close 21
	set ysiz
	opt file
	title ' '
ret:
	return
*
*------------------------------------------------------------------------------
*
*	EOF ~/mc/mcv3k/paw/mcv3k_ana.kumac
*
