	subroutine init
c	processes parameters common to all data sets
c
	include '/u1/gcf/e350/crystal/cb/abssiz'
	include '/u1/gcf/e350/crystal/cb/irspec'
	include '/u1/gcf/e350/crystal/cb/type'
c ....    am2i      * mass-squared of detected particle
c ....    am2j      * mass-squared of incident particle
c ....    amp       * mass of target particle
c ....    amp2      * mass-squared of target particle
c
	include '/u1/gcf/e350/crystal/cb/clouds'
	include '/u1/gcf/e350/crystal/cb/datbin'
	include '/u1/gcf/e350/crystal/cb/norm'
	include '/u1/gcf/e350/crystal/cb/const'
	include '/u1/gcf/e350/crystal/cb/foxin'
	include '/u1/gcf/e350/crystal/cb/fixcom'
	include '/u1/rgk/icicle/cb/dbprec'
	include '/u1/rgk/icicle/cb/ztpltc'
	include '/u1/gcf/e350/crystal/cb/beam'
	include '/u1/gcf/e350/crystal/cb/parms'
c
	common/itadd/itadd(7)
c	itadd(itr) is added to it1 for trigger no itr
c
	common/lbias/lbias(7)
c	lbias = 1/2/3/4/5/6  96/132/170/bp132/bp170/E
c
	dimension ium(7),ivm(8),amassj(4),amassi(7),namdta(2,3)
	dimension efmt(7),effull(7),ecorec(6)
	logical add23,add34
c
c ....    ipart     * detected particle
c	              * = 1 pi zero
c	              * = 2 eta
c	              * = 3 etaprime
c	             * = m pizero pizero
c ....    jpart     * incident particle
c	              * = 1 pi minus
c	              * = 2 pi plus
c	              * = 3 kaon minus
c	              * = 4 kaon plus
c	              * = 5 antiproton
c	              * = 6 proton
c	              * = 7 electron
c	              * = 8 positron
c ....    mt        * = .true.  target empty data present
c	              * = .false. no target empty data
c ....    effull    * effective flux for full data (for mt=.true.)
c ....    efmt      * effective flux for empty data (for mt=.true.)
c ....    pinc	 * beam momentum to be used (fitbem=.false.)
c	              * or initial guess (fitbem=.true.)
c ....    noe       * no of energy bins in data
c ....    elow      * lower edge of lowest energy bin (gev)
c ....    de        * width of energy bins (gev)
c ....    e1        * fit between energy e1 and e2
c ....    e2
c ....    fitsga   * = .true. fit for sigma  = .false. dont
c ....    fitfix    * = .true. fit for fixed mass normalization
c	              * = .false. dont
c ....    fitalp(i) * = .true.  fit for alpha in triple regge term i
c	  note that all i with same values of iusalp MUST have same
c	  values of fitalp
c	              * = .false. use alpha=alphain
c ....    sigma     * energy resolution has half width sigma*sqrt(e)
c ....    fixed     * = .true.  include in fixed mass contribution
c	              * = .false.   dont
c ....    nfs       * = .true.   all neutral
c	              * = .false.    all inclusive
c ....    ntr       * no of triple regge terms to include
c ....    collim    * width of collimator in inches
c ....    pff       * fixed mass normalization
c ....    igrp(i)   * data set i is in group igrp(i) with incident
c	              * particle jpart(igrp(i))
c ....    notrig    * number of data sets covering different energy
c	              * regions.  arrays are over notrig sets.
c ....    quick     * = .true.  just fit with small no of integration bins
c	              * = .false.  do complete fit
c ....    logplot   * = 0 plot with linear scale
c	              * = j  plot with j logarithmic decades
c ....    doplot    * = .true.  produce plot file
c	              * = .false. do not produce plot file
c ....    dolist    * =.true. produce a list in flake
c	              * =.false.  dont make a list
c ....    dofit     * =.true.  proceed normally with the fits
c	              * =.false.  bypass the fitting- proceed directly to flake
c ....    cross     * = .true.  calculate cross-section only
c ....    kgeom     * set of t values used
c ....    combine   * no of energy bins to combine together
c ....    expfac    * cross-section is exp(expfac*t)
c ....    usei2     * use isospin = 2 term
c ....    add34     * add together third and fourth bins
c ....    add23     * add together second and third bins - trigger b
c ....    iacc	 * for trigger no i use acceptance set iacc(i)
c ....	     * if =1 use erdown and erup to define limits for the
c		    * 2 triple regge terms (no longer used)
c
	character*10 ium,ivm,namdta
