2 c => Original copy from /star/emc/shester/cl/pams/emc/jet/jet_finer_ua1.F
4 c:>------------------------------------------------------------------
5 C:ROUTINE: subroutine jet_finder_ua1
6 C:DESCRIPTION: UA1 jet algorithm from LUND JETSET called from EMC_erj
7 C:ARGUMENTS: emc_energy_h, emc_energy,
8 C:ARGUMENTS: et_tot, EMC_jetpar, ierror
9 C:RETURN VALUE: ierror=1 on error
10 c:>------------------------------------------------------------------
11 subroutine jet_finder_ua1(
12 + ncell, ncell_tot, etc, etac, phic,
13 + min_move, max_move, mode, prec_bg, ierror)
14 implicit none ! 5-oct-2001
15 c#include "math_constants.inc"
16 c#include "calorSize.inc"
23 parameter(NMAX=30000,JMAX=100) ! 10-oct-2201
24 integer ncell, ierror, mode, ncell_tot
25 real etc(NMAX),etac(NMAX),phic(NMAX)
26 real cone_rad, et_seed, ej_min, et_min
27 real min_move, max_move, prec_bg
28 integer flag(NMAX),index(NMAX)
29 integer n_iter,i,j,k,l,nc
30 real et_sum,et_ave,et_sum_old
31 real et,eta,phi,eta0,phi0,etab,phib,ets,etas,phis
34 real occupationAll, occupationInJet ! 3-oct-2001 by PAI
35 integer maxTowerInJet ! 5-oct-2001 by PAI
36 save maxTowerInJet ! This is obligatory
37 integer idPerfomance /119/
39 ! print parameter - 27-sep-2001 by PAI
44 COMMON /EMCALJETS/ NJET, ETJ(100), ETAJ(100,2), PHIJ(100,2),
47 COMMON /EMCALCELLGEO/ etaCellSize, phiCellSize
49 COMMON /EMCALJETPARAM/ cone_rad, et_seed, ej_min, et_min
56 ! for add. correction of jet energy if ocupation in jet not 100% !!
57 ! may differ from real number because grid
59 + int((C_PI*cone_rad*cone_rad)/(etaCellSize*phiCellSize)+0.5)
61 + ,cone_rad, et_seed, ej_min, et_min
62 + ,min_move, max_move, mode, prec_bg
65 + ' == jet_finder_UA1 == '/
68 + ' et_seed ', f5.2,' GeV/C'/
69 + ' ej_min ', f5.2,' GeV/C'/
70 + ' et_min(tower after bg sub.) ', f5.2,' GeV/C'/
71 + ' min_cone_move ', f5.3/
72 + ' max_cone_move ', f5.3/
73 + ' Mode for BG subtraction ', i5/
75 + ' -- PAI"s addition --'/
76 + ' maxTowerInJet ', i5/
79 if(NMAX .lt. ncell_tot) then
80 print 2, NMAX, ncell_tot
81 2 format('<E> you must increase memory -> NMAX ',i6
85 call hf1(idPerfomance, 1., 1.)
86 occupationAll = float(ncell) / float(ncell_tot)
87 call hf1(111, occupationAll, 1.)
88 ! print parameter - 27-sep-2001 by PAI
91 c*-sort cells by Et decending order, store the order in index
92 call sortzv(etc,index,ncell,-1,1,0)
93 c*-sum up total energy of all cells
101 et_ave=et_sum/float(ncell_tot)
105 print *,'Iter ', n_iter, ' et_ave ', et_ave, ' #cells ', ncell
106 c*-Watch out!!! For mode=1, it can jump back to here for next iteration!!!
108 c*-kill cells (flag=2) with Et below ET_MIN after background subtraction
109 cfca call vzero(flag,ncell)
112 if(etc(i)-et_ave .le. et_min) flag(i)=2
115 c*-Initiator cell is the one with highest Et of not yet used ones
118 if(i.eq.1. and. etc(j).lt.et_seed) then
119 if(mode.eq.0 .or. (mode.eq.1 .and. n_iter.eq.1)) then
120 call hf1(idPerfomance, 2., 1.)
121 print *,' no cell with Et higher than et_seed ->', etc(j)
124 do while(etc(j) .ge. et_seed)
125 if(flag(j) .eq. 0) then
136 c*-weighted eta and phi.
139 if(flag(l).eq.0) then
141 c*-Is the cell is in the cone?
142 if(abs(deta).le.cone_rad)then
144 do while(dphi .gt. C_PI)
147 do while(dphi .le. -C_PI)
150 if(abs(dphi).le.cone_rad) then
151 r_int=sqrt(deta**2+dphi**2)
152 if(r_int.le.cone_rad)then
153 c*-calculate offset from initiate cell
156 do while(dphi .gt. C_PI)
159 do while(dphi .lt. -C_PI)
163 etas=etas+abs(et)*deta
164 phis=phis+abs(et)*dphi
166 c*-New weighted eta and phi including this cell
169 c*-If cone does not move much from previous cone, just go next step
170 r_int=sqrt((eta-etab)**2+(phi-phib)**2)
171 if(r_int .le. min_move) then
174 c*-Cone should not move more than MAX_CONE_MOVE from initiator cell
175 r_int=sqrt((etas/ets)**2+(phis/ets)**2)
176 if(r_int .ge. max_move) then
181 c*-Store this loop information
191 c*-sum up unused cells within required distance of given eta/phi
198 if(flag(l) .eq. 0) then
200 if(abs(deta).le.cone_rad)then
202 do while(dphi .gt. C_PI)
205 do while(dphi .le. -C_PI)
208 if(abs(dphi).le.cone_rad) then
209 r_int=sqrt(deta**2+dphi**2)
210 if(r_int.le.cone_rad)then
222 ! 5-oct-2001 by PAI - remove 20-feb-2002 by PAI
223 ! 20-feb-2002 - it is work if you apply cut on eT before jet finder !!!
224 ! if(maxTowerInJet .gt. nc) then
225 ! ets = ets - et_ave*(maxTowerInJet - nc)
229 c*-reject cluster below minimum Ej_min
233 if (ets .ne. 0.) then
234 if (abs(etas/ets) .lt. 23.719) then
235 arg = ets * cosh(etas/ets)
241 if(arg .lt. ej_min) then
243 if(flag(k).le.0) flag(k)=0
245 if(njet.eq.0) call hf1(idPerfomance, 3., 1.)
247 c*-eles, store flags and jet variables
249 if(flag(k).eq.-1) flag(k)=1
252 do while(phi .ge. C_2PI)
255 do while(phi .lt. 0.0)
265 call hf1(112, float(nc)/float(maxTowerInJet), 1.) ! 8-oct-2001
272 c*-recalculate energy sum excluding used cells.
275 nc=0 ! #cells in jets
277 if(flag(i).ne.1) then ! 1 if cell in jet
283 c*-if background level changes more than prec_bg, go next iteration!!!
284 c*-after 10 iteration, stop working and finish
285 if( (abs(et_sum-et_sum_old)/et_sum.gt.prec_bg
286 + .and. n_iter.le.10)
287 + .or. n_iter.eq.1) then ! minimum 2 iteration - 10-oct-2001 by pai
288 et_ave=et_sum/float(ncell_tot-nc)
291 print *,'End of iteration : et_ave ', et_ave, ' nc ', nc
292 + , ' Jet energy ', ets
294 c*-Watch out!!! Here is a big jump!!!
296 occupationInJet = float(ncell) / float(ncell_tot)
297 call hf1(111, occupationInJet, 1.)
298 write(*,*) njet,' jet found in ',n_iter,
299 + ' iteration(s) : EtSum, EtAve =',
300 + et_sum,et_sum/float(ncell_tot-nc)
301 + , ' ncell_tot ', ncell_tot, ' #cell in jet ', nc
302 + , ' occupationAll ', occupationAll
303 + , ' occupationInJet ', occupationInJet
307 write(*,*)'UA1:Problem:More than 100 jets found!'
309 elseif(njet.eq.0)then
310 write(*,*)'UA1:Done:No jet found!'
313 +'UA1:Done:Found ',njet,' jet(s)'