c
        data iocon/7*1/,iocon1/2*1/,iocon2/2*1/,namth/16*1h /,noth/0/
	data dofit/.true./,dolist/.false./,sigma/0.000160/,sigmb/0.0081/
	data ipart/1/,jpart/1,2/,cross/.false./,igrp/7*1/,lwbias/2*0/
	data ium/7hpi zero,3heta,8hetaprime,9hkaon zero,5homega,6hphoton,
& 		9hpizr pizr/,onebin/.false./,nampl/12*1h /
	data ivm/8hpi minus,7hpi plus,10hkaon minus,9hkaon plus,
& 	10hantiproton,6hproton,8helectron,8hpositron/
	data amassi/.0182,.301,.917,.248,.613,0.,.360/
	data amassj/.019483,.244,.8804,3.01e-6/
	data mt/7*.true./,fitbem/.false./,ftbrem/.false./,combin/7*1/,
&	noalp/1/,notrig/1/,quick/.true./,
&	vm1/.9396,1.230/,vm2/1.1,1.242/,vm3/1.4/,itadd/7*0/,
&	core,corem/14*1./,bratio/.9885,.38/,fitalp/2*.true.,3*.false./
&	fitsga/.false./,nfs/.false./,pinc/197.0/,
& 	amp/.9383/,mxmin2/0.883/,ntr/1/,conal/1.,.5,3*-99./
	data namdta/10hfull inclu,4hsive,3hnfs,1h ,10hbremstrahl,3hung/
	data jrspec/0/,doplot/.false./,kgeom/1/,vary/2./
	data ftnorm/.true.,4*.false./,iglow/.true./,ntrdis/0/
	data dopipi/.false./,add34/.false./,add23/.false./
	data nadd/0/,efmt/7*0./,usei2/.false./,iusalp/5*1/
c	ecorec  is the fraction of the full target flux seen by the mt material
	data ecorec/0.985,0.986,0.987,0.988,0.975,0.974/
c
100	format(1h1,130(1h*)/2h *,29h investigating trajectory of ,a10,
& 	59h particles detected by photon detector produced by beam of ,
& 	a10,20h particles          ,1h*/1h ,130(1h*)/)
101	format(17h beam momentum = ,f6.2,20h gev/c assumed known)
102	format('fitting to find beam momentum. initial guess = 'f6.2' GeV')
103	format('data set number'i2'effective flux for target full data ='
& 	1pe10.2,5x,39heffective flux for target empty data = ,1pe10.2)
105	format('fitting to find parameter sigma    initial guess 'f8.4)
107	format('energy resolution is  sqrt'f9.7,5he**2+,f6.4,1he)
108	format('no target empty data present ')
110	format('data is '2a10,' norm factor fdmicr ='1pg14.2)
111	format('collimator s2c5 opening = 'f7.2' inches ')
112	format(l1)
113	format('fitting with normaln of cex contribution fixed at'1pg13.4)
c
c	read in acceptances - file name before original $ROSES
        open(1,file='ROSES',form='formatted',access='sequential')
        rewind(1)
c
c	  old namelist roses
	read(1,*) collim,combin,core
	read(1,112) cross
	read(1,112) doplot
	read(1,*) effull,efmt,e1,e2,fitbem,fitsga,jpart,mt,nfs,noalp,quick
	read(1,112) usei2
	read(1,*) corem
	read(1,112) dofit
	if (dolist) dofit=.false.
	read(1,112) fitalp(1)
	read(1,200) ntrdis,notrig,ipart,iacc,itadd,lbias,ntr
200	format(i1/i1/i1/7i2/7i2/7i2/i1)
c
c	some consistency requirements
	ntrdis=max0(ntrdis,notrig)
	if (lwbias(1).gt.ntrdis) lwbias(1)=0
	if (lwbias(2).gt.ntrdis) lwbias(2)=0
	if (cross) usei2=.false.
	if (nfs) conal(1)=-0.08
	if (nfs) conal(2)=-0.08
        write(6,300) collim,combin,conal,core,corem,cross,
&	dofit,fitalp(1),doplot,effull,efmt,e1,e2,fitbem,fitsga,iacc,itadd,
&	ipart,jpart,lbias,mt,notrig,ntrdis,nfs,noalp,ntr,quick,usei2
300	format(/' ROSES  collim'f6.2
&	' combin'7i2' conal'5f7.2/' core'7f6.3' corem'7f6.3/
&	' cross'l2' dofit'l2' fitalp(1)'l2' doplot'l2/
&	' full effective flux ='7e10.4/' empty effective flux='7e10.4/
&	' e1 ='7f6.1' e2 ='7f6.1/
&	' fitbem'l2' fitsga'l2' iacc'7i2' itadd'7i2/
&	' detected particle ipart='i2' incident particles jpart='2i2/
&	' lbias '7i3' mt '7l2' notrig ntrdis'2i2
&	' nfs'l2' noalp'i2' ntr'i2' quick'l2' usei2'l2)
c
c	rewind fort.8 and fort.9
	if (cross) goto 55
	do 54 itr=1,ntr
54	rewind itr+7
c
c	read in acceptances
55	call mist
c
	alimf1=1./vary
	alimf2=vary-alimf1
	if (jpart(1).ne.3) goto 14
	alimf1=0.036
	alimf2=0.00
14	if (jpart(1).le.4) goto 10
	alimf1=0.9/sqrt(2.*amp*pinc)
	alimf2=0.
	vm3=0.1349
10	do 5 i=1,notrig
	e1o(i)=e1(i)
5	e2o(i)=e2(i)
	if (ntrdis.gt.7) call abort
	print 100,ium(ipart),ivm(jpart(1))
	am2i=amassi(ipart)
	am2id=am2i
	am2j=amassj((jpart(1)+1)/2)
	am2jd=am2j
	amp2=amp*amp
c	for positive beam fixed mass contribution is pi+ + p --> pi0 +delta0
	if (jpart(1).eq.2) vm1(1)=1.230
	if (jpart(1).eq.2) vm2(1)=1.242
	if (jpart(1).eq.3) vm1(1)=1.115
	if (jpart(1).eq.3) vm1(2)=1.390
	vm1(1)=vm1(1)**2
	vm2(1)=vm2(1)**2
	vm1(2)=vm1(2)**2
	vm2(2)=vm2(2)**2
	vm3=vm3**2
	irspec=jrspec
c
c	process beam
c	.90 used to be .45 for 100 gev but doubled since collimater 
c	setting proportional to deltap/p
	dbeam=.90*collim
	if (fitbem) goto 1
	print 101,pinc
	goto 2
1	print 102,pinc
	pincin=pinc
c
2	if (.not.fitsga) goto 4
	print 105,sigma
	sigman=sigma
4	print 107,sigma,sigmb
	print 111,collim
	fdmicr=1.
	effave=1.
	etest(1)=1.
	do 9 it=1,ntrdis
	effull(it)=effull(it)*0.893
	efmt(it)=efmt(it)*0.958/ecorec(jpart(igrp(it)))
c	delta rays losing nfs events
	if (nfs) effull(it)=0.90*effull(it)
c	correct for photon conversion - see table 6.i.1 of kennett phd thesis
	print 103,it,effull(it),efmt(it)
	if (it.eq.1) effave=effull(1)
	efmt(it)=efmt(it)/effave
	effull(it)=effull(it)/effave
	eftot(it)=effull(it)+efmt(it)
	fulinv(it)=1./effull(it)
	if (mt(it)) emtinv(it)=1./efmt(it)
	ful2(it)=fulinv(it)**2
	if (mt(it)) emt2(it)=emtinv(it)**2
	etest(it)=fulinv(it)
9	continue
c
	if (.not.add23) goto 11
	iada(1)=2
	iadb(1)=3
	nadd=1
	goto 12
11	if (.not.add34) goto 6
	iada(1)=3
	iadb(1)=4
	nadd=1
	goto 12
6	if (nadd.eq.0) goto 3
12	do 13 i=1,nadd
	ica=iada(i)
	icb=iadb(i)
	effull(ica)=effull(ica)+effull(icb)
	effull(icb)=effull(ica)
	efmt(ica)=efmt(ica)+efmt(icb)
	efmt(icb)=efmt(ica)
	eftot(ica)=effull(ica)+efmt(ica)
	eftot(icb)=eftot(ica)
	fulinv(ica)=1./effull(ica)
	fulinv(icb)=fulinv(ica)
	emtinv(ica)=1./efmt(ica)
	emtinv(icb)=emtinv(ica)
	ful2(ica)=fulinv(ica)**2
	ful2(icb)=ful2(ica)
	emt2(ica)=emtinv(ica)**2
	emt2(icb)=emt2(ica)
	etest(ica)=fulinv(ica)
	etest(icb)=etest(ica)
13	continue
	if (nadd.eq.2.and.iada(2).gt.iadb(1)) iada(2)=iada(2)-1
	if (nadd.eq.2.and.iadb(2).gt.iadb(1)) iadb(2)=iadb(2)-1
c
3	fdmicr=0.98/(0.9*2.57e-6*effave)
	if (nfs) then
		indnam=2
c
c		nfs correction applies at x=1 i e neutron production
c		0.90 delta rays - only target full so included above
c		0.98  neutron veto
c		0.97  beam attenuation
		fdmicr=fdmicr/(0.98*0.97)
		if (fitbem) then
		fitfix=.false.
		else
		fitfix=.true.
		endif
		fitfix=.false.
	else
		indnam=1
		fitfix=.false.
	endif
c
	print 110,(namdta(j,indnam),j=1,2),fdmicr
c
	return
	end
